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

1.1       raeburn     1: # The LearningOnline Network with CAPA
                      2: # Handler to set domain-wide configuration settings
                      3: #
1.316   ! raeburn     4: # $Id: domainprefs.pm,v 1.315 2017/10/13 20:37:34 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
1.286     raeburn    22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     23: #
1.1       raeburn    24: # /home/httpd/html/adm/gpl.txt
                     25: #
                     26: # http://www.lon-capa.org/
                     27: #
                     28: #
                     29: ###############################################################
1.297     raeburn    30: ###############################################################
1.1       raeburn    31: 
1.101     raeburn    32: =pod
                     33: 
                     34: =head1 NAME
                     35: 
                     36: Apache::domainprefs.pm
                     37: 
                     38: =head1 SYNOPSIS
                     39: 
                     40: Handles configuration of a LON-CAPA domain.  
                     41: 
                     42: This is part of the LearningOnline Network with CAPA project
                     43: described at http://www.lon-capa.org.
                     44: 
                     45: 
                     46: =head1 OVERVIEW
                     47: 
                     48: Each institution using LON-CAPA will typically have a single domain designated 
1.183     bisitz     49: for use by individuals affiliated with the institution.  Accordingly, each domain
1.101     raeburn    50: may define a default set of logos and a color scheme which can be used to "brand"
                     51: the LON-CAPA instance. In addition, an institution will typically have a language
                     52: and timezone which are used for the majority of courses.
                     53: 
                     54: LON-CAPA provides a mechanism to display and modify these defaults, as well as a 
                     55: host of other domain-wide settings which determine the types of functionality
                     56: available to users and courses in the domain.
                     57: 
                     58: There is also a mechanism to configure cataloging of courses in the domain, and
                     59: controls on the operation of automated processes which govern such things as
                     60: roster updates, user directory updates and processing of course requests.
                     61: 
                     62: The domain coordination manual which is built dynamically on install/update of 
                     63: LON-CAPA from the relevant help items provides more information about domain 
                     64: configuration.
                     65: 
                     66: Most of the domain settings are stored in the configuration.db GDBM file which is
                     67: housed on the primary library server for the domain in /home/httpd/lonUsers/$dom,
                     68: where $dom is the domain.  The configuration.db stores settings in a number of 
                     69: frozen hashes of hashes.  In a few cases, domain information must be uploaded to
                     70: the domain as files (e.g., image files for logos etc., or plain text files for
                     71: bubblesheet formats).  In this case the domainprefs.pm must be running in a user
                     72: session hosted on the primary library server in the domain, as these files are 
                     73: stored in author space belonging to a special $dom-domainconfig user.   
                     74: 
                     75: domainprefs.pm in combination with lonconfigsettings.pm will retrieve and display
                     76: the current settings, and provides an interface to make modifications.
                     77: 
                     78: =head1 SUBROUTINES
                     79: 
                     80: =over
                     81: 
                     82: =item print_quotas()
                     83: 
                     84: Inputs: 4 
                     85: 
                     86: $dom,$settings,$rowtotal,$action.
                     87: 
                     88: $dom is the domain, $settings is a reference to a hash of current settings for
                     89: the current context, $rowtotal is a reference to the scalar used to record the 
1.210     raeburn    90: number of rows displayed on the page, and $action is the context (quotas, 
1.163     raeburn    91: requestcourses or requestauthor).
1.101     raeburn    92: 
                     93: The print_quotas routine was orginally created to display/store information
                     94: about default quota sizes for portfolio spaces for the different types of 
                     95: institutional affiliation in the domain (e.g., Faculty, Staff, Student etc.), 
                     96: but is now also used to manage availability of user tools: 
                     97: i.e., blogs, aboutme page, and portfolios, and the course request tool,
1.197     raeburn    98: used by course owners to request creation of a course, and to display/store
1.223     bisitz     99: default quota sizes for Authoring Spaces.
1.101     raeburn   100: 
                    101: Outputs: 1
                    102: 
                    103: $datatable  - HTML containing form elements which allow settings to be changed. 
                    104: 
                    105: In the case of course requests, radio buttons are displayed for each institutional
                    106: affiliate type (and also default, and _LC_adv) for each of the course types 
1.271     raeburn   107: (official, unofficial, community, textbook, and placement).  
                    108: In each case the radio buttons allow the selection of one of four values:  
1.101     raeburn   109: 
1.104     raeburn   110: 0, approval, validate, autolimit=N (where N is blank, or a positive integer).
1.101     raeburn   111: which have the following effects:
                    112: 
                    113: 0
                    114: 
                    115: =over
                    116: 
                    117: - course requests are not allowed for this course types/affiliation
                    118: 
                    119: =back
                    120: 
1.104     raeburn   121: approval 
1.101     raeburn   122: 
                    123: =over 
                    124: 
                    125: - course requests must be approved by a Doman Coordinator in the 
                    126: course's domain
                    127: 
                    128: =back
                    129: 
                    130: validate 
                    131: 
                    132: =over
                    133: 
                    134: - an institutional validation (e.g., check requestor is instructor
                    135: of record) needs to be passed before the course will be created.  The required
                    136: validation is in localenroll.pm on the primary library server for the course 
                    137: domain.
                    138: 
                    139: =back
                    140: 
                    141: autolimit 
                    142: 
                    143: =over
                    144:  
1.143     raeburn   145: - course requests will be processed automatically up to a limit of
1.101     raeburn   146: N requests for the course type for the particular requestor.
                    147: If N is undefined, there is no limit to the number of course requests
                    148: which a course owner may submit and have processed automatically. 
                    149: 
                    150: =back
                    151: 
                    152: =item modify_quotas() 
                    153: 
                    154: =back
                    155: 
                    156: =cut
                    157: 
1.1       raeburn   158: package Apache::domainprefs;
                    159: 
                    160: use strict;
                    161: use Apache::Constants qw(:common :http);
                    162: use Apache::lonnet;
                    163: use Apache::loncommon();
                    164: use Apache::lonhtmlcommon();
                    165: use Apache::lonlocal;
1.43      raeburn   166: use Apache::lonmsg();
1.91      raeburn   167: use Apache::lonconfigsettings;
1.232     raeburn   168: use Apache::lonuserutils();
1.235     raeburn   169: use Apache::loncoursequeueadmin();
1.69      raeburn   170: use LONCAPA qw(:DEFAULT :match);
1.6       raeburn   171: use LONCAPA::Enrollment;
1.81      raeburn   172: use LONCAPA::lonauthcgi();
1.275     raeburn   173: use LONCAPA::SSL;
1.9       raeburn   174: use File::Copy;
1.43      raeburn   175: use Locale::Language;
1.62      raeburn   176: use DateTime::TimeZone;
1.68      raeburn   177: use DateTime::Locale;
1.267     raeburn   178: use Time::HiRes qw( sleep );
1.1       raeburn   179: 
1.155     raeburn   180: my $registered_cleanup;
                    181: my $modified_urls;
                    182: 
1.1       raeburn   183: sub handler {
                    184:     my $r=shift;
                    185:     if ($r->header_only) {
                    186:         &Apache::loncommon::content_type($r,'text/html');
                    187:         $r->send_http_header;
                    188:         return OK;
                    189:     }
                    190: 
1.91      raeburn   191:     my $context = 'domain';
1.1       raeburn   192:     my $dom = $env{'request.role.domain'};
1.5       albertel  193:     my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1       raeburn   194:     if (&Apache::lonnet::allowed('mau',$dom)) {
                    195:         &Apache::loncommon::content_type($r,'text/html');
                    196:         $r->send_http_header;
                    197:     } else {
                    198:         $env{'user.error.msg'}=
                    199:         "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
                    200:         return HTTP_NOT_ACCEPTABLE;
                    201:     }
1.155     raeburn   202: 
                    203:     $registered_cleanup=0;
                    204:     @{$modified_urls}=();
                    205: 
1.1       raeburn   206:     &Apache::lonhtmlcommon::clear_breadcrumbs();
                    207:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.58      raeburn   208:                                             ['phase','actions']);
1.30      raeburn   209:     my $phase = 'pickactions';
1.3       raeburn   210:     if ( exists($env{'form.phase'}) ) {
                    211:         $phase = $env{'form.phase'};
                    212:     }
1.150     raeburn   213:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.3       raeburn   214:     my %domconfig =
1.6       raeburn   215:       &Apache::lonnet::get_dom('configuration',['login','rolecolors',
1.125     raeburn   216:                 'quotas','autoenroll','autoupdate','autocreate',
                    217:                 'directorysrch','usercreation','usermodification',
                    218:                 'contacts','defaults','scantron','coursecategories',
                    219:                 'serverstatuses','requestcourses','helpsettings',
1.163     raeburn   220:                 'coursedefaults','usersessions','loadbalancing',
1.267     raeburn   221:                 'requestauthor','selfenrollment','inststatus',
1.279     raeburn   222:                 'ltitools','ssl','trust'],$dom);
1.297     raeburn   223:     if (ref($domconfig{'ltitools'}) eq 'HASH') {
                    224:         my %encconfig =
                    225:             &Apache::lonnet::get_dom('encconfig',['ltitools'],$dom);
                    226:         if (ref($encconfig{'ltitools'}) eq 'HASH') {
                    227:             foreach my $id (keys(%{$domconfig{'ltitools'}})) {
                    228:                 if (ref($domconfig{'ltitools'}{$id}) eq 'HASH') {
                    229:                     foreach my $item ('key','secret') {
                    230:                         $domconfig{'ltitools'}{$id}{$item} = $encconfig{'ltitools'}{$id}{$item};
                    231:                     }
                    232:                 }
                    233:             }
                    234:         }
                    235:     }
1.43      raeburn   236:     my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll',
1.125     raeburn   237:                        'autoupdate','autocreate','directorysrch','contacts',
1.224     raeburn   238:                        'usercreation','selfcreation','usermodification','scantron',
1.163     raeburn   239:                        'requestcourses','requestauthor','coursecategories',
1.267     raeburn   240:                        'serverstatuses','helpsettings','coursedefaults',
1.279     raeburn   241:                        'ltitools','selfenrollment','usersessions','ssl','trust');
1.171     raeburn   242:     my %existing;
                    243:     if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
                    244:         %existing = %{$domconfig{'loadbalancing'}};
                    245:     }
                    246:     if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.150     raeburn   247:         push(@prefs_order,'loadbalancing');
                    248:     }
1.30      raeburn   249:     my %prefs = (
                    250:         'rolecolors' =>
                    251:                    { text => 'Default color schemes',
1.67      raeburn   252:                      help => 'Domain_Configuration_Color_Schemes',
1.30      raeburn   253:                      header => [{col1 => 'Student Settings',
                    254:                                  col2 => '',},
                    255:                                 {col1 => 'Coordinator Settings',
                    256:                                  col2 => '',},
                    257:                                 {col1 => 'Author Settings',
                    258:                                  col2 => '',},
                    259:                                 {col1 => 'Administrator Settings',
                    260:                                  col2 => '',}],
1.230     raeburn   261:                       print => \&print_rolecolors,
                    262:                       modify => \&modify_rolecolors,
1.30      raeburn   263:                     },
1.110     raeburn   264:         'login' =>
1.30      raeburn   265:                     { text => 'Log-in page options',
1.67      raeburn   266:                       help => 'Domain_Configuration_Login_Page',
1.168     raeburn   267:                       header => [{col1 => 'Log-in Page Items',
                    268:                                   col2 => '',},
                    269:                                  {col1 => 'Log-in Help',
1.256     raeburn   270:                                   col2 => 'Value'},
                    271:                                  {col1 => 'Custom HTML in document head',
1.168     raeburn   272:                                   col2 => 'Value'}],
1.230     raeburn   273:                       print => \&print_login,
                    274:                       modify => \&modify_login,
1.30      raeburn   275:                     },
1.43      raeburn   276:         'defaults' => 
1.236     raeburn   277:                     { text => 'Default authentication/language/timezone/portal/types',
1.67      raeburn   278:                       help => 'Domain_Configuration_LangTZAuth',
1.43      raeburn   279:                       header => [{col1 => 'Setting',
1.236     raeburn   280:                                   col2 => 'Value'},
1.294     raeburn   281:                                  {col1 => 'Internal Authentication',
                    282:                                   col2 => 'Value'},
1.236     raeburn   283:                                  {col1 => 'Institutional user types',
1.305     raeburn   284:                                   col2 => 'Name displayed'}],
1.230     raeburn   285:                       print => \&print_defaults,
                    286:                       modify => \&modify_defaults,
1.43      raeburn   287:                     },
1.30      raeburn   288:         'quotas' => 
1.197     raeburn   289:                     { text => 'Blogs, personal web pages, webDAV/quotas, portfolios',
1.67      raeburn   290:                       help => 'Domain_Configuration_Quotas',
1.77      raeburn   291:                       header => [{col1 => 'User affiliation',
1.72      raeburn   292:                                   col2 => 'Available tools',
1.213     raeburn   293:                                   col3 => 'Quotas, MB; (Authoring requires role)',}],
1.230     raeburn   294:                       print => \&print_quotas,
                    295:                       modify => \&modify_quotas,
1.30      raeburn   296:                     },
                    297:         'autoenroll' =>
                    298:                    { text => 'Auto-enrollment settings',
1.67      raeburn   299:                      help => 'Domain_Configuration_Auto_Enrollment',
1.30      raeburn   300:                      header => [{col1 => 'Configuration setting',
                    301:                                  col2 => 'Value(s)'}],
1.230     raeburn   302:                      print => \&print_autoenroll,
                    303:                      modify => \&modify_autoenroll,
1.30      raeburn   304:                    },
                    305:         'autoupdate' => 
                    306:                    { text => 'Auto-update settings',
1.67      raeburn   307:                      help => 'Domain_Configuration_Auto_Updates',
1.30      raeburn   308:                      header => [{col1 => 'Setting',
                    309:                                  col2 => 'Value',},
1.131     raeburn   310:                                 {col1 => 'Setting',
                    311:                                  col2 => 'Affiliation'},
1.43      raeburn   312:                                 {col1 => 'User population',
1.227     bisitz    313:                                  col2 => 'Updatable user data'}],
1.230     raeburn   314:                      print => \&print_autoupdate,
                    315:                      modify => \&modify_autoupdate,
1.30      raeburn   316:                   },
1.125     raeburn   317:         'autocreate' => 
                    318:                   { text => 'Auto-course creation settings',
                    319:                      help => 'Domain_Configuration_Auto_Creation',
                    320:                      header => [{col1 => 'Configuration Setting',
                    321:                                  col2 => 'Value',}],
1.230     raeburn   322:                      print => \&print_autocreate,
                    323:                      modify => \&modify_autocreate,
1.125     raeburn   324:                   },
1.30      raeburn   325:         'directorysrch' => 
1.277     raeburn   326:                   { text => 'Directory searches',
1.67      raeburn   327:                     help => 'Domain_Configuration_InstDirectory_Search',
1.277     raeburn   328:                     header => [{col1 => 'Institutional Directory Setting',
                    329:                                 col2 => 'Value',},
                    330:                                {col1 => 'LON-CAPA Directory Setting',
1.30      raeburn   331:                                 col2 => 'Value',}],
1.230     raeburn   332:                     print => \&print_directorysrch,
                    333:                     modify => \&modify_directorysrch,
1.30      raeburn   334:                   },
                    335:         'contacts' =>
1.286     raeburn   336:                   { text => 'E-mail addresses and helpform',
1.67      raeburn   337:                     help => 'Domain_Configuration_Contact_Info',
1.286     raeburn   338:                     header => [{col1 => 'Default e-mail addresses',
                    339:                                 col2 => 'Value',},
                    340:                                {col1 => 'Recipient(s) for notifications',
                    341:                                 col2 => 'Value',},
                    342:                                {col1 => 'Ask helpdesk form settings',
                    343:                                 col2 => 'Value',},],
1.230     raeburn   344:                     print => \&print_contacts,
                    345:                     modify => \&modify_contacts,
1.30      raeburn   346:                   },
                    347:         'usercreation' => 
                    348:                   { text => 'User creation',
1.67      raeburn   349:                     help => 'Domain_Configuration_User_Creation',
1.43      raeburn   350:                     header => [{col1 => 'Format rule type',
                    351:                                 col2 => 'Format rules in force'},
1.34      raeburn   352:                                {col1 => 'User account creation',
                    353:                                 col2 => 'Usernames which may be created',},
1.30      raeburn   354:                                {col1 => 'Context',
1.43      raeburn   355:                                 col2 => 'Assignable authentication types'}],
1.230     raeburn   356:                     print => \&print_usercreation,
                    357:                     modify => \&modify_usercreation,
1.30      raeburn   358:                   },
1.224     raeburn   359:         'selfcreation' => 
                    360:                   { text => 'Users self-creating accounts',
                    361:                     help => 'Domain_Configuration_Self_Creation', 
                    362:                     header => [{col1 => 'Self-creation with institutional username',
                    363:                                 col2 => 'Enabled?'},
                    364:                                {col1 => 'Institutional user type (login/SSO self-creation)',
                    365:                                 col2 => 'Information user can enter'},
1.303     raeburn   366:                                {col1 => 'Self-creation with e-mail verification',
1.224     raeburn   367:                                 col2 => 'Settings'}],
1.230     raeburn   368:                     print => \&print_selfcreation,
                    369:                     modify => \&modify_selfcreation,
1.224     raeburn   370:                   },
1.69      raeburn   371:         'usermodification' =>
1.33      raeburn   372:                   { text => 'User modification',
1.67      raeburn   373:                     help => 'Domain_Configuration_User_Modification',
1.33      raeburn   374:                     header => [{col1 => 'Target user has role',
1.227     bisitz    375:                                 col2 => 'User information updatable in author context'},
1.33      raeburn   376:                                {col1 => 'Target user has role',
1.227     bisitz    377:                                 col2 => 'User information updatable in course context'}],
1.230     raeburn   378:                     print => \&print_usermodification,
                    379:                     modify => \&modify_usermodification,
1.33      raeburn   380:                   },
1.69      raeburn   381:         'scantron' =>
1.95      www       382:                   { text => 'Bubblesheet format file',
1.67      raeburn   383:                     help => 'Domain_Configuration_Scantron_Format',
1.46      raeburn   384:                     header => [ {col1 => 'Item',
                    385:                                  col2 => '',
                    386:                               }],
1.230     raeburn   387:                     print => \&print_scantron,
                    388:                     modify => \&modify_scantron,
1.46      raeburn   389:                   },
1.86      raeburn   390:         'requestcourses' => 
                    391:                  {text => 'Request creation of courses',
                    392:                   help => 'Domain_Configuration_Request_Courses',
                    393:                   header => [{col1 => 'User affiliation',
1.102     raeburn   394:                               col2 => 'Availability/Processing of requests',},
                    395:                              {col1 => 'Setting',
1.216     raeburn   396:                               col2 => 'Value'},
                    397:                              {col1 => 'Available textbooks',
1.235     raeburn   398:                               col2 => ''},
1.242     raeburn   399:                              {col1 => 'Available templates',
                    400:                               col2 => ''},
1.235     raeburn   401:                              {col1 => 'Validation (not official courses)',
                    402:                               col2 => 'Value'},],
1.230     raeburn   403:                   print => \&print_quotas,
                    404:                   modify => \&modify_quotas,
1.86      raeburn   405:                  },
1.163     raeburn   406:         'requestauthor' =>
1.223     bisitz    407:                  {text => 'Request Authoring Space',
1.163     raeburn   408:                   help => 'Domain_Configuration_Request_Author',
                    409:                   header => [{col1 => 'User affiliation',
                    410:                               col2 => 'Availability/Processing of requests',},
                    411:                              {col1 => 'Setting',
                    412:                               col2 => 'Value'}],
1.230     raeburn   413:                   print => \&print_quotas,
                    414:                   modify => \&modify_quotas,
1.163     raeburn   415:                  },
1.69      raeburn   416:         'coursecategories' =>
1.120     raeburn   417:                   { text => 'Cataloging of courses/communities',
1.67      raeburn   418:                     help => 'Domain_Configuration_Cataloging_Courses',
1.238     raeburn   419:                     header => [{col1 => 'Catalog type/availability',
                    420:                                 col2 => '',},
                    421:                                {col1 => 'Category settings for standard catalog',
1.57      raeburn   422:                                 col2 => '',},
                    423:                                {col1 => 'Categories',
                    424:                                 col2 => '',
                    425:                                }],
1.230     raeburn   426:                     print => \&print_coursecategories,
                    427:                     modify => \&modify_coursecategories,
1.69      raeburn   428:                   },
                    429:         'serverstatuses' =>
1.77      raeburn   430:                  {text   => 'Access to server status pages',
1.69      raeburn   431:                   help   => 'Domain_Configuration_Server_Status',
                    432:                   header => [{col1 => 'Status Page',
                    433:                               col2 => 'Other named users',
                    434:                               col3 => 'Specific IPs',
                    435:                             }],
1.230     raeburn   436:                   print => \&print_serverstatuses,
                    437:                   modify => \&modify_serverstatuses,
1.69      raeburn   438:                  },
1.118     jms       439:         'helpsettings' =>
1.282     raeburn   440:                  {text   => 'Support settings',
1.118     jms       441:                   help   => 'Domain_Configuration_Help_Settings',
1.282     raeburn   442:                   header => [{col1 => 'Help Page Settings (logged-in users)',
                    443:                               col2 => 'Value'},
                    444:                              {col1 => 'Helpdesk Roles',
                    445:                               col2 => 'Settings'},],
1.230     raeburn   446:                   print  => \&print_helpsettings,
                    447:                   modify => \&modify_helpsettings,
1.118     jms       448:                  },
1.121     raeburn   449:         'coursedefaults' => 
                    450:                  {text => 'Course/Community defaults',
                    451:                   help => 'Domain_Configuration_Course_Defaults',
1.139     raeburn   452:                   header => [{col1 => 'Defaults which can be overridden in each course by a CC',
                    453:                               col2 => 'Value',},
                    454:                              {col1 => 'Defaults which can be overridden for each course by a DC',
                    455:                               col2 => 'Value',},],
1.230     raeburn   456:                   print => \&print_coursedefaults,
                    457:                   modify => \&modify_coursedefaults,
1.121     raeburn   458:                  },
1.231     raeburn   459:         'selfenrollment' => 
                    460:                  {text   => 'Self-enrollment in Course/Community',
                    461:                   help   => 'Domain_Configuration_Selfenrollment',
                    462:                   header => [{col1 => 'Configuration Rights',
                    463:                               col2 => 'Configured by Course Personnel or Domain Coordinator?'},
                    464:                              {col1 => 'Defaults',
                    465:                               col2 => 'Value'},
                    466:                              {col1 => 'Self-enrollment validation (optional)',
                    467:                               col2 => 'Value'},],
                    468:                   print => \&print_selfenrollment,
                    469:                   modify => \&modify_selfenrollment,
                    470:                  },
1.120     raeburn   471:         'privacy' => 
                    472:                  {text   => 'User Privacy',
                    473:                   help   => 'Domain_Configuration_User_Privacy',
                    474:                   header => [{col1 => 'Setting',
                    475:                               col2 => 'Value',}],
1.230     raeburn   476:                   print => \&print_privacy,
                    477:                   modify => \&modify_privacy,
1.120     raeburn   478:                  },
1.141     raeburn   479:         'usersessions' =>
1.145     raeburn   480:                  {text  => 'User session hosting/offloading',
1.137     raeburn   481:                   help  => 'Domain_Configuration_User_Sessions',
1.145     raeburn   482:                   header => [{col1 => 'Domain server',
                    483:                               col2 => 'Servers to offload sessions to when busy'},
                    484:                              {col1 => 'Hosting of users from other domains',
1.137     raeburn   485:                               col2 => 'Rules'},
                    486:                              {col1 => "Hosting domain's own users elsewhere",
                    487:                               col2 => 'Rules'}],
1.230     raeburn   488:                   print => \&print_usersessions,
                    489:                   modify => \&modify_usersessions,
1.137     raeburn   490:                  },
1.279     raeburn   491:         'loadbalancing' =>
1.185     raeburn   492:                  {text  => 'Dedicated Load Balancer(s)',
1.150     raeburn   493:                   help  => 'Domain_Configuration_Load_Balancing',
1.171     raeburn   494:                   header => [{col1 => 'Balancers',
1.150     raeburn   495:                               col2 => 'Default destinations',
1.183     bisitz    496:                               col3 => 'User affiliation',
1.150     raeburn   497:                               col4 => 'Overrides'},
                    498:                             ],
1.230     raeburn   499:                   print => \&print_loadbalancing,
                    500:                   modify => \&modify_loadbalancing,
1.150     raeburn   501:                  },
1.279     raeburn   502:         'ltitools' => 
1.267     raeburn   503:                  {text => 'External Tools (LTI)',
1.296     raeburn   504:                   help => 'Domain_Configuration_LTI_Tools',
1.267     raeburn   505:                   header => [{col1 => 'Setting',
                    506:                               col2 => 'Value',}],
                    507:                   print => \&print_ltitools,
                    508:                   modify => \&modify_ltitools,
                    509:                  },
1.279     raeburn   510:         'ssl' =>
1.275     raeburn   511:                  {text  => 'LON-CAPA Network (SSL)',
                    512:                   help  => 'Domain_Configuration_Network_SSL',
                    513:                   header => [{col1 => 'Server',
                    514:                               col2 => 'Certificate Status'},
                    515:                              {col1 => 'Connections to other servers',
                    516:                               col2 => 'Rules'},
1.293     raeburn   517:                              {col1 => 'Connections from other servers',
                    518:                               col2 => 'Rules'},
1.275     raeburn   519:                              {col1 => "Replicating domain's published content",
                    520:                               col2 => 'Rules'}],
                    521:                   print => \&print_ssl,
                    522:                   modify => \&modify_ssl,
                    523:                  },
1.279     raeburn   524:         'trust' =>
                    525:                  {text   => 'Trust Settings',
                    526:                   help   => 'Domain_Configuration_Trust',
                    527:                   header => [{col1 => "Access to this domain's content by others",
                    528:                               col2 => 'Rules'},
                    529:                              {col1 => "Access to other domain's content by this domain",
                    530:                               col2 => 'Rules'},
                    531:                              {col1 => "Enrollment in this domain's courses by others",
                    532:                               col2 => 'Rules',},
                    533:                              {col1 => "Co-author roles in this domain for others",
                    534:                               col2 => 'Rules',},
                    535:                              {col1 => "Co-author roles for this domain's users elsewhere",
                    536:                               col2 => 'Rules',},
                    537:                              {col1 => "Domain roles in this domain assignable to others",
                    538:                               col2 => 'Rules'},
                    539:                              {col1 => "Course catalog for this domain displayed elsewhere",
                    540:                               col2 => 'Rules'},
                    541:                              {col1 => "Requests for creation of courses in this domain by others",
                    542:                               col2 => 'Rules'},
                    543:                              {col1 => "Users in other domains can send messages to this domain",
                    544:                               col2 => 'Rules'},],
                    545:                   print => \&print_trust,
                    546:                   modify => \&modify_trust,
                    547:                  },
1.3       raeburn   548:     );
1.110     raeburn   549:     if (keys(%servers) > 1) {
                    550:         $prefs{'login'}  = { text   => 'Log-in page options',
                    551:                              help   => 'Domain_Configuration_Login_Page',
                    552:                             header => [{col1 => 'Log-in Service',
                    553:                                         col2 => 'Server Setting',},
                    554:                                        {col1 => 'Log-in Page Items',
1.168     raeburn   555:                                         col2 => ''},
                    556:                                        {col1 => 'Log-in Help',
1.256     raeburn   557:                                         col2 => 'Value'},
                    558:                                        {col1 => 'Custom HTML in document head',
1.168     raeburn   559:                                         col2 => 'Value'}],
1.230     raeburn   560:                             print => \&print_login,
                    561:                             modify => \&modify_login,
1.110     raeburn   562:                            };
                    563:     }
1.174     foxr      564: 
1.6       raeburn   565:     my @roles = ('student','coordinator','author','admin');
1.30      raeburn   566:     my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3       raeburn   567:     &Apache::lonhtmlcommon::add_breadcrumb
1.30      raeburn   568:     ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133     raeburn   569:       text=>"Settings to display/modify"});
1.9       raeburn   570:     my $confname = $dom.'-domainconfig';
1.174     foxr      571: 
1.3       raeburn   572:     if ($phase eq 'process') {
1.212     raeburn   573:         my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
                    574:                                                               \%prefs,\%domconfig,$confname,\@roles);
1.224     raeburn   575:         if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.205     raeburn   576:             $r->rflush();
1.212     raeburn   577:             &devalidate_remote_domconfs($dom,$result);
1.205     raeburn   578:         }
1.30      raeburn   579:     } elsif ($phase eq 'display') {
1.192     raeburn   580:         my $js = &recaptcha_js().
1.236     raeburn   581:                  &toggle_display_js();
1.171     raeburn   582:         if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152     raeburn   583:             my ($othertitle,$usertypes,$types) =
                    584:                 &Apache::loncommon::sorted_inst_types($dom);
1.171     raeburn   585:             $js .= &lonbalance_targets_js($dom,$types,\%servers,
                    586:                                           $domconfig{'loadbalancing'}).
1.170     raeburn   587:                    &new_spares_js().
                    588:                    &common_domprefs_js().
                    589:                    &Apache::loncommon::javascript_array_indexof();
1.152     raeburn   590:         }
1.216     raeburn   591:         if (grep(/^requestcourses$/,@actions)) {
                    592:             my $javascript_validations;
                    593:             my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'}); 
                    594:             $js .= <<END;
                    595: <script type="text/javascript">
                    596: $javascript_validations
                    597: </script>
                    598: $coursebrowserjs
                    599: END
                    600:         }
1.305     raeburn   601:         if (grep(/^selfcreation$/,@actions)) {
                    602:             $js .= &selfcreate_javascript();
                    603:         }
1.286     raeburn   604:         if (grep(/^contacts$/,@actions)) {
                    605:             $js .= &contacts_javascript();
                    606:         }
1.150     raeburn   607:         &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1       raeburn   608:     } else {
1.180     raeburn   609: # check if domconfig user exists for the domain.
                    610:         my $servadm = $r->dir_config('lonAdmEMail');
                    611:         my ($configuserok,$author_ok,$switchserver) =
                    612:             &config_check($dom,$confname,$servadm);
                    613:         unless ($configuserok eq 'ok') {
1.181     raeburn   614:             &Apache::lonconfigsettings::print_header($r,$phase,$context);
                    615:             $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
1.210     raeburn   616:                           $confname).
1.181     raeburn   617:                       '<br />'
                    618:             );
1.180     raeburn   619:             if ($switchserver) {
1.181     raeburn   620:                 $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
                    621:                           '<br />'.
                    622:                           &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
                    623:                           '<br />'.
                    624:                           &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).
                    625:                           '<br />'.
                    626:                           &mt('To do that now, use the following link: [_1]',$switchserver)
                    627:                 );
                    628:             } else {
                    629:                 $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.').
                    630:                           '<br />'.
                    631:                           &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
                    632:                 );
1.180     raeburn   633:             }
                    634:             $r->print(&Apache::loncommon::end_page());
                    635:             return OK;
                    636:         }
1.21      raeburn   637:         if (keys(%domconfig) == 0) {
                    638:             my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29      raeburn   639:             my @ids=&Apache::lonnet::current_machine_ids();
                    640:             if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21      raeburn   641:                 my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41      raeburn   642:                 my @loginimages = ('img','logo','domlogo','login');
1.21      raeburn   643:                 my $custom_img_count = 0;
                    644:                 foreach my $img (@loginimages) {
                    645:                     if ($designhash{$dom.'.login.'.$img} ne '') {
                    646:                         $custom_img_count ++;
                    647:                     }
                    648:                 }
                    649:                 foreach my $role (@roles) {
                    650:                     if ($designhash{$dom.'.'.$role.'.img'} ne '') {
                    651:                         $custom_img_count ++;
                    652:                     }
                    653:                 }
                    654:                 if ($custom_img_count > 0) {
1.94      raeburn   655:                     &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21      raeburn   656:                     my $switch_server = &check_switchserver($dom,$confname);
1.29      raeburn   657:                     $r->print(
                    658:     &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
                    659:     &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
                    660:     &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 />'.
                    661:     &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
                    662:                     if ($switch_server) {
1.30      raeburn   663:                         $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29      raeburn   664:                     }
1.91      raeburn   665:                     $r->print(&Apache::loncommon::end_page());
1.21      raeburn   666:                     return OK;
                    667:                 }
                    668:             }
                    669:         }
1.91      raeburn   670:         &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3       raeburn   671:     }
                    672:     return OK;
                    673: }
                    674: 
                    675: sub process_changes {
1.205     raeburn   676:     my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92      raeburn   677:     my %domconfig;
                    678:     if (ref($values) eq 'HASH') {
                    679:         %domconfig = %{$values};
                    680:     }
1.3       raeburn   681:     my $output;
                    682:     if ($action eq 'login') {
1.205     raeburn   683:         $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6       raeburn   684:     } elsif ($action eq 'rolecolors') {
1.9       raeburn   685:         $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.205     raeburn   686:                                      $lastactref,%domconfig);
1.3       raeburn   687:     } elsif ($action eq 'quotas') {
1.216     raeburn   688:         $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3       raeburn   689:     } elsif ($action eq 'autoenroll') {
1.205     raeburn   690:         $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3       raeburn   691:     } elsif ($action eq 'autoupdate') {
                    692:         $output = &modify_autoupdate($dom,%domconfig);
1.125     raeburn   693:     } elsif ($action eq 'autocreate') {
                    694:         $output = &modify_autocreate($dom,%domconfig);
1.23      raeburn   695:     } elsif ($action eq 'directorysrch') {
1.295     raeburn   696:         $output = &modify_directorysrch($dom,$lastactref,%domconfig);
1.27      raeburn   697:     } elsif ($action eq 'usercreation') {
1.28      raeburn   698:         $output = &modify_usercreation($dom,%domconfig);
1.224     raeburn   699:     } elsif ($action eq 'selfcreation') {
1.305     raeburn   700:         $output = &modify_selfcreation($dom,$lastactref,%domconfig);
1.33      raeburn   701:     } elsif ($action eq 'usermodification') {
                    702:         $output = &modify_usermodification($dom,%domconfig);
1.28      raeburn   703:     } elsif ($action eq 'contacts') {
1.205     raeburn   704:         $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43      raeburn   705:     } elsif ($action eq 'defaults') {
1.212     raeburn   706:         $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46      raeburn   707:     } elsif ($action eq 'scantron') {
1.205     raeburn   708:         $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48      raeburn   709:     } elsif ($action eq 'coursecategories') {
1.239     raeburn   710:         $output = &modify_coursecategories($dom,$lastactref,%domconfig);
1.69      raeburn   711:     } elsif ($action eq 'serverstatuses') {
                    712:         $output = &modify_serverstatuses($dom,%domconfig);
1.86      raeburn   713:     } elsif ($action eq 'requestcourses') {
1.216     raeburn   714:         $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.163     raeburn   715:     } elsif ($action eq 'requestauthor') {
1.216     raeburn   716:         $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.118     jms       717:     } elsif ($action eq 'helpsettings') {
1.285     raeburn   718:         $output = &modify_helpsettings($r,$dom,$confname,$lastactref,%domconfig);
1.121     raeburn   719:     } elsif ($action eq 'coursedefaults') {
1.212     raeburn   720:         $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.231     raeburn   721:     } elsif ($action eq 'selfenrollment') {
                    722:         $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
1.137     raeburn   723:     } elsif ($action eq 'usersessions') {
1.212     raeburn   724:         $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150     raeburn   725:     } elsif ($action eq 'loadbalancing') {
                    726:         $output = &modify_loadbalancing($dom,%domconfig);
1.267     raeburn   727:     } elsif ($action eq 'ltitools') {
                    728:         $output = &modify_ltitools($r,$dom,$action,$lastactref,%domconfig);
1.275     raeburn   729:     } elsif ($action eq 'ssl') {
                    730:         $output = &modify_ssl($dom,$lastactref,%domconfig);
1.279     raeburn   731:     } elsif ($action eq 'trust') {
                    732:         $output = &modify_trust($dom,$lastactref,%domconfig);
1.3       raeburn   733:     }
                    734:     return $output;
                    735: }
                    736: 
                    737: sub print_config_box {
1.9       raeburn   738:     my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30      raeburn   739:     my $rowtotal = 0;
1.49      raeburn   740:     my $output;
                    741:     if ($action eq 'coursecategories') {
                    742:         $output = &coursecategories_javascript($settings);
1.236     raeburn   743:     } elsif ($action eq 'defaults') {
                    744:         $output = &defaults_javascript($settings); 
1.282     raeburn   745:     } elsif ($action eq 'helpsettings') {
                    746:         my (%privs,%levelscurrent);
                    747:         my %full=();
                    748:         my %levels=(
                    749:                      course => {},
                    750:                      domain => {},
                    751:                      system => {},
                    752:                    );
                    753:         my $context = 'domain';
                    754:         my $crstype = 'Course';
                    755:         my $formname = 'display';
                    756:         &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
                    757:         my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
                    758:         $output =
                    759:             &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,\%full, 
                    760:                                                       \@templateroles);
1.91      raeburn   761:     }
1.236     raeburn   762:     $output .=
1.30      raeburn   763:          '<table class="LC_nested_outer">
1.3       raeburn   764:           <tr>
1.306     raeburn   765:            <th class="LC_left_item LC_middle"><span class="LC_nobreak">'.
1.66      raeburn   766:            &mt($item->{text}).'&nbsp;'.
                    767:            &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
                    768:           '</tr>';
1.30      raeburn   769:     $rowtotal ++;
1.110     raeburn   770:     my $numheaders = 1;
                    771:     if (ref($item->{'header'}) eq 'ARRAY') {
                    772:         $numheaders = scalar(@{$item->{'header'}});
                    773:     }
                    774:     if ($numheaders > 1) {
1.64      raeburn   775:         my $colspan = '';
1.145     raeburn   776:         my $rightcolspan = '';
1.238     raeburn   777:         if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.277     raeburn   778:             ($action eq 'directorysrch') ||
1.256     raeburn   779:             (($action eq 'login') && ($numheaders < 4))) {
1.64      raeburn   780:             $colspan = ' colspan="2"';
                    781:         }
1.145     raeburn   782:         if ($action eq 'usersessions') {
                    783:             $rightcolspan = ' colspan="3"'; 
                    784:         }
1.30      raeburn   785:         $output .= '
1.3       raeburn   786:           <tr>
                    787:            <td>
                    788:             <table class="LC_nested">
                    789:              <tr class="LC_info_row">
1.59      bisitz    790:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145     raeburn   791:               <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30      raeburn   792:              </tr>';
1.69      raeburn   793:         $rowtotal ++;
1.230     raeburn   794:         if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.236     raeburn   795:             ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
1.277     raeburn   796:             ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'ssl') ||
1.286     raeburn   797:             ($action eq 'directorysrch') || ($action eq 'trust') || ($action eq 'helpsettings') ||
                    798:             ($action eq 'contacts')) {
1.230     raeburn   799:             $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.57      raeburn   800:         } elsif ($action eq 'coursecategories') {
1.230     raeburn   801:             $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.110     raeburn   802:         } elsif ($action eq 'login') {
1.256     raeburn   803:             if ($numheaders == 4) {
1.168     raeburn   804:                 $colspan = ' colspan="2"';
                    805:                 $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
                    806:             } else {
                    807:                 $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
                    808:             }
1.230     raeburn   809:         } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.163     raeburn   810:             $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122     jms       811:         } elsif ($action eq 'rolecolors') {
1.30      raeburn   812:             $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.6       raeburn   813:         }
1.30      raeburn   814:         $output .= '
1.6       raeburn   815:            </table>
                    816:           </td>
                    817:          </tr>
                    818:          <tr>
                    819:            <td>
                    820:             <table class="LC_nested">
                    821:              <tr class="LC_info_row">
1.230     raeburn   822:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59      bisitz    823:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30      raeburn   824:              </tr>';
                    825:             $rowtotal ++;
1.230     raeburn   826:         if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
                    827:             ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.275     raeburn   828:             ($action eq 'usersessions') || ($action eq 'coursecategories') || 
1.294     raeburn   829:             ($action eq 'trust') || ($action eq 'contacts') || ($action eq 'defaults')) {
1.238     raeburn   830:             if ($action eq 'coursecategories') {
                    831:                 $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
                    832:                 $colspan = ' colspan="2"';
1.279     raeburn   833:             } elsif ($action eq 'trust') {
                    834:                 $output .= $item->{'print'}->('shared',$dom,$settings,\$rowtotal);
1.238     raeburn   835:             } else {
                    836:                 $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
                    837:             }
1.279     raeburn   838:             if ($action eq 'trust') {
                    839:                 $output .= '
                    840:             </table>
                    841:           </td>
                    842:          </tr>';
                    843:                 my @trusthdrs = qw(2 3 4 5 6 7);
                    844:                 my @prefixes = qw(enroll othcoau coaurem domroles catalog reqcrs);
                    845:                 for (my $i=0; $i<@trusthdrs; $i++) {
                    846:                     $output .= '
                    847:          <tr>
                    848:            <td>
                    849:             <table class="LC_nested">
                    850:              <tr class="LC_info_row">
                    851:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col1'}).'</td>
                    852:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col2'}).'</td></tr>'.
                    853:                            $item->{'print'}->($prefixes[$i],$dom,$settings,\$rowtotal).'
                    854:             </table>
                    855:           </td>
                    856:          </tr>';
                    857:                 }
                    858:                 $output .= '
                    859:          <tr>
                    860:            <td>
                    861:             <table class="LC_nested">
                    862:              <tr class="LC_info_row">
                    863:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col1'}).'</td>
                    864:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col2'}).'</td></tr>'.
                    865:                            $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
                    866:             } else {
                    867:                 $output .= '
1.63      raeburn   868:            </table>
                    869:           </td>
                    870:          </tr>
                    871:          <tr>
                    872:            <td>
                    873:             <table class="LC_nested">
                    874:              <tr class="LC_info_row">
                    875:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.224     raeburn   876:               <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.238     raeburn   877:              </tr>'."\n";
1.279     raeburn   878:                 if ($action eq 'coursecategories') {
                    879:                     $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
                    880:                 } else {
                    881:                     $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
                    882:                 }
1.238     raeburn   883:             }
1.63      raeburn   884:             $rowtotal ++;
1.236     raeburn   885:         } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
1.282     raeburn   886:                  ($action eq 'defaults') || ($action eq 'directorysrch') ||
                    887:                  ($action eq 'helpsettings')) {
1.230     raeburn   888:             $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.293     raeburn   889:         } elsif ($action eq 'ssl') {
                    890:             $output .= $item->{'print'}->('connto',$dom,$settings,\$rowtotal).'
                    891:             </table>
                    892:           </td>
                    893:          </tr>
                    894:          <tr>
                    895:            <td>
                    896:             <table class="LC_nested">
                    897:              <tr class="LC_info_row">
                    898:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
                    899:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
                    900:                            $item->{'print'}->('connfrom',$dom,$settings,\$rowtotal).'
                    901:             </table>
                    902:           </td>
                    903:          </tr>
                    904:          <tr>
                    905:            <td>
                    906:             <table class="LC_nested">
                    907:              <tr class="LC_info_row">
                    908:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
                    909:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td></tr>'.
                    910:                            $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.110     raeburn   911:         } elsif ($action eq 'login') {
1.256     raeburn   912:             if ($numheaders == 4) {
1.168     raeburn   913:                 $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
                    914:            </table>
                    915:           </td>
                    916:          </tr>
                    917:          <tr>
                    918:            <td>
                    919:             <table class="LC_nested">
                    920:              <tr class="LC_info_row">
                    921:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.216     raeburn   922:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.168     raeburn   923:                        &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
                    924:                 $rowtotal ++;
                    925:             } else {
                    926:                 $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
                    927:             }
1.256     raeburn   928:             $output .= '
                    929:            </table>
                    930:           </td>
                    931:          </tr>
                    932:          <tr>
                    933:            <td>
                    934:             <table class="LC_nested">
                    935:              <tr class="LC_info_row">';
                    936:             if ($numheaders == 4) {
                    937:                 $output .= '
                    938:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
                    939:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
                    940:              </tr>';
                    941:             } else {
                    942:                 $output .= '
                    943:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
                    944:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
                    945:              </tr>';
                    946:             }
                    947:             $rowtotal ++;
                    948:             $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal);
1.102     raeburn   949:         } elsif ($action eq 'requestcourses') {
1.247     raeburn   950:             $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
                    951:             $rowtotal ++;
                    952:             $output .= &print_studentcode($settings,\$rowtotal).'
1.216     raeburn   953:            </table>
                    954:           </td>
                    955:          </tr>
                    956:          <tr>
                    957:            <td>
                    958:             <table class="LC_nested">
                    959:              <tr class="LC_info_row">
                    960:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
                    961:               <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.242     raeburn   962:                        &textbookcourses_javascript($settings).
                    963:                        &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
                    964:             </table>
                    965:            </td>
                    966:           </tr>
                    967:          <tr>
                    968:            <td>
                    969:             <table class="LC_nested">
                    970:              <tr class="LC_info_row">
                    971:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
                    972:               <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
                    973:                        &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.235     raeburn   974:             </table>
                    975:            </td>
                    976:           </tr>
                    977:           <tr>
                    978:            <td>
                    979:             <table class="LC_nested">
                    980:              <tr class="LC_info_row">
1.306     raeburn   981:               <td class="LC_left_item"'.$colspan.' style="vertical-align: top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
                    982:               <td class="LC_right_item" style="vertical-align: top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.235     raeburn   983:              </tr>'.
                    984:             &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.163     raeburn   985:         } elsif ($action eq 'requestauthor') {
                    986:             $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.247     raeburn   987:             $rowtotal ++;
1.122     jms       988:         } elsif ($action eq 'rolecolors') {
1.30      raeburn   989:             $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6       raeburn   990:            </table>
                    991:           </td>
                    992:          </tr>
                    993:          <tr>
                    994:            <td>
                    995:             <table class="LC_nested">
                    996:              <tr class="LC_info_row">
1.306     raeburn   997:               <td class="LC_left_item"'.$colspan.' style="vertical-align: top">'.
1.69      raeburn   998:                &mt($item->{'header'}->[2]->{'col1'}).'</td>
1.306     raeburn   999:               <td class="LC_right_item" style="vertical-align: top">'.
1.69      raeburn  1000:                &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3       raeburn  1001:              </tr>'.
1.30      raeburn  1002:             &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3       raeburn  1003:            </table>
                   1004:           </td>
                   1005:          </tr>
                   1006:          <tr>
                   1007:            <td>
                   1008:             <table class="LC_nested">
                   1009:              <tr class="LC_info_row">
1.59      bisitz   1010:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
                   1011:               <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3       raeburn  1012:              </tr>'.
1.30      raeburn  1013:             &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
                   1014:             $rowtotal += 2;
1.6       raeburn  1015:         }
1.3       raeburn  1016:     } else {
1.30      raeburn  1017:         $output .= '
1.3       raeburn  1018:           <tr>
                   1019:            <td>
                   1020:             <table class="LC_nested">
1.30      raeburn  1021:              <tr class="LC_info_row">';
1.277     raeburn  1022:         if ($action eq 'login') {
1.30      raeburn  1023:             $output .= '  
1.59      bisitz   1024:               <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69      raeburn  1025:         } elsif ($action eq 'serverstatuses') {
                   1026:             $output .= '
1.306     raeburn  1027:               <td class="LC_left_item" style="vertical-align: top">'.&mt($item->{'header'}->[0]->{'col1'}).
1.69      raeburn  1028:               '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
                   1029: 
1.6       raeburn  1030:         } else {
1.30      raeburn  1031:             $output .= '
1.306     raeburn  1032:               <td class="LC_left_item" style="vertical-align: top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69      raeburn  1033:         }
1.72      raeburn  1034:         if (defined($item->{'header'}->[0]->{'col3'})) {
1.306     raeburn  1035:             $output .= '<td class="LC_left_item" style="vertical-align: top">'.
1.72      raeburn  1036:                        &mt($item->{'header'}->[0]->{'col2'});
                   1037:             if ($action eq 'serverstatuses') {
                   1038:                 $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
                   1039:             } 
1.69      raeburn  1040:         } else {
1.306     raeburn  1041:             $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.69      raeburn  1042:                        &mt($item->{'header'}->[0]->{'col2'});
                   1043:         }
                   1044:         $output .= '</td>';
                   1045:         if ($item->{'header'}->[0]->{'col3'}) {
1.150     raeburn  1046:             if (defined($item->{'header'}->[0]->{'col4'})) {
1.306     raeburn  1047:                 $output .= '<td class="LC_left_item" style="vertical-align: top">'.
1.150     raeburn  1048:                             &mt($item->{'header'}->[0]->{'col3'});
                   1049:             } else {
1.306     raeburn  1050:                 $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.150     raeburn  1051:                            &mt($item->{'header'}->[0]->{'col3'});
                   1052:             }
1.69      raeburn  1053:             if ($action eq 'serverstatuses') {
                   1054:                 $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
                   1055:             }
                   1056:             $output .= '</td>';
1.6       raeburn  1057:         }
1.150     raeburn  1058:         if ($item->{'header'}->[0]->{'col4'}) {
1.306     raeburn  1059:             $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.150     raeburn  1060:                        &mt($item->{'header'}->[0]->{'col4'});
                   1061:         }
1.69      raeburn  1062:         $output .= '</tr>';
1.48      raeburn  1063:         $rowtotal ++;
1.168     raeburn  1064:         if ($action eq 'quotas') {
1.86      raeburn  1065:             $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.277     raeburn  1066:         } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') || 
1.286     raeburn  1067:                  ($action eq 'serverstatuses') || ($action eq 'loadbalancing') || 
                   1068:                  ($action eq 'ltitools')) {
1.230     raeburn  1069:             $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.46      raeburn  1070:         } elsif ($action eq 'scantron') {
                   1071:             $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
1.121     raeburn  1072:         }
1.3       raeburn  1073:     }
1.30      raeburn  1074:     $output .= '
1.3       raeburn  1075:    </table>
                   1076:   </td>
                   1077:  </tr>
1.30      raeburn  1078: </table><br />';
                   1079:     return ($output,$rowtotal);
1.1       raeburn  1080: }
                   1081: 
1.3       raeburn  1082: sub print_login {
1.168     raeburn  1083:     my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110     raeburn  1084:     my ($css_class,$datatable);
1.6       raeburn  1085:     my %choices = &login_choices();
1.110     raeburn  1086: 
1.168     raeburn  1087:     if ($caller eq 'service') {
1.149     raeburn  1088:         my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110     raeburn  1089:         my $choice = $choices{'disallowlogin'};
                   1090:         $css_class = ' class="LC_odd_row"';
1.128     raeburn  1091:         $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.306     raeburn  1092:                       '<td style="text-align: right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128     raeburn  1093:                       '<th>'.$choices{'server'}.'</th>'.
                   1094:                       '<th>'.$choices{'serverpath'}.'</th>'.
                   1095:                       '<th>'.$choices{'custompath'}.'</th>'.
                   1096:                       '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110     raeburn  1097:         my %disallowed;
                   1098:         if (ref($settings) eq 'HASH') {
                   1099:             if (ref($settings->{'loginvia'}) eq 'HASH') {
                   1100:                %disallowed = %{$settings->{'loginvia'}};
                   1101:             }
                   1102:         }
                   1103:         foreach my $lonhost (sort(keys(%servers))) {
                   1104:             my $direct = 'selected="selected"';
1.128     raeburn  1105:             if (ref($disallowed{$lonhost}) eq 'HASH') {
                   1106:                 if ($disallowed{$lonhost}{'server'} ne '') {
                   1107:                     $direct = '';
                   1108:                 }
1.110     raeburn  1109:             }
1.115     raeburn  1110:             $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128     raeburn  1111:                           '<td><select name="'.$lonhost.'_server">'.
1.110     raeburn  1112:                           '<option value=""'.$direct.'>'.$choices{'directlogin'}.
                   1113:                           '</option>';
1.184     raeburn  1114:             foreach my $hostid (sort(keys(%servers))) {
1.115     raeburn  1115:                 next if ($servers{$hostid} eq $servers{$lonhost});
1.110     raeburn  1116:                 my $selected = '';
1.128     raeburn  1117:                 if (ref($disallowed{$lonhost}) eq 'HASH') {
                   1118:                     if ($hostid eq $disallowed{$lonhost}{'server'}) {
                   1119:                         $selected = 'selected="selected"';
                   1120:                     }
1.110     raeburn  1121:                 }
                   1122:                 $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
                   1123:                               $servers{$hostid}.'</option>';
                   1124:             }
1.128     raeburn  1125:             $datatable .= '</select></td>'.
                   1126:                           '<td><select name="'.$lonhost.'_serverpath">';
                   1127:             foreach my $path ('','/','/adm/login','/adm/roles','custom') {
                   1128:                 my $pathname = $path;
                   1129:                 if ($path eq 'custom') {
                   1130:                     $pathname = &mt('Custom Path').' ->';
                   1131:                 }
                   1132:                 my $selected = '';
                   1133:                 if (ref($disallowed{$lonhost}) eq 'HASH') {
                   1134:                     if ($path eq $disallowed{$lonhost}{'serverpath'}) {
                   1135:                         $selected = 'selected="selected"';
                   1136:                     }
                   1137:                 } elsif ($path eq '') {
                   1138:                     $selected = 'selected="selected"';
                   1139:                 }
                   1140:                 $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
                   1141:             }
                   1142:             $datatable .= '</select></td>';
                   1143:             my ($custom,$exempt);
                   1144:             if (ref($disallowed{$lonhost}) eq 'HASH') {
                   1145:                 $custom = $disallowed{$lonhost}{'custompath'};
                   1146:                 $exempt = $disallowed{$lonhost}{'exempt'};
                   1147:             }
                   1148:             $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
                   1149:                           '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
                   1150:                           '</tr>';
1.110     raeburn  1151:         }
                   1152:         $datatable .= '</table></td></tr>';
                   1153:         return $datatable;
1.168     raeburn  1154:     } elsif ($caller eq 'page') {
                   1155:         my %defaultchecked = ( 
                   1156:                                'coursecatalog' => 'on',
1.188     raeburn  1157:                                'helpdesk'      => 'on',
1.168     raeburn  1158:                                'adminmail'     => 'off',
                   1159:                                'newuser'       => 'off',
                   1160:                              );
1.188     raeburn  1161:         my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.168     raeburn  1162:         my (%checkedon,%checkedoff);
1.42      raeburn  1163:         foreach my $item (@toggles) {
1.168     raeburn  1164:             if ($defaultchecked{$item} eq 'on') { 
                   1165:                 $checkedon{$item} = ' checked="checked" ';
1.42      raeburn  1166:                 $checkedoff{$item} = ' ';
1.168     raeburn  1167:             } elsif ($defaultchecked{$item} eq 'off') {
                   1168:                 $checkedoff{$item} = ' checked="checked" ';
1.42      raeburn  1169:                 $checkedon{$item} = ' ';
                   1170:             }
1.1       raeburn  1171:         }
1.168     raeburn  1172:         my @images = ('img','logo','domlogo','login');
                   1173:         my @logintext = ('textcol','bgcol');
                   1174:         my @bgs = ('pgbg','mainbg','sidebg');
                   1175:         my @links = ('link','alink','vlink');
                   1176:         my %designhash = &Apache::loncommon::get_domainconf($dom);
                   1177:         my %defaultdesign = %Apache::loncommon::defaultdesign;
                   1178:         my (%is_custom,%designs);
                   1179:         my %defaults = (
                   1180:                        font => $defaultdesign{'login.font'},
                   1181:                        );
1.6       raeburn  1182:         foreach my $item (@images) {
1.168     raeburn  1183:             $defaults{$item} = $defaultdesign{'login.'.$item};
                   1184:             $defaults{'showlogo'}{$item} = 1;
                   1185:         }
                   1186:         foreach my $item (@bgs) {
                   1187:             $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6       raeburn  1188:         }
1.41      raeburn  1189:         foreach my $item (@logintext) {
1.168     raeburn  1190:             $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41      raeburn  1191:         }
1.168     raeburn  1192:         foreach my $item (@links) {
                   1193:             $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6       raeburn  1194:         }
1.168     raeburn  1195:         if (ref($settings) eq 'HASH') {
                   1196:             foreach my $item (@toggles) {
                   1197:                 if ($settings->{$item} eq '1') {
                   1198:                     $checkedon{$item} =  ' checked="checked" ';
                   1199:                     $checkedoff{$item} = ' ';
                   1200:                 } elsif ($settings->{$item} eq '0') {
                   1201:                     $checkedoff{$item} =  ' checked="checked" ';
                   1202:                     $checkedon{$item} = ' ';
                   1203:                 }
                   1204:             }
                   1205:             foreach my $item (@images) {
                   1206:                 if (defined($settings->{$item})) {
                   1207:                     $designs{$item} = $settings->{$item};
                   1208:                     $is_custom{$item} = 1;
                   1209:                 }
                   1210:                 if (defined($settings->{'showlogo'}{$item})) {
                   1211:                     $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
                   1212:                 }
                   1213:             }
                   1214:             foreach my $item (@logintext) {
                   1215:                 if ($settings->{$item} ne '') {
                   1216:                     $designs{'logintext'}{$item} = $settings->{$item};
                   1217:                     $is_custom{$item} = 1;
                   1218:                 }
                   1219:             }
                   1220:             if ($settings->{'font'} ne '') {
                   1221:                 $designs{'font'} = $settings->{'font'};
                   1222:                 $is_custom{'font'} = 1;
                   1223:             }
                   1224:             foreach my $item (@bgs) {
                   1225:                 if ($settings->{$item} ne '') {
                   1226:                     $designs{'bgs'}{$item} = $settings->{$item};
                   1227:                     $is_custom{$item} = 1;
                   1228:                 }
                   1229:             }
                   1230:             foreach my $item (@links) {
                   1231:                 if ($settings->{$item} ne '') {
                   1232:                     $designs{'links'}{$item} = $settings->{$item};
                   1233:                     $is_custom{$item} = 1;
                   1234:                 }
                   1235:             }
                   1236:         } else {
                   1237:             if ($designhash{$dom.'.login.font'} ne '') {
                   1238:                 $designs{'font'} = $designhash{$dom.'.login.font'};
                   1239:                 $is_custom{'font'} = 1;
                   1240:             }
                   1241:             foreach my $item (@images) {
                   1242:                 if ($designhash{$dom.'.login.'.$item} ne '') {
                   1243:                     $designs{$item} = $designhash{$dom.'.login.'.$item};
                   1244:                     $is_custom{$item} = 1;
                   1245:                 }
                   1246:             }
                   1247:             foreach my $item (@bgs) {
                   1248:                 if ($designhash{$dom.'.login.'.$item} ne '') {
                   1249:                     $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
                   1250:                     $is_custom{$item} = 1;
                   1251:                 }
1.6       raeburn  1252:             }
1.168     raeburn  1253:             foreach my $item (@links) {
                   1254:                 if ($designhash{$dom.'.login.'.$item} ne '') {
                   1255:                     $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
                   1256:                     $is_custom{$item} = 1;
                   1257:                 }
1.6       raeburn  1258:             }
                   1259:         }
1.168     raeburn  1260:         my %alt_text = &Apache::lonlocal::texthash  ( img => 'Log-in banner',
                   1261:                                                       logo => 'Institution Logo',
                   1262:                                                       domlogo => 'Domain Logo',
                   1263:                                                       login => 'Login box');
                   1264:         my $itemcount = 1;
                   1265:         foreach my $item (@toggles) {
                   1266:             $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   1267:             $datatable .=  
                   1268:                 '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
                   1269:                 '</td><td>'.
                   1270:                 '<span class="LC_nobreak"><label><input type="radio" name="'.
                   1271:                 $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
                   1272:                 '</label>&nbsp;<label><input type="radio" name="'.$item.'"'.
                   1273:                 $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
                   1274:                 '</tr>';
                   1275:             $itemcount ++;
1.6       raeburn  1276:         }
1.168     raeburn  1277:         $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
                   1278:         $datatable .= '</tr></table></td></tr>';
                   1279:     } elsif ($caller eq 'help') {
                   1280:         my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
                   1281:         my $switchserver = &check_switchserver($dom,$confname);
                   1282:         my $itemcount = 1;
                   1283:         $defaulturl = '/adm/loginproblems.html';
                   1284:         $defaulttype = 'default';
                   1285:         %lt = &Apache::lonlocal::texthash (
                   1286:                      del     => 'Delete?',
                   1287:                      rep     => 'Replace:',
                   1288:                      upl     => 'Upload:',
                   1289:                      default => 'Default',
                   1290:                      custom  => 'Custom',
                   1291:                                              );
                   1292:         %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
                   1293:         my @currlangs;
                   1294:         if (ref($settings) eq 'HASH') {
                   1295:             if (ref($settings->{'helpurl'}) eq 'HASH') {
                   1296:                 foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
                   1297:                     next if ($settings->{'helpurl'}{$key} eq '');
                   1298:                     $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
                   1299:                     $type{$key} = 'custom';
                   1300:                     unless ($key eq 'nolang') {
                   1301:                         push(@currlangs,$key);
                   1302:                     }
                   1303:                 }
                   1304:             } elsif ($settings->{'helpurl'} ne '') {
                   1305:                 $type{'nolang'} = 'custom';
                   1306:                 $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8       raeburn  1307:             }
                   1308:         }
1.168     raeburn  1309:         foreach my $lang ('nolang',sort(@currlangs)) {
                   1310:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   1311:             $datatable .= '<tr'.$css_class.'>';
                   1312:             if ($url{$lang} eq '') {
                   1313:                 $url{$lang} = $defaulturl;
                   1314:             }
                   1315:             if ($type{$lang} eq '') {
                   1316:                 $type{$lang} = $defaulttype;
                   1317:             }
                   1318:             $datatable .= '<td colspan="2"><span class="LC_nobreak">';
                   1319:             if ($lang eq 'nolang') {
                   1320:                 $datatable .= &mt('Log-in help page if no specific language file: [_1]',
                   1321:                                   &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
                   1322:             } else {
                   1323:                 $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
                   1324:                                   $langchoices{$lang},
                   1325:                                   &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
                   1326:             }
                   1327:             $datatable .= '</span></td>'."\n".
                   1328:                           '<td class="LC_left_item">';
                   1329:             if ($type{$lang} eq 'custom') {
                   1330:                 $datatable .= '<span class="LC_nobreak"><label>'.
                   1331:                               '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
                   1332:                               $lt{'del'}.'</label>&nbsp;'.$lt{'rep'}.'</span>';
                   1333:             } else {
                   1334:                 $datatable .= $lt{'upl'};
                   1335:             }
                   1336:             $datatable .='<br />';
                   1337:             if ($switchserver) {
                   1338:                 $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   1339:             } else {
                   1340:                 $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6       raeburn  1341:             }
1.168     raeburn  1342:             $datatable .= '</td></tr>';
                   1343:             $itemcount ++;
1.6       raeburn  1344:         }
1.168     raeburn  1345:         my @addlangs;
                   1346:         foreach my $lang (sort(keys(%langchoices))) {
                   1347:             next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
                   1348:             push(@addlangs,$lang);
                   1349:         }
                   1350:         if (@addlangs > 0) {
                   1351:             my %toadd;
                   1352:             map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
                   1353:             $toadd{''} = &mt('Select');
                   1354:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   1355:             $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
                   1356:                           &mt('Add log-in help page for a specific language:').'&nbsp;'.
                   1357:                           &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
                   1358:                           '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
                   1359:             if ($switchserver) {
                   1360:                 $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   1361:             } else {
                   1362:                 $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6       raeburn  1363:             }
1.168     raeburn  1364:             $datatable .= '</td></tr>';
1.169     raeburn  1365:             $itemcount ++;
1.6       raeburn  1366:         }
1.169     raeburn  1367:         $datatable .= &captcha_choice('login',$settings,$itemcount);
1.256     raeburn  1368:     } elsif ($caller eq 'headtag') {
                   1369:         my %domservers = &Apache::lonnet::get_servers($dom);
                   1370:         my $choice = $choices{'headtag'};
                   1371:         $css_class = ' class="LC_odd_row"';
                   1372:         $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
1.306     raeburn  1373:                       '<td style="text-align: left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.256     raeburn  1374:                       '<th>'.$choices{'current'}.'</th>'.
                   1375:                       '<th>'.$choices{'action'}.'</th>'.
                   1376:                       '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
                   1377:         my (%currurls,%currexempt);
                   1378:         if (ref($settings) eq 'HASH') {
                   1379:             if (ref($settings->{'headtag'}) eq 'HASH') {
                   1380:                 foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
                   1381:                     if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
                   1382:                         $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
                   1383:                         $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
                   1384:                     }
                   1385:                 }
                   1386:             }
                   1387:         }
                   1388:         my %lt = &Apache::lonlocal::texthash(
                   1389:                                                del  => 'Delete?',
                   1390:                                                rep  => 'Replace:',
                   1391:                                                upl  => 'Upload:',
                   1392:                                                curr => 'View contents',
                   1393:                                                none => 'None',
                   1394:         );
                   1395:         my $switchserver = &check_switchserver($dom,$confname);
                   1396:         foreach my $lonhost (sort(keys(%domservers))) {
                   1397:             my $exempt = &check_exempt_addresses($currexempt{$lonhost});
                   1398:             $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
                   1399:             if ($currurls{$lonhost}) {
                   1400:                 $datatable .= '<td class="LC_right_item"><a href="'.
                   1401:                               "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
                   1402:                               'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
                   1403:                               '">'.$lt{'curr'}.'</a></td>'.
                   1404:                               '<td><span class="LC_nobreak"><label>'.
                   1405:                               '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
                   1406:                               $lt{'del'}.'</label>&nbsp;'.$lt{'rep'}.'</span>';
                   1407:             } else {
                   1408:                 $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
                   1409:             }
                   1410:             $datatable .='<br />';
                   1411:             if ($switchserver) {
                   1412:                 $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   1413:             } else {
                   1414:                 $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
                   1415:             }
                   1416:             $datatable .= '</td><td><input type="textbox" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
                   1417:         }
                   1418:         $datatable .= '</table></td></tr>';
1.1       raeburn  1419:     }
1.6       raeburn  1420:     return $datatable;
                   1421: }
                   1422: 
                   1423: sub login_choices {
                   1424:     my %choices =
                   1425:         &Apache::lonlocal::texthash (
1.116     bisitz   1426:             coursecatalog => 'Display Course/Community Catalog link?',
1.110     raeburn  1427:             adminmail     => "Display Administrator's E-mail Address?",
1.188     raeburn  1428:             helpdesk      => 'Display "Contact Helpdesk" link',
1.110     raeburn  1429:             disallowlogin => "Login page requests redirected",
                   1430:             hostid        => "Server",
1.128     raeburn  1431:             server        => "Redirect to:",
                   1432:             serverpath    => "Path",
                   1433:             custompath    => "Custom", 
                   1434:             exempt        => "Exempt IP(s)",
1.110     raeburn  1435:             directlogin   => "No redirect",
                   1436:             newuser       => "Link to create a user account",
                   1437:             img           => "Header",
                   1438:             logo          => "Main Logo",
                   1439:             domlogo       => "Domain Logo",
                   1440:             login         => "Log-in Header", 
                   1441:             textcol       => "Text color",
                   1442:             bgcol         => "Box color",
                   1443:             bgs           => "Background colors",
                   1444:             links         => "Link colors",
                   1445:             font          => "Font color",
                   1446:             pgbg          => "Header",
                   1447:             mainbg        => "Page",
                   1448:             sidebg        => "Login box",
                   1449:             link          => "Link",
                   1450:             alink         => "Active link",
                   1451:             vlink         => "Visited link",
1.256     raeburn  1452:             headtag       => "Custom markup",
                   1453:             action        => "Action",
                   1454:             current       => "Current",
1.6       raeburn  1455:         );
                   1456:     return %choices;
                   1457: }
                   1458: 
                   1459: sub print_rolecolors {
1.30      raeburn  1460:     my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6       raeburn  1461:     my %choices = &color_font_choices();
                   1462:     my @bgs = ('pgbg','tabbg','sidebg');
                   1463:     my @links = ('link','alink','vlink');
                   1464:     my @images = ('img');
                   1465:     my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7       albertel 1466:     my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6       raeburn  1467:     my %defaultdesign = %Apache::loncommon::defaultdesign;
                   1468:     my (%is_custom,%designs);
1.200     raeburn  1469:     my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6       raeburn  1470:     if (ref($settings) eq 'HASH') {
                   1471:         if (ref($settings->{$role}) eq 'HASH') {
                   1472:             if ($settings->{$role}->{'img'} ne '') {
                   1473:                 $designs{'img'} = $settings->{$role}->{'img'};
                   1474:                 $is_custom{'img'} = 1;
                   1475:             }
                   1476:             if ($settings->{$role}->{'font'} ne '') {
                   1477:                 $designs{'font'} = $settings->{$role}->{'font'};
                   1478:                 $is_custom{'font'} = 1;
                   1479:             }
1.97      tempelho 1480:             if ($settings->{$role}->{'fontmenu'} ne '') {
                   1481:                 $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
                   1482:                 $is_custom{'fontmenu'} = 1;
                   1483:             }
1.6       raeburn  1484:             foreach my $item (@bgs) {
                   1485:                 if ($settings->{$role}->{$item} ne '') {
                   1486:                     $designs{'bgs'}{$item} = $settings->{$role}->{$item};
                   1487:                     $is_custom{$item} = 1;
                   1488:                 }
                   1489:             }
                   1490:             foreach my $item (@links) {
                   1491:                 if ($settings->{$role}->{$item} ne '') {
                   1492:                     $designs{'links'}{$item} = $settings->{$role}->{$item};
                   1493:                     $is_custom{$item} = 1;
                   1494:                 }
                   1495:             }
                   1496:         }
                   1497:     } else {
                   1498:         if ($designhash{$dom.'.'.$role.'.img'} ne '') {
                   1499:             $designs{img} = $designhash{$dom.'.'.$role.'.img'};
                   1500:             $is_custom{'img'} = 1;
                   1501:         }
1.97      tempelho 1502:         if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
                   1503:             $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
                   1504:             $is_custom{'fontmenu'} = 1; 
                   1505:         }
1.6       raeburn  1506:         if ($designhash{$dom.'.'.$role.'.font'} ne '') {
                   1507:             $designs{font} = $designhash{$dom.'.'.$role.'.font'};
                   1508:             $is_custom{'font'} = 1;
                   1509:         }
                   1510:         foreach my $item (@bgs) {
                   1511:             if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
                   1512:                 $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
                   1513:                 $is_custom{$item} = 1;
                   1514:             
                   1515:             }
                   1516:         }
                   1517:         foreach my $item (@links) {
                   1518:             if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
                   1519:                 $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
                   1520:                 $is_custom{$item} = 1;
                   1521:             }
                   1522:         }
                   1523:     }
                   1524:     my $itemcount = 1;
1.30      raeburn  1525:     my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6       raeburn  1526:     $datatable .= '</tr></table></td></tr>';
                   1527:     return $datatable;
                   1528: }
                   1529: 
1.200     raeburn  1530: sub role_defaults {
                   1531:     my ($role,$bgs,$links,$images,$logintext) = @_;
1.202     raeburn  1532:     my %defaults;
                   1533:     unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1.200     raeburn  1534:         return %defaults;
                   1535:     }
                   1536:     my %defaultdesign = %Apache::loncommon::defaultdesign;
                   1537:     if ($role eq 'login') {
                   1538:         %defaults = (
                   1539:                        font => $defaultdesign{$role.'.font'},
                   1540:                     );
                   1541:         if (ref($logintext) eq 'ARRAY') {
                   1542:             foreach my $item (@{$logintext}) {
                   1543:                 $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
                   1544:             }
                   1545:         }
                   1546:         foreach my $item (@{$images}) {
                   1547:             $defaults{'showlogo'}{$item} = 1;
                   1548:         }
                   1549:     } else {
                   1550:         %defaults = (
                   1551:                        img => $defaultdesign{$role.'.img'},
                   1552:                        font => $defaultdesign{$role.'.font'},
                   1553:                        fontmenu => $defaultdesign{$role.'.fontmenu'},
                   1554:                     );
                   1555:     }
                   1556:     foreach my $item (@{$bgs}) {
                   1557:         $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
                   1558:     }
                   1559:     foreach my $item (@{$links}) {
                   1560:         $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
                   1561:     }
                   1562:     foreach my $item (@{$images}) {
                   1563:         $defaults{$item} = $defaultdesign{$role.'.'.$item};
                   1564:     }
                   1565:     return %defaults;
                   1566: }
                   1567: 
1.6       raeburn  1568: sub display_color_options {
1.9       raeburn  1569:     my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135     bisitz   1570:         $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159     raeburn  1571:     my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6       raeburn  1572:     my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.176     raeburn  1573:     my $datatable = '<tr'.$css_class.'>'.
1.6       raeburn  1574:         '<td>'.$choices->{'font'}.'</td>';
                   1575:     if (!$is_custom->{'font'}) {
1.30      raeburn  1576:         $datatable .=  '<td>'.&mt('Default in use:').'&nbsp;<span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6       raeburn  1577:     } else {
                   1578:         $datatable .= '<td>&nbsp;</td>';
                   1579:     }
1.174     foxr     1580:     my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
                   1581: 
1.8       raeburn  1582:     $datatable .= '<td><span class="LC_nobreak">'.
1.174     foxr     1583:                   '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1.202     raeburn  1584:                   ' value="'.$current_color.'" />&nbsp;'.
1.174     foxr     1585:                   '&nbsp;</td></tr>';
1.107     raeburn  1586:     unless ($role eq 'login') { 
                   1587:         $datatable .= '<tr'.$css_class.'>'.
                   1588:                       '<td>'.$choices->{'fontmenu'}.'</td>';
                   1589:         if (!$is_custom->{'fontmenu'}) {
                   1590:             $datatable .=  '<td>'.&mt('Default in use:').'&nbsp;<span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
                   1591:         } else {
                   1592:             $datatable .= '<td>&nbsp;</td>';
                   1593:         }
1.202     raeburn  1594: 	$current_color = $designs->{'fontmenu'} ?
1.174     foxr     1595: 	    $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107     raeburn  1596:         $datatable .= '<td><span class="LC_nobreak">'.
1.174     foxr     1597:                       '<input class="colorchooser" type="text" size="10" name="'
                   1598: 		      .$role.'_fontmenu"'.
                   1599:                       ' value="'.$current_color.'" />&nbsp;'.
                   1600:                       '&nbsp;</td></tr>';
1.97      tempelho 1601:     }
1.9       raeburn  1602:     my $switchserver = &check_switchserver($dom,$confname);
1.6       raeburn  1603:     foreach my $img (@{$images}) {
1.18      albertel 1604: 	$itemcount ++;
1.6       raeburn  1605:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8       raeburn  1606:         $datatable .= '<tr'.$css_class.'>'.
1.70      raeburn  1607:                       '<td>'.$choices->{$img};
1.41      raeburn  1608:         my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70      raeburn  1609:         if ($role eq 'login') {
                   1610:             if ($img eq 'login') {
                   1611:                 $login_hdr_pick =
1.135     bisitz   1612:                     &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70      raeburn  1613:                 $logincolors =
                   1614:                     &login_text_colors($img,$role,$logintext,$phase,$choices,
1.201     raeburn  1615:                                        $designs,$defaults);
1.70      raeburn  1616:             } elsif ($img ne 'domlogo') {
                   1617:                 $datatable.= &logo_display_options($img,$defaults,$designs);
                   1618:             }
                   1619:         }
                   1620:         $datatable .= '</td>';
1.6       raeburn  1621:         if ($designs->{$img} ne '') {
                   1622:             $imgfile = $designs->{$img};
1.18      albertel 1623: 	    $img_import = ($imgfile =~ m{^/adm/});
1.6       raeburn  1624:         } else {
                   1625:             $imgfile = $defaults->{$img};
                   1626:         }
                   1627:         if ($imgfile) {
1.9       raeburn  1628:             my ($showfile,$fullsize);
                   1629:             if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6       raeburn  1630:                 my $urldir = $1;
                   1631:                 my $filename = $2;
                   1632:                 my @info = &Apache::lonnet::stat_file($designs->{$img});
                   1633:                 if (@info) {
                   1634:                     my $thumbfile = 'tn-'.$filename;
                   1635:                     my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
                   1636:                     if (@thumb) {
                   1637:                         $showfile = $urldir.'/'.$thumbfile;
                   1638:                     } else {
                   1639:                         $showfile = $imgfile;
                   1640:                     }
                   1641:                 } else {
                   1642:                     $showfile = '';
                   1643:                 }
                   1644:             } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16      raeburn  1645:                 $showfile = $imgfile;
1.6       raeburn  1646:                 my $imgdir = $1;
                   1647:                 my $filename = $2;
1.159     raeburn  1648:                 if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6       raeburn  1649:                     $showfile = "/$imgdir/tn-".$filename;
                   1650:                 } else {
1.159     raeburn  1651:                     my $input = $londocroot.$imgfile;
                   1652:                     my $output = "$londocroot/$imgdir/tn-".$filename;
1.6       raeburn  1653:                     if (!-e $output) {
1.9       raeburn  1654:                         my ($width,$height) = &thumb_dimensions();
1.16      raeburn  1655:                         my ($fullwidth,$fullheight) = &check_dimensions($input);
                   1656:                         if ($fullwidth ne '' && $fullheight ne '') {
                   1657:                             if ($fullwidth > $width && $fullheight > $height) { 
                   1658:                                 my $size = $width.'x'.$height;
1.316   ! raeburn  1659:                                 my @args = ('convert','-sample',$size,$input,$output);
        !          1660:                                 system({$args[0]} @args);
1.159     raeburn  1661:                                 $showfile = "/$imgdir/tn-".$filename;
1.16      raeburn  1662:                             }
                   1663:                         }
1.6       raeburn  1664:                     }
                   1665:                 }
1.16      raeburn  1666:             }
1.6       raeburn  1667:             if ($showfile) {
1.40      raeburn  1668:                 if ($showfile =~ m{^/(adm|res)/}) {
                   1669:                     if ($showfile =~ m{^/res/}) {
                   1670:                         my $local_showfile =
                   1671:                             &Apache::lonnet::filelocation('',$showfile);
                   1672:                         &Apache::lonnet::repcopy($local_showfile);
                   1673:                     }
                   1674:                     $showfile = &Apache::loncommon::lonhttpdurl($showfile);
                   1675:                 }
                   1676:                 if ($imgfile) {
                   1677:                     if ($imgfile  =~ m{^/(adm|res)/}) {
                   1678:                         if ($imgfile =~ m{^/res/}) {
                   1679:                             my $local_imgfile =
                   1680:                                 &Apache::lonnet::filelocation('',$imgfile);
                   1681:                             &Apache::lonnet::repcopy($local_imgfile);
                   1682:                         }
                   1683:                         $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
                   1684:                     } else {
                   1685:                         $fullsize = $imgfile;
                   1686:                     }
                   1687:                 }
1.41      raeburn  1688:                 $datatable .= '<td>';
                   1689:                 if ($img eq 'login') {
1.135     bisitz   1690:                     $datatable .= $login_hdr_pick;
                   1691:                 } 
1.41      raeburn  1692:                 $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
                   1693:                                              $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6       raeburn  1694:             } else {
1.201     raeburn  1695:                 $datatable .= '<td>&nbsp;</td><td class="LC_left_item">'.
                   1696:                               &mt('Upload:').'<br />';
1.6       raeburn  1697:             }
                   1698:         } else {
1.201     raeburn  1699:             $datatable .= '<td>&nbsp;</td><td class="LC_left_item">'.
                   1700:                           &mt('Upload:').'<br />';
1.6       raeburn  1701:         }
1.9       raeburn  1702:         if ($switchserver) {
                   1703:             $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   1704:         } else {
1.135     bisitz   1705:             if ($img ne 'login') { # suppress file selection for Log-in header
                   1706:                 $datatable .='&nbsp;<input type="file" name="'.$role.'_'.$img.'" />';
                   1707:             }
1.9       raeburn  1708:         }
                   1709:         $datatable .= '</td></tr>';
1.6       raeburn  1710:     }
                   1711:     $itemcount ++;
                   1712:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   1713:     $datatable .= '<tr'.$css_class.'>'.
                   1714:                   '<td>'.$choices->{'bgs'}.'</td>';
                   1715:     my $bgs_def;
                   1716:     foreach my $item (@{$bgs}) {
                   1717:         if (!$is_custom->{$item}) {
1.70      raeburn  1718:             $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  1719:         }
                   1720:     }
                   1721:     if ($bgs_def) {
1.8       raeburn  1722:         $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6       raeburn  1723:     } else {
                   1724:         $datatable .= '<td>&nbsp;</td>';
                   1725:     }
                   1726:     $datatable .= '<td class="LC_right_item">'.
                   1727:                   '<table border="0"><tr>';
1.174     foxr     1728: 
1.6       raeburn  1729:     foreach my $item (@{$bgs}) {
1.306     raeburn  1730:         $datatable .= '<td style="text-align: center">'.$choices->{$item};
1.174     foxr     1731: 	my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6       raeburn  1732:         if ($designs->{'bgs'}{$item}) {
1.174     foxr     1733:             $datatable .= '&nbsp;';
1.6       raeburn  1734:         }
1.174     foxr     1735:         $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41      raeburn  1736:                       '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6       raeburn  1737:     }
                   1738:     $datatable .= '</tr></table></td></tr>';
                   1739:     $itemcount ++;
                   1740:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   1741:     $datatable .= '<tr'.$css_class.'>'.
                   1742:                   '<td>'.$choices->{'links'}.'</td>';
                   1743:     my $links_def;
                   1744:     foreach my $item (@{$links}) {
                   1745:         if (!$is_custom->{$item}) {
1.30      raeburn  1746:             $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  1747:         }
                   1748:     }
                   1749:     if ($links_def) {
1.8       raeburn  1750:         $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6       raeburn  1751:     } else {
                   1752:         $datatable .= '<td>&nbsp;</td>';
                   1753:     }
                   1754:     $datatable .= '<td class="LC_right_item">'.
                   1755:                   '<table border="0"><tr>';
                   1756:     foreach my $item (@{$links}) {
1.234     raeburn  1757: 	my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.306     raeburn  1758:         $datatable .= '<td style="text-align: center">'.$choices->{$item}."\n";
1.6       raeburn  1759:         if ($designs->{'links'}{$item}) {
1.174     foxr     1760:             $datatable.='&nbsp;';
1.6       raeburn  1761:         }
1.174     foxr     1762:         $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6       raeburn  1763:                       '" /></td>';
                   1764:     }
1.30      raeburn  1765:     $$rowtotal += $itemcount;
1.3       raeburn  1766:     return $datatable;
                   1767: }
                   1768: 
1.70      raeburn  1769: sub logo_display_options {
                   1770:     my ($img,$defaults,$designs) = @_;
                   1771:     my $checkedon;
                   1772:     if (ref($defaults) eq 'HASH') {
                   1773:         if (ref($defaults->{'showlogo'}) eq 'HASH') {
                   1774:             if ($defaults->{'showlogo'}{$img}) {
                   1775:                 $checkedon = 'checked="checked" ';     
                   1776:             }
                   1777:         } 
                   1778:     }
                   1779:     if (ref($designs) eq 'HASH') {
                   1780:         if (ref($designs->{'showlogo'}) eq 'HASH') {
                   1781:             if (defined($designs->{'showlogo'}{$img})) {
                   1782:                 if ($designs->{'showlogo'}{$img} == 0) {
                   1783:                     $checkedon = '';
                   1784:                 } elsif ($designs->{'showlogo'}{$img} == 1) {
                   1785:                     $checkedon = 'checked="checked" ';
                   1786:                 }
                   1787:             }
                   1788:         }
                   1789:     }
                   1790:     return '<br /><label>&nbsp;&nbsp;<input type="checkbox" name="'.
                   1791:            'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
                   1792:            &mt('show').'</label>'."\n";
                   1793: }
                   1794: 
1.41      raeburn  1795: sub login_header_options  {
1.135     bisitz   1796:     my ($img,$role,$defaults,$is_custom,$choices) = @_;
                   1797:     my $output = '';
1.41      raeburn  1798:     if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135     bisitz   1799:         $output .= &mt('Text default(s):').'<br />';
1.41      raeburn  1800:         if (!$is_custom->{'textcol'}) {
                   1801:             $output .= $choices->{'textcol'}.':&nbsp;'.$defaults->{'logintext'}{'textcol'}.
                   1802:                        '&nbsp;&nbsp;&nbsp;';
                   1803:         }
                   1804:         if (!$is_custom->{'bgcol'}) {
                   1805:             $output .= $choices->{'bgcol'}.':&nbsp;'.
                   1806:                        '<span id="css_'.$role.'_font" style="background-color: '.
                   1807:                        $defaults->{'logintext'}{'bgcol'}.';">&nbsp;&nbsp;&nbsp;</span>';
                   1808:         }
                   1809:         $output .= '<br />';
                   1810:     }
                   1811:     $output .='<br />';
                   1812:     return $output;
                   1813: }
                   1814: 
                   1815: sub login_text_colors {
1.201     raeburn  1816:     my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41      raeburn  1817:     my $color_menu = '<table border="0"><tr>';
                   1818:     foreach my $item (@{$logintext}) {
1.306     raeburn  1819:         $color_menu .= '<td style="text-align: center">'.$choices->{$item};
1.201     raeburn  1820:         my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
                   1821:         $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
                   1822:                       '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41      raeburn  1823:     }
                   1824:     $color_menu .= '</tr></table><br />';
                   1825:     return $color_menu;
                   1826: }
                   1827: 
                   1828: sub image_changes {
                   1829:     my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
                   1830:     my $output;
1.135     bisitz   1831:     if ($img eq 'login') {
                   1832:             # suppress image for Log-in header
                   1833:     } elsif (!$is_custom) {
1.70      raeburn  1834:         if ($img ne 'domlogo') {
1.41      raeburn  1835:             $output .= &mt('Default image:').'<br />';
                   1836:         } else {
                   1837:             $output .= &mt('Default in use:').'<br />';
                   1838:         }
                   1839:     }
1.135     bisitz   1840:     if ($img eq 'login') { # suppress image for Log-in header
                   1841:         $output .= '<td>'.$logincolors;
1.41      raeburn  1842:     } else {
1.135     bisitz   1843:         if ($img_import) {
                   1844:             $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
                   1845:         }
                   1846:         $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
                   1847:                    $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
                   1848:         if ($is_custom) {
                   1849:             $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
                   1850:                        '<input type="checkbox" name="'.
                   1851:                        $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
                   1852:                        '</label>&nbsp;'.&mt('Replace:').'</span><br />';
                   1853:         } else {
1.306     raeburn  1854:             $output .= '<td class="LC_middle">'.$logincolors.&mt('Upload:').'<br />';
1.135     bisitz   1855:         }
1.41      raeburn  1856:     }
                   1857:     return $output;
                   1858: }
                   1859: 
1.3       raeburn  1860: sub print_quotas {
1.86      raeburn  1861:     my ($dom,$settings,$rowtotal,$action) = @_;
                   1862:     my $context;
                   1863:     if ($action eq 'quotas') {
                   1864:         $context = 'tools';
                   1865:     } else {
                   1866:         $context = $action;
                   1867:     }
1.197     raeburn  1868:     my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44      raeburn  1869:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3       raeburn  1870:     my $typecount = 0;
1.101     raeburn  1871:     my ($css_class,%titles);
1.86      raeburn  1872:     if ($context eq 'requestcourses') {
1.271     raeburn  1873:         @usertools = ('official','unofficial','community','textbook','placement');
1.106     raeburn  1874:         @options =('norequest','approval','validate','autolimit');
1.101     raeburn  1875:         %validations = &Apache::lonnet::auto_courserequest_checks($dom);
                   1876:         %titles = &courserequest_titles();
1.163     raeburn  1877:     } elsif ($context eq 'requestauthor') {
                   1878:         @usertools = ('author');
                   1879:         @options = ('norequest','approval','automatic');
1.210     raeburn  1880:         %titles = &authorrequest_titles();
1.86      raeburn  1881:     } else {
1.162     raeburn  1882:         @usertools = ('aboutme','blog','webdav','portfolio');
1.101     raeburn  1883:         %titles = &tool_titles();
1.86      raeburn  1884:     }
1.26      raeburn  1885:     if (ref($types) eq 'ARRAY') {
1.23      raeburn  1886:         foreach my $type (@{$types}) {
1.197     raeburn  1887:             my ($currdefquota,$currauthorquota);
1.163     raeburn  1888:             unless (($context eq 'requestcourses') ||
                   1889:                     ($context eq 'requestauthor')) {
1.86      raeburn  1890:                 if (ref($settings) eq 'HASH') {
                   1891:                     if (ref($settings->{defaultquota}) eq 'HASH') {
1.197     raeburn  1892:                         $currdefquota = $settings->{defaultquota}->{$type};
1.86      raeburn  1893:                     } else {
                   1894:                         $currdefquota = $settings->{$type};
                   1895:                     }
1.197     raeburn  1896:                     if (ref($settings->{authorquota}) eq 'HASH') {
                   1897:                         $currauthorquota = $settings->{authorquota}->{$type};
                   1898:                     }
1.78      raeburn  1899:                 }
1.72      raeburn  1900:             }
1.3       raeburn  1901:             if (defined($usertypes->{$type})) {
                   1902:                 $typecount ++;
                   1903:                 $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72      raeburn  1904:                 $datatable .= '<tr'.$css_class.'>'.
1.3       raeburn  1905:                               '<td>'.$usertypes->{$type}.'</td>'.
1.72      raeburn  1906:                               '<td class="LC_left_item">';
1.101     raeburn  1907:                 if ($context eq 'requestcourses') {
                   1908:                     $datatable .= '<table><tr>';
                   1909:                 }
                   1910:                 my %cell;  
1.72      raeburn  1911:                 foreach my $item (@usertools) {
1.101     raeburn  1912:                     if ($context eq 'requestcourses') {
                   1913:                         my ($curroption,$currlimit);
                   1914:                         if (ref($settings) eq 'HASH') {
                   1915:                             if (ref($settings->{$item}) eq 'HASH') {
                   1916:                                 $curroption = $settings->{$item}->{$type};
                   1917:                                 if ($curroption =~ /^autolimit=(\d*)$/) {
                   1918:                                     $currlimit = $1; 
                   1919:                                 }
                   1920:                             }
                   1921:                         }
                   1922:                         if (!$curroption) {
                   1923:                             $curroption = 'norequest';
                   1924:                         }
                   1925:                         $datatable .= '<th>'.$titles{$item}.'</th>';
                   1926:                         foreach my $option (@options) {
                   1927:                             my $val = $option;
                   1928:                             if ($option eq 'norequest') {
                   1929:                                 $val = 0;  
                   1930:                             }
                   1931:                             if ($option eq 'validate') {
                   1932:                                 my $canvalidate = 0;
                   1933:                                 if (ref($validations{$item}) eq 'HASH') { 
                   1934:                                     if ($validations{$item}{$type}) {
                   1935:                                         $canvalidate = 1;
                   1936:                                     }
                   1937:                                 }
                   1938:                                 next if (!$canvalidate);
                   1939:                             }
                   1940:                             my $checked = '';
                   1941:                             if ($option eq $curroption) {
                   1942:                                 $checked = ' checked="checked"';
                   1943:                             } elsif ($option eq 'autolimit') {
                   1944:                                 if ($curroption =~ /^autolimit/) {
                   1945:                                     $checked = ' checked="checked"';
                   1946:                                 }                       
                   1947:                             } 
                   1948:                             $cell{$item} .= '<span class="LC_nobreak"><label>'.
                   1949:                                   '<input type="radio" name="crsreq_'.$item.
                   1950:                                   '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127     raeburn  1951:                                   $titles{$option}.'</label>';
1.101     raeburn  1952:                             if ($option eq 'autolimit') {
1.127     raeburn  1953:                                 $cell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
1.101     raeburn  1954:                                                 $item.'_limit_'.$type.'" size="1" '.
1.103     raeburn  1955:                                                 'value="'.$currlimit.'" />';
1.101     raeburn  1956:                             }
1.127     raeburn  1957:                             $cell{$item} .= '</span> ';
1.103     raeburn  1958:                             if ($option eq 'autolimit') {
1.127     raeburn  1959:                                 $cell{$item} .= $titles{'unlimited'};
1.103     raeburn  1960:                             }
1.101     raeburn  1961:                         }
1.163     raeburn  1962:                     } elsif ($context eq 'requestauthor') {
                   1963:                         my $curroption;
                   1964:                         if (ref($settings) eq 'HASH') {
                   1965:                             $curroption = $settings->{$type};
                   1966:                         }
                   1967:                         if (!$curroption) {
                   1968:                             $curroption = 'norequest';
                   1969:                         }
                   1970:                         foreach my $option (@options) {
                   1971:                             my $val = $option;
                   1972:                             if ($option eq 'norequest') {
                   1973:                                 $val = 0;
                   1974:                             }
                   1975:                             my $checked = '';
                   1976:                             if ($option eq $curroption) {
                   1977:                                 $checked = ' checked="checked"';
                   1978:                             }
                   1979:                             $datatable .= '<span class="LC_nobreak"><label>'.
                   1980:                                   '<input type="radio" name="authorreq_'.$type.
                   1981:                                   '" value="'.$val.'"'.$checked.' />'.
                   1982:                                   $titles{$option}.'</label></span>&nbsp; ';
                   1983:                         }
1.101     raeburn  1984:                     } else {
                   1985:                         my $checked = 'checked="checked" ';
                   1986:                         if (ref($settings) eq 'HASH') {
                   1987:                             if (ref($settings->{$item}) eq 'HASH') {
                   1988:                                 if ($settings->{$item}->{$type} == 0) {
                   1989:                                     $checked = '';
                   1990:                                 } elsif ($settings->{$item}->{$type} == 1) {
                   1991:                                     $checked =  'checked="checked" ';
                   1992:                                 }
1.78      raeburn  1993:                             }
1.72      raeburn  1994:                         }
1.101     raeburn  1995:                         $datatable .= '<span class="LC_nobreak"><label>'.
                   1996:                                       '<input type="checkbox" name="'.$context.'_'.$item.
                   1997:                                       '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
                   1998:                                       '</label></span>&nbsp; ';
1.72      raeburn  1999:                     }
1.101     raeburn  2000:                 }
                   2001:                 if ($context eq 'requestcourses') {
                   2002:                     $datatable .= '</tr><tr>';
                   2003:                     foreach my $item (@usertools) {
1.106     raeburn  2004:                         $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';  
1.101     raeburn  2005:                     }
                   2006:                     $datatable .= '</tr></table>';
1.72      raeburn  2007:                 }
1.86      raeburn  2008:                 $datatable .= '</td>';
1.163     raeburn  2009:                 unless (($context eq 'requestcourses') ||
                   2010:                         ($context eq 'requestauthor')) {
1.86      raeburn  2011:                     $datatable .= 
1.197     raeburn  2012:                               '<td class="LC_right_item">'.
                   2013:                               '<span class="LC_nobreak">'.&mt('Portfolio').':&nbsp;'.
1.3       raeburn  2014:                               '<input type="text" name="quota_'.$type.
1.72      raeburn  2015:                               '" value="'.$currdefquota.
1.197     raeburn  2016:                               '" size="5" /></span>'.('&nbsp;' x 2).
                   2017:                               '<span class="LC_nobreak">'.&mt('Authoring').':&nbsp;'.
                   2018:                               '<input type="text" name="authorquota_'.$type.
                   2019:                               '" value="'.$currauthorquota.
                   2020:                               '" size="5" /></span></td>';
1.86      raeburn  2021:                 }
                   2022:                 $datatable .= '</tr>';
1.3       raeburn  2023:             }
                   2024:         }
                   2025:     }
1.163     raeburn  2026:     unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86      raeburn  2027:         $defaultquota = '20';
1.197     raeburn  2028:         $authorquota = '500';
1.86      raeburn  2029:         if (ref($settings) eq 'HASH') {
                   2030:             if (ref($settings->{'defaultquota'}) eq 'HASH') {
                   2031:                 $defaultquota = $settings->{'defaultquota'}->{'default'};
                   2032:             } elsif (defined($settings->{'default'})) {
                   2033:                 $defaultquota = $settings->{'default'};
                   2034:             }
1.197     raeburn  2035:             if (ref($settings->{'authorquota'}) eq 'HASH') {
                   2036:                 $authorquota = $settings->{'authorquota'}->{'default'};
                   2037:             }
1.3       raeburn  2038:         }
                   2039:     }
                   2040:     $typecount ++;
                   2041:     $css_class = $typecount%2?' class="LC_odd_row"':'';
                   2042:     $datatable .= '<tr'.$css_class.'>'.
1.26      raeburn  2043:                   '<td>'.$othertitle.'</td>'.
1.72      raeburn  2044:                   '<td class="LC_left_item">';
1.101     raeburn  2045:     if ($context eq 'requestcourses') {
                   2046:         $datatable .= '<table><tr>';
                   2047:     }
                   2048:     my %defcell;
1.72      raeburn  2049:     foreach my $item (@usertools) {
1.101     raeburn  2050:         if ($context eq 'requestcourses') {
                   2051:             my ($curroption,$currlimit);
                   2052:             if (ref($settings) eq 'HASH') {
                   2053:                 if (ref($settings->{$item}) eq 'HASH') {
                   2054:                     $curroption = $settings->{$item}->{'default'};
                   2055:                     if ($curroption =~ /^autolimit=(\d*)$/) {
                   2056:                         $currlimit = $1;
                   2057:                     }
                   2058:                 }
                   2059:             }
                   2060:             if (!$curroption) {
                   2061:                 $curroption = 'norequest';
                   2062:             }
                   2063:             $datatable .= '<th>'.$titles{$item}.'</th>';
                   2064:             foreach my $option (@options) {
                   2065:                 my $val = $option;
                   2066:                 if ($option eq 'norequest') {
                   2067:                     $val = 0;
                   2068:                 }
                   2069:                 if ($option eq 'validate') {
                   2070:                     my $canvalidate = 0;
                   2071:                     if (ref($validations{$item}) eq 'HASH') {
                   2072:                         if ($validations{$item}{'default'}) {
                   2073:                             $canvalidate = 1;
                   2074:                         }
                   2075:                     }
                   2076:                     next if (!$canvalidate);
                   2077:                 }
                   2078:                 my $checked = '';
                   2079:                 if ($option eq $curroption) {
                   2080:                     $checked = ' checked="checked"';
                   2081:                 } elsif ($option eq 'autolimit') {
                   2082:                     if ($curroption =~ /^autolimit/) {
                   2083:                         $checked = ' checked="checked"';
                   2084:                     }
                   2085:                 }
                   2086:                 $defcell{$item} .= '<span class="LC_nobreak"><label>'.
                   2087:                                   '<input type="radio" name="crsreq_'.$item.
                   2088:                                   '_default" value="'.$val.'"'.$checked.' />'.
                   2089:                                   $titles{$option}.'</label>';
                   2090:                 if ($option eq 'autolimit') {
1.127     raeburn  2091:                     $defcell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
1.101     raeburn  2092:                                        $item.'_limit_default" size="1" '.
                   2093:                                        'value="'.$currlimit.'" />';
                   2094:                 }
1.127     raeburn  2095:                 $defcell{$item} .= '</span> ';
1.104     raeburn  2096:                 if ($option eq 'autolimit') {
1.127     raeburn  2097:                     $defcell{$item} .= $titles{'unlimited'};
1.104     raeburn  2098:                 }
1.101     raeburn  2099:             }
1.163     raeburn  2100:         } elsif ($context eq 'requestauthor') {
                   2101:             my $curroption;
                   2102:             if (ref($settings) eq 'HASH') {
1.172     raeburn  2103:                 $curroption = $settings->{'default'};
1.163     raeburn  2104:             }
                   2105:             if (!$curroption) {
                   2106:                 $curroption = 'norequest';
                   2107:             }
                   2108:             foreach my $option (@options) {
                   2109:                 my $val = $option;
                   2110:                 if ($option eq 'norequest') {
                   2111:                     $val = 0;
                   2112:                 }
                   2113:                 my $checked = '';
                   2114:                 if ($option eq $curroption) {
                   2115:                     $checked = ' checked="checked"';
                   2116:                 }
                   2117:                 $datatable .= '<span class="LC_nobreak"><label>'.
                   2118:                               '<input type="radio" name="authorreq_default"'.
                   2119:                               ' value="'.$val.'"'.$checked.' />'.
                   2120:                               $titles{$option}.'</label></span>&nbsp; ';
                   2121:             }
1.101     raeburn  2122:         } else {
                   2123:             my $checked = 'checked="checked" ';
                   2124:             if (ref($settings) eq 'HASH') {
                   2125:                 if (ref($settings->{$item}) eq 'HASH') {
                   2126:                     if ($settings->{$item}->{'default'} == 0) {
                   2127:                         $checked = '';
                   2128:                     } elsif ($settings->{$item}->{'default'} == 1) {
                   2129:                         $checked = 'checked="checked" ';
                   2130:                     }
1.78      raeburn  2131:                 }
1.72      raeburn  2132:             }
1.101     raeburn  2133:             $datatable .= '<span class="LC_nobreak"><label>'.
                   2134:                           '<input type="checkbox" name="'.$context.'_'.$item.
                   2135:                           '" value="default" '.$checked.'/>'.$titles{$item}.
                   2136:                           '</label></span>&nbsp; ';
                   2137:         }
                   2138:     }
                   2139:     if ($context eq 'requestcourses') {
                   2140:         $datatable .= '</tr><tr>';
                   2141:         foreach my $item (@usertools) {
1.106     raeburn  2142:             $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72      raeburn  2143:         }
1.101     raeburn  2144:         $datatable .= '</tr></table>';
1.72      raeburn  2145:     }
1.86      raeburn  2146:     $datatable .= '</td>';
1.163     raeburn  2147:     unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.197     raeburn  2148:         $datatable .= '<td class="LC_right_item">'.
                   2149:                       '<span class="LC_nobreak">'.&mt('Portfolio').':&nbsp;'.
1.86      raeburn  2150:                       '<input type="text" name="defaultquota" value="'.
1.197     raeburn  2151:                       $defaultquota.'" size="5" /></span>'.('&nbsp;' x2).
                   2152:                       '<span class="LC_nobreak">'.&mt('Authoring').':&nbsp;'.
                   2153:                       '<input type="text" name="authorquota" value="'.
                   2154:                       $authorquota.'" size="5" /></span></td>';
1.86      raeburn  2155:     }
                   2156:     $datatable .= '</tr>';
1.72      raeburn  2157:     $typecount ++;
                   2158:     $css_class = $typecount%2?' class="LC_odd_row"':'';
                   2159:     $datatable .= '<tr'.$css_class.'>'.
1.197     raeburn  2160:                   '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104     raeburn  2161:     if ($context eq 'requestcourses') {
1.109     raeburn  2162:         $datatable .= &mt('(overrides affiliation, if set)').
                   2163:                       '</td>'.
                   2164:                       '<td class="LC_left_item">'.
                   2165:                       '<table><tr>';
1.101     raeburn  2166:     } else {
1.109     raeburn  2167:         $datatable .= &mt('(overrides affiliation, if checked)').
                   2168:                       '</td>'.
                   2169:                       '<td class="LC_left_item" colspan="2">'.
                   2170:                       '<br />';
1.101     raeburn  2171:     }
                   2172:     my %advcell;
1.72      raeburn  2173:     foreach my $item (@usertools) {
1.101     raeburn  2174:         if ($context eq 'requestcourses') {
                   2175:             my ($curroption,$currlimit);
                   2176:             if (ref($settings) eq 'HASH') {
                   2177:                 if (ref($settings->{$item}) eq 'HASH') {
                   2178:                     $curroption = $settings->{$item}->{'_LC_adv'};
                   2179:                     if ($curroption =~ /^autolimit=(\d*)$/) {
                   2180:                         $currlimit = $1;
                   2181:                     }
                   2182:                 }
                   2183:             }
                   2184:             $datatable .= '<th>'.$titles{$item}.'</th>';
1.104     raeburn  2185:             my $checked = '';
                   2186:             if ($curroption eq '') {
                   2187:                 $checked = ' checked="checked"';
                   2188:             }
                   2189:             $advcell{$item} .= '<span class="LC_nobreak"><label>'.
                   2190:                                '<input type="radio" name="crsreq_'.$item.
                   2191:                                '__LC_adv" value=""'.$checked.' />'.
                   2192:                                &mt('No override set').'</label></span>&nbsp; ';
1.101     raeburn  2193:             foreach my $option (@options) {
                   2194:                 my $val = $option;
                   2195:                 if ($option eq 'norequest') {
                   2196:                     $val = 0;
                   2197:                 }
                   2198:                 if ($option eq 'validate') {
                   2199:                     my $canvalidate = 0;
                   2200:                     if (ref($validations{$item}) eq 'HASH') {
                   2201:                         if ($validations{$item}{'_LC_adv'}) {
                   2202:                             $canvalidate = 1;
                   2203:                         }
                   2204:                     }
                   2205:                     next if (!$canvalidate);
                   2206:                 }
                   2207:                 my $checked = '';
1.104     raeburn  2208:                 if ($val eq $curroption) {
1.101     raeburn  2209:                     $checked = ' checked="checked"';
                   2210:                 } elsif ($option eq 'autolimit') {
                   2211:                     if ($curroption =~ /^autolimit/) {
                   2212:                         $checked = ' checked="checked"';
                   2213:                     }
                   2214:                 }
                   2215:                 $advcell{$item} .= '<span class="LC_nobreak"><label>'.
                   2216:                                   '<input type="radio" name="crsreq_'.$item.
                   2217:                                   '__LC_adv" value="'.$val.'"'.$checked.' />'.
                   2218:                                   $titles{$option}.'</label>';
                   2219:                 if ($option eq 'autolimit') {
1.127     raeburn  2220:                     $advcell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
1.101     raeburn  2221:                                        $item.'_limit__LC_adv" size="1" '.
                   2222:                                        'value="'.$currlimit.'" />';
                   2223:                 }
1.127     raeburn  2224:                 $advcell{$item} .= '</span> ';
1.104     raeburn  2225:                 if ($option eq 'autolimit') {
1.127     raeburn  2226:                     $advcell{$item} .= $titles{'unlimited'};
1.104     raeburn  2227:                 }
1.101     raeburn  2228:             }
1.163     raeburn  2229:         } elsif ($context eq 'requestauthor') {
                   2230:             my $curroption;
                   2231:             if (ref($settings) eq 'HASH') {
                   2232:                 $curroption = $settings->{'_LC_adv'};
                   2233:             }
                   2234:             my $checked = '';
                   2235:             if ($curroption eq '') {
                   2236:                 $checked = ' checked="checked"';
                   2237:             }
                   2238:             $datatable .= '<span class="LC_nobreak"><label>'.
                   2239:                           '<input type="radio" name="authorreq__LC_adv"'.
                   2240:                           ' value=""'.$checked.' />'.
                   2241:                           &mt('No override set').'</label></span>&nbsp; ';
                   2242:             foreach my $option (@options) {
                   2243:                 my $val = $option;
                   2244:                 if ($option eq 'norequest') {
                   2245:                     $val = 0;
                   2246:                 }
                   2247:                 my $checked = '';
                   2248:                 if ($val eq $curroption) {
                   2249:                     $checked = ' checked="checked"';
                   2250:                 }
                   2251:                 $datatable .= '<span class="LC_nobreak"><label>'.
1.173     raeburn  2252:                               '<input type="radio" name="authorreq__LC_adv"'.
                   2253:                               ' value="'.$val.'"'.$checked.' />'.
1.163     raeburn  2254:                               $titles{$option}.'</label></span>&nbsp; ';
                   2255:             }
1.101     raeburn  2256:         } else {
                   2257:             my $checked = 'checked="checked" ';
                   2258:             if (ref($settings) eq 'HASH') {
                   2259:                 if (ref($settings->{$item}) eq 'HASH') {
                   2260:                     if ($settings->{$item}->{'_LC_adv'} == 0) {
                   2261:                         $checked = '';
                   2262:                     } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
                   2263:                         $checked = 'checked="checked" ';
                   2264:                     }
1.79      raeburn  2265:                 }
1.72      raeburn  2266:             }
1.101     raeburn  2267:             $datatable .= '<span class="LC_nobreak"><label>'.
                   2268:                           '<input type="checkbox" name="'.$context.'_'.$item.
                   2269:                           '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
                   2270:                           '</label></span>&nbsp; ';
                   2271:         }
                   2272:     }
                   2273:     if ($context eq 'requestcourses') {
                   2274:         $datatable .= '</tr><tr>';
                   2275:         foreach my $item (@usertools) {
1.106     raeburn  2276:             $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72      raeburn  2277:         }
1.101     raeburn  2278:         $datatable .= '</tr></table>';
1.72      raeburn  2279:     }
1.98      raeburn  2280:     $datatable .= '</td></tr>';
1.30      raeburn  2281:     $$rowtotal += $typecount;
1.3       raeburn  2282:     return $datatable;
                   2283: }
                   2284: 
1.163     raeburn  2285: sub print_requestmail {
1.305     raeburn  2286:     my ($dom,$action,$settings,$rowtotal,$customcss,$rowstyle) = @_;
1.208     raeburn  2287:     my ($now,$datatable,%currapp);
1.102     raeburn  2288:     $now = time;
                   2289:     if (ref($settings) eq 'HASH') {
                   2290:         if (ref($settings->{'notify'}) eq 'HASH') {
                   2291:             if ($settings->{'notify'}{'approval'} ne '') {
1.224     raeburn  2292:                 map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102     raeburn  2293:             }
                   2294:         }
                   2295:     }
1.191     raeburn  2296:     my $numinrow = 2;
1.224     raeburn  2297:     my $css_class;
1.305     raeburn  2298:     if ($$rowtotal%2) {
                   2299:         $css_class = 'LC_odd_row';
                   2300:     }
                   2301:     if ($customcss) {
                   2302:         $css_class .= " $customcss";
                   2303:     }
                   2304:     $css_class =~ s/^\s+//;
                   2305:     if ($css_class) {
                   2306:         $css_class = ' class="'.$css_class.'"';
                   2307:     }
                   2308:     if ($rowstyle) {
                   2309:         $css_class .= ' style="'.$rowstyle.'"';
                   2310:     }
1.163     raeburn  2311:     my $text;
                   2312:     if ($action eq 'requestcourses') {
                   2313:         $text = &mt('Receive notification of course requests requiring approval');
1.224     raeburn  2314:     } elsif ($action eq 'requestauthor') {
                   2315:         $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.163     raeburn  2316:     } else {
1.224     raeburn  2317:        $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.163     raeburn  2318:     }
1.224     raeburn  2319:     $datatable = '<tr'.$css_class.'>'.
1.163     raeburn  2320:                  ' <td>'.$text.'</td>'.
1.102     raeburn  2321:                  ' <td class="LC_left_item">';
1.191     raeburn  2322:     my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.224     raeburn  2323:                                                  $action.'notifyapproval',%currapp);
1.191     raeburn  2324:     if ($numdc > 0) {
                   2325:         $datatable .= $table;
1.102     raeburn  2326:     } else {
                   2327:         $datatable .= &mt('There are no active Domain Coordinators');
                   2328:     }
                   2329:     $datatable .='</td></tr>';
                   2330:     return $datatable;
                   2331: }
                   2332: 
1.216     raeburn  2333: sub print_studentcode {
                   2334:     my ($settings,$rowtotal) = @_;
                   2335:     my $rownum = 0; 
1.218     raeburn  2336:     my ($output,%current);
1.271     raeburn  2337:     my @crstypes = ('official','unofficial','community','textbook','placement');
1.248     raeburn  2338:     if (ref($settings) eq 'HASH') {
                   2339:         if (ref($settings->{'uniquecode'}) eq 'HASH') {
                   2340:             foreach my $type (@crstypes) {
                   2341:                 $current{$type} = $settings->{'uniquecode'}{$type};
                   2342:             }
1.218     raeburn  2343:         }
                   2344:     }
                   2345:     $output .= '<tr>'.
                   2346:                '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
                   2347:                '<td class="LC_left_item">';
                   2348:     foreach my $type (@crstypes) {
                   2349:         my $check = ' ';
                   2350:         if ($current{$type}) {
                   2351:             $check = ' checked="checked" ';
                   2352:         }
                   2353:         $output .= '<span class="LC_nobreak"><label>'.
                   2354:                    '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
                   2355:                    &mt($type).'</label></span>'.('&nbsp;'x2).' ';
                   2356:     }
                   2357:     $output .= '</td></tr>';
                   2358:     $$rowtotal ++;
                   2359:     return $output;
1.216     raeburn  2360: }
                   2361: 
                   2362: sub print_textbookcourses {
1.242     raeburn  2363:     my ($dom,$type,$settings,$rowtotal) = @_;
1.216     raeburn  2364:     my $rownum = 0;
                   2365:     my $css_class;
                   2366:     my $itemcount = 1;
                   2367:     my $maxnum = 0;
                   2368:     my $bookshash;
                   2369:     if (ref($settings) eq 'HASH') {
1.242     raeburn  2370:         $bookshash = $settings->{$type};
1.216     raeburn  2371:     }
                   2372:     my %ordered;
                   2373:     if (ref($bookshash) eq 'HASH') {
                   2374:         foreach my $item (keys(%{$bookshash})) {
                   2375:             if (ref($bookshash->{$item}) eq 'HASH') {
                   2376:                 my $num = $bookshash->{$item}{'order'};
                   2377:                 $ordered{$num} = $item;
                   2378:             }
                   2379:         }
                   2380:     }
                   2381:     my $confname = $dom.'-domainconfig';
                   2382:     my $switchserver = &check_switchserver($dom,$confname);
1.242     raeburn  2383:     my $maxnum = scalar(keys(%ordered));
                   2384:     my $datatable;
1.216     raeburn  2385:     if (keys(%ordered)) {
                   2386:         my @items = sort { $a <=> $b } keys(%ordered);
                   2387:         for (my $i=0; $i<@items; $i++) {
                   2388:             $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   2389:             my $key = $ordered{$items[$i]};
                   2390:             my %coursehash=&Apache::lonnet::coursedescription($key);
                   2391:             my $coursetitle = $coursehash{'description'};
1.243     raeburn  2392:             my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.216     raeburn  2393:             if (ref($bookshash->{$key}) eq 'HASH') {
                   2394:                 $subject = $bookshash->{$key}->{'subject'};
                   2395:                 $title = $bookshash->{$key}->{'title'};
1.242     raeburn  2396:                 if ($type eq 'textbooks') {
1.243     raeburn  2397:                     $publisher = $bookshash->{$key}->{'publisher'};
1.242     raeburn  2398:                     $author = $bookshash->{$key}->{'author'};
                   2399:                     $image = $bookshash->{$key}->{'image'};
                   2400:                     if ($image ne '') {
                   2401:                         my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
                   2402:                         my $imagethumb = "$path/tn-".$imagefile;
                   2403:                         $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
                   2404:                     }
1.216     raeburn  2405:                 }
                   2406:             }
1.242     raeburn  2407:             my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.216     raeburn  2408:             $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.242     raeburn  2409:                          .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.216     raeburn  2410:             for (my $k=0; $k<=$maxnum; $k++) {
                   2411:                 my $vpos = $k+1;
                   2412:                 my $selstr;
                   2413:                 if ($k == $i) {
                   2414:                     $selstr = ' selected="selected" ';
                   2415:                 }
                   2416:                 $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   2417:             }
                   2418:             $datatable .= '</select>'.('&nbsp;'x2).
1.242     raeburn  2419:                 '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.216     raeburn  2420:                 &mt('Delete?').'</label></span></td>'.
                   2421:                 '<td colspan="2">'.
1.242     raeburn  2422:                 '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.216     raeburn  2423:                 ('&nbsp;'x2).
1.242     raeburn  2424:                 '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
                   2425:             if ($type eq 'textbooks') {
                   2426:                 $datatable .= ('&nbsp;'x2).
1.243     raeburn  2427:                               '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
                   2428:                               ('&nbsp;'x2).
1.242     raeburn  2429:                               '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
                   2430:                               ('&nbsp;'x2).
                   2431:                               '<span class="LC_nobreak">'.&mt('Thumbnail:');
                   2432:                 if ($image) {
1.267     raeburn  2433:                     $datatable .= $imgsrc.
1.242     raeburn  2434:                                   '<label><input type="checkbox" name="'.$type.'_image_del"'.
                   2435:                                   ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
                   2436:                                   '<span class="LC_nobreak">&nbsp;'.&mt('Replace:').'&nbsp;';
                   2437:                 }
                   2438:                 if ($switchserver) {
                   2439:                     $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   2440:                 } else {
                   2441:                     $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
                   2442:                 }
1.216     raeburn  2443:             }
1.242     raeburn  2444:             $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.216     raeburn  2445:                           '<span class="LC_nobreak">'.&mt('LON-CAPA course:').'&nbsp;'.
                   2446:                           $coursetitle.'</span></td></tr>'."\n";
                   2447:             $itemcount ++;
                   2448:         }
                   2449:     }
                   2450:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.242     raeburn  2451:     my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.216     raeburn  2452:     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.242     raeburn  2453:                   '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
                   2454:                   '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.216     raeburn  2455:     for (my $k=0; $k<$maxnum+1; $k++) {
                   2456:         my $vpos = $k+1;
                   2457:         my $selstr;
                   2458:         if ($k == $maxnum) {
                   2459:             $selstr = ' selected="selected" ';
                   2460:         }
                   2461:         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   2462:     }
                   2463:     $datatable .= '</select>&nbsp;'."\n".
1.242     raeburn  2464:                   '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</td>'."\n".
1.216     raeburn  2465:                   '<td colspan="2">'.
1.242     raeburn  2466:                   '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.216     raeburn  2467:                   ('&nbsp;'x2).
1.242     raeburn  2468:                   '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
                   2469:                   ('&nbsp;'x2);
                   2470:     if ($type eq 'textbooks') {
1.243     raeburn  2471:         $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
                   2472:                       ('&nbsp;'x2).
                   2473:                       '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.242     raeburn  2474:                       ('&nbsp;'x2).
                   2475:                       '<span class="LC_nobreak">'.&mt('Image:').'&nbsp;';
                   2476:         if ($switchserver) {
                   2477:             $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   2478:         } else {
                   2479:             $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
                   2480:         }
1.216     raeburn  2481:     }
                   2482:     $datatable .= '</span>'."\n".
                   2483:                   '<span class="LC_nobreak">'.&mt('LON-CAPA course:').'&nbsp;'.
1.242     raeburn  2484:                   &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
                   2485:                   '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.216     raeburn  2486:                   &Apache::loncommon::selectcourse_link
1.242     raeburn  2487:                       ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course');
1.216     raeburn  2488:                   '</span></td>'."\n".
                   2489:                   '</tr>'."\n";
                   2490:     $itemcount ++;
                   2491:     return $datatable;
                   2492: }
                   2493: 
1.217     raeburn  2494: sub textbookcourses_javascript {
1.242     raeburn  2495:     my ($settings) = @_;
                   2496:     return unless(ref($settings) eq 'HASH');
                   2497:     my (%ordered,%total,%jstext);
                   2498:     foreach my $type ('textbooks','templates') {
                   2499:         $total{$type} = 0;
                   2500:         if (ref($settings->{$type}) eq 'HASH') {
                   2501:             foreach my $item (keys(%{$settings->{$type}})) {
                   2502:                 if (ref($settings->{$type}->{$item}) eq 'HASH') {
                   2503:                     my $num = $settings->{$type}->{$item}{'order'};
                   2504:                     $ordered{$type}{$num} = $item;
                   2505:                 }
                   2506:             }
                   2507:             $total{$type} = scalar(keys(%{$settings->{$type}}));
                   2508:         }
                   2509:         my @jsarray = ();
                   2510:         foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
                   2511:             push(@jsarray,$ordered{$type}{$item});
                   2512:         }
                   2513:         $jstext{$type} = '    var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.217     raeburn  2514:     }
                   2515:     return <<"ENDSCRIPT";
                   2516: <script type="text/javascript">
                   2517: // <![CDATA[
1.242     raeburn  2518: function reorderBooks(form,item,caller) {
1.217     raeburn  2519:     var changedVal;
1.242     raeburn  2520: $jstext{'textbooks'};
                   2521: $jstext{'templates'};
                   2522:     var newpos;
                   2523:     var maxh;
                   2524:     if (caller == 'textbooks') {  
                   2525:         newpos = 'textbooks_addbook_pos';
                   2526:         maxh = 1 + $total{'textbooks'};
                   2527:     } else {
                   2528:         newpos = 'templates_addbook_pos';
                   2529:         maxh = 1 + $total{'templates'};
                   2530:     }
1.217     raeburn  2531:     var current = new Array;
                   2532:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
                   2533:     if (item == newpos) {
                   2534:         changedVal = newitemVal;
                   2535:     } else {
                   2536:         changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
                   2537:         current[newitemVal] = newpos;
                   2538:     }
1.242     raeburn  2539:     if (caller == 'textbooks') {
                   2540:         for (var i=0; i<textbooks.length; i++) {
                   2541:             var elementName = 'textbooks_'+textbooks[i];
                   2542:             if (elementName != item) {
                   2543:                 if (form.elements[elementName]) {
                   2544:                     var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   2545:                     current[currVal] = elementName;
                   2546:                 }
                   2547:             }
                   2548:         }
                   2549:     }
                   2550:     if (caller == 'templates') {
                   2551:         for (var i=0; i<templates.length; i++) {
                   2552:             var elementName = 'templates_'+templates[i];
                   2553:             if (elementName != item) {
                   2554:                 if (form.elements[elementName]) {
                   2555:                     var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   2556:                     current[currVal] = elementName;
                   2557:                 }
1.217     raeburn  2558:             }
                   2559:         }
                   2560:     }
                   2561:     var oldVal;
                   2562:     for (var j=0; j<maxh; j++) {
                   2563:         if (current[j] == undefined) {
                   2564:             oldVal = j;
                   2565:         }
                   2566:     }
                   2567:     if (oldVal < changedVal) {
                   2568:         for (var k=oldVal+1; k<=changedVal ; k++) {
                   2569:            var elementName = current[k];
                   2570:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   2571:         }
                   2572:     } else {
                   2573:         for (var k=changedVal; k<oldVal; k++) {
                   2574:             var elementName = current[k];
                   2575:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   2576:         }
                   2577:     }
                   2578:     return;
                   2579: }
                   2580: 
                   2581: // ]]>
                   2582: </script>
                   2583: 
                   2584: ENDSCRIPT
                   2585: }
                   2586: 
1.267     raeburn  2587: sub ltitools_javascript {
                   2588:     my ($settings) = @_;
                   2589:     return unless(ref($settings) eq 'HASH');
                   2590:     my (%ordered,$total,%jstext);
                   2591:     $total = 0;
                   2592:     foreach my $item (keys(%{$settings})) {
                   2593:         if (ref($settings->{$item}) eq 'HASH') {
                   2594:             my $num = $settings->{$item}{'order'};
                   2595:             $ordered{$num} = $item;
                   2596:         }
                   2597:     }
                   2598:     $total = scalar(keys(%{$settings}));
                   2599:     my @jsarray = ();
                   2600:     foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
                   2601:         push(@jsarray,$ordered{$item});
                   2602:     }
                   2603:     my $jstext = '    var ltitools = Array('."'".join("','",@jsarray)."'".');'."\n";
                   2604:     return <<"ENDSCRIPT";
                   2605: <script type="text/javascript">
                   2606: // <![CDATA[
                   2607: function reorderLTI(form,item) {
                   2608:     var changedVal;
                   2609: $jstext
                   2610:     var newpos = 'ltitools_add_pos';
                   2611:     var maxh = 1 + $total;
                   2612:     var current = new Array;
                   2613:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
                   2614:     if (item == newpos) {
                   2615:         changedVal = newitemVal;
                   2616:     } else {
                   2617:         changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
                   2618:         current[newitemVal] = newpos;
                   2619:     }
                   2620:     for (var i=0; i<ltitools.length; i++) {
                   2621:         var elementName = 'ltitools_'+ltitools[i];
                   2622:         if (elementName != item) {
                   2623:             if (form.elements[elementName]) {
                   2624:                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   2625:                 current[currVal] = elementName;
                   2626:             }
                   2627:         }
                   2628:     }
                   2629:     var oldVal;
                   2630:     for (var j=0; j<maxh; j++) {
                   2631:         if (current[j] == undefined) {
                   2632:             oldVal = j;
                   2633:         }
                   2634:     }
                   2635:     if (oldVal < changedVal) {
                   2636:         for (var k=oldVal+1; k<=changedVal ; k++) {
                   2637:            var elementName = current[k];
                   2638:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   2639:         }
                   2640:     } else {
                   2641:         for (var k=changedVal; k<oldVal; k++) {
                   2642:             var elementName = current[k];
                   2643:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   2644:         }
                   2645:     }
                   2646:     return;
                   2647: }
                   2648: 
                   2649: // ]]>
                   2650: </script>
                   2651: 
                   2652: ENDSCRIPT
                   2653: }
                   2654: 
1.3       raeburn  2655: sub print_autoenroll {
1.30      raeburn  2656:     my ($dom,$settings,$rowtotal) = @_;
1.3       raeburn  2657:     my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.274     raeburn  2658:     my ($defdom,$runon,$runoff,$coownerson,$coownersoff,$failsafe);
1.3       raeburn  2659:     if (ref($settings) eq 'HASH') {
                   2660:         if (exists($settings->{'run'})) {
                   2661:             if ($settings->{'run'} eq '0') {
                   2662:                 $runoff = ' checked="checked" ';
                   2663:                 $runon = ' ';
                   2664:             } else {
                   2665:                 $runon = ' checked="checked" ';
                   2666:                 $runoff = ' ';
                   2667:             }
                   2668:         } else {
                   2669:             if ($autorun) {
                   2670:                 $runon = ' checked="checked" ';
                   2671:                 $runoff = ' ';
                   2672:             } else {
                   2673:                 $runoff = ' checked="checked" ';
                   2674:                 $runon = ' ';
                   2675:             }
                   2676:         }
1.129     raeburn  2677:         if (exists($settings->{'co-owners'})) {
                   2678:             if ($settings->{'co-owners'} eq '0') {
                   2679:                 $coownersoff = ' checked="checked" ';
                   2680:                 $coownerson = ' ';
                   2681:             } else {
                   2682:                 $coownerson = ' checked="checked" ';
                   2683:                 $coownersoff = ' ';
                   2684:             }
                   2685:         } else {
                   2686:             $coownersoff = ' checked="checked" ';
                   2687:             $coownerson = ' ';
                   2688:         }
1.3       raeburn  2689:         if (exists($settings->{'sender_domain'})) {
                   2690:             $defdom = $settings->{'sender_domain'};
                   2691:         }
1.274     raeburn  2692:         if (exists($settings->{'autofailsafe'})) {
                   2693:             $failsafe = $settings->{'autofailsafe'};
                   2694:         }
1.14      raeburn  2695:     } else {
                   2696:         if ($autorun) {
                   2697:             $runon = ' checked="checked" ';
                   2698:             $runoff = ' ';
                   2699:         } else {
                   2700:             $runoff = ' checked="checked" ';
                   2701:             $runon = ' ';
                   2702:         }
1.3       raeburn  2703:     }
                   2704:     my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39      raeburn  2705:     my $notif_sender;
                   2706:     if (ref($settings) eq 'HASH') {
                   2707:         $notif_sender = $settings->{'sender_uname'};
                   2708:     }
1.3       raeburn  2709:     my $datatable='<tr class="LC_odd_row">'.
                   2710:                   '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8       raeburn  2711:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3       raeburn  2712:                   '<input type="radio" name="autoenroll_run"'.
1.8       raeburn  2713:                   $runon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   2714:                   '<label><input type="radio" name="autoenroll_run"'.
1.14      raeburn  2715:                   $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3       raeburn  2716:                   '</tr><tr>'.
                   2717:                   '<td>'.&mt('Notification messages - sender').
1.8       raeburn  2718:                   '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3       raeburn  2719:                   &mt('username').':&nbsp;'.
                   2720:                   '<input type="text" name="sender_uname" value="'.
1.39      raeburn  2721:                   $notif_sender.'" size="10" />&nbsp;&nbsp;'.&mt('domain').
1.129     raeburn  2722:                   ':&nbsp;'.$domform.'</span></td></tr>'.
                   2723:                   '<tr class="LC_odd_row">'.
                   2724:                   '<td>'.&mt('Automatically assign co-ownership').'</td>'.
                   2725:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   2726:                   '<input type="radio" name="autoassign_coowners"'.
                   2727:                   $coownerson.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   2728:                   '<label><input type="radio" name="autoassign_coowners"'.
                   2729:                   $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.274     raeburn  2730:                   '</tr><tr>'.
                   2731:                   '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
                   2732:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
                   2733:                   '<input type="text" name="autoenroll_failsafe"'.
                   2734:                   ' value="'.$failsafe.'" size="4" /></td></tr>';
                   2735:     $$rowtotal += 4;
1.3       raeburn  2736:     return $datatable;
                   2737: }
                   2738: 
                   2739: sub print_autoupdate {
1.30      raeburn  2740:     my ($position,$dom,$settings,$rowtotal) = @_;
1.3       raeburn  2741:     my $datatable;
                   2742:     if ($position eq 'top') {
                   2743:         my $updateon = ' ';
                   2744:         my $updateoff = ' checked="checked" ';
                   2745:         my $classlistson = ' ';
                   2746:         my $classlistsoff = ' checked="checked" ';
                   2747:         if (ref($settings) eq 'HASH') {
                   2748:             if ($settings->{'run'} eq '1') {
                   2749:                 $updateon = $updateoff;
                   2750:                 $updateoff = ' ';
                   2751:             }
                   2752:             if ($settings->{'classlists'} eq '1') {
                   2753:                 $classlistson = $classlistsoff;
                   2754:                 $classlistsoff = ' ';
                   2755:             }
                   2756:         }
                   2757:         my %title = (
                   2758:                    run => 'Auto-update active?',
                   2759:                    classlists => 'Update information in classlists?',
                   2760:                     );
                   2761:         $datatable = '<tr class="LC_odd_row">'. 
                   2762:                   '<td>'.&mt($title{'run'}).'</td>'.
1.8       raeburn  2763:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3       raeburn  2764:                   '<input type="radio" name="autoupdate_run"'.
1.8       raeburn  2765:                   $updateon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   2766:                   '<label><input type="radio" name="autoupdate_run"'.
                   2767:                   $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3       raeburn  2768:                   '</tr><tr>'.
                   2769:                   '<td>'.&mt($title{'classlists'}).'</td>'.
1.8       raeburn  2770:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
                   2771:                   '<label><input type="radio" name="classlists"'.
                   2772:                   $classlistson.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   2773:                   '<label><input type="radio" name="classlists"'.
                   2774:                   $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3       raeburn  2775:                   '</tr>';
1.30      raeburn  2776:         $$rowtotal += 2;
1.131     raeburn  2777:     } elsif ($position eq 'middle') {
                   2778:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   2779:         my $numinrow = 3;
                   2780:         my $locknamesettings;
                   2781:         $datatable .= &insttypes_row($settings,$types,$usertypes,
                   2782:                                      $dom,$numinrow,$othertitle,
1.305     raeburn  2783:                                     'lockablenames',$rowtotal);
1.131     raeburn  2784:         $$rowtotal ++;
1.3       raeburn  2785:     } else {
1.44      raeburn  2786:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132     raeburn  2787:         my @fields = ('lastname','firstname','middlename','generation',
1.20      raeburn  2788:                       'permanentemail','id');
1.33      raeburn  2789:         my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3       raeburn  2790:         my $numrows = 0;
1.26      raeburn  2791:         if (ref($types) eq 'ARRAY') {
                   2792:             if (@{$types} > 0) {
                   2793:                 $datatable = 
                   2794:                     &usertype_update_row($settings,$usertypes,\%fieldtitles,
                   2795:                                          \@fields,$types,\$numrows);
1.30      raeburn  2796:                     $$rowtotal += @{$types}; 
1.26      raeburn  2797:             }
1.3       raeburn  2798:         }
                   2799:         $datatable .= 
                   2800:             &usertype_update_row($settings,{'default' => $othertitle},
                   2801:                                  \%fieldtitles,\@fields,['default'],
                   2802:                                  \$numrows);
1.30      raeburn  2803:         $$rowtotal ++;     
1.3       raeburn  2804:     }
                   2805:     return $datatable;
                   2806: }
                   2807: 
1.125     raeburn  2808: sub print_autocreate {
                   2809:     my ($dom,$settings,$rowtotal) = @_;
1.191     raeburn  2810:     my (%createon,%createoff,%currhash);
1.125     raeburn  2811:     my @types = ('xml','req');
                   2812:     if (ref($settings) eq 'HASH') {
                   2813:         foreach my $item (@types) {
                   2814:             $createoff{$item} = ' checked="checked" ';
                   2815:             $createon{$item} = ' ';
                   2816:             if (exists($settings->{$item})) {
                   2817:                 if ($settings->{$item}) {
                   2818:                     $createon{$item} = ' checked="checked" ';
                   2819:                     $createoff{$item} = ' ';
                   2820:                 }
                   2821:             }
                   2822:         }
1.210     raeburn  2823:         if ($settings->{'xmldc'} ne '') {
1.191     raeburn  2824:             $currhash{$settings->{'xmldc'}} = 1;
                   2825:         }
1.125     raeburn  2826:     } else {
                   2827:         foreach my $item (@types) {
                   2828:             $createoff{$item} = ' checked="checked" ';
                   2829:             $createon{$item} = ' ';
                   2830:         }
                   2831:     }
                   2832:     $$rowtotal += 2;
1.191     raeburn  2833:     my $numinrow = 2;
1.125     raeburn  2834:     my $datatable='<tr class="LC_odd_row">'.
                   2835:                   '<td>'.&mt('Create pending official courses from XML files').'</td>'.
                   2836:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   2837:                   '<input type="radio" name="autocreate_xml"'.
                   2838:                   $createon{'xml'}.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   2839:                   '<label><input type="radio" name="autocreate_xml"'.
1.143     raeburn  2840:                   $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
                   2841:                   '</td></tr><tr>'.
                   2842:                   '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
                   2843:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   2844:                   '<input type="radio" name="autocreate_req"'.
                   2845:                   $createon{'req'}.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   2846:                   '<label><input type="radio" name="autocreate_req"'.
                   2847:                   $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.191     raeburn  2848:     my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
                   2849:                                                    'autocreate_xmldc',%currhash);
1.247     raeburn  2850:     $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125     raeburn  2851:     if ($numdc > 1) {
1.247     raeburn  2852:         $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
                   2853:                       '</td><td class="LC_left_item">';
1.125     raeburn  2854:     } else {
1.247     raeburn  2855:         $datatable .= &mt('Course creation processed as:').
                   2856:                       '</td><td class="LC_right_item">';
1.125     raeburn  2857:     }
1.247     raeburn  2858:     $datatable .= $dctable.'</td></tr>';
1.191     raeburn  2859:     $$rowtotal += $rows;
1.125     raeburn  2860:     return $datatable;
                   2861: }
                   2862: 
1.23      raeburn  2863: sub print_directorysrch {
1.277     raeburn  2864:     my ($position,$dom,$settings,$rowtotal) = @_;
                   2865:     my $datatable;
                   2866:     if ($position eq 'top') {
                   2867:         my $instsrchon = ' ';
                   2868:         my $instsrchoff = ' checked="checked" ';
                   2869:         my ($exacton,$containson,$beginson);
                   2870:         my $instlocalon = ' ';
                   2871:         my $instlocaloff = ' checked="checked" ';
                   2872:         if (ref($settings) eq 'HASH') {
                   2873:             if ($settings->{'available'} eq '1') {
                   2874:                 $instsrchon = $instsrchoff;
                   2875:                 $instsrchoff = ' ';
                   2876:             }
                   2877:             if ($settings->{'localonly'} eq '1') {
                   2878:                 $instlocalon = $instlocaloff;
                   2879:                 $instlocaloff = ' ';
                   2880:             }
                   2881:             if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
                   2882:                 foreach my $type (@{$settings->{'searchtypes'}}) {
                   2883:                     if ($type eq 'exact') {
                   2884:                         $exacton = ' checked="checked" ';
                   2885:                     } elsif ($type eq 'contains') {
                   2886:                         $containson = ' checked="checked" ';
                   2887:                     } elsif ($type eq 'begins') {
                   2888:                         $beginson = ' checked="checked" ';
                   2889:                     }
                   2890:                 }
                   2891:             } else {
                   2892:                 if ($settings->{'searchtypes'} eq 'exact') {
                   2893:                     $exacton = ' checked="checked" ';
                   2894:                 } elsif ($settings->{'searchtypes'} eq 'contains') {
                   2895:                     $containson = ' checked="checked" ';
                   2896:                 } elsif ($settings->{'searchtypes'} eq 'specify') {
1.25      raeburn  2897:                     $exacton = ' checked="checked" ';
                   2898:                     $containson = ' checked="checked" ';
                   2899:                 }
                   2900:             }
1.277     raeburn  2901:         }
                   2902:         my ($searchtitles,$titleorder) = &sorted_searchtitles();
                   2903:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   2904: 
                   2905:         my $numinrow = 4;
                   2906:         my $cansrchrow = 0;
                   2907:         $datatable='<tr class="LC_odd_row">'.
                   2908:                    '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
                   2909:                    '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   2910:                    '<input type="radio" name="dirsrch_available"'.
                   2911:                    $instsrchon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   2912:                    '<label><input type="radio" name="dirsrch_available"'.
                   2913:                    $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
                   2914:                    '</tr><tr>'.
                   2915:                    '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
                   2916:                    '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   2917:                    '<input type="radio" name="dirsrch_instlocalonly"'.
                   2918:                    $instlocaloff.' value="0" />'.&mt('Yes').'</label>&nbsp;'.
                   2919:                    '<label><input type="radio" name="dirsrch_instlocalonly"'.
                   2920:                    $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
                   2921:                    '</tr>';
                   2922:         $$rowtotal += 2;
                   2923:         if (ref($usertypes) eq 'HASH') {
                   2924:             if (keys(%{$usertypes}) > 0) {
                   2925:                 $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
1.305     raeburn  2926:                                              $numinrow,$othertitle,'cansearch',
                   2927:                                              $rowtotal);
1.277     raeburn  2928:                 $cansrchrow = 1;
1.25      raeburn  2929:             }
1.23      raeburn  2930:         }
1.277     raeburn  2931:         if ($cansrchrow) {
                   2932:             $$rowtotal ++;
                   2933:             $datatable .= '<tr>';
                   2934:         } else {
                   2935:             $datatable .= '<tr class="LC_odd_row">';
1.26      raeburn  2936:         }
1.277     raeburn  2937:         $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
                   2938:                       '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
                   2939:         foreach my $title (@{$titleorder}) {
                   2940:             if (defined($searchtitles->{$title})) {
                   2941:                 my $check = ' ';
                   2942:                 if (ref($settings) eq 'HASH') {
                   2943:                     if (ref($settings->{'searchby'}) eq 'ARRAY') {
                   2944:                         if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
                   2945:                             $check = ' checked="checked" ';
                   2946:                         }
1.39      raeburn  2947:                     }
1.25      raeburn  2948:                 }
1.277     raeburn  2949:                 $datatable .= '<td class="LC_left_item">'.
                   2950:                               '<span class="LC_nobreak"><label>'.
                   2951:                               '<input type="checkbox" name="searchby" '.
                   2952:                               'value="'.$title.'"'.$check.'/>'.
                   2953:                               $searchtitles->{$title}.'</label></span></td>';
1.25      raeburn  2954:             }
                   2955:         }
1.277     raeburn  2956:         $datatable .= '</tr></table></td></tr>';
                   2957:         $$rowtotal ++;
                   2958:         if ($cansrchrow) {
                   2959:             $datatable .= '<tr class="LC_odd_row">';
                   2960:         } else {
                   2961:             $datatable .= '<tr>';
                   2962:         }
                   2963:         $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.   
                   2964:                       '<td class="LC_left_item" colspan="2">'.
                   2965:                       '<span class="LC_nobreak"><label>'.
                   2966:                       '<input type="checkbox" name="searchtypes" '.
                   2967:                       $exacton.' value="exact" />'.&mt('Exact match').
                   2968:                       '</label>&nbsp;'.
                   2969:                       '<label><input type="checkbox" name="searchtypes" '.
                   2970:                       $beginson.' value="begins" />'.&mt('Begins with').
                   2971:                       '</label>&nbsp;'.
                   2972:                       '<label><input type="checkbox" name="searchtypes" '.
                   2973:                       $containson.' value="contains" />'.&mt('Contains').
                   2974:                       '</label></span></td></tr>';
                   2975:         $$rowtotal ++;
1.26      raeburn  2976:     } else {
1.277     raeburn  2977:         my $domsrchon = ' checked="checked" ';
                   2978:         my $domsrchoff = ' ';
                   2979:         my $domlocalon = ' ';
                   2980:         my $domlocaloff = ' checked="checked" ';
                   2981:         if (ref($settings) eq 'HASH') {
                   2982:             if ($settings->{'lclocalonly'} eq '1') {
                   2983:                 $domlocalon = $domlocaloff;
                   2984:                 $domlocaloff = ' ';
                   2985:             }
                   2986:             if ($settings->{'lcavailable'} eq '0') {
                   2987:                 $domsrchoff = $domsrchon;
                   2988:                 $domsrchon = ' ';
                   2989:             }
                   2990:         }
                   2991:         $datatable='<tr class="LC_odd_row">'.
                   2992:                       '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
                   2993:                       '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   2994:                       '<input type="radio" name="dirsrch_domavailable"'.
                   2995:                       $domsrchon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   2996:                       '<label><input type="radio" name="dirsrch_domavailable"'.
                   2997:                       $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
                   2998:                       '</tr><tr>'.
                   2999:                       '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
                   3000:                       '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   3001:                       '<input type="radio" name="dirsrch_domlocalonly"'.
                   3002:                       $domlocaloff.' value="0" />'.&mt('Yes').'</label>&nbsp;'.
                   3003:                       '<label><input type="radio" name="dirsrch_domlocalonly"'.
                   3004:                       $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
                   3005:                       '</tr>';
                   3006:         $$rowtotal += 2;
1.26      raeburn  3007:     }
1.25      raeburn  3008:     return $datatable;
                   3009: }
                   3010: 
1.28      raeburn  3011: sub print_contacts {
1.286     raeburn  3012:     my ($position,$dom,$settings,$rowtotal) = @_;
1.28      raeburn  3013:     my $datatable;
                   3014:     my @contacts = ('adminemail','supportemail');
1.286     raeburn  3015:     my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
                   3016:         $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings);
                   3017:     if ($position eq 'top') {
                   3018:         if (ref($settings) eq 'HASH') {
                   3019:             foreach my $item (@contacts) {
                   3020:                 if (exists($settings->{$item})) {
                   3021:                     $to{$item} = $settings->{$item};
                   3022:                 }
                   3023:             }
                   3024:         }
                   3025:     } elsif ($position eq 'middle') {
                   3026:         @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
                   3027:                      'updatesmail','idconflictsmail');
1.288     raeburn  3028:         foreach my $type (@mailings) {
                   3029:             $otheremails{$type} = '';
                   3030:         }
1.286     raeburn  3031:     } else {
                   3032:         @mailings = ('helpdeskmail','otherdomsmail');
1.288     raeburn  3033:         foreach my $type (@mailings) {
                   3034:             $otheremails{$type} = '';
                   3035:         }
1.286     raeburn  3036:         $bccemails{'helpdeskmail'} = '';
                   3037:         $bccemails{'otherdomsmail'} = '';
                   3038:         $includestr{'helpdeskmail'} = '';
                   3039:         $includestr{'otherdomsmail'} = '';
                   3040:         ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
                   3041:     }
1.28      raeburn  3042:     if (ref($settings) eq 'HASH') {
1.286     raeburn  3043:         unless ($position eq 'top') {
                   3044:             foreach my $type (@mailings) {
                   3045:                 if (exists($settings->{$type})) {
                   3046:                     if (ref($settings->{$type}) eq 'HASH') {
                   3047:                         foreach my $item (@contacts) {
                   3048:                             if ($settings->{$type}{$item}) {
                   3049:                                 $checked{$type}{$item} = ' checked="checked" ';
                   3050:                             }
                   3051:                         }
                   3052:                         $otheremails{$type} = $settings->{$type}{'others'};
                   3053:                         if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
                   3054:                             $bccemails{$type} = $settings->{$type}{'bcc'};
                   3055:                             if ($settings->{$type}{'include'} ne '') {
                   3056:                                 ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
                   3057:                                 $includestr{$type} = &unescape($includestr{$type});
                   3058:                             }
                   3059:                         }
                   3060:                     }
                   3061:                 } elsif ($type eq 'lonstatusmail') {
                   3062:                     $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
                   3063:                 }
1.28      raeburn  3064:             }
                   3065:         }
1.286     raeburn  3066:         if ($position eq 'bottom') {
                   3067:             foreach my $type (@mailings) {
                   3068:                 $bccemails{$type} = $settings->{$type}{'bcc'};
                   3069:                 if ($settings->{$type}{'include'} ne '') {
                   3070:                     ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
                   3071:                     $includestr{$type} = &unescape($includestr{$type});
                   3072:                 }
                   3073:             }
                   3074:             if (ref($settings->{'helpform'}) eq 'HASH') {
                   3075:                 if (ref($fields) eq 'ARRAY') {
                   3076:                     foreach my $field (@{$fields}) {
                   3077:                         $currfield{$field} = $settings->{'helpform'}{$field};
1.28      raeburn  3078:                     }
1.286     raeburn  3079:                 }
                   3080:                 if (exists($settings->{'helpform'}{'maxsize'})) {
                   3081:                     $maxsize = $settings->{'helpform'}{'maxsize'};
                   3082:                 } else {
1.289     raeburn  3083:                     $maxsize = '1.0';
1.286     raeburn  3084:                 }
                   3085:             } else {
                   3086:                 if (ref($fields) eq 'ARRAY') {
                   3087:                     foreach my $field (@{$fields}) {
                   3088:                         $currfield{$field} = 'yes';
1.134     raeburn  3089:                     }
1.28      raeburn  3090:                 }
1.286     raeburn  3091:                 $maxsize = '1.0';
1.28      raeburn  3092:             }
                   3093:         }
                   3094:     } else {
1.286     raeburn  3095:         if ($position eq 'top') {
                   3096:             $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
                   3097:             $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
                   3098:             $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
                   3099:             $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.289     raeburn  3100:             $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.286     raeburn  3101:             $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
                   3102:             $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
                   3103:             $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
                   3104:         } elsif ($position eq 'bottom') {
                   3105:             $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
                   3106:             $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
                   3107:             if (ref($fields) eq 'ARRAY') {
                   3108:                 foreach my $field (@{$fields}) {
                   3109:                     $currfield{$field} = 'yes';
                   3110:                 }
                   3111:             }
                   3112:             $maxsize = '1.0';
                   3113:         }
1.28      raeburn  3114:     }
                   3115:     my ($titles,$short_titles) = &contact_titles();
                   3116:     my $rownum = 0;
                   3117:     my $css_class;
1.286     raeburn  3118:     if ($position eq 'top') {
                   3119:         foreach my $item (@contacts) {
                   3120:             $css_class = $rownum%2?' class="LC_odd_row"':'';
                   3121:             $datatable .= '<tr'.$css_class.'>'. 
                   3122:                           '<td><span class="LC_nobreak">'.$titles->{$item}.
                   3123:                           '</span></td><td class="LC_right_item">'.
                   3124:                           '<input type="text" name="'.$item.'" value="'.
                   3125:                           $to{$item}.'" /></td></tr>';
                   3126:             $rownum ++;
                   3127:         }
1.315     raeburn  3128:     } elsif ($position eq 'bottom') {
                   3129:         $css_class = $rownum%2?' class="LC_odd_row"':'';
                   3130:         $datatable .= '<tr'.$css_class.'>'.
                   3131:                       '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
                   3132:                       &mt('(e-mail, subject, and description always shown)').
                   3133:                       '</td><td class="LC_left_item">';
                   3134:         if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
                   3135:             (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
                   3136:             $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
                   3137:             foreach my $field (@{$fields}) {
                   3138:                 $datatable .= '<tr><td>'.$fieldtitles->{$field};
                   3139:                 if (($field eq 'screenshot') || ($field eq 'cc')) {
                   3140:                     $datatable .= ' '.&mt('(logged-in users)');
                   3141:                 }
                   3142:                 $datatable .='</td><td>';
                   3143:                 my $clickaction;
                   3144:                 if ($field eq 'screenshot') {
                   3145:                     $clickaction = ' onclick="screenshotSize(this);"';
                   3146:                 }
                   3147:                 if (ref($possoptions->{$field}) eq 'ARRAY') {
                   3148:                     foreach my $option (@{$possoptions->{$field}}) {
                   3149:                         my $checked;
                   3150:                         if ($currfield{$field} eq $option) {
                   3151:                             $checked = ' checked="checked"';
                   3152:                         }
                   3153:                         $datatable .= '<span class="LC_nobreak"><label>'.
                   3154:                                       '<input type="radio" name="helpform_'.$field.'" '.
                   3155:                                       'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
                   3156:                                       '</label></span>'.('&nbsp;'x2);
                   3157:                     }
                   3158:                 }
                   3159:                 if ($field eq 'screenshot') {
                   3160:                     my $display;
                   3161:                     if ($currfield{$field} eq 'no') {
                   3162:                         $display = ' style="display:none"';
                   3163:                     }
                   3164:                     $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.' />'.
                   3165:                                   '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
                   3166:                                   '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
                   3167:                 }
                   3168:                 $datatable .= '</td></tr>';
                   3169:             }
                   3170:             $datatable .= '</table>';
                   3171:         }
                   3172:         $datatable .= '</td></tr>'."\n";
                   3173:         $rownum ++;
                   3174:     }
                   3175:     unless ($position eq 'top') {
1.286     raeburn  3176:         foreach my $type (@mailings) {
                   3177:             $css_class = $rownum%2?' class="LC_odd_row"':'';
                   3178:             $datatable .= '<tr'.$css_class.'>'.
                   3179:                           '<td><span class="LC_nobreak">'.
                   3180:                           $titles->{$type}.': </span></td>'.
                   3181:                           '<td class="LC_left_item">';
                   3182:             if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
                   3183:                 $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
                   3184:             }
                   3185:             $datatable .= '<span class="LC_nobreak">';
                   3186:             foreach my $item (@contacts) {
                   3187:                 $datatable .= '<label>'.
                   3188:                               '<input type="checkbox" name="'.$type.'"'.
                   3189:                               $checked{$type}{$item}.
                   3190:                               ' value="'.$item.'" />'.$short_titles->{$item}.
                   3191:                               '</label>&nbsp;';
                   3192:             }
                   3193:             $datatable .= '</span><br />'.&mt('Others').':&nbsp;&nbsp;'.
                   3194:                           '<input type="text" name="'.$type.'_others" '.
                   3195:                           'value="'.$otheremails{$type}.'"  />';
                   3196:             my %locchecked;
                   3197:             if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
                   3198:                 foreach my $loc ('s','b') {
                   3199:                     if ($includeloc{$type} eq $loc) {
                   3200:                         $locchecked{$loc} = ' checked="checked"';
                   3201:                         last;
                   3202:                     }
                   3203:                 }
                   3204:                 $datatable .= '<br />'.&mt('Bcc:').('&nbsp;'x6).
                   3205:                               '<input type="text" name="'.$type.'_bcc" '.
                   3206:                               'value="'.$bccemails{$type}.'"  /></fieldset>'.
                   3207:                               '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
                   3208:                               &mt('Text automatically added to e-mail:').' '.
                   3209:                               '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br >'.
                   3210:                               '<span class="LC_nobreak">'.&mt('Location:').'&nbsp;'.
                   3211:                               '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
                   3212:                               ('&nbsp;'x2).
                   3213:                               '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
                   3214:                               '</span></fieldset>';
                   3215:             }
                   3216:             $datatable .= '</td></tr>'."\n";
                   3217:             $rownum ++;
                   3218:         }
1.28      raeburn  3219:     }
1.286     raeburn  3220:     if ($position eq 'middle') {
                   3221:         my %choices;
                   3222:         $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',
1.289     raeburn  3223:                                        &Apache::loncommon::modal_link('http://loncapa.org/core.html',
                   3224:                                        &mt('LON-CAPA core group - MSU'),600,500));
1.286     raeburn  3225:         $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
                   3226:                                         &Apache::loncommon::modal_link('http://loncapa.org/core.html',
                   3227:                                         &mt('LON-CAPA core group - MSU'),600,500));
                   3228:         my @toggles = ('reporterrors','reportupdates');
                   3229:         my %defaultchecked = ('reporterrors'  => 'on',
                   3230:                               'reportupdates' => 'on');
                   3231:         (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
                   3232:                                                    \%choices,$rownum);
                   3233:         $datatable .= $reports;
                   3234:     } elsif ($position eq 'bottom') {
1.315     raeburn  3235:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   3236:         my (@posstypes,%usertypeshash);
                   3237:         if (ref($types) eq 'ARRAY') {
                   3238:             @posstypes = @{$types};
                   3239:         }
                   3240:         if (@posstypes) {
                   3241:             if (ref($usertypes) eq 'HASH') {
                   3242:                 %usertypeshash = %{$usertypes};
                   3243:             }
                   3244:             my @overridden;
                   3245:             my $numinrow = 4;
                   3246:             if (ref($settings) eq 'HASH') {
                   3247:                 if (ref($settings->{'overrides'}) eq 'HASH') {
                   3248:                     foreach my $key (sort(keys(%{$settings->{'overrides'}}))) {
                   3249:                         if (ref($settings->{'overrides'}{$key}) eq 'HASH') {
                   3250:                             push(@overridden,$key);
                   3251:                             foreach my $item (@contacts) {
                   3252:                                 if ($settings->{'overrides'}{$key}{$item}) {
                   3253:                                     $checked{'override_'.$key}{$item} = ' checked="checked" ';
                   3254:                                 }
                   3255:                             }
                   3256:                             $otheremails{'override_'.$key} = $settings->{'overrides'}{$key}{'others'};
                   3257:                             $bccemails{'override_'.$key} = $settings->{'overrides'}{$key}{'bcc'};
                   3258:                             $includeloc{'override_'.$key} = '';
                   3259:                             $includestr{'override_'.$key} = '';
                   3260:                             if ($settings->{'overrides'}{$key}{'include'} ne '') {
                   3261:                                 ($includeloc{'override_'.$key},$includestr{'override_'.$key}) = 
                   3262:                                     split(/:/,$settings->{'overrides'}{$key}{'include'},2);
                   3263:                                 $includestr{'override_'.$key} = &unescape($includestr{'override_'.$key});
                   3264:                             }
1.286     raeburn  3265:                         }
                   3266:                     }
                   3267:                 }
1.315     raeburn  3268:             }
                   3269:             my $customclass = 'LC_helpdesk_override';
                   3270:             my $optionsprefix = 'LC_options_helpdesk_';
                   3271: 
                   3272:             my $onclicktypes = "toggleHelpdeskRow(this.form,'overrides','$customclass','$optionsprefix');";
                   3273:  
                   3274:             $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
                   3275:                                          $numinrow,$othertitle,'overrides',
                   3276:                                          \$rownum,$onclicktypes,$customclass);
                   3277:             $rownum ++;
                   3278:             $usertypeshash{'default'} = $othertitle;
                   3279:             foreach my $status (@posstypes) {
                   3280:                 my $css_class;
                   3281:                 if ($rownum%2) {
                   3282:                     $css_class = 'LC_odd_row ';
                   3283:                 }
                   3284:                 $css_class .= $customclass;
                   3285:                 my $rowid = $optionsprefix.$status;
                   3286:                 my $hidden = 1;
                   3287:                 my $currstyle = 'display:none';
                   3288:                 if (grep(/^\Q$status\E$/,@overridden)) {
                   3289:                     $currstyle = 'display:table-row';
                   3290:                     $hidden = 0;
                   3291:                 }
                   3292:                 my $key = 'override_'.$status;
                   3293:                 $datatable .= &overridden_helpdesk($checked{$key},$otheremails{$key},$bccemails{$key},
                   3294:                                                   $includeloc{$key},$includestr{$key},$status,$rowid,
                   3295:                                                   $usertypeshash{$status},$css_class,$currstyle,
                   3296:                                                   \@contacts,$short_titles);
                   3297:                 unless ($hidden) {
                   3298:                     $rownum ++;
1.286     raeburn  3299:                 }
                   3300:             }
1.134     raeburn  3301:         }
1.28      raeburn  3302:     }
1.30      raeburn  3303:     $$rowtotal += $rownum;
1.28      raeburn  3304:     return $datatable;
                   3305: }
                   3306: 
1.315     raeburn  3307: sub overridden_helpdesk {
                   3308:     my ($checked,$otheremails,$bccemails,$includeloc,$includestr,$type,$rowid,
                   3309:         $typetitle,$css_class,$rowstyle,$contacts,$short_titles) = @_;
                   3310:     my $class = 'LC_left_item';
                   3311:     if ($css_class) {
                   3312:         $css_class = ' class="'.$css_class.'"';
                   3313:     }
                   3314:     if ($rowid) {
                   3315:         $rowid = ' id="'.$rowid.'"';
                   3316:     }
                   3317:     if ($rowstyle) {
                   3318:         $rowstyle = ' style="'.$rowstyle.'"';
                   3319:     }
                   3320:     my ($output,$description);
                   3321:     $description = &mt('Helpdesk requests from: [_1] in this domain (overrides default)',"<b>$typetitle</b>");
                   3322:     $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
                   3323:               "<td>$description</td>\n".
                   3324:               '<td class="'.$class.'" colspan="2">'.
                   3325:               '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>'.
                   3326:               '<span class="LC_nobreak">';
                   3327:     if (ref($contacts) eq 'ARRAY') {
                   3328:         foreach my $item (@{$contacts}) {
                   3329:             my $check;
                   3330:             if (ref($checked) eq 'HASH') {
                   3331:                $check = $checked->{$item};
                   3332:             }
                   3333:             my $title;
                   3334:             if (ref($short_titles) eq 'HASH') {
                   3335:                 $title = $short_titles->{$item}; 
                   3336:             }
                   3337:             $output .= '<label>'.
                   3338:                        '<input type="checkbox" name="override_'.$type.'"'.$check.
                   3339:                        ' value="'.$item.'" />'.$title.'</label>&nbsp;';
                   3340:         }
                   3341:     }
                   3342:     $output .= '</span><br />'.&mt('Others').':&nbsp;&nbsp;'.
                   3343:                '<input type="text" name="override_'.$type.'_others" '.
                   3344:                'value="'.$otheremails.'"  />';
                   3345:     my %locchecked;
                   3346:     foreach my $loc ('s','b') {
                   3347:         if ($includeloc eq $loc) {
                   3348:             $locchecked{$loc} = ' checked="checked"';
                   3349:             last;
                   3350:         }
                   3351:     }
                   3352:     $output .= '<br />'.&mt('Bcc:').('&nbsp;'x6).
                   3353:                '<input type="text" name="override_'.$type.'_bcc" '.
                   3354:                'value="'.$bccemails.'"  /></fieldset>'.
                   3355:                '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
                   3356:                &mt('Text automatically added to e-mail:').' '.
                   3357:                '<input type="text" name="override_'.$type.'_includestr" value="'.$includestr.'" /><br >'.
                   3358:                '<span class="LC_nobreak">'.&mt('Location:').'&nbsp;'.
                   3359:                '<label><input type="radio" name="override_'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
                   3360:                ('&nbsp;'x2).
                   3361:                '<label><input type="radio" name="override_'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
                   3362:                '</span></fieldset>'.
                   3363:                '</td></tr>'."\n";
                   3364:     return $output;
                   3365: }
                   3366: 
1.286     raeburn  3367: sub contacts_javascript {
                   3368:     return <<"ENDSCRIPT";
                   3369: 
                   3370: <script type="text/javascript">
                   3371: // <![CDATA[
                   3372: 
                   3373: function screenshotSize(field) {
                   3374:     if (document.getElementById('help_screenshotsize')) {
                   3375:         if (field.value == 'no') {
1.289     raeburn  3376:             document.getElementById('help_screenshotsize').style.display="none";
1.286     raeburn  3377:         } else {
                   3378:             document.getElementById('help_screenshotsize').style.display="";
                   3379:         }
                   3380:     }
                   3381:     return;
                   3382: }
                   3383: 
1.315     raeburn  3384: function toggleHelpdeskRow(form,checkbox,target,prefix,docount) {
                   3385:     if (form.elements[checkbox].length != undefined) {
                   3386:         var count = 0;
                   3387:         if (docount) {
                   3388:             for (var i=0; i<form.elements[checkbox].length; i++) {
                   3389:                 if (form.elements[checkbox][i].checked) {
                   3390:                     count ++;
                   3391:                 }
                   3392:             }
                   3393:         }
                   3394:         for (var i=0; i<form.elements[checkbox].length; i++) {
                   3395:             var type = form.elements[checkbox][i].value;
                   3396:             if (document.getElementById(prefix+type)) {
                   3397:                 if (form.elements[checkbox][i].checked) {
                   3398:                     document.getElementById(prefix+type).style.display = 'table-row';
                   3399:                     if (count % 2 == 1) {
                   3400:                         document.getElementById(prefix+type).className = target+' LC_odd_row';
                   3401:                     } else {
                   3402:                         document.getElementById(prefix+type).className = target;
                   3403:                     }
                   3404:                     count ++;
                   3405:                 } else {
                   3406:                     document.getElementById(prefix+type).style.display = 'none';
                   3407:                 }
                   3408:             }
                   3409:         }
                   3410:     }
                   3411:     return;
                   3412: }
                   3413: 
                   3414: 
1.286     raeburn  3415: // ]]>
                   3416: </script>
                   3417: 
                   3418: ENDSCRIPT
                   3419: }
                   3420: 
1.118     jms      3421: sub print_helpsettings {
1.282     raeburn  3422:     my ($position,$dom,$settings,$rowtotal) = @_;
                   3423:     my $confname = $dom.'-domainconfig';
1.285     raeburn  3424:     my $formname = 'display';
1.168     raeburn  3425:     my ($datatable,$itemcount);
1.282     raeburn  3426:     if ($position eq 'top') {
                   3427:         $itemcount = 1;
                   3428:         my (%choices,%defaultchecked,@toggles);
                   3429:         $choices{'submitbugs'} = &mt('Display link to: [_1]?',
                   3430:                                      &Apache::loncommon::modal_link('http://bugs.loncapa.org',
                   3431:                                      &mt('LON-CAPA bug tracker'),600,500));
                   3432:         %defaultchecked = ('submitbugs' => 'on');
                   3433:         @toggles = ('submitbugs');
                   3434:         ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
                   3435:                                                      \%choices,$itemcount);
                   3436:         $$rowtotal ++;
                   3437:     } else {
                   3438:         my $css_class;
                   3439:         my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285     raeburn  3440:         my (%customroles,%ordered,%current);
1.301     raeburn  3441:         if (ref($settings) eq 'HASH') {
                   3442:             if (ref($settings->{'adhoc'}) eq 'HASH') {
                   3443:                 %current = %{$settings->{'adhoc'}};
                   3444:             }
1.285     raeburn  3445:         }
                   3446:         my $count = 0;
                   3447:         foreach my $key (sort(keys(%existing))) {
1.282     raeburn  3448:             if ($key=~/^rolesdef\_(\w+)$/) {
                   3449:                 my $rolename = $1;
1.285     raeburn  3450:                 my (%privs,$order);
1.282     raeburn  3451:                 ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
                   3452:                 $customroles{$rolename} = \%privs;
1.285     raeburn  3453:                 if (ref($current{$rolename}) eq 'HASH') {
                   3454:                     $order = $current{$rolename}{'order'};
                   3455:                 }
                   3456:                 if ($order eq '') {
                   3457:                     $order = $count;
                   3458:                 }
                   3459:                 $ordered{$order} = $rolename;
                   3460:                 $count++;
                   3461:             }
                   3462:         }
                   3463:         my $maxnum = scalar(keys(%ordered));
                   3464:         my @roles_by_num = ();
                   3465:         foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
                   3466:             push(@roles_by_num,$item);
                   3467:         }
                   3468:         my $context = 'domprefs';
                   3469:         my $crstype = 'Course';
                   3470:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292     raeburn  3471:         my @accesstypes = ('all','dh','da','none');
1.285     raeburn  3472:         my ($numstatustypes,@jsarray);
                   3473:         if (ref($types) eq 'ARRAY') {
                   3474:             if (@{$types} > 0) {
                   3475:                 $numstatustypes = scalar(@{$types});
                   3476:                 push(@accesstypes,'status');
                   3477:                 @jsarray = ('bystatus');
1.282     raeburn  3478:             }
                   3479:         }
1.290     raeburn  3480:         my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285     raeburn  3481:         if (keys(%domhelpdesk)) {
                   3482:             push(@accesstypes,('inc','exc'));
                   3483:             push(@jsarray,('notinc','notexc'));
                   3484:         }
                   3485:         my $hiddenstr = join("','",@jsarray);
                   3486:         $datatable .= &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname);
1.282     raeburn  3487:         my $context = 'domprefs';
                   3488:         my $crstype = 'Course';
1.285     raeburn  3489:         my $prefix = 'helproles_';
                   3490:         my $add_class = 'LC_hidden';
                   3491:         foreach my $num (@roles_by_num) {
                   3492:             my $role = $ordered{$num};
                   3493:             my ($desc,$access,@statuses);
                   3494:             if (ref($current{$role}) eq 'HASH') {
                   3495:                 $desc = $current{$role}{'desc'};
                   3496:                 $access = $current{$role}{'access'};
                   3497:                 if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
                   3498:                     @statuses = @{$current{$role}{'insttypes'}};
                   3499:                 }
                   3500:             }
                   3501:             if ($desc eq '') {
                   3502:                 $desc = $role;
                   3503:             }
                   3504:             my $identifier = 'custhelp'.$num;
1.282     raeburn  3505:             my %full=();
                   3506:             my %levels= (
                   3507:                          course => {},
                   3508:                          domain => {},
                   3509:                          system => {},
                   3510:                         );
                   3511:             my %levelscurrent=(
                   3512:                                course => {},
                   3513:                                domain => {},
                   3514:                                system => {},
                   3515:                               );
                   3516:             &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
                   3517:             my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
                   3518:             $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.285     raeburn  3519:             my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
1.306     raeburn  3520:             $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><b>'.$role.'</b><br />'.
1.285     raeburn  3521:                           '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
                   3522:             for (my $k=0; $k<=$maxnum; $k++) {
                   3523:                 my $vpos = $k+1;
                   3524:                 my $selstr;
                   3525:                 if ($k == $num) {
                   3526:                     $selstr = ' selected="selected" ';
                   3527:                 }
                   3528:                 $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   3529:             }
                   3530:             $datatable .= '</select>'.('&nbsp;'x2).
                   3531:                           '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
                   3532:                           '</td>'.
                   3533:                           '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
                   3534:                           &mt('Name shown to users:').
                   3535:                           '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
                   3536:                           '</fieldset>'.
                   3537:                           &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
                   3538:                                                 $othertitle,$usertypes,$types,\%domhelpdesk).
                   3539:                           '<fieldset>'.
                   3540:                           '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
1.282     raeburn  3541:                           &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
1.285     raeburn  3542:                                                                    \%levelscurrent,$identifier,
                   3543:                                                                    'LC_hidden',$prefix.$num.'_privs').
                   3544:                           '</fieldset></td>';
1.282     raeburn  3545:             $itemcount ++;
                   3546:         }
                   3547:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   3548:         my $newcust = 'custhelp'.$count;
                   3549:         my (%privs,%levelscurrent);
                   3550:         my %full=();
                   3551:         my %levels= (
                   3552:                      course => {},
                   3553:                      domain => {},
                   3554:                      system => {},
                   3555:                     );
                   3556:         &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
                   3557:         my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.285     raeburn  3558:         my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
1.306     raeburn  3559:         $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><span class="LC_nobreak"><label>'.
1.285     raeburn  3560:                       '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
                   3561:                       '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
                   3562:         for (my $k=0; $k<$maxnum+1; $k++) {
                   3563:             my $vpos = $k+1;
                   3564:             my $selstr;
                   3565:             if ($k == $maxnum) {
                   3566:                 $selstr = ' selected="selected" ';
                   3567:             }
                   3568:             $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   3569:         }
                   3570:         $datatable .= '</select>&nbsp;'."\n".
1.282     raeburn  3571:                       '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
                   3572:                       '</label></span></td>'.
1.285     raeburn  3573:                       '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
                   3574:                       '<span class="LC_nobreak">'.
                   3575:                       &mt('Internal name:').
                   3576:                       '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
                   3577:                       '</span>'.('&nbsp;'x4).
                   3578:                       '<span class="LC_nobreak">'.
                   3579:                       &mt('Name shown to users:').
                   3580:                       '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
                   3581:                       '</span></fieldset>'.
                   3582:                        &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
                   3583:                                              $usertypes,$types,\%domhelpdesk).
                   3584:                       '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
1.282     raeburn  3585:                       &Apache::lonuserutils::custom_role_header($context,$crstype,
                   3586:                                                                 \@templateroles,$newcust).
                   3587:                       &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
                   3588:                                                                \%levelscurrent,$newcust).
1.285     raeburn  3589:                       '</fieldset></td></tr>';
1.282     raeburn  3590:         $count ++;
                   3591:         $$rowtotal += $count;
                   3592:     }
1.166     raeburn  3593:     return $datatable;
1.121     raeburn  3594: }
                   3595: 
1.285     raeburn  3596: sub adhocbutton {
                   3597:     my ($prefix,$num,$field,$visibility) = @_;
                   3598:     my %lt = &Apache::lonlocal::texthash(
                   3599:                                           show => 'Show details',
                   3600:                                           hide => 'Hide details',
                   3601:                                         );
                   3602:     return '<span style="text-decoration:line-through; font-weight: normal;">'.('&nbsp;'x10).
                   3603:            '</span>'.('&nbsp;'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
                   3604:            ' value="'.$lt{$visibility}.'" style="height:20px;" '.
                   3605:            'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.('&nbsp;'x2);
                   3606: }
                   3607: 
                   3608: sub helpsettings_javascript {
                   3609:     my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
                   3610:     return unless(ref($roles_by_num) eq 'ARRAY');
                   3611:     my %html_js_lt = &Apache::lonlocal::texthash(
                   3612:                                           show => 'Show details',
                   3613:                                           hide => 'Hide details',
                   3614:                                         );
                   3615:     &html_escape(\%html_js_lt);
                   3616:     my $jstext = '    var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
                   3617:     return <<"ENDSCRIPT";
                   3618: <script type="text/javascript">
                   3619: // <![CDATA[
                   3620: 
                   3621: function reorderHelpRoles(form,item) {
                   3622:     var changedVal;
                   3623: $jstext
                   3624:     var newpos = 'helproles_${total}_pos';
                   3625:     var maxh = 1 + $total;
                   3626:     var current = new Array();
                   3627:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
                   3628:     if (item == newpos) {
                   3629:         changedVal = newitemVal;
                   3630:     } else {
                   3631:         changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
                   3632:         current[newitemVal] = newpos;
                   3633:     }
                   3634:     for (var i=0; i<helproles.length; i++) {
                   3635:         var elementName = 'helproles_'+helproles[i]+'_pos';
                   3636:         if (elementName != item) {
                   3637:             if (form.elements[elementName]) {
                   3638:                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   3639:                 current[currVal] = elementName;
                   3640:             }
                   3641:         }
                   3642:     }
                   3643:     var oldVal;
                   3644:     for (var j=0; j<maxh; j++) {
                   3645:         if (current[j] == undefined) {
                   3646:             oldVal = j;
                   3647:         }
                   3648:     }
                   3649:     if (oldVal < changedVal) {
                   3650:         for (var k=oldVal+1; k<=changedVal ; k++) {
                   3651:            var elementName = current[k];
                   3652:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   3653:         }
                   3654:     } else {
                   3655:         for (var k=changedVal; k<oldVal; k++) {
                   3656:             var elementName = current[k];
                   3657:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   3658:         }
                   3659:     }
                   3660:     return;
                   3661: }
                   3662: 
                   3663: function helpdeskAccess(num) {
                   3664:     var curraccess = null;
                   3665:     if (document.$formname.elements['helproles_'+num+'_access'].length) {
                   3666:         for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
                   3667:             if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
                   3668:                 curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
                   3669:             }
                   3670:         }
                   3671:     }
                   3672:     var shown = Array();
                   3673:     var hidden = Array();
                   3674:     if (curraccess == 'none') {
                   3675:         hidden = Array('$hiddenstr');
                   3676:     } else {
                   3677:         if (curraccess == 'status') {
                   3678:             shown = Array('bystatus');
                   3679:             hidden = Array('notinc','notexc');
                   3680:         } else {
                   3681:             if (curraccess == 'exc') {
                   3682:                 shown = Array('notexc');
                   3683:                 hidden = Array('notinc','bystatus');
                   3684:             }
                   3685:             if (curraccess == 'inc') {
                   3686:                 shown = Array('notinc');
                   3687:                 hidden = Array('notexc','bystatus');
                   3688:             }
1.293     raeburn  3689:             if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
1.285     raeburn  3690:                 hidden = Array('notinc','notexc','bystatus');
                   3691:             }
                   3692:         }
                   3693:     }
                   3694:     if (hidden.length > 0) {
                   3695:         for (var i=0; i<hidden.length; i++) {
                   3696:             if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
                   3697:                 document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
                   3698:             }
                   3699:         }
                   3700:     }
                   3701:     if (shown.length > 0) {
                   3702:         for (var i=0; i<shown.length; i++) {
                   3703:             if (document.getElementById('helproles_'+num+'_'+shown[i])) {
                   3704:                 if (shown[i] == 'privs') {
                   3705:                     document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
                   3706:                 } else {
                   3707:                     document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
                   3708:                 }
                   3709:             }
                   3710:         }
                   3711:     }
                   3712:     return;
                   3713: }
                   3714: 
                   3715: function toggleHelpdeskItem(num,field) {
                   3716:     if (document.getElementById('helproles_'+num+'_'+field)) {
                   3717:         if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
1.289     raeburn  3718:             document.getElementById('helproles_'+num+'_'+field).className =
1.285     raeburn  3719:                 document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
                   3720:             if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
                   3721:                 document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
                   3722:             }
                   3723:         } else {
                   3724:             document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
                   3725:             if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
                   3726:                 document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
                   3727:             }
                   3728:         }
                   3729:     }
                   3730:     return;
                   3731: }
                   3732: 
                   3733: // ]]>
                   3734: </script>
                   3735: 
                   3736: ENDSCRIPT
                   3737: }
                   3738: 
                   3739: sub helpdeskroles_access {
                   3740:     my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
                   3741:         $usertypes,$types,$domhelpdesk) = @_;
                   3742:     return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
                   3743:     my %lt = &Apache::lonlocal::texthash(
                   3744:                     'rou'    => 'Role usage',
                   3745:                     'whi'    => 'Which helpdesk personnel may use this role?',
1.292     raeburn  3746:                     'all'    => 'All with domain helpdesk or helpdesk assistant role',
                   3747:                     'dh'     => 'All with domain helpdesk role',
                   3748:                     'da'     => 'All with domain helpdesk assistant role',
1.285     raeburn  3749:                     'none'   => 'None',
                   3750:                     'status' => 'Determined based on institutional status',
                   3751:                     'inc'    => 'Include all, but exclude specific personnel',
                   3752:                     'exc'    => 'Exclude all, but include specific personnel',
                   3753:                   );
                   3754:     my %usecheck = (
                   3755:                      all => ' checked="checked"',
                   3756:                    );
                   3757:     my %displaydiv = (
                   3758:                       status => 'none',
                   3759:                       inc    => 'none',
                   3760:                       exc    => 'none',
                   3761:                       priv   => 'block',
                   3762:                      );
                   3763:     my $output;
                   3764:     if (ref($current) eq 'HASH') {
                   3765:         if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
                   3766:             if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
                   3767:                 $usecheck{$current->{access}} = $usecheck{'all'};
                   3768:                 delete($usecheck{'all'});
                   3769:                 if ($current->{access} =~ /^(status|inc|exc)$/) {
                   3770:                     my $access = $1;
                   3771:                     $displaydiv{$access} = 'inline';
                   3772:                 } elsif ($current->{access} eq 'none') {
                   3773:                     $displaydiv{'priv'} = 'none';
                   3774:                 }
                   3775:             }
                   3776:         }
                   3777:     }
                   3778:     $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
                   3779:               '<p>'.$lt{'whi'}.'</p>';
                   3780:     foreach my $access (@{$accesstypes}) {
                   3781:         $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
                   3782:                    ' onclick="helpdeskAccess('."'$num'".');" />'.
                   3783:                    $lt{$access}.'</label>';
                   3784:         if ($access eq 'status') {
                   3785:             $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
                   3786:                        &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
                   3787:                                                                  $othertitle,$usertypes,$types).
                   3788:                        '</div>';
                   3789:         } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
                   3790:             $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
                   3791:                        &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
                   3792:                        '</div>';
                   3793:         } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
                   3794:             $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
                   3795:                        &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
                   3796:                        '</div>';
                   3797:         }
                   3798:         $output .= '</p>';
                   3799:     }
                   3800:     $output .= '</fieldset>';
                   3801:     return $output;
                   3802: }
                   3803: 
1.121     raeburn  3804: sub radiobutton_prefs {
1.192     raeburn  3805:     my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.257     raeburn  3806:         $additional,$align) = @_;
1.121     raeburn  3807:     return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
                   3808:                    (ref($choices) eq 'HASH'));
                   3809: 
1.170     raeburn  3810:     my (%checkedon,%checkedoff,$datatable,$css_class);
1.121     raeburn  3811: 
                   3812:     foreach my $item (@{$toggles}) {
                   3813:         if ($defaultchecked->{$item} eq 'on') {
1.118     jms      3814:             $checkedon{$item} = ' checked="checked" ';
                   3815:             $checkedoff{$item} = ' ';
1.121     raeburn  3816:         } elsif ($defaultchecked->{$item} eq 'off') {
1.118     jms      3817:             $checkedoff{$item} = ' checked="checked" ';
                   3818:             $checkedon{$item} = ' ';
                   3819:         }
                   3820:     }
                   3821:     if (ref($settings) eq 'HASH') {
1.121     raeburn  3822:         foreach my $item (@{$toggles}) {
1.118     jms      3823:             if ($settings->{$item} eq '1') {
                   3824:                 $checkedon{$item} =  ' checked="checked" ';
                   3825:                 $checkedoff{$item} = ' ';
                   3826:             } elsif ($settings->{$item} eq '0') {
                   3827:                 $checkedoff{$item} =  ' checked="checked" ';
                   3828:                 $checkedon{$item} = ' ';
                   3829:             }
                   3830:         }
1.121     raeburn  3831:     }
1.192     raeburn  3832:     if ($onclick) {
                   3833:         $onclick = ' onclick="'.$onclick.'"';
                   3834:     }
1.121     raeburn  3835:     foreach my $item (@{$toggles}) {
1.118     jms      3836:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121     raeburn  3837:         $datatable .=
1.306     raeburn  3838:             '<tr'.$css_class.'><td style="vertical-align: top">'.
1.192     raeburn  3839:             '<span class="LC_nobreak">'.$choices->{$item}.
1.257     raeburn  3840:             '</span></td>';
                   3841:         if ($align eq 'left') {
                   3842:             $datatable .= '<td class="LC_left_item">';
                   3843:         } else {
                   3844:             $datatable .= '<td class="LC_right_item">';
                   3845:         }
1.289     raeburn  3846:         $datatable .=
1.257     raeburn  3847:             '<span class="LC_nobreak">'.
1.118     jms      3848:             '<label><input type="radio" name="'.
1.192     raeburn  3849:             $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118     jms      3850:             '</label>&nbsp;<label><input type="radio" name="'.$item.'" '.
1.192     raeburn  3851:             $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
                   3852:             '</span>'.$additional.
                   3853:             '</td>'.
1.118     jms      3854:             '</tr>';
                   3855:         $itemcount ++;
1.121     raeburn  3856:     }
                   3857:     return ($datatable,$itemcount);
                   3858: }
                   3859: 
1.267     raeburn  3860: sub print_ltitools {
                   3861:     my ($dom,$settings,$rowtotal) = @_;
                   3862:     my $rownum = 0;
                   3863:     my $css_class;
                   3864:     my $itemcount = 1;
                   3865:     my $maxnum = 0;
                   3866:     my %ordered;
                   3867:     if (ref($settings) eq 'HASH') {
                   3868:         foreach my $item (keys(%{$settings})) {
                   3869:             if (ref($settings->{$item}) eq 'HASH') {
                   3870:                 my $num = $settings->{$item}{'order'};
                   3871:                 $ordered{$num} = $item;
                   3872:             }
                   3873:         }
                   3874:     }
                   3875:     my $confname = $dom.'-domainconfig';
                   3876:     my $switchserver = &check_switchserver($dom,$confname);
                   3877:     my $maxnum = scalar(keys(%ordered));
                   3878:     my $datatable = &ltitools_javascript($settings);
                   3879:     my %lt = &ltitools_names();
                   3880:     my @courseroles = ('cc','in','ta','ep','st');
                   3881:     my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
                   3882:     my @fields = ('fullname','firstname','lastname','email','user','roles');
                   3883:     if (keys(%ordered)) {
                   3884:         my @items = sort { $a <=> $b } keys(%ordered);
                   3885:         for (my $i=0; $i<@items; $i++) {
                   3886:             $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   3887:             my $item = $ordered{$items[$i]};
                   3888:             my ($title,$key,$secret,$url,$imgsrc,$version);
                   3889:             if (ref($settings->{$item}) eq 'HASH') {
                   3890:                 $title = $settings->{$item}->{'title'};
                   3891:                 $url = $settings->{$item}->{'url'};
                   3892:                 $key = $settings->{$item}->{'key'};
                   3893:                 $secret = $settings->{$item}->{'secret'};
                   3894:                 my $image = $settings->{$item}->{'image'};
                   3895:                 if ($image ne '') {
                   3896:                     $imgsrc = '<img src="'.$image.'" alt="'.&mt('Tool Provider icon').'" />';
                   3897:                 }
                   3898:             }
                   3899:             my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'ltitools_".$item."'".');"';
                   3900:             $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
                   3901:                          .'<select name="ltitools_'.$item.'"'.$chgstr.'>';
                   3902:             for (my $k=0; $k<=$maxnum; $k++) {
                   3903:                 my $vpos = $k+1;
                   3904:                 my $selstr;
                   3905:                 if ($k == $i) {
                   3906:                     $selstr = ' selected="selected" ';
                   3907:                 }
                   3908:                 $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   3909:             }
                   3910:             $datatable .= '</select>'.('&nbsp;'x2).
                   3911:                 '<label><input type="checkbox" name="ltitools_del" value="'.$item.'" />'.
                   3912:                 &mt('Delete?').'</label></span></td>'.
                   3913:                 '<td colspan="2">'.
                   3914:                 '<fieldset><legend>'.&mt('Required settings').'</legend>'.
                   3915:                 '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="30" name="ltitools_title_'.$i.'" value="'.$title.'" /></span> '.
                   3916:                 ('&nbsp;'x2).
                   3917:                 '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_version_'.$i.'">'.
                   3918:                 '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
                   3919:                 ('&nbsp;'x2).
                   3920:                 '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_msgtype_'.$i.'">'.
                   3921:                 '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
                   3922:                 '<br /><br />'.
                   3923:                 '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="30" name="ltitools_url_'.$i.'"'.
                   3924:                 ' value="'.$url.'" /></span>'.
                   3925:                 ('&nbsp;'x2).
                   3926:                 '<span class="LC_nobreak">'.$lt{'key'}.
                   3927:                 '<input type="text" size="25" name="ltitools_key_'.$i.'" value="'.$key.'" /></span> '.
                   3928:                 ('&nbsp;'x2).
                   3929:                 '<span class="LC_nobreak">'.$lt{'secret'}.':'.
                   3930:                 '<input type="password" size="20" name="ltitools_secret_'.$i.'" value="'.$secret.'" />'.
                   3931:                 '<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>'.
                   3932:                 '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" /></span>'.
                   3933:                 '</fieldset>'.
                   3934:                 '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
                   3935:                 '<span class="LC_nobreak">'.&mt('Display target:');
                   3936:             my %currdisp;
                   3937:             if (ref($settings->{$item}->{'display'}) eq 'HASH') {
                   3938:                 if ($settings->{$item}->{'display'}->{'target'} eq 'window') {
                   3939:                     $currdisp{'window'} = ' checked="checked"';
1.298     raeburn  3940:                 } elsif ($settings->{$item}->{'display'}->{'target'} eq 'tab') {
                   3941:                     $currdisp{'tab'} = ' checked="checked"';
1.267     raeburn  3942:                 } else {
                   3943:                     $currdisp{'iframe'} = ' checked="checked"';
                   3944:                 }
                   3945:                 if ($settings->{$item}->{'display'}->{'width'} =~ /^(\d+)$/) {
                   3946:                     $currdisp{'width'} = $1;
                   3947:                 }
                   3948:                 if ($settings->{$item}->{'display'}->{'height'} =~ /^(\d+)$/) {
                   3949:                      $currdisp{'height'} = $1;
                   3950:                 }
1.296     raeburn  3951:                 $currdisp{'linktext'} = $settings->{$item}->{'display'}->{'linktext'};
                   3952:                 $currdisp{'explanation'} = $settings->{$item}->{'display'}->{'explanation'};
1.267     raeburn  3953:             } else {
                   3954:                 $currdisp{'iframe'} = ' checked="checked"';
                   3955:             }
1.298     raeburn  3956:             foreach my $disp ('iframe','tab','window') {
1.267     raeburn  3957:                 $datatable .= '<label><input type="radio" name="ltitools_target_'.$i.'" value="'.$disp.'"'.$currdisp{$disp}.' />'.
                   3958:                               $lt{$disp}.'</label>'.('&nbsp;'x2);
                   3959:             }
                   3960:             $datatable .= ('&nbsp;'x4);
                   3961:             foreach my $dimen ('width','height') {
                   3962:                 $datatable .= '<label>'.$lt{$dimen}.'&nbsp;'.
                   3963:                               '<input type="text" name="ltitools_'.$dimen.'_'.$i.'" size="5" value="'.$currdisp{$dimen}.'" /></label>'.
                   3964:                               ('&nbsp;'x2);
                   3965:             }
1.296     raeburn  3966:             $datatable .= '<br />'.
                   3967:                           '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
                   3968:                           '<input type="text" name="ltitools_linktext_'.$i.'" size="25" value="'.$currdisp{'linktext'}.'" /></label></div>'.
                   3969:                           '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
                   3970:                           '<textarea name="ltitools_explanation_'.$i.'" rows="5" cols="40">'.$currdisp{'explanation'}.
                   3971:                           '</textarea></div><div style=""></div><br />';
1.267     raeburn  3972:             $datatable .= '<br />';
                   3973:             foreach my $extra ('passback','roster') {
                   3974:                 my $checkedon = '';
                   3975:                 my $checkedoff = ' checked="checked"';
                   3976:                 if ($settings->{$item}->{$extra}) {
                   3977:                     $checkedon = $checkedoff;
                   3978:                     $checkedoff = '';
                   3979:                 }
                   3980:                 $datatable .= $lt{$extra}.'&nbsp;'.
                   3981:                               '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="1"'.$checkedon.' />'.
                   3982:                               &mt('Yes').'</label>'.('&nbsp;'x2).
                   3983:                               '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="0"'.$checkedoff.' />'.
                   3984:                               &mt('No').'</label>'.('&nbsp;'x4);
                   3985:             }
                   3986:             $datatable .= '<br /><br /><span class="LC_nobreak">'.$lt{'icon'}.':&nbsp;';
                   3987:             if ($imgsrc) {
                   3988:                 $datatable .= $imgsrc.
                   3989:                               '<label><input type="checkbox" name="ltitools_image_del"'.
                   3990:                               ' value="'.$item.'" />'.&mt('Delete?').'</label></span> '.
                   3991:                               '<span class="LC_nobreak">&nbsp;'.&mt('Replace:').'&nbsp;';
                   3992:             } else {
                   3993:                 $datatable .= '('.&mt('if larger than 21x21 pixels, image will be scaled').')&nbsp;';
                   3994:             }
                   3995:             if ($switchserver) {
                   3996:                 $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   3997:             } else {
                   3998:                 $datatable .= '<input type="file" name="ltitools_image_'.$i.'" value="" />';
                   3999:             }
                   4000:             $datatable .= '</span></fieldset>';
                   4001:             my (%checkedfields,%rolemaps);
                   4002:             if (ref($settings->{$item}) eq 'HASH') {
                   4003:                 if (ref($settings->{$item}->{'fields'}) eq 'HASH') {
                   4004:                     %checkedfields = %{$settings->{$item}->{'fields'}};
                   4005:                 }
                   4006:                 if (ref($settings->{$item}->{'roles'}) eq 'HASH') {
                   4007:                     %rolemaps = %{$settings->{$item}->{'roles'}};
                   4008:                     $checkedfields{'roles'} = 1;
                   4009:                 }
                   4010:             }
                   4011:             $datatable .= '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
                   4012:                           '<span class="LC_nobreak">';
                   4013:             foreach my $field (@fields) {
                   4014:                 my $checked;
                   4015:                 if ($checkedfields{$field}) {
                   4016:                     $checked = ' checked="checked"';
                   4017:                 }
                   4018:                 $datatable .= '<label>'.
                   4019:                               '<input type="checkbox" name="ltitools_fields_'.$i.'" value="'.$field.'"'.$checked.' />'.
                   4020:                               $lt{$field}.'</label>'.('&nbsp;' x2);
                   4021:             }
                   4022:             $datatable .= '</span></fieldset>'.
                   4023:                           '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
                   4024:             foreach my $role (@courseroles) {
                   4025:                 my ($selected,$selectnone);
                   4026:                 if (!$rolemaps{$role}) {
                   4027:                     $selectnone = ' selected="selected"';
                   4028:                 }
1.306     raeburn  4029:                 $datatable .= '<td style="text-align: center">'. 
1.267     raeburn  4030:                               &Apache::lonnet::plaintext($role,'Course').'<br />'.
                   4031:                               '<select name="ltitools_roles_'.$role.'_'.$i.'">'.
                   4032:                               '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
                   4033:                 foreach my $ltirole (@ltiroles) {
                   4034:                     unless ($selectnone) {
                   4035:                         if ($rolemaps{$role} eq $ltirole) {
                   4036:                             $selected = ' selected="selected"';
                   4037:                         } else {
                   4038:                             $selected = '';
                   4039:                         }
                   4040:                     }
                   4041:                     $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
                   4042:                 }
                   4043:                 $datatable .= '</select></td>';
                   4044:             }
1.273     raeburn  4045:             $datatable .= '</tr></table></fieldset>';
                   4046:             my %courseconfig;
                   4047:             if (ref($settings->{$item}) eq 'HASH') {
                   4048:                 if (ref($settings->{$item}->{'crsconf'}) eq 'HASH') {
                   4049:                     %courseconfig = %{$settings->{$item}->{'crsconf'}};
                   4050:                 }
                   4051:             }
                   4052:             $datatable .= '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
1.296     raeburn  4053:             foreach my $item ('label','title','target','linktext','explanation') {
1.273     raeburn  4054:                 my $checked;
                   4055:                 if ($courseconfig{$item}) {
                   4056:                     $checked = ' checked="checked"';
                   4057:                 }
                   4058:                 $datatable .= '<label>'.
                   4059:                        '<input type="checkbox" name="ltitools_courseconfig_'.$i.'" value="'.$item.'"'.$checked.' />'.
                   4060:                        $lt{'crs'.$item}.'</label>'.('&nbsp;' x2)."\n";
                   4061:             }
                   4062:             $datatable .= '</span></fieldset>'.
1.267     raeburn  4063:                           '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
                   4064:                           '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>';
                   4065:             if (ref($settings->{$item}->{'custom'}) eq 'HASH') {
                   4066:                 my %custom = %{$settings->{$item}->{'custom'}};
                   4067:                 if (keys(%custom) > 0) {
                   4068:                     foreach my $key (sort(keys(%custom))) {
                   4069:                         $datatable .= '<tr><td><span class="LC_nobreak">'.
                   4070:                                       '<label><input type="checkbox" name="ltitools_customdel_'.$i.'" value="'.
                   4071:                                       $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
                   4072:                                       '<td><input type="text" name="ltitools_customval_'.$key.'_'.$i.'"'.
                   4073:                                       ' value="'.$custom{$key}.'" /></td></tr>';
                   4074:                     }
                   4075:                 }
                   4076:             }
                   4077:             $datatable .= '<tr><td><span class="LC_nobreak">'.
                   4078:                           '<label><input type="checkbox" name="ltitools_customadd" value="'.$i.'" />'.
                   4079:                           &mt('Add').'</label></span></td><td><input type="text" name="ltitools_custom_name_'.$i.'" />'.
                   4080:                           '</td><td><input type="text" name="ltitools_custom_value_'.$i.'" /></td></tr>';
                   4081:             $datatable .= '</table></fieldset></td></tr>'."\n";
                   4082:             $itemcount ++;
                   4083:         }
                   4084:     }
                   4085:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   4086:     my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'ltitools_add_pos'".');"';
                   4087:     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
                   4088:                   '<input type="hidden" name="ltitools_maxnum" value="'.$maxnum.'" />'."\n".
                   4089:                   '<select name="ltitools_add_pos"'.$chgstr.'>';
                   4090:     for (my $k=0; $k<$maxnum+1; $k++) {
                   4091:         my $vpos = $k+1;
                   4092:         my $selstr;
                   4093:         if ($k == $maxnum) {
                   4094:             $selstr = ' selected="selected" ';
                   4095:         }
                   4096:         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   4097:     }
                   4098:     $datatable .= '</select>&nbsp;'."\n".
                   4099:                   '<input type="checkbox" name="ltitools_add" value="1" />'.&mt('Add').'</td>'."\n".
                   4100:                   '<td colspan="2">'.
                   4101:                   '<fieldset><legend>'.&mt('Required settings').'</legend>'.
                   4102:                   '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="30" name="ltitools_add_title" value="" /></span> '."\n".
                   4103:                   ('&nbsp;'x2).
                   4104:                   '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_add_version">'.
                   4105:                   '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
                   4106:                   ('&nbsp;'x2).
                   4107:                   '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_add_msgtype">'.
                   4108:                   '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
                   4109:                   '<br />'.
                   4110:                   '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="30" name="ltitools_add_url" value="" /></span> '."\n".
                   4111:                   ('&nbsp;'x2).
                   4112:                   '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="ltitools_add_key" value="" /></span> '."\n".
                   4113:                   ('&nbsp;'x2).
                   4114:                   '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="ltitools_add_secret" value="" />'.
                   4115:                   '<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".
                   4116:                   '</fieldset>'.
                   4117:                   '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
                   4118:                   '<span class="LC_nobreak">'.&mt('Display target:');
                   4119:     my %defaultdisp;
                   4120:     $defaultdisp{'iframe'} = ' checked="checked"';
1.298     raeburn  4121:     foreach my $disp ('iframe','tab','window') {
1.267     raeburn  4122:         $datatable .= '<label><input type="radio" name="ltitools_add_target" value="'.$disp.'"'.$defaultdisp{$disp}.' />'.
                   4123:                       $lt{$disp}.'</label>'.('&nbsp;'x2);
                   4124:     }
                   4125:     $datatable .= ('&nbsp;'x4);
                   4126:     foreach my $dimen ('width','height') {
                   4127:         $datatable .= '<label>'.$lt{$dimen}.'&nbsp;'.
                   4128:                       '<input type="text" name="ltitools_add_'.$dimen.'" size="5" /></label>'.
                   4129:                       ('&nbsp;'x2);
                   4130:     }
1.296     raeburn  4131:     $datatable .= '<br />'.
                   4132:                   '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
                   4133:                   '<input type="text" name="ltitools_add_linktext" size="5" /></label></div>'.
                   4134:                   '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
                   4135:                   '<textarea name=ltitools_add_explanation" rows="5" cols="40"></textarea>'.
                   4136:                   '</div><div style=""></div><br />';
1.267     raeburn  4137:     foreach my $extra ('passback','roster') {
                   4138:         $datatable .= $lt{$extra}.'&nbsp;'.
                   4139:                       '<label><input type="radio" name="ltitools_add_'.$extra.'" value="1" />'.
                   4140:                       &mt('Yes').'</label>'.('&nbsp;'x2).
                   4141:                       '<label><input type="radio" name="ltitools_add_'.$extra.'" value="0" checked="checked" />'.
                   4142:                       &mt('No').'</label>'.('&nbsp;'x4);
                   4143:     }
                   4144:     $datatable .= '<br /><br /><span class="LC_nobreak">'.$lt{'icon'}.':&nbsp;'.
                   4145:                   '('.&mt('if larger than 21x21 pixels, image will be scaled').')&nbsp;';
                   4146:     if ($switchserver) {
                   4147:         $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   4148:     } else {
                   4149:         $datatable .= '<input type="file" name="ltitools_add_image" value="" />';
                   4150:     }
                   4151:     $datatable .= '</span></fieldset>'.
                   4152:                   '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
                   4153:                   '<span class="LC_nobreak">';
                   4154:     foreach my $field (@fields) {
                   4155:         $datatable .= '<label>'.
                   4156:                       '<input type="checkbox" name="ltitools_add_fields" value="'.$field.'" />'.
                   4157:                       $lt{$field}.'</label>'.('&nbsp;' x2);
                   4158:     }
                   4159:     $datatable .= '</span></fieldset>'.
                   4160:                   '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
                   4161:     foreach my $role (@courseroles) {
                   4162:         my ($checked,$checkednone);
1.306     raeburn  4163:         $datatable .= '<td style="text-align: center">'.
1.267     raeburn  4164:                       &Apache::lonnet::plaintext($role,'Course').'<br />'.
                   4165:                       '<select name="ltitools_add_roles_'.$role.'">'.
                   4166:                       '<option value="" selected="selected">'.&mt('Select').'</option>';
                   4167:         foreach my $ltirole (@ltiroles) {
                   4168:             $datatable .= '<option value="'.$ltirole.'">'.$ltirole.'</option>';
                   4169:         }
                   4170:         $datatable .= '</select></td>';
                   4171:     }
                   4172:     $datatable .= '</tr></table></fieldset>'.
1.273     raeburn  4173:                   '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
1.296     raeburn  4174:     foreach my $item ('label','title','target','linktext','explanation') {
                   4175:         $datatable .= '<label>'.
                   4176:                       '<input type="checkbox" name="ltitools_courseconfig" value="'.$item.'" checked="checked" />'.
                   4177:                       $lt{'crs'.$item}.'</label>'.('&nbsp;' x2)."\n";
1.273     raeburn  4178:     }
                   4179:     $datatable .= '</span></fieldset>'.
1.267     raeburn  4180:                   '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
                   4181:                   '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
                   4182:                   '<tr><td><span class="LC_nobreak">'.
                   4183:                   '<label><input type="checkbox" name="ltitools_add_custom" value="1" />'.
                   4184:                   &mt('Add').'</label></span></td><td><input type="text" name="ltitools_add_custom_name" />'.
                   4185:                   '</td><td><input type="text" name="ltitools_add_custom_value" /></td></tr>'.
                   4186:                   '</table></fieldset></td></tr>'."\n".
                   4187:                   '</td>'."\n".
                   4188:                   '</tr>'."\n";
                   4189:     $itemcount ++;
                   4190:     return $datatable;
                   4191: }
                   4192: 
                   4193: sub ltitools_names {
                   4194:     my %lt = &Apache::lonlocal::texthash(
1.296     raeburn  4195:                                           'title'          => 'Title',
                   4196:                                           'version'        => 'Version',
                   4197:                                           'msgtype'        => 'Message Type',
                   4198:                                           'url'            => 'URL',
                   4199:                                           'key'            => 'Key',
                   4200:                                           'secret'         => 'Secret',
                   4201:                                           'icon'           => 'Icon',   
                   4202:                                           'user'           => 'Username:domain',
                   4203:                                           'fullname'       => 'Full Name',
                   4204:                                           'firstname'      => 'First Name',
                   4205:                                           'lastname'       => 'Last Name',
                   4206:                                           'email'          => 'E-mail',
                   4207:                                           'roles'          => 'Role',
1.298     raeburn  4208:                                           'window'         => 'Window',
                   4209:                                           'tab'            => 'Tab',
1.296     raeburn  4210:                                           'iframe'         => 'iFrame',
                   4211:                                           'height'         => 'Height',
                   4212:                                           'width'          => 'Width',
                   4213:                                           'linktext'       => 'Default Link Text',
                   4214:                                           'explanation'    => 'Default Explanation',
                   4215:                                           'passback'       => 'Tool can return grades:',
                   4216:                                           'roster'         => 'Tool can retrieve roster:',
                   4217:                                           'crstarget'      => 'Display target',
                   4218:                                           'crslabel'       => 'Course label',
                   4219:                                           'crstitle'       => 'Course title', 
                   4220:                                           'crslinktext'    => 'Link Text',
                   4221:                                           'crsexplanation' => 'Explanation',
1.267     raeburn  4222:                                         );
                   4223:     return %lt;
                   4224: }
                   4225: 
1.121     raeburn  4226: sub print_coursedefaults {
1.139     raeburn  4227:     my ($position,$dom,$settings,$rowtotal) = @_;
1.192     raeburn  4228:     my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121     raeburn  4229:     my $itemcount = 1;
1.192     raeburn  4230:     my %choices =  &Apache::lonlocal::texthash (
                   4231:         canuse_pdfforms      => 'Course/Community users can create/upload PDF forms',
1.198     raeburn  4232:         uploadquota          => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.192     raeburn  4233:         anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
                   4234:         coursecredits        => 'Credits can be specified for courses',
1.257     raeburn  4235:         uselcmath            => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
                   4236:         usejsme              => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
1.314     raeburn  4237:         texengine            => 'Default method to display mathematics',
1.257     raeburn  4238:         postsubmit           => 'Disable submit button/keypress following student submission',
1.276     raeburn  4239:         canclone             => "People who may clone a course (besides course's owner and coordinators)",
                   4240:         mysqltables          => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.192     raeburn  4241:     );
1.198     raeburn  4242:     my %staticdefaults = (
1.314     raeburn  4243:                            texengine            => 'MathJax',
1.198     raeburn  4244:                            anonsurvey_threshold => 10,
                   4245:                            uploadquota          => 500,
1.257     raeburn  4246:                            postsubmit           => 60,
1.276     raeburn  4247:                            mysqltables          => 172800,
1.198     raeburn  4248:                          );
1.139     raeburn  4249:     if ($position eq 'top') {
1.257     raeburn  4250:         %defaultchecked = (
                   4251:                             'canuse_pdfforms' => 'off',
                   4252:                             'uselcmath'       => 'on',
                   4253:                             'usejsme'         => 'on',
1.289     raeburn  4254:                             'canclone'        => 'none',
1.257     raeburn  4255:                           );
                   4256:         @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.314     raeburn  4257:         my $deftex = $staticdefaults{'texengine'};
                   4258:         if (ref($settings) eq 'HASH') {
                   4259:             if ($settings->{'texengine'}) {
                   4260:                 if ($settings->{'texengine'} =~ /^(MathJax|mimetex|tth)$/) {
                   4261:                     $deftex = $settings->{'texengine'};
                   4262:                 }
                   4263:             }
                   4264:         }
                   4265:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   4266:         my $mathdisp = '<tr'.$css_class.'><td style="vertical-align: top">'.
                   4267:                        '<span class="LC_nobreak">'.$choices{'texengine'}.
                   4268:                        '</span></td><td class="LC_right_item">'.
                   4269:                        '<select name="texengine">'."\n";
                   4270:         my %texoptions = (
                   4271:                             MathJax  => 'MathJax',
                   4272:                             mimetex  => &mt('Convert to Images'),
                   4273:                             tth      => &mt('TeX to HTML'),
                   4274:                          );
                   4275:         foreach my $renderer ('MathJax','mimetex','tth') {
                   4276:             my $selected = '';
                   4277:             if ($renderer eq $deftex) {
                   4278:                 $selected = ' selected="selected"';
                   4279:             }
                   4280:             $mathdisp .= '<option value="'.$renderer.'"'.$selected.'>'.$texoptions{$renderer}.'</option>'."\n";
                   4281:         }
                   4282:         $mathdisp .= '</select></td></tr>'."\n";
                   4283:         $itemcount ++;
1.139     raeburn  4284:         ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.257     raeburn  4285:                                                      \%choices,$itemcount);
1.314     raeburn  4286:         $datatable = $mathdisp.$datatable;
1.264     raeburn  4287:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   4288:         $datatable .=
1.306     raeburn  4289:             '<tr'.$css_class.'><td style="vertical-align: top">'.
1.264     raeburn  4290:             '<span class="LC_nobreak">'.$choices{'canclone'}.
                   4291:             '</span></td><td class="LC_left_item">';
                   4292:         my $currcanclone = 'none';
                   4293:         my $onclick;
                   4294:         my @cloneoptions = ('none','domain');
                   4295:         my %clonetitles = (
                   4296:                              none     => 'No additional course requesters',
                   4297:                              domain   => "Any course requester in course's domain",
                   4298:                              instcode => 'Course requests for official courses ...',
                   4299:                           );
                   4300:         my (%codedefaults,@code_order,@posscodes);
                   4301:         if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
                   4302:                                                     \@code_order) eq 'ok') {
                   4303:             if (@code_order > 0) {
                   4304:                 push(@cloneoptions,'instcode');
                   4305:                 $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
                   4306:             }
                   4307:         }
                   4308:         if (ref($settings) eq 'HASH') {
                   4309:             if ($settings->{'canclone'}) {
                   4310:                 if (ref($settings->{'canclone'}) eq 'HASH') {
                   4311:                     if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
                   4312:                         if (@code_order > 0) {
                   4313:                             $currcanclone = 'instcode';
                   4314:                             @posscodes = @{$settings->{'canclone'}{'instcode'}};
                   4315:                         }
                   4316:                     }
                   4317:                 } elsif ($settings->{'canclone'} eq 'domain') {
                   4318:                     $currcanclone = $settings->{'canclone'};
                   4319:                 }
                   4320:             }
1.289     raeburn  4321:         }
1.264     raeburn  4322:         foreach my $option (@cloneoptions) {
                   4323:             my ($checked,$additional);
                   4324:             if ($currcanclone eq $option) {
                   4325:                 $checked = ' checked="checked"';
                   4326:             }
                   4327:             if ($option eq 'instcode') {
                   4328:                 if (@code_order) {
                   4329:                     my $show = 'none';
                   4330:                     if ($checked) {
                   4331:                         $show = 'block';
                   4332:                     }
                   4333:                     $additional = '<div id="cloneinstcode" style="display:'.$show.'" />'.
                   4334:                                   &mt('Institutional codes for new and cloned course have identical:').
                   4335:                                   '<br />';
                   4336:                     foreach my $item (@code_order) {
                   4337:                         my $codechk;
                   4338:                         if ($checked) {
                   4339:                             if (grep(/^\Q$item\E$/,@posscodes)) {
                   4340:                                 $codechk = ' checked="checked"';
                   4341:                             }
                   4342:                         }
                   4343:                         $additional .= '<label>'.
                   4344:                                        '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
                   4345:                                        $item.'</label>';
                   4346:                     }
                   4347:                     $additional .= ('&nbsp;'x2).'('.&mt('check as many as needed').')</div>';
                   4348:                 }
                   4349:             }
                   4350:             $datatable .=
                   4351:                 '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
                   4352:                 ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
                   4353:                 '</label>&nbsp;'.$additional.'</span><br />';
                   4354:         }
                   4355:         $datatable .= '</td>'.
                   4356:                       '</tr>';
                   4357:         $itemcount ++;
1.139     raeburn  4358:     } else {
                   4359:         $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.276     raeburn  4360:         my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout,%currmysql);
1.192     raeburn  4361:         my $currusecredits = 0;
1.257     raeburn  4362:         my $postsubmitclient = 1;
1.271     raeburn  4363:         my @types = ('official','unofficial','community','textbook','placement');
1.139     raeburn  4364:         if (ref($settings) eq 'HASH') {
                   4365:             $currdefresponder = $settings->{'anonsurvey_threshold'};
1.198     raeburn  4366:             if (ref($settings->{'uploadquota'}) eq 'HASH') {
                   4367:                 foreach my $type (keys(%{$settings->{'uploadquota'}})) {
                   4368:                     $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
                   4369:                 }
                   4370:             }
1.192     raeburn  4371:             if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.257     raeburn  4372:                 foreach my $type (@types) {
                   4373:                     next if ($type eq 'community');
                   4374:                     $defcredits{$type} = $settings->{'coursecredits'}->{$type};
                   4375:                     if ($defcredits{$type} ne '') {
                   4376:                         $currusecredits = 1;
                   4377:                     }
                   4378:                 }
                   4379:             }
                   4380:             if (ref($settings->{'postsubmit'}) eq 'HASH') {
                   4381:                 if ($settings->{'postsubmit'}->{'client'} eq 'off') {
                   4382:                     $postsubmitclient = 0;
                   4383:                     foreach my $type (@types) {
                   4384:                         $deftimeout{$type} = $staticdefaults{'postsubmit'};
                   4385:                     }
                   4386:                 } else {
                   4387:                     foreach my $type (@types) {
                   4388:                         if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
                   4389:                             if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
1.289     raeburn  4390:                                 $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
1.257     raeburn  4391:                             } else {
                   4392:                                 $deftimeout{$type} = $staticdefaults{'postsubmit'};
                   4393:                             }
                   4394:                         } else {
                   4395:                             $deftimeout{$type} = $staticdefaults{'postsubmit'};
                   4396:                         }
                   4397:                     }
                   4398:                 }
                   4399:             } else {
                   4400:                 foreach my $type (@types) {
                   4401:                     $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.192     raeburn  4402:                 }
                   4403:             }
1.276     raeburn  4404:             if (ref($settings->{'mysqltables'}) eq 'HASH') {
                   4405:                 foreach my $type (keys(%{$settings->{'mysqltables'}})) {
                   4406:                     $currmysql{$type} = $settings->{'mysqltables'}{$type};
                   4407:                 }
                   4408:             } else {
                   4409:                 foreach my $type (@types) {
                   4410:                     $currmysql{$type} = $staticdefaults{'mysqltables'};
                   4411:                 }
                   4412:             }
1.258     raeburn  4413:         } else {
                   4414:             foreach my $type (@types) {
                   4415:                 $deftimeout{$type} = $staticdefaults{'postsubmit'};
                   4416:             }
1.139     raeburn  4417:         }
                   4418:         if (!$currdefresponder) {
1.198     raeburn  4419:             $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139     raeburn  4420:         } elsif ($currdefresponder < 1) {
                   4421:             $currdefresponder = 1;
                   4422:         }
1.198     raeburn  4423:         foreach my $type (@types) {
                   4424:             if ($curruploadquota{$type} eq '') {
                   4425:                 $curruploadquota{$type} = $staticdefaults{'uploadquota'};
                   4426:             }
                   4427:         }
1.139     raeburn  4428:         $datatable .=
1.192     raeburn  4429:                 '<tr'.$css_class.'><td><span class="LC_nobreak">'.
                   4430:                 $choices{'anonsurvey_threshold'}.
1.139     raeburn  4431:                 '</span></td>'.
                   4432:                 '<td class="LC_right_item"><span class="LC_nobreak">'.
                   4433:                 '<input type="text" name="anonsurvey_threshold"'.
                   4434:                 ' value="'.$currdefresponder.'" size="5" /></span>'.
1.230     raeburn  4435:                 '</td></tr>'."\n";
                   4436:         $itemcount ++;
                   4437:         $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   4438:         $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
                   4439:                       $choices{'uploadquota'}.
                   4440:                       '</span></td>'.
1.306     raeburn  4441:                       '<td style="text-align: right" class="LC_right_item">'.
1.230     raeburn  4442:                       '<table><tr>';
1.198     raeburn  4443:         foreach my $type (@types) {
1.306     raeburn  4444:             $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.198     raeburn  4445:                            '<input type="text" name="uploadquota_'.$type.'"'.
                   4446:                            ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
                   4447:         }
                   4448:         $datatable .= '</tr></table></td></tr>'."\n";
1.230     raeburn  4449:         $itemcount ++;
1.236     raeburn  4450:         my $onclick = "toggleDisplay(this.form,'credits');";
1.210     raeburn  4451:         my $display = 'none';
1.192     raeburn  4452:         if ($currusecredits) {
                   4453:             $display = 'block';
                   4454:         }
                   4455:         my $additional = '<div id="credits" style="display: '.$display.'">'.
1.257     raeburn  4456:                          '<i>'.&mt('Default credits').'</i><br /><table><tr>';
                   4457:         foreach my $type (@types) {
                   4458:             next if ($type eq 'community');
1.306     raeburn  4459:             $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257     raeburn  4460:                            '<input type="text" name="'.$type.'_credits"'.
1.258     raeburn  4461:                            ' value="'.$defcredits{$type}.'" size="3" /></td>';
1.257     raeburn  4462:         }
                   4463:         $additional .= '</tr></table></div>'."\n";
1.192     raeburn  4464:         %defaultchecked = ('coursecredits' => 'off');
                   4465:         @toggles = ('coursecredits');
                   4466:         my $current = {
                   4467:                         'coursecredits' => $currusecredits,
                   4468:                       };
                   4469:         (my $table,$itemcount) =
                   4470:             &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.257     raeburn  4471:                                \%choices,$itemcount,$onclick,$additional,'left');
                   4472:         $datatable .= $table;
                   4473:         $onclick = "toggleDisplay(this.form,'studentsubmission');";
                   4474:         my $display = 'none';
                   4475:         if ($postsubmitclient) {
                   4476:             $display = 'block';
                   4477:         }
                   4478:         $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.259     raeburn  4479:                       &mt('Number of seconds submit is disabled').'<br />'.
                   4480:                       '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
                   4481:                       '<table><tr>';
1.257     raeburn  4482:         foreach my $type (@types) {
1.306     raeburn  4483:             $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257     raeburn  4484:                            '<input type="text" name="'.$type.'_timeout" value="'.
                   4485:                            $deftimeout{$type}.'" size="5" /></td>';
                   4486:         }
                   4487:         $additional .= '</tr></table></div>'."\n";
                   4488:         %defaultchecked = ('postsubmit' => 'on');
                   4489:         @toggles = ('postsubmit');
1.280     raeburn  4490:         $current = {
                   4491:                        'postsubmit' => $postsubmitclient,
                   4492:                    };
1.257     raeburn  4493:         ($table,$itemcount) =
                   4494:             &radiobutton_prefs($current,\@toggles,\%defaultchecked,
                   4495:                                \%choices,$itemcount,$onclick,$additional,'left');
1.192     raeburn  4496:         $datatable .= $table;
1.276     raeburn  4497:         $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   4498:         $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
                   4499:                       $choices{'mysqltables'}.
                   4500:                       '</span></td>'.
1.306     raeburn  4501:                       '<td style="text-align: right" class="LC_right_item">'.
1.276     raeburn  4502:                       '<table><tr>';
                   4503:         foreach my $type (@types) {
1.306     raeburn  4504:             $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.276     raeburn  4505:                            '<input type="text" name="mysqltables_'.$type.'"'.
1.295     raeburn  4506:                            ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.276     raeburn  4507:         }
                   4508:         $datatable .= '</tr></table></td></tr>'."\n";
                   4509:         $itemcount ++;
                   4510: 
1.139     raeburn  4511:     }
1.192     raeburn  4512:     $$rowtotal += $itemcount;
1.121     raeburn  4513:     return $datatable;
1.118     jms      4514: }
                   4515: 
1.231     raeburn  4516: sub print_selfenrollment {
                   4517:     my ($position,$dom,$settings,$rowtotal) = @_;
                   4518:     my ($css_class,$datatable);
                   4519:     my $itemcount = 1;
1.271     raeburn  4520:     my @types = ('official','unofficial','community','textbook','placement');
1.231     raeburn  4521:     if (($position eq 'top') || ($position eq 'middle')) {
1.232     raeburn  4522:         my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
                   4523:         my %descs = &Apache::lonuserutils::selfenroll_default_descs();
1.231     raeburn  4524:         my @rows;
                   4525:         my $key;
                   4526:         if ($position eq 'top') {
                   4527:             $key = 'admin'; 
                   4528:             if (ref($rowsref) eq 'ARRAY') {
                   4529:                 @rows = @{$rowsref};
                   4530:             }
                   4531:         } elsif ($position eq 'middle') {
                   4532:             $key = 'default';
                   4533:             @rows = ('types','registered','approval','limit');
                   4534:         }
                   4535:         foreach my $row (@rows) {
                   4536:             if (defined($titlesref->{$row})) {
                   4537:                 $itemcount ++;
                   4538:                 $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   4539:                 $datatable .= '<tr'.$css_class.'>'.
                   4540:                               '<td>'.$titlesref->{$row}.'</td>'.
                   4541:                               '<td class="LC_left_item">'.
                   4542:                               '<table><tr>';
                   4543:                 my (%current,%currentcap);
                   4544:                 if (ref($settings) eq 'HASH') {
                   4545:                     if (ref($settings->{$key}) eq 'HASH') {
                   4546:                         foreach my $type (@types) {
                   4547:                             if (ref($settings->{$key}->{$type}) eq 'HASH') {
                   4548:                                 $current{$type} = $settings->{$key}->{$type}->{$row};
                   4549:                             }
                   4550:                             if (($row eq 'limit') && ($key eq 'default')) {
                   4551:                                 if (ref($settings->{$key}->{$type}) eq 'HASH') {
                   4552:                                     $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
                   4553:                                 }
                   4554:                             }
                   4555:                         }
                   4556:                     }
                   4557:                 }
                   4558:                 my %roles = (
                   4559:                              '0' => &Apache::lonnet::plaintext('dc'),
                   4560:                             ); 
                   4561:             
                   4562:                 foreach my $type (@types) {
                   4563:                     unless (($row eq 'registered') && ($key eq 'default')) {
                   4564:                         $datatable .= '<th>'.&mt($type).'</th>';
                   4565:                     }
                   4566:                 }
                   4567:                 unless (($row eq 'registered') && ($key eq 'default')) {
                   4568:                     $datatable .= '</tr><tr>';
                   4569:                 }
                   4570:                 foreach my $type (@types) {
                   4571:                     if ($type eq 'community') {
                   4572:                         $roles{'1'} = &mt('Community personnel');
                   4573:                     } else {
                   4574:                         $roles{'1'} = &mt('Course personnel');
                   4575:                     }
                   4576:                     $datatable .= '<td style="vertical-align: top">';
                   4577:                     if ($position eq 'top') {
                   4578:                         my %checked;
                   4579:                         if ($current{$type} eq '0') {
                   4580:                             $checked{'0'} = ' checked="checked"';
                   4581:                         } else {
                   4582:                             $checked{'1'} = ' checked="checked"';
                   4583:                         }
                   4584:                         foreach my $role ('1','0') {
                   4585:                             $datatable .= '<span class="LC_nobreak"><label>'.
                   4586:                                           '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
                   4587:                                           'value="'.$role.'"'.$checked{$role}.' />'.
                   4588:                                           $roles{$role}.'</label></span> ';
                   4589:                         }
                   4590:                     } else {
                   4591:                         if ($row eq 'types') {
                   4592:                             my %checked;
                   4593:                             if ($current{$type} =~ /^(all|dom)$/) {
                   4594:                                 $checked{$1} = ' checked="checked"';
                   4595:                             } else {
                   4596:                                 $checked{''} = ' checked="checked"';
                   4597:                             }
                   4598:                             foreach my $val ('','dom','all') {
                   4599:                                 $datatable .= '<span class="LC_nobreak"><label>'.
                   4600:                                               '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
                   4601:                                               'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
                   4602:                             }
                   4603:                         } elsif ($row eq 'registered') {
                   4604:                             my %checked;
                   4605:                             if ($current{$type} eq '1') {
                   4606:                                 $checked{'1'} = ' checked="checked"';
                   4607:                             } else {
                   4608:                                 $checked{'0'} = ' checked="checked"';
                   4609:                             }
                   4610:                             foreach my $val ('0','1') {
                   4611:                                 $datatable .= '<span class="LC_nobreak"><label>'.
                   4612:                                               '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
                   4613:                                               'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
                   4614:                             }
                   4615:                         } elsif ($row eq 'approval') {
                   4616:                             my %checked;
                   4617:                             if ($current{$type} =~ /^([12])$/) {
                   4618:                                 $checked{$1} = ' checked="checked"';
                   4619:                             } else {
                   4620:                                 $checked{'0'} = ' checked="checked"';
                   4621:                             }
                   4622:                             for my $val (0..2) {
                   4623:                                 $datatable .= '<span class="LC_nobreak"><label>'.
                   4624:                                               '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
                   4625:                                               'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
                   4626:                             }
                   4627:                         } elsif ($row eq 'limit') {
                   4628:                             my %checked;
                   4629:                             if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
                   4630:                                 $checked{$1} = ' checked="checked"';
                   4631:                             } else {
                   4632:                                 $checked{'none'} = ' checked="checked"';
                   4633:                             }
                   4634:                             my $cap;
                   4635:                             if ($currentcap{$type} =~ /^\d+$/) {
                   4636:                                 $cap = $currentcap{$type};
                   4637:                             }
                   4638:                             foreach my $val ('none','allstudents','selfenrolled') {
                   4639:                                 $datatable .= '<span class="LC_nobreak"><label>'.
                   4640:                                               '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
                   4641:                                               'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
                   4642:                             }
                   4643:                             $datatable .= '<br />'.
                   4644:                                           '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
                   4645:                                           '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
                   4646:                                           '</span>'; 
                   4647:                         }
                   4648:                     }
                   4649:                     $datatable .= '</td>';
                   4650:                 }
                   4651:                 $datatable .= '</tr>';
                   4652:             }
                   4653:             $datatable .= '</table></td></tr>';
                   4654:         }
                   4655:     } elsif ($position eq 'bottom') {
1.235     raeburn  4656:         $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
                   4657:     }
                   4658:     $$rowtotal += $itemcount;
                   4659:     return $datatable;
                   4660: }
                   4661: 
                   4662: sub print_validation_rows {
                   4663:     my ($caller,$dom,$settings,$rowtotal) = @_;
                   4664:     my ($itemsref,$namesref,$fieldsref);
                   4665:     if ($caller eq 'selfenroll') { 
                   4666:         ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
                   4667:     } elsif ($caller eq 'requestcourses') {
                   4668:         ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
                   4669:     }
                   4670:     my %currvalidation;
                   4671:     if (ref($settings) eq 'HASH') {
                   4672:         if (ref($settings->{'validation'}) eq 'HASH') {
                   4673:             %currvalidation = %{$settings->{'validation'}};
1.231     raeburn  4674:         }
1.235     raeburn  4675:     }
                   4676:     my $datatable;
                   4677:     my $itemcount = 0;
                   4678:     foreach my $item (@{$itemsref}) {
                   4679:         my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   4680:         $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
                   4681:                       $namesref->{$item}.
                   4682:                       '</span></td>'.
                   4683:                       '<td class="LC_left_item">';
                   4684:         if (($item eq 'url') || ($item eq 'button')) {
                   4685:             $datatable .= '<span class="LC_nobreak">'.
                   4686:                           '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
                   4687:                           ' value="'.$currvalidation{$item}.'" size="50" /></span>';
                   4688:         } elsif ($item eq 'fields') {
                   4689:             my @currfields;
                   4690:             if (ref($currvalidation{$item}) eq 'ARRAY') {
                   4691:                 @currfields = @{$currvalidation{$item}};
                   4692:             }
                   4693:             foreach my $field (@{$fieldsref}) {
                   4694:                 my $check = '';
                   4695:                 if (grep(/^\Q$field\E$/,@currfields)) {
                   4696:                     $check = ' checked="checked"';
                   4697:                 }
                   4698:                 $datatable .= '<span class="LC_nobreak"><label>'.
                   4699:                               '<input type="checkbox" name="'.$caller.'_validation_fields"'.
                   4700:                               ' value="'.$field.'"'.$check.' />'.$field.
                   4701:                               '</label></span> ';
                   4702:             }
                   4703:         } elsif ($item eq 'markup') {
                   4704:             $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5" wrap="soft">'.
                   4705:                            $currvalidation{$item}.
1.231     raeburn  4706:                               '</textarea>';
1.235     raeburn  4707:         }
                   4708:         $datatable .= '</td></tr>'."\n";
                   4709:         if (ref($rowtotal)) {
1.231     raeburn  4710:             $itemcount ++;
                   4711:         }
                   4712:     }
1.235     raeburn  4713:     if ($caller eq 'requestcourses') {
                   4714:         my %currhash;
1.248     raeburn  4715:         if (ref($settings) eq 'HASH') {
                   4716:             if (ref($settings->{'validation'}) eq 'HASH') {
                   4717:                 if ($settings->{'validation'}{'dc'} ne '') {
                   4718:                     $currhash{$settings->{'validation'}{'dc'}} = 1;
                   4719:                 }
1.235     raeburn  4720:             }
                   4721:         }
                   4722:         my $numinrow = 2;
                   4723:         my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
                   4724:                                                        'validationdc',%currhash);
1.247     raeburn  4725:         my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   4726:         $datatable .= '</td></tr><tr'.$css_class.'><td>';
1.235     raeburn  4727:         if ($numdc > 1) {
1.247     raeburn  4728:             $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.235     raeburn  4729:         } else {
1.247     raeburn  4730:             $datatable .=  &mt('Course creation processed as: ');
1.235     raeburn  4731:         }
1.247     raeburn  4732:         $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.235     raeburn  4733:         $itemcount ++;
                   4734:     }
                   4735:     if (ref($rowtotal)) {
                   4736:         $$rowtotal += $itemcount;
                   4737:     }
1.231     raeburn  4738:     return $datatable;
                   4739: }
                   4740: 
1.137     raeburn  4741: sub print_usersessions {
                   4742:     my ($position,$dom,$settings,$rowtotal) = @_;
1.279     raeburn  4743:     my ($css_class,$datatable,$itemcount,%checked,%choices);
1.275     raeburn  4744:     my (%by_ip,%by_location,@intdoms,@instdoms);
                   4745:     &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.145     raeburn  4746: 
                   4747:     my @alldoms = &Apache::lonnet::all_domains();
1.152     raeburn  4748:     my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149     raeburn  4749:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152     raeburn  4750:     my %altids = &id_for_thisdom(%servers);
1.145     raeburn  4751:     if ($position eq 'top') {
1.152     raeburn  4752:         if (keys(%serverhomes) > 1) {
1.145     raeburn  4753:             my %spareid = &current_offloads_to($dom,$settings,\%servers);
1.261     raeburn  4754:             my $curroffloadnow;
                   4755:             if (ref($settings) eq 'HASH') {
                   4756:                 if (ref($settings->{'offloadnow'}) eq 'HASH') {
                   4757:                     $curroffloadnow = $settings->{'offloadnow'};
                   4758:                 }
                   4759:             }
                   4760:             $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$curroffloadnow,$rowtotal);
1.145     raeburn  4761:         } else {
1.140     raeburn  4762:             $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.279     raeburn  4763:                           &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.').
                   4764:                           '</td></tr>';
1.140     raeburn  4765:         }
1.137     raeburn  4766:     } else {
1.279     raeburn  4767:         my %titles = &usersession_titles();
                   4768:         my ($prefix,@types);
                   4769:         if ($position eq 'bottom') {
                   4770:             $prefix = 'remote';
                   4771:             @types = ('version','excludedomain','includedomain');
1.145     raeburn  4772:         } else {
1.279     raeburn  4773:             $prefix = 'hosted';
                   4774:             @types = ('excludedomain','includedomain');
                   4775:         }
                   4776:         ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
                   4777:     }
                   4778:     $$rowtotal += $itemcount;
                   4779:     return $datatable;
                   4780: }
                   4781: 
                   4782: sub rules_by_location {
                   4783:     my ($settings,$prefix,$by_location,$by_ip,$types,$titles) = @_; 
                   4784:     my ($datatable,$itemcount,$css_class);
                   4785:     if (keys(%{$by_location}) == 0) {
                   4786:         $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   4787:         $datatable = '<tr'.$css_class.'><td colspan="2">'.
                   4788:                      &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.').
                   4789:                      '</td></tr>';
                   4790:         $itemcount = 1;
                   4791:     } else {
                   4792:         $itemcount = 0;
                   4793:         my $numinrow = 5;
                   4794:         my (%current,%checkedon,%checkedoff);
                   4795:         my @locations = sort(keys(%{$by_location}));
                   4796:         foreach my $type (@{$types}) {
                   4797:             $checkedon{$type} = '';
                   4798:             $checkedoff{$type} = ' checked="checked"';
                   4799:         }
                   4800:         if (ref($settings) eq 'HASH') {
                   4801:             if (ref($settings->{$prefix}) eq 'HASH') {
                   4802:                 foreach my $key (keys(%{$settings->{$prefix}})) {
                   4803:                     $current{$key} = $settings->{$prefix}{$key};
                   4804:                     if ($key eq 'version') {
                   4805:                         if ($current{$key} ne '') {
1.145     raeburn  4806:                             $checkedon{$key} = ' checked="checked"';
                   4807:                             $checkedoff{$key} = '';
                   4808:                         }
1.279     raeburn  4809:                     } elsif (ref($current{$key}) eq 'ARRAY') {
                   4810:                         $checkedon{$key} = ' checked="checked"';
                   4811:                         $checkedoff{$key} = '';
1.137     raeburn  4812:                     }
                   4813:                 }
                   4814:             }
1.279     raeburn  4815:         }
                   4816:         foreach my $type (@{$types}) {
                   4817:             next if ($type ne 'version' && !@locations);
                   4818:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   4819:             $datatable .= '<tr'.$css_class.'>
                   4820:                            <td><span class="LC_nobreak">'.$titles->{$type}.'</span><br />
                   4821:                            <span class="LC_nobreak">&nbsp;
                   4822:                            <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>&nbsp;
                   4823:                            <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
                   4824:             if ($type eq 'version') {
                   4825:                 my @lcversions = &Apache::lonnet::all_loncaparevs();
                   4826:                 my $selector = '<select name="'.$prefix.'_version">';
                   4827:                 foreach my $version (@lcversions) {
                   4828:                     my $selected = '';
                   4829:                     if ($current{'version'} eq $version) {
                   4830:                         $selected = ' selected="selected"';
1.145     raeburn  4831:                     }
1.279     raeburn  4832:                     $selector .= ' <option value="'.$version.'"'.
                   4833:                                  $selected.'>'.$version.'</option>';
                   4834:                 }
                   4835:                 $selector .= '</select> ';
                   4836:                 $datatable .= &mt('remote server must be version: [_1] or later',$selector);
                   4837:             } else {
                   4838:                 $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
                   4839:                              'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
                   4840:                              ' />'.('&nbsp;'x2).
                   4841:                              '<input type="button" value="'.&mt('uncheck all').'" '.
                   4842:                              'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
                   4843:                              "\n".
                   4844:                              '</div><div><table>';
                   4845:                 my $rem;
                   4846:                 for (my $i=0; $i<@locations; $i++) {
                   4847:                     my ($showloc,$value,$checkedtype);
                   4848:                     if (ref($by_location->{$locations[$i]}) eq 'ARRAY') {
                   4849:                         my $ip = $by_location->{$locations[$i]}->[0];
                   4850:                         if (ref($by_ip->{$ip}) eq 'ARRAY') {
                   4851:                             $value = join(':',@{$by_ip->{$ip}});
                   4852:                             $showloc = join(', ',@{$by_ip->{$ip}});
                   4853:                             if (ref($current{$type}) eq 'ARRAY') {
                   4854:                                 foreach my $loc (@{$by_ip->{$ip}}) {
                   4855:                                     if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
                   4856:                                         $checkedtype = ' checked="checked"';
                   4857:                                         last;
1.145     raeburn  4858:                                     }
1.138     raeburn  4859:                                 }
                   4860:                             }
                   4861:                         }
1.137     raeburn  4862:                     }
1.279     raeburn  4863:                     $rem = $i%($numinrow);
                   4864:                     if ($rem == 0) {
                   4865:                         if ($i > 0) {
                   4866:                             $datatable .= '</tr>';
                   4867:                         }
                   4868:                         $datatable .= '<tr>';
                   4869:                     }
                   4870:                     $datatable .= '<td class="LC_left_item">'.
                   4871:                                   '<span class="LC_nobreak"><label>'.
                   4872:                                   '<input type="checkbox" name="'.$prefix.'_'.$type.
                   4873:                                   '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
                   4874:                                   '</label></span></td>';
                   4875:                 }
                   4876:                 $rem = @locations%($numinrow);
                   4877:                 my $colsleft = $numinrow - $rem;
                   4878:                 if ($colsleft > 1 ) {
                   4879:                     $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   4880:                                   '&nbsp;</td>';
                   4881:                 } elsif ($colsleft == 1) {
                   4882:                     $datatable .= '<td class="LC_left_item">&nbsp;</td>';
1.137     raeburn  4883:                 }
1.279     raeburn  4884:                 $datatable .= '</tr></table>';
1.137     raeburn  4885:             }
1.279     raeburn  4886:             $datatable .= '</td></tr>';
                   4887:             $itemcount ++;
1.137     raeburn  4888:         }
                   4889:     }
1.279     raeburn  4890:     return ($datatable,$itemcount);
1.137     raeburn  4891: }
                   4892: 
1.275     raeburn  4893: sub print_ssl {
                   4894:     my ($position,$dom,$settings,$rowtotal) = @_;
                   4895:     my ($css_class,$datatable);
                   4896:     my $itemcount = 1;
                   4897:     if ($position eq 'top') {
1.281     raeburn  4898:         my $primary_id = &Apache::lonnet::domain($dom,'primary');
                   4899:         my $intdom = &Apache::lonnet::internet_dom($primary_id);
                   4900:         my $same_institution;
                   4901:         if ($intdom ne '') {
                   4902:             my $internet_names = &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
                   4903:             if (ref($internet_names) eq 'ARRAY') {
                   4904:                 if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
                   4905:                     $same_institution = 1;
                   4906:                 }
                   4907:             }
                   4908:         }
1.275     raeburn  4909:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.281     raeburn  4910:         $datatable = '<tr'.$css_class.'><td colspan="2">';
                   4911:         if ($same_institution) {
                   4912:             my %domservers = &Apache::lonnet::get_servers($dom);
                   4913:             $datatable .= &LONCAPA::SSL::print_certstatus(\%domservers,'web','domprefs');
                   4914:         } else {
                   4915:             $datatable .= &mt("You need to be logged into one of your own domain's servers to display information about the status of LON-CAPA SSL certificates.");
                   4916:         }
                   4917:         $datatable .= '</td></tr>';
1.275     raeburn  4918:         $itemcount ++;
                   4919:     } else {
                   4920:         my %titles = &ssl_titles();
                   4921:         my (%by_ip,%by_location,@intdoms,@instdoms);
                   4922:         &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
                   4923:         my @alldoms = &Apache::lonnet::all_domains();
                   4924:         my %serverhomes = %Apache::lonnet::serverhomeIDs;
                   4925:         my @domservers = &Apache::lonnet::get_servers($dom);
                   4926:         my %servers = &Apache::lonnet::internet_dom_servers($dom);
                   4927:         my %altids = &id_for_thisdom(%servers);
1.293     raeburn  4928:         if (($position eq 'connto') || ($position eq 'connfrom')) {
                   4929:             my $legacy;
                   4930:             unless (ref($settings) eq 'HASH') {
                   4931:                 my $name;
                   4932:                 if ($position eq 'connto') {
                   4933:                     $name = 'loncAllowInsecure';
                   4934:                 } else {
                   4935:                     $name = 'londAllowInsecure';
                   4936:                 }
                   4937:                 my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
                   4938:                 my @ids=&Apache::lonnet::current_machine_ids();
                   4939:                 if (($primarylibserv ne '') && (!grep(/^\Q$primarylibserv\E$/,@ids))) {
                   4940:                     my %what = (
                   4941:                                    $name => 1,
                   4942:                                );
                   4943:                     my ($result,$returnhash) =
                   4944:                         &Apache::lonnet::get_remote_globals($primarylibserv,\%what);
                   4945:                     if ($result eq 'ok') {
                   4946:                         if (ref($returnhash) eq 'HASH') {
                   4947:                             $legacy = $returnhash->{$name};
                   4948:                         }
                   4949:                     }
                   4950:                 } else {
                   4951:                     $legacy = $Apache::lonnet::perlvar{$name};
                   4952:                 }
                   4953:             }
1.275     raeburn  4954:             foreach my $type ('dom','intdom','other') {
                   4955:                 my %checked;
                   4956:                 $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   4957:                 $datatable .= '<tr'.$css_class.'><td>'.$titles{$type}.'</td>'.
                   4958:                               '<td class="LC_right_item">';
                   4959:                 my $skip; 
                   4960:                 if ($type eq 'dom') {
                   4961:                     unless (keys(%servers) > 1) {
                   4962:                         $datatable .= &mt('Nothing to set here, as there are no other servers/VMs');    
                   4963:                         $skip = 1;
                   4964:                     }
                   4965:                 }
                   4966:                 if ($type eq 'intdom') {
                   4967:                     unless (@instdoms > 1) {
                   4968:                         $datatable .= &mt('Nothing to set here, as there are no other domains for this institution');
                   4969:                         $skip = 1;
                   4970:                     } 
                   4971:                 } elsif ($type eq 'other') {
                   4972:                     if (keys(%by_location) == 0) {
                   4973:                         $datatable .= &mt('Nothing to set here, as there are no other institutions');
                   4974:                         $skip = 1;
                   4975:                     }
                   4976:                 }
                   4977:                 unless ($skip) {
                   4978:                     $checked{'yes'} = ' checked="checked"'; 
                   4979:                     if (ref($settings) eq 'HASH') {
1.293     raeburn  4980:                         if (ref($settings->{$position}) eq 'HASH') {
                   4981:                             if ($settings->{$position}->{$type} =~ /^(no|req)$/) {
1.275     raeburn  4982:                                 $checked{$1} = $checked{'yes'};
                   4983:                                 delete($checked{'yes'}); 
                   4984:                             }
                   4985:                         }
1.293     raeburn  4986:                     } else {
                   4987:                         if ($legacy == 0) {
                   4988:                             $checked{'req'} = $checked{'yes'};
                   4989:                             delete($checked{'yes'});    
                   4990:                         }
1.275     raeburn  4991:                     }
                   4992:                     foreach my $option ('no','yes','req') {
                   4993:                         $datatable .= '<span class="LC_nobreak"><label>'.
1.293     raeburn  4994:                                       '<input type="radio" name="'.$position.'_'.$type.'" '.
1.275     raeburn  4995:                                       'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
                   4996:                                       '</label></span>'.('&nbsp;'x2);
                   4997:                     }
                   4998:                 }
                   4999:                 $datatable .= '</td></tr>';
                   5000:                 $itemcount ++; 
                   5001:             }
                   5002:         } else {
                   5003:             my $prefix = 'replication';
                   5004:             my @types = ('certreq','nocertreq');
1.279     raeburn  5005:             if (keys(%by_location) == 0) {
                   5006:                 $datatable .= '<tr'.$css_class.'><td>'.
                   5007:                               &mt('Nothing to set here, as there are no other institutions').
                   5008:                               '</td></tr>';
                   5009:                 $itemcount ++;
1.275     raeburn  5010:             } else {
1.279     raeburn  5011:                 ($datatable,$itemcount) = 
                   5012:                     &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
1.275     raeburn  5013:             }
                   5014:         }
                   5015:     }
                   5016:     $$rowtotal += $itemcount;
                   5017:     return $datatable;
                   5018: }
                   5019: 
                   5020: sub ssl_titles {
                   5021:     return &Apache::lonlocal::texthash (
                   5022:                dom           => 'LON-CAPA servers/VMs from same domain',
                   5023:                intdom        => 'LON-CAPA servers/VMs from same "internet" domain',
                   5024:                other         => 'External LON-CAPA servers/VMs',
1.293     raeburn  5025:                connto        => 'Connections to other servers',
                   5026:                connfrom      => 'Connections from other servers',
1.275     raeburn  5027:                replication   => 'Replicating content to other institutions',
                   5028:                certreq       => 'Client certificate required, but specific domains exempt',
                   5029:                nocertreq     => 'No client certificate required, except for specific domains',
                   5030:                no            => 'SSL not used',
                   5031:                yes           => 'SSL Optional (used if available)',
                   5032:                req           => 'SSL Required',
                   5033:     );
1.279     raeburn  5034: }
                   5035: 
                   5036: sub print_trust {
                   5037:     my ($prefix,$dom,$settings,$rowtotal) = @_;
                   5038:     my ($css_class,$datatable,%checked,%choices);
                   5039:     my (%by_ip,%by_location,@intdoms,@instdoms);
                   5040:     &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
                   5041:     my $itemcount = 1;
                   5042:     my %titles = &trust_titles();
                   5043:     my @types = ('exc','inc');
                   5044:     if ($prefix eq 'top') {
                   5045:         $prefix = 'content';
                   5046:     } elsif ($prefix eq 'bottom') {
                   5047:         $prefix = 'msg';
                   5048:     }
                   5049:     ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
                   5050:     $$rowtotal += $itemcount;
                   5051:     return $datatable;
                   5052: }
                   5053: 
                   5054: sub trust_titles {
                   5055:     return &Apache::lonlocal::texthash(
                   5056:                content  => "Access to this domain's content by others",
                   5057:                shared   => "Access to other domain's content by this domain",
                   5058:                enroll   => "Enrollment in this domain's courses by others", 
                   5059:                othcoau  => "Co-author roles in this domain for others",
                   5060:                coaurem  => "Co-author roles for this domain's users elsewhere", 
                   5061:                domroles => "Domain roles in this domain assignable to others",
                   5062:                catalog  => "Course Catalog for this domain displayed elsewhere",
                   5063:                reqcrs   => "Requests for creation of courses in this domain by others",
                   5064:                msg      => "Users in other domains can send messages to this domain",
                   5065:                exc      => "Allow all, but exclude specific domains",
                   5066:                inc      => "Deny all, but include specific domains",
                   5067:            );
1.275     raeburn  5068: } 
                   5069: 
1.138     raeburn  5070: sub build_location_hashes {
1.275     raeburn  5071:     my ($intdoms,$by_ip,$by_location,$instdoms) = @_;
1.138     raeburn  5072:     return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
1.275     raeburn  5073:                   (ref($by_location) eq 'HASH') && (ref($instdoms) eq 'ARRAY'));
1.138     raeburn  5074:     my %iphost = &Apache::lonnet::get_iphost();
                   5075:     my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
                   5076:     my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
                   5077:     if (ref($iphost{$primary_ip}) eq 'ARRAY') {
                   5078:         foreach my $id (@{$iphost{$primary_ip}}) {
                   5079:             my $intdom = &Apache::lonnet::internet_dom($id);
                   5080:             unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
                   5081:                 push(@{$intdoms},$intdom);
                   5082:             }
                   5083:         }
                   5084:     }
                   5085:     foreach my $ip (keys(%iphost)) {
                   5086:         if (ref($iphost{$ip}) eq 'ARRAY') {
                   5087:             foreach my $id (@{$iphost{$ip}}) {
                   5088:                 my $location = &Apache::lonnet::internet_dom($id);
                   5089:                 if ($location) {
1.275     raeburn  5090:                     if (grep(/^\Q$location\E$/,@{$intdoms})) {
                   5091:                         my $dom = &Apache::lonnet::host_domain($id);
                   5092:                         unless (grep(/^\Q$dom\E/,@{$instdoms})) {
                   5093:                             push(@{$instdoms},$dom);
                   5094:                         }
                   5095:                         next;
                   5096:                     }
1.138     raeburn  5097:                     if (ref($by_ip->{$ip}) eq 'ARRAY') {
                   5098:                         unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
                   5099:                             push(@{$by_ip->{$ip}},$location);
                   5100:                         }
                   5101:                     } else {
                   5102:                         $by_ip->{$ip} = [$location];
                   5103:                     }
                   5104:                 }
                   5105:             }
                   5106:         }
                   5107:     }
                   5108:     foreach my $ip (sort(keys(%{$by_ip}))) {
                   5109:         if (ref($by_ip->{$ip}) eq 'ARRAY') {
                   5110:             @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
                   5111:             my $first = $by_ip->{$ip}->[0];
                   5112:             if (ref($by_location->{$first}) eq 'ARRAY') {
                   5113:                 unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
                   5114:                     push(@{$by_location->{$first}},$ip);
                   5115:                 }
                   5116:             } else {
                   5117:                 $by_location->{$first} = [$ip];
                   5118:             }
                   5119:         }
                   5120:     }
                   5121:     return;
                   5122: }
                   5123: 
1.145     raeburn  5124: sub current_offloads_to {
                   5125:     my ($dom,$settings,$servers) = @_;
                   5126:     my (%spareid,%otherdomconfigs);
1.152     raeburn  5127:     if (ref($servers) eq 'HASH') {
1.145     raeburn  5128:         foreach my $lonhost (sort(keys(%{$servers}))) {
                   5129:             my $gotspares;
1.152     raeburn  5130:             if (ref($settings) eq 'HASH') {
                   5131:                 if (ref($settings->{'spares'}) eq 'HASH') {
                   5132:                     if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
                   5133:                         $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
                   5134:                         $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
                   5135:                         $gotspares = 1;
                   5136:                     }
1.145     raeburn  5137:                 }
                   5138:             }
                   5139:             unless ($gotspares) {
                   5140:                 my $gotspares;
                   5141:                 my $serverhomeID =
                   5142:                     &Apache::lonnet::get_server_homeID($servers->{$lonhost});
                   5143:                 my $serverhomedom =
                   5144:                     &Apache::lonnet::host_domain($serverhomeID);
                   5145:                 if ($serverhomedom ne $dom) {
                   5146:                     if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
                   5147:                         if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
                   5148:                             if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
                   5149:                                 $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
                   5150:                                 $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
                   5151:                                 $gotspares = 1;
                   5152:                             }
                   5153:                         }
                   5154:                     } else {
                   5155:                         $otherdomconfigs{$serverhomedom} =
                   5156:                             &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
                   5157:                         if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
                   5158:                             if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
                   5159:                                 if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
                   5160:                                     if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
                   5161:                                         $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
                   5162:                                         $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
                   5163:                                         $gotspares = 1;
                   5164:                                     }
                   5165:                                 }
                   5166:                             }
                   5167:                         }
                   5168:                     }
                   5169:                 }
                   5170:             }
                   5171:             unless ($gotspares) {
                   5172:                 if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
                   5173:                     $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
                   5174:                     $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
                   5175:                } else {
                   5176:                     my $server_hostname = &Apache::lonnet::hostname($lonhost);
                   5177:                     my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
                   5178:                     if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
                   5179:                         $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
                   5180:                         $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
                   5181:                     } else {
1.150     raeburn  5182:                         my %what = (
                   5183:                              spareid => 1,
                   5184:                         );
                   5185:                         my ($result,$returnhash) = 
                   5186:                             &Apache::lonnet::get_remote_globals($lonhost,\%what);
                   5187:                         if ($result eq 'ok') { 
                   5188:                             if (ref($returnhash) eq 'HASH') {
                   5189:                                 if (ref($returnhash->{'spareid'}) eq 'HASH') {
                   5190:                                     $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
                   5191:                                     $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
                   5192:                                 }
                   5193:                             }
1.145     raeburn  5194:                         }
                   5195:                     }
                   5196:                 }
                   5197:             }
                   5198:         }
                   5199:     }
                   5200:     return %spareid;
                   5201: }
                   5202: 
                   5203: sub spares_row {
1.261     raeburn  5204:     my ($dom,$servers,$spareid,$serverhomes,$altids,$curroffloadnow,$rowtotal) = @_;
1.145     raeburn  5205:     my $css_class;
                   5206:     my $numinrow = 4;
                   5207:     my $itemcount = 1;
                   5208:     my $datatable;
1.152     raeburn  5209:     my %typetitles = &sparestype_titles();
                   5210:     if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145     raeburn  5211:         foreach my $server (sort(keys(%{$servers}))) {
1.152     raeburn  5212:             my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
                   5213:             my ($othercontrol,$serverdom);
                   5214:             if ($serverhome ne $server) {
                   5215:                 $serverdom = &Apache::lonnet::host_domain($serverhome);
                   5216:                 $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
                   5217:             } else {
                   5218:                 $serverdom = &Apache::lonnet::host_domain($server);
                   5219:                 if ($serverdom ne $dom) {
                   5220:                     $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
                   5221:                 }
                   5222:             }
                   5223:             next unless (ref($spareid->{$server}) eq 'HASH');
1.261     raeburn  5224:             my $checkednow;
                   5225:             if (ref($curroffloadnow) eq 'HASH') {
                   5226:                 if ($curroffloadnow->{$server}) {
                   5227:                     $checkednow = ' checked="checked"';
                   5228:                 }
                   5229:             }
1.145     raeburn  5230:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   5231:             $datatable .= '<tr'.$css_class.'>
                   5232:                            <td rowspan="2">
1.183     bisitz   5233:                             <span class="LC_nobreak">'.
                   5234:                           &mt('[_1] when busy, offloads to:'
1.261     raeburn  5235:                               ,'<b>'.$server.'</b>').'</span><br />'.
1.289     raeburn  5236:                           '<span class="LC_nobreak">'."\n".
1.261     raeburn  5237:                           '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
                   5238:                           '&nbsp;'.&mt('Switch active users on next access').'</label></span>'.
1.183     bisitz   5239:                           "\n";
1.145     raeburn  5240:             my (%current,%canselect);
1.152     raeburn  5241:             my @choices = 
                   5242:                 &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
                   5243:             foreach my $type ('primary','default') {
                   5244:                 if (ref($spareid->{$server}) eq 'HASH') {
1.145     raeburn  5245:                     if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
                   5246:                         my @spares = @{$spareid->{$server}{$type}};
                   5247:                         if (@spares > 0) {
1.152     raeburn  5248:                             if ($othercontrol) {
                   5249:                                 $current{$type} = join(', ',@spares);
                   5250:                             } else {
                   5251:                                 $current{$type} .= '<table>';
                   5252:                                 my $numspares = scalar(@spares);
                   5253:                                 for (my $i=0;  $i<@spares; $i++) {
                   5254:                                     my $rem = $i%($numinrow);
                   5255:                                     if ($rem == 0) {
                   5256:                                         if ($i > 0) {
                   5257:                                             $current{$type} .= '</tr>';
                   5258:                                         }
                   5259:                                         $current{$type} .= '<tr>';
1.145     raeburn  5260:                                     }
1.152     raeburn  5261:                                     $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;'.
                   5262:                                                        $spareid->{$server}{$type}[$i].
                   5263:                                                        '</label></td>'."\n";
                   5264:                                 }
                   5265:                                 my $rem = @spares%($numinrow);
                   5266:                                 my $colsleft = $numinrow - $rem;
                   5267:                                 if ($colsleft > 1 ) {
                   5268:                                     $current{$type} .= '<td colspan="'.$colsleft.
                   5269:                                                        '" class="LC_left_item">'.
                   5270:                                                        '&nbsp;</td>';
                   5271:                                 } elsif ($colsleft == 1) {
                   5272:                                     $current{$type} .= '<td class="LC_left_item">&nbsp;</td>'."\n";
1.145     raeburn  5273:                                 }
1.152     raeburn  5274:                                 $current{$type} .= '</tr></table>';
1.150     raeburn  5275:                             }
1.145     raeburn  5276:                         }
                   5277:                     }
                   5278:                     if ($current{$type} eq '') {
                   5279:                         $current{$type} = &mt('None specified');
                   5280:                     }
1.152     raeburn  5281:                     if ($othercontrol) {
                   5282:                         if ($type eq 'primary') {
                   5283:                             $canselect{$type} = $othercontrol;
                   5284:                         }
                   5285:                     } else {
                   5286:                         $canselect{$type} = 
                   5287:                             &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').'&nbsp;'.
                   5288:                             '<select name="newspare_'.$type.'_'.$server.'" '.
                   5289:                             'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
                   5290:                             '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
                   5291:                         if (@choices > 0) {
                   5292:                             foreach my $lonhost (@choices) {
                   5293:                                 $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
                   5294:                             }
                   5295:                         }
                   5296:                         $canselect{$type} .= '</select>'."\n";
                   5297:                     }
                   5298:                 } else {
                   5299:                     $current{$type} = &mt('Could not be determined');
                   5300:                     if ($type eq 'primary') {
                   5301:                         $canselect{$type} =  $othercontrol;
                   5302:                     }
1.145     raeburn  5303:                 }
1.152     raeburn  5304:                 if ($type eq 'default') {
                   5305:                     $datatable .= '<tr'.$css_class.'>';
                   5306:                 }
                   5307:                 $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
                   5308:                               '<td>'.$current{$type}.'</td>'."\n".
                   5309:                               '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145     raeburn  5310:             }
                   5311:             $itemcount ++;
                   5312:         }
                   5313:     }
                   5314:     $$rowtotal += $itemcount;
                   5315:     return $datatable;
                   5316: }
                   5317: 
1.152     raeburn  5318: sub possible_newspares {
                   5319:     my ($server,$currspares,$serverhomes,$altids) = @_;
                   5320:     my $serverhostname = &Apache::lonnet::hostname($server);
                   5321:     my %excluded;
                   5322:     if ($serverhostname ne '') {
                   5323:         %excluded = (
                   5324:                        $serverhostname => 1,
                   5325:                     );
                   5326:     }
                   5327:     if (ref($currspares) eq 'HASH') {
                   5328:         foreach my $type (keys(%{$currspares})) {
                   5329:             if (ref($currspares->{$type}) eq 'ARRAY') {
                   5330:                 if (@{$currspares->{$type}} > 0) {
                   5331:                     foreach my $curr (@{$currspares->{$type}}) {
                   5332:                         my $hostname = &Apache::lonnet::hostname($curr);
                   5333:                         $excluded{$hostname} = 1;
                   5334:                     }
                   5335:                 }
                   5336:             }
                   5337:         }
                   5338:     }
                   5339:     my @choices;
                   5340:     if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
                   5341:         if (keys(%{$serverhomes}) > 1) {
                   5342:             foreach my $name (sort(keys(%{$serverhomes}))) {
                   5343:                 unless ($excluded{$name}) {
                   5344:                     if (exists($altids->{$serverhomes->{$name}})) {
                   5345:                         push(@choices,$altids->{$serverhomes->{$name}});
                   5346:                     } else {
                   5347:                         push(@choices,$serverhomes->{$name});
1.145     raeburn  5348:                     }
                   5349:                 }
                   5350:             }
                   5351:         }
                   5352:     }
1.152     raeburn  5353:     return sort(@choices);
1.145     raeburn  5354: }
                   5355: 
1.150     raeburn  5356: sub print_loadbalancing {
                   5357:     my ($dom,$settings,$rowtotal) = @_;
                   5358:     my $primary_id = &Apache::lonnet::domain($dom,'primary');
                   5359:     my $intdom = &Apache::lonnet::internet_dom($primary_id);
                   5360:     my $numinrow = 1;
                   5361:     my $datatable;
                   5362:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.171     raeburn  5363:     my (%currbalancer,%currtargets,%currrules,%existing);
                   5364:     if (ref($settings) eq 'HASH') {
                   5365:         %existing = %{$settings};
                   5366:     }
                   5367:     if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
                   5368:         &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
                   5369:                                   \%currtargets,\%currrules);
1.150     raeburn  5370:     } else {
                   5371:         return;
                   5372:     }
                   5373:     my ($othertitle,$usertypes,$types) =
                   5374:         &Apache::loncommon::sorted_inst_types($dom);
1.209     raeburn  5375:     my $rownum = 8;
1.150     raeburn  5376:     if (ref($types) eq 'ARRAY') {
                   5377:         $rownum += scalar(@{$types});
                   5378:     }
1.171     raeburn  5379:     my @css_class = ('LC_odd_row','LC_even_row');
                   5380:     my $balnum = 0;
                   5381:     my $islast;
                   5382:     my (@toshow,$disabledtext);
                   5383:     if (keys(%currbalancer) > 0) {
                   5384:         @toshow = sort(keys(%currbalancer));
                   5385:         if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
                   5386:             push(@toshow,'');
                   5387:         }
                   5388:     } else {
                   5389:         @toshow = ('');
                   5390:         $disabledtext = &mt('No existing load balancer');
                   5391:     }
                   5392:     foreach my $lonhost (@toshow) {
                   5393:         if ($balnum == scalar(@toshow)-1) {
                   5394:             $islast = 1;
                   5395:         } else {
                   5396:             $islast = 0;
                   5397:         }
                   5398:         my $cssidx = $balnum%2;
                   5399:         my $targets_div_style = 'display: none';
                   5400:         my $disabled_div_style = 'display: block';
                   5401:         my $homedom_div_style = 'display: none';
                   5402:         $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
1.306     raeburn  5403:                       '<td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171     raeburn  5404:                       '<p>';
                   5405:         if ($lonhost eq '') {
1.210     raeburn  5406:             $datatable .= '<span class="LC_nobreak">';
1.171     raeburn  5407:             if (keys(%currbalancer) > 0) {
                   5408:                 $datatable .= &mt('Add balancer:');
                   5409:             } else {
                   5410:                 $datatable .= &mt('Enable balancer:');
                   5411:             }
                   5412:             $datatable .= '&nbsp;'.
                   5413:                           '<select name="loadbalancing_lonhost_'.$balnum.'"'.
                   5414:                           ' id="loadbalancing_lonhost_'.$balnum.'"'.
                   5415:                           ' onchange="toggleTargets('."'$balnum'".');">'."\n".
                   5416:                           '<option value="" selected="selected">'.&mt('None').
                   5417:                           '</option>'."\n";
                   5418:             foreach my $server (sort(keys(%servers))) {
                   5419:                 next if ($currbalancer{$server});
                   5420:                 $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
                   5421:             }
1.210     raeburn  5422:             $datatable .=
1.171     raeburn  5423:                 '</select>'."\n".
                   5424:                 '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" />&nbsp;</span>'."\n";
                   5425:         } else {
                   5426:             $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
                   5427:                           '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" />&nbsp;'.
                   5428:                            &mt('Stop balancing').'</label>'.
                   5429:                            '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
                   5430:             $targets_div_style = 'display: block';
                   5431:             $disabled_div_style = 'display: none';
                   5432:             if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
                   5433:                 $homedom_div_style = 'display: block';
                   5434:             }
                   5435:         }
1.306     raeburn  5436:         $datatable .= '</p></td><td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171     raeburn  5437:                   '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
                   5438:                   $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
                   5439:                   '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
                   5440:         my ($numspares,@spares) = &count_servers($lonhost,%servers);
                   5441:         my @sparestypes = ('primary','default');
                   5442:         my %typetitles = &sparestype_titles();
1.284     raeburn  5443:         my %hostherechecked = (
                   5444:                                   no => ' checked="checked"',
                   5445:                               );
1.171     raeburn  5446:         foreach my $sparetype (@sparestypes) {
                   5447:             my $targettable;
                   5448:             for (my $i=0; $i<$numspares; $i++) {
                   5449:                 my $checked;
                   5450:                 if (ref($currtargets{$lonhost}) eq 'HASH') {
                   5451:                     if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
                   5452:                         if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
                   5453:                             $checked = ' checked="checked"';
                   5454:                         }
                   5455:                     }
                   5456:                 }
                   5457:                 my ($chkboxval,$disabled);
                   5458:                 if (($lonhost ne '') && (exists($servers{$lonhost}))) {
                   5459:                     $chkboxval = $spares[$i];
                   5460:                 }
                   5461:                 if (exists($currbalancer{$spares[$i]})) {
                   5462:                     $disabled = ' disabled="disabled"';
                   5463:                 }
1.210     raeburn  5464:                 $targettable .=
1.253     raeburn  5465:                     '<td><span class="LC_nobreak"><label>'.
                   5466:                     '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.171     raeburn  5467:                     $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  5468:                     '</span></label></span></td>';
1.171     raeburn  5469:                 my $rem = $i%($numinrow);
                   5470:                 if ($rem == 0) {
                   5471:                     if (($i > 0) && ($i < $numspares-1)) {
                   5472:                         $targettable .= '</tr>';
                   5473:                     }
                   5474:                     if ($i < $numspares-1) {
                   5475:                         $targettable .= '<tr>';
1.150     raeburn  5476:                     }
                   5477:                 }
                   5478:             }
1.171     raeburn  5479:             if ($targettable ne '') {
                   5480:                 my $rem = $numspares%($numinrow);
                   5481:                 my $colsleft = $numinrow - $rem;
                   5482:                 if ($colsleft > 1 ) {
                   5483:                     $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   5484:                                     '&nbsp;</td>';
                   5485:                 } elsif ($colsleft == 1) {
                   5486:                     $targettable .= '<td class="LC_left_item">&nbsp;</td>';
                   5487:                 }
                   5488:                 $datatable .=  '<i>'.$typetitles{$sparetype}.'</i><br />'.
                   5489:                                '<table><tr>'.$targettable.'</tr></table><br />';
                   5490:             }
1.284     raeburn  5491:             $hostherechecked{$sparetype} = '';
                   5492:             if (ref($currtargets{$lonhost}) eq 'HASH') {
                   5493:                 if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
                   5494:                     if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
                   5495:                         $hostherechecked{$sparetype} = ' checked="checked"';
                   5496:                         $hostherechecked{'no'} = '';
                   5497:                     }
                   5498:                 }
                   5499:             }
                   5500:         }
                   5501:         $datatable .= &mt('Hosting on balancer itself').'<br />'.
                   5502:                       '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
                   5503:                       $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
                   5504:         foreach my $sparetype (@sparestypes) {
                   5505:             $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
                   5506:                           'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
                   5507:                           '</i></label><br />';
1.171     raeburn  5508:         }
                   5509:         $datatable .= '</div></td></tr>'.
                   5510:                       &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
                   5511:                                            $othertitle,$usertypes,$types,\%servers,
                   5512:                                            \%currbalancer,$lonhost,
                   5513:                                            $targets_div_style,$homedom_div_style,
                   5514:                                            $css_class[$cssidx],$balnum,$islast);
                   5515:         $$rowtotal += $rownum;
                   5516:         $balnum ++;
                   5517:     }
                   5518:     $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
                   5519:     return $datatable;
                   5520: }
                   5521: 
                   5522: sub get_loadbalancers_config {
                   5523:     my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
                   5524:     return unless ((ref($servers) eq 'HASH') &&
                   5525:                    (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
                   5526:                    (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
                   5527:     if (keys(%{$existing}) > 0) {
                   5528:         my $oldlonhost;
                   5529:         foreach my $key (sort(keys(%{$existing}))) {
                   5530:             if ($key eq 'lonhost') {
                   5531:                 $oldlonhost = $existing->{'lonhost'};
                   5532:                 $currbalancer->{$oldlonhost} = 1;
                   5533:             } elsif ($key eq 'targets') {
                   5534:                 if ($oldlonhost) {
                   5535:                     $currtargets->{$oldlonhost} = $existing->{'targets'};
                   5536:                 }
                   5537:             } elsif ($key eq 'rules') {
                   5538:                 if ($oldlonhost) {
                   5539:                     $currrules->{$oldlonhost} = $existing->{'rules'};
                   5540:                 }
                   5541:             } elsif (ref($existing->{$key}) eq 'HASH') {
                   5542:                 $currbalancer->{$key} = 1;
                   5543:                 $currtargets->{$key} = $existing->{$key}{'targets'};
                   5544:                 $currrules->{$key} = $existing->{$key}{'rules'};
1.150     raeburn  5545:             }
                   5546:         }
1.171     raeburn  5547:     } else {
                   5548:         my ($balancerref,$targetsref) =
                   5549:                 &Apache::lonnet::get_lonbalancer_config($servers);
                   5550:         if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
                   5551:             foreach my $server (sort(keys(%{$balancerref}))) {
                   5552:                 $currbalancer->{$server} = 1;
                   5553:                 $currtargets->{$server} = $targetsref->{$server};
1.150     raeburn  5554:             }
                   5555:         }
                   5556:     }
1.171     raeburn  5557:     return;
1.150     raeburn  5558: }
                   5559: 
                   5560: sub loadbalancing_rules {
                   5561:     my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171     raeburn  5562:         $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
                   5563:         $css_class,$balnum,$islast) = @_;
1.150     raeburn  5564:     my $output;
1.171     raeburn  5565:     my $num = 0;
1.210     raeburn  5566:     my ($alltypes,$othertypes,$titles) =
1.150     raeburn  5567:         &loadbalancing_titles($dom,$intdom,$usertypes,$types);
                   5568:     if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH'))  {
                   5569:         foreach my $type (@{$alltypes}) {
1.171     raeburn  5570:             $num ++;
1.150     raeburn  5571:             my $current;
                   5572:             if (ref($currrules) eq 'HASH') {
                   5573:                 $current = $currrules->{$type};
                   5574:             }
1.253     raeburn  5575:             if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.171     raeburn  5576:                 if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150     raeburn  5577:                     $current = '';
                   5578:                 }
                   5579:             }
                   5580:             $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171     raeburn  5581:                                              $servers,$currbalancer,$lonhost,$dom,
                   5582:                                              $targets_div_style,$homedom_div_style,
                   5583:                                              $css_class,$balnum,$num,$islast);
1.150     raeburn  5584:         }
                   5585:     }
                   5586:     return $output;
                   5587: }
                   5588: 
                   5589: sub loadbalancing_titles {
                   5590:     my ($dom,$intdom,$usertypes,$types) = @_;
                   5591:     my %othertypes = (
                   5592:            '_LC_adv'         => &mt('Advanced users from [_1]',$dom),
                   5593:            '_LC_author'      => &mt('Users from [_1] with author role',$dom),
                   5594:            '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
                   5595:            '_LC_external'    => &mt('Users not from [_1]',$intdom),
1.209     raeburn  5596:            '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
                   5597:            '_LC_ipchange'    => &mt('Non-SSO users with IP mismatch'),
1.150     raeburn  5598:                      );
1.209     raeburn  5599:     my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.302     raeburn  5600:     my @available;
1.150     raeburn  5601:     if (ref($types) eq 'ARRAY') {
1.302     raeburn  5602:         @available = @{$types};
1.150     raeburn  5603:     }
1.302     raeburn  5604:     unless (grep(/^default$/,@available)) {
                   5605:         push(@available,'default');
                   5606:     }
                   5607:     unshift(@alltypes,@available);
1.150     raeburn  5608:     my %titles;
                   5609:     foreach my $type (@alltypes) {
                   5610:         if ($type =~ /^_LC_/) {
                   5611:             $titles{$type} = $othertypes{$type};
                   5612:         } elsif ($type eq 'default') {
                   5613:             $titles{$type} = &mt('All users from [_1]',$dom);
                   5614:             if (ref($types) eq 'ARRAY') {
                   5615:                 if (@{$types} > 0) {
                   5616:                     $titles{$type} = &mt('Other users from [_1]',$dom);
                   5617:                 }
                   5618:             }
                   5619:         } elsif (ref($usertypes) eq 'HASH') {
                   5620:             $titles{$type} = $usertypes->{$type};
                   5621:         }
                   5622:     }
                   5623:     return (\@alltypes,\%othertypes,\%titles);
                   5624: }
                   5625: 
                   5626: sub loadbalance_rule_row {
1.171     raeburn  5627:     my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
                   5628:         $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.209     raeburn  5629:     my @rulenames;
1.150     raeburn  5630:     my %ruletitles = &offloadtype_text();
1.209     raeburn  5631:     if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.254     raeburn  5632:         @rulenames = ('balancer','offloadedto','specific');
1.150     raeburn  5633:     } else {
1.209     raeburn  5634:         @rulenames = ('default','homeserver');
                   5635:         if ($type eq '_LC_external') {
                   5636:             push(@rulenames,'externalbalancer');
                   5637:         } else {
                   5638:             push(@rulenames,'specific');
                   5639:         }
                   5640:         push(@rulenames,'none');
1.150     raeburn  5641:     }
                   5642:     my $style = $targets_div_style;
1.253     raeburn  5643:     if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150     raeburn  5644:         $style = $homedom_div_style;
                   5645:     }
1.171     raeburn  5646:     my $space;
                   5647:     if ($islast && $num == 1) {
                   5648:         $space = '<div display="inline-block">&nbsp;</div>';
                   5649:     }
1.210     raeburn  5650:     my $output =
1.306     raeburn  5651:         '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td style="vertical-align: top">'.$space.
1.171     raeburn  5652:         '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
                   5653:         '<td valaign="top">'.$space.
                   5654:         '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150     raeburn  5655:     for (my $i=0; $i<@rulenames; $i++) {
                   5656:         my $rule = $rulenames[$i];
                   5657:         my ($checked,$extra);
                   5658:         if ($rulenames[$i] eq 'default') {
                   5659:             $rule = '';
                   5660:         }
                   5661:         if ($rulenames[$i] eq 'specific') {
                   5662:             if (ref($servers) eq 'HASH') {
                   5663:                 my $default;
                   5664:                 if (($current ne '') && (exists($servers->{$current}))) {
                   5665:                     $checked = ' checked="checked"';
                   5666:                 }
                   5667:                 unless ($checked) {
                   5668:                     $default = ' selected="selected"';
                   5669:                 }
1.210     raeburn  5670:                 $extra =
1.171     raeburn  5671:                     ':&nbsp;<select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
                   5672:                     '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
                   5673:                     '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
                   5674:                     '<option value=""'.$default.'></option>'."\n";
                   5675:                 foreach my $server (sort(keys(%{$servers}))) {
                   5676:                     if (ref($currbalancer) eq 'HASH') {
                   5677:                         next if (exists($currbalancer->{$server}));
                   5678:                     }
1.150     raeburn  5679:                     my $selected;
1.171     raeburn  5680:                     if ($server eq $current) {
1.150     raeburn  5681:                         $selected = ' selected="selected"';
                   5682:                     }
1.171     raeburn  5683:                     $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150     raeburn  5684:                 }
                   5685:                 $extra .= '</select>';
                   5686:             }
                   5687:         } elsif ($rule eq $current) {
                   5688:             $checked = ' checked="checked"';
                   5689:         }
                   5690:         $output .= '<span class="LC_nobreak"><label>'.
1.171     raeburn  5691:                    '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
                   5692:                    '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
                   5693:                    $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.254     raeburn  5694:                    ')"'.$checked.' />&nbsp;';
                   5695:         if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
                   5696:             $output .= $ruletitles{'particular'};
                   5697:         } else {
                   5698:             $output .= $ruletitles{$rulenames[$i]};
                   5699:         }
                   5700:         $output .= '</label>'.$extra.'</span><br />'."\n";
1.150     raeburn  5701:     }
                   5702:     $output .= '</div></td></tr>'."\n";
                   5703:     return $output;
                   5704: }
                   5705: 
                   5706: sub offloadtype_text {
                   5707:     my %ruletitles = &Apache::lonlocal::texthash (
                   5708:            'default'          => 'Offloads to default destinations',
                   5709:            'homeserver'       => "Offloads to user's home server",
                   5710:            'externalbalancer' => "Offloads to Load Balancer in user's domain",
                   5711:            'specific'         => 'Offloads to specific server',
1.161     raeburn  5712:            'none'             => 'No offload',
1.209     raeburn  5713:            'balancer'         => 'Session hosted on Load Balancer, after re-authentication',
                   5714:            'offloadedto'      => 'Session hosted on offload server, after re-authentication',
1.254     raeburn  5715:            'particular'       => 'Session hosted (after re-auth) on server:',
1.150     raeburn  5716:     );
                   5717:     return %ruletitles;
                   5718: }
                   5719: 
                   5720: sub sparestype_titles {
                   5721:     my %typestitles = &Apache::lonlocal::texthash (
                   5722:                           'primary' => 'primary',
                   5723:                           'default' => 'default',
                   5724:                       );
                   5725:     return %typestitles;
                   5726: }
                   5727: 
1.28      raeburn  5728: sub contact_titles {
                   5729:     my %titles = &Apache::lonlocal::texthash (
1.286     raeburn  5730:                    'supportemail'    => 'Support E-mail address',
                   5731:                    'adminemail'      => 'Default Server Admin E-mail address',
                   5732:                    'errormail'       => 'Error reports to be e-mailed to',
                   5733:                    'packagesmail'    => 'Package update alerts to be e-mailed to',
1.315     raeburn  5734:                    'helpdeskmail'    => "Helpdesk requests from all users in this domain",
                   5735:                    'otherdomsmail'   => 'Helpdesk requests from users in other (unconfigured) domains',
1.286     raeburn  5736:                    'lonstatusmail'   => 'E-mail from nightly status check (warnings/errors)',
                   5737:                    'requestsmail'    => 'E-mail from course requests requiring approval',
                   5738:                    'updatesmail'     => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.203     raeburn  5739:                    'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.28      raeburn  5740:                  );
                   5741:     my %short_titles = &Apache::lonlocal::texthash (
                   5742:                            adminemail   => 'Admin E-mail address',
                   5743:                            supportemail => 'Support E-mail',
                   5744:                        );   
                   5745:     return (\%titles,\%short_titles);
                   5746: }
                   5747: 
1.286     raeburn  5748: sub helpform_fields {
                   5749:     my %titles =  &Apache::lonlocal::texthash (
                   5750:                        'username'   => 'Name',
                   5751:                        'user'       => 'Username/domain',
                   5752:                        'phone'      => 'Phone',
                   5753:                        'cc'         => 'Cc e-mail',
                   5754:                        'course'     => 'Course Details',
                   5755:                        'section'    => 'Sections',
1.289     raeburn  5756:                        'screenshot' => 'File upload',
1.286     raeburn  5757:     );
                   5758:     my @fields = ('username','phone','user','course','section','cc','screenshot');
                   5759:     my %possoptions = (
                   5760:                         username     => ['yes','no','req'],
1.289     raeburn  5761:                         phone        => ['yes','no','req'],
1.286     raeburn  5762:                         user         => ['yes','no'],
1.289     raeburn  5763:                         cc           => ['yes','no'],
1.286     raeburn  5764:                         course       => ['yes','no'],
                   5765:                         section      => ['yes','no'],
                   5766:                         screenshot   => ['yes','no'],
                   5767:                       );
                   5768:     my %fieldoptions = &Apache::lonlocal::texthash (
                   5769:                          'yes'  => 'Optional',
                   5770:                          'req'  => 'Required',
                   5771:                          'no'   => "Not shown",
                   5772:     );
                   5773:     return (\@fields,\%titles,\%fieldoptions,\%possoptions);
                   5774: }
                   5775: 
1.72      raeburn  5776: sub tool_titles {
                   5777:     my %titles = &Apache::lonlocal::texthash (
1.162     raeburn  5778:                      aboutme    => 'Personal web page',
1.86      raeburn  5779:                      blog       => 'Blog',
1.162     raeburn  5780:                      webdav     => 'WebDAV',
1.86      raeburn  5781:                      portfolio  => 'Portfolio',
1.88      bisitz   5782:                      official   => 'Official courses (with institutional codes)',
                   5783:                      unofficial => 'Unofficial courses',
1.98      raeburn  5784:                      community  => 'Communities',
1.216     raeburn  5785:                      textbook   => 'Textbook courses',
1.271     raeburn  5786:                      placement  => 'Placement tests',
1.86      raeburn  5787:                  );
1.72      raeburn  5788:     return %titles;
                   5789: }
                   5790: 
1.101     raeburn  5791: sub courserequest_titles {
                   5792:     my %titles = &Apache::lonlocal::texthash (
                   5793:                                    official   => 'Official',
                   5794:                                    unofficial => 'Unofficial',
                   5795:                                    community  => 'Communities',
1.216     raeburn  5796:                                    textbook   => 'Textbook',
1.271     raeburn  5797:                                    placement  => 'Placement tests',
1.101     raeburn  5798:                                    norequest  => 'Not allowed',
1.104     raeburn  5799:                                    approval   => 'Approval by Dom. Coord.',
1.101     raeburn  5800:                                    validate   => 'With validation',
                   5801:                                    autolimit  => 'Numerical limit',
1.103     raeburn  5802:                                    unlimited  => '(blank for unlimited)',
1.101     raeburn  5803:                  );
                   5804:     return %titles;
                   5805: }
                   5806: 
1.163     raeburn  5807: sub authorrequest_titles {
                   5808:     my %titles = &Apache::lonlocal::texthash (
                   5809:                                    norequest  => 'Not allowed',
                   5810:                                    approval   => 'Approval by Dom. Coord.',
                   5811:                                    automatic  => 'Automatic approval',
                   5812:                  );
                   5813:     return %titles;
1.210     raeburn  5814: }
1.163     raeburn  5815: 
1.101     raeburn  5816: sub courserequest_conditions {
                   5817:     my %conditions = &Apache::lonlocal::texthash (
1.104     raeburn  5818:        approval    => '(Processing of request subject to approval by Domain Coordinator).',
1.193     bisitz   5819:        validate   => '(Processing of request subject to institutional validation).',
1.101     raeburn  5820:                  );
                   5821:     return %conditions;
                   5822: }
                   5823: 
                   5824: 
1.27      raeburn  5825: sub print_usercreation {
1.30      raeburn  5826:     my ($position,$dom,$settings,$rowtotal) = @_;
1.27      raeburn  5827:     my $numinrow = 4;
1.28      raeburn  5828:     my $datatable;
                   5829:     if ($position eq 'top') {
1.30      raeburn  5830:         $$rowtotal ++;
1.34      raeburn  5831:         my $rowcount = 0;
1.32      raeburn  5832:         my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28      raeburn  5833:         if (ref($rules) eq 'HASH') {
                   5834:             if (keys(%{$rules}) > 0) {
1.32      raeburn  5835:                 $datatable .= &user_formats_row('username',$settings,$rules,
                   5836:                                                 $ruleorder,$numinrow,$rowcount);
1.30      raeburn  5837:                 $$rowtotal ++;
1.32      raeburn  5838:                 $rowcount ++;
                   5839:             }
                   5840:         }
                   5841:         my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
                   5842:         if (ref($idrules) eq 'HASH') {
                   5843:             if (keys(%{$idrules}) > 0) {
                   5844:                 $datatable .= &user_formats_row('id',$settings,$idrules,
                   5845:                                                 $idruleorder,$numinrow,$rowcount);
                   5846:                 $$rowtotal ++;
                   5847:                 $rowcount ++;
1.28      raeburn  5848:             }
                   5849:         }
1.39      raeburn  5850:         if ($rowcount == 0) {
                   5851:             $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';  
                   5852:             $$rowtotal ++;
                   5853:             $rowcount ++;
                   5854:         }
1.34      raeburn  5855:     } elsif ($position eq 'middle') {
1.224     raeburn  5856:         my @creators = ('author','course','requestcrs');
1.37      raeburn  5857:         my ($rules,$ruleorder) =
                   5858:             &Apache::lonnet::inst_userrules($dom,'username');
1.34      raeburn  5859:         my %lt = &usercreation_types();
                   5860:         my %checked;
                   5861:         if (ref($settings) eq 'HASH') {
                   5862:             if (ref($settings->{'cancreate'}) eq 'HASH') {
                   5863:                 foreach my $item (@creators) {
                   5864:                     $checked{$item} = $settings->{'cancreate'}{$item};
                   5865:                 }
                   5866:             } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
                   5867:                 foreach my $item (@creators) {
                   5868:                     if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
                   5869:                         $checked{$item} = 'none';
                   5870:                     }
                   5871:                 }
                   5872:             }
                   5873:         }
                   5874:         my $rownum = 0;
                   5875:         foreach my $item (@creators) {
                   5876:             $rownum ++;
1.224     raeburn  5877:             if ($checked{$item} eq '') {
                   5878:                 $checked{$item} = 'any';
1.34      raeburn  5879:             }
                   5880:             my $css_class;
                   5881:             if ($rownum%2) {
                   5882:                 $css_class = '';
                   5883:             } else {
                   5884:                 $css_class = ' class="LC_odd_row" ';
                   5885:             }
                   5886:             $datatable .= '<tr'.$css_class.'>'.
                   5887:                          '<td><span class="LC_nobreak">'.$lt{$item}.
1.306     raeburn  5888:                          '</span></td><td style="text-align: right">';
1.224     raeburn  5889:             my @options = ('any');
                   5890:             if (ref($rules) eq 'HASH') {
                   5891:                 if (keys(%{$rules}) > 0) {
                   5892:                     push(@options,('official','unofficial'));
1.37      raeburn  5893:                 }
                   5894:             }
1.224     raeburn  5895:             push(@options,'none');
1.37      raeburn  5896:             foreach my $option (@options) {
1.50      raeburn  5897:                 my $type = 'radio';
1.34      raeburn  5898:                 my $check = ' ';
1.224     raeburn  5899:                 if ($checked{$item} eq $option) {
                   5900:                     $check = ' checked="checked" ';
1.34      raeburn  5901:                 } 
                   5902:                 $datatable .= '<span class="LC_nobreak"><label>'.
1.50      raeburn  5903:                               '<input type="'.$type.'" name="can_createuser_'.
1.34      raeburn  5904:                               $item.'" value="'.$option.'"'.$check.'/>&nbsp;'.
                   5905:                               $lt{$option}.'</label>&nbsp;&nbsp;</span>';
                   5906:             }
                   5907:             $datatable .= '</td></tr>';
                   5908:         }
1.28      raeburn  5909:     } else {
                   5910:         my @contexts = ('author','course','domain');
                   5911:         my @authtypes = ('int','krb4','krb5','loc');
                   5912:         my %checked;
                   5913:         if (ref($settings) eq 'HASH') {
                   5914:             if (ref($settings->{'authtypes'}) eq 'HASH') {
                   5915:                 foreach my $item (@contexts) {
                   5916:                     if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
                   5917:                         foreach my $auth (@authtypes) {
                   5918:                             if ($settings->{'authtypes'}{$item}{$auth}) {
                   5919:                                 $checked{$item}{$auth} = ' checked="checked" ';
                   5920:                             }
                   5921:                         }
                   5922:                     }
                   5923:                 }
1.27      raeburn  5924:             }
1.35      raeburn  5925:         } else {
                   5926:             foreach my $item (@contexts) {
1.36      raeburn  5927:                 foreach my $auth (@authtypes) {
1.35      raeburn  5928:                     $checked{$item}{$auth} = ' checked="checked" ';
                   5929:                 }
                   5930:             }
1.27      raeburn  5931:         }
1.28      raeburn  5932:         my %title = &context_names();
                   5933:         my %authname = &authtype_names();
                   5934:         my $rownum = 0;
                   5935:         my $css_class; 
                   5936:         foreach my $item (@contexts) {
                   5937:             if ($rownum%2) {
                   5938:                 $css_class = '';
                   5939:             } else {
                   5940:                 $css_class = ' class="LC_odd_row" ';
                   5941:             }
1.30      raeburn  5942:             $datatable .=   '<tr'.$css_class.'>'.
1.28      raeburn  5943:                             '<td>'.$title{$item}.
                   5944:                             '</td><td class="LC_left_item">'.
                   5945:                             '<span class="LC_nobreak">';
                   5946:             foreach my $auth (@authtypes) {
                   5947:                 $datatable .= '<label>'. 
                   5948:                               '<input type="checkbox" name="'.$item.'_auth" '.
                   5949:                               $checked{$item}{$auth}.' value="'.$auth.'" />'.
                   5950:                               $authname{$auth}.'</label>&nbsp;';
                   5951:             }
                   5952:             $datatable .= '</span></td></tr>';
                   5953:             $rownum ++;
1.27      raeburn  5954:         }
1.30      raeburn  5955:         $$rowtotal += $rownum;
1.27      raeburn  5956:     }
                   5957:     return $datatable;
                   5958: }
                   5959: 
1.224     raeburn  5960: sub print_selfcreation {
                   5961:     my ($position,$dom,$settings,$rowtotal) = @_;
1.305     raeburn  5962:     my (@selfcreate,$createsettings,$processing,$emailoptions,$emailverified,
                   5963:         $emaildomain,$datatable);
1.224     raeburn  5964:     if (ref($settings) eq 'HASH') {
                   5965:         if (ref($settings->{'cancreate'}) eq 'HASH') {
                   5966:             $createsettings = $settings->{'cancreate'};
1.236     raeburn  5967:             if (ref($createsettings) eq 'HASH') {
                   5968:                 if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
                   5969:                     @selfcreate = @{$createsettings->{'selfcreate'}};
                   5970:                 } elsif ($createsettings->{'selfcreate'} ne '') {
                   5971:                     if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
                   5972:                         @selfcreate = ('email','login','sso');
                   5973:                     } elsif ($createsettings->{'selfcreate'} ne 'none') {
                   5974:                         @selfcreate = ($createsettings->{'selfcreate'});
                   5975:                     }
                   5976:                 }
                   5977:                 if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
                   5978:                     $processing = $createsettings->{'selfcreateprocessing'};
1.224     raeburn  5979:                 }
1.305     raeburn  5980:                 if (ref($createsettings->{'emailoptions'}) eq 'HASH') {
                   5981:                     $emailoptions = $createsettings->{'emailoptions'};
                   5982:                 }
1.303     raeburn  5983:                 if (ref($createsettings->{'emailverified'}) eq 'HASH') {
                   5984:                     $emailverified = $createsettings->{'emailverified'};
                   5985:                 }
                   5986:                 if (ref($createsettings->{'emaildomain'}) eq 'HASH') {
                   5987:                     $emaildomain = $createsettings->{'emaildomain'};
                   5988:                 }
1.224     raeburn  5989:             }
                   5990:         }
                   5991:     }
                   5992:     my %radiohash;
                   5993:     my $numinrow = 4;
                   5994:     map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
1.302     raeburn  5995:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.224     raeburn  5996:     if ($position eq 'top') {
                   5997:         my %choices = &Apache::lonlocal::texthash (
                   5998:                                                       cancreate_login      => 'Institutional Login',
                   5999:                                                       cancreate_sso        => 'Institutional Single Sign On',
                   6000:                                                   );
                   6001:         my @toggles = sort(keys(%choices));
                   6002:         my %defaultchecked = (
                   6003:                                'cancreate_login' => 'off',
                   6004:                                'cancreate_sso'   => 'off',
                   6005:                              );
1.228     raeburn  6006:         my ($onclick,$itemcount);
1.224     raeburn  6007:         ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
                   6008:                                                      \%choices,$itemcount,$onclick);
1.228     raeburn  6009:         $$rowtotal += $itemcount;
                   6010:         
1.224     raeburn  6011:         if (ref($usertypes) eq 'HASH') {
                   6012:             if (keys(%{$usertypes}) > 0) {
                   6013:                 $datatable .= &insttypes_row($createsettings,$types,$usertypes,
                   6014:                                              $dom,$numinrow,$othertitle,
1.305     raeburn  6015:                                              'statustocreate',$rowtotal);
1.224     raeburn  6016:                 $$rowtotal ++;
                   6017:             }
                   6018:         }
1.240     raeburn  6019:         my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
                   6020:         my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
                   6021:         $fieldtitles{'inststatus'} = &mt('Institutional status');
                   6022:         my $rem;
                   6023:         my $numperrow = 2;
                   6024:         my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
                   6025:         $datatable .= '<tr'.$css_class.'>'.
1.241     raeburn  6026:                      '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.240     raeburn  6027:                      '<td class="LC_left_item">'."\n".
                   6028:                      '<table><tr><td>'."\n";
                   6029:         for (my $i=0; $i<@fields; $i++) {
                   6030:             $rem = $i%($numperrow);
                   6031:             if ($rem == 0) {
                   6032:                 if ($i > 0) {
                   6033:                     $datatable .= '</tr>';
                   6034:                 }
                   6035:                 $datatable .= '<tr>';
                   6036:             }
                   6037:             my $currval;
1.248     raeburn  6038:             if (ref($createsettings) eq 'HASH') {
                   6039:                 if (ref($createsettings->{'shibenv'}) eq 'HASH') {
                   6040:                     $currval = $createsettings->{'shibenv'}{$fields[$i]};
                   6041:                 }
1.240     raeburn  6042:             }
                   6043:             $datatable .= '<td class="LC_left_item">'.
                   6044:                           '<span class="LC_nobreak">'.
                   6045:                           '<input type="text" name="shibenv_'.$fields[$i].'" '.
                   6046:                           'value="'.$currval.'" size="10" />&nbsp;'.
                   6047:                           $fieldtitles{$fields[$i]}.'</span></td>';
                   6048:         }
                   6049:         my $colsleft = $numperrow - $rem;
                   6050:         if ($colsleft > 1 ) {
                   6051:             $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   6052:                          '&nbsp;</td>';
                   6053:         } elsif ($colsleft == 1) {
                   6054:             $datatable .= '<td class="LC_left_item">&nbsp;</td>';
                   6055:         }
                   6056:         $datatable .= '</tr></table></td></tr>';
                   6057:         $$rowtotal ++;
1.224     raeburn  6058:     } elsif ($position eq 'middle') {
                   6059:         my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
1.302     raeburn  6060:         my @posstypes;
1.224     raeburn  6061:         if (ref($types) eq 'ARRAY') {
1.302     raeburn  6062:             @posstypes = @{$types};
                   6063:         }
                   6064:         unless (grep(/^default$/,@posstypes)) {
                   6065:             push(@posstypes,'default');
                   6066:         }
                   6067:         my %usertypeshash;
                   6068:         if (ref($usertypes) eq 'HASH') {
                   6069:             %usertypeshash = %{$usertypes};
                   6070:         }
                   6071:         $usertypeshash{'default'} = $othertitle;
                   6072:         foreach my $status (@posstypes) {
                   6073:             $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
                   6074:                                                    $numinrow,$$rowtotal,\%usertypeshash);
                   6075:             $$rowtotal ++;
1.224     raeburn  6076:         }
                   6077:     } else {
1.236     raeburn  6078:         my %choices = &Apache::lonlocal::texthash (
1.305     raeburn  6079:                           'cancreate_email' => 'Non-institutional username (via e-mail verification)',
1.236     raeburn  6080:                                                   );
                   6081:         my @toggles = sort(keys(%choices));
                   6082:         my %defaultchecked = (
                   6083:                                'cancreate_email' => 'off',
                   6084:                              );
1.305     raeburn  6085:         my $customclass = 'LC_selfcreate_email';
                   6086:         my $classprefix = 'LC_canmodify_emailusername_';
                   6087:         my $optionsprefix = 'LC_options_emailusername_';
1.236     raeburn  6088:         my $display = 'none';
1.305     raeburn  6089:         my $rowstyle = 'display:none';
1.236     raeburn  6090:         if (grep(/^\Qemail\E$/,@selfcreate)) {
                   6091:             $display = 'block';
1.305     raeburn  6092:             $rowstyle = 'display:table-row';
1.236     raeburn  6093:         }
1.305     raeburn  6094:         my $onclick = "toggleRows(this.form,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
                   6095:         ($datatable,$$rowtotal) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
                   6096:                                                      \%choices,$$rowtotal,$onclick);
                   6097:         $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal,$customclass,
                   6098:                                          $rowstyle);
                   6099:         $$rowtotal ++;
                   6100:         $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal,$customclass,
                   6101:                                       $rowstyle);
                   6102:         $$rowtotal ++;
                   6103:         my (@ordered,@posstypes,%usertypeshash);
1.236     raeburn  6104:         my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.305     raeburn  6105:         my ($emailrules,$emailruleorder) =
                   6106:             &Apache::lonnet::inst_userrules($dom,'email');
                   6107:         my $primary_id = &Apache::lonnet::domain($dom,'primary');
                   6108:         my $intdom = &Apache::lonnet::internet_dom($primary_id);
                   6109:         if (ref($types) eq 'ARRAY') {
                   6110:             @posstypes = @{$types};
                   6111:         }
                   6112:         if (@posstypes) {
                   6113:             unless (grep(/^default$/,@posstypes)) {
                   6114:                 push(@posstypes,'default');
1.302     raeburn  6115:             }
                   6116:             if (ref($usertypes) eq 'HASH') {
                   6117:                 %usertypeshash = %{$usertypes};
                   6118:             }
1.305     raeburn  6119:             my $currassign;
                   6120:             if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
                   6121:                 $currassign = {
                   6122:                                   selfassign => $domdefaults{'inststatusguest'},
                   6123:                               };
                   6124:                 @ordered = @{$domdefaults{'inststatusguest'}};
                   6125:             } else {
                   6126:                 $currassign = { selfassign => [] };
                   6127:             }
                   6128:             my $onclicktypes = "toggleDataRow(this.form,'selfassign','$customclass','$optionsprefix',);".
                   6129:                                "toggleDataRow(this.form,'selfassign','$customclass','$classprefix',1);";
                   6130:             $datatable .= &insttypes_row($currassign,$types,$usertypes,$dom,
                   6131:                                          $numinrow,$othertitle,'selfassign',
                   6132:                                          $rowtotal,$onclicktypes,$customclass,
                   6133:                                          $rowstyle);
                   6134:             $$rowtotal ++;
1.302     raeburn  6135:             $usertypeshash{'default'} = $othertitle;
1.305     raeburn  6136:             foreach my $status (@posstypes) {
                   6137:                 my $css_class;
                   6138:                 if ($$rowtotal%2) {
                   6139:                     $css_class = 'LC_odd_row ';
                   6140:                 }
                   6141:                 $css_class .= $customclass;
                   6142:                 my $rowid = $optionsprefix.$status;
                   6143:                 my $hidden = 1;
                   6144:                 my $currstyle = 'display:none';
                   6145:                 if (grep(/^\Q$status\E$/,@ordered)) {
                   6146:                     $currstyle = $rowstyle;
                   6147:                     $hidden = 0; 
                   6148:                 }
                   6149:                 $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
                   6150:                                              $emailrules,$emailruleorder,$settings,$status,$rowid,
                   6151:                                              $usertypeshash{$status},$css_class,$currstyle,$intdom);
                   6152:                 unless ($hidden) {
                   6153:                     $$rowtotal ++;
                   6154:                 }
1.224     raeburn  6155:             }
1.302     raeburn  6156:         } else {
1.305     raeburn  6157:             my $css_class;
                   6158:             if ($$rowtotal%2) {
                   6159:                 $css_class = 'LC_odd_row ';
                   6160:             }
                   6161:             $css_class .= $customclass;
1.302     raeburn  6162:             $usertypeshash{'default'} = $othertitle;
1.305     raeburn  6163:             $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
                   6164:                                          $emailrules,$emailruleorder,$settings,'default','',
                   6165:                                          $othertitle,$css_class,$rowstyle,$intdom);
                   6166:             $$rowtotal ++;
1.224     raeburn  6167:         }
                   6168:         my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.228     raeburn  6169:         $numinrow = 1;
1.305     raeburn  6170:         if (@posstypes) {
                   6171:             foreach my $status (@posstypes) {
                   6172:                 my $rowid = $classprefix.$status;
                   6173:                 my $datarowstyle = 'display:none';
                   6174:                 if (grep(/^\Q$status\E$/,@ordered)) { 
                   6175:                     $datarowstyle = $rowstyle; 
                   6176:                 }
                   6177:                 $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
                   6178:                                                        $numinrow,$$rowtotal,\%usertypeshash,$infofields,
                   6179:                                                        $infotitles,$rowid,$customclass,$datarowstyle);
                   6180:                 unless ($datarowstyle eq 'display:none') {
                   6181:                     $$rowtotal ++;
                   6182:                 }
1.224     raeburn  6183:             }
1.305     raeburn  6184:         } else {
                   6185:             $datatable .= &modifiable_userdata_row('cancreate','emailusername_default',$settings,
                   6186:                                                    $numinrow,$$rowtotal,\%usertypeshash,$infofields,
                   6187:                                                    $infotitles,'',$customclass,$rowstyle);
1.224     raeburn  6188:         }
                   6189:     }
                   6190:     return $datatable;
                   6191: }
                   6192: 
1.305     raeburn  6193: sub selfcreate_javascript {
                   6194:     return <<"ENDSCRIPT";
                   6195: 
                   6196: <script type="text/javascript">
                   6197: // <![CDATA[
                   6198: 
                   6199: function toggleRows(form,radio,checkbox,target,prefix,altprefix) {
                   6200:     var x = document.getElementsByClassName(target);
                   6201:     var insttypes = 0;
                   6202:     var insttypeRegExp = new RegExp(prefix);
                   6203:     if ((x.length != undefined) && (x.length > 0)) {
                   6204:         if (form.elements[radio].length != undefined) {
                   6205:             for (var i=0; i<form.elements[radio].length; i++) {
                   6206:                 if (form.elements[radio][i].checked) {
                   6207:                     if (form.elements[radio][i].value == 1) {
                   6208:                         for (var j=0; j<x.length; j++) {
                   6209:                             if (x[j].id == 'undefined') {
                   6210:                                 x[j].style.display = 'table-row';
                   6211:                             } else if (insttypeRegExp.test(x[j].id)) {
                   6212:                                 insttypes ++;
                   6213:                             } else {
                   6214:                                 x[j].style.display = 'table-row';
                   6215:                             }
                   6216:                         }
                   6217:                     } else {
                   6218:                         for (var j=0; j<x.length; j++) {
                   6219:                             x[j].style.display = 'none';
                   6220:                         }
1.236     raeburn  6221:                     }
1.305     raeburn  6222:                     break;
                   6223:                 }
                   6224:             }
                   6225:             if (insttypes > 0) {
                   6226:                 toggleDataRow(form,checkbox,target,altprefix);
                   6227:                 toggleDataRow(form,checkbox,target,prefix,1);
                   6228:             }
                   6229:         }
                   6230:     }
                   6231:     return;
                   6232: }
                   6233: 
                   6234: function toggleDataRow(form,checkbox,target,prefix,docount) {
                   6235:     if (form.elements[checkbox].length != undefined) {
                   6236:         var count = 0;
                   6237:         if (docount) {
                   6238:             for (var i=0; i<form.elements[checkbox].length; i++) {
                   6239:                 if (form.elements[checkbox][i].checked) {
                   6240:                     count ++;
1.236     raeburn  6241:                 }
1.305     raeburn  6242:             }
                   6243:         }
                   6244:         for (var i=0; i<form.elements[checkbox].length; i++) {
                   6245:             var type = form.elements[checkbox][i].value;
                   6246:             if (document.getElementById(prefix+type)) {
                   6247:                 if (form.elements[checkbox][i].checked) {
                   6248:                     document.getElementById(prefix+type).style.display = 'table-row';
                   6249:                     if (count % 2 == 1) {
                   6250:                         document.getElementById(prefix+type).className = target+' LC_odd_row';
                   6251:                     } else {
                   6252:                         document.getElementById(prefix+type).className = target;
1.236     raeburn  6253:                     }
1.305     raeburn  6254:                     count ++;
1.236     raeburn  6255:                 } else {
1.305     raeburn  6256:                     document.getElementById(prefix+type).style.display = 'none';
                   6257:                 }
                   6258:             }
                   6259:         }
                   6260:     }
                   6261:     return;
                   6262: }
                   6263: 
                   6264: function toggleEmailOptions(form,radio,prefix,altprefix,status) {
                   6265:     var caller = radio+'_'+status;
                   6266:     if (form.elements[caller].length != undefined) {
                   6267:         for (var i=0; i<form.elements[caller].length; i++) {
                   6268:             if (form.elements[caller][i].checked) {
                   6269:                 if (document.getElementById(altprefix+'_inst_'+status)) {
                   6270:                     var curr = form.elements[caller][i].value;
                   6271:                     if (prefix) {
                   6272:                         document.getElementById(prefix+'_'+status).style.display = 'none';
                   6273:                     }
                   6274:                     document.getElementById(altprefix+'_inst_'+status).style.display = 'none';
                   6275:                     document.getElementById(altprefix+'_noninst_'+status).style.display = 'none';
                   6276:                     if (curr == 'custom') {
                   6277:                         if (prefix) { 
                   6278:                             document.getElementById(prefix+'_'+status).style.display = 'inline';
                   6279:                         }
                   6280:                     } else if (curr == 'inst') {
                   6281:                         document.getElementById(altprefix+'_inst_'+status).style.display = 'inline';
                   6282:                     } else if (curr == 'noninst') {
                   6283:                         document.getElementById(altprefix+'_noninst_'+status).style.display = 'inline';
1.236     raeburn  6284:                     }
1.305     raeburn  6285:                     break;
1.236     raeburn  6286:                 }
                   6287:             }
                   6288:         }
                   6289:     }
                   6290: }
                   6291: 
1.305     raeburn  6292: // ]]>
                   6293: </script>
                   6294: 
                   6295: ENDSCRIPT
                   6296: }
                   6297: 
                   6298: sub noninst_users {
                   6299:     my ($processing,$emailverified,$emailoptions,$emaildomain,$emailrules,
                   6300:         $emailruleorder,$settings,$type,$rowid,$typetitle,$css_class,$rowstyle,$intdom) = @_; 
                   6301:     my $class = 'LC_left_item';
                   6302:     if ($css_class) {
                   6303:         $css_class = ' class="'.$css_class.'"'; 
                   6304:     }
                   6305:     if ($rowid) {
                   6306:         $rowid = ' id="'.$rowid.'"';
                   6307:     }
                   6308:     if ($rowstyle) {
                   6309:         $rowstyle = ' style="'.$rowstyle.'"';
                   6310:     }
                   6311:     my ($output,$description);
                   6312:     if ($type eq 'default') {
                   6313:         $description = &mt('Requests for: [_1]',$typetitle);
                   6314:     } else {
                   6315:         $description = &mt('Requests for: [_1] (status self-reported)',$typetitle);
                   6316:     }
                   6317:     $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
                   6318:               "<td>$description</td>\n".           
                   6319:               '<td class="'.$class.'" colspan="2">'.
                   6320:               '<table><tr>';
                   6321:     my %headers = &Apache::lonlocal::texthash( 
                   6322:               approve  => 'Processing',
                   6323:               email    => 'E-mail',
                   6324:               username => 'Username',
                   6325:     );
                   6326:     foreach my $item ('approve','email','username') {
                   6327:         $output .= '<th>'.$headers{$item}.'</th>';
1.303     raeburn  6328:     }
1.305     raeburn  6329:     $output .= '</tr><tr>';
                   6330:     foreach my $item ('approve','email','username') {
1.306     raeburn  6331:         $output .= '<td style="vertical-align: top">';
1.305     raeburn  6332:         my (%choices,@options,$hashref,$defoption,$name,$onclick,$hascustom);
                   6333:         if ($item eq 'approve') {
                   6334:             %choices = &Apache::lonlocal::texthash (
                   6335:                                                      automatic => 'Automatically approved',
                   6336:                                                      approval  => 'Queued for approval',
                   6337:                                                    );
                   6338:             @options = ('automatic','approval');
                   6339:             $hashref = $processing;
                   6340:             $defoption = 'automatic';
                   6341:             $name = 'cancreate_emailprocess_'.$type;
                   6342:         } elsif ($item eq 'email') {
                   6343:             %choices = &Apache::lonlocal::texthash (
                   6344:                                                      any     => 'Any e-mail',
                   6345:                                                      inst    => 'Institutional only',
                   6346:                                                      noninst => 'Non-institutional only',
                   6347:                                                      custom  => 'Custom restrictions',
                   6348:                                                    );
                   6349:             @options = ('any','inst','noninst');
                   6350:             my $showcustom;
                   6351:             if (ref($emailrules) eq 'HASH') {
                   6352:                 if (keys(%{$emailrules}) > 0) {
                   6353:                     push(@options,'custom');
                   6354:                     $showcustom = 'cancreate_emailrule';
                   6355:                     if (ref($settings) eq 'HASH') {
                   6356:                         if (ref($settings->{'email_rule'}) eq 'ARRAY') {
                   6357:                             foreach my $rule (@{$settings->{'email_rule'}}) {
                   6358:                                 if (exists($emailrules->{$rule})) {
                   6359:                                     $hascustom ++;
                   6360:                                 }
                   6361:                             }
                   6362:                         } elsif (ref($settings->{'email_rule'}) eq 'HASH') {
                   6363:                             if (ref($settings->{'email_rule'}{$type}) eq 'ARRAY') {
                   6364:                                 foreach my $rule (@{$settings->{'email_rule'}{$type}}) {
                   6365:                                     if (exists($emailrules->{$rule})) {
                   6366:                                         $hascustom ++;
                   6367:                                     }
                   6368:                                 }
                   6369:                             }
                   6370:                         }
                   6371:                     }
                   6372:                 }
                   6373:             }
                   6374:             $onclick = ' onclick="toggleEmailOptions(this.form,'."'cancreate_emailoptions','$showcustom',".
                   6375:                                                      "'cancreate_emaildomain','$type'".');"';
                   6376:             $hashref = $emailoptions;
                   6377:             $defoption = 'any';
                   6378:             $name = 'cancreate_emailoptions_'.$type;
                   6379:         } elsif ($item eq 'username') {
                   6380:             %choices = &Apache::lonlocal::texthash (
                   6381:                                                      all    => 'Same as e-mail',
                   6382:                                                      first  => 'Omit @domain',
                   6383:                                                      free   => 'Free to choose',
                   6384:                                                    );
                   6385:             @options = ('all','first','free');
                   6386:             $hashref = $emailverified;
                   6387:             $defoption = 'all';
                   6388:             $name = 'cancreate_usernameoptions_'.$type;
                   6389:         }
                   6390:         foreach my $option (@options) {
                   6391:             my $checked;
                   6392:             if (ref($hashref) eq 'HASH') {
                   6393:                 if ($type eq '') {
                   6394:                     if (!exists($hashref->{'default'})) {
                   6395:                         if ($option eq $defoption) {
                   6396:                             $checked = ' checked="checked"';
                   6397:                         }
                   6398:                     } else {
                   6399:                         if ($hashref->{'default'} eq $option) {
                   6400:                             $checked = ' checked="checked"';
                   6401:                         }
1.303     raeburn  6402:                     }
                   6403:                 } else {
1.305     raeburn  6404:                     if (!exists($hashref->{$type})) {
                   6405:                         if ($option eq $defoption) {
                   6406:                             $checked = ' checked="checked"';
                   6407:                         }
                   6408:                     } else {
                   6409:                         if ($hashref->{$type} eq $option) {
                   6410:                             $checked = ' checked="checked"';
                   6411:                         }
1.303     raeburn  6412:                     }
                   6413:                 }
1.305     raeburn  6414:             } elsif (($item eq 'email') && ($hascustom)) {
                   6415:                 if ($option eq 'custom') {
                   6416:                     $checked = ' checked="checked"';
                   6417:                 }
                   6418:             } elsif ($option eq $defoption) {
                   6419:                 $checked = ' checked="checked"';
                   6420:             }
                   6421:             $output .= '<span class="LC_nobreak"><label>'.
                   6422:                        '<input type="radio" name="'.$name.'"'.
                   6423:                        $checked.' value="'.$option.'"'.$onclick.' />'.
                   6424:                        $choices{$option}.'</label></span><br />';
                   6425:             if ($item eq 'email') {
                   6426:                 if ($option eq 'custom') {
                   6427:                     my $id = 'cancreate_emailrule_'.$type;
                   6428:                     my $display = 'none';
                   6429:                     if ($checked) {
                   6430:                         $display = 'inline';
1.303     raeburn  6431:                     }
1.305     raeburn  6432:                     my $numinrow = 2;
                   6433:                     $output .= '<fieldset id="'.$id.'" style="display:'.$display.';">'.
                   6434:                                '<legend>'.&mt('Disallow').'</legend><table>'.
                   6435:                                &user_formats_row('email',$settings,$emailrules,
                   6436:                                                  $emailruleorder,$numinrow,'',$type);
                   6437:                               '</table></fieldset>';
                   6438:                 } elsif (($option eq 'inst') || ($option eq 'noninst')) {
                   6439:                     my %text = &Apache::lonlocal::texthash (
                   6440:                                                              inst    => 'must end:',
                   6441:                                                              noninst => 'cannot end:',
                   6442:                                                            );
                   6443:                     my $value;
                   6444:                     if (ref($emaildomain) eq 'HASH') {
                   6445:                         if (ref($emaildomain->{$type}) eq 'HASH') {
                   6446:                             $value = $emaildomain->{$type}->{$option}; 
1.303     raeburn  6447:                         }
                   6448:                     }
1.305     raeburn  6449:                     if ($value eq '') {
                   6450:                         $value = '@'.$intdom;
                   6451:                     }
                   6452:                     my $condition = 'cancreate_emaildomain_'.$option.'_'.$type;
                   6453:                     my $display = 'none';
                   6454:                     if ($checked) {
                   6455:                         $display = 'inline';
                   6456:                     }
                   6457:                     $output .= '<div id="'.$condition.'" style="display:'.$display.';">'.
                   6458:                                '<span class="LC_domprefs_email">'.$text{$option}.'</span> '.
                   6459:                                '<input type="text" name="'.$condition.'" value="'.$value.'" size="10" />'.
                   6460:                                '</div>';
1.303     raeburn  6461:                 }
                   6462:             }
                   6463:         }
1.305     raeburn  6464:         $output .= '</td>'."\n";
1.303     raeburn  6465:     }
1.305     raeburn  6466:     $output .= "</tr></table></td></tr>\n";
1.303     raeburn  6467:     return $output;
                   6468: }
                   6469: 
1.165     raeburn  6470: sub captcha_choice {
1.305     raeburn  6471:     my ($context,$settings,$itemcount,$customcss,$rowstyle) = @_;
1.269     raeburn  6472:     my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
                   6473:         $vertext,$currver);
1.165     raeburn  6474:     my %lt = &captcha_phrases();
                   6475:     $keyentry = 'hidden';
                   6476:     if ($context eq 'cancreate') {
1.224     raeburn  6477:         $rowname = &mt('CAPTCHA validation');
1.169     raeburn  6478:     } elsif ($context eq 'login') {
                   6479:         $rowname =  &mt('"Contact helpdesk" CAPTCHA validation');
1.165     raeburn  6480:     }
                   6481:     if (ref($settings) eq 'HASH') {
                   6482:         if ($settings->{'captcha'}) {
                   6483:             $checked{$settings->{'captcha'}} = ' checked="checked"';
                   6484:         } else {
                   6485:             $checked{'original'} = ' checked="checked"';
                   6486:         }
                   6487:         if ($settings->{'captcha'} eq 'recaptcha') {
                   6488:             $pubtext = $lt{'pub'};
                   6489:             $privtext = $lt{'priv'};
                   6490:             $keyentry = 'text';
1.269     raeburn  6491:             $vertext = $lt{'ver'};
                   6492:             $currver = $settings->{'recaptchaversion'};
                   6493:             if ($currver ne '2') {
                   6494:                 $currver = 1;
                   6495:             }
1.165     raeburn  6496:         }
                   6497:         if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
                   6498:             $currpub = $settings->{'recaptchakeys'}{'public'};
                   6499:             $currpriv = $settings->{'recaptchakeys'}{'private'};
                   6500:         }
                   6501:     } else {
                   6502:         $checked{'original'} = ' checked="checked"';
                   6503:     }
1.305     raeburn  6504:     my $css_class;
                   6505:     if ($itemcount%2) {
                   6506:         $css_class = 'LC_odd_row';
                   6507:     }
                   6508:     if ($customcss) {
                   6509:         $css_class .= " $customcss";
                   6510:     }
                   6511:     $css_class =~ s/^\s+//;
                   6512:     if ($css_class) {
                   6513:         $css_class = ' class="'.$css_class.'"';
                   6514:     }
                   6515:     if ($rowstyle) {
                   6516:         $css_class .= ' style="'.$rowstyle.'"';
                   6517:     }
1.169     raeburn  6518:     my $output = '<tr'.$css_class.'>'.
                   6519:                  '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
1.165     raeburn  6520:                  '<table><tr><td>'."\n";
                   6521:     foreach my $option ('original','recaptcha','notused') {
                   6522:         $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
                   6523:                    $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
                   6524:                    $lt{$option}.'</label></span>';
                   6525:         unless ($option eq 'notused') {
                   6526:             $output .= ('&nbsp;'x2)."\n";
                   6527:         }
                   6528:     }
                   6529: #
                   6530: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
                   6531: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
1.210     raeburn  6532: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
1.165     raeburn  6533: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
1.210     raeburn  6534: #
1.165     raeburn  6535:     $output .= '</td></tr>'."\n".
1.305     raeburn  6536:                '<tr><td class="LC_zero_height">'."\n".
1.165     raeburn  6537:                '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span>&nbsp;'."\n".
                   6538:                '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
                   6539:                $currpub.'" size="40" /></span><br />'."\n".
                   6540:                '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span>&nbsp;'."\n".
                   6541:                '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.269     raeburn  6542:                $currpriv.'" size="40" /></span><br />'.
                   6543:                '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span>&nbsp;'."\n".
                   6544:                '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
                   6545:                $currver.'" size="3" /></span><br />'.
                   6546:                '</td></tr></table>'."\n".
1.165     raeburn  6547:                '</td></tr>';
                   6548:     return $output;
                   6549: }
                   6550: 
1.32      raeburn  6551: sub user_formats_row {
1.305     raeburn  6552:     my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount,$status) = @_;
1.32      raeburn  6553:     my $output;
                   6554:     my %text = (
                   6555:                    'username' => 'new usernames',
                   6556:                    'id'       => 'IDs',
                   6557:                );
1.305     raeburn  6558:     unless ($type eq 'email') {
                   6559:         my $css_class = $rowcount%2?' class="LC_odd_row"':'';
                   6560:         $output = '<tr '.$css_class.'>'.
                   6561:                   '<td><span class="LC_nobreak">'.
                   6562:                   &mt("Format rules to check for $text{$type}: ").
                   6563:                   '</td><td class="LC_left_item" colspan="2"><table>';
1.63      raeburn  6564:     }
1.27      raeburn  6565:     my $rem;
                   6566:     if (ref($ruleorder) eq 'ARRAY') {
                   6567:         for (my $i=0; $i<@{$ruleorder}; $i++) {
                   6568:             if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
                   6569:                 my $rem = $i%($numinrow);
                   6570:                 if ($rem == 0) {
                   6571:                     if ($i > 0) {
                   6572:                         $output .= '</tr>';
                   6573:                     }
                   6574:                     $output .= '<tr>';
                   6575:                 }
                   6576:                 my $check = ' ';
1.39      raeburn  6577:                 if (ref($settings) eq 'HASH') {
                   6578:                     if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
                   6579:                         if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
                   6580:                             $check = ' checked="checked" ';
                   6581:                         }
1.305     raeburn  6582:                     } elsif ((ref($settings->{$type.'_rule'}) eq 'HASH') && ($status ne '')) {
                   6583:                         if (ref($settings->{$type.'_rule'}->{$status}) eq 'ARRAY') {
                   6584:                             if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}->{$status}})) {
                   6585:                                 $check = ' checked="checked" ';
                   6586:                             }
                   6587:                         }
1.27      raeburn  6588:                     }
                   6589:                 }
1.305     raeburn  6590:                 my $name = $type.'_rule';
                   6591:                 if ($type eq 'email') {
                   6592:                     $name .= '_'.$status;
                   6593:                 }
1.27      raeburn  6594:                 $output .= '<td class="LC_left_item">'.
                   6595:                            '<span class="LC_nobreak"><label>'.
1.311     raeburn  6596:                            '<input type="checkbox" name="'.$name.'" '.
1.27      raeburn  6597:                            'value="'.$ruleorder->[$i].'"'.$check.'/>'.
                   6598:                            $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
                   6599:             }
                   6600:         }
                   6601:         $rem = @{$ruleorder}%($numinrow);
                   6602:     }
1.305     raeburn  6603:     my $colsleft;
                   6604:     if ($rem) {
                   6605:         $colsleft = $numinrow - $rem;
                   6606:     }
1.27      raeburn  6607:     if ($colsleft > 1 ) {
                   6608:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   6609:                    '&nbsp;</td>';
                   6610:     } elsif ($colsleft == 1) {
                   6611:         $output .= '<td class="LC_left_item">&nbsp;</td>';
                   6612:     }
1.305     raeburn  6613:     $output .= '</tr></table>';
                   6614:     unless ($type eq 'email') {
                   6615:         $output .= '</td></tr>';
                   6616:     }
1.27      raeburn  6617:     return $output;
                   6618: }
                   6619: 
1.34      raeburn  6620: sub usercreation_types {
                   6621:     my %lt = &Apache::lonlocal::texthash (
                   6622:                     author     => 'When adding a co-author',
                   6623:                     course     => 'When adding a user to a course',
1.100     raeburn  6624:                     requestcrs => 'When requesting a course',
1.34      raeburn  6625:                     any        => 'Any',
                   6626:                     official   => 'Institutional only ',
                   6627:                     unofficial => 'Non-institutional only',
                   6628:                     none       => 'None',
                   6629:     );
                   6630:     return %lt;
1.48      raeburn  6631: }
1.34      raeburn  6632: 
1.224     raeburn  6633: sub selfcreation_types {
                   6634:     my %lt = &Apache::lonlocal::texthash (
                   6635:                     selfcreate => 'User creates own account',
                   6636:                     any        => 'Any',
                   6637:                     official   => 'Institutional only ',
                   6638:                     unofficial => 'Non-institutional only',
                   6639:                     email      => 'E-mail address',
                   6640:                     login      => 'Institutional Login',
                   6641:                     sso        => 'SSO',
                   6642:              );
                   6643: }
                   6644: 
1.28      raeburn  6645: sub authtype_names {
                   6646:     my %lt = &Apache::lonlocal::texthash(
                   6647:                       int    => 'Internal',
                   6648:                       krb4   => 'Kerberos 4',
                   6649:                       krb5   => 'Kerberos 5',
                   6650:                       loc    => 'Local',
                   6651:                   );
                   6652:     return %lt;
                   6653: }
                   6654: 
                   6655: sub context_names {
                   6656:     my %context_title = &Apache::lonlocal::texthash(
                   6657:        author => 'Creating users when an Author',
                   6658:        course => 'Creating users when in a course',
                   6659:        domain => 'Creating users when a Domain Coordinator',
                   6660:     );
                   6661:     return %context_title;
                   6662: }
                   6663: 
1.33      raeburn  6664: sub print_usermodification {
                   6665:     my ($position,$dom,$settings,$rowtotal) = @_;
                   6666:     my $numinrow = 4;
                   6667:     my ($context,$datatable,$rowcount);
                   6668:     if ($position eq 'top') {
                   6669:         $rowcount = 0;
                   6670:         $context = 'author'; 
                   6671:         foreach my $role ('ca','aa') {
                   6672:             $datatable .= &modifiable_userdata_row($context,$role,$settings,
                   6673:                                                    $numinrow,$rowcount);
                   6674:             $$rowtotal ++;
                   6675:             $rowcount ++;
                   6676:         }
1.230     raeburn  6677:     } elsif ($position eq 'bottom') {
1.33      raeburn  6678:         $context = 'course';
                   6679:         $rowcount = 0;
                   6680:         foreach my $role ('st','ep','ta','in','cr') {
                   6681:             $datatable .= &modifiable_userdata_row($context,$role,$settings,
                   6682:                                                    $numinrow,$rowcount);
                   6683:             $$rowtotal ++;
                   6684:             $rowcount ++;
                   6685:         }
                   6686:     }
                   6687:     return $datatable;
                   6688: }
                   6689: 
1.43      raeburn  6690: sub print_defaults {
1.236     raeburn  6691:     my ($position,$dom,$settings,$rowtotal) = @_;
1.43      raeburn  6692:     my $rownum = 0;
1.294     raeburn  6693:     my ($datatable,$css_class,$titles);
                   6694:     unless ($position eq 'bottom') {
                   6695:         $titles = &defaults_titles($dom);
                   6696:     }
1.236     raeburn  6697:     if ($position eq 'top') {
                   6698:         my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
                   6699:                      'datelocale_def','portal_def');
                   6700:         my %defaults;
                   6701:         if (ref($settings) eq 'HASH') {
                   6702:             %defaults = %{$settings};
1.43      raeburn  6703:         } else {
1.236     raeburn  6704:             my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
                   6705:             foreach my $item (@items) {
                   6706:                 $defaults{$item} = $domdefaults{$item};
                   6707:             }
1.43      raeburn  6708:         }
1.236     raeburn  6709:         foreach my $item (@items) {
                   6710:             if ($rownum%2) {
                   6711:                 $css_class = '';
                   6712:             } else {
                   6713:                 $css_class = ' class="LC_odd_row" ';
                   6714:             }
                   6715:             $datatable .= '<tr'.$css_class.'>'.
                   6716:                           '<td><span class="LC_nobreak">'.$titles->{$item}.
                   6717:                           '</span></td><td class="LC_right_item" colspan="3">';
                   6718:             if ($item eq 'auth_def') {
                   6719:                 my @authtypes = ('internal','krb4','krb5','localauth');
                   6720:                 my %shortauth = (
                   6721:                                  internal => 'int',
                   6722:                                  krb4 => 'krb4',
                   6723:                                  krb5 => 'krb5',
                   6724:                                  localauth  => 'loc'
                   6725:                                 );
                   6726:                 my %authnames = &authtype_names();
                   6727:                 foreach my $auth (@authtypes) {
                   6728:                     my $checked = ' ';
                   6729:                     if ($defaults{$item} eq $auth) {
                   6730:                         $checked = ' checked="checked" ';
                   6731:                     }
                   6732:                     $datatable .= '<label><input type="radio" name="'.$item.
                   6733:                                   '" value="'.$auth.'"'.$checked.'/>'.
                   6734:                                   $authnames{$shortauth{$auth}}.'</label>&nbsp;&nbsp;';
                   6735:                 }
                   6736:             } elsif ($item eq 'timezone_def') {
                   6737:                 my $includeempty = 1;
                   6738:                 $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
                   6739:             } elsif ($item eq 'datelocale_def') {
                   6740:                 my $includeempty = 1;
                   6741:                 $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
                   6742:             } elsif ($item eq 'lang_def') {
1.263     raeburn  6743:                 my $includeempty = 1;
                   6744:                 $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.236     raeburn  6745:             } else {
                   6746:                 my $size;
                   6747:                 if ($item eq 'portal_def') {
                   6748:                     $size = ' size="25"';
                   6749:                 }
                   6750:                 $datatable .= '<input type="text" name="'.$item.'" value="'.
                   6751:                               $defaults{$item}.'"'.$size.' />';
1.43      raeburn  6752:             }
1.236     raeburn  6753:             $datatable .= '</td></tr>';
                   6754:             $rownum ++;
                   6755:         }
1.294     raeburn  6756:     } elsif ($position eq 'middle') {
                   6757:         my @items = ('intauth_cost','intauth_check','intauth_switch');
                   6758:         my %defaults;
                   6759:         if (ref($settings) eq 'HASH') {
                   6760:             %defaults = %{$settings};
                   6761:             if ($defaults{'intauth_cost'} !~ /^\d+$/) {
                   6762:                 $defaults{'intauth_cost'} = 10;
                   6763:             }
                   6764:             if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
                   6765:                 $defaults{'intauth_check'} = 0;
                   6766:             }
                   6767:             if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
                   6768:                 $defaults{'intauth_switch'} = 0;
                   6769:             }
                   6770:         } else {
                   6771:             %defaults = (
                   6772:                           'intauth_cost'   => 10,
                   6773:                           'intauth_check'  => 0,
                   6774:                           'intauth_switch' => 0,
                   6775:                         );
                   6776:         }
                   6777:         foreach my $item (@items) {
                   6778:             if ($rownum%2) {
                   6779:                 $css_class = '';
                   6780:             } else {
                   6781:                 $css_class = ' class="LC_odd_row" ';
                   6782:             }
                   6783:             $datatable .= '<tr'.$css_class.'>'.
                   6784:                           '<td><span class="LC_nobreak">'.$titles->{$item}.
                   6785:                           '</span></td><td class="LC_left_item" colspan="3">';
                   6786:             if ($item eq 'intauth_switch') {
                   6787:                 my @options = (0,1,2);
                   6788:                 my %optiondesc = &Apache::lonlocal::texthash (
                   6789:                                    0 => 'No',
                   6790:                                    1 => 'Yes',
                   6791:                                    2 => 'Yes, and copy existing passwd file to passwd.bak file',
                   6792:                                  );
                   6793:                 $datatable .= '<table width="100%">';
                   6794:                 foreach my $option (@options) {
                   6795:                     my $checked = ' ';
                   6796:                     if ($defaults{$item} eq $option) {
                   6797:                         $checked = ' checked="checked"';
                   6798:                     }
                   6799:                     $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
                   6800:                                   '<label><input type="radio" name="'.$item.
                   6801:                                   '" value="'.$option.'"'.$checked.' />'.
                   6802:                                   $optiondesc{$option}.'</label></span></td></tr>';
                   6803:                 }
                   6804:                 $datatable .= '</table>';
                   6805:             } elsif ($item eq 'intauth_check') {
                   6806:                 my @options = (0,1,2);
                   6807:                 my %optiondesc = &Apache::lonlocal::texthash (
                   6808:                                    0 => 'No',
                   6809:                                    1 => 'Yes, allow login then update passwd file using default cost (if higher)',
                   6810:                                    2 => 'Yes, disallow login if stored cost is less than domain default',
                   6811:                                  );
                   6812:                 $datatable .= '<table wisth="100%">';
                   6813:                 foreach my $option (@options) {
                   6814:                     my $checked = ' ';
                   6815:                     my $onclick;
                   6816:                     if ($defaults{$item} eq $option) {
                   6817:                         $checked = ' checked="checked"';
                   6818:                     }
                   6819:                     if ($option == 2) {
                   6820:                         $onclick = ' onclick="javascript:warnIntAuth(this);"';
                   6821:                     }
                   6822:                     $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
                   6823:                                   '<label><input type="radio" name="'.$item.
                   6824:                                   '" value="'.$option.'"'.$checked.$onclick.' />'.
                   6825:                                   $optiondesc{$option}.'</label></span></td></tr>';
                   6826:                 }
                   6827:                 $datatable .= '</table>';
                   6828:             } else {
                   6829:                 $datatable .= '<input type="text" name="'.$item.'" value="'.
                   6830:                               $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />'; 
                   6831:             }
                   6832:             $datatable .= '</td></tr>';
                   6833:             $rownum ++;
                   6834:         }
1.236     raeburn  6835:     } else {
1.294     raeburn  6836:         my %defaults;
1.236     raeburn  6837:         if (ref($settings) eq 'HASH') {
1.305     raeburn  6838:             if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
1.236     raeburn  6839:                 my $maxnum = @{$settings->{'inststatusorder'}};
                   6840:                 for (my $i=0; $i<$maxnum; $i++) {
                   6841:                     $css_class = $rownum%2?' class="LC_odd_row"':'';
                   6842:                     my $item = $settings->{'inststatusorder'}->[$i];
                   6843:                     my $title = $settings->{'inststatustypes'}->{$item};
                   6844:                     my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
                   6845:                     $datatable .= '<tr'.$css_class.'>'.
                   6846:                                   '<td><span class="LC_nobreak">'.
                   6847:                                   '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
                   6848:                     for (my $k=0; $k<=$maxnum; $k++) {
                   6849:                         my $vpos = $k+1;
                   6850:                         my $selstr;
                   6851:                         if ($k == $i) {
                   6852:                             $selstr = ' selected="selected" ';
                   6853:                         }
                   6854:                         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   6855:                     }
                   6856:                     $datatable .= '</select>&nbsp;'.&mt('Internal ID:').'&nbsp;<b>'.$item.'</b>&nbsp;'.
                   6857:                                   '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
                   6858:                                   &mt('delete').'</span></td>'.
1.305     raeburn  6859:                                   '<td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.&mt('Name displayed:').
1.236     raeburn  6860:                                   '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
1.305     raeburn  6861:                                   '</span></td></tr>';
1.236     raeburn  6862:                 }
                   6863:                 $css_class = $rownum%2?' class="LC_odd_row"':'';
                   6864:                 my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
                   6865:                 $datatable .= '<tr '.$css_class.'>'.
                   6866:                               '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
                   6867:                 for (my $k=0; $k<=$maxnum; $k++) {
                   6868:                     my $vpos = $k+1;
                   6869:                     my $selstr;
                   6870:                     if ($k == $maxnum) {
                   6871:                         $selstr = ' selected="selected" ';
                   6872:                     }
                   6873:                     $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   6874:                 }
                   6875:                 $datatable .= '</select>&nbsp;'.&mt('Internal ID:').
1.263     raeburn  6876:                               '<input type="text" size="10" name="addinststatus" value="" />'.
1.236     raeburn  6877:                               '&nbsp;'.&mt('(new)').
1.305     raeburn  6878:                               '</span></td><td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.
1.236     raeburn  6879:                               &mt('Name displayed:').
                   6880:                               '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
                   6881:                               '</tr>'."\n";
                   6882:                 $rownum ++;
1.141     raeburn  6883:             }
1.43      raeburn  6884:         }
                   6885:     }
                   6886:     $$rowtotal += $rownum;
                   6887:     return $datatable;
                   6888: }
                   6889: 
1.168     raeburn  6890: sub get_languages_hash {
                   6891:     my %langchoices;
                   6892:     foreach my $id (&Apache::loncommon::languageids()) {
                   6893:         my $code = &Apache::loncommon::supportedlanguagecode($id);
                   6894:         if ($code ne '') {
                   6895:             $langchoices{$code} =  &Apache::loncommon::plainlanguagedescription($id);
                   6896:         }
                   6897:     }
                   6898:     return %langchoices;
                   6899: }
                   6900: 
1.43      raeburn  6901: sub defaults_titles {
1.141     raeburn  6902:     my ($dom) = @_;
1.43      raeburn  6903:     my %titles = &Apache::lonlocal::texthash (
                   6904:                    'auth_def'      => 'Default authentication type',
                   6905:                    'auth_arg_def'  => 'Default authentication argument',
                   6906:                    'lang_def'      => 'Default language',
1.54      raeburn  6907:                    'timezone_def'  => 'Default timezone',
1.68      raeburn  6908:                    'datelocale_def' => 'Default locale for dates',
1.141     raeburn  6909:                    'portal_def'     => 'Portal/Default URL',
1.294     raeburn  6910:                    'intauth_cost'   => 'Encryption cost for bcrypt (positive integer)',
                   6911:                    'intauth_check'  => 'Check bcrypt cost if authenticated',
                   6912:                    'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43      raeburn  6913:                  );
1.141     raeburn  6914:     if ($dom) {
                   6915:         my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
                   6916:         my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
                   6917:         my $protocol = $Apache::lonnet::protocol{$uprimary_id};
                   6918:         $protocol = 'http' if ($protocol ne 'https');
                   6919:         if ($uint_dom) {
                   6920:             $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
                   6921:                                          $uint_dom);
                   6922:         }
                   6923:     }
1.43      raeburn  6924:     return (\%titles);
                   6925: }
                   6926: 
1.46      raeburn  6927: sub print_scantronformat {
                   6928:     my ($r,$dom,$confname,$settings,$rowtotal) = @_;
                   6929:     my $itemcount = 1;
1.60      raeburn  6930:     my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
                   6931:         %confhash);
1.46      raeburn  6932:     my $switchserver = &check_switchserver($dom,$confname);
                   6933:     my %lt = &Apache::lonlocal::texthash (
1.95      www      6934:                 default => 'Default bubblesheet format file error',
                   6935:                 custom  => 'Custom bubblesheet format file error',
1.46      raeburn  6936:              );
                   6937:     my %scantronfiles = (
                   6938:         default => 'default.tab',
                   6939:         custom => 'custom.tab',
                   6940:     );
                   6941:     foreach my $key (keys(%scantronfiles)) {
                   6942:         $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
                   6943:                               .$scantronfiles{$key};
                   6944:     }
                   6945:     my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
                   6946:     if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
                   6947:         if (!$switchserver) {
                   6948:             my $servadm = $r->dir_config('lonAdmEMail');
                   6949:             my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
                   6950:             if ($configuserok eq 'ok') {
                   6951:                 if ($author_ok eq 'ok') {
                   6952:                     my %legacyfile = (
                   6953:  default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab', 
                   6954:  custom  => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab', 
                   6955:                     );
                   6956:                     my %md5chk;
                   6957:                     foreach my $type (keys(%legacyfile)) {
1.60      raeburn  6958:                         ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
                   6959:                         chomp($md5chk{$type});
1.46      raeburn  6960:                     }
                   6961:                     if ($md5chk{'default'} ne $md5chk{'custom'}) {
                   6962:                         foreach my $type (keys(%legacyfile)) {
1.60      raeburn  6963:                             ($scantronurls{$type},my $error) = 
1.46      raeburn  6964:                                 &legacy_scantronformat($r,$dom,$confname,
                   6965:                                                  $type,$legacyfile{$type},
                   6966:                                                  $scantronurls{$type},
                   6967:                                                  $scantronfiles{$type});
1.60      raeburn  6968:                             if ($error ne '') {
                   6969:                                 $error{$type} = $error;
                   6970:                             }
                   6971:                         }
                   6972:                         if (keys(%error) == 0) {
                   6973:                             $is_custom = 1;
                   6974:                             $confhash{'scantron'}{'scantronformat'} = 
                   6975:                                 $scantronurls{'custom'};
                   6976:                             my $putresult = 
                   6977:                                 &Apache::lonnet::put_dom('configuration',
                   6978:                                                          \%confhash,$dom);
                   6979:                             if ($putresult ne 'ok') {
                   6980:                                 $error{'custom'} = 
                   6981:                                     '<span class="LC_error">'.
                   6982:                                     &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
                   6983:                             }
1.46      raeburn  6984:                         }
                   6985:                     } else {
1.60      raeburn  6986:                         ($scantronurls{'default'},my $error) =
1.46      raeburn  6987:                             &legacy_scantronformat($r,$dom,$confname,
                   6988:                                           'default',$legacyfile{'default'},
                   6989:                                           $scantronurls{'default'},
                   6990:                                           $scantronfiles{'default'});
1.60      raeburn  6991:                         if ($error eq '') {
                   6992:                             $confhash{'scantron'}{'scantronformat'} = ''; 
                   6993:                             my $putresult =
                   6994:                                 &Apache::lonnet::put_dom('configuration',
                   6995:                                                          \%confhash,$dom);
                   6996:                             if ($putresult ne 'ok') {
                   6997:                                 $error{'default'} =
                   6998:                                     '<span class="LC_error">'.
                   6999:                                     &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
                   7000:                             }
                   7001:                         } else {
                   7002:                             $error{'default'} = $error;
                   7003:                         }
1.46      raeburn  7004:                     }
                   7005:                 }
                   7006:             }
                   7007:         } else {
1.95      www      7008:             $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46      raeburn  7009:         }
                   7010:     }
                   7011:     if (ref($settings) eq 'HASH') {
                   7012:         if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
                   7013:             my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
                   7014:             if ((!@info) || ($info[0] eq 'no_such_dir')) {
                   7015:                 $scantronurl = '';
                   7016:             } else {
                   7017:                 $scantronurl = $settings->{'scantronformat'};
                   7018:             }
                   7019:             $is_custom = 1;
                   7020:         } else {
                   7021:             $scantronurl = $scantronurls{'default'};
                   7022:         }
                   7023:     } else {
1.60      raeburn  7024:         if ($is_custom) {
                   7025:             $scantronurl = $scantronurls{'custom'};
                   7026:         } else {
                   7027:             $scantronurl = $scantronurls{'default'};
                   7028:         }
1.46      raeburn  7029:     }
                   7030:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   7031:     $datatable .= '<tr'.$css_class.'>';
                   7032:     if (!$is_custom) {
1.65      raeburn  7033:         $datatable .= '<td>'.&mt('Default in use:').'<br />'.
                   7034:                       '<span class="LC_nobreak">';
1.46      raeburn  7035:         if ($scantronurl) {
1.199     raeburn  7036:             $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
                   7037:                                                          undef,undef,undef,undef,'background-color:#ffffff');
1.46      raeburn  7038:         } else {
                   7039:             $datatable = &mt('File unavailable for display');
                   7040:         }
1.65      raeburn  7041:         $datatable .= '</span></td>';
1.60      raeburn  7042:         if (keys(%error) == 0) { 
1.306     raeburn  7043:             $datatable .= '<td style="vertical-align: bottom">';
1.60      raeburn  7044:             if (!$switchserver) {
                   7045:                 $datatable .= &mt('Upload:').'<br />';
                   7046:             }
                   7047:         } else {
                   7048:             my $errorstr;
                   7049:             foreach my $key (sort(keys(%error))) {
                   7050:                 $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
                   7051:             }
                   7052:             $datatable .= '<td>'.$errorstr;
                   7053:         }
1.46      raeburn  7054:     } else {
                   7055:         if (keys(%error) > 0) {
                   7056:             my $errorstr;
                   7057:             foreach my $key (sort(keys(%error))) {
                   7058:                 $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
                   7059:             } 
1.60      raeburn  7060:             $datatable .= '<td>'.$errorstr.'</td><td>&nbsp;';
1.46      raeburn  7061:         } elsif ($scantronurl) {
1.199     raeburn  7062:             my $link =  &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
                   7063:                                                        undef,undef,undef,undef,'background-color:#ffffff');
1.65      raeburn  7064:             $datatable .= '<td><span class="LC_nobreak">'.
1.199     raeburn  7065:                           $link.
                   7066:                           '<label><input type="checkbox" name="scantronformat_del"'.
                   7067:                           ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65      raeburn  7068:                           '<td><span class="LC_nobreak">&nbsp;'.
                   7069:                           &mt('Replace:').'</span><br />';
1.46      raeburn  7070:         }
                   7071:     }
                   7072:     if (keys(%error) == 0) {
                   7073:         if ($switchserver) {
                   7074:             $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   7075:         } else {
1.65      raeburn  7076:             $datatable .='<span class="LC_nobreak">&nbsp;'.
                   7077:                          '<input type="file" name="scantronformat" /></span>';
1.46      raeburn  7078:         }
                   7079:     }
                   7080:     $datatable .= '</td></tr>';
                   7081:     $$rowtotal ++;
                   7082:     return $datatable;
                   7083: }
                   7084: 
                   7085: sub legacy_scantronformat {
                   7086:     my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
                   7087:     my ($url,$error);
                   7088:     my @statinfo = &Apache::lonnet::stat_file($newurl);
                   7089:     if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
                   7090:         (my $result,$url) =
                   7091:             &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
                   7092:                          '','',$newfile);
                   7093:         if ($result ne 'ok') {
1.130     raeburn  7094:             $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46      raeburn  7095:         }
                   7096:     }
                   7097:     return ($url,$error);
                   7098: }
1.43      raeburn  7099: 
1.49      raeburn  7100: sub print_coursecategories {
1.57      raeburn  7101:     my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
                   7102:     my $datatable;
                   7103:     if ($position eq 'top') {
1.238     raeburn  7104:         my (%checked);
                   7105:         my @catitems = ('unauth','auth');
                   7106:         my @cattypes = ('std','domonly','codesrch','none');
                   7107:         $checked{'unauth'} = 'std';
                   7108:         $checked{'auth'} = 'std';
                   7109:         if (ref($settings) eq 'HASH') {
                   7110:             foreach my $type (@cattypes) {
                   7111:                 if ($type eq $settings->{'unauth'}) {
                   7112:                     $checked{'unauth'} = $type;
                   7113:                 }
                   7114:                 if ($type eq $settings->{'auth'}) {
                   7115:                     $checked{'auth'} = $type;
                   7116:                 }
                   7117:             }
                   7118:         }
                   7119:         my %lt = &Apache::lonlocal::texthash (
                   7120:                                                unauth   => 'Catalog type for unauthenticated users',
                   7121:                                                auth     => 'Catalog type for authenticated users',
                   7122:                                                none     => 'No catalog',
                   7123:                                                std      => 'Standard catalog',
                   7124:                                                domonly  => 'Domain-only catalog',
                   7125:                                                codesrch => "Code search form",
                   7126:                                              );
                   7127:        my $itemcount = 0;
                   7128:        foreach my $item (@catitems) {
                   7129:            my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
                   7130:            $datatable .= '<tr '.$css_class.'>'.
                   7131:                          '<td>'.$lt{$item}.'</td>'.
                   7132:                          '<td class="LC_right_item"><span class="LC_nobreak">';
                   7133:            foreach my $type (@cattypes) {
                   7134:                my $ischecked;
                   7135:                if ($checked{$item} eq $type) {
                   7136:                    $ischecked=' checked="checked"';
                   7137:                }
                   7138:                $datatable .= '<label>'.
                   7139:                              '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
                   7140:                              ' />'.$lt{$type}.'</label>&nbsp;';
                   7141:            }
                   7142:            $datatable .= '</td></tr>';
                   7143:            $itemcount ++;
                   7144:         }
                   7145:         $$rowtotal += $itemcount;
                   7146:     } elsif ($position eq 'middle') {
1.57      raeburn  7147:         my $toggle_cats_crs = ' ';
                   7148:         my $toggle_cats_dom = ' checked="checked" ';
                   7149:         my $can_cat_crs = ' ';
                   7150:         my $can_cat_dom = ' checked="checked" ';
1.120     raeburn  7151:         my $toggle_catscomm_comm = ' ';
                   7152:         my $toggle_catscomm_dom = ' checked="checked" ';
                   7153:         my $can_catcomm_comm = ' ';
                   7154:         my $can_catcomm_dom = ' checked="checked" ';
1.272     raeburn  7155:         my $toggle_catsplace_place = ' ';
                   7156:         my $toggle_catsplace_dom = ' checked="checked" ';
                   7157:         my $can_catplace_place = ' ';
                   7158:         my $can_catplace_dom = ' checked="checked" ';
1.120     raeburn  7159: 
1.57      raeburn  7160:         if (ref($settings) eq 'HASH') {
                   7161:             if ($settings->{'togglecats'} eq 'crs') {
                   7162:                 $toggle_cats_crs = $toggle_cats_dom;
                   7163:                 $toggle_cats_dom = ' ';
                   7164:             }
                   7165:             if ($settings->{'categorize'} eq 'crs') {
                   7166:                 $can_cat_crs = $can_cat_dom;
                   7167:                 $can_cat_dom = ' ';
                   7168:             }
1.120     raeburn  7169:             if ($settings->{'togglecatscomm'} eq 'comm') {
                   7170:                 $toggle_catscomm_comm = $toggle_catscomm_dom;
                   7171:                 $toggle_catscomm_dom = ' ';
                   7172:             }
                   7173:             if ($settings->{'categorizecomm'} eq 'comm') {
                   7174:                 $can_catcomm_comm = $can_catcomm_dom;
                   7175:                 $can_catcomm_dom = ' ';
                   7176:             }
1.272     raeburn  7177:             if ($settings->{'togglecatsplace'} eq 'place') {
                   7178:                 $toggle_catsplace_place = $toggle_catsplace_dom;
                   7179:                 $toggle_catsplace_dom = ' ';
                   7180:             }
                   7181:             if ($settings->{'categorizeplace'} eq 'place') {
                   7182:                 $can_catplace_place = $can_catplace_dom;
                   7183:                 $can_catplace_dom = ' ';
                   7184:             }
1.57      raeburn  7185:         }
                   7186:         my %title = &Apache::lonlocal::texthash (
1.272     raeburn  7187:                      togglecats      => 'Show/Hide a course in catalog',
                   7188:                      togglecatscomm  => 'Show/Hide a community in catalog',
                   7189:                      togglecatsplace => 'Show/Hide a placement test in catalog',
                   7190:                      categorize      => 'Assign a category to a course',
                   7191:                      categorizecomm  => 'Assign a category to a community',
                   7192:                      categorizeplace => 'Assign a category to a placement test',
1.57      raeburn  7193:                     );
                   7194:         my %level = &Apache::lonlocal::texthash (
1.272     raeburn  7195:                      dom   => 'Set in Domain',
                   7196:                      crs   => 'Set in Course',
                   7197:                      comm  => 'Set in Community',
                   7198:                      place => 'Set in Placement Test',
1.57      raeburn  7199:                     );
                   7200:         $datatable = '<tr class="LC_odd_row">'.
                   7201:                   '<td>'.$title{'togglecats'}.'</td>'.
                   7202:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   7203:                   '<input type="radio" name="togglecats"'.
                   7204:                   $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   7205:                   '<label><input type="radio" name="togglecats"'.
                   7206:                   $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
                   7207:                   '</tr><tr>'.
                   7208:                   '<td>'.$title{'categorize'}.'</td>'.
                   7209:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
                   7210:                   '<label><input type="radio" name="categorize"'.
                   7211:                   $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   7212:                   '<label><input type="radio" name="categorize"'.
                   7213:                   $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120     raeburn  7214:                   '</tr><tr class="LC_odd_row">'.
                   7215:                   '<td>'.$title{'togglecatscomm'}.'</td>'.
                   7216:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   7217:                   '<input type="radio" name="togglecatscomm"'.
                   7218:                   $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   7219:                   '<label><input type="radio" name="togglecatscomm"'.
                   7220:                   $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
                   7221:                   '</tr><tr>'.
                   7222:                   '<td>'.$title{'categorizecomm'}.'</td>'.
                   7223:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
                   7224:                   '<label><input type="radio" name="categorizecomm"'.
                   7225:                   $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   7226:                   '<label><input type="radio" name="categorizecomm"'.
                   7227:                   $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.272     raeburn  7228:                   '</tr><tr>'.
                   7229:                   '<td>'.$title{'togglecatsplace'}.'</td>'.
                   7230:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   7231:                   '<input type="radio" name="togglecatsplace"'.
                   7232:                   $toggle_catsplace_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   7233:                   '<label><input type="radio" name="togglecatscomm"'.
                   7234:                   $toggle_catsplace_place.' value="comm" />'.$level{'place'}.'</label></span></td>'.
                   7235:                   '</tr><tr>'.
                   7236:                   '<td>'.$title{'categorizeplace'}.'</td>'.
                   7237:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
                   7238:                   '<label><input type="radio" name="categorizeplace"'.
                   7239:                   $can_catplace_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   7240:                   '<label><input type="radio" name="categorizeplace"'.
                   7241:                   $can_catplace_place.'value="place" />'.$level{'place'}.'</label></span></td>'.
1.57      raeburn  7242:                   '</tr>';
1.272     raeburn  7243:         $$rowtotal += 6;
1.57      raeburn  7244:     } else {
                   7245:         my $css_class;
                   7246:         my $itemcount = 1;
                   7247:         my $cathash; 
                   7248:         if (ref($settings) eq 'HASH') {
                   7249:             $cathash = $settings->{'cats'};
                   7250:         }
                   7251:         if (ref($cathash) eq 'HASH') {
                   7252:             my (@cats,@trails,%allitems,%idx,@jsarray);
                   7253:             &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
                   7254:                                                    \%allitems,\%idx,\@jsarray);
                   7255:             my $maxdepth = scalar(@cats);
                   7256:             my $colattrib = '';
                   7257:             if ($maxdepth > 2) {
                   7258:                 $colattrib = ' colspan="2" ';
                   7259:             }
                   7260:             my @path;
                   7261:             if (@cats > 0) {
                   7262:                 if (ref($cats[0]) eq 'ARRAY') {
                   7263:                     my $numtop = @{$cats[0]};
                   7264:                     my $maxnum = $numtop;
1.120     raeburn  7265:                     my %default_names = (
                   7266:                           instcode    => &mt('Official courses'),
                   7267:                           communities => &mt('Communities'),
1.272     raeburn  7268:                           placement   => &mt('Placement Tests'),
1.120     raeburn  7269:                     );
                   7270: 
                   7271:                     if ((!grep(/^instcode$/,@{$cats[0]})) || 
                   7272:                         ($cathash->{'instcode::0'} eq '') ||
                   7273:                         (!grep(/^communities$/,@{$cats[0]})) || 
1.272     raeburn  7274:                         ($cathash->{'communities::0'} eq '') ||
                   7275:                         (!grep(/^placement$/,@{$cats[0]})) ||
                   7276:                         ($cathash->{'placement::0'} eq '')) {
1.57      raeburn  7277:                         $maxnum ++;
                   7278:                     }
                   7279:                     my $lastidx;
                   7280:                     for (my $i=0; $i<$numtop; $i++) {
                   7281:                         my $parent = $cats[0][$i];
                   7282:                         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   7283:                         my $item = &escape($parent).'::0';
                   7284:                         my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
                   7285:                         $lastidx = $idx{$item};
                   7286:                         $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
                   7287:                                       .'<select name="'.$item.'"'.$chgstr.'>';
                   7288:                         for (my $k=0; $k<=$maxnum; $k++) {
                   7289:                             my $vpos = $k+1;
                   7290:                             my $selstr;
                   7291:                             if ($k == $i) {
                   7292:                                 $selstr = ' selected="selected" ';
                   7293:                             }
                   7294:                             $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   7295:                         }
1.214     raeburn  7296:                         $datatable .= '</select></span></td><td>';
1.272     raeburn  7297:                         if ($parent eq 'instcode' || $parent eq 'communities' || $parent eq 'placement') {
1.120     raeburn  7298:                             $datatable .=  '<span class="LC_nobreak">'
                   7299:                                            .$default_names{$parent}.'</span>';
                   7300:                             if ($parent eq 'instcode') {
                   7301:                                 $datatable .= '<br /><span class="LC_nobreak">('
                   7302:                                               .&mt('with institutional codes')
                   7303:                                               .')</span></td><td'.$colattrib.'>';
                   7304:                             } else {
                   7305:                                 $datatable .= '<table><tr><td>';
                   7306:                             }
                   7307:                             $datatable .= '<span class="LC_nobreak">'
                   7308:                                           .'<label><input type="radio" name="'
                   7309:                                           .$parent.'" value="1" checked="checked" />'
                   7310:                                           .&mt('Display').'</label>';
                   7311:                             if ($parent eq 'instcode') {
                   7312:                                 $datatable .= '&nbsp;';
                   7313:                             } else {
                   7314:                                 $datatable .= '</span></td></tr><tr><td>'
                   7315:                                               .'<span class="LC_nobreak">';
                   7316:                             }
                   7317:                             $datatable .= '<label><input type="radio" name="'
                   7318:                                           .$parent.'" value="0" />'
                   7319:                                           .&mt('Do not display').'</label></span>';
1.272     raeburn  7320:                             if (($parent eq 'communities') || ($parent eq 'placement')) {
1.120     raeburn  7321:                                 $datatable .= '</td></tr></table>';
                   7322:                             }
                   7323:                             $datatable .= '</td>';
1.57      raeburn  7324:                         } else {
                   7325:                             $datatable .= $parent
1.214     raeburn  7326:                                           .'&nbsp;<span class="LC_nobreak"><label>'
                   7327:                                           .'<input type="checkbox" name="deletecategory" '
1.57      raeburn  7328:                                           .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
                   7329:                         }
                   7330:                         my $depth = 1;
                   7331:                         push(@path,$parent);
                   7332:                         $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
                   7333:                         pop(@path);
                   7334:                         $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
                   7335:                         $itemcount ++;
                   7336:                     }
1.48      raeburn  7337:                     $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57      raeburn  7338:                     my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
                   7339:                     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48      raeburn  7340:                     for (my $k=0; $k<=$maxnum; $k++) {
                   7341:                         my $vpos = $k+1;
                   7342:                         my $selstr;
1.57      raeburn  7343:                         if ($k == $numtop) {
1.48      raeburn  7344:                             $selstr = ' selected="selected" ';
                   7345:                         }
                   7346:                         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   7347:                     }
1.59      bisitz   7348:                     $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').'&nbsp;'
1.57      raeburn  7349:                                   .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
                   7350:                                   .'</tr>'."\n";
1.48      raeburn  7351:                     $itemcount ++;
1.272     raeburn  7352:                     foreach my $default ('instcode','communities','placement') {
1.120     raeburn  7353:                         if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
                   7354:                             $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   7355:                             my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
                   7356:                             $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
                   7357:                                           '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
                   7358:                             for (my $k=0; $k<=$maxnum; $k++) {
                   7359:                                 my $vpos = $k+1;
                   7360:                                 my $selstr;
                   7361:                                 if ($k == $maxnum) {
                   7362:                                     $selstr = ' selected="selected" ';
                   7363:                                 }
                   7364:                                 $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57      raeburn  7365:                             }
1.120     raeburn  7366:                             $datatable .= '</select></span></td>'.
                   7367:                                           '<td><span class="LC_nobreak">'.
                   7368:                                           $default_names{$default}.'</span>';
                   7369:                             if ($default eq 'instcode') {
                   7370:                                 $datatable .= '<br /><span class="LC_nobreak">(' 
                   7371:                                               .&mt('with institutional codes').')</span>';
                   7372:                             }
                   7373:                             $datatable .= '</td>'
                   7374:                                           .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
                   7375:                                           .&mt('Display').'</label>&nbsp;'
                   7376:                                           .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
                   7377:                                           .&mt('Do not display').'</label></span></td></tr>';
1.48      raeburn  7378:                         }
                   7379:                     }
                   7380:                 }
1.57      raeburn  7381:             } else {
                   7382:                 $datatable .= &initialize_categories($itemcount);
1.48      raeburn  7383:             }
                   7384:         } else {
1.238     raeburn  7385:             $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td>'
1.57      raeburn  7386:                           .&initialize_categories($itemcount);
1.48      raeburn  7387:         }
1.57      raeburn  7388:         $$rowtotal += $itemcount;
1.48      raeburn  7389:     }
                   7390:     return $datatable;
                   7391: }
                   7392: 
1.69      raeburn  7393: sub print_serverstatuses {
                   7394:     my ($dom,$settings,$rowtotal) = @_;
                   7395:     my $datatable;
                   7396:     my @pages = &serverstatus_pages();
                   7397:     my (%namedaccess,%machineaccess);
                   7398:     foreach my $type (@pages) {
                   7399:         $namedaccess{$type} = '';
                   7400:         $machineaccess{$type}= '';
                   7401:     }
                   7402:     if (ref($settings) eq 'HASH') {
                   7403:         foreach my $type (@pages) {
                   7404:             if (exists($settings->{$type})) {
                   7405:                 if (ref($settings->{$type}) eq 'HASH') {
                   7406:                     foreach my $key (keys(%{$settings->{$type}})) {
                   7407:                         if ($key eq 'namedusers') {
                   7408:                             $namedaccess{$type} = $settings->{$type}->{$key};
                   7409:                         } elsif ($key eq 'machines') {
                   7410:                             $machineaccess{$type} = $settings->{$type}->{$key};
                   7411:                         }
                   7412:                     }
                   7413:                 }
                   7414:             }
                   7415:         }
                   7416:     }
1.81      raeburn  7417:     my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69      raeburn  7418:     my $rownum = 0;
                   7419:     my $css_class;
                   7420:     foreach my $type (@pages) {
                   7421:         $rownum ++;
                   7422:         $css_class = $rownum%2?' class="LC_odd_row"':'';
                   7423:         $datatable .= '<tr'.$css_class.'>'.
                   7424:                       '<td><span class="LC_nobreak">'.
                   7425:                       $titles->{$type}.'</span></td>'.
                   7426:                       '<td class="LC_left_item">'.
                   7427:                       '<input type="text" name="'.$type.'_namedusers" '.
                   7428:                       'value="'.$namedaccess{$type}.'" size="30" /></td>'.
                   7429:                       '<td class="LC_right_item">'.
                   7430:                       '<span class="LC_nobreak">'.
                   7431:                       '<input type="text" name="'.$type.'_machines" '.
                   7432:                       'value="'.$machineaccess{$type}.'" size="10" />'.
                   7433:                       '</td></tr>'."\n";
                   7434:     }
                   7435:     $$rowtotal += $rownum;
                   7436:     return $datatable;
                   7437: }
                   7438: 
                   7439: sub serverstatus_pages {
                   7440:     return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.275     raeburn  7441:             'checksums','clusterstatus','certstatus','metadata_keywords',
                   7442:             'metadata_harvest','takeoffline','takeonline','showenv','toggledebug',
                   7443:             'ping','domconf','uniquecodes','diskusage','coursecatalog');
1.69      raeburn  7444: }
                   7445: 
1.236     raeburn  7446: sub defaults_javascript {
                   7447:     my ($settings) = @_;
1.294     raeburn  7448:     my $intauthcheck = &mt('Warning: disallowing login for an authenticated user if the stored cost is less than the default will require a password reset by/for the user.');
                   7449:     my $intauthcost = &mt('Warning: bcrypt encryption cost for internal authentication must be an integer.');
                   7450:     &js_escape(\$intauthcheck);
                   7451:     &js_escape(\$intauthcost);
                   7452:     my $intauthjs = <<"ENDSCRIPT";
                   7453: 
                   7454: function warnIntAuth(field) {
                   7455:     if (field.name == 'intauth_check') {
                   7456:         if (field.value == '2') {
                   7457:             alert('$intauthcheck');
                   7458:         }
                   7459:     }
                   7460:     if (field.name == 'intauth_cost') {
                   7461:         field.value.replace(/\s/g,'');
                   7462:         if (field.value != '') {
                   7463:             var regexdigit=/^\\d+\$/;
                   7464:             if (!regexdigit.test(field.value)) {
                   7465:                 alert('$intauthcost');
                   7466:             }
                   7467:         }
                   7468:     }
                   7469:     return;
                   7470: }
                   7471: 
                   7472: ENDSCRIPT
                   7473: 
                   7474:     if (ref($settings) ne 'HASH') {
                   7475:         return &Apache::lonhtmlcommon::scripttag($intauthjs);
                   7476:     }
1.236     raeburn  7477:     if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
                   7478:         my $maxnum = scalar(@{$settings->{'inststatusorder'}});
                   7479:         if ($maxnum eq '') {
                   7480:             $maxnum = 0;
                   7481:         }
                   7482:         $maxnum ++;
1.249     raeburn  7483:         my $jstext = '    var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';  
1.236     raeburn  7484:         return <<"ENDSCRIPT";
                   7485: <script type="text/javascript">
                   7486: // <![CDATA[
                   7487: function reorderTypes(form,caller) {
                   7488:     var changedVal;
                   7489: $jstext 
                   7490:     var newpos = 'addinststatus_pos';
                   7491:     var current = new Array;
                   7492:     var maxh = $maxnum;
                   7493:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
                   7494:     var oldVal;
                   7495:     if (caller == newpos) {
                   7496:         changedVal = newitemVal;
                   7497:     } else {
                   7498:         var curritem = 'inststatus_pos_'+caller;
                   7499:         changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
                   7500:         current[newitemVal] = newpos;
                   7501:     }
                   7502:     for (var i=0; i<inststatuses.length; i++) {
                   7503:         if (inststatuses[i] != caller) {
                   7504:             var elementName = 'inststatus_pos_'+inststatuses[i];
                   7505:             if (form.elements[elementName]) {
                   7506:                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   7507:                 current[currVal] = elementName;
                   7508:             }
                   7509:         }
                   7510:     }
                   7511:     for (var j=0; j<maxh; j++) {
                   7512:         if (current[j] == undefined) {
                   7513:             oldVal = j;
                   7514:         }
                   7515:     }
                   7516:     if (oldVal < changedVal) {
                   7517:         for (var k=oldVal+1; k<=changedVal ; k++) {
                   7518:            var elementName = current[k];
                   7519:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   7520:         }
                   7521:     } else {
                   7522:         for (var k=changedVal; k<oldVal; k++) {
                   7523:             var elementName = current[k];
                   7524:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   7525:         }
                   7526:     }
                   7527:     return;
                   7528: }
                   7529: 
1.294     raeburn  7530: $intauthjs
                   7531: 
1.236     raeburn  7532: // ]]>
                   7533: </script>
                   7534: 
                   7535: ENDSCRIPT
1.294     raeburn  7536:     } else {
                   7537:         return &Apache::lonhtmlcommon::scripttag($intauthjs);
1.236     raeburn  7538:     }
                   7539: }
                   7540: 
1.49      raeburn  7541: sub coursecategories_javascript {
                   7542:     my ($settings) = @_;
1.57      raeburn  7543:     my ($output,$jstext,$cathash);
1.49      raeburn  7544:     if (ref($settings) eq 'HASH') {
1.57      raeburn  7545:         $cathash = $settings->{'cats'};
                   7546:     }
                   7547:     if (ref($cathash) eq 'HASH') {
1.49      raeburn  7548:         my (@cats,@jsarray,%idx);
1.57      raeburn  7549:         &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49      raeburn  7550:         if (@jsarray > 0) {
                   7551:             $jstext = '    var categories = Array('.scalar(@jsarray).');'."\n";
                   7552:             for (my $i=0; $i<@jsarray; $i++) {
                   7553:                 if (ref($jsarray[$i]) eq 'ARRAY') {
                   7554:                     my $catstr = join('","',@{$jsarray[$i]});
                   7555:                     $jstext .= '    categories['.$i.'] = Array("'.$catstr.'");'."\n";
                   7556:                 }
                   7557:             }
                   7558:         }
                   7559:     } else {
                   7560:         $jstext  = '    var categories = Array(1);'."\n".
                   7561:                    '    categories[0] = Array("instcode_pos");'."\n"; 
                   7562:     }
1.237     bisitz   7563:     my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
                   7564:     my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.272     raeburn  7565:     my $placement_reserved = &mt('The name: [_1] is a reserved category.','"placement"');
1.265     damieng  7566:     my $choose_again = "\n".&mt('Please use a different name for the new top level category.'); 
                   7567:     &js_escape(\$instcode_reserved);
                   7568:     &js_escape(\$communities_reserved);
1.272     raeburn  7569:     &js_escape(\$placement_reserved);
1.265     damieng  7570:     &js_escape(\$choose_again);
1.49      raeburn  7571:     $output = <<"ENDSCRIPT";
                   7572: <script type="text/javascript">
1.109     raeburn  7573: // <![CDATA[
1.49      raeburn  7574: function reorderCats(form,parent,item,idx) {
                   7575:     var changedVal;
                   7576: $jstext
                   7577:     var newpos = 'addcategory_pos';
                   7578:     if (parent == '') {
                   7579:         var has_instcode = 0;
                   7580:         var maxtop = categories[idx].length;
                   7581:         for (var j=0; j<maxtop; j++) {
                   7582:             if (categories[idx][j] == 'instcode::0') {
                   7583:                 has_instcode == 1;
                   7584:             }
                   7585:         }
                   7586:         if (has_instcode == 0) {
                   7587:             categories[idx][maxtop] = 'instcode_pos';
                   7588:         }
                   7589:     } else {
                   7590:         newpos += '_'+parent;
                   7591:     }
                   7592:     var maxh = 1 + categories[idx].length;
                   7593:     var current = new Array;
                   7594:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
                   7595:     if (item == newpos) {
                   7596:         changedVal = newitemVal;
                   7597:     } else {
                   7598:         changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
                   7599:         current[newitemVal] = newpos;
                   7600:     }
                   7601:     for (var i=0; i<categories[idx].length; i++) {
                   7602:         var elementName = categories[idx][i];
                   7603:         if (elementName != item) {
                   7604:             if (form.elements[elementName]) {
                   7605:                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   7606:                 current[currVal] = elementName;
                   7607:             }
                   7608:         }
                   7609:     }
                   7610:     var oldVal;
                   7611:     for (var j=0; j<maxh; j++) {
                   7612:         if (current[j] == undefined) {
                   7613:             oldVal = j;
                   7614:         }
                   7615:     }
                   7616:     if (oldVal < changedVal) {
                   7617:         for (var k=oldVal+1; k<=changedVal ; k++) {
                   7618:            var elementName = current[k];
                   7619:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   7620:         }
                   7621:     } else {
                   7622:         for (var k=changedVal; k<oldVal; k++) {
                   7623:             var elementName = current[k];
                   7624:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   7625:         }
                   7626:     }
                   7627:     return;
                   7628: }
1.120     raeburn  7629: 
                   7630: function categoryCheck(form) {
                   7631:     if (form.elements['addcategory_name'].value == 'instcode') {
                   7632:         alert('$instcode_reserved\\n$choose_again');
                   7633:         return false;
                   7634:     }
                   7635:     if (form.elements['addcategory_name'].value == 'communities') {
                   7636:         alert('$communities_reserved\\n$choose_again');
                   7637:         return false;
                   7638:     }
1.272     raeburn  7639:     if (form.elements['addcategory_name'].value == 'placement') {
                   7640:         alert('$placement_reserved\\n$choose_again');
                   7641:         return false;
                   7642:     }
1.120     raeburn  7643:     return true;
                   7644: }
                   7645: 
1.109     raeburn  7646: // ]]>
1.49      raeburn  7647: </script>
                   7648: 
                   7649: ENDSCRIPT
                   7650:     return $output;
                   7651: }
                   7652: 
1.48      raeburn  7653: sub initialize_categories {
                   7654:     my ($itemcount) = @_;
1.120     raeburn  7655:     my ($datatable,$css_class,$chgstr);
                   7656:     my %default_names = (
                   7657:                       instcode    => 'Official courses (with institutional codes)',
                   7658:                       communities => 'Communities',
1.272     raeburn  7659:                       placement   => 'Placement Tests',
1.120     raeburn  7660:                         );
                   7661:     my $select0 = ' selected="selected"';
                   7662:     my $select1 = '';
1.272     raeburn  7663:     foreach my $default ('instcode','communities','placement') {
1.120     raeburn  7664:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   7665:         $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
1.272     raeburn  7666:         if (($default eq 'communities') || ($default eq 'placement')) {
1.120     raeburn  7667:             $select1 = $select0;
                   7668:             $select0 = '';
                   7669:         }
                   7670:         $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
                   7671:                      .'<select name="'.$default.'_pos">'
                   7672:                      .'<option value="0"'.$select0.'>1</option>'
                   7673:                      .'<option value="1"'.$select1.'>2</option>'
                   7674:                      .'<option value="2">3</option></select>&nbsp;'
                   7675:                      .$default_names{$default}
                   7676:                      .'</span></td><td><span class="LC_nobreak">'
                   7677:                      .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
                   7678:                      .&mt('Display').'</label>&nbsp;<label>'
                   7679:                      .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48      raeburn  7680:                  .'</label></span></td></tr>';
1.120     raeburn  7681:         $itemcount ++;
                   7682:     }
1.48      raeburn  7683:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49      raeburn  7684:     $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48      raeburn  7685:     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120     raeburn  7686:                   .'<select name="addcategory_pos"'.$chgstr.'>'
                   7687:                   .'<option value="0">1</option>'
                   7688:                   .'<option value="1">2</option>'
                   7689:                   .'<option value="2" selected="selected">3</option></select>&nbsp;'
1.48      raeburn  7690:                   .&mt('Add category').'</td><td>'.&mt('Name:')
                   7691:                   .'&nbsp;<input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
                   7692:     return $datatable;
                   7693: }
                   7694: 
                   7695: sub build_category_rows {
1.49      raeburn  7696:     my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
                   7697:     my ($text,$name,$item,$chgstr);
1.48      raeburn  7698:     if (ref($cats) eq 'ARRAY') {
                   7699:         my $maxdepth = scalar(@{$cats});
                   7700:         if (ref($cats->[$depth]) eq 'HASH') {
                   7701:             if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
                   7702:                 my $numchildren = @{$cats->[$depth]{$parent}};
                   7703:                 my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204     raeburn  7704:                 $text .= '<td><table class="LC_data_table">';
1.49      raeburn  7705:                 my ($idxnum,$parent_name,$parent_item);
                   7706:                 my $higher = $depth - 1;
                   7707:                 if ($higher == 0) {
                   7708:                     $parent_name = &escape($parent).'::'.$higher;
                   7709:                 } else {
                   7710:                     if (ref($path) eq 'ARRAY') {
                   7711:                         $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
                   7712:                     }
                   7713:                 }
                   7714:                 $parent_item = 'addcategory_pos_'.$parent_name;
1.48      raeburn  7715:                 for (my $j=0; $j<=$numchildren; $j++) {
1.49      raeburn  7716:                     if ($j < $numchildren) {
1.48      raeburn  7717:                         $name = $cats->[$depth]{$parent}[$j];
                   7718:                         $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49      raeburn  7719:                         $idxnum = $idx->{$item};
                   7720:                     } else {
                   7721:                         $name = $parent_name;
                   7722:                         $item = $parent_item;
1.48      raeburn  7723:                     }
1.49      raeburn  7724:                     $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
                   7725:                     $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48      raeburn  7726:                     for (my $i=0; $i<=$numchildren; $i++) {
                   7727:                         my $vpos = $i+1;
                   7728:                         my $selstr;
                   7729:                         if ($j == $i) {
                   7730:                             $selstr = ' selected="selected" ';
                   7731:                         }
                   7732:                         $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
                   7733:                     }
                   7734:                     $text .= '</select>&nbsp;';
                   7735:                     if ($j < $numchildren) {
                   7736:                         my $deeper = $depth+1;
                   7737:                         $text .= $name.'&nbsp;'
                   7738:                                  .'<label><input type="checkbox" name="deletecategory" value="'
                   7739:                                  .$item.'" />'.&mt('Delete').'</label></span></td><td>';
                   7740:                         if(ref($path) eq 'ARRAY') {
                   7741:                             push(@{$path},$name);
1.49      raeburn  7742:                             $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48      raeburn  7743:                             pop(@{$path});
                   7744:                         }
                   7745:                     } else {
1.59      bisitz   7746:                         $text .= &mt('Add subcategory:').'&nbsp;</span><input type="textbox" size="20" name="addcategory_name_';
1.48      raeburn  7747:                         if ($j == $numchildren) {
                   7748:                             $text .= $name;
                   7749:                         } else {
                   7750:                             $text .= $item;
                   7751:                         }
                   7752:                         $text .= '" value="" />';
                   7753:                     }
                   7754:                     $text .= '</td></tr>';
                   7755:                 }
                   7756:                 $text .= '</table></td>';
                   7757:             } else {
                   7758:                 my $higher = $depth-1;
                   7759:                 if ($higher == 0) {
                   7760:                     $name = &escape($parent).'::'.$higher;
                   7761:                 } else {
                   7762:                     if (ref($path) eq 'ARRAY') {
                   7763:                         $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
                   7764:                     }
                   7765:                 }
                   7766:                 my $colspan;
                   7767:                 if ($parent ne 'instcode') {
                   7768:                     $colspan = $maxdepth - $depth - 1;
                   7769:                     $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
                   7770:                 }
                   7771:             }
                   7772:         }
                   7773:     }
                   7774:     return $text;
                   7775: }
                   7776: 
1.33      raeburn  7777: sub modifiable_userdata_row {
1.305     raeburn  7778:     my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,
                   7779:         $rowid,$customcss,$rowstyle) = @_;
1.228     raeburn  7780:     my ($role,$rolename,$statustype);
                   7781:     $role = $item;
1.224     raeburn  7782:     if ($context eq 'cancreate') {
1.305     raeburn  7783:         if ($item =~ /^(emailusername)_(.+)$/) {
                   7784:             $role = $1;
                   7785:             $statustype = $2;
1.228     raeburn  7786:             if (ref($usertypes) eq 'HASH') {
                   7787:                 if ($usertypes->{$statustype}) {
                   7788:                     $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
                   7789:                 } else {
                   7790:                     $rolename = &mt('Data provided by user');
                   7791:                 }
                   7792:             }
1.224     raeburn  7793:         }
                   7794:     } elsif ($context eq 'selfcreate') {
1.63      raeburn  7795:         if (ref($usertypes) eq 'HASH') {
                   7796:             $rolename = $usertypes->{$role};
                   7797:         } else {
                   7798:             $rolename = $role;
                   7799:         }
1.33      raeburn  7800:     } else {
1.63      raeburn  7801:         if ($role eq 'cr') {
                   7802:             $rolename = &mt('Custom role');
                   7803:         } else {
                   7804:             $rolename = &Apache::lonnet::plaintext($role);
                   7805:         }
1.33      raeburn  7806:     }
1.224     raeburn  7807:     my (@fields,%fieldtitles);
                   7808:     if (ref($fieldsref) eq 'ARRAY') {
                   7809:         @fields = @{$fieldsref};
                   7810:     } else {
                   7811:         @fields = ('lastname','firstname','middlename','generation',
                   7812:                    'permanentemail','id');
                   7813:     }
                   7814:     if ((ref($titlesref) eq 'HASH')) {
                   7815:         %fieldtitles = %{$titlesref};
                   7816:     } else {
                   7817:         %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
                   7818:     }
1.33      raeburn  7819:     my $output;
1.305     raeburn  7820:     my $css_class;
                   7821:     if ($rowcount%2) {
                   7822:         $css_class = 'LC_odd_row';
                   7823:     }
                   7824:     if ($customcss) {
                   7825:         $css_class .= " $customcss";
                   7826:     }
                   7827:     $css_class =~ s/^\s+//;
                   7828:     if ($css_class) {
                   7829:         $css_class = ' class="'.$css_class.'"';
                   7830:     }
                   7831:     if ($rowstyle) {
                   7832:         $css_class .= ' style="'.$rowstyle.'"';
                   7833:     }
                   7834:     if ($rowid) {
                   7835:         $rowid = ' id="'.$rowid.'"';
                   7836:     }
                   7837:     $output = '<tr '.$css_class.$rowid.'>'.
1.33      raeburn  7838:               '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
                   7839:               '<td class="LC_left_item" colspan="2"><table>';
                   7840:     my $rem;
                   7841:     my %checks;
                   7842:     if (ref($settings) eq 'HASH') {
                   7843:         if (ref($settings->{$context}) eq 'HASH') {
                   7844:             if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.228     raeburn  7845:                 my $hashref = $settings->{$context}->{$role};
                   7846:                 if ($role eq 'emailusername') {
                   7847:                     if ($statustype) {
                   7848:                         if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
                   7849:                             $hashref = $settings->{$context}->{$role}->{$statustype};
                   7850:                             if (ref($hashref) eq 'HASH') { 
                   7851:                                 foreach my $field (@fields) {
                   7852:                                     if ($hashref->{$field}) {
                   7853:                                         $checks{$field} = $hashref->{$field};
                   7854:                                     }
                   7855:                                 }
                   7856:                             }
                   7857:                         }
                   7858:                     }
                   7859:                 } else {
                   7860:                     if (ref($hashref) eq 'HASH') {
                   7861:                         foreach my $field (@fields) {
                   7862:                             if ($hashref->{$field}) {
                   7863:                                 $checks{$field} = ' checked="checked" ';
                   7864:                             }
                   7865:                         }
1.33      raeburn  7866:                     }
                   7867:                 }
                   7868:             }
                   7869:         }
                   7870:     }
1.305     raeburn  7871:  
                   7872:     my $total = scalar(@fields);
                   7873:     for (my $i=0; $i<$total; $i++) {
                   7874:         $rem = $i%($numinrow);
1.33      raeburn  7875:         if ($rem == 0) {
                   7876:             if ($i > 0) {
                   7877:                 $output .= '</tr>';
                   7878:             }
                   7879:             $output .= '<tr>';
                   7880:         }
                   7881:         my $check = ' ';
1.228     raeburn  7882:         unless ($role eq 'emailusername') {
                   7883:             if (exists($checks{$fields[$i]})) {
                   7884:                 $check = $checks{$fields[$i]}
                   7885:             } else {
                   7886:                 if ($role eq 'st') {
                   7887:                     if (ref($settings) ne 'HASH') {
                   7888:                         $check = ' checked="checked" '; 
                   7889:                     }
1.33      raeburn  7890:                 }
                   7891:             }
                   7892:         }
                   7893:         $output .= '<td class="LC_left_item">'.
1.228     raeburn  7894:                    '<span class="LC_nobreak">';
                   7895:         if ($role eq 'emailusername') {
                   7896:             unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
                   7897:                 $checks{$fields[$i]} = 'omit';
                   7898:             }
                   7899:             foreach my $option ('required','optional','omit') {
                   7900:                 my $checked='';
                   7901:                 if ($checks{$fields[$i]} eq $option) {
                   7902:                     $checked='checked="checked" ';
                   7903:                 }
                   7904:                 $output .= '<label>'.
                   7905:                            '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
                   7906:                            &mt($option).'</label>'.('&nbsp;' x2);
                   7907:             }
                   7908:             $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
                   7909:         } else {
                   7910:             $output .= '<label>'.
                   7911:                        '<input type="checkbox" name="canmodify_'.$role.'" '.
                   7912:                        'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
                   7913:                        '</label>';
                   7914:         }
                   7915:         $output .= '</span></td>';
1.33      raeburn  7916:     }
1.305     raeburn  7917:     $rem = $total%$numinrow;
                   7918:     my $colsleft;
                   7919:     if ($rem) {
                   7920:         $colsleft = $numinrow - $rem;
                   7921:     }
                   7922:     if ($colsleft > 1) {
1.33      raeburn  7923:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   7924:                    '&nbsp;</td>';
                   7925:     } elsif ($colsleft == 1) {
                   7926:         $output .= '<td class="LC_left_item">&nbsp;</td>';
                   7927:     }
                   7928:     $output .= '</tr></table></td></tr>';
                   7929:     return $output;
                   7930: }
1.28      raeburn  7931: 
1.93      raeburn  7932: sub insttypes_row {
1.305     raeburn  7933:     my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
                   7934:         $customcss,$rowstyle) = @_;
1.93      raeburn  7935:     my %lt = &Apache::lonlocal::texthash (
                   7936:                       cansearch => 'Users allowed to search',
                   7937:                       statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131     raeburn  7938:                       lockablenames => 'User preference to lock name',
1.305     raeburn  7939:                       selfassign    => 'Self-reportable affiliations',
1.315     raeburn  7940:                       overrides     => "Override domain's helpdesk settings based on requester's affiliation",
1.93      raeburn  7941:              );
                   7942:     my $showdom;
                   7943:     if ($context eq 'cansearch') {
                   7944:         $showdom = ' ('.$dom.')';
                   7945:     }
1.165     raeburn  7946:     my $class = 'LC_left_item';
                   7947:     if ($context eq 'statustocreate') {
                   7948:         $class = 'LC_right_item';
                   7949:     }
1.305     raeburn  7950:     my $css_class;
                   7951:     if ($$rowtotal%2) {
                   7952:         $css_class = 'LC_odd_row';
                   7953:     }
                   7954:     if ($customcss) {
                   7955:         $css_class .= ' '.$customcss;
                   7956:     }
                   7957:     $css_class =~ s/^\s+//;
                   7958:     if ($css_class) {
                   7959:         $css_class = ' class="'.$css_class.'"';
                   7960:     }
                   7961:     if ($rowstyle) {
                   7962:         $css_class .= ' style="'.$rowstyle.'"';
                   7963:     }
                   7964:     if ($onclick) {
                   7965:         $onclick = 'onclick="'.$onclick.'" ';
1.224     raeburn  7966:     }
                   7967:     my $output = '<tr'.$css_class.'>'.
                   7968:                  '<td>'.$lt{$context}.$showdom.
                   7969:                  '</td><td class="'.$class.'" colspan="2"><table>';
1.26      raeburn  7970:     my $rem;
                   7971:     if (ref($types) eq 'ARRAY') {
                   7972:         for (my $i=0; $i<@{$types}; $i++) {
                   7973:             if (defined($usertypes->{$types->[$i]})) {
                   7974:                 my $rem = $i%($numinrow);
                   7975:                 if ($rem == 0) {
                   7976:                     if ($i > 0) {
                   7977:                         $output .= '</tr>';
                   7978:                     }
                   7979:                     $output .= '<tr>';
1.23      raeburn  7980:                 }
1.26      raeburn  7981:                 my $check = ' ';
1.99      raeburn  7982:                 if (ref($settings) eq 'HASH') {
                   7983:                     if (ref($settings->{$context}) eq 'ARRAY') {
                   7984:                         if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
                   7985:                             $check = ' checked="checked" ';
                   7986:                         }
1.315     raeburn  7987:                     } elsif (ref($settings->{$context}) eq 'HASH') {
                   7988:                         if (ref($settings->{$context}->{$types->[$i]}) eq 'HASH') {
                   7989:                             $check = ' checked="checked" ';
                   7990:                         }
1.99      raeburn  7991:                     } elsif ($context eq 'statustocreate') {
1.26      raeburn  7992:                         $check = ' checked="checked" ';
                   7993:                     }
1.23      raeburn  7994:                 }
1.26      raeburn  7995:                 $output .= '<td class="LC_left_item">'.
                   7996:                            '<span class="LC_nobreak"><label>'.
1.93      raeburn  7997:                            '<input type="checkbox" name="'.$context.'" '.
1.305     raeburn  7998:                            'value="'.$types->[$i].'"'.$check.$onclick.' />'.
1.26      raeburn  7999:                            $usertypes->{$types->[$i]}.'</label></span></td>';
1.23      raeburn  8000:             }
                   8001:         }
1.26      raeburn  8002:         $rem = @{$types}%($numinrow);
1.23      raeburn  8003:     }
                   8004:     my $colsleft = $numinrow - $rem;
1.315     raeburn  8005:     if ($context eq 'overrides') {
                   8006:         if ($colsleft > 1) {
                   8007:             $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
                   8008:         } else {
                   8009:             $output .= '<td class="LC_left_item">';
                   8010:         }
                   8011:         $output .= '&nbsp;';  
1.23      raeburn  8012:     } else {
1.315     raeburn  8013:         if (($rem == 0) && (@{$types} > 0)) {
                   8014:             $output .= '<tr>';
                   8015:         }
                   8016:         if ($colsleft > 1) {
                   8017:             $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
                   8018:         } else {
                   8019:             $output .= '<td class="LC_left_item">';
                   8020:         }
                   8021:         my $defcheck = ' ';
                   8022:         if (ref($settings) eq 'HASH') {  
                   8023:             if (ref($settings->{$context}) eq 'ARRAY') {
                   8024:                 if (grep(/^default$/,@{$settings->{$context}})) {
                   8025:                     $defcheck = ' checked="checked" ';
                   8026:                 }
                   8027:             } elsif ($context eq 'statustocreate') {
1.99      raeburn  8028:                 $defcheck = ' checked="checked" ';
                   8029:             }
1.26      raeburn  8030:         }
1.315     raeburn  8031:         $output .= '<span class="LC_nobreak"><label>'.
                   8032:                    '<input type="checkbox" name="'.$context.'" '.
                   8033:                    'value="default"'.$defcheck.$onclick.' />'.
                   8034:                    $othertitle.'</label></span>';
1.23      raeburn  8035:     }
1.315     raeburn  8036:     $output .= '</td></tr></table></td></tr>';
1.25      raeburn  8037:     return $output;
1.23      raeburn  8038: }
                   8039: 
                   8040: sub sorted_searchtitles {
                   8041:     my %searchtitles = &Apache::lonlocal::texthash(
                   8042:                          'uname' => 'username',
                   8043:                          'lastname' => 'last name',
                   8044:                          'lastfirst' => 'last name, first name',
                   8045:                      );
                   8046:     my @titleorder = ('uname','lastname','lastfirst');
                   8047:     return (\%searchtitles,\@titleorder);
                   8048: }
                   8049: 
1.25      raeburn  8050: sub sorted_searchtypes {
                   8051:     my %srchtypes_desc = (
                   8052:                            exact    => 'is exact match',
                   8053:                            contains => 'contains ..',
                   8054:                            begins   => 'begins with ..',
                   8055:                          );
                   8056:     my @srchtypeorder = ('exact','begins','contains');
                   8057:     return (\%srchtypes_desc,\@srchtypeorder);
                   8058: }
                   8059: 
1.3       raeburn  8060: sub usertype_update_row {
                   8061:     my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
                   8062:     my $datatable;
                   8063:     my $numinrow = 4;
                   8064:     foreach my $type (@{$types}) {
                   8065:         if (defined($usertypes->{$type})) {
                   8066:             $$rownums ++;
                   8067:             my $css_class = $$rownums%2?' class="LC_odd_row"':'';
                   8068:             $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
                   8069:                           '</td><td class="LC_left_item"><table>';
                   8070:             for (my $i=0; $i<@{$fields}; $i++) {
                   8071:                 my $rem = $i%($numinrow);
                   8072:                 if ($rem == 0) {
                   8073:                     if ($i > 0) {
                   8074:                         $datatable .= '</tr>';
                   8075:                     }
                   8076:                     $datatable .= '<tr>';
                   8077:                 }
                   8078:                 my $check = ' ';
1.39      raeburn  8079:                 if (ref($settings) eq 'HASH') {
                   8080:                     if (ref($settings->{'fields'}) eq 'HASH') {
                   8081:                         if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
                   8082:                             if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
                   8083:                                 $check = ' checked="checked" ';
                   8084:                             }
1.3       raeburn  8085:                         }
                   8086:                     }
                   8087:                 }
                   8088: 
                   8089:                 if ($i == @{$fields}-1) {
                   8090:                     my $colsleft = $numinrow - $rem;
                   8091:                     if ($colsleft > 1) {
                   8092:                         $datatable .= '<td colspan="'.$colsleft.'">';
                   8093:                     } else {
                   8094:                         $datatable .= '<td>';
                   8095:                     }
                   8096:                 } else {
                   8097:                     $datatable .= '<td>';
                   8098:                 }
1.8       raeburn  8099:                 $datatable .= '<span class="LC_nobreak"><label>'.
                   8100:                               '<input type="checkbox" name="updateable_'.$type.
                   8101:                               '_'.$fields->[$i].'" value="1"'.$check.'/>'.
                   8102:                               $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3       raeburn  8103:             }
                   8104:             $datatable .= '</tr></table></td></tr>';
                   8105:         }
                   8106:     }
                   8107:     return $datatable;
1.1       raeburn  8108: }
                   8109: 
                   8110: sub modify_login {
1.205     raeburn  8111:     my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168     raeburn  8112:     my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
                   8113:         %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
                   8114:     %title = ( coursecatalog => 'Display course catalog',
                   8115:                adminmail => 'Display administrator E-mail address',
1.188     raeburn  8116:                helpdesk  => 'Display "Contact Helpdesk" link',
1.168     raeburn  8117:                newuser => 'Link for visitors to create a user account',
                   8118:                loginheader => 'Log-in box header');
                   8119:     @offon = ('off','on');
1.112     raeburn  8120:     if (ref($domconfig{login}) eq 'HASH') {
                   8121:         if (ref($domconfig{login}{loginvia}) eq 'HASH') {
                   8122:             foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
                   8123:                 $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
                   8124:             }
                   8125:         }
                   8126:     }
1.9       raeburn  8127:     ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
                   8128:                                            \%domconfig,\%loginhash);
1.188     raeburn  8129:     my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42      raeburn  8130:     foreach my $item (@toggles) {
                   8131:         $loginhash{login}{$item} = $env{'form.'.$item};
                   8132:     }
1.41      raeburn  8133:     $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6       raeburn  8134:     if (ref($colchanges{'login'}) eq 'HASH') {  
                   8135:         $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
                   8136:                                          \%loginhash);
                   8137:     }
1.110     raeburn  8138: 
1.149     raeburn  8139:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.256     raeburn  8140:     my %domservers = &Apache::lonnet::get_servers($dom);
1.128     raeburn  8141:     my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110     raeburn  8142:     if (keys(%servers) > 1) {
                   8143:         foreach my $lonhost (keys(%servers)) {
1.128     raeburn  8144:             next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
                   8145:             if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
                   8146:                 if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
                   8147:                     $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
                   8148:                 } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
                   8149:                     if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
                   8150:                         $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
                   8151:                         $changes{'loginvia'}{$lonhost} = 1;
                   8152:                     } else {
                   8153:                         $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
                   8154:                         $changes{'loginvia'}{$lonhost} = 1;
                   8155:                     }
                   8156:                 } else {
                   8157:                     if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
                   8158:                         $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
                   8159:                         $changes{'loginvia'}{$lonhost} = 1;
                   8160:                     }
                   8161:                 }
                   8162:                 if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
                   8163:                     foreach my $item (@loginvia_attribs) {
                   8164:                         $loginhash{login}{loginvia}{$lonhost}{$item} = '';
                   8165:                     }
                   8166:                 } else {
                   8167:                     foreach my $item (@loginvia_attribs) {
                   8168:                         my $new = $env{'form.'.$lonhost.'_'.$item};
                   8169:                         if (($item eq 'serverpath') && ($new eq 'custom')) {
                   8170:                             $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
                   8171:                             if ($env{'form.'.$lonhost.'_custompath'} eq '') {
                   8172:                                 $new = '/';
                   8173:                             }
                   8174:                         }
                   8175:                         if (($item eq 'custompath') && 
                   8176:                             ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
                   8177:                             $new = '';
                   8178:                         }
                   8179:                         if ($new ne $curr_loginvia{$lonhost}{$item}) {
                   8180:                             $changes{'loginvia'}{$lonhost} = 1;
                   8181:                         }
                   8182:                         if ($item eq 'exempt') {
1.256     raeburn  8183:                             $new = &check_exempt_addresses($new);
1.128     raeburn  8184:                         }
                   8185:                         $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
                   8186:                     }
                   8187:                 }
1.112     raeburn  8188:             } else {
1.128     raeburn  8189:                 if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
                   8190:                     $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112     raeburn  8191:                     $changes{'loginvia'}{$lonhost} = 1;
1.128     raeburn  8192:                     foreach my $item (@loginvia_attribs) {
                   8193:                         my $new = $env{'form.'.$lonhost.'_'.$item};
                   8194:                         if (($item eq 'serverpath') && ($new eq 'custom')) {
                   8195:                             if ($env{'form.'.$lonhost.'_custompath'} eq '') {
                   8196:                                 $new = '/';
                   8197:                             }
                   8198:                         }
                   8199:                         if (($item eq 'custompath') && 
                   8200:                             ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
                   8201:                             $new = '';
                   8202:                         }
                   8203:                         $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
                   8204:                     }
1.110     raeburn  8205:                 }
                   8206:             }
                   8207:         }
                   8208:     }
1.119     raeburn  8209: 
1.168     raeburn  8210:     my $servadm = $r->dir_config('lonAdmEMail');
                   8211:     my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
                   8212:     if (ref($domconfig{'login'}) eq 'HASH') {
                   8213:         if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
                   8214:             foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
                   8215:                 if ($lang eq 'nolang') {
                   8216:                     push(@currlangs,$lang);
                   8217:                 } elsif (defined($langchoices{$lang})) {
                   8218:                     push(@currlangs,$lang);
                   8219:                 } else {
                   8220:                     next;
                   8221:                 }
                   8222:             }
                   8223:         }
                   8224:     }
                   8225:     my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
                   8226:     if (@currlangs > 0) {
                   8227:         foreach my $lang (@currlangs) {
                   8228:             if (grep(/^\Q$lang\E$/,@delurls)) {
                   8229:                 $changes{'helpurl'}{$lang} = 1;
                   8230:             } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
                   8231:                 $changes{'helpurl'}{$lang} = 1;
                   8232:                 $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
                   8233:                 push(@newlangs,$lang);
                   8234:             } else {
                   8235:                 $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
                   8236:             }
                   8237:         }
                   8238:     }
                   8239:     unless (grep(/^nolang$/,@currlangs)) {
                   8240:         if ($env{'form.loginhelpurl_nolang.filename'}) {
                   8241:             $changes{'helpurl'}{'nolang'} = 1;
                   8242:             $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
                   8243:             push(@newlangs,'nolang');
                   8244:         }
                   8245:     }
                   8246:     if ($env{'form.loginhelpurl_add_lang'}) {
                   8247:         if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
                   8248:             ($env{'form.loginhelpurl_add_file.filename'})) {
                   8249:             $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
                   8250:             $addedfile = $env{'form.loginhelpurl_add_lang'};
                   8251:         }
                   8252:     }
                   8253:     if ((@newlangs > 0) || ($addedfile)) {
                   8254:         my $error;
                   8255:         my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
                   8256:         if ($configuserok eq 'ok') {
                   8257:             if ($switchserver) {
                   8258:                 $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
                   8259:             } elsif ($author_ok eq 'ok') {
                   8260:                 my @allnew = @newlangs;
                   8261:                 if ($addedfile ne '') {
                   8262:                     push(@allnew,$addedfile);
                   8263:                 }
                   8264:                 foreach my $lang (@allnew) {
                   8265:                     my $formelem = 'loginhelpurl_'.$lang;
                   8266:                     if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
                   8267:                         $formelem = 'loginhelpurl_add_file';
                   8268:                     }
                   8269:                     (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
                   8270:                                                                "help/$lang",'','',$newfile{$lang});
                   8271:                     if ($result eq 'ok') {
                   8272:                         $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
                   8273:                         $changes{'helpurl'}{$lang} = 1;
                   8274:                     } else {
                   8275:                         my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
                   8276:                         $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210     raeburn  8277:                         if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168     raeburn  8278:                             (!grep(/^\Q$lang\E$/,@delurls))) {
                   8279:                             $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
                   8280:                         }
                   8281:                     }
                   8282:                 }
                   8283:             } else {
                   8284:                 $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);
                   8285:             }
                   8286:         } else {
                   8287:             $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);
                   8288:         }
                   8289:         if ($error) {
                   8290:             &Apache::lonnet::logthis($error);
                   8291:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   8292:         }
                   8293:     }
1.256     raeburn  8294: 
                   8295:     my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
                   8296:     if (ref($domconfig{'login'}) eq 'HASH') {
                   8297:         if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
                   8298:             foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
                   8299:                 if ($domservers{$lonhost}) {
                   8300:                     if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
                   8301:                         $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.268     raeburn  8302:                         $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.256     raeburn  8303:                     }
                   8304:                 }
                   8305:             }
                   8306:         }
                   8307:     }
                   8308:     my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
                   8309:     foreach my $lonhost (sort(keys(%domservers))) {
                   8310:         if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
                   8311:             $changes{'headtag'}{$lonhost} = 1;
                   8312:         } else {
                   8313:             if ($env{'form.loginheadtagexempt_'.$lonhost}) {
                   8314:                 $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
                   8315:             }
                   8316:             if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
                   8317:                 push(@newhosts,$lonhost);
                   8318:             } elsif ($currheadtagurls{$lonhost}) {
                   8319:                 $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
                   8320:                 if ($currexempt{$lonhost}) {
1.289     raeburn  8321:                     if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
1.256     raeburn  8322:                         $changes{'headtag'}{$lonhost} = 1;
                   8323:                     }
                   8324:                 } elsif ($possexempt{$lonhost}) {
                   8325:                     $changes{'headtag'}{$lonhost} = 1;
                   8326:                 }
                   8327:                 if ($possexempt{$lonhost}) {
                   8328:                     $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
                   8329:                 }
                   8330:             }
                   8331:         }
                   8332:     }
                   8333:     if (@newhosts) {
                   8334:         my $error;
                   8335:         my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
                   8336:         if ($configuserok eq 'ok') {
                   8337:             if ($switchserver) {
                   8338:                 $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
                   8339:             } elsif ($author_ok eq 'ok') {
                   8340:                 foreach my $lonhost (@newhosts) {
                   8341:                     my $formelem = 'loginheadtag_'.$lonhost;
                   8342:                     (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
                   8343:                                                                           "login/headtag/$lonhost",'','',
                   8344:                                                                           $env{'form.loginheadtag_'.$lonhost.'.filename'});
                   8345:                     if ($result eq 'ok') {
                   8346:                         $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
                   8347:                         $changes{'headtag'}{$lonhost} = 1;
                   8348:                         if ($possexempt{$lonhost}) {
                   8349:                             $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
                   8350:                         }
                   8351:                     } else {
                   8352:                         my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
                   8353:                                            $newheadtagurls{$lonhost},$result);
                   8354:                         $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
                   8355:                         if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
                   8356:                             (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
                   8357:                             $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
                   8358:                         }
                   8359:                     }
                   8360:                 }
                   8361:             } else {
                   8362:                 $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);
                   8363:             }
                   8364:         } else {
                   8365:             $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);
                   8366:         }
                   8367:         if ($error) {
                   8368:             &Apache::lonnet::logthis($error);
                   8369:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   8370:         }
                   8371:     }
1.169     raeburn  8372:     &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168     raeburn  8373: 
                   8374:     my $defaulthelpfile = '/adm/loginproblems.html';
                   8375:     my $defaulttext = &mt('Default in use');
                   8376: 
1.1       raeburn  8377:     my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
                   8378:                                              $dom);
                   8379:     if ($putresult eq 'ok') {
1.188     raeburn  8380:         my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42      raeburn  8381:         my %defaultchecked = (
                   8382:                     'coursecatalog' => 'on',
1.188     raeburn  8383:                     'helpdesk'      => 'on',
1.42      raeburn  8384:                     'adminmail'     => 'off',
1.43      raeburn  8385:                     'newuser'       => 'off',
1.42      raeburn  8386:         );
1.55      raeburn  8387:         if (ref($domconfig{'login'}) eq 'HASH') {
                   8388:             foreach my $item (@toggles) {
                   8389:                 if ($defaultchecked{$item} eq 'on') { 
                   8390:                     if (($domconfig{'login'}{$item} eq '0') &&
                   8391:                         ($env{'form.'.$item} eq '1')) {
                   8392:                         $changes{$item} = 1;
                   8393:                     } elsif (($domconfig{'login'}{$item} eq '' ||
                   8394:                               $domconfig{'login'}{$item} eq '1') &&
                   8395:                              ($env{'form.'.$item} eq '0')) {
                   8396:                         $changes{$item} = 1;
                   8397:                     }
                   8398:                 } elsif ($defaultchecked{$item} eq 'off') {
                   8399:                     if (($domconfig{'login'}{$item} eq '1') &&
                   8400:                         ($env{'form.'.$item} eq '0')) {
                   8401:                         $changes{$item} = 1;
                   8402:                     } elsif (($domconfig{'login'}{$item} eq '' ||
                   8403:                               $domconfig{'login'}{$item} eq '0') &&
                   8404:                              ($env{'form.'.$item} eq '1')) {
                   8405:                         $changes{$item} = 1;
                   8406:                     }
1.42      raeburn  8407:                 }
                   8408:             }
1.41      raeburn  8409:         }
1.6       raeburn  8410:         if (keys(%changes) > 0 || $colchgtext) {
1.41      raeburn  8411:             &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212     raeburn  8412:             if (ref($lastactref) eq 'HASH') {
                   8413:                 $lastactref->{'domainconfig'} = 1;
                   8414:             }
1.1       raeburn  8415:             $resulttext = &mt('Changes made:').'<ul>';
                   8416:             foreach my $item (sort(keys(%changes))) {
1.135     bisitz   8417:                 if ($item eq 'loginvia') {
1.112     raeburn  8418:                     if (ref($changes{$item}) eq 'HASH') {
                   8419:                         $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
                   8420:                         foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128     raeburn  8421:                             if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
                   8422:                                 if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
                   8423:                                     my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
                   8424:                                     $protocol = 'http' if ($protocol ne 'https');
                   8425:                                     my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
                   8426: 
                   8427:                                     if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
                   8428:                                         $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
                   8429:                                     } else {
                   8430:                                         $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'}; 
                   8431:                                     }
                   8432:                                     $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
                   8433:                                     if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
                   8434:                                         $resulttext .= '&nbsp;'.&mt('No redirection for clients from following IPs:').'&nbsp;'.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
                   8435:                                     }
                   8436:                                     $resulttext .= '</li>';
                   8437:                                 } else {
                   8438:                                     $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
                   8439:                                 }
1.112     raeburn  8440:                             } else {
1.128     raeburn  8441:                                 $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112     raeburn  8442:                             }
                   8443:                         }
1.128     raeburn  8444:                         $resulttext .= '</ul></li>';
1.112     raeburn  8445:                     }
1.168     raeburn  8446:                 } elsif ($item eq 'helpurl') {
                   8447:                     if (ref($changes{$item}) eq 'HASH') {
                   8448:                         foreach my $lang (sort(keys(%{$changes{$item}}))) {
                   8449:                             if (grep(/^\Q$lang\E$/,@delurls)) {
                   8450:                                 my ($chg,$link);
                   8451:                                 $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
                   8452:                                 if ($lang eq 'nolang') {
                   8453:                                     $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
                   8454:                                 } else {
                   8455:                                     $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
                   8456:                                 }
                   8457:                                 $resulttext .= '<li>'.$chg.'</li>';
                   8458:                             } else {
                   8459:                                 my $chg;
                   8460:                                 if ($lang eq 'nolang') {
                   8461:                                     $chg = &mt('custom log-in help file for no preferred language');
                   8462:                                 } else {
                   8463:                                     $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
                   8464:                                 }
                   8465:                                 $resulttext .= '<li>'.&Apache::loncommon::modal_link(
                   8466:                                                       $loginhash{'login'}{'helpurl'}{$lang}.
                   8467:                                                       '?inhibitmenu=yes',$chg,600,500).
                   8468:                                                '</li>';
                   8469:                             }
                   8470:                         }
                   8471:                     }
1.256     raeburn  8472:                 } elsif ($item eq 'headtag') {
                   8473:                     if (ref($changes{$item}) eq 'HASH') {
                   8474:                         foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
                   8475:                             if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
                   8476:                                 $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
                   8477:                             } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
                   8478:                                 $resulttext .= '<li><a href="'.
                   8479:                                                "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
                   8480:                                                'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
                   8481:                                                '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
                   8482:                                 if ($possexempt{$lonhost}) {
                   8483:                                     $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
                   8484:                                 } else {
                   8485:                                     $resulttext .= &mt('included for any client IP');
                   8486:                                 }
                   8487:                                 $resulttext .= '</li>';
                   8488:                             }
                   8489:                         }
                   8490:                     }
1.169     raeburn  8491:                 } elsif ($item eq 'captcha') {
                   8492:                     if (ref($loginhash{'login'}) eq 'HASH') {
1.210     raeburn  8493:                         my $chgtxt;
1.169     raeburn  8494:                         if ($loginhash{'login'}{$item} eq 'notused') {
                   8495:                             $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
                   8496:                         } else {
                   8497:                             my %captchas = &captcha_phrases();
                   8498:                             if ($captchas{$loginhash{'login'}{$item}}) {
                   8499:                                 $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
                   8500:                             } else {
                   8501:                                 $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
                   8502:                             }
                   8503:                         }
                   8504:                         $resulttext .= '<li>'.$chgtxt.'</li>';
                   8505:                     }
                   8506:                 } elsif ($item eq 'recaptchakeys') {
                   8507:                     if (ref($loginhash{'login'}) eq 'HASH') {
                   8508:                         my ($privkey,$pubkey);
                   8509:                         if (ref($loginhash{'login'}{$item}) eq 'HASH') {
                   8510:                             $pubkey = $loginhash{'login'}{$item}{'public'};
                   8511:                             $privkey = $loginhash{'login'}{$item}{'private'};
                   8512:                         }
                   8513:                         my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
                   8514:                         if (!$pubkey) {
                   8515:                             $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
                   8516:                         } else {
                   8517:                             $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
                   8518:                         }
                   8519:                         if (!$privkey) {
                   8520:                             $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
                   8521:                         } else {
1.251     raeburn  8522:                             $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.169     raeburn  8523:                         }
                   8524:                         $chgtxt .= '</ul>';
                   8525:                         $resulttext .= '<li>'.$chgtxt.'</li>';
                   8526:                     }
1.269     raeburn  8527:                 } elsif ($item eq 'recaptchaversion') {
                   8528:                     if (ref($loginhash{'login'}) eq 'HASH') {
                   8529:                         if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
1.270     raeburn  8530:                             $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
1.269     raeburn  8531:                                            '</li>';
                   8532:                         }
                   8533:                     }
1.41      raeburn  8534:                 } else {
                   8535:                     $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
                   8536:                 }
1.1       raeburn  8537:             }
1.6       raeburn  8538:             $resulttext .= $colchgtext.'</ul>';
1.1       raeburn  8539:         } else {
                   8540:             $resulttext = &mt('No changes made to log-in page settings');
                   8541:         }
                   8542:     } else {
1.11      albertel 8543:         $resulttext = '<span class="LC_error">'.
                   8544: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  8545:     }
1.6       raeburn  8546:     if ($errors) {
1.9       raeburn  8547:         $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6       raeburn  8548:                        $errors.'</ul>';
                   8549:     }
                   8550:     return $resulttext;
                   8551: }
                   8552: 
1.256     raeburn  8553: sub check_exempt_addresses {
                   8554:     my ($iplist) = @_;
                   8555:     $iplist =~ s/^\s+//;
                   8556:     $iplist =~ s/\s+$//;
                   8557:     my @poss_ips = split(/\s*[,:]\s*/,$iplist);
                   8558:     my (@okips,$new);
                   8559:     foreach my $ip (@poss_ips) {
                   8560:         if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
                   8561:             if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
                   8562:                 push(@okips,$ip);
                   8563:             }
                   8564:         }
                   8565:     }
                   8566:     if (@okips > 0) {
                   8567:         $new = join(',',@okips);
                   8568:     } else {
                   8569:         $new = '';
                   8570:     }
                   8571:     return $new;
                   8572: }
                   8573: 
1.6       raeburn  8574: sub color_font_choices {
                   8575:     my %choices =
                   8576:         &Apache::lonlocal::texthash (
                   8577:             img => "Header",
                   8578:             bgs => "Background colors",
                   8579:             links => "Link colors",
1.55      raeburn  8580:             images => "Images",
1.6       raeburn  8581:             font => "Font color",
1.201     raeburn  8582:             fontmenu => "Font menu",
1.76      raeburn  8583:             pgbg => "Page",
1.6       raeburn  8584:             tabbg => "Header",
                   8585:             sidebg => "Border",
                   8586:             link => "Link",
                   8587:             alink => "Active link",
                   8588:             vlink => "Visited link",
                   8589:         );
                   8590:     return %choices;
                   8591: }
                   8592: 
                   8593: sub modify_rolecolors {
1.205     raeburn  8594:     my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6       raeburn  8595:     my ($resulttext,%rolehash);
                   8596:     $rolehash{'rolecolors'} = {};
1.55      raeburn  8597:     if (ref($domconfig{'rolecolors'}) ne 'HASH') {
                   8598:         if ($domconfig{'rolecolors'} eq '') {
                   8599:             $domconfig{'rolecolors'} = {};
                   8600:         }
                   8601:     }
1.9       raeburn  8602:     my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6       raeburn  8603:                          $domconfig{'rolecolors'},$rolehash{'rolecolors'});
                   8604:     my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
                   8605:                                              $dom);
                   8606:     if ($putresult eq 'ok') {
                   8607:         if (keys(%changes) > 0) {
1.41      raeburn  8608:             &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212     raeburn  8609:             if (ref($lastactref) eq 'HASH') {
                   8610:                 $lastactref->{'domainconfig'} = 1;
                   8611:             }
1.6       raeburn  8612:             $resulttext = &display_colorchgs($dom,\%changes,$roles,
                   8613:                                              $rolehash{'rolecolors'});
                   8614:         } else {
                   8615:             $resulttext = &mt('No changes made to default color schemes');
                   8616:         }
                   8617:     } else {
1.11      albertel 8618:         $resulttext = '<span class="LC_error">'.
                   8619: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.6       raeburn  8620:     }
                   8621:     if ($errors) {
                   8622:         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
                   8623:                        $errors.'</ul>';
                   8624:     }
                   8625:     return $resulttext;
                   8626: }
                   8627: 
                   8628: sub modify_colors {
1.9       raeburn  8629:     my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12      raeburn  8630:     my (%changes,%choices);
1.51      raeburn  8631:     my @bgs;
1.6       raeburn  8632:     my @links = ('link','alink','vlink');
1.41      raeburn  8633:     my @logintext;
1.6       raeburn  8634:     my @images;
                   8635:     my $servadm = $r->dir_config('lonAdmEMail');
                   8636:     my $errors;
1.200     raeburn  8637:     my %defaults;
1.6       raeburn  8638:     foreach my $role (@{$roles}) {
                   8639:         if ($role eq 'login') {
1.12      raeburn  8640:             %choices = &login_choices();
1.41      raeburn  8641:             @logintext = ('textcol','bgcol');
1.12      raeburn  8642:         } else {
                   8643:             %choices = &color_font_choices();
                   8644:         }
                   8645:         if ($role eq 'login') {
1.41      raeburn  8646:             @images = ('img','logo','domlogo','login');
1.51      raeburn  8647:             @bgs = ('pgbg','mainbg','sidebg');
1.6       raeburn  8648:         } else {
                   8649:             @images = ('img');
1.200     raeburn  8650:             @bgs = ('pgbg','tabbg','sidebg');
                   8651:         }
                   8652:         my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
                   8653:         unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
                   8654:             $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
                   8655:         }
                   8656:         if ($role eq 'login') {
                   8657:             foreach my $item (@logintext) {
1.234     raeburn  8658:                 $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
                   8659:                 if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
                   8660:                     $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
                   8661:                 }
                   8662:                 unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.200     raeburn  8663:                     $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
                   8664:                 }
                   8665:             }
                   8666:         } else {
1.234     raeburn  8667:             $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
                   8668:             if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
                   8669:                 $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
                   8670:             }
                   8671:             unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.200     raeburn  8672:                 $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
                   8673:             }
1.6       raeburn  8674:         }
1.200     raeburn  8675:         foreach my $item (@bgs) {
1.234     raeburn  8676:             $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
                   8677:             if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
                   8678:                 $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
                   8679:             }
                   8680:             unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.200     raeburn  8681:                 $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
                   8682:             }
                   8683:         }
                   8684:         foreach my $item (@links) {
1.234     raeburn  8685:             $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
                   8686:             if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
                   8687:                 $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
                   8688:             }
                   8689:             unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.200     raeburn  8690:                 $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
                   8691:             }
1.6       raeburn  8692:         }
1.46      raeburn  8693:         my ($configuserok,$author_ok,$switchserver) = 
                   8694:             &config_check($dom,$confname,$servadm);
1.9       raeburn  8695:         my ($width,$height) = &thumb_dimensions();
1.40      raeburn  8696:         if (ref($domconfig->{$role}) ne 'HASH') {
                   8697:             $domconfig->{$role} = {};
                   8698:         }
1.8       raeburn  8699:         foreach my $img (@images) {
1.70      raeburn  8700:             if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {  
                   8701:                 if (defined($env{'form.login_showlogo_'.$img})) {
                   8702:                     $confhash->{$role}{'showlogo'}{$img} = 1;
                   8703:                 } else { 
                   8704:                     $confhash->{$role}{'showlogo'}{$img} = 0;
                   8705:                 }
                   8706:             } 
1.18      albertel 8707: 	    if ( ! $env{'form.'.$role.'_'.$img.'.filename'} 
                   8708: 		 && !defined($domconfig->{$role}{$img})
                   8709: 		 && !$env{'form.'.$role.'_del_'.$img}
                   8710: 		 && $env{'form.'.$role.'_import_'.$img}) {
                   8711: 		# import the old configured image from the .tab setting
                   8712: 		# if they haven't provided a new one 
                   8713: 		$domconfig->{$role}{$img} = 
                   8714: 		    $env{'form.'.$role.'_import_'.$img};
                   8715: 	    }
1.6       raeburn  8716:             if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9       raeburn  8717:                 my $error;
1.6       raeburn  8718:                 if ($configuserok eq 'ok') {
1.9       raeburn  8719:                     if ($switchserver) {
1.12      raeburn  8720:                         $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9       raeburn  8721:                     } else {
                   8722:                         if ($author_ok eq 'ok') {
                   8723:                             my ($result,$logourl) = 
                   8724:                                 &publishlogo($r,'upload',$role.'_'.$img,
                   8725:                                            $dom,$confname,$img,$width,$height);
                   8726:                             if ($result eq 'ok') {
                   8727:                                 $confhash->{$role}{$img} = $logourl;
1.12      raeburn  8728:                                 $changes{$role}{'images'}{$img} = 1;
1.9       raeburn  8729:                             } else {
1.12      raeburn  8730:                                 $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  8731:                             }
                   8732:                         } else {
1.46      raeburn  8733:                             $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  8734:                         }
                   8735:                     }
                   8736:                 } else {
1.46      raeburn  8737:                     $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  8738:                 }
                   8739:                 if ($error) {
1.8       raeburn  8740:                     &Apache::lonnet::logthis($error);
1.11      albertel 8741:                     $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8       raeburn  8742:                 }
                   8743:             } elsif ($domconfig->{$role}{$img} ne '') {
1.9       raeburn  8744:                 if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
                   8745:                     my $error;
                   8746:                     if ($configuserok eq 'ok') {
                   8747: # is confname an author?
                   8748:                         if ($switchserver eq '') {
                   8749:                             if ($author_ok eq 'ok') {
                   8750:                                 my ($result,$logourl) = 
                   8751:                                &publishlogo($r,'copy',$domconfig->{$role}{$img},
                   8752:                                             $dom,$confname,$img,$width,$height);
                   8753:                                 if ($result eq 'ok') {
                   8754:                                     $confhash->{$role}{$img} = $logourl;
1.18      albertel 8755: 				    $changes{$role}{'images'}{$img} = 1;
1.9       raeburn  8756:                                 }
                   8757:                             }
                   8758:                         }
                   8759:                     }
1.6       raeburn  8760:                 }
                   8761:             }
                   8762:         }
                   8763:         if (ref($domconfig) eq 'HASH') {
                   8764:             if (ref($domconfig->{$role}) eq 'HASH') {
                   8765:                 foreach my $img (@images) {
                   8766:                     if ($domconfig->{$role}{$img} ne '') {
                   8767:                         if ($env{'form.'.$role.'_del_'.$img}) {
                   8768:                             $confhash->{$role}{$img} = '';
1.12      raeburn  8769:                             $changes{$role}{'images'}{$img} = 1;
1.6       raeburn  8770:                         } else {
1.9       raeburn  8771:                             if ($confhash->{$role}{$img} eq '') {
                   8772:                                 $confhash->{$role}{$img} = $domconfig->{$role}{$img};
                   8773:                             }
1.6       raeburn  8774:                         }
                   8775:                     } else {
                   8776:                         if ($env{'form.'.$role.'_del_'.$img}) {
                   8777:                             $confhash->{$role}{$img} = '';
1.12      raeburn  8778:                             $changes{$role}{'images'}{$img} = 1;
1.6       raeburn  8779:                         } 
                   8780:                     }
1.70      raeburn  8781:                     if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
                   8782:                         if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
                   8783:                             if ($confhash->{$role}{'showlogo'}{$img} ne 
                   8784:                                 $domconfig->{$role}{'showlogo'}{$img}) {
                   8785:                                 $changes{$role}{'showlogo'}{$img} = 1; 
                   8786:                             }
                   8787:                         } else {
                   8788:                             if ($confhash->{$role}{'showlogo'}{$img} == 0) {
                   8789:                                 $changes{$role}{'showlogo'}{$img} = 1;
                   8790:                             }
                   8791:                         }
                   8792:                     }
                   8793:                 }
1.6       raeburn  8794:                 if ($domconfig->{$role}{'font'} ne '') {
                   8795:                     if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
                   8796:                         $changes{$role}{'font'} = 1;
                   8797:                     }
                   8798:                 } else {
                   8799:                     if ($confhash->{$role}{'font'}) {
                   8800:                         $changes{$role}{'font'} = 1;
                   8801:                     }
                   8802:                 }
1.107     raeburn  8803:                 if ($role ne 'login') {
                   8804:                     if ($domconfig->{$role}{'fontmenu'} ne '') {
                   8805:                         if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
                   8806:                             $changes{$role}{'fontmenu'} = 1;
                   8807:                         }
                   8808:                     } else {
                   8809:                         if ($confhash->{$role}{'fontmenu'}) {
                   8810:                             $changes{$role}{'fontmenu'} = 1;
                   8811:                         }
1.97      tempelho 8812:                     }
                   8813:                 }
1.6       raeburn  8814:                 foreach my $item (@bgs) {
                   8815:                     if ($domconfig->{$role}{$item} ne '') {
                   8816:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
                   8817:                             $changes{$role}{'bgs'}{$item} = 1;
                   8818:                         } 
                   8819:                     } else {
                   8820:                         if ($confhash->{$role}{$item}) {
                   8821:                             $changes{$role}{'bgs'}{$item} = 1;
                   8822:                         }
                   8823:                     }
                   8824:                 }
                   8825:                 foreach my $item (@links) {
                   8826:                     if ($domconfig->{$role}{$item} ne '') {
                   8827:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
                   8828:                             $changes{$role}{'links'}{$item} = 1;
                   8829:                         }
                   8830:                     } else {
                   8831:                         if ($confhash->{$role}{$item}) {
                   8832:                             $changes{$role}{'links'}{$item} = 1;
                   8833:                         }
                   8834:                     }
                   8835:                 }
1.41      raeburn  8836:                 foreach my $item (@logintext) {
                   8837:                     if ($domconfig->{$role}{$item} ne '') {
                   8838:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
                   8839:                             $changes{$role}{'logintext'}{$item} = 1;
                   8840:                         }
                   8841:                     } else {
                   8842:                         if ($confhash->{$role}{$item}) {
                   8843:                             $changes{$role}{'logintext'}{$item} = 1;
                   8844:                         }
                   8845:                     }
                   8846:                 }
1.6       raeburn  8847:             } else {
                   8848:                 &default_change_checker($role,\@images,\@links,\@bgs,
1.41      raeburn  8849:                                         \@logintext,$confhash,\%changes); 
1.6       raeburn  8850:             }
                   8851:         } else {
                   8852:             &default_change_checker($role,\@images,\@links,\@bgs,
1.41      raeburn  8853:                                     \@logintext,$confhash,\%changes); 
1.6       raeburn  8854:         }
                   8855:     }
                   8856:     return ($errors,%changes);
                   8857: }
                   8858: 
1.46      raeburn  8859: sub config_check {
                   8860:     my ($dom,$confname,$servadm) = @_;
                   8861:     my ($configuserok,$author_ok,$switchserver,%currroles);
                   8862:     my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
                   8863:     ($configuserok,%currroles) = &check_configuser($uhome,$dom,
                   8864:                                                    $confname,$servadm);
                   8865:     if ($configuserok eq 'ok') {
                   8866:         $switchserver = &check_switchserver($dom,$confname);
                   8867:         if ($switchserver eq '') {
                   8868:             $author_ok = &check_authorstatus($dom,$confname,%currroles);
                   8869:         }
                   8870:     }
                   8871:     return ($configuserok,$author_ok,$switchserver);
                   8872: }
                   8873: 
1.6       raeburn  8874: sub default_change_checker {
1.41      raeburn  8875:     my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6       raeburn  8876:     foreach my $item (@{$links}) {
                   8877:         if ($confhash->{$role}{$item}) {
                   8878:             $changes->{$role}{'links'}{$item} = 1;
                   8879:         }
                   8880:     }
                   8881:     foreach my $item (@{$bgs}) {
                   8882:         if ($confhash->{$role}{$item}) {
                   8883:             $changes->{$role}{'bgs'}{$item} = 1;
                   8884:         }
                   8885:     }
1.41      raeburn  8886:     foreach my $item (@{$logintext}) {
                   8887:         if ($confhash->{$role}{$item}) {
                   8888:             $changes->{$role}{'logintext'}{$item} = 1;
                   8889:         }
                   8890:     }
1.6       raeburn  8891:     foreach my $img (@{$images}) {
                   8892:         if ($env{'form.'.$role.'_del_'.$img}) {
                   8893:             $confhash->{$role}{$img} = '';
1.12      raeburn  8894:             $changes->{$role}{'images'}{$img} = 1;
1.6       raeburn  8895:         }
1.70      raeburn  8896:         if ($role eq 'login') {
                   8897:             if ($confhash->{$role}{'showlogo'}{$img} == 0) {
                   8898:                 $changes->{$role}{'showlogo'}{$img} = 1;
                   8899:             }
                   8900:         }
1.6       raeburn  8901:     }
                   8902:     if ($confhash->{$role}{'font'}) {
                   8903:         $changes->{$role}{'font'} = 1;
                   8904:     }
1.48      raeburn  8905: }
1.6       raeburn  8906: 
                   8907: sub display_colorchgs {
                   8908:     my ($dom,$changes,$roles,$confhash) = @_;
                   8909:     my (%choices,$resulttext);
                   8910:     if (!grep(/^login$/,@{$roles})) {
                   8911:         $resulttext = &mt('Changes made:').'<br />';
                   8912:     }
                   8913:     foreach my $role (@{$roles}) {
                   8914:         if ($role eq 'login') {
                   8915:             %choices = &login_choices();
                   8916:         } else {
                   8917:             %choices = &color_font_choices();
                   8918:         }
                   8919:         if (ref($changes->{$role}) eq 'HASH') {
                   8920:             if ($role ne 'login') {
                   8921:                 $resulttext .= '<h4>'.&mt($role).'</h4>';
                   8922:             }
                   8923:             foreach my $key (sort(keys(%{$changes->{$role}}))) {
                   8924:                 if ($role ne 'login') {
                   8925:                     $resulttext .= '<ul>';
                   8926:                 }
                   8927:                 if (ref($changes->{$role}{$key}) eq 'HASH') {
                   8928:                     if ($role ne 'login') {
                   8929:                         $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
                   8930:                     }
                   8931:                     foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70      raeburn  8932:                         if (($role eq 'login') && ($key eq 'showlogo')) {
                   8933:                             if ($confhash->{$role}{$key}{$item}) {
                   8934:                                 $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
                   8935:                             } else {
                   8936:                                 $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
                   8937:                             }
                   8938:                         } elsif ($confhash->{$role}{$item} eq '') {
1.6       raeburn  8939:                             $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
                   8940:                         } else {
1.12      raeburn  8941:                             my $newitem = $confhash->{$role}{$item};
                   8942:                             if ($key eq 'images') {
1.306     raeburn  8943:                                 $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" style="vertical-align: bottom" />';
1.12      raeburn  8944:                             }
                   8945:                             $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6       raeburn  8946:                         }
                   8947:                     }
                   8948:                     if ($role ne 'login') {
                   8949:                         $resulttext .= '</ul></li>';
                   8950:                     }
                   8951:                 } else {
                   8952:                     if ($confhash->{$role}{$key} eq '') {
                   8953:                         $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
                   8954:                     } else {
                   8955:                         $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
                   8956:                     }
                   8957:                 }
                   8958:                 if ($role ne 'login') {
                   8959:                     $resulttext .= '</ul>';
                   8960:                 }
                   8961:             }
                   8962:         }
                   8963:     }
1.3       raeburn  8964:     return $resulttext;
1.1       raeburn  8965: }
                   8966: 
1.9       raeburn  8967: sub thumb_dimensions {
                   8968:     return ('200','50');
                   8969: }
                   8970: 
1.16      raeburn  8971: sub check_dimensions {
                   8972:     my ($inputfile) = @_;
                   8973:     my ($fullwidth,$fullheight);
                   8974:     if ($inputfile =~ m|^[/\w.\-]+$|) {
                   8975:         if (open(PIPE,"identify $inputfile 2>&1 |")) {
                   8976:             my $imageinfo = <PIPE>;
                   8977:             if (!close(PIPE)) {
                   8978:                 &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
                   8979:             }
                   8980:             chomp($imageinfo);
                   8981:             my ($fullsize) = 
1.21      raeburn  8982:                 ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16      raeburn  8983:             if ($fullsize) {
                   8984:                 ($fullwidth,$fullheight) = split(/x/,$fullsize);
                   8985:             }
                   8986:         }
                   8987:     }
                   8988:     return ($fullwidth,$fullheight);
                   8989: }
                   8990: 
1.9       raeburn  8991: sub check_configuser {
                   8992:     my ($uhome,$dom,$confname,$servadm) = @_;
                   8993:     my ($configuserok,%currroles);
                   8994:     if ($uhome eq 'no_host') {
                   8995:         srand( time() ^ ($$ + ($$ << 15))  ); # Seed rand.
                   8996:         my $configpass = &LONCAPA::Enrollment::create_password();
                   8997:         $configuserok = 
                   8998:             &Apache::lonnet::modifyuser($dom,$confname,'','internal',
                   8999:                              $configpass,'','','','','',undef,$servadm);
                   9000:     } else {
                   9001:         $configuserok = 'ok';
                   9002:         %currroles = 
                   9003:             &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
                   9004:     }
                   9005:     return ($configuserok,%currroles);
                   9006: }
                   9007: 
                   9008: sub check_authorstatus {
                   9009:     my ($dom,$confname,%currroles) = @_;
                   9010:     my $author_ok;
1.40      raeburn  9011:     if (!$currroles{':'.$dom.':au'}) {
1.9       raeburn  9012:         my $start = time;
                   9013:         my $end = 0;
                   9014:         $author_ok = 
                   9015:             &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47      raeburn  9016:                                         'au',$end,$start,'','','domconfig');
1.9       raeburn  9017:     } else {
                   9018:         $author_ok = 'ok';
                   9019:     }
                   9020:     return $author_ok;
                   9021: }
                   9022: 
                   9023: sub publishlogo {
1.46      raeburn  9024:     my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.267     raeburn  9025:     my ($output,$fname,$logourl,$madethumb);
1.9       raeburn  9026:     if ($action eq 'upload') {
                   9027:         $fname=$env{'form.'.$formname.'.filename'};
                   9028:         chop($env{'form.'.$formname});
                   9029:     } else {
                   9030:         ($fname) = ($formname =~ /([^\/]+)$/);
                   9031:     }
1.46      raeburn  9032:     if ($savefileas ne '') {
                   9033:         $fname = $savefileas;
                   9034:     }
1.9       raeburn  9035:     $fname=&Apache::lonnet::clean_filename($fname);
                   9036: # See if there is anything left
                   9037:     unless ($fname) { return ('error: no uploaded file'); }
                   9038:     $fname="$subdir/$fname";
1.210     raeburn  9039:     my $docroot=$r->dir_config('lonDocRoot');
1.164     raeburn  9040:     my $filepath="$docroot/priv";
                   9041:     my $relpath = "$dom/$confname";
1.9       raeburn  9042:     my ($fnamepath,$file,$fetchthumb);
                   9043:     $file=$fname;
                   9044:     if ($fname=~m|/|) {
                   9045:         ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
                   9046:     }
1.164     raeburn  9047:     my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9       raeburn  9048:     my $count;
1.164     raeburn  9049:     for ($count=5;$count<=$#parts;$count++) {
1.9       raeburn  9050:         $filepath.="/$parts[$count]";
                   9051:         if ((-e $filepath)!=1) {
                   9052:             mkdir($filepath,02770);
                   9053:         }
                   9054:     }
                   9055:     # Check for bad extension and disallow upload
                   9056:     if ($file=~/\.(\w+)$/ &&
                   9057:         (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
                   9058:         $output = 
1.207     bisitz   9059:             &mt('Invalid file extension ([_1]) - reserved for internal use.',$1); 
1.9       raeburn  9060:     } elsif ($file=~/\.(\w+)$/ &&
                   9061:         !defined(&Apache::loncommon::fileembstyle($1))) {
                   9062:         $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
                   9063:     } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.195     bisitz   9064:         $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  9065:     } elsif (-d "$filepath/$file") {
1.195     bisitz   9066:         $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9       raeburn  9067:     } else {
                   9068:         my $source = $filepath.'/'.$file;
                   9069:         my $logfile;
1.316   ! raeburn  9070:         if (!open($logfile,">>",$source.'.log')) {
1.196     raeburn  9071:             return (&mt('No write permission to Authoring Space'));
1.9       raeburn  9072:         }
                   9073:         print $logfile
                   9074: "\n================= Publish ".localtime()." ================\n".
                   9075: $env{'user.name'}.':'.$env{'user.domain'}."\n";
                   9076: # Save the file
1.316   ! raeburn  9077:         if (!open(FH,">",$source)) {
1.9       raeburn  9078:             &Apache::lonnet::logthis('Failed to create '.$source);
                   9079:             return (&mt('Failed to create file'));
                   9080:         }
                   9081:         if ($action eq 'upload') {
                   9082:             if (!print FH ($env{'form.'.$formname})) {
                   9083:                 &Apache::lonnet::logthis('Failed to write to '.$source);
                   9084:                 return (&mt('Failed to write file'));
                   9085:             }
                   9086:         } else {
                   9087:             my $original = &Apache::lonnet::filelocation('',$formname);
                   9088:             if(!copy($original,$source)) {
                   9089:                 &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
                   9090:                 return (&mt('Failed to write file'));
                   9091:             }
                   9092:         }
                   9093:         close(FH);
                   9094:         chmod(0660, $source); # Permissions to rw-rw---.
                   9095: 
                   9096:         my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
                   9097:         my $copyfile=$targetdir.'/'.$file;
                   9098: 
                   9099:         my @parts=split(/\//,$targetdir);
                   9100:         my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
                   9101:         for (my $count=5;$count<=$#parts;$count++) {
                   9102:             $path.="/$parts[$count]";
                   9103:             if (!-e $path) {
                   9104:                 print $logfile "\nCreating directory ".$path;
                   9105:                 mkdir($path,02770);
                   9106:             }
                   9107:         }
                   9108:         my $versionresult;
                   9109:         if (-e $copyfile) {
                   9110:             $versionresult = &logo_versioning($targetdir,$file,$logfile);
                   9111:         } else {
                   9112:             $versionresult = 'ok';
                   9113:         }
                   9114:         if ($versionresult eq 'ok') {
                   9115:             if (copy($source,$copyfile)) {
                   9116:                 print $logfile "\nCopied original source to ".$copyfile."\n";
                   9117:                 $output = 'ok';
                   9118:                 $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155     raeburn  9119:                 push(@{$modified_urls},[$copyfile,$source]);
                   9120:                 my $metaoutput = 
                   9121:                     &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
                   9122:                 unless ($registered_cleanup) {
                   9123:                     my $handlers = $r->get_handlers('PerlCleanupHandler');
                   9124:                     $r->set_handlers('PerlCleanupHandler' => [\&notifysubscribed,@{$handlers}]);
                   9125:                     $registered_cleanup=1;
                   9126:                 }
1.9       raeburn  9127:             } else {
                   9128:                 print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
                   9129:                 $output = &mt('Failed to copy file to RES space').", $!";
                   9130:             }
                   9131:             if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
                   9132:                 my $inputfile = $filepath.'/'.$file;
                   9133:                 my $outfile = $filepath.'/'.'tn-'.$file;
1.16      raeburn  9134:                 my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
                   9135:                 if ($fullwidth ne '' && $fullheight ne '') { 
                   9136:                     if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
                   9137:                         my $thumbsize = $thumbwidth.'x'.$thumbheight;
1.316   ! raeburn  9138:                         my @args = ('convert','-sample',$thumbsize,$inputfile,$outfile);
        !          9139:                         system({$args[0]} @args);
1.16      raeburn  9140:                         chmod(0660, $filepath.'/tn-'.$file);
                   9141:                         if (-e $outfile) {
                   9142:                             my $copyfile=$targetdir.'/tn-'.$file;
                   9143:                             if (copy($outfile,$copyfile)) {
                   9144:                                 print $logfile "\nCopied source to ".$copyfile."\n";
1.155     raeburn  9145:                                 my $thumb_metaoutput = 
                   9146:                                     &write_metadata($dom,$confname,$formname,
                   9147:                                                     $targetdir,'tn-'.$file,$logfile);
                   9148:                                 push(@{$modified_urls},[$copyfile,$outfile]);
                   9149:                                 unless ($registered_cleanup) {
                   9150:                                     my $handlers = $r->get_handlers('PerlCleanupHandler');
                   9151:                                     $r->set_handlers('PerlCleanupHandler' => [\&notifysubscribed,@{$handlers}]);
                   9152:                                     $registered_cleanup=1;
                   9153:                                 }
1.267     raeburn  9154:                                 $madethumb = 1;
1.16      raeburn  9155:                             } else {
                   9156:                                 print $logfile "\nUnable to write ".$copyfile.
                   9157:                                                ':'.$!."\n";
                   9158:                             }
                   9159:                         }
1.9       raeburn  9160:                     }
                   9161:                 }
                   9162:             }
                   9163:         } else {
                   9164:             $output = $versionresult;
                   9165:         }
                   9166:     }
1.267     raeburn  9167:     return ($output,$logourl,$madethumb);
1.9       raeburn  9168: }
                   9169: 
                   9170: sub logo_versioning {
                   9171:     my ($targetdir,$file,$logfile) = @_;
                   9172:     my $target = $targetdir.'/'.$file;
                   9173:     my ($maxversion,$fn,$extn,$output);
                   9174:     $maxversion = 0;
                   9175:     if ($file =~ /^(.+)\.(\w+)$/) {
                   9176:         $fn=$1;
                   9177:         $extn=$2;
                   9178:     }
                   9179:     opendir(DIR,$targetdir);
                   9180:     while (my $filename=readdir(DIR)) {
                   9181:         if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
                   9182:             $maxversion=($1>$maxversion)?$1:$maxversion;
                   9183:         }
                   9184:     }
                   9185:     $maxversion++;
                   9186:     print $logfile "\nCreating old version ".$maxversion."\n";
                   9187:     my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
                   9188:     if (copy($target,$copyfile)) {
                   9189:         print $logfile "Copied old target to ".$copyfile."\n";
                   9190:         $copyfile=$copyfile.'.meta';
                   9191:         if (copy($target.'.meta',$copyfile)) {
                   9192:             print $logfile "Copied old target metadata to ".$copyfile."\n";
                   9193:             $output = 'ok';
                   9194:         } else {
                   9195:             print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
                   9196:             $output = &mt('Failed to copy old meta').", $!, ";
                   9197:         }
                   9198:     } else {
                   9199:         print $logfile "Unable to write ".$copyfile.':'.$!."\n";
                   9200:         $output = &mt('Failed to copy old target').", $!, ";
                   9201:     }
                   9202:     return $output;
                   9203: }
                   9204: 
                   9205: sub write_metadata {
                   9206:     my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
                   9207:     my (%metadatafields,%metadatakeys,$output);
                   9208:     $metadatafields{'title'}=$formname;
                   9209:     $metadatafields{'creationdate'}=time;
                   9210:     $metadatafields{'lastrevisiondate'}=time;
                   9211:     $metadatafields{'copyright'}='public';
                   9212:     $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
                   9213:                                          $env{'user.domain'};
                   9214:     $metadatafields{'authorspace'}=$confname.':'.$dom;
                   9215:     $metadatafields{'domain'}=$dom;
                   9216:     {
                   9217:         print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
                   9218:         my $mfh;
1.316   ! raeburn  9219:         if (open($mfh,">",$targetdir.'/'.$file.'.meta')) {
1.184     raeburn  9220:             foreach (sort(keys(%metadatafields))) {
1.155     raeburn  9221:                 unless ($_=~/\./) {
                   9222:                     my $unikey=$_;
                   9223:                     $unikey=~/^([A-Za-z]+)/;
                   9224:                     my $tag=$1;
                   9225:                     $tag=~tr/A-Z/a-z/;
                   9226:                     print $mfh "\n\<$tag";
                   9227:                     foreach (split(/\,/,$metadatakeys{$unikey})) {
                   9228:                         my $value=$metadatafields{$unikey.'.'.$_};
                   9229:                         $value=~s/\"/\'\'/g;
                   9230:                         print $mfh ' '.$_.'="'.$value.'"';
                   9231:                     }
                   9232:                     print $mfh '>'.
                   9233:                         &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
                   9234:                             .'</'.$tag.'>';
                   9235:                 }
                   9236:             }
                   9237:             $output = 'ok';
                   9238:             print $logfile "\nWrote metadata";
                   9239:             close($mfh);
                   9240:         } else {
                   9241:             print $logfile "\nFailed to open metadata file";
1.9       raeburn  9242:             $output = &mt('Could not write metadata');
                   9243:         }
                   9244:     }
1.155     raeburn  9245:     return $output;
                   9246: }
                   9247: 
                   9248: sub notifysubscribed {
                   9249:     foreach my $targetsource (@{$modified_urls}){
                   9250:         next unless (ref($targetsource) eq 'ARRAY');
                   9251:         my ($target,$source)=@{$targetsource};
                   9252:         if ($source ne '') {
1.316   ! raeburn  9253:             if (open(my $logfh,">>",$source.'.log')) {
1.155     raeburn  9254:                 print $logfh "\nCleanup phase: Notifications\n";
                   9255:                 my @subscribed=&subscribed_hosts($target);
                   9256:                 foreach my $subhost (@subscribed) {
                   9257:                     print $logfh "\nNotifying host ".$subhost.':';
                   9258:                     my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
                   9259:                     print $logfh $reply;
                   9260:                 }
                   9261:                 my @subscribedmeta=&subscribed_hosts("$target.meta");
                   9262:                 foreach my $subhost (@subscribedmeta) {
                   9263:                     print $logfh "\nNotifying host for metadata only ".$subhost.':';
                   9264:                     my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
                   9265:                                                         $subhost);
                   9266:                     print $logfh $reply;
                   9267:                 }
                   9268:                 print $logfh "\n============ Done ============\n";
1.160     raeburn  9269:                 close($logfh);
1.155     raeburn  9270:             }
                   9271:         }
                   9272:     }
                   9273:     return OK;
                   9274: }
                   9275: 
                   9276: sub subscribed_hosts {
                   9277:     my ($target) = @_;
                   9278:     my @subscribed;
1.316   ! raeburn  9279:     if (open(my $fh,"<","$target.subscription")) {
1.155     raeburn  9280:         while (my $subline=<$fh>) {
                   9281:             if ($subline =~ /^($match_lonid):/) {
                   9282:                 my $host = $1;
                   9283:                 if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
                   9284:                     unless (grep(/^\Q$host\E$/,@subscribed)) {
                   9285:                         push(@subscribed,$host);
                   9286:                     }
                   9287:                 }
                   9288:             }
                   9289:         }
                   9290:     }
                   9291:     return @subscribed;
1.9       raeburn  9292: }
                   9293: 
                   9294: sub check_switchserver {
                   9295:     my ($dom,$confname) = @_;
                   9296:     my ($allowed,$switchserver);
                   9297:     my $home = &Apache::lonnet::homeserver($confname,$dom);
                   9298:     if ($home eq 'no_host') {
                   9299:         $home = &Apache::lonnet::domain($dom,'primary');
                   9300:     }
                   9301:     my @ids=&Apache::lonnet::current_machine_ids();
1.10      albertel 9302:     foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
                   9303:     if (!$allowed) {
1.180     raeburn  9304: 	$switchserver='<a href="/adm/switchserver?otherserver='.$home.'&amp;role=dc./'.$dom.'/&amp;destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9       raeburn  9305:     }
                   9306:     return $switchserver;
                   9307: }
                   9308: 
1.1       raeburn  9309: sub modify_quotas {
1.216     raeburn  9310:     my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101     raeburn  9311:     my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216     raeburn  9312:         %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.235     raeburn  9313:         $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
                   9314:         $validationfieldsref);
1.86      raeburn  9315:     if ($action eq 'quotas') {
                   9316:         $context = 'tools'; 
1.163     raeburn  9317:     } else {
1.86      raeburn  9318:         $context = $action;
                   9319:     }
                   9320:     if ($context eq 'requestcourses') {
1.271     raeburn  9321:         @usertools = ('official','unofficial','community','textbook','placement');
1.106     raeburn  9322:         @options =('norequest','approval','validate','autolimit');
1.101     raeburn  9323:         %validations = &Apache::lonnet::auto_courserequest_checks($dom);
                   9324:         %titles = &courserequest_titles();
                   9325:         $toolregexp = join('|',@usertools);
                   9326:         %conditions = &courserequest_conditions();
1.216     raeburn  9327:         $confname = $dom.'-domainconfig';
                   9328:         my $servadm = $r->dir_config('lonAdmEMail');
                   9329:         ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.235     raeburn  9330:         ($validationitemsref,$validationnamesref,$validationfieldsref) = 
                   9331:             &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.163     raeburn  9332:     } elsif ($context eq 'requestauthor') {
                   9333:         @usertools = ('author');
                   9334:         %titles = &authorrequest_titles();
1.86      raeburn  9335:     } else {
1.162     raeburn  9336:         @usertools = ('aboutme','blog','webdav','portfolio');
1.101     raeburn  9337:         %titles = &tool_titles();
1.86      raeburn  9338:     }
1.212     raeburn  9339:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44      raeburn  9340:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1       raeburn  9341:     foreach my $key (keys(%env)) {
1.101     raeburn  9342:         if ($context eq 'requestcourses') {
                   9343:             if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
                   9344:                 my $item = $1;
                   9345:                 my $type = $2;
                   9346:                 if ($type =~ /^limit_(.+)/) {
                   9347:                     $limithash{$item}{$1} = $env{$key};
                   9348:                 } else {
                   9349:                     $confhash{$item}{$type} = $env{$key};
                   9350:                 }
                   9351:             }
1.163     raeburn  9352:         } elsif ($context eq 'requestauthor') {
                   9353:             if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
                   9354:                 $confhash{$1} = $env{$key};
                   9355:             }
1.101     raeburn  9356:         } else {
1.86      raeburn  9357:             if ($key =~ /^form\.quota_(.+)$/) {
                   9358:                 $confhash{'defaultquota'}{$1} = $env{$key};
1.197     raeburn  9359:             } elsif ($key =~ /^form\.authorquota_(.+)$/) {
                   9360:                 $confhash{'authorquota'}{$1} = $env{$key};
                   9361:             } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101     raeburn  9362:                 @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
                   9363:             }
1.72      raeburn  9364:         }
                   9365:     }
1.163     raeburn  9366:     if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.224     raeburn  9367:         my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102     raeburn  9368:         @approvalnotify = sort(@approvalnotify);
                   9369:         $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.271     raeburn  9370:         my @crstypes = ('official','unofficial','community','textbook','placement');
1.218     raeburn  9371:         my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
                   9372:         foreach my $type (@hasuniquecode) {
                   9373:             if (grep(/^\Q$type\E$/,@crstypes)) {
                   9374:                 $confhash{'uniquecode'}{$type} = 1;
                   9375:             }
1.216     raeburn  9376:         }
1.242     raeburn  9377:         my (%newbook,%allpos);
1.216     raeburn  9378:         if ($context eq 'requestcourses') {
1.242     raeburn  9379:             foreach my $type ('textbooks','templates') {
                   9380:                 @{$allpos{$type}} = (); 
                   9381:                 my $invalid;
                   9382:                 if ($type eq 'textbooks') {
                   9383:                     $invalid = &mt('Invalid LON-CAPA course for textbook');
                   9384:                 } else {
                   9385:                     $invalid = &mt('Invalid LON-CAPA course for template');
                   9386:                 }
                   9387:                 if ($env{'form.'.$type.'_addbook'}) {
                   9388:                     if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
                   9389:                         ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
                   9390:                         if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
                   9391:                                                         $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
                   9392:                             $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
                   9393:                         } else {
                   9394:                             $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
                   9395:                             my $position = $env{'form.'.$type.'_addbook_pos'};
                   9396:                             $position =~ s/\D+//g;
                   9397:                             if ($position ne '') {
                   9398:                                 $allpos{$type}[$position] = $newbook{$type};
                   9399:                             }
1.216     raeburn  9400:                         }
1.242     raeburn  9401:                     } else {
                   9402:                         $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.216     raeburn  9403:                     }
                   9404:                 }
1.242     raeburn  9405:             } 
1.216     raeburn  9406:         }
1.102     raeburn  9407:         if (ref($domconfig{$action}) eq 'HASH') {
                   9408:             if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
                   9409:                 if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
                   9410:                     $changes{'notify'}{'approval'} = 1;
                   9411:                 }
                   9412:             } else {
1.144     raeburn  9413:                 if ($confhash{'notify'}{'approval'}) {
1.102     raeburn  9414:                     $changes{'notify'}{'approval'} = 1;
                   9415:                 }
                   9416:             }
1.218     raeburn  9417:             if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
                   9418:                 if (ref($confhash{'uniquecode'}) eq 'HASH') {
                   9419:                     foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
                   9420:                         unless ($confhash{'uniquecode'}{$crstype}) {
                   9421:                             $changes{'uniquecode'} = 1;
                   9422:                         }
                   9423:                     }
                   9424:                     unless ($changes{'uniquecode'}) {
                   9425:                         foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
                   9426:                             unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
                   9427:                                 $changes{'uniquecode'} = 1;
                   9428:                             }
                   9429:                         }
                   9430:                     }
                   9431:                } else {
                   9432:                    $changes{'uniquecode'} = 1;
                   9433:                }
                   9434:             } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
                   9435:                 $changes{'uniquecode'} = 1;
1.216     raeburn  9436:             }
                   9437:             if ($context eq 'requestcourses') {
1.242     raeburn  9438:                 foreach my $type ('textbooks','templates') {
                   9439:                     if (ref($domconfig{$action}{$type}) eq 'HASH') {
                   9440:                         my %deletions;
                   9441:                         my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
                   9442:                         if (@todelete) {
                   9443:                             map { $deletions{$_} = 1; } @todelete;
                   9444:                         }
                   9445:                         my %imgdeletions;
                   9446:                         my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
                   9447:                         if (@todeleteimages) {
                   9448:                             map { $imgdeletions{$_} = 1; } @todeleteimages;
                   9449:                         }
                   9450:                         my $maxnum = $env{'form.'.$type.'_maxnum'};
                   9451:                         for (my $i=0; $i<=$maxnum; $i++) {
                   9452:                             my $itemid = $env{'form.'.$type.'_id_'.$i};
                   9453:                             my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/); 
                   9454:                             if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
                   9455:                                 if ($deletions{$key}) {
                   9456:                                     if ($domconfig{$action}{$type}{$key}{'image'}) {
                   9457:                                         #FIXME need to obsolete item in RES space
                   9458:                                     }
                   9459:                                     next;
                   9460:                                 } else {
                   9461:                                     my $newpos = $env{'form.'.$itemid};
                   9462:                                     $newpos =~ s/\D+//g;
1.243     raeburn  9463:                                     foreach my $item ('subject','title','publisher','author') {
1.289     raeburn  9464:                                         next if ((($item eq 'author') || ($item eq 'publisher')) &&
1.243     raeburn  9465:                                                  ($type eq 'templates'));
1.242     raeburn  9466:                                         $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
                   9467:                                         if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
                   9468:                                             $changes{$type}{$key} = 1;
                   9469:                                         }
                   9470:                                     }
                   9471:                                     $allpos{$type}[$newpos] = $key;
                   9472:                                 }
                   9473:                                 if ($imgdeletions{$key}) {
                   9474:                                     $changes{$type}{$key} = 1;
1.216     raeburn  9475:                                     #FIXME need to obsolete item in RES space
1.242     raeburn  9476:                                 } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
                   9477:                                     my ($cdom,$cnum) = split(/_/,$key);
1.313     raeburn  9478:                                     if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
                   9479:                                         $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
                   9480:                                     } else {
                   9481:                                         my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
                   9482:                                                                                       $cdom,$cnum,$type,$configuserok,
                   9483:                                                                                       $switchserver,$author_ok);
                   9484:                                         if ($imgurl) {
                   9485:                                             $confhash{$type}{$key}{'image'} = $imgurl;
                   9486:                                             $changes{$type}{$key} = 1; 
                   9487:                                         }
                   9488:                                         if ($error) {
                   9489:                                             &Apache::lonnet::logthis($error);
                   9490:                                             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   9491:                                         }
                   9492:                                     }
1.242     raeburn  9493:                                 } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
                   9494:                                     $confhash{$type}{$key}{'image'} = 
                   9495:                                         $domconfig{$action}{$type}{$key}{'image'};
1.216     raeburn  9496:                                 }
                   9497:                             }
                   9498:                         }
                   9499:                     }
                   9500:                 }
                   9501:             }
1.102     raeburn  9502:         } else {
1.144     raeburn  9503:             if ($confhash{'notify'}{'approval'}) {
1.102     raeburn  9504:                 $changes{'notify'}{'approval'} = 1;
                   9505:             }
1.218     raeburn  9506:             if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216     raeburn  9507:                 $changes{'uniquecode'} = 1;
                   9508:             }
                   9509:         }
                   9510:         if ($context eq 'requestcourses') {
1.242     raeburn  9511:             foreach my $type ('textbooks','templates') {
                   9512:                 if ($newbook{$type}) {
                   9513:                     $changes{$type}{$newbook{$type}} = 1;
1.243     raeburn  9514:                     foreach my $item ('subject','title','publisher','author') {
                   9515:                         next if ((($item eq 'author') || ($item eq 'publisher')) &&
                   9516:                                  ($type eq 'template'));
1.242     raeburn  9517:                         $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
                   9518:                         if ($env{'form.'.$type.'_addbook_'.$item}) {
                   9519:                             $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
                   9520:                         }
                   9521:                     }
                   9522:                     if ($type eq 'textbooks') {
                   9523:                         if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
                   9524:                             my ($cdom,$cnum) = split(/_/,$newbook{$type});
1.313     raeburn  9525:                             if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
                   9526:                                 $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
                   9527:                             } else {
                   9528:                                 my ($imageurl,$error) =
                   9529:                                     &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
                   9530:                                                             $configuserok,$switchserver,$author_ok);
                   9531:                                 if ($imageurl) {
                   9532:                                     $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
                   9533:                                 }
                   9534:                                 if ($error) {
                   9535:                                     &Apache::lonnet::logthis($error);
                   9536:                                     $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   9537:                                 }
1.242     raeburn  9538:                             }
                   9539:                         }
1.216     raeburn  9540:                     }
                   9541:                 }
1.242     raeburn  9542:                 if (@{$allpos{$type}} > 0) {
                   9543:                     my $idx = 0;
                   9544:                     foreach my $item (@{$allpos{$type}}) {
                   9545:                         if ($item ne '') {
                   9546:                             $confhash{$type}{$item}{'order'} = $idx;
                   9547:                             if (ref($domconfig{$action}) eq 'HASH') {
                   9548:                                 if (ref($domconfig{$action}{$type}) eq 'HASH') {
                   9549:                                     if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
                   9550:                                         if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
                   9551:                                             $changes{$type}{$item} = 1;
                   9552:                                         }
1.216     raeburn  9553:                                     }
                   9554:                                 }
                   9555:                             }
1.242     raeburn  9556:                             $idx ++;
1.216     raeburn  9557:                         }
                   9558:                     }
                   9559:                 }
                   9560:             }
1.235     raeburn  9561:             if (ref($validationitemsref) eq 'ARRAY') {
                   9562:                 foreach my $item (@{$validationitemsref}) {
                   9563:                     if ($item eq 'fields') {
                   9564:                         my @changed;
                   9565:                         @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
                   9566:                         if (@{$confhash{'validation'}{$item}} > 0) {
                   9567:                             @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
                   9568:                         }
1.266     raeburn  9569:                         if (ref($domconfig{'requestcourses'}) eq 'HASH') {
                   9570:                             if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
                   9571:                                 if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
                   9572:                                     @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
                   9573:                                                                                   $domconfig{'requestcourses'}{'validation'}{$item});
                   9574:                                 } else {
                   9575:                                     @changed = @{$confhash{'validation'}{$item}};
                   9576:                                 }
1.235     raeburn  9577:                             } else {
                   9578:                                 @changed = @{$confhash{'validation'}{$item}};
                   9579:                             }
                   9580:                         } else {
                   9581:                             @changed = @{$confhash{'validation'}{$item}};
                   9582:                         }
                   9583:                         if (@changed) {
                   9584:                             if ($confhash{'validation'}{$item}) {
                   9585:                                 $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
                   9586:                             } else {
                   9587:                                 $changes{'validation'}{$item} = &mt('None');
                   9588:                             }
                   9589:                         }
                   9590:                     } else {
                   9591:                         $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
                   9592:                         if ($item eq 'markup') {
                   9593:                             if ($env{'form.requestcourses_validation_'.$item}) {
                   9594:                                 $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
                   9595:                             }
                   9596:                         }
1.266     raeburn  9597:                         if (ref($domconfig{'requestcourses'}) eq 'HASH') {
                   9598:                             if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
                   9599:                                 if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
                   9600:                                     $changes{'validation'}{$item} = $confhash{'validation'}{$item};
                   9601:                                 }
                   9602:                             } else {
                   9603:                                 if ($confhash{'validation'}{$item} ne '') {
                   9604:                                     $changes{'validation'}{$item} = $confhash{'validation'}{$item};
                   9605:                                 }
1.235     raeburn  9606:                             }
                   9607:                         } else {
                   9608:                             if ($confhash{'validation'}{$item} ne '') {
                   9609:                                 $changes{'validation'}{$item} = $confhash{'validation'}{$item};
                   9610:                             }
                   9611:                         }
                   9612:                     }
                   9613:                 }
                   9614:             }
                   9615:             if ($env{'form.validationdc'}) {
                   9616:                 my $newval = $env{'form.validationdc'};
1.285     raeburn  9617:                 my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.235     raeburn  9618:                 if (exists($domcoords{$newval})) {
                   9619:                     $confhash{'validation'}{'dc'} = $newval;
                   9620:                 }
                   9621:             }
                   9622:             if (ref($confhash{'validation'}) eq 'HASH') {
1.266     raeburn  9623:                 if (ref($domconfig{'requestcourses'}) eq 'HASH') {
                   9624:                     if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
                   9625:                         if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
                   9626:                             unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
                   9627:                                 if ($confhash{'validation'}{'dc'} eq '') {
                   9628:                                     $changes{'validation'}{'dc'} = &mt('None');
                   9629:                                 } else {
                   9630:                                     $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
                   9631:                                 }
1.235     raeburn  9632:                             }
1.266     raeburn  9633:                         } elsif ($confhash{'validation'}{'dc'} ne '') {
                   9634:                             $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.235     raeburn  9635:                         }
                   9636:                     } elsif ($confhash{'validation'}{'dc'} ne '') {
                   9637:                         $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
                   9638:                     }
                   9639:                 } elsif ($confhash{'validation'}{'dc'} ne '') {
                   9640:                     $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.289     raeburn  9641:                 }
1.266     raeburn  9642:             } else {
                   9643:                 if (ref($domconfig{'requestcourses'}) eq 'HASH') {
                   9644:                     if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
                   9645:                         if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
                   9646:                             $changes{'validation'}{'dc'} = &mt('None');
                   9647:                         }
                   9648:                     }
1.235     raeburn  9649:                 }
                   9650:             }
1.102     raeburn  9651:         }
                   9652:     } else {
1.86      raeburn  9653:         $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.197     raeburn  9654:         $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86      raeburn  9655:     }
1.72      raeburn  9656:     foreach my $item (@usertools) {
                   9657:         foreach my $type (@{$types},'default','_LC_adv') {
1.104     raeburn  9658:             my $unset; 
1.101     raeburn  9659:             if ($context eq 'requestcourses') {
1.104     raeburn  9660:                 $unset = '0';
                   9661:                 if ($type eq '_LC_adv') {
                   9662:                     $unset = '';
                   9663:                 }
1.101     raeburn  9664:                 if ($confhash{$item}{$type} eq 'autolimit') {
                   9665:                     $confhash{$item}{$type} .= '=';
                   9666:                     unless ($limithash{$item}{$type} =~ /\D/) {
                   9667:                         $confhash{$item}{$type} .= $limithash{$item}{$type};
                   9668:                     }
                   9669:                 }
1.163     raeburn  9670:             } elsif ($context eq 'requestauthor') {
                   9671:                 $unset = '0';
                   9672:                 if ($type eq '_LC_adv') {
                   9673:                     $unset = '';
                   9674:                 }
1.72      raeburn  9675:             } else {
1.101     raeburn  9676:                 if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
                   9677:                     $confhash{$item}{$type} = 1;
                   9678:                 } else {
                   9679:                     $confhash{$item}{$type} = 0;
                   9680:                 }
1.72      raeburn  9681:             }
1.86      raeburn  9682:             if (ref($domconfig{$action}) eq 'HASH') {
1.163     raeburn  9683:                 if ($action eq 'requestauthor') {
                   9684:                     if ($domconfig{$action}{$type} ne $confhash{$type}) {
                   9685:                         $changes{$type} = 1;
                   9686:                     }
                   9687:                 } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86      raeburn  9688:                     if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
                   9689:                         $changes{$item}{$type} = 1;
                   9690:                     }
                   9691:                 } else {
                   9692:                     if ($context eq 'requestcourses') {
1.104     raeburn  9693:                         if ($confhash{$item}{$type} ne $unset) {
1.86      raeburn  9694:                             $changes{$item}{$type} = 1;
                   9695:                         }
                   9696:                     } else {
                   9697:                         if (!$confhash{$item}{$type}) {
                   9698:                             $changes{$item}{$type} = 1;
                   9699:                         }
                   9700:                     }
                   9701:                 }
                   9702:             } else {
                   9703:                 if ($context eq 'requestcourses') {
1.104     raeburn  9704:                     if ($confhash{$item}{$type} ne $unset) {
1.72      raeburn  9705:                         $changes{$item}{$type} = 1;
                   9706:                     }
1.163     raeburn  9707:                 } elsif ($context eq 'requestauthor') {
                   9708:                     if ($confhash{$type} ne $unset) {
                   9709:                         $changes{$type} = 1;
                   9710:                     }
1.72      raeburn  9711:                 } else {
                   9712:                     if (!$confhash{$item}{$type}) {
                   9713:                         $changes{$item}{$type} = 1;
                   9714:                     }
                   9715:                 }
                   9716:             }
1.1       raeburn  9717:         }
                   9718:     }
1.163     raeburn  9719:     unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86      raeburn  9720:         if (ref($domconfig{'quotas'}) eq 'HASH') {
                   9721:             if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
                   9722:                 foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
                   9723:                     if (exists($confhash{'defaultquota'}{$key})) {
                   9724:                         if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
                   9725:                             $changes{'defaultquota'}{$key} = 1;
                   9726:                         }
                   9727:                     } else {
                   9728:                         $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72      raeburn  9729:                     }
                   9730:                 }
1.86      raeburn  9731:             } else {
                   9732:                 foreach my $key (keys(%{$domconfig{'quotas'}})) {
                   9733:                     if (exists($confhash{'defaultquota'}{$key})) {
                   9734:                         if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
                   9735:                             $changes{'defaultquota'}{$key} = 1;
                   9736:                         }
                   9737:                     } else {
                   9738:                         $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72      raeburn  9739:                     }
1.1       raeburn  9740:                 }
                   9741:             }
1.197     raeburn  9742:             if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
                   9743:                 foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
                   9744:                     if (exists($confhash{'authorquota'}{$key})) {
                   9745:                         if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
                   9746:                             $changes{'authorquota'}{$key} = 1;
                   9747:                         }
                   9748:                     } else {
                   9749:                         $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
                   9750:                     }
                   9751:                 }
                   9752:             }
1.1       raeburn  9753:         }
1.86      raeburn  9754:         if (ref($confhash{'defaultquota'}) eq 'HASH') {
                   9755:             foreach my $key (keys(%{$confhash{'defaultquota'}})) {
                   9756:                 if (ref($domconfig{'quotas'}) eq 'HASH') {
                   9757:                     if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
                   9758:                         if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
                   9759:                             $changes{'defaultquota'}{$key} = 1;
                   9760:                         }
                   9761:                     } else {
                   9762:                         if (!exists($domconfig{'quotas'}{$key})) {
                   9763:                             $changes{'defaultquota'}{$key} = 1;
                   9764:                         }
1.72      raeburn  9765:                     }
                   9766:                 } else {
1.86      raeburn  9767:                     $changes{'defaultquota'}{$key} = 1;
1.55      raeburn  9768:                 }
1.1       raeburn  9769:             }
                   9770:         }
1.197     raeburn  9771:         if (ref($confhash{'authorquota'}) eq 'HASH') {
                   9772:             foreach my $key (keys(%{$confhash{'authorquota'}})) {
                   9773:                 if (ref($domconfig{'quotas'}) eq 'HASH') {
                   9774:                     if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
                   9775:                         if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
                   9776:                             $changes{'authorquota'}{$key} = 1;
                   9777:                         }
                   9778:                     } else {
                   9779:                         $changes{'authorquota'}{$key} = 1;
                   9780:                     }
                   9781:                 } else {
                   9782:                     $changes{'authorquota'}{$key} = 1;
                   9783:                 }
                   9784:             }
                   9785:         }
1.1       raeburn  9786:     }
1.72      raeburn  9787: 
1.163     raeburn  9788:     if ($context eq 'requestauthor') {
                   9789:         $domdefaults{'requestauthor'} = \%confhash;
                   9790:     } else {
                   9791:         foreach my $key (keys(%confhash)) {
1.242     raeburn  9792:             unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.216     raeburn  9793:                 $domdefaults{$key} = $confhash{$key};
                   9794:             }
1.163     raeburn  9795:         }
1.72      raeburn  9796:     }
1.163     raeburn  9797: 
1.1       raeburn  9798:     my %quotahash = (
1.86      raeburn  9799:                       $action => { %confhash }
1.1       raeburn  9800:                     );
                   9801:     my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
                   9802:                                              $dom);
                   9803:     if ($putresult eq 'ok') {
                   9804:         if (keys(%changes) > 0) {
1.72      raeburn  9805:             my $cachetime = 24*60*60;
                   9806:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212     raeburn  9807:             if (ref($lastactref) eq 'HASH') {
                   9808:                 $lastactref->{'domdefaults'} = 1;
                   9809:             }
1.1       raeburn  9810:             $resulttext = &mt('Changes made:').'<ul>';
1.210     raeburn  9811:             unless (($context eq 'requestcourses') ||
1.163     raeburn  9812:                     ($context eq 'requestauthor')) {
1.86      raeburn  9813:                 if (ref($changes{'defaultquota'}) eq 'HASH') {
                   9814:                     $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
                   9815:                     foreach my $type (@{$types},'default') {
                   9816:                         if (defined($changes{'defaultquota'}{$type})) {
                   9817:                             my $typetitle = $usertypes->{$type};
                   9818:                             if ($type eq 'default') {
                   9819:                                 $typetitle = $othertitle;
                   9820:                             }
1.213     raeburn  9821:                             $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72      raeburn  9822:                         }
                   9823:                     }
1.86      raeburn  9824:                     $resulttext .= '</ul></li>';
1.72      raeburn  9825:                 }
1.197     raeburn  9826:                 if (ref($changes{'authorquota'}) eq 'HASH') {
1.223     bisitz   9827:                     $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.197     raeburn  9828:                     foreach my $type (@{$types},'default') {
                   9829:                         if (defined($changes{'authorquota'}{$type})) {
                   9830:                             my $typetitle = $usertypes->{$type};
                   9831:                             if ($type eq 'default') {
                   9832:                                 $typetitle = $othertitle;
                   9833:                             }
1.213     raeburn  9834:                             $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.197     raeburn  9835:                         }
                   9836:                     }
                   9837:                     $resulttext .= '</ul></li>';
                   9838:                 }
1.72      raeburn  9839:             }
1.80      raeburn  9840:             my %newenv;
1.72      raeburn  9841:             foreach my $item (@usertools) {
1.163     raeburn  9842:                 my (%haschgs,%inconf);
                   9843:                 if ($context eq 'requestauthor') {
                   9844:                     %haschgs = %changes;
1.210     raeburn  9845:                     %inconf = %confhash;
1.163     raeburn  9846:                 } else {
                   9847:                     if (ref($changes{$item}) eq 'HASH') {
                   9848:                         %haschgs = %{$changes{$item}};
                   9849:                     }
                   9850:                     if (ref($confhash{$item}) eq 'HASH') {
                   9851:                         %inconf = %{$confhash{$item}};
                   9852:                     }
                   9853:                 }
                   9854:                 if (keys(%haschgs) > 0) {
1.80      raeburn  9855:                     my $newacc = 
                   9856:                         &Apache::lonnet::usertools_access($env{'user.name'},
                   9857:                                                           $env{'user.domain'},
1.86      raeburn  9858:                                                           $item,'reload',$context);
1.210     raeburn  9859:                     if (($context eq 'requestcourses') ||
1.163     raeburn  9860:                         ($context eq 'requestauthor')) {
1.108     raeburn  9861:                         if ($env{'environment.canrequest.'.$item} ne $newacc) {
                   9862:                             $newenv{'environment.canrequest.'.$item} = $newacc;
1.86      raeburn  9863:                         }
                   9864:                     } else {
                   9865:                         if ($env{'environment.availabletools.'.$item} ne $newacc) { 
                   9866:                             $newenv{'environment.availabletools.'.$item} = $newacc;
                   9867:                         }
1.80      raeburn  9868:                     }
1.163     raeburn  9869:                     unless ($context eq 'requestauthor') {
                   9870:                         $resulttext .= '<li>'.$titles{$item}.'<ul>';
                   9871:                     }
1.72      raeburn  9872:                     foreach my $type (@{$types},'default','_LC_adv') {
1.163     raeburn  9873:                         if ($haschgs{$type}) {
1.72      raeburn  9874:                             my $typetitle = $usertypes->{$type};
                   9875:                             if ($type eq 'default') {
                   9876:                                 $typetitle = $othertitle;
                   9877:                             } elsif ($type eq '_LC_adv') {
                   9878:                                 $typetitle = 'LON-CAPA Advanced Users'; 
                   9879:                             }
1.163     raeburn  9880:                             if ($inconf{$type}) {
1.101     raeburn  9881:                                 if ($context eq 'requestcourses') {
                   9882:                                     my $cond;
1.163     raeburn  9883:                                     if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101     raeburn  9884:                                         if ($1 eq '') {
                   9885:                                             $cond = &mt('(Automatic processing of any request).');
                   9886:                                         } else {
                   9887:                                             $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
                   9888:                                         }
                   9889:                                     } else { 
1.163     raeburn  9890:                                         $cond = $conditions{$inconf{$type}};
1.101     raeburn  9891:                                     }
                   9892:                                     $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172     raeburn  9893:                                 } elsif ($context eq 'requestauthor') {
                   9894:                                     $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
                   9895:                                                              $titles{$inconf{$type}},$typetitle);
                   9896: 
1.101     raeburn  9897:                                 } else {
                   9898:                                     $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
                   9899:                                 }
1.72      raeburn  9900:                             } else {
1.104     raeburn  9901:                                 if ($type eq '_LC_adv') {
1.163     raeburn  9902:                                     if ($inconf{$type} eq '0') {
1.104     raeburn  9903:                                         $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
                   9904:                                     } else { 
                   9905:                                         $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
                   9906:                                     }
                   9907:                                 } else {
                   9908:                                     $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
                   9909:                                 }
1.72      raeburn  9910:                             }
                   9911:                         }
1.26      raeburn  9912:                     }
1.163     raeburn  9913:                     unless ($context eq 'requestauthor') {
                   9914:                         $resulttext .= '</ul></li>';
                   9915:                     }
1.26      raeburn  9916:                 }
1.1       raeburn  9917:             }
1.163     raeburn  9918:             if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102     raeburn  9919:                 if (ref($changes{'notify'}) eq 'HASH') {
                   9920:                     if ($changes{'notify'}{'approval'}) {
                   9921:                         if (ref($confhash{'notify'}) eq 'HASH') {
                   9922:                             if ($confhash{'notify'}{'approval'}) {
                   9923:                                 $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
                   9924:                             } else {
1.163     raeburn  9925:                                 $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102     raeburn  9926:                             }
                   9927:                         }
                   9928:                     }
                   9929:                 }
                   9930:             }
1.216     raeburn  9931:             if ($action eq 'requestcourses') {
                   9932:                 my @offon = ('off','on');
                   9933:                 if ($changes{'uniquecode'}) {
1.218     raeburn  9934:                     if (ref($confhash{'uniquecode'}) eq 'HASH') {
                   9935:                         my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
                   9936:                         $resulttext .= '<li>'.
                   9937:                                        &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
                   9938:                                        '</li>';
                   9939:                     } else {
                   9940:                         $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
                   9941:                                        '</li>';
                   9942:                     }
1.216     raeburn  9943:                 }
1.242     raeburn  9944:                 foreach my $type ('textbooks','templates') {
                   9945:                     if (ref($changes{$type}) eq 'HASH') {
                   9946:                         $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
                   9947:                         foreach my $key (sort(keys(%{$changes{$type}}))) {
                   9948:                             my %coursehash = &Apache::lonnet::coursedescription($key);
                   9949:                             my $coursetitle = $coursehash{'description'};
                   9950:                             my $position = $confhash{$type}{$key}{'order'} + 1;
                   9951:                             $resulttext .= '<li>';
1.243     raeburn  9952:                             foreach my $item ('subject','title','publisher','author') {
                   9953:                                 next if ((($item eq 'author') || ($item eq 'publisher')) &&
                   9954:                                          ($type eq 'templates'));
1.242     raeburn  9955:                                 my $name = $item.':';
                   9956:                                 $name =~ s/^(\w)/\U$1/;
                   9957:                                 $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
                   9958:                             }
                   9959:                             $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
                   9960:                             if ($type eq 'textbooks') {
                   9961:                                 if ($confhash{$type}{$key}{'image'}) {
                   9962:                                     $resulttext .= ' '.&mt('Image: [_1]',
                   9963:                                                    '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
                   9964:                                                    ' alt="Textbook cover" />').'<br />';
                   9965:                                 }
                   9966:                             }
                   9967:                             $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.216     raeburn  9968:                         }
1.242     raeburn  9969:                         $resulttext .= '</ul></li>';
1.216     raeburn  9970:                     }
                   9971:                 }
1.235     raeburn  9972:                 if (ref($changes{'validation'}) eq 'HASH') {
                   9973:                     if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
                   9974:                         $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
                   9975:                         foreach my $item (@{$validationitemsref}) {
                   9976:                             if (exists($changes{'validation'}{$item})) {
                   9977:                                 if ($item eq 'markup') {
                   9978:                                     $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
                   9979:                                                               '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
                   9980:                                 } else {
                   9981:                                     $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
                   9982:                                                               '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
                   9983:                                 }
                   9984:                             }
                   9985:                         }
                   9986:                         if (exists($changes{'validation'}{'dc'})) {
                   9987:                             $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
                   9988:                                                      '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
                   9989:                         }
                   9990:                     }
                   9991:                 }
1.216     raeburn  9992:             }
1.1       raeburn  9993:             $resulttext .= '</ul>';
1.80      raeburn  9994:             if (keys(%newenv)) {
                   9995:                 &Apache::lonnet::appenv(\%newenv);
                   9996:             }
1.1       raeburn  9997:         } else {
1.86      raeburn  9998:             if ($context eq 'requestcourses') {
                   9999:                 $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163     raeburn  10000:             } elsif ($context eq 'requestauthor') {
                   10001:                 $resulttext = &mt('No changes made to rights to request author space.');
1.86      raeburn  10002:             } else {
1.90      weissno  10003:                 $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86      raeburn  10004:             }
1.1       raeburn  10005:         }
                   10006:     } else {
1.11      albertel 10007:         $resulttext = '<span class="LC_error">'.
                   10008: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  10009:     }
1.216     raeburn  10010:     if ($errors) {
                   10011:         $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
                   10012:                        '<ul>'.$errors.'</ul></p>';
                   10013:     }
1.3       raeburn  10014:     return $resulttext;
1.1       raeburn  10015: }
                   10016: 
1.216     raeburn  10017: sub process_textbook_image {
1.242     raeburn  10018:     my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.216     raeburn  10019:     my $filename = $env{'form.'.$caller.'.filename'};
                   10020:     my ($error,$url);
                   10021:     my ($width,$height) = (50,50);
                   10022:     if ($configuserok eq 'ok') {
                   10023:         if ($switchserver) {
                   10024:             $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
                   10025:                          $switchserver);
                   10026:         } elsif ($author_ok eq 'ok') {
                   10027:             my ($result,$imageurl) =
                   10028:                 &publishlogo($r,'upload',$caller,$dom,$confname,
1.312     raeburn  10029:                              "$type/$cdom/$cnum/cover",$width,$height);
1.216     raeburn  10030:             if ($result eq 'ok') {
                   10031:                 $url = $imageurl;
                   10032:             } else {
                   10033:                 $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
                   10034:             }
                   10035:         } else {
                   10036:             $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);
                   10037:         }
                   10038:     } else {
                   10039:         $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);
                   10040:     }
                   10041:     return ($url,$error);
                   10042: }
                   10043: 
1.267     raeburn  10044: sub modify_ltitools {
                   10045:     my ($r,$dom,$action,$lastactref,%domconfig) = @_;
                   10046:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.297     raeburn  10047:     my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
1.267     raeburn  10048:     my $confname = $dom.'-domainconfig';
                   10049:     my $servadm = $r->dir_config('lonAdmEMail');
                   10050:     my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
                   10051:     my (%posslti,%possfield);
                   10052:     my @courseroles = ('cc','in','ta','ep','st');
                   10053:     my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
                   10054:     map { $posslti{$_} = 1; } @ltiroles;
                   10055:     my @allfields = ('fullname','firstname','lastname','email','user','roles');
                   10056:     map { $possfield{$_} = 1; } @allfields;
                   10057:     my %lt = &ltitools_names(); 
                   10058:     if ($env{'form.ltitools_add'}) {
                   10059:         my $title = $env{'form.ltitools_add_title'};
                   10060:         $title =~ s/(`)/'/g;
                   10061:         ($newid,my $error) = &get_ltitools_id($dom,$title);
                   10062:         if ($newid) {
                   10063:             my $position = $env{'form.ltitools_add_pos'};
                   10064:             $position =~ s/\D+//g;
                   10065:             if ($position ne '') {
                   10066:                 $allpos[$position] = $newid;
                   10067:             }
                   10068:             $changes{$newid} = 1;
                   10069:             foreach my $item ('title','url','key','secret') {
                   10070:                 $env{'form.ltitools_add_'.$item} =~ s/(`)/'/g;
                   10071:                 if ($env{'form.ltitools_add_'.$item}) {
1.297     raeburn  10072:                     if (($item eq 'key') || ($item eq 'secret')) {
                   10073:                         $encconfig{$newid}{$item} = $env{'form.ltitools_add_'.$item};
                   10074:                     } else {
                   10075:                         $confhash{$newid}{$item} = $env{'form.ltitools_add_'.$item};
                   10076:                     }
1.267     raeburn  10077:                 }
                   10078:             }
                   10079:             if ($env{'form.ltitools_add_version'} eq 'LTI-1p0') {
                   10080:                 $confhash{$newid}{'version'} = $env{'form.ltitools_add_version'};
                   10081:             }
                   10082:             if ($env{'form.ltitools_add_msgtype'} eq 'basic-lti-launch-request') {
                   10083:                 $confhash{$newid}{'msgtype'} = $env{'form.ltitools_add_msgtype'};
                   10084:             }
1.296     raeburn  10085:             foreach my $item ('width','height','linktext','explanation') {
1.267     raeburn  10086:                 $env{'form.ltitools_add_'.$item} =~ s/^\s+//;
                   10087:                 $env{'form.ltitools_add_'.$item} =~ s/\s+$//;
1.296     raeburn  10088:                 if (($item eq 'width') || ($item eq 'height')) {
                   10089:                     if ($env{'form.ltitools_add_'.$item} =~ /^\d+$/) {
                   10090:                         $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
                   10091:                     }
                   10092:                 } else {
                   10093:                     if ($env{'form.ltitools_add_'.$item} ne '') {
                   10094:                         $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item}; 
                   10095:                     }
1.267     raeburn  10096:                 }
                   10097:             }
                   10098:             if ($env{'form.ltitools_add_target'} eq 'window') {
                   10099:                 $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1.298     raeburn  10100:             } elsif ($env{'form.ltitools_add_target'} eq 'tab') {
                   10101:                 $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1.267     raeburn  10102:             } else {
                   10103:                 $confhash{$newid}{'display'}{'target'} = 'iframe';
                   10104:             }
                   10105:             foreach my $item ('passback','roster') {
                   10106:                 if ($env{'form.ltitools_add_'.$item}) {
                   10107:                     $confhash{$newid}{$item} = 1;
                   10108:                 }
                   10109:             }
                   10110:             if ($env{'form.ltitools_add_image.filename'} ne '') {
                   10111:                 my ($imageurl,$error) =
1.307     raeburn  10112:                     &process_ltitools_image($r,$dom,$confname,'ltitools_add_image',$newid,
1.267     raeburn  10113:                                             $configuserok,$switchserver,$author_ok);
                   10114:                 if ($imageurl) {
                   10115:                     $confhash{$newid}{'image'} = $imageurl;
                   10116:                 }
                   10117:                 if ($error) {
                   10118:                     &Apache::lonnet::logthis($error);
                   10119:                     $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   10120:                 }
                   10121:             }
                   10122:             my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_add_fields');
                   10123:             foreach my $field (@fields) {
                   10124:                 if ($possfield{$field}) {
                   10125:                     if ($field eq 'roles') {
                   10126:                         foreach my $role (@courseroles) {
                   10127:                             my $choice = $env{'form.ltitools_add_roles_'.$role};
                   10128:                             if (($choice ne '') && ($posslti{$choice})) {
                   10129:                                 $confhash{$newid}{'roles'}{$role} = $choice;
                   10130:                                 if ($role eq 'cc') {
                   10131:                                     $confhash{$newid}{'roles'}{'co'} = $choice; 
                   10132:                                 }
                   10133:                             }
                   10134:                         }
                   10135:                     } else {
                   10136:                         $confhash{$newid}{'fields'}{$field} = 1;
                   10137:                     }
                   10138:                 }
                   10139:             }
1.273     raeburn  10140:             my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig');
                   10141:             foreach my $item (@courseconfig) {
                   10142:                 $confhash{$newid}{'crsconf'}{$item} = 1;
                   10143:             }
1.267     raeburn  10144:             if ($env{'form.ltitools_add_custom'}) {
                   10145:                 my $name = $env{'form.ltitools_add_custom_name'};
                   10146:                 my $value = $env{'form.ltitools_add_custom_value'};
                   10147:                 $value =~ s/(`)/'/g;
                   10148:                 $name =~ s/(`)/'/g;
                   10149:                 $confhash{$newid}{'custom'}{$name} = $value;
                   10150:             }
                   10151:         } else {
                   10152:             my $error = &mt('Failed to acquire unique ID for new external tool');   
                   10153:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   10154:         }
                   10155:     }
                   10156:     if (ref($domconfig{$action}) eq 'HASH') {
                   10157:         my %deletions;
                   10158:         my @todelete = &Apache::loncommon::get_env_multiple('form.ltitools_del');
                   10159:         if (@todelete) {
                   10160:             map { $deletions{$_} = 1; } @todelete;
                   10161:         }
                   10162:         my %customadds;
                   10163:         my @newcustom = &Apache::loncommon::get_env_multiple('form.ltitools_customadd');
                   10164:         if (@newcustom) {
                   10165:             map { $customadds{$_} = 1; } @newcustom;
                   10166:         } 
                   10167:         my %imgdeletions;
                   10168:         my @todeleteimages = &Apache::loncommon::get_env_multiple('form.ltitools_image_del');
                   10169:         if (@todeleteimages) {
                   10170:             map { $imgdeletions{$_} = 1; } @todeleteimages;
                   10171:         }
                   10172:         my $maxnum = $env{'form.ltitools_maxnum'};
                   10173:         for (my $i=0; $i<=$maxnum; $i++) {
                   10174:             my $itemid = $env{'form.ltitools_id_'.$i};
1.308     raeburn  10175:             $itemid =~ s/\D+//g;
1.267     raeburn  10176:             if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
                   10177:                 if ($deletions{$itemid}) {
                   10178:                     if ($domconfig{$action}{$itemid}{'image'}) {
                   10179:                         #FIXME need to obsolete item in RES space
                   10180:                     }
                   10181:                     $changes{$itemid} = $domconfig{$action}{$itemid}{'title'};
                   10182:                     next;
                   10183:                 } else {
                   10184:                     my $newpos = $env{'form.ltitools_'.$itemid};
                   10185:                     $newpos =~ s/\D+//g;
1.297     raeburn  10186:                     foreach my $item ('title','url') {
1.267     raeburn  10187:                         $confhash{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
                   10188:                         if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
                   10189:                             $changes{$itemid} = 1;
                   10190:                         }
                   10191:                     }
1.297     raeburn  10192:                     foreach my $item ('key','secret') {
                   10193:                         $encconfig{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
                   10194:                         if ($domconfig{$action}{$itemid}{$item} ne $encconfig{$itemid}{$item}) {
                   10195:                             $changes{$itemid} = 1;
                   10196:                         }
                   10197:                     }
1.267     raeburn  10198:                     if ($env{'form.ltitools_version_'.$i} eq 'LTI-1p0') {
                   10199:                         $confhash{$itemid}{'version'} = $env{'form.ltitools_version_'.$i};
                   10200:                     }
                   10201:                     if ($env{'form.ltitools_msgtype_'.$i} eq 'basic-lti-launch-request') {
                   10202:                         $confhash{$itemid}{'msgtype'} = $env{'form.ltitools_msgtype_'.$i};
                   10203:                     }
                   10204:                     foreach my $size ('width','height') {
                   10205:                         $env{'form.ltitools_'.$size.'_'.$i} =~ s/^\s+//;
                   10206:                         $env{'form.ltitools_'.$size.'_'.$i} =~ s/\s+$//;
                   10207:                         if ($env{'form.ltitools_'.$size.'_'.$i} =~ /^\d+$/) {
                   10208:                             $confhash{$itemid}{'display'}{$size} = $env{'form.ltitools_'.$size.'_'.$i};
                   10209:                             if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
                   10210:                                 if ($domconfig{$action}{$itemid}{'display'}{$size} ne $confhash{$itemid}{'display'}{$size}) {
                   10211:                                     $changes{$itemid} = 1;
                   10212:                                 }
                   10213:                             } else {
                   10214:                                 $changes{$itemid} = 1;
                   10215:                             }
1.296     raeburn  10216:                         } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
                   10217:                             if ($domconfig{$action}{$itemid}{'display'}{$size} ne '') {
                   10218:                                 $changes{$itemid} = 1;
                   10219:                             }
                   10220:                         }
                   10221:                     }
                   10222:                     foreach my $item ('linktext','explanation') {
                   10223:                         $env{'form.ltitools_'.$item.'_'.$i} =~ s/^\s+//;
                   10224:                         $env{'form.ltitools_'.$item.'_'.$i} =~ s/\s+$//;
                   10225:                         if ($env{'form.ltitools_'.$item.'_'.$i} ne '') {
                   10226:                             $confhash{$itemid}{'display'}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
                   10227:                             if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
                   10228:                                 if ($domconfig{$action}{$itemid}{'display'}{$item} ne $confhash{$itemid}{'display'}{$item}) {
                   10229:                                     $changes{$itemid} = 1;
                   10230:                                 }
                   10231:                             } else {
                   10232:                                 $changes{$itemid} = 1;
                   10233:                             }
                   10234:                         } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
                   10235:                             if ($domconfig{$action}{$itemid}{'display'}{$item} ne '') {
                   10236:                                 $changes{$itemid} = 1;
                   10237:                             }
1.267     raeburn  10238:                         }
                   10239:                     }
                   10240:                     if ($env{'form.ltitools_target_'.$i} eq 'window') {
                   10241:                         $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
1.298     raeburn  10242:                     } elsif ($env{'form.ltitools_target_'.$i} eq 'tab') {
                   10243:                         $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
1.267     raeburn  10244:                     } else {
                   10245:                         $confhash{$itemid}{'display'}{'target'} = 'iframe';
                   10246:                     }
                   10247:                     if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
                   10248:                         if ($domconfig{$action}{$itemid}{'display'}{'target'} ne $confhash{$itemid}{'display'}{'target'}) {
                   10249:                             $changes{$itemid} = 1;
                   10250:                         }
                   10251:                     } else {
                   10252:                         $changes{$itemid} = 1;
                   10253:                     }
                   10254:                     foreach my $extra ('passback','roster') {
                   10255:                         if ($env{'form.ltitools_'.$extra.'_'.$i}) {
                   10256:                             $confhash{$itemid}{$extra} = 1;
                   10257:                         }
                   10258:                         if ($domconfig{$action}{$itemid}{$extra} ne $confhash{$itemid}{$extra}) {
                   10259:                             $changes{$itemid} = 1;
                   10260:                         }
                   10261:                     }
1.273     raeburn  10262:                     my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig_'.$i);
1.296     raeburn  10263:                     foreach my $item ('label','title','target','linktext','explanation') {
1.273     raeburn  10264:                         if (grep(/^\Q$item\E$/,@courseconfig)) {
                   10265:                             $confhash{$itemid}{'crsconf'}{$item} = 1;
                   10266:                             if (ref($domconfig{$action}{$itemid}{'crsconf'}) eq 'HASH') {
                   10267:                                 if ($domconfig{$action}{$itemid}{'crsconf'}{$item} ne $confhash{$itemid}{'crsconf'}{$item}) {
                   10268:                                     $changes{$itemid} = 1;
                   10269:                                 }
                   10270:                             } else {
                   10271:                                 $changes{$itemid} = 1;
                   10272:                             }
                   10273:                         }
                   10274:                     }
1.267     raeburn  10275:                     my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_fields_'.$i);
                   10276:                     foreach my $field (@fields) {
                   10277:                         if ($possfield{$field}) {
                   10278:                             if ($field eq 'roles') {
                   10279:                                 foreach my $role (@courseroles) {
                   10280:                                     my $choice = $env{'form.ltitools_roles_'.$role.'_'.$i};
                   10281:                                     if (($choice ne '') && ($posslti{$choice})) {
                   10282:                                         $confhash{$itemid}{'roles'}{$role} = $choice;
                   10283:                                         if ($role eq 'cc') {
                   10284:                                             $confhash{$itemid}{'roles'}{'co'} = $choice;
                   10285:                                         }
                   10286:                                     }
                   10287:                                     if (ref($domconfig{$action}{$itemid}{'roles'}) eq 'HASH') {
                   10288:                                         if ($domconfig{$action}{$itemid}{'roles'}{$role} ne $confhash{$itemid}{'roles'}{$role}) {
                   10289:                                             $changes{$itemid} = 1;
                   10290:                                         }
                   10291:                                     } elsif ($confhash{$itemid}{'roles'}{$role}) {
                   10292:                                         $changes{$itemid} = 1;
                   10293:                                     }
                   10294:                                 }
                   10295:                             } else {
                   10296:                                 $confhash{$itemid}{'fields'}{$field} = 1;
                   10297:                                 if (ref($domconfig{$action}{$itemid}{'fields'}) eq 'HASH') {
                   10298:                                     if ($domconfig{$action}{$itemid}{'fields'}{$field} ne $confhash{$itemid}{'fields'}{$field}) {
                   10299:                                         $changes{$itemid} = 1;
                   10300:                                     }
                   10301:                                 } else {
                   10302:                                     $changes{$itemid} = 1;
                   10303:                                 }
                   10304:                             }
                   10305:                         }
                   10306:                     }
                   10307:                     $allpos[$newpos] = $itemid;
                   10308:                 }
                   10309:                 if ($imgdeletions{$itemid}) {
                   10310:                     $changes{$itemid} = 1;
                   10311:                     #FIXME need to obsolete item in RES space
                   10312:                 } elsif ($env{'form.ltitools_image_'.$i.'.filename'}) {
                   10313:                     my ($imgurl,$error) = &process_ltitools_image($r,$dom,$confname,'ltitools_image_'.$i,
                   10314:                                                                  $itemid,$configuserok,$switchserver,
                   10315:                                                                  $author_ok);
                   10316:                     if ($imgurl) {
                   10317:                         $confhash{$itemid}{'image'} = $imgurl;
                   10318:                         $changes{$itemid} = 1;
                   10319:                     }
                   10320:                     if ($error) {
                   10321:                         &Apache::lonnet::logthis($error);
                   10322:                         $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   10323:                     }
                   10324:                 } elsif ($domconfig{$action}{$itemid}{'image'}) {
                   10325:                     $confhash{$itemid}{'image'} =
                   10326:                        $domconfig{$action}{$itemid}{'image'};
                   10327:                 }
                   10328:                 if ($customadds{$i}) {
                   10329:                     my $name = $env{'form.ltitools_custom_name_'.$i};
                   10330:                     $name =~ s/(`)/'/g;
                   10331:                     $name =~ s/^\s+//;
                   10332:                     $name =~ s/\s+$//;
                   10333:                     my $value = $env{'form.ltitools_custom_value_'.$i};
                   10334:                     $value =~ s/(`)/'/g;
                   10335:                     $value =~ s/^\s+//;
                   10336:                     $value =~ s/\s+$//;
                   10337:                     if ($name ne '') {
                   10338:                         $confhash{$itemid}{'custom'}{$name} = $value;
                   10339:                         $changes{$itemid} = 1;
                   10340:                     }
                   10341:                 }
                   10342:                 my %customdels;
                   10343:                 my @customdeletions = &Apache::loncommon::get_env_multiple('form.ltitools_customdel_'.$i); 
                   10344:                 if (@customdeletions) {
                   10345:                     $changes{$itemid} = 1;
                   10346:                 }
                   10347:                 map { $customdels{$_} = 1; } @customdeletions;
                   10348:                 if (ref($domconfig{$action}{$itemid}{'custom'}) eq 'HASH') {
                   10349:                     foreach my $key (keys(%{$domconfig{$action}{$itemid}{'custom'}})) {
                   10350:                         unless ($customdels{$key}) {
                   10351:                             if ($env{'form.ltitools_customval_'.$key.'_'.$i} ne '') {
                   10352:                                 $confhash{$itemid}{'custom'}{$key} = $env{'form.ltitools_customval_'.$key.'_'.$i}; 
                   10353:                             }
                   10354:                             if ($domconfig{$action}{$itemid}{'custom'}{$key} ne $env{'form.ltitools_customval_'.$key.'_'.$i}) {
                   10355:                                 $changes{$itemid} = 1;
                   10356:                             }
                   10357:                         }
                   10358:                     }
                   10359:                 }
                   10360:                 unless ($changes{$itemid}) {
                   10361:                     foreach my $key (keys(%{$domconfig{$action}{$itemid}})) {
                   10362:                         if (ref($domconfig{$action}{$itemid}{$key}) eq 'HASH') {
                   10363:                             if (ref($confhash{$itemid}{$key}) eq 'HASH') {
                   10364:                                 foreach my $innerkey (keys(%{$domconfig{$action}{$itemid}{$key}})) {
                   10365:                                     unless (exists($confhash{$itemid}{$key}{$innerkey})) {
                   10366:                                         $changes{$itemid} = 1;
                   10367:                                         last;
                   10368:                                     }
                   10369:                                 }
                   10370:                             } elsif (keys(%{$domconfig{$action}{$itemid}{$key}}) > 0) {
                   10371:                                 $changes{$itemid} = 1;
                   10372:                             }
                   10373:                         }
                   10374:                         last if ($changes{$itemid});
                   10375:                     }
                   10376:                 }
                   10377:             }
                   10378:         }
                   10379:     }
                   10380:     if (@allpos > 0) {
                   10381:         my $idx = 0;
                   10382:         foreach my $itemid (@allpos) {
                   10383:             if ($itemid ne '') {
                   10384:                 $confhash{$itemid}{'order'} = $idx;
                   10385:                 if (ref($domconfig{$action}) eq 'HASH') {
                   10386:                     if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
                   10387:                         if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
                   10388:                             $changes{$itemid} = 1;
                   10389:                         }
                   10390:                     }
                   10391:                 }
                   10392:                 $idx ++;
                   10393:             }
                   10394:         }
                   10395:     }
                   10396:     my %ltitoolshash = (
                   10397:                           $action => { %confhash }
                   10398:                        );
                   10399:     my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,
                   10400:                                              $dom);
                   10401:     if ($putresult eq 'ok') {
1.297     raeburn  10402:         my %ltienchash = (
                   10403:                              $action => { %encconfig }
                   10404:                          );
                   10405:         &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom);
1.267     raeburn  10406:         if (keys(%changes) > 0) {
                   10407:             my $cachetime = 24*60*60;
1.297     raeburn  10408:             my %ltiall = %confhash;
                   10409:             foreach my $id (keys(%ltiall)) {
                   10410:                 if (ref($encconfig{$id}) eq 'HASH') {
                   10411:                     foreach my $item ('key','secret') {
                   10412:                         $ltiall{$id}{$item} = $encconfig{$id}{$item};
                   10413:                     }
                   10414:                 }
                   10415:             }
                   10416:             &Apache::lonnet::do_cache_new('ltitools',$dom,\%ltiall,$cachetime);
1.267     raeburn  10417:             if (ref($lastactref) eq 'HASH') {
                   10418:                 $lastactref->{'ltitools'} = 1;
                   10419:             }
                   10420:             $resulttext = &mt('Changes made:').'<ul>';
                   10421:             my %bynum;
                   10422:             foreach my $itemid (sort(keys(%changes))) {
                   10423:                 my $position = $confhash{$itemid}{'order'};
                   10424:                 $bynum{$position} = $itemid;
                   10425:             }
                   10426:             foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
                   10427:                 my $itemid = $bynum{$pos}; 
                   10428:                 if (ref($confhash{$itemid}) ne 'HASH') {
                   10429:                     $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
                   10430:                 } else {
                   10431:                     $resulttext .= '<li><b>'.$confhash{$itemid}{'title'}.'</b>';
                   10432:                     if ($confhash{$itemid}{'image'}) {
                   10433:                         $resulttext .= '&nbsp;'.
                   10434:                                        '<img src="'.$confhash{$itemid}{'image'}.'"'.
                   10435:                                        ' alt="'.&mt('Tool Provider icon').'" />';
                   10436:                     }
                   10437:                     $resulttext .= '</li><ul>';
                   10438:                     my $position = $pos + 1;
                   10439:                     $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
1.297     raeburn  10440:                     foreach my $item ('version','msgtype','url') {
1.267     raeburn  10441:                         if ($confhash{$itemid}{$item} ne '') {
                   10442:                             $resulttext .= '<li>'.$lt{$item}.':&nbsp;'.$confhash{$itemid}{$item}.'</li>';
                   10443:                         }
                   10444:                     }
1.297     raeburn  10445:                     if ($encconfig{$itemid}{'key'} ne '') {
                   10446:                         $resulttext .= '<li>'.$lt{'key'}.':&nbsp;'.$encconfig{$itemid}{'key'}.'</li>';
                   10447:                     }
                   10448:                     if ($encconfig{$itemid}{'secret'} ne '') {
1.267     raeburn  10449:                         $resulttext .= '<li>'.$lt{'secret'}.':&nbsp;';
1.297     raeburn  10450:                         my $num = length($encconfig{$itemid}{'secret'});
1.267     raeburn  10451:                         $resulttext .= ('*'x$num).'</li>';
                   10452:                     }
1.273     raeburn  10453:                     $resulttext .= '<li>'.&mt('Configurable in course:');
1.296     raeburn  10454:                     my @possconfig = ('label','title','target','linktext','explanation');
1.273     raeburn  10455:                     my $numconfig = 0; 
                   10456:                     if (ref($confhash{$itemid}{'crsconf'}) eq 'HASH') { 
                   10457:                         foreach my $item (@possconfig) {
                   10458:                             if ($confhash{$itemid}{'crsconf'}{$item}) {
                   10459:                                 $numconfig ++;
1.296     raeburn  10460:                                 $resulttext .= ' "'.$lt{'crs'.$item}.'"';
1.273     raeburn  10461:                             }
                   10462:                         }
                   10463:                     }
                   10464:                     if (!$numconfig) {
                   10465:                         $resulttext .= &mt('None');
                   10466:                     }
                   10467:                     $resulttext .= '</li>';
1.267     raeburn  10468:                     foreach my $item ('passback','roster') {
                   10469:                         $resulttext .= '<li>'.$lt{$item}.'&nbsp;';
                   10470:                         if ($confhash{$itemid}{$item}) {
                   10471:                             $resulttext .= &mt('Yes');
                   10472:                         } else {
                   10473:                             $resulttext .= &mt('No');
                   10474:                         }
                   10475:                         $resulttext .= '</li>';
                   10476:                     }
                   10477:                     if (ref($confhash{$itemid}{'display'}) eq 'HASH') {
                   10478:                         my $displaylist;
                   10479:                         if ($confhash{$itemid}{'display'}{'target'}) {
                   10480:                             $displaylist = &mt('Display target').':&nbsp;'.
                   10481:                                            $confhash{$itemid}{'display'}{'target'}.',';
                   10482:                         }
                   10483:                         foreach my $size ('width','height') { 
                   10484:                             if ($confhash{$itemid}{'display'}{$size}) {
                   10485:                                 $displaylist .= ('&nbsp;'x2).$lt{$size}.':&nbsp;'.
                   10486:                                                 $confhash{$itemid}{'display'}{$size}.',';
                   10487:                             }
                   10488:                         }
                   10489:                         if ($displaylist) {
                   10490:                             $displaylist =~ s/,$//;
                   10491:                             $resulttext .= '<li>'.$displaylist.'</li>';
                   10492:                         }
1.296     raeburn  10493:                         foreach my $item ('linktext','explanation') {
                   10494:                             if ($confhash{$itemid}{'display'}{$item}) {
                   10495:                                 $resulttext .= '<li>'.$lt{$item}.':&nbsp;'.$confhash{$itemid}{'display'}{$item}.'</li>';
                   10496:                             }
                   10497:                         }
                   10498:                     }
1.267     raeburn  10499:                     if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
                   10500:                         my $fieldlist;
                   10501:                         foreach my $field (@allfields) {
                   10502:                             if ($confhash{$itemid}{'fields'}{$field}) {
                   10503:                                 $fieldlist .= ('&nbsp;'x2).$lt{$field}.',';
                   10504:                             }
                   10505:                         }
                   10506:                         if ($fieldlist) {
                   10507:                             $fieldlist =~ s/,$//;
                   10508:                             $resulttext .= '<li>'.&mt('Data sent').':'.$fieldlist.'</li>';
                   10509:                         }
                   10510:                     }
                   10511:                     if (ref($confhash{$itemid}{'roles'}) eq 'HASH') {
                   10512:                         my $rolemaps;
                   10513:                         foreach my $role (@courseroles) {
                   10514:                             if ($confhash{$itemid}{'roles'}{$role}) {
                   10515:                                 $rolemaps .= ('&nbsp;'x2).&Apache::lonnet::plaintext($role,'Course').'='.
                   10516:                                              $confhash{$itemid}{'roles'}{$role}.',';
                   10517:                             }
                   10518:                         }
                   10519:                         if ($rolemaps) {
                   10520:                             $rolemaps =~ s/,$//; 
                   10521:                             $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
                   10522:                         }
                   10523:                     }
                   10524:                     if (ref($confhash{$itemid}{'custom'}) eq 'HASH') {
                   10525:                         my $customlist;
                   10526:                         if (keys(%{$confhash{$itemid}{'custom'}})) {
                   10527:                             foreach my $key (sort(keys(%{$confhash{$itemid}{'custom'}}))) {
                   10528:                                 $customlist .= $key.':'.$confhash{$itemid}{'custom'}{$key}.('&nbsp;'x2);
                   10529:                             } 
                   10530:                         }
                   10531:                         if ($customlist) {
                   10532:                             $resulttext .= '<li>'.&mt('Custom items').':'.$customlist.'</li>';
                   10533:                         }
                   10534:                     } 
                   10535:                     $resulttext .= '</ul></li>';
                   10536:                 }
                   10537:             }
                   10538:             $resulttext .= '</ul>';
                   10539:         } else {
                   10540:             $resulttext = &mt('No changes made.');
                   10541:         }
                   10542:     } else {
                   10543:         $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
                   10544:     }
                   10545:     if ($errors) {
                   10546:         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
                   10547:                        $errors.'</ul>';
                   10548:     }
                   10549:     return $resulttext;
                   10550: }
                   10551: 
                   10552: sub process_ltitools_image {
                   10553:     my ($r,$dom,$confname,$caller,$itemid,$configuserok,$switchserver,$author_ok) = @_;
                   10554:     my $filename = $env{'form.'.$caller.'.filename'};
                   10555:     my ($error,$url);
                   10556:     my ($width,$height) = (21,21);
                   10557:     if ($configuserok eq 'ok') {
                   10558:         if ($switchserver) {
                   10559:             $error = &mt('Upload of Tool Provider (LTI) icon is not permitted to this server: [_1]',
                   10560:                          $switchserver);
                   10561:         } elsif ($author_ok eq 'ok') {
                   10562:             my ($result,$imageurl,$madethumb) =
                   10563:                 &publishlogo($r,'upload',$caller,$dom,$confname,
                   10564:                              "ltitools/$itemid/icon",$width,$height);
                   10565:             if ($result eq 'ok') {
                   10566:                 if ($madethumb) {
                   10567:                     my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
                   10568:                     my $imagethumb = "$path/tn-".$imagefile;
                   10569:                     $url = $imagethumb;
                   10570:                 } else {
                   10571:                     $url = $imageurl;
                   10572:                 }
                   10573:             } else {
                   10574:                 $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
                   10575:             }
                   10576:         } else {
                   10577:             $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);
                   10578:         }
                   10579:     } else {
                   10580:         $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);
                   10581:     }
                   10582:     return ($url,$error);
                   10583: }
                   10584: 
                   10585: sub get_ltitools_id {
                   10586:     my ($cdom,$title) = @_;
                   10587:     # get lock on ltitools db
                   10588:     my $lockhash = {
                   10589:                       lock => $env{'user.name'}.
                   10590:                               ':'.$env{'user.domain'},
                   10591:                    };
                   10592:     my $tries = 0;
                   10593:     my $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
                   10594:     my ($id,$error);
                   10595:  
                   10596:     while (($gotlock ne 'ok') && ($tries<10)) {
                   10597:         $tries ++;
                   10598:         sleep (0.1);
                   10599:         $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
                   10600:     }
                   10601:     if ($gotlock eq 'ok') {
                   10602:         my %currids = &Apache::lonnet::dump_dom('ltitools',$cdom);
                   10603:         if ($currids{'lock'}) {
                   10604:             delete($currids{'lock'});
                   10605:             if (keys(%currids)) {
                   10606:                 my @curr = sort { $a <=> $b } keys(%currids);
                   10607:                 if ($curr[-1] =~ /^\d+$/) {
                   10608:                     $id = 1 + $curr[-1];
                   10609:                 }
                   10610:             } else {
                   10611:                 $id = 1;
                   10612:             }
                   10613:             if ($id) {
                   10614:                 unless (&Apache::lonnet::newput_dom('ltitools',{ $id => $title },$cdom) eq 'ok') {
                   10615:                     $error = 'nostore';
                   10616:                 }
                   10617:             } else {
                   10618:                 $error = 'nonumber';
                   10619:             }
                   10620:         }
                   10621:         my $dellockoutcome = &Apache::lonnet::del_dom('ltitools',['lock'],$cdom);
                   10622:     } else {
                   10623:         $error = 'nolock';
                   10624:     }
                   10625:     return ($id,$error);
                   10626: }
                   10627: 
1.3       raeburn  10628: sub modify_autoenroll {
1.205     raeburn  10629:     my ($dom,$lastactref,%domconfig) = @_;
1.1       raeburn  10630:     my ($resulttext,%changes);
                   10631:     my %currautoenroll;
                   10632:     if (ref($domconfig{'autoenroll'}) eq 'HASH') {
                   10633:         foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
                   10634:             $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
                   10635:         }
                   10636:     }
                   10637:     my $autorun = &Apache::lonnet::auto_run(undef,$dom),
                   10638:     my %title = ( run => 'Auto-enrollment active',
1.129     raeburn  10639:                   sender => 'Sender for notification messages',
1.274     raeburn  10640:                   coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
                   10641:                   failsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1       raeburn  10642:     my @offon = ('off','on');
1.17      raeburn  10643:     my $sender_uname = $env{'form.sender_uname'};
                   10644:     my $sender_domain = $env{'form.sender_domain'};
                   10645:     if ($sender_domain eq '') {
                   10646:         $sender_uname = '';
                   10647:     } elsif ($sender_uname eq '') {
                   10648:         $sender_domain = '';
                   10649:     }
1.129     raeburn  10650:     my $coowners = $env{'form.autoassign_coowners'};
1.274     raeburn  10651:     my $failsafe = $env{'form.autoenroll_failsafe'};
                   10652:     $failsafe =~ s{^\s+|\s+$}{}g;
                   10653:     if ($failsafe =~ /\D/) {
                   10654:         undef($failsafe);
                   10655:     }
1.1       raeburn  10656:     my %autoenrollhash =  (
1.129     raeburn  10657:                        autoenroll => { 'run' => $env{'form.autoenroll_run'},
                   10658:                                        'sender_uname' => $sender_uname,
                   10659:                                        'sender_domain' => $sender_domain,
                   10660:                                        'co-owners' => $coowners,
1.274     raeburn  10661:                                        'autofailsafe' => $failsafe,
1.1       raeburn  10662:                                 }
                   10663:                      );
1.4       raeburn  10664:     my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
                   10665:                                              $dom);
1.1       raeburn  10666:     if ($putresult eq 'ok') {
                   10667:         if (exists($currautoenroll{'run'})) {
                   10668:              if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
                   10669:                  $changes{'run'} = 1;
                   10670:              }
                   10671:         } elsif ($autorun) {
                   10672:             if ($env{'form.autoenroll_run'} ne '1') {
1.23      raeburn  10673:                  $changes{'run'} = 1;
1.1       raeburn  10674:             }
                   10675:         }
1.17      raeburn  10676:         if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1       raeburn  10677:             $changes{'sender'} = 1;
                   10678:         }
1.17      raeburn  10679:         if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1       raeburn  10680:             $changes{'sender'} = 1;
                   10681:         }
1.129     raeburn  10682:         if ($currautoenroll{'co-owners'} ne '') {
                   10683:             if ($currautoenroll{'co-owners'} ne $coowners) {
                   10684:                 $changes{'coowners'} = 1;
                   10685:             }
                   10686:         } elsif ($coowners) {
                   10687:             $changes{'coowners'} = 1;
1.274     raeburn  10688:         }
                   10689:         if ($currautoenroll{'autofailsafe'} ne $failsafe) {
                   10690:             $changes{'autofailsafe'} = 1;
                   10691:         }
1.1       raeburn  10692:         if (keys(%changes) > 0) {
                   10693:             $resulttext = &mt('Changes made:').'<ul>';
1.3       raeburn  10694:             if ($changes{'run'}) {
1.1       raeburn  10695:                 $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
                   10696:             }
                   10697:             if ($changes{'sender'}) {
1.17      raeburn  10698:                 if ($sender_uname eq '' || $sender_domain eq '') {
                   10699:                     $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
                   10700:                 } else {
                   10701:                     $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
                   10702:                 }
1.1       raeburn  10703:             }
1.129     raeburn  10704:             if ($changes{'coowners'}) {
                   10705:                 $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
                   10706:                 &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212     raeburn  10707:                 if (ref($lastactref) eq 'HASH') {
                   10708:                     $lastactref->{'domainconfig'} = 1;
                   10709:                 }
1.129     raeburn  10710:             }
1.274     raeburn  10711:             if ($changes{'autofailsafe'}) {
                   10712:                 if ($failsafe ne '') {
1.299     raeburn  10713:                     $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$failsafe).'</li>';
1.274     raeburn  10714:                 } else {
1.299     raeburn  10715:                     $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section: deleted');
1.274     raeburn  10716:                 }
                   10717:                 &Apache::lonnet::get_domain_defaults($dom,1);
                   10718:                 if (ref($lastactref) eq 'HASH') {
                   10719:                     $lastactref->{'domdefaults'} = 1;
                   10720:                 }
                   10721:             }
1.1       raeburn  10722:             $resulttext .= '</ul>';
                   10723:         } else {
                   10724:             $resulttext = &mt('No changes made to auto-enrollment settings');
                   10725:         }
                   10726:     } else {
1.11      albertel 10727:         $resulttext = '<span class="LC_error">'.
                   10728: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  10729:     }
1.3       raeburn  10730:     return $resulttext;
1.1       raeburn  10731: }
                   10732: 
                   10733: sub modify_autoupdate {
1.3       raeburn  10734:     my ($dom,%domconfig) = @_;
1.1       raeburn  10735:     my ($resulttext,%currautoupdate,%fields,%changes);
                   10736:     if (ref($domconfig{'autoupdate'}) eq 'HASH') {
                   10737:         foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
                   10738:             $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
                   10739:         }
                   10740:     }
                   10741:     my @offon = ('off','on');
                   10742:     my %title = &Apache::lonlocal::texthash (
                   10743:                    run => 'Auto-update:',
                   10744:                    classlists => 'Updates to user information in classlists?'
                   10745:                 );
1.44      raeburn  10746:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1       raeburn  10747:     my %fieldtitles = &Apache::lonlocal::texthash (
                   10748:                         id => 'Student/Employee ID',
1.20      raeburn  10749:                         permanentemail => 'E-mail address',
1.1       raeburn  10750:                         lastname => 'Last Name',
                   10751:                         firstname => 'First Name',
                   10752:                         middlename => 'Middle Name',
1.132     raeburn  10753:                         generation => 'Generation',
1.1       raeburn  10754:                       );
1.142     raeburn  10755:     $othertitle = &mt('All users');
1.1       raeburn  10756:     if (keys(%{$usertypes}) >  0) {
1.26      raeburn  10757:         $othertitle = &mt('Other users');
1.1       raeburn  10758:     }
                   10759:     foreach my $key (keys(%env)) {
                   10760:         if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132     raeburn  10761:             my ($usertype,$item) = ($1,$2);
                   10762:             if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
                   10763:                 if ($usertype eq 'default') {   
                   10764:                     push(@{$fields{$1}},$2);
                   10765:                 } elsif (ref($types) eq 'ARRAY') {
                   10766:                     if (grep(/^\Q$usertype\E$/,@{$types})) {
                   10767:                         push(@{$fields{$1}},$2);
                   10768:                     }
                   10769:                 }
                   10770:             }
1.1       raeburn  10771:         }
                   10772:     }
1.131     raeburn  10773:     my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
                   10774:     @lockablenames = sort(@lockablenames);
                   10775:     if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
                   10776:         my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
                   10777:         if (@changed) {
                   10778:             $changes{'lockablenames'} = 1;
                   10779:         }
                   10780:     } else {
                   10781:         if (@lockablenames) {
                   10782:             $changes{'lockablenames'} = 1;
                   10783:         }
                   10784:     }
1.1       raeburn  10785:     my %updatehash = (
                   10786:                       autoupdate => { run => $env{'form.autoupdate_run'},
                   10787:                                       classlists => $env{'form.classlists'},
                   10788:                                       fields => {%fields},
1.131     raeburn  10789:                                       lockablenames => \@lockablenames,
1.1       raeburn  10790:                                     }
                   10791:                      );
                   10792:     foreach my $key (keys(%currautoupdate)) {
                   10793:         if (($key eq 'run') || ($key eq 'classlists')) {
                   10794:             if (exists($updatehash{autoupdate}{$key})) {
                   10795:                 if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
                   10796:                     $changes{$key} = 1;
                   10797:                 }
                   10798:             }
                   10799:         } elsif ($key eq 'fields') {
                   10800:             if (ref($currautoupdate{$key}) eq 'HASH') {
1.26      raeburn  10801:                 foreach my $item (@{$types},'default') {
1.1       raeburn  10802:                     if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
                   10803:                         my $change = 0;
                   10804:                         foreach my $type (@{$currautoupdate{$key}{$item}}) {
                   10805:                             if (!exists($fields{$item})) {
                   10806:                                 $change = 1;
1.132     raeburn  10807:                                 last;
1.1       raeburn  10808:                             } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26      raeburn  10809:                                 if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1       raeburn  10810:                                     $change = 1;
1.132     raeburn  10811:                                     last;
1.1       raeburn  10812:                                 }
                   10813:                             }
                   10814:                         }
                   10815:                         if ($change) {
                   10816:                             push(@{$changes{$key}},$item);
                   10817:                         }
1.26      raeburn  10818:                     } 
1.1       raeburn  10819:                 }
                   10820:             }
1.131     raeburn  10821:         } elsif ($key eq 'lockablenames') {
                   10822:             if (ref($currautoupdate{$key}) eq 'ARRAY') {
                   10823:                 my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
                   10824:                 if (@changed) {
                   10825:                     $changes{'lockablenames'} = 1;
                   10826:                 }
                   10827:             } else {
                   10828:                 if (@lockablenames) {
                   10829:                     $changes{'lockablenames'} = 1;
                   10830:                 }
                   10831:             }
                   10832:         }
                   10833:     }
                   10834:     unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
                   10835:         if (@lockablenames) {
                   10836:             $changes{'lockablenames'} = 1;
1.1       raeburn  10837:         }
                   10838:     }
1.26      raeburn  10839:     foreach my $item (@{$types},'default') {
                   10840:         if (defined($fields{$item})) {
                   10841:             if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132     raeburn  10842:                 if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
                   10843:                     my $change = 0;
                   10844:                     if (ref($fields{$item}) eq 'ARRAY') {
                   10845:                         foreach my $type (@{$fields{$item}}) {
                   10846:                             if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
                   10847:                                 $change = 1;
                   10848:                                 last;
                   10849:                             }
                   10850:                         }
                   10851:                     }
                   10852:                     if ($change) {
                   10853:                         push(@{$changes{'fields'}},$item);
                   10854:                     }
                   10855:                 } else {
1.26      raeburn  10856:                     push(@{$changes{'fields'}},$item);
                   10857:                 }
                   10858:             } else {
                   10859:                 push(@{$changes{'fields'}},$item);
1.1       raeburn  10860:             }
                   10861:         }
                   10862:     }
                   10863:     my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
                   10864:                                              $dom);
                   10865:     if ($putresult eq 'ok') {
                   10866:         if (keys(%changes) > 0) {
                   10867:             $resulttext = &mt('Changes made:').'<ul>';
                   10868:             foreach my $key (sort(keys(%changes))) {
1.131     raeburn  10869:                 if ($key eq 'lockablenames') {
                   10870:                     $resulttext .= '<li>';
                   10871:                     if (@lockablenames) {
                   10872:                         $usertypes->{'default'} = $othertitle;
                   10873:                         $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
                   10874:                                    join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
                   10875:                     } else {
                   10876:                         $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
                   10877:                     }
                   10878:                     $resulttext .= '</li>';
                   10879:                 } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1       raeburn  10880:                     foreach my $item (@{$changes{$key}}) {
                   10881:                         my @newvalues;
                   10882:                         foreach my $type (@{$fields{$item}}) {
                   10883:                             push(@newvalues,$fieldtitles{$type});
                   10884:                         }
1.3       raeburn  10885:                         my $newvaluestr;
                   10886:                         if (@newvalues > 0) {
                   10887:                             $newvaluestr = join(', ',@newvalues);
                   10888:                         } else {
                   10889:                             $newvaluestr = &mt('none');
1.6       raeburn  10890:                         }
1.1       raeburn  10891:                         if ($item eq 'default') {
1.26      raeburn  10892:                             $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1       raeburn  10893:                         } else {
1.26      raeburn  10894:                             $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1       raeburn  10895:                         }
                   10896:                     }
                   10897:                 } else {
                   10898:                     my $newvalue;
                   10899:                     if ($key eq 'run') {
                   10900:                         $newvalue = $offon[$env{'form.autoupdate_run'}];
                   10901:                     } else {
                   10902:                         $newvalue = $offon[$env{'form.'.$key}];
1.3       raeburn  10903:                     }
1.1       raeburn  10904:                     $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
                   10905:                 }
                   10906:             }
                   10907:             $resulttext .= '</ul>';
                   10908:         } else {
1.3       raeburn  10909:             $resulttext = &mt('No changes made to autoupdates');
1.1       raeburn  10910:         }
                   10911:     } else {
1.11      albertel 10912:         $resulttext = '<span class="LC_error">'.
                   10913: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  10914:     }
1.3       raeburn  10915:     return $resulttext;
1.1       raeburn  10916: }
                   10917: 
1.125     raeburn  10918: sub modify_autocreate {
                   10919:     my ($dom,%domconfig) = @_;
                   10920:     my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
                   10921:     if (ref($domconfig{'autocreate'}) eq 'HASH') {
                   10922:         foreach my $key (keys(%{$domconfig{'autocreate'}})) {
                   10923:             $currautocreate{$key} = $domconfig{'autocreate'}{$key};
                   10924:         }
                   10925:     }
                   10926:     my %title= ( xml => 'Auto-creation of courses in XML course description files',
                   10927:                  req => 'Auto-creation of validated requests for official courses',
                   10928:                  xmldc => 'Identity of course creator of courses from XML files',
                   10929:                );
                   10930:     my @types = ('xml','req');
                   10931:     foreach my $item (@types) {
                   10932:         $newvals{$item} = $env{'form.autocreate_'.$item};
                   10933:         $newvals{$item} =~ s/\D//g;
                   10934:         $newvals{$item} = 0 if ($newvals{$item} eq '');
                   10935:     }
                   10936:     $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.285     raeburn  10937:     my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125     raeburn  10938:     unless (exists($domcoords{$newvals{'xmldc'}})) {
                   10939:         $newvals{'xmldc'} = '';
                   10940:     } 
                   10941:     %autocreatehash =  (
                   10942:                         autocreate => { xml => $newvals{'xml'},
                   10943:                                         req => $newvals{'req'},
                   10944:                                       }
                   10945:                        );
                   10946:     if ($newvals{'xmldc'} ne '') {
                   10947:         $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
                   10948:     }
                   10949:     my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
                   10950:                                              $dom);
                   10951:     if ($putresult eq 'ok') {
                   10952:         my @items = @types;
                   10953:         if ($newvals{'xml'}) {
                   10954:             push(@items,'xmldc');
                   10955:         }
                   10956:         foreach my $item (@items) {
                   10957:             if (exists($currautocreate{$item})) {
                   10958:                 if ($currautocreate{$item} ne $newvals{$item}) {
                   10959:                     $changes{$item} = 1;
                   10960:                 }
                   10961:             } elsif ($newvals{$item}) {
                   10962:                 $changes{$item} = 1;
                   10963:             }
                   10964:         }
                   10965:         if (keys(%changes) > 0) {
                   10966:             my @offon = ('off','on'); 
                   10967:             $resulttext = &mt('Changes made:').'<ul>';
                   10968:             foreach my $item (@types) {
                   10969:                 if ($changes{$item}) {
                   10970:                     my $newtxt = $offon[$newvals{$item}];
1.178     raeburn  10971:                     $resulttext .= '<li>'.
                   10972:                                    &mt("$title{$item} set to [_1]$newtxt [_2]",
                   10973:                                        '<b>','</b>').
                   10974:                                    '</li>';
1.125     raeburn  10975:                 }
                   10976:             }
                   10977:             if ($changes{'xmldc'}) {
                   10978:                 my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
                   10979:                 my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178     raeburn  10980:                 $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>'; 
1.125     raeburn  10981:             }
                   10982:             $resulttext .= '</ul>';
                   10983:         } else {
                   10984:             $resulttext = &mt('No changes made to auto-creation settings');
                   10985:         }
                   10986:     } else {
                   10987:         $resulttext = '<span class="LC_error">'.
                   10988:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   10989:     }
                   10990:     return $resulttext;
                   10991: }
                   10992: 
1.23      raeburn  10993: sub modify_directorysrch {
1.295     raeburn  10994:     my ($dom,$lastactref,%domconfig) = @_;
1.23      raeburn  10995:     my ($resulttext,%changes);
                   10996:     my %currdirsrch;
                   10997:     if (ref($domconfig{'directorysrch'}) eq 'HASH') {
                   10998:         foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
                   10999:             $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
                   11000:         }
                   11001:     }
1.277     raeburn  11002:     my %title = ( available => 'Institutional directory search available',
                   11003:                   localonly => 'Other domains can search institution',
                   11004:                   lcavailable => 'LON-CAPA directory search available',
1.289     raeburn  11005:                   lclocalonly => 'Other domains can search LON-CAPA domain',
1.23      raeburn  11006:                   searchby => 'Search types',
                   11007:                   searchtypes => 'Search latitude');
                   11008:     my @offon = ('off','on');
1.24      raeburn  11009:     my @otherdoms = ('Yes','No');
1.23      raeburn  11010: 
1.25      raeburn  11011:     my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');  
1.23      raeburn  11012:     my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
                   11013:     my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
                   11014: 
1.44      raeburn  11015:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26      raeburn  11016:     if (keys(%{$usertypes}) == 0) {
                   11017:         @cansearch = ('default');
                   11018:     } else {
                   11019:         if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
                   11020:             foreach my $type (@{$currdirsrch{'cansearch'}}) {
                   11021:                 if (!grep(/^\Q$type\E$/,@cansearch)) {
                   11022:                     push(@{$changes{'cansearch'}},$type);
                   11023:                 }
1.23      raeburn  11024:             }
1.26      raeburn  11025:             foreach my $type (@cansearch) {
                   11026:                 if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
                   11027:                     push(@{$changes{'cansearch'}},$type);
                   11028:                 }
1.23      raeburn  11029:             }
1.26      raeburn  11030:         } else {
                   11031:             push(@{$changes{'cansearch'}},@cansearch);
1.23      raeburn  11032:         }
                   11033:     }
                   11034: 
                   11035:     if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
                   11036:         foreach my $by (@{$currdirsrch{'searchby'}}) {
                   11037:             if (!grep(/^\Q$by\E$/,@searchby)) {
                   11038:                 push(@{$changes{'searchby'}},$by);
                   11039:             }
                   11040:         }
                   11041:         foreach my $by (@searchby) {
                   11042:             if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
                   11043:                 push(@{$changes{'searchby'}},$by);
                   11044:             }
                   11045:         }
                   11046:     } else {
                   11047:         push(@{$changes{'searchby'}},@searchby);
                   11048:     }
1.25      raeburn  11049: 
                   11050:     if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
                   11051:         foreach my $type (@{$currdirsrch{'searchtypes'}}) {
                   11052:             if (!grep(/^\Q$type\E$/,@searchtypes)) {
                   11053:                 push(@{$changes{'searchtypes'}},$type);
                   11054:             }
                   11055:         }
                   11056:         foreach my $type (@searchtypes) {
                   11057:             if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
                   11058:                 push(@{$changes{'searchtypes'}},$type);
                   11059:             }
                   11060:         }
                   11061:     } else {
                   11062:         if (exists($currdirsrch{'searchtypes'})) {
                   11063:             foreach my $type (@searchtypes) {  
                   11064:                 if ($type ne $currdirsrch{'searchtypes'}) { 
                   11065:                     push(@{$changes{'searchtypes'}},$type);
                   11066:                 }
                   11067:             }
                   11068:             if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
                   11069:                 push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
                   11070:             }   
                   11071:         } else {
                   11072:             push(@{$changes{'searchtypes'}},@searchtypes); 
                   11073:         }
                   11074:     }
                   11075: 
1.23      raeburn  11076:     my %dirsrch_hash =  (
                   11077:             directorysrch => { available => $env{'form.dirsrch_available'},
                   11078:                                cansearch => \@cansearch,
1.277     raeburn  11079:                                localonly => $env{'form.dirsrch_instlocalonly'},
                   11080:                                lclocalonly => $env{'form.dirsrch_domlocalonly'},
                   11081:                                lcavailable => $env{'form.dirsrch_domavailable'},
1.23      raeburn  11082:                                searchby => \@searchby,
1.25      raeburn  11083:                                searchtypes => \@searchtypes,
1.23      raeburn  11084:                              }
                   11085:             );
                   11086:     my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
                   11087:                                              $dom);
                   11088:     if ($putresult eq 'ok') {
                   11089:         if (exists($currdirsrch{'available'})) {
                   11090:              if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
                   11091:                  $changes{'available'} = 1;
                   11092:              }
                   11093:         } else {
                   11094:             if ($env{'form.dirsrch_available'} eq '1') {
                   11095:                 $changes{'available'} = 1;
                   11096:             }
                   11097:         }
1.277     raeburn  11098:         if (exists($currdirsrch{'lcavailable'})) {
1.289     raeburn  11099:             if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
                   11100:                 $changes{'lcavailable'} = 1;
                   11101:             }
1.277     raeburn  11102:         } else {
                   11103:             if ($env{'form.dirsrch_lcavailable'} eq '1') {
                   11104:                 $changes{'lcavailable'} = 1;
                   11105:             }
                   11106:         }
1.24      raeburn  11107:         if (exists($currdirsrch{'localonly'})) {
1.289     raeburn  11108:             if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
                   11109:                 $changes{'localonly'} = 1;
                   11110:             }
1.24      raeburn  11111:         } else {
1.277     raeburn  11112:             if ($env{'form.dirsrch_instlocalonly'} eq '1') {
1.24      raeburn  11113:                 $changes{'localonly'} = 1;
                   11114:             }
                   11115:         }
1.277     raeburn  11116:         if (exists($currdirsrch{'lclocalonly'})) {
1.289     raeburn  11117:             if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
                   11118:                 $changes{'lclocalonly'} = 1;
                   11119:             }
1.277     raeburn  11120:         } else {
                   11121:             if ($env{'form.dirsrch_domlocalonly'} eq '1') {
                   11122:                 $changes{'lclocalonly'} = 1;
                   11123:             }
                   11124:         }
1.23      raeburn  11125:         if (keys(%changes) > 0) {
                   11126:             $resulttext = &mt('Changes made:').'<ul>';
                   11127:             if ($changes{'available'}) {
                   11128:                 $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
                   11129:             }
1.277     raeburn  11130:             if ($changes{'lcavailable'}) {
                   11131:                 $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
                   11132:             }
1.24      raeburn  11133:             if ($changes{'localonly'}) {
1.277     raeburn  11134:                 $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
1.24      raeburn  11135:             }
1.277     raeburn  11136:             if ($changes{'lclocalonly'}) {
                   11137:                 $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.289     raeburn  11138:             }
1.23      raeburn  11139:             if (ref($changes{'cansearch'}) eq 'ARRAY') {
                   11140:                 my $chgtext;
1.26      raeburn  11141:                 if (ref($usertypes) eq 'HASH') {
                   11142:                     if (keys(%{$usertypes}) > 0) {
                   11143:                         foreach my $type (@{$types}) {
                   11144:                             if (grep(/^\Q$type\E$/,@cansearch)) {
                   11145:                                 $chgtext .= $usertypes->{$type}.'; ';
                   11146:                             }
                   11147:                         }
                   11148:                         if (grep(/^default$/,@cansearch)) {
                   11149:                             $chgtext .= $othertitle;
                   11150:                         } else {
                   11151:                             $chgtext =~ s/\; $//;
                   11152:                         }
1.210     raeburn  11153:                         $resulttext .=
1.178     raeburn  11154:                             '<li>'.
                   11155:                             &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
                   11156:                                 '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
                   11157:                             '</li>';
1.23      raeburn  11158:                     }
                   11159:                 }
                   11160:             }
                   11161:             if (ref($changes{'searchby'}) eq 'ARRAY') {
                   11162:                 my ($searchtitles,$titleorder) = &sorted_searchtitles();
                   11163:                 my $chgtext;
                   11164:                 foreach my $type (@{$titleorder}) {
                   11165:                     if (grep(/^\Q$type\E$/,@searchby)) {
                   11166:                         if (defined($searchtitles->{$type})) {
                   11167:                             $chgtext .= $searchtitles->{$type}.'; ';
                   11168:                         }
                   11169:                     }
                   11170:                 }
                   11171:                 $chgtext =~ s/\; $//;
                   11172:                 $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
                   11173:             }
1.25      raeburn  11174:             if (ref($changes{'searchtypes'}) eq 'ARRAY') {
                   11175:                 my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes(); 
                   11176:                 my $chgtext;
                   11177:                 foreach my $type (@{$srchtypeorder}) {
                   11178:                     if (grep(/^\Q$type\E$/,@searchtypes)) {
                   11179:                         if (defined($srchtypes_desc->{$type})) {
                   11180:                             $chgtext .= $srchtypes_desc->{$type}.'; ';
                   11181:                         }
                   11182:                     }
                   11183:                 }
                   11184:                 $chgtext =~ s/\; $//;
1.178     raeburn  11185:                 $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23      raeburn  11186:             }
                   11187:             $resulttext .= '</ul>';
1.295     raeburn  11188:             &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
                   11189:             if (ref($lastactref) eq 'HASH') {
                   11190:                 $lastactref->{'directorysrch'} = 1;
                   11191:             }
1.23      raeburn  11192:         } else {
1.277     raeburn  11193:             $resulttext = &mt('No changes made to directory search settings');
1.23      raeburn  11194:         }
                   11195:     } else {
                   11196:         $resulttext = '<span class="LC_error">'.
1.27      raeburn  11197:                       &mt('An error occurred: [_1]',$putresult).'</span>';
                   11198:     }
                   11199:     return $resulttext;
                   11200: }
                   11201: 
1.28      raeburn  11202: sub modify_contacts {
1.205     raeburn  11203:     my ($dom,$lastactref,%domconfig) = @_;
1.28      raeburn  11204:     my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
                   11205:     if (ref($domconfig{'contacts'}) eq 'HASH') {
                   11206:         foreach my $key (keys(%{$domconfig{'contacts'}})) {
                   11207:             $currsetting{$key} = $domconfig{'contacts'}{$key};
                   11208:         }
                   11209:     }
1.286     raeburn  11210:     my (%others,%to,%bcc,%includestr,%includeloc);
1.28      raeburn  11211:     my @contacts = ('supportemail','adminemail');
1.286     raeburn  11212:     my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
                   11213:                     'lonstatusmail','requestsmail','updatesmail','idconflictsmail');
1.203     raeburn  11214:     my @toggles = ('reporterrors','reportupdates');
1.286     raeburn  11215:     my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28      raeburn  11216:     foreach my $type (@mailings) {
                   11217:         @{$newsetting{$type}} = 
                   11218:             &Apache::loncommon::get_env_multiple('form.'.$type);
                   11219:         foreach my $item (@contacts) {
                   11220:             if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
                   11221:                 $contacts_hash{contacts}{$type}{$item} = 1;
                   11222:             } else {
                   11223:                 $contacts_hash{contacts}{$type}{$item} = 0;
                   11224:             }
1.289     raeburn  11225:         }
1.28      raeburn  11226:         $others{$type} = $env{'form.'.$type.'_others'};
                   11227:         $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.286     raeburn  11228:         if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134     raeburn  11229:             $bcc{$type} = $env{'form.'.$type.'_bcc'};
                   11230:             $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.286     raeburn  11231:             if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
                   11232:                 $includestr{$type} = $env{'form.'.$type.'_includestr'};
                   11233:                 $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
                   11234:                 $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
                   11235:             }
1.134     raeburn  11236:         }
1.28      raeburn  11237:     }
                   11238:     foreach my $item (@contacts) {
                   11239:         $to{$item} = $env{'form.'.$item};
                   11240:         $contacts_hash{'contacts'}{$item} = $to{$item};
                   11241:     }
1.203     raeburn  11242:     foreach my $item (@toggles) {
                   11243:         if ($env{'form.'.$item} =~ /^(0|1)$/) {
                   11244:             $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
                   11245:         }
                   11246:     }
1.286     raeburn  11247:     if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
                   11248:         foreach my $field (@{$fields}) {
                   11249:             if (ref($possoptions->{$field}) eq 'ARRAY') {
                   11250:                 my $value = $env{'form.helpform_'.$field};
                   11251:                 $value =~ s/^\s+|\s+$//g;
                   11252:                 if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
1.315     raeburn  11253:                     $contacts_hash{'contacts'}{'helpform'}{$field} = $value;
1.286     raeburn  11254:                     if ($field eq 'screenshot') {
                   11255:                         $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
                   11256:                         if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
1.315     raeburn  11257:                             $contacts_hash{'contacts'}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
1.286     raeburn  11258:                         }
                   11259:                     }
                   11260:                 }
                   11261:             }
                   11262:         }
                   11263:     }
1.315     raeburn  11264:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   11265:     my (@statuses,%usertypeshash,@overrides);
                   11266:     if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
                   11267:         @statuses = @{$types};
                   11268:         if (ref($usertypes) eq 'HASH') {
                   11269:             %usertypeshash = %{$usertypes};
                   11270:         }
                   11271:     }
                   11272:     if (@statuses) {
                   11273:         my @possoverrides = &Apache::loncommon::get_env_multiple('form.overrides');
                   11274:         foreach my $type (@possoverrides) {
                   11275:             if (($type ne '') && (grep(/^\Q$type\E$/,@statuses))) {
                   11276:                 push(@overrides,$type);
                   11277:             }
                   11278:         }
                   11279:         if (@overrides) {
                   11280:             foreach my $type (@overrides) {
                   11281:                 my @standard = &Apache::loncommon::get_env_multiple('form.override_'.$type);
                   11282:                 foreach my $item (@contacts) {
                   11283:                     if (grep(/^\Q$item\E$/,@standard)) {
                   11284:                         $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 1;
                   11285:                         $newsetting{'override_'.$type}{$item} = 1;
                   11286:                     } else {
                   11287:                         $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 0;
                   11288:                         $newsetting{'override_'.$type}{$item} = 0;
                   11289:                     }
                   11290:                 }
                   11291:                 $contacts_hash{'contacts'}{'overrides'}{$type}{'others'} = $env{'form.override_'.$type.'_others'};
                   11292:                 $contacts_hash{'contacts'}{'overrides'}{$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
                   11293:                 $newsetting{'override_'.$type}{'others'} = $env{'form.override_'.$type.'_others'};
                   11294:                 $newsetting{'override_'.$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
                   11295:                 if (($env{'form.override_'.$type.'_includestr'} ne '') && ($env{'form.override_'.$type.'_includeloc'} =~ /^s|b$/)) {
                   11296:                     $includestr{$type} = $env{'form.override_'.$type.'_includestr'};
                   11297:                     $includeloc{$type} = $env{'form.override_'.$type.'_includeloc'};
                   11298:                     $contacts_hash{'contacts'}{'overrides'}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
                   11299:                     $newsetting{'override_'.$type}{'include'} = $contacts_hash{'contacts'}{'overrides'}{$type}{'include'};
                   11300:                 }
                   11301:             }     
                   11302:         }
                   11303:     }
1.28      raeburn  11304:     if (keys(%currsetting) > 0) {
                   11305:         foreach my $item (@contacts) {
                   11306:             if ($to{$item} ne $currsetting{$item}) {
                   11307:                 $changes{$item} = 1;
                   11308:             }
                   11309:         }
                   11310:         foreach my $type (@mailings) {
                   11311:             foreach my $item (@contacts) {
                   11312:                 if (ref($currsetting{$type}) eq 'HASH') {
                   11313:                     if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
                   11314:                         push(@{$changes{$type}},$item);
                   11315:                     }
                   11316:                 } else {
                   11317:                     push(@{$changes{$type}},@{$newsetting{$type}});
                   11318:                 }
                   11319:             }
                   11320:             if ($others{$type} ne $currsetting{$type}{'others'}) {
                   11321:                 push(@{$changes{$type}},'others');
                   11322:             }
1.289     raeburn  11323:             if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134     raeburn  11324:                 if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
                   11325:                     push(@{$changes{$type}},'bcc'); 
                   11326:                 }
1.286     raeburn  11327:                 my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
                   11328:                 if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
                   11329:                     push(@{$changes{$type}},'include');
                   11330:                 }
                   11331:             }
                   11332:         }
                   11333:         if (ref($fields) eq 'ARRAY') {
                   11334:             if (ref($currsetting{'helpform'}) eq 'HASH') {
                   11335:                 foreach my $field (@{$fields}) {
                   11336:                     if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
                   11337:                         push(@{$changes{'helpform'}},$field);
                   11338:                     }
                   11339:                     if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
                   11340:                         if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
                   11341:                             push(@{$changes{'helpform'}},'maxsize');
                   11342:                         }
                   11343:                     }
                   11344:                 }
                   11345:             } else {
                   11346:                 foreach my $field (@{$fields}) {
                   11347:                     if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
                   11348:                         push(@{$changes{'helpform'}},$field);
                   11349:                     }
                   11350:                     if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
                   11351:                         if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
                   11352:                             push(@{$changes{'helpform'}},'maxsize');
                   11353:                         }
                   11354:                     }
                   11355:                 }
1.134     raeburn  11356:             }
1.28      raeburn  11357:         }
1.315     raeburn  11358:         if (@statuses) {
                   11359:             if (ref($currsetting{'overrides'}) eq 'HASH') { 
                   11360:                 foreach my $key (keys(%{$currsetting{'overrides'}})) {
                   11361:                     if (ref($currsetting{'overrides'}{$key}) eq 'HASH') {
                   11362:                         if (ref($newsetting{'override_'.$key}) eq 'HASH') {
                   11363:                             foreach my $item (@contacts,'bcc','others','include') {
                   11364:                                 if ($currsetting{'overrides'}{$key}{$item} ne $newsetting{'override_'.$key}{$item}) { 
                   11365:                                     push(@{$changes{'overrides'}},$key);
                   11366:                                     last;
                   11367:                                 }
                   11368:                             }
                   11369:                         } else {
                   11370:                             push(@{$changes{'overrides'}},$key);
                   11371:                         }
                   11372:                     }
                   11373:                 }
                   11374:                 foreach my $key (@overrides) {
                   11375:                     unless (exists($currsetting{'overrides'}{$key})) {
                   11376:                         push(@{$changes{'overrides'}},$key);
                   11377:                     }
                   11378:                 }
                   11379:             } else {
                   11380:                 foreach my $key (@overrides) {
                   11381:                     push(@{$changes{'overrides'}},$key); 
                   11382:                 }
                   11383:             }
                   11384:         }
1.28      raeburn  11385:     } else {
                   11386:         my %default;
                   11387:         $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
                   11388:         $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
                   11389:         $default{'errormail'} = 'adminemail';
                   11390:         $default{'packagesmail'} = 'adminemail';
                   11391:         $default{'helpdeskmail'} = 'supportemail';
1.286     raeburn  11392:         $default{'otherdomsmail'} = 'supportemail';
1.89      raeburn  11393:         $default{'lonstatusmail'} = 'adminemail';
1.102     raeburn  11394:         $default{'requestsmail'} = 'adminemail';
1.190     raeburn  11395:         $default{'updatesmail'} = 'adminemail';
1.28      raeburn  11396:         foreach my $item (@contacts) {
                   11397:            if ($to{$item} ne $default{$item}) {
1.286     raeburn  11398:                $changes{$item} = 1;
1.203     raeburn  11399:            }
1.28      raeburn  11400:         }
                   11401:         foreach my $type (@mailings) {
                   11402:             if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
                   11403:                 push(@{$changes{$type}},@{$newsetting{$type}});
                   11404:             }
                   11405:             if ($others{$type} ne '') {
                   11406:                 push(@{$changes{$type}},'others');
1.134     raeburn  11407:             }
1.286     raeburn  11408:             if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134     raeburn  11409:                 if ($bcc{$type} ne '') {
                   11410:                     push(@{$changes{$type}},'bcc');
                   11411:                 }
1.286     raeburn  11412:                 if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
                   11413:                     push(@{$changes{$type}},'include');
                   11414:                 }
1.134     raeburn  11415:             }
1.28      raeburn  11416:         }
1.286     raeburn  11417:         if (ref($fields) eq 'ARRAY') {
                   11418:             foreach my $field (@{$fields}) {
                   11419:                 if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
                   11420:                     push(@{$changes{'helpform'}},$field);
                   11421:                 }
                   11422:                 if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
                   11423:                     if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
                   11424:                         push(@{$changes{'helpform'}},'maxsize');
                   11425:                     }
                   11426:                 }
                   11427:             }
1.289     raeburn  11428:         }
1.28      raeburn  11429:     }
1.203     raeburn  11430:     foreach my $item (@toggles) {
                   11431:         if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
                   11432:             $changes{$item} = 1;
                   11433:         } elsif ((!$env{'form.'.$item}) &&
                   11434:                  (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
                   11435:             $changes{$item} = 1;
                   11436:         }
                   11437:     }
1.28      raeburn  11438:     my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
                   11439:                                              $dom);
                   11440:     if ($putresult eq 'ok') {
                   11441:         if (keys(%changes) > 0) {
1.205     raeburn  11442:             &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212     raeburn  11443:             if (ref($lastactref) eq 'HASH') {
                   11444:                 $lastactref->{'domainconfig'} = 1;
                   11445:             }
1.28      raeburn  11446:             my ($titles,$short_titles)  = &contact_titles();
                   11447:             $resulttext = &mt('Changes made:').'<ul>';
                   11448:             foreach my $item (@contacts) {
                   11449:                 if ($changes{$item}) {
                   11450:                     $resulttext .= '<li>'.$titles->{$item}.
                   11451:                                     &mt(' set to: ').
                   11452:                                     '<span class="LC_cusr_emph">'.
                   11453:                                     $to{$item}.'</span></li>';
                   11454:                 }
                   11455:             }
                   11456:             foreach my $type (@mailings) {
                   11457:                 if (ref($changes{$type}) eq 'ARRAY') {
1.286     raeburn  11458:                     if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.289     raeburn  11459:                         $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
1.286     raeburn  11460:                     } else {
                   11461:                         $resulttext .= '<li>'.$titles->{$type}.': ';
                   11462:                     }
1.28      raeburn  11463:                     my @text;
                   11464:                     foreach my $item (@{$newsetting{$type}}) {
                   11465:                         push(@text,$short_titles->{$item});
                   11466:                     }
                   11467:                     if ($others{$type} ne '') {
                   11468:                         push(@text,$others{$type});
                   11469:                     }
1.286     raeburn  11470:                     if (@text) {
                   11471:                         $resulttext .= '<span class="LC_cusr_emph">'.
                   11472:                                        join(', ',@text).'</span>';
                   11473:                     }
                   11474:                     if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134     raeburn  11475:                         if ($bcc{$type} ne '') {
1.286     raeburn  11476:                             my $bcctext;
                   11477:                             if (@text) {
1.289     raeburn  11478:                                 $bcctext = '&nbsp;'.&mt('with Bcc to');
1.286     raeburn  11479:                             } else {
                   11480:                                 $bcctext = '(Bcc)';
                   11481:                             }
                   11482:                             $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
                   11483:                         } elsif (!@text) {
                   11484:                             $resulttext .= &mt('No one');
                   11485:                         }   
1.289     raeburn  11486:                         if ($includestr{$type} ne '') {
1.286     raeburn  11487:                             if ($includeloc{$type} eq 'b') {
                   11488:                                 $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
                   11489:                             } elsif ($includeloc{$type} eq 's') {
                   11490:                                 $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
                   11491:                             }
1.134     raeburn  11492:                         }
1.286     raeburn  11493:                     } elsif (!@text) {
                   11494:                         $resulttext .= &mt('No recipients');
1.134     raeburn  11495:                     }
                   11496:                     $resulttext .= '</li>';
1.28      raeburn  11497:                 }
                   11498:             }
1.315     raeburn  11499:             if (ref($changes{'overrides'}) eq 'ARRAY') {
                   11500:                 my @deletions;
                   11501:                 foreach my $type (@{$changes{'overrides'}}) {
                   11502:                     if ($usertypeshash{$type}) {
                   11503:                         if (grep(/^\Q$type\E/,@overrides)) {
                   11504:                             $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation set for [_1]",
                   11505:                                                       $usertypeshash{$type}).'<ul><li>';
                   11506:                             if (ref($newsetting{'override_'.$type}) eq 'HASH') {
                   11507:                                 my @text;
                   11508:                                 foreach my $item (@contacts) {
                   11509:                                     if ($newsetting{'override_'.$type}{$item}) { 
                   11510:                                         push(@text,$short_titles->{$item});
                   11511:                                     }
                   11512:                                 }
                   11513:                                 if ($newsetting{'override_'.$type}{'others'} ne '') {
                   11514:                                     push(@text,$newsetting{'override_'.$type}{'others'});
                   11515:                                 }
                   11516:   
                   11517:                                 if (@text) {
                   11518:                                     $resulttext .= &mt('Helpdesk e-mail sent to: [_1]',
                   11519:                                                        '<span class="LC_cusr_emph">'.join(', ',@text).'</span>');
                   11520:                                 }
                   11521:                                 if ($newsetting{'override_'.$type}{'bcc'} ne '') {
                   11522:                                     my $bcctext;
                   11523:                                     if (@text) {
                   11524:                                         $bcctext = '&nbsp;'.&mt('with Bcc to');
                   11525:                                     } else {
                   11526:                                         $bcctext = '(Bcc)';
                   11527:                                     }
                   11528:                                     $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$newsetting{'override_'.$type}{'bcc'}.'</span>';
                   11529:                                 } elsif (!@text) {
                   11530:                                      $resulttext .= &mt('Helpdesk e-mail sent to no one');
                   11531:                                 }
                   11532:                                 $resulttext .= '</li>';
                   11533:                                 if ($newsetting{'override_'.$type}{'include'} ne '') {
                   11534:                                     my ($loc,$str) = split(/:/,$newsetting{'override_'.$type}{'include'});
                   11535:                                     if ($loc eq 'b') {
                   11536:                                         $resulttext .= '<li>'.&mt('Text automatically added to e-mail body:').' '.&unescape($str).'</li>';
                   11537:                                     } elsif ($loc eq 's') {
                   11538:                                         $resulttext .= '<li>'.&mt('Text automatically added to e-mail subject:').' '.&unescape($str).'</li>';
                   11539:                                     }
                   11540:                                 }
                   11541:                             }
                   11542:                             $resulttext .= '</li></ul></li>';
                   11543:                         } else {
                   11544:                             push(@deletions,$usertypeshash{$type});
                   11545:                         }
                   11546:                     }
                   11547:                 }
                   11548:                 if (@deletions) {
                   11549:                     $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation discontinued for: [_1]",
                   11550:                                               join(', ',@deletions)).'</li>';
                   11551:                 }
                   11552:             }
1.203     raeburn  11553:             my @offon = ('off','on');
                   11554:             if ($changes{'reporterrors'}) {
                   11555:                 $resulttext .= '<li>'.
                   11556:                                &mt('E-mail error reports to [_1] set to "'.
                   11557:                                    $offon[$env{'form.reporterrors'}].'".',
                   11558:                                    &Apache::loncommon::modal_link('http://loncapa.org/core.html',
                   11559:                                        &mt('LON-CAPA core group - MSU'),600,500)).
                   11560:                                '</li>';
                   11561:             }
                   11562:             if ($changes{'reportupdates'}) {
                   11563:                 $resulttext .= '<li>'.
                   11564:                                 &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
                   11565:                                     $offon[$env{'form.reportupdates'}].'".',
                   11566:                                     &Apache::loncommon::modal_link('http://loncapa.org/core.html',
                   11567:                                         &mt('LON-CAPA core group - MSU'),600,500)).
                   11568:                                 '</li>';
                   11569:             }
1.286     raeburn  11570:             if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
                   11571:                 my (@optional,@required,@unused,$maxsizechg);
                   11572:                 foreach my $field (@{$changes{'helpform'}}) {
                   11573:                     if ($field eq 'maxsize') {
                   11574:                         $maxsizechg = 1;
                   11575:                         next;
                   11576:                     }
                   11577:                     if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
1.289     raeburn  11578:                         push(@optional,$field);
1.286     raeburn  11579:                     } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
                   11580:                         push(@unused,$field);
                   11581:                     } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
1.289     raeburn  11582:                         push(@required,$field);
1.286     raeburn  11583:                     }
                   11584:                 }
                   11585:                 if (@optional) {
                   11586:                     $resulttext .= '<li>'.
                   11587:                                    &mt('Help form fields changed to "Optional": [_1].',
                   11588:                                        '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
                   11589:                                    '</li>';
                   11590:                 }
                   11591:                 if (@required) {
                   11592:                     $resulttext .= '<li>'.
                   11593:                                    &mt('Help form fields changed to "Required": [_1].',
                   11594:                                        '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
                   11595:                                    '</li>';
                   11596:                 }
                   11597:                 if (@unused) {
                   11598:                     $resulttext .= '<li>'.
                   11599:                                    &mt('Help form fields changed to "Not shown": [_1].',
                   11600:                                        '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
                   11601:                                    '</li>';
                   11602:                 }
                   11603:                 if ($maxsizechg) {
                   11604:                     $resulttext .= '<li>'.
                   11605:                                    &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
                   11606:                                        $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
                   11607:                                    '</li>';
                   11608:                 }
                   11609:             }
1.28      raeburn  11610:             $resulttext .= '</ul>';
                   11611:         } else {
1.288     raeburn  11612:             $resulttext = &mt('No changes made to contacts and form settings');
1.28      raeburn  11613:         }
                   11614:     } else {
                   11615:         $resulttext = '<span class="LC_error">'.
                   11616:             &mt('An error occurred: [_1].',$putresult).'</span>';
                   11617:     }
                   11618:     return $resulttext;
                   11619: }
                   11620: 
                   11621: sub modify_usercreation {
1.27      raeburn  11622:     my ($dom,%domconfig) = @_;
1.224     raeburn  11623:     my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43      raeburn  11624:     my $warningmsg;
1.27      raeburn  11625:     if (ref($domconfig{'usercreation'}) eq 'HASH') {
                   11626:         foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224     raeburn  11627:             if ($key eq 'cancreate') {
                   11628:                 if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
                   11629:                     foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
1.303     raeburn  11630:                         if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
                   11631:                             $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
                   11632:                         } else {
1.224     raeburn  11633:                             $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
                   11634:                         }
                   11635:                     }
                   11636:                 }
                   11637:             } elsif ($key eq 'email_rule') {
                   11638:                 $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
                   11639:             } else {
                   11640:                 $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
                   11641:             }
1.27      raeburn  11642:         }
                   11643:     }
                   11644:     my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32      raeburn  11645:     my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224     raeburn  11646:     my @contexts = ('author','course','requestcrs');
1.34      raeburn  11647:     foreach my $item(@contexts) {
1.224     raeburn  11648:         $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93      raeburn  11649:     }
1.34      raeburn  11650:     if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
                   11651:         foreach my $item (@contexts) {
1.224     raeburn  11652:             if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
                   11653:                 push(@{$changes{'cancreate'}},$item);
1.50      raeburn  11654:             }
1.27      raeburn  11655:         }
1.34      raeburn  11656:     } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
                   11657:         foreach my $item (@contexts) {
1.43      raeburn  11658:             if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34      raeburn  11659:                 if ($cancreate{$item} ne 'any') {
                   11660:                     push(@{$changes{'cancreate'}},$item);
                   11661:                 }
                   11662:             } else {
                   11663:                 if ($cancreate{$item} ne 'none') {
                   11664:                     push(@{$changes{'cancreate'}},$item);
                   11665:                 }
1.27      raeburn  11666:             }
                   11667:         }
                   11668:     } else {
1.43      raeburn  11669:         foreach my $item (@contexts)  {
1.34      raeburn  11670:             push(@{$changes{'cancreate'}},$item);
                   11671:         }
1.27      raeburn  11672:     }
1.34      raeburn  11673: 
1.27      raeburn  11674:     if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
                   11675:         foreach my $type (@{$curr_usercreation{'username_rule'}}) {
                   11676:             if (!grep(/^\Q$type\E$/,@username_rule)) {
                   11677:                 push(@{$changes{'username_rule'}},$type);
                   11678:             }
                   11679:         }
                   11680:         foreach my $type (@username_rule) {
                   11681:             if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
                   11682:                 push(@{$changes{'username_rule'}},$type);
                   11683:             }
                   11684:         }
                   11685:     } else {
                   11686:         push(@{$changes{'username_rule'}},@username_rule);
                   11687:     }
                   11688: 
1.32      raeburn  11689:     if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
                   11690:         foreach my $type (@{$curr_usercreation{'id_rule'}}) {
                   11691:             if (!grep(/^\Q$type\E$/,@id_rule)) {
                   11692:                 push(@{$changes{'id_rule'}},$type);
                   11693:             }
                   11694:         }
                   11695:         foreach my $type (@id_rule) {
                   11696:             if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
                   11697:                 push(@{$changes{'id_rule'}},$type);
                   11698:             }
                   11699:         }
                   11700:     } else {
                   11701:         push(@{$changes{'id_rule'}},@id_rule);
                   11702:     }
                   11703: 
1.43      raeburn  11704:     my @authen_contexts = ('author','course','domain');
1.28      raeburn  11705:     my @authtypes = ('int','krb4','krb5','loc');
                   11706:     my %authhash;
1.43      raeburn  11707:     foreach my $item (@authen_contexts) {
1.28      raeburn  11708:         my @authallowed =  &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
                   11709:         foreach my $auth (@authtypes) {
                   11710:             if (grep(/^\Q$auth\E$/,@authallowed)) {
                   11711:                 $authhash{$item}{$auth} = 1;
                   11712:             } else {
                   11713:                 $authhash{$item}{$auth} = 0;
                   11714:             }
                   11715:         }
                   11716:     }
                   11717:     if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43      raeburn  11718:         foreach my $item (@authen_contexts) {
1.28      raeburn  11719:             if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
                   11720:                 foreach my $auth (@authtypes) {
                   11721:                     if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
                   11722:                         push(@{$changes{'authtypes'}},$item);
                   11723:                         last;
                   11724:                     }
                   11725:                 }
                   11726:             }
                   11727:         }
                   11728:     } else {
1.43      raeburn  11729:         foreach my $item (@authen_contexts) {
1.28      raeburn  11730:             push(@{$changes{'authtypes'}},$item);
                   11731:         }
                   11732:     }
                   11733: 
1.224     raeburn  11734:     $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'}; 
                   11735:     $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
                   11736:     $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
                   11737:     $save_usercreate{'id_rule'} = \@id_rule;
                   11738:     $save_usercreate{'username_rule'} = \@username_rule,
                   11739:     $save_usercreate{'authtypes'} = \%authhash;
                   11740: 
1.27      raeburn  11741:     my %usercreation_hash =  (
1.224     raeburn  11742:         usercreation     => \%save_usercreate,
                   11743:     );
1.27      raeburn  11744: 
                   11745:     my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
                   11746:                                              $dom);
1.50      raeburn  11747: 
1.224     raeburn  11748:     if ($putresult eq 'ok') {
                   11749:         if (keys(%changes) > 0) {
                   11750:             $resulttext = &mt('Changes made:').'<ul>';
                   11751:             if (ref($changes{'cancreate'}) eq 'ARRAY') {
                   11752:                 my %lt = &usercreation_types();
                   11753:                 foreach my $type (@{$changes{'cancreate'}}) {
                   11754:                     my $chgtext = $lt{$type}.', ';
                   11755:                     if ($cancreate{$type} eq 'none') {
                   11756:                         $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
                   11757:                     } elsif ($cancreate{$type} eq 'any') {
                   11758:                         $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
                   11759:                     } elsif ($cancreate{$type} eq 'official') {
                   11760:                         $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
                   11761:                     } elsif ($cancreate{$type} eq 'unofficial') {
                   11762:                         $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
                   11763:                     }
                   11764:                     $resulttext .= '<li>'.$chgtext.'</li>';
                   11765:                 }
                   11766:             }
                   11767:             if (ref($changes{'username_rule'}) eq 'ARRAY') {
                   11768:                 my ($rules,$ruleorder) = 
                   11769:                     &Apache::lonnet::inst_userrules($dom,'username');
                   11770:                 my $chgtext = '<ul>';
                   11771:                 foreach my $type (@username_rule) {
                   11772:                     if (ref($rules->{$type}) eq 'HASH') {
                   11773:                         $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
                   11774:                     }
                   11775:                 }
                   11776:                 $chgtext .= '</ul>';
                   11777:                 if (@username_rule > 0) {
                   11778:                     $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';     
                   11779:                 } else {
                   11780:                     $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>'; 
                   11781:                 }
                   11782:             }
                   11783:             if (ref($changes{'id_rule'}) eq 'ARRAY') {
                   11784:                 my ($idrules,$idruleorder) = 
                   11785:                     &Apache::lonnet::inst_userrules($dom,'id');
                   11786:                 my $chgtext = '<ul>';
                   11787:                 foreach my $type (@id_rule) {
                   11788:                     if (ref($idrules->{$type}) eq 'HASH') {
                   11789:                         $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
                   11790:                     }
                   11791:                 }
                   11792:                 $chgtext .= '</ul>';
                   11793:                 if (@id_rule > 0) {
                   11794:                     $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
                   11795:                 } else {
                   11796:                     $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
                   11797:                 }
                   11798:             }
                   11799:             my %authname = &authtype_names();
                   11800:             my %context_title = &context_names();
                   11801:             if (ref($changes{'authtypes'}) eq 'ARRAY') {
                   11802:                 my $chgtext = '<ul>';
                   11803:                 foreach my $type (@{$changes{'authtypes'}}) {
                   11804:                     my @allowed;
                   11805:                     $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
                   11806:                     foreach my $auth (@authtypes) {
                   11807:                         if ($authhash{$type}{$auth}) {
                   11808:                             push(@allowed,$authname{$auth});
                   11809:                         }
                   11810:                     }
                   11811:                     if (@allowed > 0) {
                   11812:                         $chgtext .= join(', ',@allowed).'</li>';
                   11813:                     } else {
                   11814:                         $chgtext .= &mt('none').'</li>';
                   11815:                     }
                   11816:                 }
                   11817:                 $chgtext .= '</ul>';
                   11818:                 $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
                   11819:                 $resulttext .= '</li>';
                   11820:             }
                   11821:             $resulttext .= '</ul>';
                   11822:         } else {
                   11823:             $resulttext = &mt('No changes made to user creation settings');
                   11824:         }
                   11825:     } else {
                   11826:         $resulttext = '<span class="LC_error">'.
                   11827:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   11828:     }
                   11829:     if ($warningmsg ne '') {
                   11830:         $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
                   11831:     }
                   11832:     return $resulttext;
                   11833: }
                   11834: 
                   11835: sub modify_selfcreation {
1.305     raeburn  11836:     my ($dom,$lastactref,%domconfig) = @_;
                   11837:     my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
                   11838:     my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
                   11839:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.303     raeburn  11840:     my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
                   11841:     if (ref($typesref) eq 'ARRAY') {
                   11842:         @types = @{$typesref};
                   11843:     }
                   11844:     if (ref($usertypesref) eq 'HASH') {
                   11845:         %usertypes = %{$usertypesref};
1.228     raeburn  11846:     }
1.303     raeburn  11847:     $usertypes{'default'} = $othertitle;
1.224     raeburn  11848: #
                   11849: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
                   11850: #
                   11851:     if (ref($domconfig{'usercreation'}) eq 'HASH') {
                   11852:         foreach my $key (keys(%{$domconfig{'usercreation'}})) {
                   11853:             if ($key eq 'cancreate') {
                   11854:                 if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
                   11855:                     foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
                   11856:                         if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.303     raeburn  11857:                             ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
                   11858:                             ($item eq 'recaptchaversion') || ($item eq 'notify') ||
                   11859:                             ($item eq 'emailusername') || ($item eq 'shibenv') ||
                   11860:                             ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
1.305     raeburn  11861:                             ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
1.224     raeburn  11862:                             $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
                   11863:                         } else {
                   11864:                             $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
                   11865:                         }
                   11866:                     }
                   11867:                 }
                   11868:             } elsif ($key eq 'email_rule') {
                   11869:                 $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
                   11870:             } else {
                   11871:                 $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
                   11872:             }
                   11873:         }
                   11874:     }
                   11875: #
                   11876: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
                   11877: #
                   11878:     if (ref($domconfig{'usermodification'}) eq 'HASH') {
                   11879:         foreach my $key (keys(%{$domconfig{'usermodification'}})) {
                   11880:             if ($key eq 'selfcreate') {
                   11881:                 $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
                   11882:             } else {
                   11883:                 $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
                   11884:             }
                   11885:         }
                   11886:     }
1.305     raeburn  11887: #
                   11888: # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
                   11889: #
                   11890:     if (ref($domconfig{'inststatus'}) eq 'HASH') {
                   11891:         foreach my $key (keys(%{$domconfig{'inststatus'}})) {
                   11892:             if ($key eq 'inststatusguest') {
                   11893:                 $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
                   11894:             } else {
                   11895:                 $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
                   11896:             }
                   11897:         }
                   11898:     }
1.224     raeburn  11899: 
                   11900:     my @contexts = ('selfcreate');
                   11901:     @{$cancreate{'selfcreate'}} = ();
                   11902:     %{$cancreate{'emailusername'}} = ();
1.305     raeburn  11903:     if (@types) {
                   11904:         @{$cancreate{'statustocreate'}} = ();
                   11905:     }
1.236     raeburn  11906:     %{$cancreate{'selfcreateprocessing'}} = ();
1.240     raeburn  11907:     %{$cancreate{'shibenv'}} = ();
1.303     raeburn  11908:     %{$cancreate{'emailverified'}} = ();
1.305     raeburn  11909:     %{$cancreate{'emailoptions'}} = ();
1.303     raeburn  11910:     %{$cancreate{'emaildomain'}} = ();
1.50      raeburn  11911:     my %selfcreatetypes = (
                   11912:                              sso   => 'users authenticated by institutional single sign on',
                   11913:                              login => 'users authenticated by institutional log-in',
1.303     raeburn  11914:                              email => 'users verified by e-mail',
1.50      raeburn  11915:                           );
1.224     raeburn  11916: #
                   11917: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
                   11918: # is permitted.
                   11919: #
1.305     raeburn  11920:     my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
1.236     raeburn  11921: 
1.305     raeburn  11922:     my (@statuses,%email_rule);
1.228     raeburn  11923:     foreach my $item ('login','sso','email') {
1.224     raeburn  11924:         if ($item eq 'email') {
1.236     raeburn  11925:             if ($env{'form.cancreate_email'}) {
1.305     raeburn  11926:                 if (@types) {
                   11927:                     my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
                   11928:                     foreach my $status (@poss_statuses) {
                   11929:                         if (grep(/^\Q$status\E$/,(@types,'default'))) {
                   11930:                             push(@statuses,$status);
                   11931:                         }
                   11932:                     }
                   11933:                     $save_inststatus{'inststatusguest'} = \@statuses;
                   11934:                 } else {
                   11935:                     push(@statuses,'default');
                   11936:                 }
                   11937:                 if (@statuses) {
                   11938:                     my %curr_rule;
                   11939:                     if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
                   11940:                         foreach my $type (@statuses) {
                   11941:                             $curr_rule{$type} = $curr_usercreation{'email_rule'};
1.303     raeburn  11942:                         }
1.305     raeburn  11943:                     } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
                   11944:                         foreach my $type (@statuses) {
                   11945:                             $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
                   11946:                         }
                   11947:                     }
                   11948:                     push(@{$cancreate{'selfcreate'}},'email');
                   11949:                     push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
                   11950:                     my %curremaildom;
                   11951:                     if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
                   11952:                         %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
                   11953:                     }
                   11954:                     foreach my $type (@statuses) {
                   11955:                         if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
                   11956:                             $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
                   11957:                         }
                   11958:                         if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
                   11959:                             $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
                   11960:                         }
                   11961:                         if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
                   11962: #
                   11963: # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
                   11964: #
                   11965:                             my $chosen = $1;
                   11966:                             if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
                   11967:                                 my $emaildom;
                   11968:                                 if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
                   11969:                                     $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type}; 
                   11970:                                     $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
                   11971:                                     if (ref($curremaildom{$type}) eq 'HASH') {
                   11972:                                         if (exists($curremaildom{$type}{$chosen})) {
                   11973:                                             if ($curremaildom{$type}{$chosen} ne $emaildom) {
                   11974:                                                 push(@{$changes{'cancreate'}},'emaildomain');
                   11975:                                             }
                   11976:                                         } elsif ($emaildom ne '') {
                   11977:                                             push(@{$changes{'cancreate'}},'emaildomain');
                   11978:                                         }
                   11979:                                     } elsif ($emaildom ne '') {
                   11980:                                         push(@{$changes{'cancreate'}},'emaildomain');
                   11981:                                     } 
                   11982:                                 }
                   11983:                                 $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
                   11984:                             } elsif ($chosen eq 'custom') {
                   11985:                                 my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
                   11986:                                 $email_rule{$type} = [];
                   11987:                                 if (ref($emailrules) eq 'HASH') {
                   11988:                                     foreach my $rule (@possemail_rules) {
                   11989:                                         if (exists($emailrules->{$rule})) {
                   11990:                                             push(@{$email_rule{$type}},$rule);
                   11991:                                         }
                   11992:                                     }
                   11993:                                 }
                   11994:                                 if (@{$email_rule{$type}}) {
                   11995:                                     $cancreate{'emailoptions'}{$type} = 'custom';
                   11996:                                     if (ref($curr_rule{$type}) eq 'ARRAY') {
                   11997:                                         if (@{$curr_rule{$type}} > 0) {
                   11998:                                             foreach my $rule (@{$curr_rule{$type}}) {
                   11999:                                                 if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
                   12000:                                                     push(@{$changes{'email_rule'}},$type);
                   12001:                                                 }
                   12002:                                             }
                   12003:                                         }
                   12004:                                         foreach my $type (@{$email_rule{$type}}) {
                   12005:                                             if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
                   12006:                                                 push(@{$changes{'email_rule'}},$type);
                   12007:                                             }
                   12008:                                         }
                   12009:                                     } else {
                   12010:                                         push(@{$changes{'email_rule'}},$type);
                   12011:                                     }
                   12012:                                 }
                   12013:                             } else {
                   12014:                                 $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
                   12015:                             }
                   12016:                         }
                   12017:                     }
                   12018:                     if (@types) {
                   12019:                         if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
                   12020:                             my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
                   12021:                             if (@changed) {
                   12022:                                 push(@{$changes{'inststatus'}},'inststatusguest');
                   12023:                             }
                   12024:                         } else {
                   12025:                             push(@{$changes{'inststatus'}},'inststatusguest');
                   12026:                         }
                   12027:                     }
                   12028:                 } else {
                   12029:                     delete($env{'form.cancreate_email'});
                   12030:                     if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
                   12031:                         if (@{$curr_inststatus{'inststatusguest'}} > 0) {
                   12032:                             push(@{$changes{'inststatus'}},'inststatusguest');
                   12033:                         }
                   12034:                     }
                   12035:                 }
                   12036:             } else {
                   12037:                 $save_inststatus{'inststatusguest'} = [];
                   12038:                 if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
                   12039:                     if (@{$curr_inststatus{'inststatusguest'}} > 0) {
                   12040:                         push(@{$changes{'inststatus'}},'inststatusguest');
1.236     raeburn  12041:                     }
                   12042:                 }
1.224     raeburn  12043:             }
                   12044:         } else {
                   12045:             if ($env{'form.cancreate_'.$item}) {
                   12046:                 push(@{$cancreate{'selfcreate'}},$item);
                   12047:             }
                   12048:         }
                   12049:     }
1.305     raeburn  12050:     my (%userinfo,%savecaptcha);
1.224     raeburn  12051:     my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
                   12052: #
1.228     raeburn  12053: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
                   12054: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.224     raeburn  12055: #
1.236     raeburn  12056: 
1.244     raeburn  12057:     if ($env{'form.cancreate_email'}) {
1.228     raeburn  12058:         push(@contexts,'emailusername');
1.305     raeburn  12059:         if (@statuses) {
                   12060:             foreach my $type (@statuses) {
1.228     raeburn  12061:                 if (ref($infofields) eq 'ARRAY') {
                   12062:                     foreach my $field (@{$infofields}) {
                   12063:                         if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
                   12064:                             $cancreate{'emailusername'}{$type}{$field} = $1;
                   12065:                         }
                   12066:                     }
1.224     raeburn  12067:                 }
                   12068:             }
                   12069:         }
                   12070: #
                   12071: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
1.303     raeburn  12072: # queued requests for self-creation of account verified by e-mail.
1.224     raeburn  12073: #
                   12074: 
                   12075:         my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
                   12076:         @approvalnotify = sort(@approvalnotify);
                   12077:         $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
                   12078:         if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
                   12079:             if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
                   12080:                 if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
                   12081:                     push(@{$changes{'cancreate'}},'notify');
                   12082:                 }
                   12083:             } else {
                   12084:                 if ($cancreate{'notify'}{'approval'}) {
                   12085:                     push(@{$changes{'cancreate'}},'notify');
                   12086:                 }
                   12087:             }
                   12088:         } elsif ($cancreate{'notify'}{'approval'}) {
                   12089:             push(@{$changes{'cancreate'}},'notify');
                   12090:         }
                   12091: 
                   12092:         &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
                   12093:     }
                   12094: #  
1.236     raeburn  12095: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.224     raeburn  12096: # institutional log-in.
                   12097: #
                   12098:     if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
                   12099:         if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) || 
                   12100:                ($domdefaults{'auth_def'} eq 'localauth'))) {
                   12101:             $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.').' '.
                   12102:                           &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.');
                   12103:         }
                   12104:     }
                   12105:     my @fields = ('lastname','firstname','middlename','generation',
                   12106:                   'permanentemail','id');
1.240     raeburn  12107:     my @shibfields = (@fields,'inststatus');
1.224     raeburn  12108:     my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
                   12109: #
                   12110: # Where usernames may created for institutional log-in and/or institutional single sign on:
                   12111: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
                   12112: # may self-create accounts 
                   12113: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
                   12114: # which the user may supply, if institutional data is unavailable.
                   12115: #
                   12116:     if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
1.303     raeburn  12117:         if (@types) {
1.305     raeburn  12118:             @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
                   12119:             push(@contexts,'statustocreate');
1.303     raeburn  12120:             foreach my $type (@types) {
1.224     raeburn  12121:                 my @modifiable =  &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
                   12122:                 foreach my $field (@fields) {
                   12123:                     if (grep(/^\Q$field\E$/,@modifiable)) {
                   12124:                         $save_usermodify{'selfcreate'}{$type}{$field} = 1;
                   12125:                     } else {
                   12126:                         $save_usermodify{'selfcreate'}{$type}{$field} = 0;
                   12127:                     }
                   12128:                 }
                   12129:             }
                   12130:             if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
1.303     raeburn  12131:                 foreach my $type (@types) {
1.224     raeburn  12132:                     if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
                   12133:                         foreach my $field (@fields) {
                   12134:                             if ($save_usermodify{'selfcreate'}{$type}{$field} ne
                   12135:                                 $curr_usermodify{'selfcreate'}{$type}{$field}) {
                   12136:                                 push(@{$changes{'selfcreate'}},$type);
                   12137:                                 last;
                   12138:                             }
                   12139:                         }
                   12140:                     }
                   12141:                 }
                   12142:             } else {
1.303     raeburn  12143:                 foreach my $type (@types) {
1.224     raeburn  12144:                     push(@{$changes{'selfcreate'}},$type);
                   12145:                 }
                   12146:             }
                   12147:         }
1.240     raeburn  12148:         foreach my $field (@shibfields) {
                   12149:             if ($env{'form.shibenv_'.$field} ne '') {
                   12150:                 $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
                   12151:             }
                   12152:         }
                   12153:         if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
                   12154:             if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
                   12155:                 foreach my $field (@shibfields) {
                   12156:                     if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
                   12157:                         push(@{$changes{'cancreate'}},'shibenv');
                   12158:                     }
                   12159:                 }
                   12160:             } else {
                   12161:                 foreach my $field (@shibfields) {
                   12162:                     if ($env{'form.shibenv_'.$field}) {
                   12163:                         push(@{$changes{'cancreate'}},'shibenv');
                   12164:                         last;
                   12165:                     }
                   12166:                 }
                   12167:             }
                   12168:         }
1.224     raeburn  12169:     }
                   12170:     foreach my $item (@contexts) {
                   12171:         if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
                   12172:             foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
                   12173:                 if (ref($cancreate{$item}) eq 'ARRAY') {
                   12174:                     if (!grep(/^$curr$/,@{$cancreate{$item}})) {
                   12175:                         if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   12176:                             push(@{$changes{'cancreate'}},$item);
                   12177:                         }
                   12178:                     }
                   12179:                 }
                   12180:             }
                   12181:             if (ref($cancreate{$item}) eq 'ARRAY') {
                   12182:                 foreach my $type (@{$cancreate{$item}}) {
                   12183:                     if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
                   12184:                         if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   12185:                             push(@{$changes{'cancreate'}},$item);
                   12186:                         }
                   12187:                     }
                   12188:                 }
                   12189:             }
                   12190:         } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
                   12191:             if (ref($cancreate{$item}) eq 'HASH') {
1.305     raeburn  12192:                 foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
                   12193:                     if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
                   12194:                         foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
                   12195:                             unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228     raeburn  12196:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   12197:                                     push(@{$changes{'cancreate'}},$item);
                   12198:                                 }
                   12199:                             }
                   12200:                         }
1.305     raeburn  12201:                     } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
                   12202:                         if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228     raeburn  12203:                             if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   12204:                                 push(@{$changes{'cancreate'}},$item);
                   12205:                             }
1.224     raeburn  12206:                         }
                   12207:                     }
                   12208:                 }
1.305     raeburn  12209:                 foreach my $type (keys(%{$cancreate{$item}})) {
                   12210:                     if (ref($cancreate{$item}{$type}) eq 'HASH') {
                   12211:                         foreach my $field (keys(%{$cancreate{$item}{$type}})) {
                   12212:                             if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
                   12213:                                 unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228     raeburn  12214:                                     if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   12215:                                         push(@{$changes{'cancreate'}},$item);
                   12216:                                     }
                   12217:                                 }
                   12218:                             } else {
                   12219:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   12220:                                     push(@{$changes{'cancreate'}},$item);
                   12221:                                 }
                   12222:                             }
                   12223:                         }
1.305     raeburn  12224:                     } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
                   12225:                         if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228     raeburn  12226:                             if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   12227:                                 push(@{$changes{'cancreate'}},$item);
                   12228:                             }
1.224     raeburn  12229:                         }
                   12230:                     }
                   12231:                 }
                   12232:             }
                   12233:         } elsif ($curr_usercreation{'cancreate'}{$item}) {
                   12234:             if (ref($cancreate{$item}) eq 'ARRAY') {
                   12235:                 if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
                   12236:                     if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   12237:                         push(@{$changes{'cancreate'}},$item);
                   12238:                     }
                   12239:                 }
1.305     raeburn  12240:             }
                   12241:         } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
                   12242:             if (ref($cancreate{$item}) eq 'HASH') {
                   12243:                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   12244:                     push(@{$changes{'cancreate'}},$item);
1.224     raeburn  12245:                 }
                   12246:             }
                   12247:         } elsif ($item eq 'emailusername') {
1.228     raeburn  12248:             if (ref($cancreate{$item}) eq 'HASH') {
                   12249:                 foreach my $type (keys(%{$cancreate{$item}})) {
                   12250:                     if (ref($cancreate{$item}{$type}) eq 'HASH') {
                   12251:                         foreach my $field (keys(%{$cancreate{$item}{$type}})) {
                   12252:                             if ($cancreate{$item}{$type}{$field}) {
                   12253:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   12254:                                     push(@{$changes{'cancreate'}},$item);
                   12255:                                 }
                   12256:                                 last;
                   12257:                             }
                   12258:                         }
                   12259:                     }
                   12260:                 }
1.224     raeburn  12261:             }
                   12262:         }
                   12263:     }
                   12264: #
                   12265: # Populate %save_usercreate hash with updates to self-creation configuration.
                   12266: #
                   12267:     $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
                   12268:     $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.269     raeburn  12269:     $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.224     raeburn  12270:     $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
                   12271:     if (ref($cancreate{'notify'}) eq 'HASH') {
                   12272:         $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
                   12273:     }
1.236     raeburn  12274:     if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
                   12275:         $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
                   12276:     }
1.303     raeburn  12277:     if (ref($cancreate{'emailverified'}) eq 'HASH') {
                   12278:         $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
                   12279:     }
1.305     raeburn  12280:     if (ref($cancreate{'emailoptions'}) eq 'HASH') {
                   12281:         $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
                   12282:     }
1.303     raeburn  12283:     if (ref($cancreate{'emaildomain'}) eq 'HASH') {
                   12284:         $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
                   12285:     }
1.224     raeburn  12286:     if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
                   12287:         $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
                   12288:     }
1.240     raeburn  12289:     if (ref($cancreate{'shibenv'}) eq 'HASH') {
                   12290:         $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
                   12291:     }
1.224     raeburn  12292:     $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.305     raeburn  12293:     $save_usercreate{'email_rule'} = \%email_rule;
1.224     raeburn  12294: 
                   12295:     my %userconfig_hash = (
                   12296:             usercreation     => \%save_usercreate,
                   12297:             usermodification => \%save_usermodify,
1.305     raeburn  12298:             inststatus       => \%save_inststatus,
1.224     raeburn  12299:     );
1.305     raeburn  12300: 
1.224     raeburn  12301:     my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
                   12302:                                              $dom);
                   12303: #
1.305     raeburn  12304: # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
1.224     raeburn  12305: #
1.27      raeburn  12306:     if ($putresult eq 'ok') {
                   12307:         if (keys(%changes) > 0) {
                   12308:             $resulttext = &mt('Changes made:').'<ul>';
                   12309:             if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224     raeburn  12310:                 my %lt = &selfcreation_types();
1.34      raeburn  12311:                 foreach my $type (@{$changes{'cancreate'}}) {
1.303     raeburn  12312:                     my $chgtext = '';
1.45      raeburn  12313:                     if ($type eq 'selfcreate') {
1.50      raeburn  12314:                         if (@{$cancreate{$type}} == 0) {
1.224     raeburn  12315:                             $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50      raeburn  12316:                         } else {
1.224     raeburn  12317:                             $chgtext .= &mt('Self-creation of a new account is permitted for:').
                   12318:                                         '<ul>';
1.50      raeburn  12319:                             foreach my $case (@{$cancreate{$type}}) {
                   12320:                                 $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
                   12321:                             }
                   12322:                             $chgtext .= '</ul>';
1.100     raeburn  12323:                             if (ref($cancreate{$type}) eq 'ARRAY') {
                   12324:                                 if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
                   12325:                                     if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
                   12326:                                         if (@{$cancreate{'statustocreate'}} == 0) {
1.303     raeburn  12327:                                             $chgtext .= '<span class="LC_warning">'.
                   12328:                                                         &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
                   12329:                                                         '</span><br />';
                   12330:                                         }
                   12331:                                     }
                   12332:                                 }
                   12333:                                 if (grep(/^email$/,@{$cancreate{$type}})) {
1.305     raeburn  12334:                                     if (!@statuses) {
                   12335:                                         $chgtext .= '<span class="LC_warning">'.
                   12336:                                                     &mt("However, e-mail verification is currently set to 'unavailable' for all user types (including 'other'), so self-creation of accounts is not possible for non-institutional log-in.").
                   12337:                                                     '</span><br />';
1.303     raeburn  12338: 
1.100     raeburn  12339:                                     }
                   12340:                                 }
                   12341:                             }
1.43      raeburn  12342:                         }
1.240     raeburn  12343:                     } elsif ($type eq 'shibenv') {
                   12344:                         if (keys(%{$cancreate{$type}}) == 0) {
1.303     raeburn  12345:                             $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />'; 
1.240     raeburn  12346:                         } else {
                   12347:                             $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
                   12348:                                         '<ul>';
                   12349:                             foreach my $field (@shibfields) {
                   12350:                                 next if ($cancreate{$type}{$field} eq '');
                   12351:                                 if ($field eq 'inststatus') {
                   12352:                                     $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
                   12353:                                 } else {
                   12354:                                     $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
                   12355:                                 }
                   12356:                             }
                   12357:                             $chgtext .= '</ul>';
1.303     raeburn  12358:                         }
1.93      raeburn  12359:                     } elsif ($type eq 'statustocreate') {
1.96      raeburn  12360:                         if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
                   12361:                             (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
                   12362:                             if (@{$cancreate{'selfcreate'}} > 0) {
                   12363:                                 if (@{$cancreate{'statustocreate'}} == 0) {
1.100     raeburn  12364:                                     $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96      raeburn  12365:                                     if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224     raeburn  12366:                                         $chgtext .= '<br />'.
                   12367:                                                     '<span class="LC_warning">'.
                   12368:                                                     &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
                   12369:                                                     '</span>';
                   12370:                                     }
1.303     raeburn  12371:                                 } elsif (keys(%usertypes) > 0) {
1.96      raeburn  12372:                                     if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100     raeburn  12373:                                         $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
                   12374:                                     } else {
                   12375:                                         $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
                   12376:                                     }
                   12377:                                     $chgtext .= '<ul>';
                   12378:                                     foreach my $case (@{$cancreate{$type}}) {
                   12379:                                         if ($case eq 'default') {
                   12380:                                             $chgtext .= '<li>'.$othertitle.'</li>';
                   12381:                                         } else {
1.303     raeburn  12382:                                             $chgtext .= '<li>'.$usertypes{$case}.'</li>';
1.93      raeburn  12383:                                         }
                   12384:                                     }
1.100     raeburn  12385:                                     $chgtext .= '</ul>';
                   12386:                                     if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.303     raeburn  12387:                                         $chgtext .= '<span class="LC_warning">'.
1.224     raeburn  12388:                                                     &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
                   12389:                                                     '</span>';
1.100     raeburn  12390:                                     }
                   12391:                                 }
                   12392:                             } else {
                   12393:                                 if (@{$cancreate{$type}} == 0) {
                   12394:                                     $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
                   12395:                                 } else {
                   12396:                                     $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  12397:                                 }
                   12398:                             }
1.303     raeburn  12399:                             $chgtext .= '<br />';
1.93      raeburn  12400:                         }
1.236     raeburn  12401:                     } elsif ($type eq 'selfcreateprocessing') {
                   12402:                         my %choices = &Apache::lonlocal::texthash (
                   12403:                                                                     automatic => 'Automatic approval',
                   12404:                                                                     approval  => 'Queued for approval',
                   12405:                                                                   );
1.305     raeburn  12406:                         if (@types) {
                   12407:                             if (@statuses) {
1.303     raeburn  12408:                                 $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:'). 
1.309     raeburn  12409:                                             '<ul>';
1.305     raeburn  12410:                                 foreach my $status (@statuses) {
                   12411:                                     if ($status eq 'default') {
                   12412:                                         $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303     raeburn  12413:                                     } else {
1.305     raeburn  12414:                                         $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303     raeburn  12415:                                     }
                   12416:                                 }
                   12417:                                 $chgtext .= '</ul>';
                   12418:                             }
                   12419:                         } else {
                   12420:                             $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
                   12421:                                             $choices{$cancreate{'selfcreateprocessing'}{'default'}});
                   12422:                         }
                   12423:                     } elsif ($type eq 'emailverified') {
                   12424:                         my %options = &Apache::lonlocal::texthash (
1.305     raeburn  12425:                                                                     all   => 'Same as e-mail',
                   12426:                                                                     first => 'Omit @domain',
                   12427:                                                                     free  => 'Free to choose',
1.303     raeburn  12428:                                                                   );
1.305     raeburn  12429:                         if (@types) {
                   12430:                             if (@statuses) {
1.303     raeburn  12431:                                 $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
                   12432:                                             '<ul>';
1.305     raeburn  12433:                                 foreach my $status (@statuses) {
1.303     raeburn  12434:                                     if ($type eq 'default') {
1.305     raeburn  12435:                                         $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303     raeburn  12436:                                     } else {
1.305     raeburn  12437:                                         $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303     raeburn  12438:                                     }
                   12439:                                 }
                   12440:                                 $chgtext .= '</ul>';
                   12441:                             }
                   12442:                         } else {
1.305     raeburn  12443:                             $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
1.304     raeburn  12444:                                             $options{$cancreate{'emailverified'}{'default'}});
1.303     raeburn  12445:                         }
1.305     raeburn  12446:                     } elsif ($type eq 'emailoptions') {
                   12447:                         my %options = &Apache::lonlocal::texthash (
                   12448:                                                                     any     => 'Any e-mail',
                   12449:                                                                     inst    => 'Institutional only',
                   12450:                                                                     noninst => 'Non-institutional only',
                   12451:                                                                     custom  => 'Custom restrictions',
                   12452:                                                                   );
                   12453:                         if (@types) {
                   12454:                             if (@statuses) {
                   12455:                                 $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
                   12456:                                             '<ul>';
                   12457:                                 foreach my $status (@statuses) {
                   12458:                                     if ($type eq 'default') {
                   12459:                                         $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
                   12460:                                     } else {
                   12461:                                         $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
1.303     raeburn  12462:                                     }
                   12463:                                 }
1.305     raeburn  12464:                                 $chgtext .= '</ul>';
                   12465:                             }
                   12466:                         } else {
                   12467:                             if ($cancreate{'emailoptions'}{'default'} eq 'any') {
                   12468:                                 $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
                   12469:                             } else {
                   12470:                                 $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
                   12471:                                                 $options{$cancreate{'emailoptions'}{'default'}});
1.303     raeburn  12472:                             }
1.305     raeburn  12473:                         }
                   12474:                     } elsif ($type eq 'emaildomain') {
                   12475:                         my $output;
                   12476:                         if (@statuses) {
                   12477:                             foreach my $type (@statuses) {
                   12478:                                 if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
                   12479:                                     if ($cancreate{'emailoptions'}{$type} eq 'inst') {
                   12480:                                         if ($type eq 'default') {
                   12481:                                             if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
                   12482:                                                 ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
                   12483:                                                 $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
                   12484:                                             } else {
                   12485:                                                 $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
                   12486:                                                                                         $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
                   12487:                                             }
1.303     raeburn  12488:                                         } else {
1.305     raeburn  12489:                                             if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
                   12490:                                                 ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
                   12491:                                                 $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
                   12492:                                             } else {
                   12493:                                                 $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
                   12494:                                                                                               $cancreate{'emaildomain'}{$type}{'inst'}).'</li>'; 
                   12495:                                             }
1.303     raeburn  12496:                                         }
1.305     raeburn  12497:                                     } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
                   12498:                                         if ($type eq 'default') {
                   12499:                                             if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
                   12500:                                                 ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
                   12501:                                                 $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
                   12502:                                             } else {
                   12503:                                                 $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
                   12504:                                                                                         $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
                   12505:                                             }
1.303     raeburn  12506:                                         } else {
1.305     raeburn  12507:                                             if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
                   12508:                                                 ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
                   12509:                                                 $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
                   12510:                                             } else {
                   12511:                                                 $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
                   12512:                                                                                                 $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';   
                   12513:                                             }
1.303     raeburn  12514:                                         }
                   12515:                                     }
                   12516:                                 }
                   12517:                             }
1.305     raeburn  12518:                         }
                   12519:                         if ($output ne '') {
                   12520:                             $chgtext .= &mt('For self-created accounts verified by e-mail address:').
                   12521:                                         '<ul>'.$output.'</ul>';
1.236     raeburn  12522:                         }
1.165     raeburn  12523:                     } elsif ($type eq 'captcha') {
1.224     raeburn  12524:                         if ($savecaptcha{$type} eq 'notused') {
1.165     raeburn  12525:                             $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
                   12526:                         } else {
                   12527:                             my %captchas = &captcha_phrases();
1.224     raeburn  12528:                             if ($captchas{$savecaptcha{$type}}) {
                   12529:                                 $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165     raeburn  12530:                             } else {
1.210     raeburn  12531:                                 $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165     raeburn  12532:                             }
                   12533:                         }
                   12534:                     } elsif ($type eq 'recaptchakeys') {
                   12535:                         my ($privkey,$pubkey);
1.224     raeburn  12536:                         if (ref($savecaptcha{$type}) eq 'HASH') {
                   12537:                             $pubkey = $savecaptcha{$type}{'public'};
                   12538:                             $privkey = $savecaptcha{$type}{'private'};
1.165     raeburn  12539:                         }
                   12540:                         $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
                   12541:                         if (!$pubkey) {
                   12542:                             $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
                   12543:                         } else {
                   12544:                             $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
                   12545:                         }
                   12546:                         if (!$privkey) {
                   12547:                             $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
                   12548:                         } else {
                   12549:                             $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
                   12550:                         }
                   12551:                         $chgtext .= '</ul>';
1.269     raeburn  12552:                     } elsif ($type eq 'recaptchaversion') {
                   12553:                         if ($savecaptcha{'captcha'} eq 'recaptcha') {
1.270     raeburn  12554:                             $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
1.269     raeburn  12555:                         }
1.224     raeburn  12556:                     } elsif ($type eq 'emailusername') {
                   12557:                         if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.305     raeburn  12558:                             if (@statuses) {
                   12559:                                 foreach my $type (@statuses) {
1.228     raeburn  12560:                                     if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
                   12561:                                         if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.303     raeburn  12562:                                             $chgtext .= &mt('When self-creating account with e-mail verification, the following information will be provided by [_1]:',"'$usertypes{$type}'").
1.228     raeburn  12563:                                                     '<ul>';
                   12564:                                             foreach my $field (@{$infofields}) {
                   12565:                                                 if ($cancreate{'emailusername'}{$type}{$field}) {
                   12566:                                                     $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
                   12567:                                                 }
                   12568:                                             }
1.245     raeburn  12569:                                             $chgtext .= '</ul>';
                   12570:                                         } else {
1.303     raeburn  12571:                                             $chgtext .= &mt('When self creating account with e-mail verification, no information besides e-mail address will be provided by [_1].',"'$usertypes{$type}'").'<br />';
1.228     raeburn  12572:                                         }
                   12573:                                     } else {
1.303     raeburn  12574:                                         $chgtext .= &mt('When self creating account with e-mail verification, no information besides e-mail address will be provided by [_1].',"'$usertypes{$type}'").'<br />';
1.224     raeburn  12575:                                     }
                   12576:                                 }
                   12577:                             }
                   12578:                         }
                   12579:                     } elsif ($type eq 'notify') {
1.303     raeburn  12580:                         my $numapprove = 0;
1.224     raeburn  12581:                         if (ref($changes{'cancreate'}) eq 'ARRAY') {
                   12582:                             if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
                   12583:                                 if ($cancreate{'notify'}{'approval'}) {
1.303     raeburn  12584:                                     $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
                   12585:                                     $numapprove ++;
1.224     raeburn  12586:                                 }
                   12587:                             }
1.43      raeburn  12588:                         }
1.303     raeburn  12589:                         unless ($numapprove) {
                   12590:                             $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
                   12591:                         }
1.34      raeburn  12592:                     }
1.224     raeburn  12593:                     if ($chgtext) {
                   12594:                         $resulttext .= '<li>'.$chgtext.'</li>';
1.32      raeburn  12595:                     }
                   12596:                 }
                   12597:             }
1.305     raeburn  12598:             if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
1.43      raeburn  12599:                 my ($emailrules,$emailruleorder) =
                   12600:                     &Apache::lonnet::inst_userrules($dom,'email');
1.305     raeburn  12601:                 foreach my $type (@{$changes{'email_rule'}}) {
                   12602:                     if (ref($email_rule{$type}) eq 'ARRAY') {
                   12603:                         my $chgtext = '<ul>';
                   12604:                         foreach my $rule (@{$email_rule{$type}}) {
                   12605:                             if (ref($emailrules->{$rule}) eq 'HASH') {
                   12606:                                 $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
                   12607:                             }
                   12608:                         }
                   12609:                         $chgtext .= '</ul>';
1.310     raeburn  12610:                         my $typename;
1.305     raeburn  12611:                         if (@types) {
                   12612:                             if ($type eq 'default') {
                   12613:                                 $typename = $othertitle;
                   12614:                             } else {
                   12615:                                 $typename = $usertypes{$type};
                   12616:                             } 
                   12617:                             $chgtext .= &mt('(Affiliation: [_1])',$typename);
                   12618:                         }
                   12619:                         if (@{$email_rule{$type}} > 0) {
                   12620:                             $resulttext .= '<li>'.
                   12621:                                            &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
                   12622:                                                $usertypes{$type}).
                   12623:                                            $chgtext.
                   12624:                                            '</li>';
                   12625:                         } else {
                   12626:                             $resulttext .= '<li>'.
1.310     raeburn  12627:                                            &mt('There are now no restrictions on e-mail addresses which may be used for verification when a user requests an account.').
1.305     raeburn  12628:                                            '</li>'.
1.310     raeburn  12629:                                            &mt('(Affiliation: [_1])',$typename);
1.305     raeburn  12630:                         }
1.43      raeburn  12631:                     }
                   12632:                 }
1.305     raeburn  12633:             }
                   12634:             if (ref($changes{'inststatus'}) eq 'ARRAY') {
                   12635:                 if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
                   12636:                     if (@{$save_inststatus{'inststatusguest'}} > 0) {
                   12637:                         my $chgtext = '<ul>';
                   12638:                         foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
                   12639:                             $chgtext .= '<li>'.$usertypes{$type}.'</li>';
                   12640:                         }
                   12641:                         $chgtext .= '</ul>';
                   12642:                         $resulttext .= '<li>'.
                   12643:                                        &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
                   12644:                                           $chgtext.
                   12645:                                        '</li>';
                   12646:                     } else {
                   12647:                         $resulttext .= '<li>'.
                   12648:                                        &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
                   12649:                                        '</li>';
                   12650:                     }
1.43      raeburn  12651:                 }
                   12652:             }
1.224     raeburn  12653:             if (ref($changes{'selfcreate'}) eq 'ARRAY') {
                   12654:                 $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
                   12655:                 my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
                   12656:                 foreach my $type (@{$changes{'selfcreate'}}) {
                   12657:                     my $typename = $type;
1.303     raeburn  12658:                     if (keys(%usertypes) > 0) {
                   12659:                         if ($usertypes{$type} ne '') {
                   12660:                             $typename = $usertypes{$type};
1.224     raeburn  12661:                         }
                   12662:                     }
                   12663:                     my @modifiable;
                   12664:                     $resulttext .= '<li>'.
                   12665:                                     &mt('Self-creation of account by users with status: [_1]',
                   12666:                                         '<span class="LC_cusr_emph">'.$typename.'</span>').
                   12667:                                     ' - '.&mt('modifiable fields (if institutional data blank): ');
                   12668:                     foreach my $field (@fields) {
                   12669:                         if ($save_usermodify{'selfcreate'}{$type}{$field}) {
                   12670:                             push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28      raeburn  12671:                         }
                   12672:                     }
1.224     raeburn  12673:                     if (@modifiable > 0) {
                   12674:                         $resulttext .= join(', ',@modifiable);
1.43      raeburn  12675:                     } else {
1.224     raeburn  12676:                         $resulttext .= &mt('none');
1.43      raeburn  12677:                     }
1.224     raeburn  12678:                     $resulttext .= '</li>';
1.28      raeburn  12679:                 }
1.224     raeburn  12680:                 $resulttext .= '</ul></li>';
1.28      raeburn  12681:             }
1.27      raeburn  12682:             $resulttext .= '</ul>';
1.305     raeburn  12683:             my $cachetime = 24*60*60;
                   12684:             $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
                   12685:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
                   12686:             if (ref($lastactref) eq 'HASH') {
                   12687:                 $lastactref->{'domdefaults'} = 1;
                   12688:             }
1.27      raeburn  12689:         } else {
1.224     raeburn  12690:             $resulttext = &mt('No changes made to self-creation settings');
1.27      raeburn  12691:         }
                   12692:     } else {
                   12693:         $resulttext = '<span class="LC_error">'.
1.23      raeburn  12694:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   12695:     }
1.43      raeburn  12696:     if ($warningmsg ne '') {
                   12697:         $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
                   12698:     }
1.23      raeburn  12699:     return $resulttext;
                   12700: }
                   12701: 
1.165     raeburn  12702: sub process_captcha {
                   12703:     my ($container,$changes,$newsettings,$current) = @_;
                   12704:     return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
                   12705:     $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
                   12706:     unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
                   12707:         $newsettings->{'captcha'} = 'original';
                   12708:     }
                   12709:     if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
1.210     raeburn  12710:         if ($container eq 'cancreate') {
1.169     raeburn  12711:             if (ref($changes->{'cancreate'}) eq 'ARRAY') {
                   12712:                 push(@{$changes->{'cancreate'}},'captcha');
                   12713:             } elsif (!defined($changes->{'cancreate'})) {
                   12714:                 $changes->{'cancreate'} = ['captcha'];
                   12715:             }
                   12716:         } else {
                   12717:             $changes->{'captcha'} = 1;
1.165     raeburn  12718:         }
                   12719:     }
1.269     raeburn  12720:     my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.165     raeburn  12721:     if ($newsettings->{'captcha'} eq 'recaptcha') {
                   12722:         $newpub = $env{'form.'.$container.'_recaptchapub'};
                   12723:         $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.250     raeburn  12724:         $newpub =~ s/[^\w\-]//g;
                   12725:         $newpriv =~ s/[^\w\-]//g;
1.169     raeburn  12726:         $newsettings->{'recaptchakeys'} = {
                   12727:                                              public  => $newpub,
                   12728:                                              private => $newpriv,
                   12729:                                           };
1.269     raeburn  12730:         $newversion = $env{'form.'.$container.'_recaptchaversion'};
                   12731:         $newversion =~ s/\D//g;
                   12732:         if ($newversion ne '2') {
                   12733:             $newversion = 1;
                   12734:         }
                   12735:         $newsettings->{'recaptchaversion'} = $newversion;
1.165     raeburn  12736:     }
                   12737:     if (ref($current->{'recaptchakeys'}) eq 'HASH') {
                   12738:         $currpub = $current->{'recaptchakeys'}{'public'};
                   12739:         $currpriv = $current->{'recaptchakeys'}{'private'};
1.179     raeburn  12740:         unless ($newsettings->{'captcha'} eq 'recaptcha') {
                   12741:             $newsettings->{'recaptchakeys'} = {
                   12742:                                                  public  => '',
                   12743:                                                  private => '',
                   12744:                                               }
                   12745:         }
1.165     raeburn  12746:     }
1.269     raeburn  12747:     if ($current->{'captcha'} eq 'recaptcha') {
                   12748:         $currversion = $current->{'recaptchaversion'};
                   12749:         if ($currversion ne '2') {
                   12750:             $currversion = 1;
                   12751:         }
                   12752:     }
                   12753:     if ($currversion ne $newversion) {
                   12754:         if ($container eq 'cancreate') {
                   12755:             if (ref($changes->{'cancreate'}) eq 'ARRAY') {
                   12756:                 push(@{$changes->{'cancreate'}},'recaptchaversion');
                   12757:             } elsif (!defined($changes->{'cancreate'})) {
                   12758:                 $changes->{'cancreate'} = ['recaptchaversion'];
                   12759:             }
                   12760:         } else {
                   12761:             $changes->{'recaptchaversion'} = 1;
                   12762:         }
                   12763:     }
1.165     raeburn  12764:     if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169     raeburn  12765:         if ($container eq 'cancreate') {
                   12766:             if (ref($changes->{'cancreate'}) eq 'ARRAY') {
                   12767:                 push(@{$changes->{'cancreate'}},'recaptchakeys');
                   12768:             } elsif (!defined($changes->{'cancreate'})) {
                   12769:                 $changes->{'cancreate'} = ['recaptchakeys'];
                   12770:             }
                   12771:         } else {
1.210     raeburn  12772:             $changes->{'recaptchakeys'} = 1;
1.165     raeburn  12773:         }
                   12774:     }
                   12775:     return;
                   12776: }
                   12777: 
1.33      raeburn  12778: sub modify_usermodification {
                   12779:     my ($dom,%domconfig) = @_;
1.224     raeburn  12780:     my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33      raeburn  12781:     if (ref($domconfig{'usermodification'}) eq 'HASH') {
                   12782:         foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224     raeburn  12783:             if ($key eq 'selfcreate') {
                   12784:                 $modifyhash{$key} = $domconfig{'usermodification'}{$key};
                   12785:             } else {  
                   12786:                 $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
                   12787:             }
1.33      raeburn  12788:         }
                   12789:     }
1.224     raeburn  12790:     my @contexts = ('author','course');
1.33      raeburn  12791:     my %context_title = (
                   12792:                            author => 'In author context',
                   12793:                            course => 'In course context',
                   12794:                         );
                   12795:     my @fields = ('lastname','firstname','middlename','generation',
                   12796:                   'permanentemail','id');
                   12797:     my %roles = (
                   12798:                   author => ['ca','aa'],
                   12799:                   course => ['st','ep','ta','in','cr'],
                   12800:                 );
                   12801:     my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
                   12802:     foreach my $context (@contexts) {
                   12803:         foreach my $role (@{$roles{$context}}) {
                   12804:             my @modifiable =  &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
                   12805:             foreach my $item (@fields) {
                   12806:                 if (grep(/^\Q$item\E$/,@modifiable)) {
                   12807:                     $modifyhash{$context}{$role}{$item} = 1;
                   12808:                 } else {
                   12809:                     $modifyhash{$context}{$role}{$item} = 0;
                   12810:                 }
                   12811:             }
                   12812:         }
                   12813:         if (ref($curr_usermodification{$context}) eq 'HASH') {
                   12814:             foreach my $role (@{$roles{$context}}) {
                   12815:                 if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
                   12816:                     foreach my $field (@fields) {
                   12817:                         if ($modifyhash{$context}{$role}{$field} ne 
                   12818:                                 $curr_usermodification{$context}{$role}{$field}) {
                   12819:                             push(@{$changes{$context}},$role);
                   12820:                             last;
                   12821:                         }
                   12822:                     }
                   12823:                 }
                   12824:             }
                   12825:         } else {
                   12826:             foreach my $context (@contexts) {
                   12827:                 foreach my $role (@{$roles{$context}}) {
                   12828:                     push(@{$changes{$context}},$role);
                   12829:                 }
                   12830:             }
                   12831:         }
                   12832:     }
                   12833:     my %usermodification_hash =  (
                   12834:                                    usermodification => \%modifyhash,
                   12835:                                  );
                   12836:     my $putresult = &Apache::lonnet::put_dom('configuration',
                   12837:                                              \%usermodification_hash,$dom);
                   12838:     if ($putresult eq 'ok') {
                   12839:         if (keys(%changes) > 0) {
                   12840:             $resulttext = &mt('Changes made: ').'<ul>';
                   12841:             foreach my $context (@contexts) {
                   12842:                 if (ref($changes{$context}) eq 'ARRAY') {
                   12843:                     $resulttext .= '<li>'.$context_title{$context}.':<ul>';
                   12844:                     if (ref($changes{$context}) eq 'ARRAY') {
                   12845:                         foreach my $role (@{$changes{$context}}) {
                   12846:                             my $rolename;
1.224     raeburn  12847:                             if ($role eq 'cr') {
                   12848:                                 $rolename = &mt('Custom');
1.33      raeburn  12849:                             } else {
1.224     raeburn  12850:                                 $rolename = &Apache::lonnet::plaintext($role);
1.33      raeburn  12851:                             }
                   12852:                             my @modifiable;
1.224     raeburn  12853:                             $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33      raeburn  12854:                             foreach my $field (@fields) {
                   12855:                                 if ($modifyhash{$context}{$role}{$field}) {
                   12856:                                     push(@modifiable,$fieldtitles{$field});
                   12857:                                 }
                   12858:                             }
                   12859:                             if (@modifiable > 0) {
                   12860:                                 $resulttext .= join(', ',@modifiable);
                   12861:                             } else {
                   12862:                                 $resulttext .= &mt('none'); 
                   12863:                             }
                   12864:                             $resulttext .= '</li>';
                   12865:                         }
                   12866:                         $resulttext .= '</ul></li>';
                   12867:                     }
                   12868:                 }
                   12869:             }
                   12870:             $resulttext .= '</ul>';
                   12871:         } else {
                   12872:             $resulttext = &mt('No changes made to user modification settings');
                   12873:         }
                   12874:     } else {
                   12875:         $resulttext = '<span class="LC_error">'.
                   12876:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   12877:     }
                   12878:     return $resulttext;
                   12879: }
                   12880: 
1.43      raeburn  12881: sub modify_defaults {
1.212     raeburn  12882:     my ($dom,$lastactref,%domconfig) = @_;
1.43      raeburn  12883:     my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212     raeburn  12884:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.294     raeburn  12885:     my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
                   12886:                  'portal_def','intauth_cost','intauth_check','intauth_switch');
1.43      raeburn  12887:     my @authtypes = ('internal','krb4','krb5','localauth');
                   12888:     foreach my $item (@items) {
                   12889:         $newvalues{$item} = $env{'form.'.$item};
                   12890:         if ($item eq 'auth_def') {
                   12891:             if ($newvalues{$item} ne '') {
                   12892:                 if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
                   12893:                     push(@errors,$item);
                   12894:                 }
                   12895:             }
                   12896:         } elsif ($item eq 'lang_def') {
                   12897:             if ($newvalues{$item} ne '') {
                   12898:                 if ($newvalues{$item} =~ /^(\w+)/) {
                   12899:                     my $langcode = $1;
1.103     raeburn  12900:                     if ($langcode ne 'x_chef') {
                   12901:                         if (code2language($langcode) eq '') {
                   12902:                             push(@errors,$item);
                   12903:                         }
1.43      raeburn  12904:                     }
                   12905:                 } else {
                   12906:                     push(@errors,$item);
                   12907:                 }
                   12908:             }
1.54      raeburn  12909:         } elsif ($item eq 'timezone_def') {
                   12910:             if ($newvalues{$item} ne '') {
1.62      raeburn  12911:                 if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54      raeburn  12912:                     push(@errors,$item);   
                   12913:                 }
                   12914:             }
1.68      raeburn  12915:         } elsif ($item eq 'datelocale_def') {
                   12916:             if ($newvalues{$item} ne '') {
                   12917:                 my @datelocale_ids = DateTime::Locale->ids();
                   12918:                 if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
                   12919:                     push(@errors,$item);
                   12920:                 }
                   12921:             }
1.141     raeburn  12922:         } elsif ($item eq 'portal_def') {
                   12923:             if ($newvalues{$item} ne '') {
                   12924:                 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])\/?$/) {
                   12925:                     push(@errors,$item);
                   12926:                 }
                   12927:             }
1.294     raeburn  12928:         } elsif ($item eq 'intauth_cost') {
                   12929:             if ($newvalues{$item} ne '') {
                   12930:                 if ($newvalues{$item} =~ /\D/) {
                   12931:                     push(@errors,$item);
                   12932:                 }
                   12933:             }
                   12934:         } elsif ($item eq 'intauth_check') {
                   12935:             if ($newvalues{$item} ne '') {
                   12936:                 unless ($newvalues{$item} =~ /^(0|1|2)$/) {
                   12937:                     push(@errors,$item);
                   12938:                 }
                   12939:             }
                   12940:         } elsif ($item eq 'intauth_switch') {
                   12941:             if ($newvalues{$item} ne '') {
                   12942:                 unless ($newvalues{$item} =~ /^(0|1|2)$/) {
                   12943:                     push(@errors,$item);
                   12944:                 }
                   12945:             }
1.43      raeburn  12946:         }
                   12947:         if (grep(/^\Q$item\E$/,@errors)) {
                   12948:             $newvalues{$item} = $domdefaults{$item};
                   12949:         } elsif ($domdefaults{$item} ne $newvalues{$item}) {
                   12950:             $changes{$item} = 1;
                   12951:         }
1.72      raeburn  12952:         $domdefaults{$item} = $newvalues{$item};
1.43      raeburn  12953:     }
                   12954:     my %defaults_hash = (
1.72      raeburn  12955:                          defaults => \%newvalues,
                   12956:                         );
1.43      raeburn  12957:     my $title = &defaults_titles();
1.236     raeburn  12958: 
                   12959:     my $currinststatus;
                   12960:     if (ref($domconfig{'inststatus'}) eq 'HASH') {
                   12961:         $currinststatus = $domconfig{'inststatus'};
                   12962:     } else {
                   12963:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   12964:         $currinststatus = {
                   12965:                              inststatustypes => $usertypes,
                   12966:                              inststatusorder => $types,
                   12967:                              inststatusguest => [],
                   12968:                           };
                   12969:     }
                   12970:     my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
                   12971:     my @allpos;
                   12972:     my %alltypes;
1.305     raeburn  12973:     my @inststatusguest;
                   12974:     if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
                   12975:         foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
                   12976:             unless (grep(/^\Q$type\E$/,@todelete)) {
                   12977:                 push(@inststatusguest,$type);
                   12978:             }
                   12979:         }
                   12980:     }
                   12981:     my ($currtitles,$currorder);
1.236     raeburn  12982:     if (ref($currinststatus) eq 'HASH') {
                   12983:         if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
                   12984:             foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
                   12985:                 if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
                   12986:                     if ($currinststatus->{inststatustypes}->{$type} ne '') {
                   12987:                         $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
                   12988:                     }
                   12989:                 }
                   12990:                 unless (grep(/^\Q$type\E$/,@todelete)) { 
                   12991:                     my $position = $env{'form.inststatus_pos_'.$type};
                   12992:                     $position =~ s/\D+//g;
                   12993:                     $allpos[$position] = $type;
                   12994:                     $alltypes{$type} = $env{'form.inststatus_title_'.$type};
                   12995:                     $alltypes{$type} =~ s/`//g;
                   12996:                 }
                   12997:             }
                   12998:             $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
                   12999:             $currtitles =~ s/,$//;
                   13000:         }
                   13001:     }
                   13002:     if ($env{'form.addinststatus'}) {
                   13003:         my $newtype = $env{'form.addinststatus'};
                   13004:         $newtype =~ s/\W//g;
                   13005:         unless (exists($alltypes{$newtype})) {
                   13006:             $alltypes{$newtype} = $env{'form.addinststatus_title'};
                   13007:             $alltypes{$newtype} =~ s/`//g; 
                   13008:             my $position = $env{'form.addinststatus_pos'};
                   13009:             $position =~ s/\D+//g;
                   13010:             if ($position ne '') {
                   13011:                 $allpos[$position] = $newtype;
                   13012:             }
                   13013:         }
                   13014:     }
1.305     raeburn  13015:     my @orderedstatus;
1.236     raeburn  13016:     foreach my $type (@allpos) {
                   13017:         unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
                   13018:             push(@orderedstatus,$type);
                   13019:         }
                   13020:     }
                   13021:     foreach my $type (keys(%alltypes)) {
                   13022:         unless (grep(/^\Q$type\E$/,@orderedstatus)) {
                   13023:             delete($alltypes{$type});
                   13024:         }
                   13025:     }
                   13026:     $defaults_hash{'inststatus'} = {
                   13027:                                      inststatustypes => \%alltypes,
                   13028:                                      inststatusorder => \@orderedstatus,
1.305     raeburn  13029:                                      inststatusguest => \@inststatusguest,
1.236     raeburn  13030:                                    };
                   13031:     if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
                   13032:         foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
                   13033:             $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
                   13034:         }
                   13035:     }
                   13036:     if ($currorder ne join(',',@orderedstatus)) {
                   13037:         $changes{'inststatus'}{'inststatusorder'} = 1;
                   13038:     }
                   13039:     my $newtitles;
                   13040:     foreach my $item (@orderedstatus) {
                   13041:         $newtitles .= $alltypes{$item}.',';
                   13042:     }
                   13043:     $newtitles =~ s/,$//;
                   13044:     if ($currtitles ne $newtitles) {
                   13045:         $changes{'inststatus'}{'inststatustypes'} = 1;
                   13046:     }
1.43      raeburn  13047:     my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
                   13048:                                              $dom);
                   13049:     if ($putresult eq 'ok') {
                   13050:         if (keys(%changes) > 0) {
                   13051:             $resulttext = &mt('Changes made:').'<ul>';
1.212     raeburn  13052:             my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43      raeburn  13053:             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";
                   13054:             foreach my $item (sort(keys(%changes))) {
1.236     raeburn  13055:                 if ($item eq 'inststatus') {
                   13056:                     if (ref($changes{'inststatus'}) eq 'HASH') {
1.305     raeburn  13057:                         if (@orderedstatus) {
1.236     raeburn  13058:                             $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
                   13059:                             foreach my $type (@orderedstatus) { 
                   13060:                                 $resulttext .= $alltypes{$type}.', ';
                   13061:                             }
                   13062:                             $resulttext =~ s/, $//;
                   13063:                             $resulttext .= '</li>';
1.305     raeburn  13064:                         } else {
                   13065:                             $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>'; 
1.236     raeburn  13066:                         }
                   13067:                     }
                   13068:                 } else {
                   13069:                     my $value = $env{'form.'.$item};
                   13070:                     if ($value eq '') {
                   13071:                         $value = &mt('none');
                   13072:                     } elsif ($item eq 'auth_def') {
                   13073:                         my %authnames = &authtype_names();
                   13074:                         my %shortauth = (
                   13075:                                           internal   => 'int',
                   13076:                                           krb4       => 'krb4',
                   13077:                                           krb5       => 'krb5',
                   13078:                                           localauth  => 'loc',
                   13079:                         );
                   13080:                         $value = $authnames{$shortauth{$value}};
1.294     raeburn  13081:                     } elsif ($item eq 'intauth_switch') {
                   13082:                         my %optiondesc = &Apache::lonlocal::texthash (
                   13083:                                             0 => 'No',
                   13084:                                             1 => 'Yes',
                   13085:                                             2 => 'Yes, and copy existing passwd file to passwd.bak file',
                   13086:                                          );
                   13087:                         if ($value =~ /^(0|1|2)$/) {
                   13088:                             $value = $optiondesc{$value};
                   13089:                         } else {
                   13090:                             $value = &mt('none -- defaults to No');
                   13091:                         }
                   13092:                     } elsif ($item eq 'intauth_check') {
                   13093:                         my %optiondesc = &Apache::lonlocal::texthash (
                   13094:                                              0 => 'No',
                   13095:                                              1 => 'Yes, allow login then update passwd file using default cost (if higher)',
                   13096:                                              2 => 'Yes, disallow login if stored cost is less than domain default',
                   13097:                                          );
                   13098:                         if ($value =~ /^(0|1|2)$/) {
                   13099:                             $value = $optiondesc{$value};
                   13100:                         } else {
                   13101:                             $value = &mt('none -- defaults to No');
                   13102:                         }
1.236     raeburn  13103:                     }
                   13104:                     $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
                   13105:                     $mailmsgtext .= "$title->{$item} set to $value\n";  
1.43      raeburn  13106:                 }
                   13107:             }
                   13108:             $resulttext .= '</ul>';
                   13109:             $mailmsgtext .= "\n";
                   13110:             my $cachetime = 24*60*60;
1.72      raeburn  13111:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212     raeburn  13112:             if (ref($lastactref) eq 'HASH') {
                   13113:                 $lastactref->{'domdefaults'} = 1;
                   13114:             }
1.68      raeburn  13115:             if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203     raeburn  13116:                 my $notify = 1;
                   13117:                 if (ref($domconfig{'contacts'}) eq 'HASH') {
                   13118:                     if ($domconfig{'contacts'}{'reportupdates'} == 0) {
                   13119:                         $notify = 0;
                   13120:                     }
                   13121:                 }
                   13122:                 if ($notify) {
                   13123:                     &Apache::lonmsg::sendemail('installrecord@loncapa.org',
                   13124:                                                "LON-CAPA Domain Settings Change - $dom",
                   13125:                                                $mailmsgtext);
                   13126:                 }
1.54      raeburn  13127:             }
1.43      raeburn  13128:         } else {
1.54      raeburn  13129:             $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43      raeburn  13130:         }
                   13131:     } else {
                   13132:         $resulttext = '<span class="LC_error">'.
                   13133:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   13134:     }
                   13135:     if (@errors > 0) {
                   13136:         $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
                   13137:         foreach my $item (@errors) {
                   13138:             $resulttext .= ' "'.$title->{$item}.'",';
                   13139:         }
                   13140:         $resulttext =~ s/,$//;
                   13141:     }
                   13142:     return $resulttext;
                   13143: }
                   13144: 
1.46      raeburn  13145: sub modify_scantron {
1.205     raeburn  13146:     my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46      raeburn  13147:     my ($resulttext,%confhash,%changes,$errors);
                   13148:     my $custom = 'custom.tab';
                   13149:     my $default = 'default.tab';
                   13150:     my $servadm = $r->dir_config('lonAdmEMail');
                   13151:     my ($configuserok,$author_ok,$switchserver) = 
                   13152:         &config_check($dom,$confname,$servadm);
                   13153:     if ($env{'form.scantronformat.filename'} ne '') {
                   13154:         my $error;
                   13155:         if ($configuserok eq 'ok') {
                   13156:             if ($switchserver) {
1.130     raeburn  13157:                 $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46      raeburn  13158:             } else {
                   13159:                 if ($author_ok eq 'ok') {
                   13160:                     my ($result,$scantronurl) =
                   13161:                         &publishlogo($r,'upload','scantronformat',$dom,
                   13162:                                      $confname,'scantron','','',$custom);
                   13163:                     if ($result eq 'ok') {
                   13164:                         $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48      raeburn  13165:                         $changes{'scantronformat'} = 1;
1.46      raeburn  13166:                     } else {
                   13167:                         $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
                   13168:                     }
                   13169:                 } else {
                   13170:                     $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);
                   13171:                 }
                   13172:             }
                   13173:         } else {
                   13174:             $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);
                   13175:         }
                   13176:         if ($error) {
                   13177:             &Apache::lonnet::logthis($error);
                   13178:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   13179:         }
                   13180:     }
1.48      raeburn  13181:     if (ref($domconfig{'scantron'}) eq 'HASH') {
                   13182:         if ($domconfig{'scantron'}{'scantronformat'} ne '') {
                   13183:             if ($env{'form.scantronformat_del'}) {
                   13184:                 $confhash{'scantron'}{'scantronformat'} = '';
                   13185:                 $changes{'scantronformat'} = 1;
1.46      raeburn  13186:             }
                   13187:         }
                   13188:     }
                   13189:     if (keys(%confhash) > 0) {
                   13190:         my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
                   13191:                                                  $dom);
                   13192:         if ($putresult eq 'ok') {
                   13193:             if (keys(%changes) > 0) {
1.48      raeburn  13194:                 if (ref($confhash{'scantron'}) eq 'HASH') {
                   13195:                     $resulttext = &mt('Changes made:').'<ul>';
                   13196:                     if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130     raeburn  13197:                         $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48      raeburn  13198:                     } else {
1.130     raeburn  13199:                         $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46      raeburn  13200:                     }
1.48      raeburn  13201:                     $resulttext .= '</ul>';
                   13202:                 } else {
1.130     raeburn  13203:                     $resulttext = &mt('Changes made to bubblesheet format file.');
1.46      raeburn  13204:                 }
                   13205:                 $resulttext .= '</ul>';
                   13206:                 &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212     raeburn  13207:                 if (ref($lastactref) eq 'HASH') {
                   13208:                     $lastactref->{'domainconfig'} = 1;
                   13209:                 }
1.46      raeburn  13210:             } else {
1.130     raeburn  13211:                 $resulttext = &mt('No changes made to bubblesheet format file');
1.46      raeburn  13212:             }
                   13213:         } else {
                   13214:             $resulttext = '<span class="LC_error">'.
                   13215:                 &mt('An error occurred: [_1]',$putresult).'</span>';
                   13216:         }
                   13217:     } else {
1.130     raeburn  13218:         $resulttext = &mt('No changes made to bubblesheet format file'); 
1.46      raeburn  13219:     }
                   13220:     if ($errors) {
                   13221:         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
                   13222:                        $errors.'</ul>';
                   13223:     }
                   13224:     return $resulttext;
                   13225: }
                   13226: 
1.48      raeburn  13227: sub modify_coursecategories {
1.239     raeburn  13228:     my ($dom,$lastactref,%domconfig) = @_;
1.57      raeburn  13229:     my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
                   13230:         $cathash);
1.48      raeburn  13231:     my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.238     raeburn  13232:     my @catitems = ('unauth','auth');
                   13233:     my @cattypes = ('std','domonly','codesrch','none');
1.55      raeburn  13234:     if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57      raeburn  13235:         $cathash = $domconfig{'coursecategories'}{'cats'};
                   13236:         if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
                   13237:             $changes{'togglecats'} = 1;
                   13238:             $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
                   13239:         }
                   13240:         if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
                   13241:             $changes{'categorize'} = 1;
                   13242:             $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
                   13243:         }
1.120     raeburn  13244:         if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
                   13245:             $changes{'togglecatscomm'} = 1;
                   13246:             $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
                   13247:         }
                   13248:         if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
                   13249:             $changes{'categorizecomm'} = 1;
                   13250:             $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
1.272     raeburn  13251: 
                   13252:         }
                   13253:         if ($domconfig{'coursecategories'}{'togglecatsplace'} ne $env{'form.togglecatsplace'}) {
                   13254:             $changes{'togglecatsplace'} = 1;
                   13255:             $domconfig{'coursecategories'}{'togglecatsplace'} = $env{'form.togglecatsplace'};
                   13256:         }
                   13257:         if ($domconfig{'coursecategories'}{'categorizeplace'} ne $env{'form.categorizeplace'}) {
                   13258:             $changes{'categorizeplace'} = 1;
                   13259:             $domconfig{'coursecategories'}{'categorizeplace'} = $env{'form.categorizeplace'};
1.120     raeburn  13260:         }
1.238     raeburn  13261:         foreach my $item (@catitems) {
                   13262:             if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
                   13263:                 if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
                   13264:                     $changes{$item} = 1;
                   13265:                     $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
                   13266:                 }
                   13267:             }
                   13268:         }
1.57      raeburn  13269:     } else {
                   13270:         $changes{'togglecats'} = 1;
                   13271:         $changes{'categorize'} = 1;
1.124     raeburn  13272:         $changes{'togglecatscomm'} = 1;
                   13273:         $changes{'categorizecomm'} = 1;
1.272     raeburn  13274:         $changes{'togglecatsplace'} = 1;
                   13275:         $changes{'categorizeplace'} = 1;
1.87      raeburn  13276:         $domconfig{'coursecategories'} = {
                   13277:                                              togglecats => $env{'form.togglecats'},
                   13278:                                              categorize => $env{'form.categorize'},
1.124     raeburn  13279:                                              togglecatscomm => $env{'form.togglecatscomm'},
                   13280:                                              categorizecomm => $env{'form.categorizecomm'},
1.272     raeburn  13281:                                              togglecatsplace => $env{'form.togglecatsplace'},
                   13282:                                              categorizeplace => $env{'form.categorizeplace'},
1.120     raeburn  13283:                                          };
1.238     raeburn  13284:         foreach my $item (@catitems) {
                   13285:             if ($env{'form.coursecat_'.$item} ne 'std') {
                   13286:                 $changes{$item} = 1;
                   13287:             }
                   13288:             if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
                   13289:                 $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
                   13290:             }
                   13291:         }
1.57      raeburn  13292:     }
                   13293:     if (ref($cathash) eq 'HASH') {
                   13294:         if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '')  && ($env{'form.instcode'} == 0)) {
1.55      raeburn  13295:             push (@deletecategory,'instcode::0');
                   13296:         }
1.120     raeburn  13297:         if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '')  && ($env{'form.communities'} == 0)) {
                   13298:             push(@deletecategory,'communities::0');
                   13299:         }
1.272     raeburn  13300:         if (($domconfig{'coursecategories'}{'cats'}{'placement::0'} ne '')  && ($env{'form.placement'} == 0)) {
                   13301:             push(@deletecategory,'placement::0');
                   13302:         }
1.48      raeburn  13303:     }
1.57      raeburn  13304:     my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
                   13305:     if (ref($cathash) eq 'HASH') {
1.48      raeburn  13306:         if (@deletecategory > 0) {
                   13307:             #FIXME Need to remove category from all courses using a deleted category 
1.57      raeburn  13308:             &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48      raeburn  13309:             foreach my $item (@deletecategory) {
1.57      raeburn  13310:                 if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
                   13311:                     delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48      raeburn  13312:                     $deletions{$item} = 1;
1.57      raeburn  13313:                     &recurse_cat_deletes($item,$cathash,\%deletions);
1.48      raeburn  13314:                 }
                   13315:             }
                   13316:         }
1.57      raeburn  13317:         foreach my $item (keys(%{$cathash})) {
1.48      raeburn  13318:             my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57      raeburn  13319:             if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48      raeburn  13320:                 $reorderings{$item} = 1;
1.57      raeburn  13321:                 $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48      raeburn  13322:             }
                   13323:             if ($env{'form.addcategory_name_'.$item} ne '') {
                   13324:                 my $newcat = $env{'form.addcategory_name_'.$item};
                   13325:                 my $newdepth = $depth+1;
                   13326:                 my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57      raeburn  13327:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48      raeburn  13328:                 $adds{$newitem} = 1; 
                   13329:             }
                   13330:             if ($env{'form.subcat_'.$item} ne '') {
                   13331:                 my $newcat = $env{'form.subcat_'.$item};
                   13332:                 my $newdepth = $depth+1;
                   13333:                 my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57      raeburn  13334:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48      raeburn  13335:                 $adds{$newitem} = 1;
                   13336:             }
                   13337:         }
                   13338:     }
                   13339:     if ($env{'form.instcode'} eq '1') {
1.57      raeburn  13340:         if (ref($cathash) eq 'HASH') {
1.48      raeburn  13341:             my $newitem = 'instcode::0';
1.57      raeburn  13342:             if ($cathash->{$newitem} eq '') {  
                   13343:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48      raeburn  13344:                 $adds{$newitem} = 1;
                   13345:             }
                   13346:         } else {
                   13347:             my $newitem = 'instcode::0';
1.57      raeburn  13348:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48      raeburn  13349:             $adds{$newitem} = 1;
                   13350:         }
                   13351:     }
1.120     raeburn  13352:     if ($env{'form.communities'} eq '1') {
                   13353:         if (ref($cathash) eq 'HASH') {
                   13354:             my $newitem = 'communities::0';
                   13355:             if ($cathash->{$newitem} eq '') {
                   13356:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
                   13357:                 $adds{$newitem} = 1;
                   13358:             }
                   13359:         } else {
                   13360:             my $newitem = 'communities::0';
                   13361:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
                   13362:             $adds{$newitem} = 1;
                   13363:         }
                   13364:     }
1.272     raeburn  13365:     if ($env{'form.placement'} eq '1') {
                   13366:         if (ref($cathash) eq 'HASH') {
                   13367:             my $newitem = 'placement::0';
                   13368:             if ($cathash->{$newitem} eq '') {
                   13369:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
                   13370:                 $adds{$newitem} = 1;
                   13371:             }
                   13372:         } else {
                   13373:             my $newitem = 'placement::0';
                   13374:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
                   13375:             $adds{$newitem} = 1;
                   13376:         }
                   13377:     }
1.48      raeburn  13378:     if ($env{'form.addcategory_name'} ne '') {
1.120     raeburn  13379:         if (($env{'form.addcategory_name'} ne 'instcode') &&
1.272     raeburn  13380:             ($env{'form.addcategory_name'} ne 'communities') &&
                   13381:             ($env{'form.addcategory_name'} ne 'placement')) {
1.120     raeburn  13382:             my $newitem = &escape($env{'form.addcategory_name'}).'::0';
                   13383:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
                   13384:             $adds{$newitem} = 1;
                   13385:         }
1.48      raeburn  13386:     }
1.57      raeburn  13387:     my $putresult;
1.48      raeburn  13388:     if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
                   13389:         if (keys(%deletions) > 0) {
                   13390:             foreach my $key (keys(%deletions)) {
                   13391:                 if ($predelallitems{$key} ne '') {
                   13392:                     $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
                   13393:                 }
                   13394:             }
                   13395:         }
                   13396:         my (@chkcats,@chktrails,%chkallitems);
1.57      raeburn  13397:         &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48      raeburn  13398:         if (ref($chkcats[0]) eq 'ARRAY') {
                   13399:             my $depth = 0;
                   13400:             my $chg = 0;
                   13401:             for (my $i=0; $i<@{$chkcats[0]}; $i++) {
                   13402:                 my $name = $chkcats[0][$i];
                   13403:                 my $item;
                   13404:                 if ($name eq '') {
                   13405:                     $chg ++;
                   13406:                 } else {
                   13407:                     $item = &escape($name).'::0';
                   13408:                     if ($chg) {
1.57      raeburn  13409:                         $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48      raeburn  13410:                     }
                   13411:                     $depth ++; 
1.57      raeburn  13412:                     &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48      raeburn  13413:                     $depth --;
                   13414:                 }
                   13415:             }
                   13416:         }
1.57      raeburn  13417:     }
                   13418:     if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
                   13419:         $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48      raeburn  13420:         if ($putresult eq 'ok') {
1.57      raeburn  13421:             my %title = (
1.120     raeburn  13422:                          togglecats     => 'Show/Hide a course in catalog',
                   13423:                          categorize     => 'Assign a category to a course',
                   13424:                          togglecatscomm => 'Show/Hide a community in catalog',
                   13425:                          categorizecomm => 'Assign a category to a community',
1.57      raeburn  13426:                         );
                   13427:             my %level = (
1.120     raeburn  13428:                          dom  => 'set in Domain ("Modify Course/Community")',
                   13429:                          crs  => 'set in Course ("Course Configuration")',
                   13430:                          comm => 'set in Community ("Community Configuration")',
1.238     raeburn  13431:                          none     => 'No catalog',
                   13432:                          std      => 'Standard catalog',
                   13433:                          domonly  => 'Domain-only catalog',
                   13434:                          codesrch => 'Code search form',
1.57      raeburn  13435:                         );
1.48      raeburn  13436:             $resulttext = &mt('Changes made:').'<ul>';
1.57      raeburn  13437:             if ($changes{'togglecats'}) {
                   13438:                 $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>'; 
                   13439:             }
                   13440:             if ($changes{'categorize'}) {
                   13441:                 $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48      raeburn  13442:             }
1.120     raeburn  13443:             if ($changes{'togglecatscomm'}) {
                   13444:                 $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
                   13445:             }
                   13446:             if ($changes{'categorizecomm'}) {
                   13447:                 $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
                   13448:             }
1.238     raeburn  13449:             if ($changes{'unauth'}) {
                   13450:                 $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
                   13451:             }
                   13452:             if ($changes{'auth'}) {
                   13453:                 $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
                   13454:             }
1.57      raeburn  13455:             if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
                   13456:                 my $cathash;
                   13457:                 if (ref($domconfig{'coursecategories'}) eq 'HASH') {
                   13458:                     $cathash = $domconfig{'coursecategories'}{'cats'};
                   13459:                 } else {
                   13460:                     $cathash = {};
                   13461:                 } 
                   13462:                 my (@cats,@trails,%allitems);
                   13463:                     &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
                   13464:                 if (keys(%deletions) > 0) {
                   13465:                     $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
                   13466:                     foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) { 
                   13467:                         $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
                   13468:                     }
                   13469:                     $resulttext .= '</ul></li>';
                   13470:                 }
                   13471:                 if (keys(%reorderings) > 0) {
                   13472:                     my %sort_by_trail;
                   13473:                     $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
                   13474:                     foreach my $key (keys(%reorderings)) {
                   13475:                         if ($allitems{$key} ne '') {
                   13476:                             $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
                   13477:                         }
1.48      raeburn  13478:                     }
1.57      raeburn  13479:                     foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
                   13480:                         $resulttext .= '<li>'.$trails[$trail].'</li>';
                   13481:                     }
                   13482:                     $resulttext .= '</ul></li>';
1.48      raeburn  13483:                 }
1.57      raeburn  13484:                 if (keys(%adds) > 0) {
                   13485:                     my %sort_by_trail;
                   13486:                     $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
                   13487:                     foreach my $key (keys(%adds)) {
                   13488:                         if ($allitems{$key} ne '') {
                   13489:                             $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
                   13490:                         }
                   13491:                     }
                   13492:                     foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
                   13493:                         $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48      raeburn  13494:                     }
1.57      raeburn  13495:                     $resulttext .= '</ul></li>';
1.48      raeburn  13496:                 }
                   13497:             }
                   13498:             $resulttext .= '</ul>';
1.239     raeburn  13499:             if ($changes{'unauth'} || $changes{'auth'}) {
1.246     raeburn  13500:                 my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
                   13501:                 if ($changes{'auth'}) {
                   13502:                     $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
                   13503:                 }
                   13504:                 if ($changes{'unauth'}) {
                   13505:                     $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
                   13506:                 }
                   13507:                 my $cachetime = 24*60*60;
                   13508:                 &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.239     raeburn  13509:                 if (ref($lastactref) eq 'HASH') {
1.246     raeburn  13510:                     $lastactref->{'domdefaults'} = 1;
1.239     raeburn  13511:                 }
                   13512:             }
1.48      raeburn  13513:         } else {
                   13514:             $resulttext = '<span class="LC_error">'.
1.57      raeburn  13515:                           &mt('An error occurred: [_1]',$putresult).'</span>';
1.48      raeburn  13516:         }
                   13517:     } else {
1.120     raeburn  13518:         $resulttext = &mt('No changes made to course and community categories');
1.48      raeburn  13519:     }
                   13520:     return $resulttext;
                   13521: }
                   13522: 
1.69      raeburn  13523: sub modify_serverstatuses {
                   13524:     my ($dom,%domconfig) = @_;
                   13525:     my ($resulttext,%changes,%currserverstatus,%newserverstatus);
                   13526:     if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
                   13527:         %currserverstatus = %{$domconfig{'serverstatuses'}};
                   13528:     }
                   13529:     my @pages = &serverstatus_pages();
                   13530:     foreach my $type (@pages) {
                   13531:         $newserverstatus{$type}{'namedusers'} = '';
                   13532:         $newserverstatus{$type}{'machines'} = '';
                   13533:         if (defined($env{'form.'.$type.'_namedusers'})) {
                   13534:             my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
                   13535:             my @okusers;
                   13536:             foreach my $user (@users) {
                   13537:                 my ($uname,$udom) = split(/:/,$user);
                   13538:                 if (($udom =~ /^$match_domain$/) &&   
                   13539:                     (&Apache::lonnet::domain($udom)) &&
                   13540:                     ($uname =~ /^$match_username$/)) {
                   13541:                     if (!grep(/^\Q$user\E/,@okusers)) {
                   13542:                         push(@okusers,$user);
                   13543:                     }
                   13544:                 }
                   13545:             }
                   13546:             if (@okusers > 0) {
                   13547:                  @okusers = sort(@okusers);
                   13548:                  $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
                   13549:             }
                   13550:         }
                   13551:         if (defined($env{'form.'.$type.'_machines'})) {
                   13552:             my @machines = split(/,/,$env{'form.'.$type.'_machines'});
                   13553:             my @okmachines;
                   13554:             foreach my $ip (@machines) {
                   13555:                 my @parts = split(/\./,$ip);
                   13556:                 next if (@parts < 4);
                   13557:                 my $badip = 0;
                   13558:                 for (my $i=0; $i<4; $i++) {
                   13559:                     if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
                   13560:                         $badip = 1;
                   13561:                         last;
                   13562:                     }
                   13563:                 }
                   13564:                 if (!$badip) {
                   13565:                     push(@okmachines,$ip);     
                   13566:                 }
                   13567:             }
                   13568:             @okmachines = sort(@okmachines);
                   13569:             $newserverstatus{$type}{'machines'} = join(',',@okmachines);
                   13570:         }
                   13571:     }
                   13572:     my %serverstatushash =  (
                   13573:                                 serverstatuses => \%newserverstatus,
                   13574:                             );
                   13575:     foreach my $type (@pages) {
1.83      raeburn  13576:         foreach my $setting ('namedusers','machines') {
1.84      raeburn  13577:             my (@current,@new);
1.83      raeburn  13578:             if (ref($currserverstatus{$type}) eq 'HASH') {
1.84      raeburn  13579:                 if ($currserverstatus{$type}{$setting} ne '') { 
                   13580:                     @current = split(/,/,$currserverstatus{$type}{$setting});
                   13581:                 }
                   13582:             }
                   13583:             if ($newserverstatus{$type}{$setting} ne '') {
                   13584:                 @new = split(/,/,$newserverstatus{$type}{$setting});
1.83      raeburn  13585:             }
                   13586:             if (@current > 0) {
                   13587:                 if (@new > 0) {
                   13588:                     foreach my $item (@current) {
                   13589:                         if (!grep(/^\Q$item\E$/,@new)) {
                   13590:                             $changes{$type}{$setting} = 1;
1.82      raeburn  13591:                             last;
                   13592:                         }
                   13593:                     }
1.84      raeburn  13594:                     foreach my $item (@new) {
                   13595:                         if (!grep(/^\Q$item\E$/,@current)) {
                   13596:                             $changes{$type}{$setting} = 1;
                   13597:                             last;
1.82      raeburn  13598:                         }
                   13599:                     }
                   13600:                 } else {
1.83      raeburn  13601:                     $changes{$type}{$setting} = 1;
1.69      raeburn  13602:                 }
1.83      raeburn  13603:             } elsif (@new > 0) {
                   13604:                 $changes{$type}{$setting} = 1;
1.69      raeburn  13605:             }
                   13606:         }
                   13607:     }
                   13608:     if (keys(%changes) > 0) {
1.81      raeburn  13609:         my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69      raeburn  13610:         my $putresult = &Apache::lonnet::put_dom('configuration',
                   13611:                                                  \%serverstatushash,$dom);
                   13612:         if ($putresult eq 'ok') {
                   13613:             $resulttext .= &mt('Changes made:').'<ul>';
                   13614:             foreach my $type (@pages) {
1.84      raeburn  13615:                 if (ref($changes{$type}) eq 'HASH') {
1.69      raeburn  13616:                     $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84      raeburn  13617:                     if ($changes{$type}{'namedusers'}) {
1.69      raeburn  13618:                         if ($newserverstatus{$type}{'namedusers'} eq '') {
                   13619:                             $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
                   13620:                         } else {
                   13621:                             $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
                   13622:                         }
1.84      raeburn  13623:                     }
                   13624:                     if ($changes{$type}{'machines'}) {
1.69      raeburn  13625:                         if ($newserverstatus{$type}{'machines'} eq '') {
                   13626:                             $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
                   13627:                         } else {
                   13628:                             $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
                   13629:                         }
                   13630: 
                   13631:                     }
                   13632:                     $resulttext .= '</ul></li>';
                   13633:                 }
                   13634:             }
                   13635:             $resulttext .= '</ul>';
                   13636:         } else {
                   13637:             $resulttext = '<span class="LC_error">'.
                   13638:                           &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
                   13639: 
                   13640:         }
                   13641:     } else {
                   13642:         $resulttext = &mt('No changes made to access to server status pages');
                   13643:     }
                   13644:     return $resulttext;
                   13645: }
                   13646: 
1.118     jms      13647: sub modify_helpsettings {
1.285     raeburn  13648:     my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.166     raeburn  13649:     my ($resulttext,$errors,%changes,%helphash);
                   13650:     my %defaultchecked = ('submitbugs' => 'on');
                   13651:     my @offon = ('off','on');
1.118     jms      13652:     my @toggles = ('submitbugs');
1.285     raeburn  13653:     my %current = ('submitbugs' => '',
                   13654:                    'adhoc'      => {},
                   13655:                   );
1.118     jms      13656:     if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.282     raeburn  13657:         %current = %{$domconfig{'helpsettings'}};
                   13658:     }
1.285     raeburn  13659:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.282     raeburn  13660:     foreach my $item (@toggles) {
                   13661:         if ($defaultchecked{$item} eq 'on') { 
                   13662:             if ($current{$item} eq '') {
                   13663:                 if ($env{'form.'.$item} eq '0') {
                   13664:                     $changes{$item} = 1;
                   13665:                 }
                   13666:             } elsif ($current{$item} ne $env{'form.'.$item}) {
                   13667:                 $changes{$item} = 1;
                   13668:             }
                   13669:         } elsif ($defaultchecked{$item} eq 'off') {
                   13670:             if ($current{$item} eq '') {
                   13671:                 if ($env{'form.'.$item} eq '1') {
1.166     raeburn  13672:                     $changes{$item} = 1;
                   13673:                 }
1.282     raeburn  13674:             } elsif ($current{$item} ne $env{'form.'.$item}) {
                   13675:                 $changes{$item} = 1;
                   13676:             }
                   13677:         }
                   13678:         if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
                   13679:             $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
                   13680:         }
                   13681:     }
1.285     raeburn  13682:     my $maxnum = $env{'form.helproles_maxnum'};
1.282     raeburn  13683:     my $confname = $dom.'-domainconfig';
                   13684:     my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285     raeburn  13685:     my (@allpos,%newsettings,%changedprivs,$newrole);
                   13686:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292     raeburn  13687:     my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.290     raeburn  13688:     my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285     raeburn  13689:     my %lt = &Apache::lonlocal::texthash(
                   13690:                     s      => 'system',
                   13691:                     d      => 'domain',
                   13692:                     order  => 'Display order',
                   13693:                     access => 'Role usage',
1.291     raeburn  13694:                     all    => 'All with domain helpdesk or helpdesk assistant role',
1.292     raeburn  13695:                     dh     => 'All with domain helpdesk role',
                   13696:                     da     => 'All with domain helpdesk assistant role',
1.285     raeburn  13697:                     none   => 'None',
                   13698:                     status => 'Determined based on institutional status',
                   13699:                     inc    => 'Include all, but exclude specific personnel',
                   13700:                     exc    => 'Exclude all, but include specific personnel',
                   13701:     );
                   13702:     for (my $num=0; $num<=$maxnum; $num++) {
                   13703:         my ($prefix,$identifier,$rolename,%curr);
                   13704:         if ($num == $maxnum) {
                   13705:             next unless ($env{'form.newcusthelp'} == $maxnum);
                   13706:             $identifier = 'custhelp'.$num;
                   13707:             $prefix = 'helproles_'.$num;
                   13708:             $rolename = $env{'form.custhelpname'.$num};
                   13709:             $rolename=~s/[^A-Za-z0-9]//gs;
                   13710:             next if ($rolename eq '');
                   13711:             next if (exists($existing{'rolesdef_'.$rolename}));
                   13712:             my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
                   13713:             my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
                   13714:                                                      $newprivs{'c'},$confname,$dom);
                   13715:             if ($result ne 'ok') {
                   13716:                 $errors .= '<li><span class="LC_error">'.
                   13717:                            &mt('An error occurred storing the new custom role: [_1]',
                   13718:                            $result).'</span></li>';
                   13719:                 next;
                   13720:             } else {
                   13721:                 $changedprivs{$rolename} = \%newprivs;
                   13722:                 $newrole = $rolename;
                   13723:             }
                   13724:         } else {
                   13725:             $prefix = 'helproles_'.$num;
                   13726:             $rolename = $env{'form.'.$prefix};
                   13727:             next if ($rolename eq '');
                   13728:             next unless (exists($existing{'rolesdef_'.$rolename}));
                   13729:             $identifier = 'custhelp'.$num;
                   13730:             my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
                   13731:             my %currprivs;
1.289     raeburn  13732:             ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
1.285     raeburn  13733:                 split(/\_/,$existing{'rolesdef_'.$rolename});
                   13734:             foreach my $level ('c','d','s') {
                   13735:                 if ($newprivs{$level} ne $currprivs{$level}) {
                   13736:                     my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
                   13737:                                                              $newprivs{'c'},$confname,$dom);
                   13738:                     if ($result ne 'ok') {
                   13739:                         $errors .= '<li><span class="LC_error">'.
                   13740:                                    &mt('An error occurred storing privileges for existing role [_1]: [_2]',
                   13741:                                        $rolename,$result).'</span></li>';
                   13742:                     } else {
                   13743:                         $changedprivs{$rolename} = \%newprivs;
                   13744:                     }
                   13745:                     last;
                   13746:                 }
                   13747:             }
                   13748:             if (ref($current{'adhoc'}) eq 'HASH') {
                   13749:                 if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
                   13750:                     %curr = %{$current{'adhoc'}{$rolename}};
                   13751:                 }
                   13752:             }
                   13753:         }
                   13754:         my $newpos = $env{'form.'.$prefix.'_pos'};
                   13755:         $newpos =~ s/\D+//g;
                   13756:         $allpos[$newpos] = $rolename;
                   13757:         my $newdesc = $env{'form.'.$prefix.'_desc'};
                   13758:         $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
                   13759:         if ($curr{'desc'}) {
                   13760:             if ($curr{'desc'} ne $newdesc) {
                   13761:                 $changes{'customrole'}{$rolename}{'desc'} = 1;
                   13762:                 $newsettings{$rolename}{'desc'} = $newdesc;
                   13763:             }
                   13764:         } elsif ($newdesc ne '') {
                   13765:             $changes{'customrole'}{$rolename}{'desc'} = 1;
                   13766:             $newsettings{$rolename}{'desc'} = $newdesc;
                   13767:         }
                   13768:         my $access = $env{'form.'.$prefix.'_access'};
                   13769:         if (grep(/^\Q$access\E$/,@accesstypes)) {
                   13770:             $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
                   13771:             if ($access eq 'status') {
                   13772:                 my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
                   13773:                 if (scalar(@statuses) == 0) {
1.289     raeburn  13774:                     $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
1.285     raeburn  13775:                 } else {
                   13776:                     my (@shownstatus,$numtypes);
                   13777:                     $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
                   13778:                     if (ref($types) eq 'ARRAY') {
                   13779:                         $numtypes = scalar(@{$types});
                   13780:                         foreach my $type (sort(@statuses)) {
                   13781:                             if ($type eq 'default') {
                   13782:                                 push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
                   13783:                             } elsif (grep(/^\Q$type\E$/,@{$types})) {
                   13784:                                 push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
                   13785:                                 push(@shownstatus,$usertypes->{$type});
                   13786:                             }
                   13787:                         }
                   13788:                     }
                   13789:                     if (grep(/^default$/,@statuses)) {
                   13790:                         push(@shownstatus,$othertitle);
                   13791:                     }
                   13792:                     if (scalar(@shownstatus) == 1+$numtypes) {
                   13793:                         $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
                   13794:                         delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
                   13795:                     } else {
                   13796:                         $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
                   13797:                         if (ref($curr{'status'}) eq 'ARRAY') {
                   13798:                             my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
                   13799:                             if (@diffs) {
                   13800:                                 $changes{'customrole'}{$rolename}{$access} = 1;
                   13801:                             }
                   13802:                         } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
                   13803:                             $changes{'customrole'}{$rolename}{$access} = 1;
1.282     raeburn  13804:                         }
1.166     raeburn  13805:                     }
                   13806:                 }
1.285     raeburn  13807:             } elsif (($access eq 'inc') || ($access eq 'exc')) {
                   13808:                 my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
                   13809:                 my @newspecstaff;
                   13810:                 $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
                   13811:                 foreach my $person (sort(@personnel)) {
                   13812:                     if ($domhelpdesk{$person}) {
                   13813:                         push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
                   13814:                     }
                   13815:                 }
                   13816:                 if (ref($curr{$access}) eq 'ARRAY') {
                   13817:                     my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
                   13818:                     if (@diffs) {
                   13819:                         $changes{'customrole'}{$rolename}{$access} = 1;
                   13820:                     }
                   13821:                 } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
                   13822:                     $changes{'customrole'}{$rolename}{$access} = 1;
                   13823:                 }
                   13824:                 foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
                   13825:                     my ($uname,$udom) = split(/:/,$person);
                   13826:                         push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
                   13827:                 }
                   13828:                 $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.166     raeburn  13829:             }
1.285     raeburn  13830:         } else {
                   13831:             $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
                   13832:         }
                   13833:         unless ($curr{'access'} eq $access) {
                   13834:             $changes{'customrole'}{$rolename}{'access'} = 1;
                   13835:             $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.282     raeburn  13836:         }
                   13837:     }
1.285     raeburn  13838:     if (@allpos > 0) {
                   13839:         my $idx = 0;
                   13840:         foreach my $rolename (@allpos) {
                   13841:             if ($rolename ne '') {
                   13842:                 $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
                   13843:                 if (ref($current{'adhoc'}) eq 'HASH') {
                   13844:                     if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
                   13845:                         if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
                   13846:                             $changes{'customrole'}{$rolename}{'order'} = 1;
1.289     raeburn  13847:                             $newsettings{$rolename}{'order'} = $idx+1;
1.285     raeburn  13848:                         }
                   13849:                     }
1.282     raeburn  13850:                 }
1.285     raeburn  13851:                 $idx ++;
1.166     raeburn  13852:             }
                   13853:         }
1.118     jms      13854:     }
1.123     jms      13855:     my $putresult;
                   13856:     if (keys(%changes) > 0) {
1.166     raeburn  13857:         $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168     raeburn  13858:         if ($putresult eq 'ok') {
1.285     raeburn  13859:             if (ref($helphash{'helpsettings'}) eq 'HASH') {
                   13860:                 $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
                   13861:                 if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
                   13862:                     $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
                   13863:                 }
                   13864:             }
                   13865:             my $cachetime = 24*60*60;
                   13866:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
                   13867:             if (ref($lastactref) eq 'HASH') {
                   13868:                 $lastactref->{'domdefaults'} = 1;
                   13869:             }
                   13870:         } else {
                   13871:             $errors .= '<li><span class="LC_error">'.
                   13872:                        &mt('An error occurred storing the settings: [_1]',
                   13873:                            $putresult).'</span></li>';
                   13874:         }
                   13875:     }
                   13876:     if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
                   13877:         $resulttext = &mt('Changes made:').'<ul>';
                   13878:         my (%shownprivs,@levelorder);
                   13879:         @levelorder = ('c','d','s');
                   13880:         if ((keys(%changes)) && ($putresult eq 'ok')) {
1.166     raeburn  13881:             foreach my $item (sort(keys(%changes))) {
                   13882:                 if ($item eq 'submitbugs') {
                   13883:                     $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
                   13884:                                               &Apache::loncommon::modal_link('http://bugs.loncapa.org',
                   13885:                                               &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.282     raeburn  13886:                 } elsif ($item eq 'customrole') {
                   13887:                     if (ref($changes{'customrole'}) eq 'HASH') {
1.285     raeburn  13888:                         my @keyorder = ('order','desc','access','status','exc','inc');
                   13889:                         my %keytext = &Apache::lonlocal::texthash(
                   13890:                                                                    order  => 'Order',
                   13891:                                                                    desc   => 'Role description',
                   13892:                                                                    access => 'Role usage',
1.300     droeschl 13893:                                                                    status => 'Allowed institutional types',
1.285     raeburn  13894:                                                                    exc    => 'Allowed personnel',
                   13895:                                                                    inc    => 'Disallowed personnel',
                   13896:                         );
1.282     raeburn  13897:                         foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.285     raeburn  13898:                             if (ref($changes{'customrole'}{$role}) eq 'HASH') {
                   13899:                                 if ($role eq $newrole) {
                   13900:                                     $resulttext .= '<li>'.&mt('New custom role added: [_1]',
                   13901:                                                               $role).'<ul>';
                   13902:                                 } else {
                   13903:                                     $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
                   13904:                                                               $role).'<ul>';
                   13905:                                 }
                   13906:                                 foreach my $key (@keyorder) {
                   13907:                                     if ($changes{'customrole'}{$role}{$key}) {
                   13908:                                         $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
                   13909:                                                                   $keytext{$key},$newsettings{$role}{$key}).
                   13910:                                                        '</li>';
                   13911:                                     }
                   13912:                                 }
                   13913:                                 if (ref($changedprivs{$role}) eq 'HASH') {
                   13914:                                     $shownprivs{$role} = 1;
                   13915:                                     $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
                   13916:                                     foreach my $level (@levelorder) {
                   13917:                                         foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
                   13918:                                             next if ($item eq '');
                   13919:                                             my ($priv) = split(/\&/,$item,2);
                   13920:                                             if (&Apache::lonnet::plaintext($priv)) {
                   13921:                                                 $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
                   13922:                                                 unless ($level eq 'c') {
                   13923:                                                     $resulttext .= ' ('.$lt{$level}.')';
                   13924:                                                 }
                   13925:                                                 $resulttext .= '</li>';
                   13926:                                             }
                   13927:                                         }
                   13928:                                     }
                   13929:                                     $resulttext .= '</ul>';
                   13930:                                 }
                   13931:                                 $resulttext .= '</ul></li>';
                   13932:                             }
                   13933:                         }
                   13934:                     }
                   13935:                 }
                   13936:             }
                   13937:         }
                   13938:         if (keys(%changedprivs)) {
                   13939:             foreach my $role (sort(keys(%changedprivs))) {
                   13940:                 unless ($shownprivs{$role}) {
                   13941:                     $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
                   13942:                                               $role).'<ul>'.
                   13943:                                    '<li>'.&mt('Privileges set to :').'<ul>';
                   13944:                     foreach my $level (@levelorder) {
                   13945:                         foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
                   13946:                             next if ($item eq '');
                   13947:                             my ($priv) = split(/\&/,$item,2);
                   13948:                             if (&Apache::lonnet::plaintext($priv)) {
                   13949:                                 $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
                   13950:                                 unless ($level eq 'c') {
                   13951:                                     $resulttext .= ' ('.$lt{$level}.')';
                   13952:                                 }
                   13953:                                 $resulttext .= '</li>';
                   13954:                             }
1.282     raeburn  13955:                         }
                   13956:                     }
1.285     raeburn  13957:                     $resulttext .= '</ul></li></ul></li>';
1.166     raeburn  13958:                 }
                   13959:             }
                   13960:         }
1.285     raeburn  13961:         $resulttext .= '</ul>';
                   13962:     } else {
                   13963:         $resulttext = &mt('No changes made to help settings');
1.118     jms      13964:     }
                   13965:     if ($errors) {
1.168     raeburn  13966:         $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.285     raeburn  13967:                                     $errors.'</ul>';
1.118     jms      13968:     }
                   13969:     return $resulttext;
                   13970: }
                   13971: 
1.121     raeburn  13972: sub modify_coursedefaults {
1.212     raeburn  13973:     my ($dom,$lastactref,%domconfig) = @_;
1.121     raeburn  13974:     my ($resulttext,$errors,%changes,%defaultshash);
1.257     raeburn  13975:     my %defaultchecked = (
                   13976:                            'canuse_pdfforms' => 'off',
                   13977:                            'uselcmath'       => 'on',
                   13978:                            'usejsme'         => 'on'
                   13979:                          );
                   13980:     my @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.198     raeburn  13981:     my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.276     raeburn  13982:                    'uploadquota_community','uploadquota_textbook','uploadquota_placement',
                   13983:                    'mysqltables_official','mysqltables_unofficial','mysqltables_community',
                   13984:                    'mysqltables_textbook','mysqltables_placement');
1.271     raeburn  13985:     my @types = ('official','unofficial','community','textbook','placement');
1.198     raeburn  13986:     my %staticdefaults = (
                   13987:                            anonsurvey_threshold => 10,
                   13988:                            uploadquota          => 500,
1.257     raeburn  13989:                            postsubmit           => 60,
1.276     raeburn  13990:                            mysqltables          => 172800,
1.198     raeburn  13991:                          );
1.314     raeburn  13992:     my %texoptions = (
                   13993:                         MathJax  => 'MathJax',
                   13994:                         mimetex  => &mt('Convert to Images'),
                   13995:                         tth      => &mt('TeX to HTML'),
                   13996:                      );
1.121     raeburn  13997:     $defaultshash{'coursedefaults'} = {};
                   13998: 
                   13999:     if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
                   14000:         if ($domconfig{'coursedefaults'} eq '') {
                   14001:             $domconfig{'coursedefaults'} = {};
                   14002:         }
                   14003:     }
                   14004: 
                   14005:     if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
                   14006:         foreach my $item (@toggles) {
                   14007:             if ($defaultchecked{$item} eq 'on') {
                   14008:                 if (($domconfig{'coursedefaults'}{$item} eq '') &&
                   14009:                     ($env{'form.'.$item} eq '0')) {
                   14010:                     $changes{$item} = 1;
1.192     raeburn  14011:                 } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121     raeburn  14012:                     $changes{$item} = 1;
                   14013:                 }
                   14014:             } elsif ($defaultchecked{$item} eq 'off') {
                   14015:                 if (($domconfig{'coursedefaults'}{$item} eq '') &&
                   14016:                     ($env{'form.'.$item} eq '1')) {
                   14017:                     $changes{$item} = 1;
                   14018:                 } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
                   14019:                     $changes{$item} = 1;
                   14020:                 }
                   14021:             }
                   14022:             $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
                   14023:         }
1.198     raeburn  14024:         foreach my $item (@numbers) {
                   14025:             my ($currdef,$newdef);
1.208     raeburn  14026:             $newdef = $env{'form.'.$item};
1.198     raeburn  14027:             if ($item eq 'anonsurvey_threshold') {
                   14028:                 $currdef = $domconfig{'coursedefaults'}{$item};
                   14029:                 $newdef =~ s/\D//g;
                   14030:                 if ($newdef eq '' || $newdef < 1) {
                   14031:                     $newdef = 1;
                   14032:                 }
                   14033:                 $defaultshash{'coursedefaults'}{$item} = $newdef;
                   14034:             } else {
1.276     raeburn  14035:                 my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
                   14036:                 if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
                   14037:                     $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.198     raeburn  14038:                 }
                   14039:                 $newdef =~ s/[^\w.\-]//g;
1.276     raeburn  14040:                 $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.198     raeburn  14041:             }
                   14042:             if ($currdef ne $newdef) {
                   14043:                 my $staticdef;
                   14044:                 if ($item eq 'anonsurvey_threshold') {
                   14045:                     unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
                   14046:                         $changes{$item} = 1;
                   14047:                     }
1.276     raeburn  14048:                 } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
1.289     raeburn  14049:                     my $setting = $1;
1.276     raeburn  14050:                     unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
                   14051:                         $changes{$setting} = 1;
1.198     raeburn  14052:                     }
                   14053:                 }
1.139     raeburn  14054:             }
                   14055:         }
1.314     raeburn  14056:         my $texengine;
                   14057:         if ($env{'form.texengine'} =~ /^(MathJax|mimetex|tth)$/) {
                   14058:             $texengine = $env{'form.texengine'};
                   14059:             if ($defaultshash{'coursedefaults'}{'texengine'} eq '') {
                   14060:                 unless ($texengine eq 'MathJax') {
                   14061:                     $changes{'texengine'} = 1;
                   14062:                 }
                   14063:             } elsif ($defaultshash{'coursedefaults'}{'texengine'} ne $texengine) {
                   14064:                 $changes{'texengine'} = 1;
                   14065:             }
                   14066:         }
                   14067:         if ($texengine ne '') {
                   14068:             $defaultshash{'coursedefaults'}{'texengine'} = $texengine;
                   14069:         }
1.264     raeburn  14070:         my $currclone = $domconfig{'coursedefaults'}{'canclone'};
                   14071:         my @currclonecode;
                   14072:         if (ref($currclone) eq 'HASH') {
                   14073:             if (ref($currclone->{'instcode'}) eq 'ARRAY') {
                   14074:                 @currclonecode = @{$currclone->{'instcode'}};
                   14075:             }
                   14076:         }
                   14077:         my $newclone;
1.289     raeburn  14078:         if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
1.264     raeburn  14079:             $newclone = $env{'form.canclone'};
                   14080:         }
                   14081:         if ($newclone eq 'instcode') {
                   14082:             my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
                   14083:             my (%codedefaults,@code_order,@clonecode);
                   14084:             &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
                   14085:                                                     \@code_order);
                   14086:             foreach my $item (@code_order) {
                   14087:                 if (grep(/^\Q$item\E$/,@newcodes)) {
                   14088:                     push(@clonecode,$item);
                   14089:                 }
                   14090:             }
                   14091:             if (@clonecode) {
                   14092:                 $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
                   14093:                 my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
                   14094:                 if (@diffs) {
                   14095:                     $changes{'canclone'} = 1;
                   14096:                 }
                   14097:             } else {
                   14098:                 $newclone eq '';
                   14099:             }
                   14100:         } elsif ($newclone ne '') {
1.289     raeburn  14101:             $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
                   14102:         }
1.264     raeburn  14103:         if ($newclone ne $currclone) {
                   14104:             $changes{'canclone'} = 1;
                   14105:         }
1.257     raeburn  14106:         my %credits;
                   14107:         foreach my $type (@types) {
                   14108:             unless ($type eq 'community') {
                   14109:                 $credits{$type} = $env{'form.'.$type.'_credits'};
                   14110:                 $credits{$type} =~ s/[^\d.]+//g;
                   14111:             }
                   14112:         }
                   14113:         if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
                   14114:             ($env{'form.coursecredits'} eq '1')) {
                   14115:             $changes{'coursecredits'} = 1;
                   14116:             foreach my $type (keys(%credits)) {
                   14117:                 $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
                   14118:             }
                   14119:         } else {
1.289     raeburn  14120:             if ($env{'form.coursecredits'} eq '1') {
1.257     raeburn  14121:                 foreach my $type (@types) {
                   14122:                     unless ($type eq 'community') {
1.289     raeburn  14123:                         if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
1.257     raeburn  14124:                             $changes{'coursecredits'} = 1;
                   14125:                         }
                   14126:                         $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
                   14127:                     }
                   14128:                 }
                   14129:             } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
                   14130:                 foreach my $type (@types) {
                   14131:                     unless ($type eq 'community') {
                   14132:                         if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
                   14133:                             $changes{'coursecredits'} = 1;
                   14134:                             last;
                   14135:                         }
                   14136:                     }
                   14137:                 }
                   14138:             }
                   14139:         }
                   14140:         if ($env{'form.postsubmit'} eq '1') {
                   14141:             $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
                   14142:             my %currtimeout;
                   14143:             if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
                   14144:                 if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
                   14145:                     $changes{'postsubmit'} = 1;
                   14146:                 }
                   14147:                 if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
                   14148:                     %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
                   14149:                 }
                   14150:             } else {
                   14151:                 $changes{'postsubmit'} = 1;
                   14152:             }
                   14153:             foreach my $type (@types) {
                   14154:                 my $timeout = $env{'form.'.$type.'_timeout'};
                   14155:                 $timeout =~ s/\D//g;
                   14156:                 if ($timeout == $staticdefaults{'postsubmit'}) {
                   14157:                     $timeout = '';
                   14158:                 } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
                   14159:                     $timeout = '0';
                   14160:                 }
                   14161:                 unless ($timeout eq '') {
                   14162:                     $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
                   14163:                 }
                   14164:                 if (exists($currtimeout{$type})) {
                   14165:                     if ($timeout ne $currtimeout{$type}) {
1.289     raeburn  14166:                         $changes{'postsubmit'} = 1;
1.257     raeburn  14167:                     }
                   14168:                 } elsif ($timeout ne '') {
                   14169:                     $changes{'postsubmit'} = 1;
                   14170:                 }
                   14171:             }
                   14172:         } else {
                   14173:             $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
                   14174:             if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
                   14175:                 if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
                   14176:                     $changes{'postsubmit'} = 1;
                   14177:                 }
                   14178:             } else {
                   14179:                 $changes{'postsubmit'} = 1;
                   14180:             }
1.192     raeburn  14181:         }
1.121     raeburn  14182:     }
                   14183:     my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
                   14184:                                              $dom);
                   14185:     if ($putresult eq 'ok') {
                   14186:         if (keys(%changes) > 0) {
1.213     raeburn  14187:             my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.257     raeburn  14188:             if (($changes{'canuse_pdfforms'}) || ($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.264     raeburn  14189:                 ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.314     raeburn  14190:                 ($changes{'canclone'}) || ($changes{'mysqltables'}) || ($changes{'texengine'})) {
                   14191:                 foreach my $item ('canuse_pdfforms','uselcmath','usejsme','texengine') {
1.257     raeburn  14192:                     if ($changes{$item}) {
                   14193:                         $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
                   14194:                     }
1.289     raeburn  14195:                 }
1.192     raeburn  14196:                 if ($changes{'coursecredits'}) {
                   14197:                     if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.257     raeburn  14198:                         foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
                   14199:                             $domdefaults{$type.'credits'} =
                   14200:                                 $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
                   14201:                         }
                   14202:                     }
                   14203:                 }
                   14204:                 if ($changes{'postsubmit'}) {
                   14205:                     if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
                   14206:                         $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
                   14207:                         if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
                   14208:                             foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
                   14209:                                 $domdefaults{$type.'postsubtimeout'} =
                   14210:                                     $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
                   14211:                             }
                   14212:                         }
1.192     raeburn  14213:                     }
                   14214:                 }
1.198     raeburn  14215:                 if ($changes{'uploadquota'}) {
                   14216:                     if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
                   14217:                         foreach my $type (@types) {
                   14218:                             $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
                   14219:                         }
                   14220:                     }
                   14221:                 }
1.264     raeburn  14222:                 if ($changes{'canclone'}) {
                   14223:                     if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
                   14224:                         if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
                   14225:                             my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
                   14226:                             if (@clonecodes) {
                   14227:                                 $domdefaults{'canclone'} = join('+',@clonecodes);
                   14228:                             }
                   14229:                         }
                   14230:                     } else {
                   14231:                         $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
                   14232:                     }
                   14233:                 }
1.121     raeburn  14234:                 my $cachetime = 24*60*60;
                   14235:                 &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212     raeburn  14236:                 if (ref($lastactref) eq 'HASH') {
                   14237:                     $lastactref->{'domdefaults'} = 1;
                   14238:                 }
1.121     raeburn  14239:             }
                   14240:             $resulttext = &mt('Changes made:').'<ul>';
                   14241:             foreach my $item (sort(keys(%changes))) {
                   14242:                 if ($item eq 'canuse_pdfforms') {
                   14243:                     if ($env{'form.'.$item} eq '1') {
                   14244:                         $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
                   14245:                     } else {
                   14246:                         $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
                   14247:                     }
1.257     raeburn  14248:                 } elsif ($item eq 'uselcmath') {
                   14249:                     if ($env{'form.'.$item} eq '1') {
                   14250:                         $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
                   14251:                     } else {
                   14252:                         $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
                   14253:                     }
                   14254:                 } elsif ($item eq 'usejsme') {
                   14255:                     if ($env{'form.'.$item} eq '1') {
                   14256:                         $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
                   14257:                     } else {
1.289     raeburn  14258:                         $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.257     raeburn  14259:                     }
1.314     raeburn  14260:                 } elsif ($item eq 'texengine') {
                   14261:                     if ($defaultshash{'coursedefaults'}{'texengine'} ne '') {
                   14262:                         $resulttext .= '<li>'.&mt('Default method to display mathematics set to: "[_1]"',
                   14263:                                                   $texoptions{$defaultshash{'coursedefaults'}{'texengine'}}).'</li>';
                   14264:                     }
1.139     raeburn  14265:                 } elsif ($item eq 'anonsurvey_threshold') {
1.192     raeburn  14266:                     $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198     raeburn  14267:                 } elsif ($item eq 'uploadquota') {
                   14268:                     if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
                   14269:                         $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
                   14270:                                        '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
                   14271:                                        '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216     raeburn  14272:                                        '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
1.271     raeburn  14273:                                        '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'placement'}.'</b>').'</li>'. 
1.198     raeburn  14274:                                        '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
                   14275:                                        '</ul>'.
                   14276:                                        '</li>';
                   14277:                     } else {
                   14278:                         $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
                   14279:                     }
1.276     raeburn  14280:                 } elsif ($item eq 'mysqltables') {
                   14281:                     if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
                   14282:                         $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
                   14283:                                        '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
                   14284:                                        '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
                   14285:                                        '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
                   14286:                                        '<li>'.&mt('Placement tests: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'placement'}.'</b>').'</li>'.
                   14287:                                        '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
                   14288:                                        '</ul>'.
                   14289:                                        '</li>';
                   14290:                     } else {
                   14291:                         $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
                   14292:                     }
1.257     raeburn  14293:                 } elsif ($item eq 'postsubmit') {
                   14294:                     if ($domdefaults{'postsubmit'} eq 'off') {
                   14295:                         $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
                   14296:                     } else {
                   14297:                         $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
1.289     raeburn  14298:                         if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
1.257     raeburn  14299:                             $resulttext .= &mt('durations:').'<ul>';
                   14300:                             foreach my $type (@types) {
                   14301:                                 $resulttext .= '<li>';
                   14302:                                 my $timeout;
                   14303:                                 if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
                   14304:                                     $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
                   14305:                                 }
                   14306:                                 my $display;
                   14307:                                 if ($timeout eq '0') {
                   14308:                                     $display = &mt('unlimited');
                   14309:                                 } elsif ($timeout eq '') {
                   14310:                                     $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
                   14311:                                 } else {
                   14312:                                     $display = &mt('[quant,_1,second]',$timeout);
                   14313:                                 }
                   14314:                                 if ($type eq 'community') {
                   14315:                                     $resulttext .= &mt('Communities');
                   14316:                                 } elsif ($type eq 'official') {
                   14317:                                     $resulttext .= &mt('Official courses');
                   14318:                                 } elsif ($type eq 'unofficial') {
                   14319:                                     $resulttext .= &mt('Unofficial courses');
                   14320:                                 } elsif ($type eq 'textbook') {
                   14321:                                     $resulttext .= &mt('Textbook courses');
1.271     raeburn  14322:                                 } elsif ($type eq 'placement') {
                   14323:                                     $resulttext .= &mt('Placement tests');
1.257     raeburn  14324:                                 }
                   14325:                                 $resulttext .= ' -- '.$display.'</li>';
                   14326:                             }
                   14327:                             $resulttext .= '</ul>';
                   14328:                         }
1.289     raeburn  14329:                         $resulttext .= '</li>';
1.257     raeburn  14330:                     }
1.192     raeburn  14331:                 } elsif ($item eq 'coursecredits') {
                   14332:                     if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
                   14333:                         if (($domdefaults{'officialcredits'} eq '') &&
1.216     raeburn  14334:                             ($domdefaults{'unofficialcredits'} eq '') &&
                   14335:                             ($domdefaults{'textbookcredits'} eq '')) {
1.192     raeburn  14336:                             $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
                   14337:                         } else {
                   14338:                             $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
                   14339:                                            '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
                   14340:                                            '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216     raeburn  14341:                                            '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192     raeburn  14342:                                            '</ul>'.
                   14343:                                            '</li>';
                   14344:                         }
                   14345:                     } else {
                   14346:                         $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
                   14347:                     }
1.264     raeburn  14348:                 } elsif ($item eq 'canclone') {
                   14349:                     if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
                   14350:                         if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
                   14351:                             my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
                   14352:                             $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
                   14353:                         }
                   14354:                     } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
                   14355:                         $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
                   14356:                     } else {
1.289     raeburn  14357:                         $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
1.264     raeburn  14358:                     }
1.140     raeburn  14359:                 }
1.121     raeburn  14360:             }
                   14361:             $resulttext .= '</ul>';
                   14362:         } else {
                   14363:             $resulttext = &mt('No changes made to course defaults');
                   14364:         }
                   14365:     } else {
                   14366:         $resulttext = '<span class="LC_error">'.
                   14367:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   14368:     }
                   14369:     return $resulttext;
                   14370: }
                   14371: 
1.231     raeburn  14372: sub modify_selfenrollment {
                   14373:     my ($dom,$lastactref,%domconfig) = @_;
                   14374:     my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
1.271     raeburn  14375:     my @types = ('official','unofficial','community','textbook','placement');
1.231     raeburn  14376:     my %titles = &tool_titles();
1.232     raeburn  14377:     my %descs = &Apache::lonuserutils::selfenroll_default_descs();
                   14378:     ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
1.231     raeburn  14379:     $ordered{'default'} = ['types','registered','approval','limit'];
                   14380: 
                   14381:     my (%roles,%shown,%toplevel);
                   14382:     $roles{'0'} = &Apache::lonnet::plaintext('dc');
                   14383: 
                   14384:     if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
                   14385:         if ($domconfig{'selfenrollment'} eq '') {
                   14386:             $domconfig{'selfenrollment'} = {};
                   14387:         }
                   14388:     }
                   14389:     %toplevel = (
                   14390:                   admin      => 'Configuration Rights',
                   14391:                   default    => 'Default settings',
                   14392:                   validation => 'Validation of self-enrollment requests',
                   14393:                 );
1.233     raeburn  14394:     my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
1.231     raeburn  14395: 
                   14396:     if (ref($ordered{'admin'}) eq 'ARRAY') {
                   14397:         foreach my $item (@{$ordered{'admin'}}) {
                   14398:             foreach my $type (@types) {
                   14399:                 if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
                   14400:                     $selfenrollhash{'admin'}{$type}{$item} = 1;
                   14401:                 } else {
                   14402:                     $selfenrollhash{'admin'}{$type}{$item} = 0;
                   14403:                 }
                   14404:                 if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
                   14405:                     if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
                   14406:                         if ($selfenrollhash{'admin'}{$type}{$item} ne
                   14407:                             $domconfig{'selfenrollment'}{'admin'}{$type}{$item})  {
                   14408:                             push(@{$changes{'admin'}{$type}},$item);
                   14409:                         }
                   14410:                     } else {
                   14411:                         if (!$selfenrollhash{'admin'}{$type}{$item}) {
                   14412:                             push(@{$changes{'admin'}{$type}},$item);
                   14413:                         }
                   14414:                     }
                   14415:                 } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
                   14416:                     push(@{$changes{'admin'}{$type}},$item);
                   14417:                 }
                   14418:             }
                   14419:         }
                   14420:     }
                   14421: 
                   14422:     foreach my $item (@{$ordered{'default'}}) {
                   14423:         foreach my $type (@types) {
                   14424:             my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
                   14425:             if ($item eq 'types') {
                   14426:                 unless (($value eq 'all') || ($value eq 'dom')) {
                   14427:                     $value = '';
                   14428:                 }
                   14429:             } elsif ($item eq 'registered') {
                   14430:                 unless ($value eq '1') {
                   14431:                     $value = 0;
                   14432:                 }
                   14433:             } elsif ($item eq 'approval') {
                   14434:                 unless ($value =~ /^[012]$/) {
                   14435:                     $value = 0;
                   14436:                 }
                   14437:             } else {
                   14438:                 unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
                   14439:                     $value = 'none';
                   14440:                 }
                   14441:             }
                   14442:             $selfenrollhash{'default'}{$type}{$item} = $value;
                   14443:             if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
                   14444:                 if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
                   14445:                     if ($selfenrollhash{'default'}{$type}{$item} ne
                   14446:                          $domconfig{'selfenrollment'}{'default'}{$type}{$item})  {
                   14447:                          push(@{$changes{'default'}{$type}},$item);
                   14448:                     }
                   14449:                 } else {
                   14450:                     push(@{$changes{'default'}{$type}},$item);
                   14451:                 }
                   14452:             } else {
                   14453:                 push(@{$changes{'default'}{$type}},$item);
                   14454:             }
                   14455:             if ($item eq 'limit') {
                   14456:                 if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
                   14457:                     $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
                   14458:                     if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
                   14459:                         $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
                   14460:                     }
                   14461:                 } else {
                   14462:                     $selfenrollhash{'default'}{$type}{'cap'} = '';
                   14463:                 }
                   14464:                 if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
                   14465:                     if ($selfenrollhash{'default'}{$type}{'cap'} ne
                   14466:                          $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'})  {
                   14467:                          push(@{$changes{'default'}{$type}},'cap');
                   14468:                     }
                   14469:                 } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
                   14470:                     push(@{$changes{'default'}{$type}},'cap');
                   14471:                 }
                   14472:             }
                   14473:         }
                   14474:     }
                   14475: 
                   14476:     foreach my $item (@{$itemsref}) {
                   14477:         if ($item eq 'fields') {
                   14478:             my @changed;
                   14479:             @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
                   14480:             if (@{$selfenrollhash{'validation'}{$item}} > 0) {
                   14481:                 @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
                   14482:             }
                   14483:             if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
                   14484:                 if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
                   14485:                     @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
                   14486:                                                                   $domconfig{'selfenrollment'}{'validation'}{$item});
                   14487:                 } else {
                   14488:                     @changed = @{$selfenrollhash{'validation'}{$item}};
                   14489:                 }
                   14490:             } else {
                   14491:                 @changed = @{$selfenrollhash{'validation'}{$item}};
                   14492:             }
                   14493:             if (@changed) {
                   14494:                 if ($selfenrollhash{'validation'}{$item}) { 
                   14495:                     $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
                   14496:                 } else {
                   14497:                     $changes{'validation'}{$item} = &mt('None');
                   14498:                 }
                   14499:             }
                   14500:         } else {
                   14501:             $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
                   14502:             if ($item eq 'markup') {
                   14503:                if ($env{'form.selfenroll_validation_'.$item}) {
                   14504:                    $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
                   14505:                }
                   14506:             }
                   14507:             if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
                   14508:                 if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
                   14509:                     $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
                   14510:                 }
                   14511:             }
                   14512:         }
                   14513:     }
                   14514: 
                   14515:     my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
                   14516:                                              $dom);
                   14517:     if ($putresult eq 'ok') {
                   14518:         if (keys(%changes) > 0) {
                   14519:             my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
                   14520:             $resulttext = &mt('Changes made:').'<ul>';
                   14521:             foreach my $key ('admin','default','validation') {
                   14522:                 if (ref($changes{$key}) eq 'HASH') {
                   14523:                     $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
                   14524:                     if ($key eq 'validation') {
                   14525:                         foreach my $item (@{$itemsref}) {
                   14526:                             if (exists($changes{$key}{$item})) {
                   14527:                                 if ($item eq 'markup') {
                   14528:                                     $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
                   14529:                                                               '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
                   14530:                                 } else {  
                   14531:                                     $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
                   14532:                                                               '<b>'.$changes{$key}{$item}.'</b>').'</li>';
                   14533:                                 }
                   14534:                             }
                   14535:                         }
                   14536:                     } else {
                   14537:                         foreach my $type (@types) {
                   14538:                             if ($type eq 'community') {
                   14539:                                 $roles{'1'} = &mt('Community personnel');
                   14540:                             } else {
                   14541:                                 $roles{'1'} = &mt('Course personnel');
                   14542:                             }
                   14543:                             if (ref($changes{$key}{$type}) eq 'ARRAY') {
1.232     raeburn  14544:                                 if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
                   14545:                                     if ($key eq 'admin') {
                   14546:                                         my @mgrdc = ();
                   14547:                                         if (ref($ordered{$key}) eq 'ARRAY') {
                   14548:                                             foreach my $item (@{$ordered{'admin'}}) {
                   14549:                                                 if (ref($selfenrollhash{$key}{$type}) eq 'HASH') { 
                   14550:                                                     if ($selfenrollhash{$key}{$type}{$item} eq '0') {
                   14551:                                                         push(@mgrdc,$item);
                   14552:                                                     }
                   14553:                                                 }
                   14554:                                             }
                   14555:                                             if (@mgrdc) {
                   14556:                                                 $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
                   14557:                                             } else {
                   14558:                                                 delete($domdefaults{$type.'selfenrolladmdc'});
                   14559:                                             }
                   14560:                                         }
                   14561:                                     } else {
                   14562:                                         if (ref($ordered{$key}) eq 'ARRAY') {
                   14563:                                             foreach my $item (@{$ordered{$key}}) {
                   14564:                                                 if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
                   14565:                                                     $domdefaults{$type.'selfenroll'.$item} =
                   14566:                                                         $selfenrollhash{$key}{$type}{$item};
                   14567:                                                 }
                   14568:                                             }
                   14569:                                         }
                   14570:                                     }
                   14571:                                 }
1.231     raeburn  14572:                                 $resulttext .= '<li>'.$titles{$type}.'<ul>';
                   14573:                                 foreach my $item (@{$ordered{$key}}) {
                   14574:                                     if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
                   14575:                                         $resulttext .= '<li>';
                   14576:                                         if ($key eq 'admin') {
                   14577:                                             $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
                   14578:                                                                '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
                   14579:                                         } else {
                   14580:                                             $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
                   14581:                                                                '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
                   14582:                                         }
                   14583:                                         $resulttext .= '</li>';
                   14584:                                     }
                   14585:                                 }
                   14586:                                 $resulttext .= '</ul></li>';
                   14587:                             }
                   14588:                         }
                   14589:                         $resulttext .= '</ul></li>'; 
                   14590:                     }
                   14591:                 }
1.305     raeburn  14592:             }
                   14593:             if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
                   14594:                 my $cachetime = 24*60*60;
                   14595:                 &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
                   14596:                 if (ref($lastactref) eq 'HASH') {
                   14597:                     $lastactref->{'domdefaults'} = 1;
1.232     raeburn  14598:                 }
1.231     raeburn  14599:             }
                   14600:             $resulttext .= '</ul>';
                   14601:         } else {
                   14602:             $resulttext = &mt('No changes made to self-enrollment settings');
                   14603:         }
                   14604:     } else {
                   14605:         $resulttext = '<span class="LC_error">'.
                   14606:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   14607:     }
                   14608:     return $resulttext;
                   14609: }
                   14610: 
1.137     raeburn  14611: sub modify_usersessions {
1.212     raeburn  14612:     my ($dom,$lastactref,%domconfig) = @_;
1.145     raeburn  14613:     my @hostingtypes = ('version','excludedomain','includedomain');
                   14614:     my @offloadtypes = ('primary','default');
                   14615:     my %types = (
                   14616:                   remote => \@hostingtypes,
                   14617:                   hosted => \@hostingtypes,
                   14618:                   spares => \@offloadtypes,
                   14619:                 );
                   14620:     my @prefixes = ('remote','hosted','spares');
1.137     raeburn  14621:     my @lcversions = &Apache::lonnet::all_loncaparevs();
1.275     raeburn  14622:     my (%by_ip,%by_location,@intdoms,@instdoms);
                   14623:     &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.138     raeburn  14624:     my @locations = sort(keys(%by_location));
1.137     raeburn  14625:     my (%defaultshash,%changes);
                   14626:     foreach my $prefix (@prefixes) {
                   14627:         $defaultshash{'usersessions'}{$prefix} = {};
                   14628:     }
1.212     raeburn  14629:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137     raeburn  14630:     my $resulttext;
1.138     raeburn  14631:     my %iphost = &Apache::lonnet::get_iphost();
1.137     raeburn  14632:     foreach my $prefix (@prefixes) {
1.145     raeburn  14633:         next if ($prefix eq 'spares');
                   14634:         foreach my $type (@{$types{$prefix}}) {
1.137     raeburn  14635:             my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
                   14636:             if ($type eq 'version') {
                   14637:                 my $value = $env{'form.'.$prefix.'_'.$type};
                   14638:                 my $okvalue;
                   14639:                 if ($value ne '') {
                   14640:                     if (grep(/^\Q$value\E$/,@lcversions)) {
                   14641:                         $okvalue = $value;
                   14642:                     }
                   14643:                 }
                   14644:                 if (ref($domconfig{'usersessions'}) eq 'HASH') {
                   14645:                     if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
                   14646:                         if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
                   14647:                             if ($inuse == 0) {
                   14648:                                 $changes{$prefix}{$type} = 1;
                   14649:                             } else {
                   14650:                                 if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
                   14651:                                     $changes{$prefix}{$type} = 1;
                   14652:                                 }
                   14653:                                 if ($okvalue ne '') {
                   14654:                                     $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
                   14655:                                 } 
                   14656:                             }
                   14657:                         } else {
                   14658:                             if (($inuse == 1) && ($okvalue ne '')) {
                   14659:                                 $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
                   14660:                                 $changes{$prefix}{$type} = 1;
                   14661:                             }
                   14662:                         }
                   14663:                     } else {
                   14664:                         if (($inuse == 1) && ($okvalue ne '')) {
                   14665:                             $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
                   14666:                             $changes{$prefix}{$type} = 1;
                   14667:                         }
                   14668:                     }
                   14669:                 } else {
                   14670:                     if (($inuse == 1) && ($okvalue ne '')) {
                   14671:                         $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
                   14672:                         $changes{$prefix}{$type} = 1;
                   14673:                     }
                   14674:                 }
                   14675:             } else {
                   14676:                 my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
                   14677:                 my @okvals;
                   14678:                 foreach my $val (@vals) {
1.138     raeburn  14679:                     if ($val =~ /:/) {
                   14680:                         my @items = split(/:/,$val);
                   14681:                         foreach my $item (@items) {
                   14682:                             if (ref($by_location{$item}) eq 'ARRAY') {
                   14683:                                 push(@okvals,$item);
                   14684:                             }
                   14685:                         }
                   14686:                     } else {
                   14687:                         if (ref($by_location{$val}) eq 'ARRAY') {
                   14688:                             push(@okvals,$val);
                   14689:                         }
1.137     raeburn  14690:                     }
                   14691:                 }
                   14692:                 @okvals = sort(@okvals);
                   14693:                 if (ref($domconfig{'usersessions'}) eq 'HASH') {
                   14694:                     if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
                   14695:                         if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
                   14696:                             if ($inuse == 0) {
                   14697:                                 $changes{$prefix}{$type} = 1; 
                   14698:                             } else {
                   14699:                                 $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
                   14700:                                 my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
                   14701:                                 if (@changed > 0) {
                   14702:                                     $changes{$prefix}{$type} = 1;
                   14703:                                 }
                   14704:                             }
                   14705:                         } else {
                   14706:                             if ($inuse == 1) {
                   14707:                                 $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
                   14708:                                 $changes{$prefix}{$type} = 1;
                   14709:                             }
                   14710:                         } 
                   14711:                     } else {
                   14712:                         if ($inuse == 1) {
                   14713:                             $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
                   14714:                             $changes{$prefix}{$type} = 1;
                   14715:                         }
                   14716:                     }
                   14717:                 } else {
                   14718:                     if ($inuse == 1) {
                   14719:                         $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
                   14720:                         $changes{$prefix}{$type} = 1;
                   14721:                     }
                   14722:                 }
                   14723:             }
                   14724:         }
                   14725:     }
1.145     raeburn  14726: 
                   14727:     my @alldoms = &Apache::lonnet::all_domains();
1.149     raeburn  14728:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145     raeburn  14729:     my %spareid = &current_offloads_to($dom,$domconfig{'usersessions'},\%servers);
                   14730:     my $savespares;
                   14731: 
                   14732:     foreach my $lonhost (sort(keys(%servers))) {
                   14733:         my $serverhomeID =
                   14734:             &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152     raeburn  14735:         my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145     raeburn  14736:         $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
                   14737:         my %spareschg;
                   14738:         foreach my $type (@{$types{'spares'}}) {
                   14739:             my @okspares;
                   14740:             my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
                   14741:             foreach my $server (@checked) {
1.152     raeburn  14742:                 if (&Apache::lonnet::hostname($server) ne '') {
                   14743:                     unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
                   14744:                         unless (grep(/^\Q$server\E$/,@okspares)) {
                   14745:                             push(@okspares,$server);
                   14746:                         }
1.145     raeburn  14747:                     }
                   14748:                 }
                   14749:             }
                   14750:             my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
                   14751:             my $newspare;
1.152     raeburn  14752:             if (($new ne '') && (&Apache::lonnet::hostname($new))) {
                   14753:                 unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145     raeburn  14754:                     $newspare = $new;
                   14755:                 }
                   14756:             }
1.152     raeburn  14757:             my @spares;
                   14758:             if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
                   14759:                 @spares = sort(@okspares,$newspare);
                   14760:             } else {
                   14761:                 @spares = sort(@okspares);
                   14762:             }
                   14763:             $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145     raeburn  14764:             if (ref($spareid{$lonhost}) eq 'HASH') {
                   14765:                 if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152     raeburn  14766:                     my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145     raeburn  14767:                     if (@diffs > 0) {
                   14768:                         $spareschg{$type} = 1;
                   14769:                     }
                   14770:                 }
                   14771:             }
                   14772:         }
                   14773:         if (keys(%spareschg) > 0) {
                   14774:             $changes{'spares'}{$lonhost} = \%spareschg;
                   14775:         }
                   14776:     }
1.261     raeburn  14777:     $defaultshash{'usersessions'}{'offloadnow'} = {};
                   14778:     my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
                   14779:     my @okoffload;
                   14780:     if (@offloadnow) {
                   14781:         foreach my $server (@offloadnow) {
                   14782:             if (&Apache::lonnet::hostname($server) ne '') {
                   14783:                 unless (grep(/^\Q$server\E$/,@okoffload)) {
                   14784:                     push(@okoffload,$server);
                   14785:                 }
                   14786:             }
                   14787:         }
                   14788:         if (@okoffload) {
                   14789:             foreach my $lonhost (@okoffload) {
                   14790:                 $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
                   14791:             }
                   14792:         }
                   14793:     }
1.145     raeburn  14794:     if (ref($domconfig{'usersessions'}) eq 'HASH') {
                   14795:         if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
                   14796:             if (ref($changes{'spares'}) eq 'HASH') {
                   14797:                 if (keys(%{$changes{'spares'}}) > 0) {
                   14798:                     $savespares = 1;
                   14799:                 }
                   14800:             }
                   14801:         } else {
                   14802:             $savespares = 1;
                   14803:         }
1.261     raeburn  14804:         if (ref($domconfig{'usersessions'}{'offloadnow'}) eq 'HASH') {
                   14805:             foreach my $lonhost (keys(%{$domconfig{'usersessions'}{'offloadnow'}})) {
                   14806:                 unless ($defaultshash{'usersessions'}{'offloadnow'}{$lonhost}) {
                   14807:                     $changes{'offloadnow'} = 1;
                   14808:                     last;
                   14809:                 }
                   14810:             }
                   14811:             unless ($changes{'offloadnow'}) {
1.289     raeburn  14812:                 foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{'offloadnow'}})) {
1.261     raeburn  14813:                     unless ($domconfig{'usersessions'}{'offloadnow'}{$lonhost}) {
                   14814:                         $changes{'offloadnow'} = 1;
                   14815:                         last;
                   14816:                     }
                   14817:                 }
                   14818:             }
                   14819:         } elsif (@okoffload) {
                   14820:             $changes{'offloadnow'} = 1;
                   14821:         }
                   14822:     } elsif (@okoffload) {
                   14823:         $changes{'offloadnow'} = 1;
1.145     raeburn  14824:     }
1.147     raeburn  14825:     my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
                   14826:     if ((keys(%changes) > 0) || ($savespares)) {
1.137     raeburn  14827:         my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
                   14828:                                                  $dom);
                   14829:         if ($putresult eq 'ok') {
                   14830:             if (ref($defaultshash{'usersessions'}) eq 'HASH') {
                   14831:                 if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
                   14832:                     $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
                   14833:                 }
                   14834:                 if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
                   14835:                     $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
                   14836:                 }
1.261     raeburn  14837:                 if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
                   14838:                     $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
                   14839:                 }
1.137     raeburn  14840:             }
                   14841:             my $cachetime = 24*60*60;
                   14842:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.295     raeburn  14843:             &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.212     raeburn  14844:             if (ref($lastactref) eq 'HASH') {
                   14845:                 $lastactref->{'domdefaults'} = 1;
1.295     raeburn  14846:                 $lastactref->{'usersessions'} = 1;
1.212     raeburn  14847:             }
1.147     raeburn  14848:             if (keys(%changes) > 0) {
                   14849:                 my %lt = &usersession_titles();
                   14850:                 $resulttext = &mt('Changes made:').'<ul>';
                   14851:                 foreach my $prefix (@prefixes) {
                   14852:                     if (ref($changes{$prefix}) eq 'HASH') {
                   14853:                         $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
                   14854:                         if ($prefix eq 'spares') {
                   14855:                             if (ref($changes{$prefix}) eq 'HASH') {
                   14856:                                 foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
                   14857:                                     $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148     raeburn  14858:                                     my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211     raeburn  14859:                                     my $cachekey = &escape('spares').':'.&escape($lonhostdom);
                   14860:                                     &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147     raeburn  14861:                                     if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
                   14862:                                         foreach my $type (@{$types{$prefix}}) {
                   14863:                                             if ($changes{$prefix}{$lonhost}{$type}) {
                   14864:                                                 my $offloadto = &mt('None');
                   14865:                                                 if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
                   14866:                                                     if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {   
                   14867:                                                         $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
                   14868:                                                     }
1.145     raeburn  14869:                                                 }
1.147     raeburn  14870:                                                 $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).('&nbsp;'x3);
1.145     raeburn  14871:                                             }
1.137     raeburn  14872:                                         }
                   14873:                                     }
1.147     raeburn  14874:                                     $resulttext .= '</li>';
1.137     raeburn  14875:                                 }
                   14876:                             }
1.147     raeburn  14877:                         } else {
                   14878:                             foreach my $type (@{$types{$prefix}}) {
                   14879:                                 if (defined($changes{$prefix}{$type})) {
                   14880:                                     my $newvalue;
                   14881:                                     if (ref($defaultshash{'usersessions'}) eq 'HASH') {
                   14882:                                         if (ref($defaultshash{'usersessions'}{$prefix})) {
                   14883:                                             if ($type eq 'version') {
                   14884:                                                 $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
                   14885:                                             } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
                   14886:                                                 if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
                   14887:                                                     $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
                   14888:                                                 }
1.145     raeburn  14889:                                             }
                   14890:                                         }
                   14891:                                     }
1.147     raeburn  14892:                                     if ($newvalue eq '') {
                   14893:                                         if ($type eq 'version') {
                   14894:                                             $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
                   14895:                                         } else {
                   14896:                                             $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
                   14897:                                         }
1.145     raeburn  14898:                                     } else {
1.147     raeburn  14899:                                         if ($type eq 'version') {
                   14900:                                             $newvalue .= ' '.&mt('(or later)'); 
                   14901:                                         }
                   14902:                                         $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145     raeburn  14903:                                     }
1.137     raeburn  14904:                                 }
                   14905:                             }
                   14906:                         }
1.147     raeburn  14907:                         $resulttext .= '</ul>';
1.137     raeburn  14908:                     }
                   14909:                 }
1.261     raeburn  14910:                 if ($changes{'offloadnow'}) {
                   14911:                     if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
                   14912:                         if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
                   14913:                             $resulttext .= '<li>'.&mt('Switch active users on next access, for server(s):').'<ul>';
                   14914:                             foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
                   14915:                                 $resulttext .= '<li>'.$lonhost.'</li>';
                   14916:                             }
                   14917:                             $resulttext .= '</ul>';
                   14918:                         } else {
                   14919:                             $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.');
                   14920:                         }
                   14921:                     } else {
                   14922:                         $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.').'</li>';
                   14923:                     }
                   14924:                 }
1.147     raeburn  14925:                 $resulttext .= '</ul>';
                   14926:             } else {
                   14927:                 $resulttext = $nochgmsg;
1.137     raeburn  14928:             }
                   14929:         } else {
                   14930:             $resulttext = '<span class="LC_error">'.
                   14931:                           &mt('An error occurred: [_1]',$putresult).'</span>';
                   14932:         }
                   14933:     } else {
1.147     raeburn  14934:         $resulttext = $nochgmsg;
1.137     raeburn  14935:     }
                   14936:     return $resulttext;
                   14937: }
                   14938: 
1.275     raeburn  14939: sub modify_ssl {
                   14940:     my ($dom,$lastactref,%domconfig) = @_;
                   14941:     my (%by_ip,%by_location,@intdoms,@instdoms);
                   14942:     &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
                   14943:     my @locations = sort(keys(%by_location));
                   14944:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
                   14945:     my (%defaultshash,%changes);
                   14946:     my $action = 'ssl';
1.293     raeburn  14947:     my @prefixes = ('connto','connfrom','replication');
1.275     raeburn  14948:     foreach my $prefix (@prefixes) {
                   14949:         $defaultshash{$action}{$prefix} = {};
                   14950:     }
                   14951:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
                   14952:     my $resulttext;
                   14953:     my %iphost = &Apache::lonnet::get_iphost();
                   14954:     my @reptypes = ('certreq','nocertreq');
                   14955:     my @connecttypes = ('dom','intdom','other');
                   14956:     my %types = (
1.293     raeburn  14957:                   connto      => \@connecttypes,
                   14958:                   connfrom    => \@connecttypes,
                   14959:                   replication => \@reptypes,
1.275     raeburn  14960:                 );
                   14961:     foreach my $prefix (sort(keys(%types))) {
                   14962:         foreach my $type (@{$types{$prefix}}) {
1.293     raeburn  14963:             if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275     raeburn  14964:                 my $value = 'yes';
                   14965:                 if ($env{'form.'.$prefix.'_'.$type} =~ /^(no|req)$/) {
                   14966:                     $value = $env{'form.'.$prefix.'_'.$type};
                   14967:                 }
                   14968:                 if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
                   14969:                     if ($domconfig{$action}{$prefix}{$type} ne '') {
                   14970:                         if ($value ne $domconfig{$action}{$prefix}{$type}) {
                   14971:                             $changes{$prefix}{$type} = 1;
                   14972:                         }
                   14973:                         $defaultshash{$action}{$prefix}{$type} = $value;
                   14974:                     } else {
                   14975:                         $defaultshash{$action}{$prefix}{$type} = $value;
                   14976:                         $changes{$prefix}{$type} = 1;
                   14977:                     }
                   14978:                 } else {
                   14979:                     $defaultshash{$action}{$prefix}{$type} = $value;
                   14980:                     $changes{$prefix}{$type} = 1;
                   14981:                 }
                   14982:                 if (($type eq 'dom') && (keys(%servers) == 1)) {
                   14983:                     delete($changes{$prefix}{$type});
                   14984:                 } elsif (($type eq 'intdom') && (@instdoms == 1)) {
                   14985:                     delete($changes{$prefix}{$type});
                   14986:                 } elsif (($type eq 'other') && (keys(%by_location) == 0)) { 
                   14987:                     delete($changes{$prefix}{$type});
                   14988:                 }
                   14989:             } elsif ($prefix eq 'replication') {
                   14990:                 if (@locations > 0) {
                   14991:                     my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
                   14992:                     my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
                   14993:                     my @okvals;
                   14994:                     foreach my $val (@vals) {
                   14995:                         if ($val =~ /:/) {
                   14996:                             my @items = split(/:/,$val);
                   14997:                             foreach my $item (@items) {
                   14998:                                 if (ref($by_location{$item}) eq 'ARRAY') {
                   14999:                                     push(@okvals,$item);
                   15000:                                 }
                   15001:                             }
                   15002:                         } else {
                   15003:                             if (ref($by_location{$val}) eq 'ARRAY') {
                   15004:                                 push(@okvals,$val);
                   15005:                             }
                   15006:                         }
                   15007:                     }
                   15008:                     @okvals = sort(@okvals);
                   15009:                     if (ref($domconfig{$action}) eq 'HASH') {
                   15010:                         if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
                   15011:                             if (ref($domconfig{$action}{$prefix}{$type}) eq 'ARRAY') {
                   15012:                                 if ($inuse == 0) {
                   15013:                                     $changes{$prefix}{$type} = 1;
                   15014:                                 } else {
                   15015:                                     $defaultshash{$action}{$prefix}{$type} = \@okvals;
                   15016:                                     my @changed = &Apache::loncommon::compare_arrays($domconfig{$action}{$prefix}{$type},$defaultshash{$action}{$prefix}{$type});
                   15017:                                     if (@changed > 0) {
                   15018:                                         $changes{$prefix}{$type} = 1;
                   15019:                                     }
                   15020:                                 }
                   15021:                             } else {
                   15022:                                 if ($inuse == 1) {
                   15023:                                     $defaultshash{$action}{$prefix}{$type} = \@okvals;
                   15024:                                     $changes{$prefix}{$type} = 1;
                   15025:                                 }
                   15026:                             }
                   15027:                         } else {
                   15028:                             if ($inuse == 1) {
                   15029:                                 $defaultshash{$action}{$prefix}{$type} = \@okvals;
                   15030:                                 $changes{$prefix}{$type} = 1;
                   15031:                             }
                   15032:                         }
                   15033:                     } else {
                   15034:                         if ($inuse == 1) {
                   15035:                             $defaultshash{$action}{$prefix}{$type} = \@okvals;
                   15036:                             $changes{$prefix}{$type} = 1;
                   15037:                         }
                   15038:                     }
                   15039:                 }
                   15040:             }
                   15041:         }
                   15042:     }
                   15043:     my $nochgmsg = &mt('No changes made to LON-CAPA SSL settings');
                   15044:     if (keys(%changes) > 0) {
                   15045:         my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
                   15046:                                                  $dom);
                   15047:         if ($putresult eq 'ok') {
                   15048:             if (ref($defaultshash{$action}) eq 'HASH') {
                   15049:                 if (ref($defaultshash{$action}{'replication'}) eq 'HASH') {
                   15050:                     $domdefaults{'replication'} = $defaultshash{$action}{'replication'};
                   15051:                 }
1.293     raeburn  15052:                 if (ref($defaultshash{$action}{'connto'}) eq 'HASH') {
                   15053:                     $domdefaults{'connto'} = $domconfig{$action}{'connto'};
                   15054:                 }
                   15055:                 if (ref($defaultshash{$action}{'connfrom'}) eq 'HASH') {
                   15056:                     $domdefaults{'connfrom'} = $domconfig{$action}{'connfrom'};
1.275     raeburn  15057:                 }
                   15058:             }
                   15059:             my $cachetime = 24*60*60;
                   15060:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
                   15061:             if (ref($lastactref) eq 'HASH') {
                   15062:                 $lastactref->{'domdefaults'} = 1;
                   15063:             }
                   15064:             if (keys(%changes) > 0) {
                   15065:                 my %titles = &ssl_titles();
                   15066:                 $resulttext = &mt('Changes made:').'<ul>';
                   15067:                 foreach my $prefix (@prefixes) {
                   15068:                     if (ref($changes{$prefix}) eq 'HASH') {
                   15069:                         $resulttext .= '<li>'.$titles{$prefix}.'<ul>';
                   15070:                         foreach my $type (@{$types{$prefix}}) {
                   15071:                             if (defined($changes{$prefix}{$type})) {
                   15072:                                 my $newvalue;
                   15073:                                 if (ref($defaultshash{$action}) eq 'HASH') {
                   15074:                                     if (ref($defaultshash{$action}{$prefix})) {
1.293     raeburn  15075:                                         if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275     raeburn  15076:                                             $newvalue = $titles{$defaultshash{$action}{$prefix}{$type}};
                   15077:                                         } elsif (ref($defaultshash{$action}{$prefix}{$type}) eq 'ARRAY') {
                   15078:                                             if (@{$defaultshash{$action}{$prefix}{$type}} > 0) {
                   15079:                                                 $newvalue = join(', ',@{$defaultshash{$action}{$prefix}{$type}});
                   15080:                                             }
                   15081:                                         }
                   15082:                                     }
                   15083:                                     if ($newvalue eq '') {
                   15084:                                         $resulttext .= '<li>'.&mt('[_1] set to: none',$titles{$type}).'</li>';
                   15085:                                     } else {
                   15086:                                         $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$titles{$type},$newvalue).'</li>';
                   15087:                                     }
                   15088:                                 }
                   15089:                             }
                   15090:                         }
                   15091:                         $resulttext .= '</ul>';
                   15092:                     }
                   15093:                 }
                   15094:             } else {
                   15095:                 $resulttext = $nochgmsg;
                   15096:             }
                   15097:         } else {
                   15098:             $resulttext = '<span class="LC_error">'.
                   15099:                           &mt('An error occurred: [_1]',$putresult).'</span>';
                   15100:         }
                   15101:     } else {
                   15102:         $resulttext = $nochgmsg;
                   15103:     }
                   15104:     return $resulttext;
                   15105: }
                   15106: 
1.279     raeburn  15107: sub modify_trust {
                   15108:     my ($dom,$lastactref,%domconfig) = @_;
                   15109:     my (%by_ip,%by_location,@intdoms,@instdoms);
                   15110:     &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
                   15111:     my @locations = sort(keys(%by_location));
                   15112:     my @prefixes = qw(content shared enroll othcoau coaurem domroles catalog reqcrs msg);
                   15113:     my @types = ('exc','inc');
                   15114:     my (%defaultshash,%changes);
                   15115:     foreach my $prefix (@prefixes) {
                   15116:         $defaultshash{'trust'}{$prefix} = {};
                   15117:     }
                   15118:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
                   15119:     my $resulttext;
                   15120:     foreach my $prefix (@prefixes) {
                   15121:         foreach my $type (@types) {
                   15122:             my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
                   15123:             my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
                   15124:             my @okvals;
                   15125:             foreach my $val (@vals) {
                   15126:                 if ($val =~ /:/) {
                   15127:                     my @items = split(/:/,$val);
                   15128:                     foreach my $item (@items) {
                   15129:                         if (ref($by_location{$item}) eq 'ARRAY') {
                   15130:                             push(@okvals,$item);
                   15131:                         }
                   15132:                     }
                   15133:                 } else {
                   15134:                     if (ref($by_location{$val}) eq 'ARRAY') {
                   15135:                         push(@okvals,$val);
                   15136:                     }
                   15137:                 }
                   15138:             }
                   15139:             @okvals = sort(@okvals);
                   15140:             if (ref($domconfig{'trust'}) eq 'HASH') {
                   15141:                 if (ref($domconfig{'trust'}{$prefix}) eq 'HASH') {
                   15142:                     if (ref($domconfig{'trust'}{$prefix}{$type}) eq 'ARRAY') {
                   15143:                         if ($inuse == 0) {
                   15144:                             $changes{$prefix}{$type} = 1;
                   15145:                         } else {
                   15146:                             $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
                   15147:                             my @changed = &Apache::loncommon::compare_arrays($domconfig{'trust'}{$prefix}{$type},$defaultshash{'trust'}{$prefix}{$type});
                   15148:                             if (@changed > 0) {
                   15149:                                 $changes{$prefix}{$type} = 1;
                   15150:                             }
                   15151:                         }
                   15152:                     } else {
                   15153:                         if ($inuse == 1) {
                   15154:                             $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
                   15155:                             $changes{$prefix}{$type} = 1;
                   15156:                         }
                   15157:                     }
                   15158:                 } else {
                   15159:                     if ($inuse == 1) {
                   15160:                         $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
                   15161:                         $changes{$prefix}{$type} = 1;
                   15162:                     }
                   15163:                 }
                   15164:             } else {
                   15165:                 if ($inuse == 1) {
                   15166:                     $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
                   15167:                     $changes{$prefix}{$type} = 1;
                   15168:                 }
                   15169:             }
                   15170:         }
                   15171:     }
                   15172:     my $nochgmsg = &mt('No changes made to trust settings.');
                   15173:     if (keys(%changes) > 0) {
                   15174:         my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
                   15175:                                                  $dom);
                   15176:         if ($putresult eq 'ok') {
                   15177:             if (ref($defaultshash{'trust'}) eq 'HASH') {
                   15178:                 foreach my $prefix (@prefixes) {
                   15179:                     if (ref($defaultshash{'trust'}{$prefix}) eq 'HASH') {
                   15180:                         $domdefaults{'trust'.$prefix} = $defaultshash{'trust'}{$prefix};
                   15181:                     }
                   15182:                 }
                   15183:             }
                   15184:             my $cachetime = 24*60*60;
                   15185:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
                   15186:             if (ref($lastactref) eq 'HASH') {
                   15187:                 $lastactref->{'domdefaults'} = 1;
                   15188:             }
                   15189:             if (keys(%changes) > 0) {
                   15190:                 my %lt = &trust_titles();
                   15191:                 $resulttext = &mt('Changes made:').'<ul>';
                   15192:                 foreach my $prefix (@prefixes) {
                   15193:                     if (ref($changes{$prefix}) eq 'HASH') {
                   15194:                         $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
                   15195:                         foreach my $type (@types) {
                   15196:                             if (defined($changes{$prefix}{$type})) {
                   15197:                                 my $newvalue;
                   15198:                                 if (ref($defaultshash{'trust'}) eq 'HASH') {
                   15199:                                     if (ref($defaultshash{'trust'}{$prefix})) {
                   15200:                                         if (ref($defaultshash{'trust'}{$prefix}{$type}) eq 'ARRAY') {
                   15201:                                             if (@{$defaultshash{'trust'}{$prefix}{$type}} > 0) {
                   15202:                                                 $newvalue = join(', ',@{$defaultshash{'trust'}{$prefix}{$type}});
                   15203:                                             }
                   15204:                                         }
                   15205:                                     }
                   15206:                                 }
                   15207:                                 if ($newvalue eq '') {
                   15208:                                     $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
                   15209:                                 } else {
                   15210:                                     $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
                   15211:                                 }
                   15212:                             }
                   15213:                         }
                   15214:                         $resulttext .= '</ul>';
                   15215:                     }
                   15216:                 }
                   15217:                 $resulttext .= '</ul>';
                   15218:             } else {
                   15219:                 $resulttext = $nochgmsg;
                   15220:             }
                   15221:         } else {
                   15222:             $resulttext = '<span class="LC_error">'.
                   15223:                           &mt('An error occurred: [_1]',$putresult).'</span>';
                   15224:         }
                   15225:     } else {
                   15226:         $resulttext = $nochgmsg;
                   15227:     }
                   15228:     return $resulttext;
                   15229: }
                   15230: 
1.150     raeburn  15231: sub modify_loadbalancing {
                   15232:     my ($dom,%domconfig) = @_;
                   15233:     my $primary_id = &Apache::lonnet::domain($dom,'primary');
                   15234:     my $intdom = &Apache::lonnet::internet_dom($primary_id);
                   15235:     my ($othertitle,$usertypes,$types) =
                   15236:         &Apache::loncommon::sorted_inst_types($dom);
                   15237:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.253     raeburn  15238:     my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150     raeburn  15239:     my @sparestypes = ('primary','default');
                   15240:     my %typetitles = &sparestype_titles();
                   15241:     my $resulttext;
1.171     raeburn  15242:     my (%currbalancer,%currtargets,%currrules,%existing);
                   15243:     if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
                   15244:         %existing = %{$domconfig{'loadbalancing'}};
                   15245:     }
                   15246:     &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
                   15247:                               \%currtargets,\%currrules);
                   15248:     my ($saveloadbalancing,%defaultshash,%changes);
                   15249:     my ($alltypes,$othertypes,$titles) =
                   15250:         &loadbalancing_titles($dom,$intdom,$usertypes,$types);
                   15251:     my %ruletitles = &offloadtype_text();
                   15252:     my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
                   15253:     for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
                   15254:         my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
                   15255:         if ($balancer eq '') {
                   15256:             next;
                   15257:         }
1.210     raeburn  15258:         if (!exists($servers{$balancer})) {
1.171     raeburn  15259:             if (exists($currbalancer{$balancer})) {
                   15260:                 push(@{$changes{'delete'}},$balancer);
1.150     raeburn  15261:             }
1.171     raeburn  15262:             next;
                   15263:         }
                   15264:         if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
                   15265:             push(@{$changes{'delete'}},$balancer);
                   15266:             next;
                   15267:         }
                   15268:         if (!exists($currbalancer{$balancer})) {
                   15269:             push(@{$changes{'add'}},$balancer);
                   15270:         }
                   15271:         $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
                   15272:         $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
                   15273:         $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
                   15274:         unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
                   15275:             $saveloadbalancing = 1;
                   15276:         }
                   15277:         foreach my $sparetype (@sparestypes) {
                   15278:             my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
                   15279:             my @offloadto;
                   15280:             foreach my $target (@targets) {
                   15281:                 if (($servers{$target}) && ($target ne $balancer)) {
                   15282:                     if ($sparetype eq 'default') {
                   15283:                         if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
                   15284:                             next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150     raeburn  15285:                         }
                   15286:                     }
1.171     raeburn  15287:                     unless(grep(/^\Q$target\E$/,@offloadto)) {
                   15288:                         push(@offloadto,$target);
                   15289:                     }
1.150     raeburn  15290:                 }
                   15291:             }
1.284     raeburn  15292:             if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
                   15293:                 unless(grep(/^\Q$balancer\E$/,@offloadto)) {
                   15294:                     push(@offloadto,$balancer);
                   15295:                 }
                   15296:             }
                   15297:             $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150     raeburn  15298:         }
1.171     raeburn  15299:         if (ref($currtargets{$balancer}) eq 'HASH') {
1.150     raeburn  15300:             foreach my $sparetype (@sparestypes) {
1.171     raeburn  15301:                 if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
                   15302:                     my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150     raeburn  15303:                     if (@targetdiffs > 0) {
1.171     raeburn  15304:                         $changes{'curr'}{$balancer}{'targets'} = 1;
1.150     raeburn  15305:                     }
1.171     raeburn  15306:                 } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
                   15307:                     if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
                   15308:                         $changes{'curr'}{$balancer}{'targets'} = 1;
1.150     raeburn  15309:                     }
                   15310:                 }
                   15311:             }
                   15312:         } else {
1.171     raeburn  15313:             if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210     raeburn  15314:                 foreach my $sparetype (@sparestypes) {
1.171     raeburn  15315:                     if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
                   15316:                         if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
                   15317:                             $changes{'curr'}{$balancer}{'targets'} = 1;
                   15318:                         }
1.150     raeburn  15319:                     }
                   15320:                 }
1.210     raeburn  15321:             }
1.150     raeburn  15322:         }
                   15323:         my $ishomedom;
1.171     raeburn  15324:         if (&Apache::lonnet::host_domain($balancer) eq $dom) {
                   15325:             $ishomedom = 1;
1.150     raeburn  15326:         }
                   15327:         if (ref($alltypes) eq 'ARRAY') {
                   15328:             foreach my $type (@{$alltypes}) {
                   15329:                 my $rule;
1.210     raeburn  15330:                 unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150     raeburn  15331:                          (!$ishomedom)) {
1.171     raeburn  15332:                     $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
                   15333:                 }
                   15334:                 if ($rule eq 'specific') {
1.255     raeburn  15335:                     my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.289     raeburn  15336:                     if (exists($servers{$specifiedhost})) {
1.255     raeburn  15337:                         $rule = $specifiedhost;
                   15338:                     }
1.150     raeburn  15339:                 }
1.171     raeburn  15340:                 $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
                   15341:                 if (ref($currrules{$balancer}) eq 'HASH') {
                   15342:                     if ($rule ne $currrules{$balancer}{$type}) {
                   15343:                         $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150     raeburn  15344:                     }
                   15345:                 } elsif ($rule ne '') {
1.171     raeburn  15346:                     $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150     raeburn  15347:                 }
                   15348:             }
                   15349:         }
1.171     raeburn  15350:     }
                   15351:     my $nochgmsg = &mt('No changes made to Load Balancer settings.');
                   15352:     if ((keys(%changes) > 0) || ($saveloadbalancing)) {
                   15353:         unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
                   15354:             $defaultshash{'loadbalancing'} = {};
                   15355:         }
                   15356:         my $putresult = &Apache::lonnet::put_dom('configuration',
                   15357:                                                  \%defaultshash,$dom);
                   15358:         if ($putresult eq 'ok') {
                   15359:             if (keys(%changes) > 0) {
1.252     raeburn  15360:                 my %toupdate;
1.171     raeburn  15361:                 if (ref($changes{'delete'}) eq 'ARRAY') {
                   15362:                     foreach my $balancer (sort(@{$changes{'delete'}})) {
                   15363:                         $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.252     raeburn  15364:                         $toupdate{$balancer} = 1;
1.150     raeburn  15365:                     }
1.171     raeburn  15366:                 }
                   15367:                 if (ref($changes{'add'}) eq 'ARRAY') {
1.210     raeburn  15368:                     foreach my $balancer (sort(@{$changes{'add'}})) {
1.171     raeburn  15369:                         $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.252     raeburn  15370:                         $toupdate{$balancer} = 1;
1.171     raeburn  15371:                     }
                   15372:                 }
                   15373:                 if (ref($changes{'curr'}) eq 'HASH') {
                   15374:                     foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.253     raeburn  15375:                         $toupdate{$balancer} = 1;
1.171     raeburn  15376:                         if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
                   15377:                             if ($changes{'curr'}{$balancer}{'targets'}) {
                   15378:                                 my %offloadstr;
                   15379:                                 foreach my $sparetype (@sparestypes) {
                   15380:                                     if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
                   15381:                                         if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
                   15382:                                             $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
                   15383:                                         }
                   15384:                                     }
1.150     raeburn  15385:                                 }
1.171     raeburn  15386:                                 if (keys(%offloadstr) == 0) {
                   15387:                                     $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150     raeburn  15388:                                 } else {
1.171     raeburn  15389:                                     my $showoffload;
                   15390:                                     foreach my $sparetype (@sparestypes) {
                   15391:                                         $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>:&nbsp;';
                   15392:                                         if (defined($offloadstr{$sparetype})) {
                   15393:                                             $showoffload .= $offloadstr{$sparetype};
                   15394:                                         } else {
                   15395:                                             $showoffload .= &mt('None');
                   15396:                                         }
                   15397:                                         $showoffload .= ('&nbsp;'x3);
                   15398:                                     }
                   15399:                                     $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150     raeburn  15400:                                 }
                   15401:                             }
                   15402:                         }
1.171     raeburn  15403:                         if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
                   15404:                             if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
                   15405:                                 foreach my $type (@{$alltypes}) {
                   15406:                                     if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
                   15407:                                         my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
                   15408:                                         my $balancetext;
                   15409:                                         if ($rule eq '') {
                   15410:                                             $balancetext =  $ruletitles{'default'};
1.209     raeburn  15411:                                         } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.289     raeburn  15412:                                                  ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.254     raeburn  15413:                                             if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.252     raeburn  15414:                                                 foreach my $sparetype (@sparestypes) {
                   15415:                                                     if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
                   15416:                                                         map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
                   15417:                                                     }
                   15418:                                                 }
1.253     raeburn  15419:                                                 foreach my $item (@{$alltypes}) {
                   15420:                                                     next if ($item =~  /^_LC_ipchange/);
                   15421:                                                     my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
                   15422:                                                     if ($hasrule eq 'homeserver') {
                   15423:                                                         map { $toupdate{$_} = 1; } (keys(%libraryservers));
                   15424:                                                     } else {
                   15425:                                                         unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
                   15426:                                                             if ($servers{$hasrule}) {
                   15427:                                                                 $toupdate{$hasrule} = 1;
                   15428:                                                             }
                   15429:                                                         }
                   15430:                                                     }
                   15431:                                                 }
1.254     raeburn  15432:                                                 if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
                   15433:                                                     $balancetext =  $ruletitles{$rule};
                   15434:                                                 } else {
                   15435:                                                     my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
                   15436:                                                     $balancetext = $ruletitles{'particular'}.' '.$receiver;
                   15437:                                                     if ($receiver) {
                   15438:                                                         $toupdate{$receiver};
                   15439:                                                     }
                   15440:                                                 }
                   15441:                                             } else {
                   15442:                                                 $balancetext =  $ruletitles{$rule};
1.252     raeburn  15443:                                             }
1.171     raeburn  15444:                                         } else {
                   15445:                                             $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
                   15446:                                         }
1.210     raeburn  15447:                                         $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150     raeburn  15448:                                     }
                   15449:                                 }
                   15450:                             }
                   15451:                         }
1.252     raeburn  15452:                         if (keys(%toupdate)) {
                   15453:                             my %thismachine;
                   15454:                             my $updatedhere;
                   15455:                             my $cachetime = 60*60*24;
                   15456:                             map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
                   15457:                             foreach my $lonhost (keys(%toupdate)) {
                   15458:                                 if ($thismachine{$lonhost}) {
                   15459:                                     unless ($updatedhere) {
                   15460:                                         &Apache::lonnet::do_cache_new('loadbalancing',$dom,
                   15461:                                                                       $defaultshash{'loadbalancing'},
                   15462:                                                                       $cachetime);
                   15463:                                         $updatedhere = 1;
                   15464:                                     }
                   15465:                                 } else {
                   15466:                                     my $cachekey = &escape('loadbalancing').':'.&escape($dom);
                   15467:                                     &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
                   15468:                                 }
                   15469:                             }
                   15470:                         }
1.150     raeburn  15471:                     }
1.171     raeburn  15472:                 }
                   15473:                 if ($resulttext ne '') {
                   15474:                     $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150     raeburn  15475:                 } else {
                   15476:                     $resulttext = $nochgmsg;
                   15477:                 }
                   15478:             } else {
1.171     raeburn  15479:                 $resulttext = $nochgmsg;
1.150     raeburn  15480:             }
                   15481:         } else {
1.171     raeburn  15482:             $resulttext = '<span class="LC_error">'.
                   15483:                           &mt('An error occurred: [_1]',$putresult).'</span>';
1.150     raeburn  15484:         }
                   15485:     } else {
1.171     raeburn  15486:         $resulttext = $nochgmsg;
1.150     raeburn  15487:     }
                   15488:     return $resulttext;
                   15489: }
                   15490: 
1.48      raeburn  15491: sub recurse_check {
                   15492:     my ($chkcats,$categories,$depth,$name) = @_;
                   15493:     if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
                   15494:         my $chg = 0;
                   15495:         for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
                   15496:             my $category = $chkcats->[$depth]{$name}[$j];
                   15497:             my $item;
                   15498:             if ($category eq '') {
                   15499:                 $chg ++;
                   15500:             } else {
                   15501:                 my $deeper = $depth + 1;
                   15502:                 $item = &escape($category).':'.&escape($name).':'.$depth;
                   15503:                 if ($chg) {
                   15504:                     $categories->{$item} -= $chg;
                   15505:                 }
                   15506:                 &recurse_check($chkcats,$categories,$deeper,$category);
                   15507:                 $deeper --;
                   15508:             }
                   15509:         }
                   15510:     }
                   15511:     return;
                   15512: }
                   15513: 
                   15514: sub recurse_cat_deletes {
                   15515:     my ($item,$coursecategories,$deletions) = @_;
                   15516:     my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
                   15517:     my $subdepth = $depth + 1;
                   15518:     if (ref($coursecategories) eq 'HASH') {
                   15519:         foreach my $subitem (keys(%{$coursecategories})) {
                   15520:             my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
                   15521:             if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
                   15522:                 delete($coursecategories->{$subitem});
                   15523:                 $deletions->{$subitem} = 1;
                   15524:                 &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168     raeburn  15525:             }
1.48      raeburn  15526:         }
                   15527:     }
                   15528:     return;
                   15529: }
                   15530: 
1.125     raeburn  15531: sub active_dc_picker {
1.191     raeburn  15532:     my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.287     raeburn  15533:     my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.191     raeburn  15534:     my @domcoord = keys(%domcoords);
                   15535:     if (keys(%currhash)) {
                   15536:         foreach my $dc (keys(%currhash)) {
                   15537:             unless (exists($domcoords{$dc})) {
                   15538:                 push(@domcoord,$dc);
                   15539:             }
                   15540:         }
                   15541:     }
                   15542:     @domcoord = sort(@domcoord);
1.210     raeburn  15543:     my $numdcs = scalar(@domcoord);
1.191     raeburn  15544:     my $rows = 0;
                   15545:     my $table;
1.125     raeburn  15546:     if ($numdcs > 1) {
1.191     raeburn  15547:         $table = '<table>';
                   15548:         for (my $i=0; $i<@domcoord; $i++) {
1.125     raeburn  15549:             my $rem = $i%($numinrow);
                   15550:             if ($rem == 0) {
                   15551:                 if ($i > 0) {
1.191     raeburn  15552:                     $table .= '</tr>';
1.125     raeburn  15553:                 }
1.191     raeburn  15554:                 $table .= '<tr>';
                   15555:                 $rows ++;
1.125     raeburn  15556:             }
1.191     raeburn  15557:             my $check = '';
                   15558:             if ($inputtype eq 'radio') {
                   15559:                 if (keys(%currhash) == 0) {
                   15560:                     if (!$i) {
                   15561:                         $check = ' checked="checked"';
                   15562:                     }
                   15563:                 } elsif (exists($currhash{$domcoord[$i]})) {
                   15564:                     $check = ' checked="checked"';
                   15565:                 }
                   15566:             } else {
                   15567:                 if (exists($currhash{$domcoord[$i]})) {
                   15568:                     $check = ' checked="checked"';
1.125     raeburn  15569:                 }
                   15570:             }
1.191     raeburn  15571:             if ($i == @domcoord - 1) {
1.125     raeburn  15572:                 my $colsleft = $numinrow - $rem;
                   15573:                 if ($colsleft > 1) {
1.191     raeburn  15574:                     $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125     raeburn  15575:                 } else {
1.191     raeburn  15576:                     $table .= '<td class="LC_left_item">';
1.125     raeburn  15577:                 }
                   15578:             } else {
1.191     raeburn  15579:                 $table .= '<td class="LC_left_item">';
                   15580:             }
                   15581:             my ($dcname,$dcdom) = split(':',$domcoord[$i]);
                   15582:             my $user = &Apache::loncommon::plainname($dcname,$dcdom);
                   15583:             $table .= '<span class="LC_nobreak"><label>'.
                   15584:                       '<input type="'.$inputtype.'" name="'.$name.'"'.
                   15585:                       ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
                   15586:             if ($user ne $dcname.':'.$dcdom) {
1.219     raeburn  15587:                 $table .=  ' ('.$dcname.':'.$dcdom.')';
1.191     raeburn  15588:             }
1.219     raeburn  15589:             $table .= '</label></span></td>';
1.191     raeburn  15590:         }
                   15591:         $table .= '</tr></table>';
                   15592:     } elsif ($numdcs == 1) {
1.219     raeburn  15593:         my ($dcname,$dcdom) = split(':',$domcoord[0]);
                   15594:         my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191     raeburn  15595:         if ($inputtype eq 'radio') {
1.247     raeburn  15596:             $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.219     raeburn  15597:             if ($user ne $dcname.':'.$dcdom) {
                   15598:                 $table .=  ' ('.$dcname.':'.$dcdom.')';
                   15599:             }
1.191     raeburn  15600:         } else {
                   15601:             my $check;
                   15602:             if (exists($currhash{$domcoord[0]})) {
                   15603:                 $check = ' checked="checked"';
1.125     raeburn  15604:             }
1.247     raeburn  15605:             $table = '<span class="LC_nobreak"><label>'.
                   15606:                      '<input type="checkbox" name="'.$name.'" '.
                   15607:                      'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.219     raeburn  15608:             if ($user ne $dcname.':'.$dcdom) {
1.220     raeburn  15609:                 $table .=  ' ('.$dcname.':'.$dcdom.')';
1.219     raeburn  15610:             }
1.220     raeburn  15611:             $table .= '</label></span>';
1.191     raeburn  15612:             $rows ++;
1.125     raeburn  15613:         }
                   15614:     }
1.191     raeburn  15615:     return ($numdcs,$table,$rows);
1.125     raeburn  15616: }
                   15617: 
1.137     raeburn  15618: sub usersession_titles {
                   15619:     return &Apache::lonlocal::texthash(
                   15620:                hosted => 'Hosting of sessions for users from other domains on servers in this domain',
                   15621:                remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145     raeburn  15622:                spares => 'Servers offloaded to, when busy',
1.137     raeburn  15623:                version => 'LON-CAPA version requirement',
1.138     raeburn  15624:                excludedomain => 'Allow all, but exclude specific domains',
                   15625:                includedomain => 'Deny all, but include specific domains',
1.145     raeburn  15626:                primary => 'Primary (checked first)',
1.154     raeburn  15627:                default => 'Default',
1.137     raeburn  15628:            );
                   15629: }
                   15630: 
1.152     raeburn  15631: sub id_for_thisdom {
                   15632:     my (%servers) = @_;
                   15633:     my %altids;
                   15634:     foreach my $server (keys(%servers)) {
                   15635:         my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
                   15636:         if ($serverhome ne $server) {
                   15637:             $altids{$serverhome} = $server;
                   15638:         }
                   15639:     }
                   15640:     return %altids;
                   15641: }
                   15642: 
1.150     raeburn  15643: sub count_servers {
                   15644:     my ($currbalancer,%servers) = @_;
                   15645:     my (@spares,$numspares);
                   15646:     foreach my $lonhost (sort(keys(%servers))) {
                   15647:         next if ($currbalancer eq $lonhost);
                   15648:         push(@spares,$lonhost);
                   15649:     }
                   15650:     if ($currbalancer) {
                   15651:         $numspares = scalar(@spares);
                   15652:     } else {
                   15653:         $numspares = scalar(@spares) - 1;
                   15654:     }
                   15655:     return ($numspares,@spares);
                   15656: }
                   15657: 
                   15658: sub lonbalance_targets_js {
1.171     raeburn  15659:     my ($dom,$types,$servers,$settings) = @_;
1.150     raeburn  15660:     my $select = &mt('Select');
                   15661:     my ($alltargets,$allishome,$allinsttypes,@alltypes);
                   15662:     if (ref($servers) eq 'HASH') {
                   15663:         $alltargets = join("','",sort(keys(%{$servers})));
                   15664:         my @homedoms;
                   15665:         foreach my $server (sort(keys(%{$servers}))) {
                   15666:             if (&Apache::lonnet::host_domain($server) eq $dom) {
                   15667:                 push(@homedoms,'1');
                   15668:             } else {
                   15669:                 push(@homedoms,'0');
                   15670:             }
                   15671:         }
                   15672:         $allishome = join("','",@homedoms);
                   15673:     }
                   15674:     if (ref($types) eq 'ARRAY') {
                   15675:         if (@{$types} > 0) {
                   15676:             @alltypes = @{$types};
                   15677:         }
                   15678:     }
                   15679:     push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
                   15680:     $allinsttypes = join("','",@alltypes);
1.171     raeburn  15681:     my (%currbalancer,%currtargets,%currrules,%existing);
                   15682:     if (ref($settings) eq 'HASH') {
                   15683:         %existing = %{$settings};
                   15684:     }
                   15685:     &get_loadbalancers_config($servers,\%existing,\%currbalancer,
                   15686:                               \%currtargets,\%currrules);
1.210     raeburn  15687:     my $balancers = join("','",sort(keys(%currbalancer)));
1.150     raeburn  15688:     return <<"END";
                   15689: 
                   15690: <script type="text/javascript">
                   15691: // <![CDATA[
                   15692: 
1.171     raeburn  15693: currBalancers = new Array('$balancers');
                   15694: 
                   15695: function toggleTargets(balnum) {
                   15696:     var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
                   15697:     var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
                   15698:     var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
                   15699:     var prevbalancer = prevhostitem.value;
                   15700:     var baltotal = document.getElementById('loadbalancing_total').value;
                   15701:     prevhostitem.value = balancer;
                   15702:     if (prevbalancer != '') {
                   15703:         var prevIdx = currBalancers.indexOf(prevbalancer);
                   15704:         if (prevIdx != -1) {
                   15705:             currBalancers.splice(prevIdx,1);
                   15706:         }
                   15707:     }
1.150     raeburn  15708:     if (balancer == '') {
1.171     raeburn  15709:         hideSpares(balnum);
1.150     raeburn  15710:     } else {
1.171     raeburn  15711:         var currIdx = currBalancers.indexOf(balancer);
                   15712:         if (currIdx == -1) {
                   15713:             currBalancers.push(balancer);
                   15714:         }
1.150     raeburn  15715:         var homedoms = new Array('$allishome');
1.171     raeburn  15716:         var ishomedom = homedoms[lonhostitem.selectedIndex];
                   15717:         showSpares(balancer,ishomedom,balnum);
1.150     raeburn  15718:     }
1.171     raeburn  15719:     balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150     raeburn  15720:     return;
                   15721: }
                   15722: 
1.171     raeburn  15723: function showSpares(balancer,ishomedom,balnum) {
1.150     raeburn  15724:     var alltargets = new Array('$alltargets');
                   15725:     var insttypes = new Array('$allinsttypes');
1.151     raeburn  15726:     var offloadtypes = new Array('primary','default');
                   15727: 
1.171     raeburn  15728:     document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
                   15729:     document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152     raeburn  15730:  
1.151     raeburn  15731:     for (var i=0; i<offloadtypes.length; i++) {
                   15732:         var count = 0;
                   15733:         for (var j=0; j<alltargets.length; j++) {
                   15734:             if (alltargets[j] != balancer) {
1.171     raeburn  15735:                 var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
                   15736:                 item.value = alltargets[j];
                   15737:                 item.style.textAlign='left';
                   15738:                 item.style.textFace='normal';
                   15739:                 document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
                   15740:                 if (currBalancers.indexOf(alltargets[j]) == -1) {
                   15741:                     item.disabled = '';
                   15742:                 } else {
                   15743:                     item.disabled = 'disabled';
                   15744:                     item.checked = false;
                   15745:                 }
1.151     raeburn  15746:                 count ++;
                   15747:             }
1.150     raeburn  15748:         }
                   15749:     }
1.151     raeburn  15750:     for (var k=0; k<insttypes.length; k++) {
                   15751:         if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150     raeburn  15752:             if (ishomedom == 1) {
1.171     raeburn  15753:                 document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
                   15754:                 document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150     raeburn  15755:             } else {
1.171     raeburn  15756:                 document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
                   15757:                 document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150     raeburn  15758:             }
                   15759:         } else {
1.171     raeburn  15760:             document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
                   15761:             document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150     raeburn  15762:         }
1.151     raeburn  15763:         if ((insttypes[k] != '_LC_external') && 
                   15764:             ((insttypes[k] != '_LC_internetdom') ||
                   15765:              ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171     raeburn  15766:             var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
                   15767:             item.options.length = 0;
                   15768:             item.options[0] = new Option("","",true,true);
1.210     raeburn  15769:             var idx = 0;
1.151     raeburn  15770:             for (var m=0; m<alltargets.length; m++) {
1.171     raeburn  15771:                 if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
                   15772:                     idx ++;
                   15773:                     item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150     raeburn  15774:                 }
                   15775:             }
                   15776:         }
                   15777:     }
                   15778:     return;
                   15779: }
                   15780: 
1.171     raeburn  15781: function hideSpares(balnum) {
1.150     raeburn  15782:     var alltargets = new Array('$alltargets');
                   15783:     var insttypes = new Array('$allinsttypes');
                   15784:     var offloadtypes = new Array('primary','default');
                   15785: 
1.171     raeburn  15786:     document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
                   15787:     document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150     raeburn  15788: 
                   15789:     var total = alltargets.length - 1;
                   15790:     for (var i=0; i<offloadtypes; i++) {
                   15791:         for (var j=0; j<total; j++) {
1.171     raeburn  15792:            document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
                   15793:            document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
                   15794:            document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151     raeburn  15795:         }
1.150     raeburn  15796:     }
                   15797:     for (var k=0; k<insttypes.length; k++) {
1.171     raeburn  15798:         document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
                   15799:         document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151     raeburn  15800:         if (insttypes[k] != '_LC_external') {
1.171     raeburn  15801:             document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
                   15802:             document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150     raeburn  15803:         }
                   15804:     }
                   15805:     return;
                   15806: }
                   15807: 
1.171     raeburn  15808: function checkOffloads(item,balnum,type) {
1.150     raeburn  15809:     var alltargets = new Array('$alltargets');
                   15810:     var offloadtypes = new Array('primary','default');
                   15811:     if (item.checked) {
                   15812:         var total = alltargets.length - 1;
                   15813:         var other;
                   15814:         if (type == offloadtypes[0]) {
1.151     raeburn  15815:             other = offloadtypes[1];
1.150     raeburn  15816:         } else {
1.151     raeburn  15817:             other = offloadtypes[0];
1.150     raeburn  15818:         }
                   15819:         for (var i=0; i<total; i++) {
1.171     raeburn  15820:             var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150     raeburn  15821:             if (server == item.value) {
1.171     raeburn  15822:                 if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
                   15823:                     document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150     raeburn  15824:                 }
                   15825:             }
                   15826:         }
                   15827:     }
                   15828:     return;
                   15829: }
                   15830: 
1.171     raeburn  15831: function singleServerToggle(balnum,type) {
                   15832:     var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150     raeburn  15833:     if (offloadtoSelIdx == 0) {
1.171     raeburn  15834:         document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
                   15835:         document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150     raeburn  15836: 
                   15837:     } else {
1.171     raeburn  15838:         document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
                   15839:         document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150     raeburn  15840:     }
                   15841:     return;
                   15842: }
                   15843: 
1.171     raeburn  15844: function balanceruleChange(formname,balnum,type) {
1.150     raeburn  15845:     if (type == '_LC_external') {
1.171     raeburn  15846:         return;
1.150     raeburn  15847:     }
1.171     raeburn  15848:     var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150     raeburn  15849:     for (var i=0; i<typesRules.length; i++) {
                   15850:         if (formname.elements[typesRules[i]].checked) {
                   15851:             if (formname.elements[typesRules[i]].value != 'specific') {
1.171     raeburn  15852:                 document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
                   15853:                 document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150     raeburn  15854:             } else {
1.171     raeburn  15855:                 document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
                   15856:             }
                   15857:         }
                   15858:     }
                   15859:     return;
                   15860: }
                   15861: 
                   15862: function balancerDeleteChange(balnum) {
                   15863:     var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
                   15864:     var baltotal = document.getElementById('loadbalancing_total').value;
                   15865:     var addtarget;
                   15866:     var removetarget;
                   15867:     var action = 'delete';
                   15868:     if (document.getElementById('loadbalancing_delete_'+balnum)) {
                   15869:         var lonhost = hostitem.value;
                   15870:         var currIdx = currBalancers.indexOf(lonhost);
                   15871:         if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
                   15872:             if (currIdx != -1) {
                   15873:                 currBalancers.splice(currIdx,1);
                   15874:             }
                   15875:             addtarget = lonhost;
                   15876:         } else {
                   15877:             if (currIdx == -1) {
                   15878:                 currBalancers.push(lonhost);
                   15879:             }
                   15880:             removetarget = lonhost;
                   15881:             action = 'undelete';
                   15882:         }
                   15883:         balancerChange(balnum,baltotal,action,addtarget,removetarget);
                   15884:     }
                   15885:     return;
                   15886: }
                   15887: 
                   15888: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
                   15889:     if (baltotal > 1) {
                   15890:         var offloadtypes = new Array('primary','default');
                   15891:         var alltargets = new Array('$alltargets');
                   15892:         var insttypes = new Array('$allinsttypes');
                   15893:         for (var i=0; i<baltotal; i++) {
                   15894:             if (i != balnum) {
                   15895:                 for (var j=0; j<offloadtypes.length; j++) {
                   15896:                     var total = alltargets.length - 1;
                   15897:                     for (var k=0; k<total; k++) {
                   15898:                         var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
                   15899:                         var server = serveritem.value;
                   15900:                         if ((action == 'delete') || (action == 'change' && addtarget != ''))  {
                   15901:                             if (server == addtarget) {
                   15902:                                 serveritem.disabled = '';
                   15903:                             }
                   15904:                         }
                   15905:                         if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
                   15906:                             if (server == removetarget) {
                   15907:                                 serveritem.disabled = 'disabled';
                   15908:                                 serveritem.checked = false;
                   15909:                             }
                   15910:                         }
                   15911:                     }
                   15912:                 }
                   15913:                 for (var j=0; j<insttypes.length; j++) {
                   15914:                     if (insttypes[j] != '_LC_external') {
                   15915:                         if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
                   15916:                             var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
                   15917:                             var currSel = singleserver.selectedIndex;
                   15918:                             var currVal = singleserver.options[currSel].value;
                   15919:                             if ((action == 'delete') || (action == 'change' && addtarget != '')) {
                   15920:                                 var numoptions = singleserver.options.length;
                   15921:                                 var needsnew = 1;
                   15922:                                 for (var k=0; k<numoptions; k++) {
                   15923:                                     if (singleserver.options[k] == addtarget) {
                   15924:                                         needsnew = 0;
                   15925:                                         break;
                   15926:                                     }
                   15927:                                 }
                   15928:                                 if (needsnew == 1) {
                   15929:                                     singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
                   15930:                                 }
                   15931:                             }
                   15932:                             if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
                   15933:                                 singleserver.options.length = 0;
                   15934:                                 if ((currVal) && (currVal != removetarget)) {
                   15935:                                     singleserver.options[0] = new Option("","",false,false);
                   15936:                                 } else {
                   15937:                                     singleserver.options[0] = new Option("","",true,true);
                   15938:                                 }
                   15939:                                 var idx = 0;
                   15940:                                 for (var m=0; m<alltargets.length; m++) {
                   15941:                                     if (currBalancers.indexOf(alltargets[m]) == -1) {
                   15942:                                         idx ++;
                   15943:                                         if (currVal == alltargets[m]) {
                   15944:                                             singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
                   15945:                                         } else {
                   15946:                                             singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
                   15947:                                         }
                   15948:                                     }
                   15949:                                 }
                   15950:                             }
                   15951:                         }
                   15952:                     }
                   15953:                 }
1.150     raeburn  15954:             }
                   15955:         }
                   15956:     }
                   15957:     return;
                   15958: }
                   15959: 
1.152     raeburn  15960: // ]]>
                   15961: </script>
                   15962: 
                   15963: END
                   15964: }
                   15965: 
                   15966: sub new_spares_js {
                   15967:     my @sparestypes = ('primary','default');
                   15968:     my $types = join("','",@sparestypes);
                   15969:     my $select = &mt('Select');
                   15970:     return <<"END";
                   15971: 
                   15972: <script type="text/javascript">
                   15973: // <![CDATA[
                   15974: 
                   15975: function updateNewSpares(formname,lonhost) {
                   15976:     var types = new Array('$types');
                   15977:     var include = new Array();
                   15978:     var exclude = new Array();
                   15979:     for (var i=0; i<types.length; i++) {
                   15980:         var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
                   15981:         for (var j=0; j<spareboxes.length; j++) {
                   15982:             if (formname.elements[spareboxes[j]].checked) {
                   15983:                 exclude.push(formname.elements[spareboxes[j]].value);
                   15984:             } else {
                   15985:                 include.push(formname.elements[spareboxes[j]].value);
                   15986:             }
                   15987:         }
                   15988:     }
                   15989:     for (var i=0; i<types.length; i++) {
                   15990:         var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
                   15991:         var selIdx = newSpare.selectedIndex;
                   15992:         var currnew = newSpare.options[selIdx].value;
                   15993:         var okSpares = new Array();
                   15994:         for (var j=0; j<newSpare.options.length; j++) {
                   15995:             var possible = newSpare.options[j].value;
                   15996:             if (possible != '') {
                   15997:                 if (exclude.indexOf(possible) == -1) {
                   15998:                     okSpares.push(possible);
                   15999:                 } else {
                   16000:                     if (currnew == possible) {
                   16001:                         selIdx = 0;
                   16002:                     }
                   16003:                 }
                   16004:             }
                   16005:         }
                   16006:         for (var k=0; k<include.length; k++) {
                   16007:             if (okSpares.indexOf(include[k]) == -1) {
                   16008:                 okSpares.push(include[k]);
                   16009:             }
                   16010:         }
                   16011:         okSpares.sort();
                   16012:         newSpare.options.length = 0;
                   16013:         if (selIdx == 0) {
                   16014:             newSpare.options[0] = new Option("$select","",true,true);
                   16015:         } else {
                   16016:             newSpare.options[0] = new Option("$select","",false,false);
                   16017:         }
                   16018:         for (var m=0; m<okSpares.length; m++) {
                   16019:             var idx = m+1;
                   16020:             var selThis = 0;
                   16021:             if (selIdx != 0) {
                   16022:                 if (okSpares[m] == currnew) {
                   16023:                     selThis = 1;
                   16024:                 }
                   16025:             }
                   16026:             if (selThis == 1) {
                   16027:                 newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
                   16028:             } else {
                   16029:                 newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
                   16030:             }
                   16031:         }
                   16032:     }
                   16033:     return;
                   16034: }
                   16035: 
                   16036: function checkNewSpares(lonhost,type) {
                   16037:     var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
                   16038:     var chosen =  newSpare.options[newSpare.selectedIndex].value;
                   16039:     if (chosen != '') { 
                   16040:         var othertype;
                   16041:         var othernewSpare;
                   16042:         if (type == 'primary') {
                   16043:             othernewSpare = document.getElementById('newspare_default_'+lonhost);
                   16044:         }
                   16045:         if (type == 'default') {
                   16046:             othernewSpare = document.getElementById('newspare_primary_'+lonhost);
                   16047:         }
                   16048:         if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
                   16049:             othernewSpare.selectedIndex = 0;
                   16050:         }
                   16051:     }
                   16052:     return;
                   16053: }
                   16054: 
                   16055: // ]]>
                   16056: </script>
                   16057: 
                   16058: END
                   16059: 
                   16060: }
                   16061: 
                   16062: sub common_domprefs_js {
                   16063:     return <<"END";
                   16064: 
                   16065: <script type="text/javascript">
                   16066: // <![CDATA[
                   16067: 
1.150     raeburn  16068: function getIndicesByName(formname,item) {
1.152     raeburn  16069:     var group = new Array();
1.150     raeburn  16070:     for (var i=0;i<formname.elements.length;i++) {
                   16071:         if (formname.elements[i].name == item) {
1.152     raeburn  16072:             group.push(formname.elements[i].id);
1.150     raeburn  16073:         }
                   16074:     }
1.152     raeburn  16075:     return group;
1.150     raeburn  16076: }
                   16077: 
                   16078: // ]]>
                   16079: </script>
                   16080: 
                   16081: END
1.152     raeburn  16082: 
1.150     raeburn  16083: }
                   16084: 
1.165     raeburn  16085: sub recaptcha_js {
                   16086:     my %lt = &captcha_phrases();
                   16087:     return <<"END";
                   16088: 
                   16089: <script type="text/javascript">
                   16090: // <![CDATA[
                   16091: 
                   16092: function updateCaptcha(caller,context) {
                   16093:     var privitem;
                   16094:     var pubitem;
                   16095:     var privtext;
                   16096:     var pubtext;
1.269     raeburn  16097:     var versionitem;
                   16098:     var versiontext;
1.165     raeburn  16099:     if (document.getElementById(context+'_recaptchapub')) {
                   16100:         pubitem = document.getElementById(context+'_recaptchapub');
                   16101:     } else {
                   16102:         return;
                   16103:     }
                   16104:     if (document.getElementById(context+'_recaptchapriv')) {
                   16105:         privitem = document.getElementById(context+'_recaptchapriv');
                   16106:     } else {
                   16107:         return;
                   16108:     }
                   16109:     if (document.getElementById(context+'_recaptchapubtxt')) {
                   16110:         pubtext = document.getElementById(context+'_recaptchapubtxt');
                   16111:     } else {
                   16112:         return;
                   16113:     }
                   16114:     if (document.getElementById(context+'_recaptchaprivtxt')) {
                   16115:         privtext = document.getElementById(context+'_recaptchaprivtxt');
                   16116:     } else {
                   16117:         return;
                   16118:     }
1.269     raeburn  16119:     if (document.getElementById(context+'_recaptchaversion')) {
                   16120:         versionitem = document.getElementById(context+'_recaptchaversion');
                   16121:     } else {
                   16122:         return;
                   16123:     }
                   16124:     if (document.getElementById(context+'_recaptchavertxt')) {
                   16125:         versiontext = document.getElementById(context+'_recaptchavertxt');
                   16126:     } else {
                   16127:         return;
                   16128:     }
1.165     raeburn  16129:     if (caller.checked) {
                   16130:         if (caller.value == 'recaptcha') {
                   16131:             pubitem.type = 'text';
                   16132:             privitem.type = 'text';
                   16133:             pubitem.size = '40';
                   16134:             privitem.size = '40';
                   16135:             pubtext.innerHTML = "$lt{'pub'}";
                   16136:             privtext.innerHTML = "$lt{'priv'}";
1.269     raeburn  16137:             versionitem.type = 'text';
                   16138:             versionitem.size = '3';
1.289     raeburn  16139:             versiontext.innerHTML = "$lt{'ver'}";
1.165     raeburn  16140:         } else {
                   16141:             pubitem.type = 'hidden';
                   16142:             privitem.type = 'hidden';
1.269     raeburn  16143:             versionitem.type = 'hidden';
1.165     raeburn  16144:             pubtext.innerHTML = '';
                   16145:             privtext.innerHTML = '';
1.269     raeburn  16146:             versiontext.innerHTML = '';
1.165     raeburn  16147:         }
                   16148:     }
                   16149:     return;
                   16150: }
                   16151: 
                   16152: // ]]>
                   16153: </script>
                   16154: 
                   16155: END
                   16156: 
                   16157: }
                   16158: 
1.236     raeburn  16159: sub toggle_display_js {
1.192     raeburn  16160:     return <<"END";
                   16161: 
                   16162: <script type="text/javascript">
                   16163: // <![CDATA[
                   16164: 
1.236     raeburn  16165: function toggleDisplay(domForm,caller) {
                   16166:     if (document.getElementById(caller)) {
                   16167:         var divitem = document.getElementById(caller);
                   16168:         var optionsElement = domForm.coursecredits;
1.264     raeburn  16169:         var checkval = 1;
                   16170:         var dispval = 'block';
1.303     raeburn  16171:         var selfcreateRegExp = /^cancreate_emailverified/;
1.236     raeburn  16172:         if (caller == 'emailoptions') {
                   16173:             optionsElement = domForm.cancreate_email; 
                   16174:         }
1.257     raeburn  16175:         if (caller == 'studentsubmission') {
                   16176:             optionsElement = domForm.postsubmit;
                   16177:         }
1.264     raeburn  16178:         if (caller == 'cloneinstcode') {
                   16179:             optionsElement = domForm.canclone;
                   16180:             checkval = 'instcode';
                   16181:         }
1.303     raeburn  16182:         if (selfcreateRegExp.test(caller)) {
                   16183:             optionsElement = domForm.elements[caller];
                   16184:             checkval = 'other';
                   16185:             dispval = 'inline'
                   16186:         }
1.236     raeburn  16187:         if (optionsElement.length) {
1.192     raeburn  16188:             var currval;
1.236     raeburn  16189:             for (var i=0; i<optionsElement.length; i++) {
                   16190:                 if (optionsElement[i].checked) {
                   16191:                    currval = optionsElement[i].value;
1.192     raeburn  16192:                 }
                   16193:             }
1.264     raeburn  16194:             if (currval == checkval) {
                   16195:                 divitem.style.display = dispval;
1.192     raeburn  16196:             } else {
1.236     raeburn  16197:                 divitem.style.display = 'none';
1.192     raeburn  16198:             }
                   16199:         }
                   16200:     }
                   16201:     return;
                   16202: }
                   16203: 
                   16204: // ]]>
                   16205: </script>
                   16206: 
                   16207: END
                   16208: 
                   16209: }
                   16210: 
1.165     raeburn  16211: sub captcha_phrases {
                   16212:     return &Apache::lonlocal::texthash (
                   16213:                  priv => 'Private key',
                   16214:                  pub  => 'Public key',
                   16215:                  original  => 'original (CAPTCHA)',
                   16216:                  recaptcha => 'successor (ReCAPTCHA)',
                   16217:                  notused   => 'unused',
1.289     raeburn  16218:                  ver => 'ReCAPTCHA version (1 or 2)',
1.165     raeburn  16219:     );
                   16220: }
                   16221: 
1.205     raeburn  16222: sub devalidate_remote_domconfs {
1.212     raeburn  16223:     my ($dom,$cachekeys) = @_;
                   16224:     return unless (ref($cachekeys) eq 'HASH');
1.205     raeburn  16225:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
                   16226:     my %thismachine;
                   16227:     map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.295     raeburn  16228:     my @posscached = ('domainconfig','domdefaults','ltitools','usersessions','directorysrch');
1.260     raeburn  16229:     if (keys(%servers)) {
1.205     raeburn  16230:         foreach my $server (keys(%servers)) {
                   16231:             next if ($thismachine{$server});
1.212     raeburn  16232:             my @cached;
                   16233:             foreach my $name (@posscached) {
                   16234:                 if ($cachekeys->{$name}) {
                   16235:                     push(@cached,&escape($name).':'.&escape($dom));
                   16236:                 }
                   16237:             }
                   16238:             if (@cached) {
                   16239:                 &Apache::lonnet::remote_devalidate_cache($server,\@cached);
                   16240:             }
1.205     raeburn  16241:         }
                   16242:     }
                   16243:     return;
                   16244: }
                   16245: 
1.3       raeburn  16246: 1;

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