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

1.1       raeburn     1: # The LearningOnline Network with CAPA
                      2: # Handler to set domain-wide configuration settings
                      3: #
1.283   ! raeburn     4: # $Id: domainprefs.pm,v 1.282 2016/10/05 13:59:46 raeburn Exp $
1.2       albertel    5: #
1.1       raeburn     6: # Copyright Michigan State University Board of Trustees
                      7: #
                      8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                      9: #
                     10: # LON-CAPA is free software; you can redistribute it and/or modify
                     11: # it under the terms of the GNU General Public License as published by
                     12: # the Free Software Foundation; either version 2 of the License, or
                     13: # (at your option) any later version.
                     14: #
                     15: # LON-CAPA is distributed in the hope that it will be useful,
                     16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     18: # GNU General Public License for more details.
                     19: #
                     20: # You should have received a copy of the GNU General Public License
                     21: # along with LON-CAPA; if not, write to the Free Software
                     22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA#
                     23: # /home/httpd/html/adm/gpl.txt
                     24: #
                     25: # http://www.lon-capa.org/
                     26: #
                     27: #
                     28: ###############################################################
                     29: ##############################################################
                     30: 
1.101     raeburn    31: =pod
                     32: 
                     33: =head1 NAME
                     34: 
                     35: Apache::domainprefs.pm
                     36: 
                     37: =head1 SYNOPSIS
                     38: 
                     39: Handles configuration of a LON-CAPA domain.  
                     40: 
                     41: This is part of the LearningOnline Network with CAPA project
                     42: described at http://www.lon-capa.org.
                     43: 
                     44: 
                     45: =head1 OVERVIEW
                     46: 
                     47: Each institution using LON-CAPA will typically have a single domain designated 
1.183     bisitz     48: for use by individuals affiliated with the institution.  Accordingly, each domain
1.101     raeburn    49: may define a default set of logos and a color scheme which can be used to "brand"
                     50: the LON-CAPA instance. In addition, an institution will typically have a language
                     51: and timezone which are used for the majority of courses.
                     52: 
                     53: LON-CAPA provides a mechanism to display and modify these defaults, as well as a 
                     54: host of other domain-wide settings which determine the types of functionality
                     55: available to users and courses in the domain.
                     56: 
                     57: There is also a mechanism to configure cataloging of courses in the domain, and
                     58: controls on the operation of automated processes which govern such things as
                     59: roster updates, user directory updates and processing of course requests.
                     60: 
                     61: The domain coordination manual which is built dynamically on install/update of 
                     62: LON-CAPA from the relevant help items provides more information about domain 
                     63: configuration.
                     64: 
                     65: Most of the domain settings are stored in the configuration.db GDBM file which is
                     66: housed on the primary library server for the domain in /home/httpd/lonUsers/$dom,
                     67: where $dom is the domain.  The configuration.db stores settings in a number of 
                     68: frozen hashes of hashes.  In a few cases, domain information must be uploaded to
                     69: the domain as files (e.g., image files for logos etc., or plain text files for
                     70: bubblesheet formats).  In this case the domainprefs.pm must be running in a user
                     71: session hosted on the primary library server in the domain, as these files are 
                     72: stored in author space belonging to a special $dom-domainconfig user.   
                     73: 
                     74: domainprefs.pm in combination with lonconfigsettings.pm will retrieve and display
                     75: the current settings, and provides an interface to make modifications.
                     76: 
                     77: =head1 SUBROUTINES
                     78: 
                     79: =over
                     80: 
                     81: =item print_quotas()
                     82: 
                     83: Inputs: 4 
                     84: 
                     85: $dom,$settings,$rowtotal,$action.
                     86: 
                     87: $dom is the domain, $settings is a reference to a hash of current settings for
                     88: the current context, $rowtotal is a reference to the scalar used to record the 
1.210     raeburn    89: number of rows displayed on the page, and $action is the context (quotas, 
1.163     raeburn    90: requestcourses or requestauthor).
1.101     raeburn    91: 
                     92: The print_quotas routine was orginally created to display/store information
                     93: about default quota sizes for portfolio spaces for the different types of 
                     94: institutional affiliation in the domain (e.g., Faculty, Staff, Student etc.), 
                     95: but is now also used to manage availability of user tools: 
                     96: i.e., blogs, aboutme page, and portfolios, and the course request tool,
1.197     raeburn    97: used by course owners to request creation of a course, and to display/store
1.223     bisitz     98: default quota sizes for Authoring Spaces.
1.101     raeburn    99: 
                    100: Outputs: 1
                    101: 
                    102: $datatable  - HTML containing form elements which allow settings to be changed. 
                    103: 
                    104: In the case of course requests, radio buttons are displayed for each institutional
                    105: affiliate type (and also default, and _LC_adv) for each of the course types 
1.271     raeburn   106: (official, unofficial, community, textbook, and placement).  
                    107: In each case the radio buttons allow the selection of one of four values:  
1.101     raeburn   108: 
1.104     raeburn   109: 0, approval, validate, autolimit=N (where N is blank, or a positive integer).
1.101     raeburn   110: which have the following effects:
                    111: 
                    112: 0
                    113: 
                    114: =over
                    115: 
                    116: - course requests are not allowed for this course types/affiliation
                    117: 
                    118: =back
                    119: 
1.104     raeburn   120: approval 
1.101     raeburn   121: 
                    122: =over 
                    123: 
                    124: - course requests must be approved by a Doman Coordinator in the 
                    125: course's domain
                    126: 
                    127: =back
                    128: 
                    129: validate 
                    130: 
                    131: =over
                    132: 
                    133: - an institutional validation (e.g., check requestor is instructor
                    134: of record) needs to be passed before the course will be created.  The required
                    135: validation is in localenroll.pm on the primary library server for the course 
                    136: domain.
                    137: 
                    138: =back
                    139: 
                    140: autolimit 
                    141: 
                    142: =over
                    143:  
1.143     raeburn   144: - course requests will be processed automatically up to a limit of
1.101     raeburn   145: N requests for the course type for the particular requestor.
                    146: If N is undefined, there is no limit to the number of course requests
                    147: which a course owner may submit and have processed automatically. 
                    148: 
                    149: =back
                    150: 
                    151: =item modify_quotas() 
                    152: 
                    153: =back
                    154: 
                    155: =cut
                    156: 
1.1       raeburn   157: package Apache::domainprefs;
                    158: 
                    159: use strict;
                    160: use Apache::Constants qw(:common :http);
                    161: use Apache::lonnet;
                    162: use Apache::loncommon();
                    163: use Apache::lonhtmlcommon();
                    164: use Apache::lonlocal;
1.43      raeburn   165: use Apache::lonmsg();
1.91      raeburn   166: use Apache::lonconfigsettings;
1.232     raeburn   167: use Apache::lonuserutils();
1.235     raeburn   168: use Apache::loncoursequeueadmin();
1.69      raeburn   169: use LONCAPA qw(:DEFAULT :match);
1.6       raeburn   170: use LONCAPA::Enrollment;
1.81      raeburn   171: use LONCAPA::lonauthcgi();
1.275     raeburn   172: use LONCAPA::SSL;
1.9       raeburn   173: use File::Copy;
1.43      raeburn   174: use Locale::Language;
1.62      raeburn   175: use DateTime::TimeZone;
1.68      raeburn   176: use DateTime::Locale;
1.267     raeburn   177: use Time::HiRes qw( sleep );
1.1       raeburn   178: 
1.155     raeburn   179: my $registered_cleanup;
                    180: my $modified_urls;
                    181: 
1.1       raeburn   182: sub handler {
                    183:     my $r=shift;
                    184:     if ($r->header_only) {
                    185:         &Apache::loncommon::content_type($r,'text/html');
                    186:         $r->send_http_header;
                    187:         return OK;
                    188:     }
                    189: 
1.91      raeburn   190:     my $context = 'domain';
1.1       raeburn   191:     my $dom = $env{'request.role.domain'};
1.5       albertel  192:     my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1       raeburn   193:     if (&Apache::lonnet::allowed('mau',$dom)) {
                    194:         &Apache::loncommon::content_type($r,'text/html');
                    195:         $r->send_http_header;
                    196:     } else {
                    197:         $env{'user.error.msg'}=
                    198:         "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
                    199:         return HTTP_NOT_ACCEPTABLE;
                    200:     }
1.155     raeburn   201: 
                    202:     $registered_cleanup=0;
                    203:     @{$modified_urls}=();
                    204: 
1.1       raeburn   205:     &Apache::lonhtmlcommon::clear_breadcrumbs();
                    206:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.58      raeburn   207:                                             ['phase','actions']);
1.30      raeburn   208:     my $phase = 'pickactions';
1.3       raeburn   209:     if ( exists($env{'form.phase'}) ) {
                    210:         $phase = $env{'form.phase'};
                    211:     }
1.150     raeburn   212:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.3       raeburn   213:     my %domconfig =
1.6       raeburn   214:       &Apache::lonnet::get_dom('configuration',['login','rolecolors',
1.125     raeburn   215:                 'quotas','autoenroll','autoupdate','autocreate',
                    216:                 'directorysrch','usercreation','usermodification',
                    217:                 'contacts','defaults','scantron','coursecategories',
                    218:                 'serverstatuses','requestcourses','helpsettings',
1.163     raeburn   219:                 'coursedefaults','usersessions','loadbalancing',
1.267     raeburn   220:                 'requestauthor','selfenrollment','inststatus',
1.279     raeburn   221:                 'ltitools','ssl','trust'],$dom);
1.43      raeburn   222:     my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll',
1.125     raeburn   223:                        'autoupdate','autocreate','directorysrch','contacts',
1.224     raeburn   224:                        'usercreation','selfcreation','usermodification','scantron',
1.163     raeburn   225:                        'requestcourses','requestauthor','coursecategories',
1.267     raeburn   226:                        'serverstatuses','helpsettings','coursedefaults',
1.279     raeburn   227:                        'ltitools','selfenrollment','usersessions','ssl','trust');
1.171     raeburn   228:     my %existing;
                    229:     if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
                    230:         %existing = %{$domconfig{'loadbalancing'}};
                    231:     }
                    232:     if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.150     raeburn   233:         push(@prefs_order,'loadbalancing');
                    234:     }
1.30      raeburn   235:     my %prefs = (
                    236:         'rolecolors' =>
                    237:                    { text => 'Default color schemes',
1.67      raeburn   238:                      help => 'Domain_Configuration_Color_Schemes',
1.30      raeburn   239:                      header => [{col1 => 'Student Settings',
                    240:                                  col2 => '',},
                    241:                                 {col1 => 'Coordinator Settings',
                    242:                                  col2 => '',},
                    243:                                 {col1 => 'Author Settings',
                    244:                                  col2 => '',},
                    245:                                 {col1 => 'Administrator Settings',
                    246:                                  col2 => '',}],
1.230     raeburn   247:                       print => \&print_rolecolors,
                    248:                       modify => \&modify_rolecolors,
1.30      raeburn   249:                     },
1.110     raeburn   250:         'login' =>
1.30      raeburn   251:                     { text => 'Log-in page options',
1.67      raeburn   252:                       help => 'Domain_Configuration_Login_Page',
1.168     raeburn   253:                       header => [{col1 => 'Log-in Page Items',
                    254:                                   col2 => '',},
                    255:                                  {col1 => 'Log-in Help',
1.256     raeburn   256:                                   col2 => 'Value'},
                    257:                                  {col1 => 'Custom HTML in document head',
1.168     raeburn   258:                                   col2 => 'Value'}],
1.230     raeburn   259:                       print => \&print_login,
                    260:                       modify => \&modify_login,
1.30      raeburn   261:                     },
1.43      raeburn   262:         'defaults' => 
1.236     raeburn   263:                     { text => 'Default authentication/language/timezone/portal/types',
1.67      raeburn   264:                       help => 'Domain_Configuration_LangTZAuth',
1.43      raeburn   265:                       header => [{col1 => 'Setting',
1.236     raeburn   266:                                   col2 => 'Value'},
                    267:                                  {col1 => 'Institutional user types',
                    268:                                   col2 => 'Assignable to e-mail usernames'}],
1.230     raeburn   269:                       print => \&print_defaults,
                    270:                       modify => \&modify_defaults,
1.43      raeburn   271:                     },
1.30      raeburn   272:         'quotas' => 
1.197     raeburn   273:                     { text => 'Blogs, personal web pages, webDAV/quotas, portfolios',
1.67      raeburn   274:                       help => 'Domain_Configuration_Quotas',
1.77      raeburn   275:                       header => [{col1 => 'User affiliation',
1.72      raeburn   276:                                   col2 => 'Available tools',
1.213     raeburn   277:                                   col3 => 'Quotas, MB; (Authoring requires role)',}],
1.230     raeburn   278:                       print => \&print_quotas,
                    279:                       modify => \&modify_quotas,
1.30      raeburn   280:                     },
                    281:         'autoenroll' =>
                    282:                    { text => 'Auto-enrollment settings',
1.67      raeburn   283:                      help => 'Domain_Configuration_Auto_Enrollment',
1.30      raeburn   284:                      header => [{col1 => 'Configuration setting',
                    285:                                  col2 => 'Value(s)'}],
1.230     raeburn   286:                      print => \&print_autoenroll,
                    287:                      modify => \&modify_autoenroll,
1.30      raeburn   288:                    },
                    289:         'autoupdate' => 
                    290:                    { text => 'Auto-update settings',
1.67      raeburn   291:                      help => 'Domain_Configuration_Auto_Updates',
1.30      raeburn   292:                      header => [{col1 => 'Setting',
                    293:                                  col2 => 'Value',},
1.131     raeburn   294:                                 {col1 => 'Setting',
                    295:                                  col2 => 'Affiliation'},
1.43      raeburn   296:                                 {col1 => 'User population',
1.227     bisitz    297:                                  col2 => 'Updatable user data'}],
1.230     raeburn   298:                      print => \&print_autoupdate,
                    299:                      modify => \&modify_autoupdate,
1.30      raeburn   300:                   },
1.125     raeburn   301:         'autocreate' => 
                    302:                   { text => 'Auto-course creation settings',
                    303:                      help => 'Domain_Configuration_Auto_Creation',
                    304:                      header => [{col1 => 'Configuration Setting',
                    305:                                  col2 => 'Value',}],
1.230     raeburn   306:                      print => \&print_autocreate,
                    307:                      modify => \&modify_autocreate,
1.125     raeburn   308:                   },
1.30      raeburn   309:         'directorysrch' => 
1.277     raeburn   310:                   { text => 'Directory searches',
1.67      raeburn   311:                     help => 'Domain_Configuration_InstDirectory_Search',
1.277     raeburn   312:                     header => [{col1 => 'Institutional Directory Setting',
                    313:                                 col2 => 'Value',},
                    314:                                {col1 => 'LON-CAPA Directory Setting',
1.30      raeburn   315:                                 col2 => 'Value',}],
1.230     raeburn   316:                     print => \&print_directorysrch,
                    317:                     modify => \&modify_directorysrch,
1.30      raeburn   318:                   },
                    319:         'contacts' =>
                    320:                   { text => 'Contact Information',
1.67      raeburn   321:                     help => 'Domain_Configuration_Contact_Info',
1.30      raeburn   322:                     header => [{col1 => 'Setting',
                    323:                                 col2 => 'Value',}],
1.230     raeburn   324:                     print => \&print_contacts,
                    325:                     modify => \&modify_contacts,
1.30      raeburn   326:                   },
                    327:         'usercreation' => 
                    328:                   { text => 'User creation',
1.67      raeburn   329:                     help => 'Domain_Configuration_User_Creation',
1.43      raeburn   330:                     header => [{col1 => 'Format rule type',
                    331:                                 col2 => 'Format rules in force'},
1.34      raeburn   332:                                {col1 => 'User account creation',
                    333:                                 col2 => 'Usernames which may be created',},
1.30      raeburn   334:                                {col1 => 'Context',
1.43      raeburn   335:                                 col2 => 'Assignable authentication types'}],
1.230     raeburn   336:                     print => \&print_usercreation,
                    337:                     modify => \&modify_usercreation,
1.30      raeburn   338:                   },
1.224     raeburn   339:         'selfcreation' => 
                    340:                   { text => 'Users self-creating accounts',
                    341:                     help => 'Domain_Configuration_Self_Creation', 
                    342:                     header => [{col1 => 'Self-creation with institutional username',
                    343:                                 col2 => 'Enabled?'},
                    344:                                {col1 => 'Institutional user type (login/SSO self-creation)',
                    345:                                 col2 => 'Information user can enter'},
                    346:                                {col1 => 'Self-creation with e-mail as username',
                    347:                                 col2 => 'Settings'}],
1.230     raeburn   348:                     print => \&print_selfcreation,
                    349:                     modify => \&modify_selfcreation,
1.224     raeburn   350:                   },
1.69      raeburn   351:         'usermodification' =>
1.33      raeburn   352:                   { text => 'User modification',
1.67      raeburn   353:                     help => 'Domain_Configuration_User_Modification',
1.33      raeburn   354:                     header => [{col1 => 'Target user has role',
1.227     bisitz    355:                                 col2 => 'User information updatable in author context'},
1.33      raeburn   356:                                {col1 => 'Target user has role',
1.227     bisitz    357:                                 col2 => 'User information updatable in course context'}],
1.230     raeburn   358:                     print => \&print_usermodification,
                    359:                     modify => \&modify_usermodification,
1.33      raeburn   360:                   },
1.69      raeburn   361:         'scantron' =>
1.95      www       362:                   { text => 'Bubblesheet format file',
1.67      raeburn   363:                     help => 'Domain_Configuration_Scantron_Format',
1.46      raeburn   364:                     header => [ {col1 => 'Item',
                    365:                                  col2 => '',
                    366:                               }],
1.230     raeburn   367:                     print => \&print_scantron,
                    368:                     modify => \&modify_scantron,
1.46      raeburn   369:                   },
1.86      raeburn   370:         'requestcourses' => 
                    371:                  {text => 'Request creation of courses',
                    372:                   help => 'Domain_Configuration_Request_Courses',
                    373:                   header => [{col1 => 'User affiliation',
1.102     raeburn   374:                               col2 => 'Availability/Processing of requests',},
                    375:                              {col1 => 'Setting',
1.216     raeburn   376:                               col2 => 'Value'},
                    377:                              {col1 => 'Available textbooks',
1.235     raeburn   378:                               col2 => ''},
1.242     raeburn   379:                              {col1 => 'Available templates',
                    380:                               col2 => ''},
1.235     raeburn   381:                              {col1 => 'Validation (not official courses)',
                    382:                               col2 => 'Value'},],
1.230     raeburn   383:                   print => \&print_quotas,
                    384:                   modify => \&modify_quotas,
1.86      raeburn   385:                  },
1.163     raeburn   386:         'requestauthor' =>
1.223     bisitz    387:                  {text => 'Request Authoring Space',
1.163     raeburn   388:                   help => 'Domain_Configuration_Request_Author',
                    389:                   header => [{col1 => 'User affiliation',
                    390:                               col2 => 'Availability/Processing of requests',},
                    391:                              {col1 => 'Setting',
                    392:                               col2 => 'Value'}],
1.230     raeburn   393:                   print => \&print_quotas,
                    394:                   modify => \&modify_quotas,
1.163     raeburn   395:                  },
1.69      raeburn   396:         'coursecategories' =>
1.120     raeburn   397:                   { text => 'Cataloging of courses/communities',
1.67      raeburn   398:                     help => 'Domain_Configuration_Cataloging_Courses',
1.238     raeburn   399:                     header => [{col1 => 'Catalog type/availability',
                    400:                                 col2 => '',},
                    401:                                {col1 => 'Category settings for standard catalog',
1.57      raeburn   402:                                 col2 => '',},
                    403:                                {col1 => 'Categories',
                    404:                                 col2 => '',
                    405:                                }],
1.230     raeburn   406:                     print => \&print_coursecategories,
                    407:                     modify => \&modify_coursecategories,
1.69      raeburn   408:                   },
                    409:         'serverstatuses' =>
1.77      raeburn   410:                  {text   => 'Access to server status pages',
1.69      raeburn   411:                   help   => 'Domain_Configuration_Server_Status',
                    412:                   header => [{col1 => 'Status Page',
                    413:                               col2 => 'Other named users',
                    414:                               col3 => 'Specific IPs',
                    415:                             }],
1.230     raeburn   416:                   print => \&print_serverstatuses,
                    417:                   modify => \&modify_serverstatuses,
1.69      raeburn   418:                  },
1.118     jms       419:         'helpsettings' =>
1.282     raeburn   420:                  {text   => 'Support settings',
1.118     jms       421:                   help   => 'Domain_Configuration_Help_Settings',
1.282     raeburn   422:                   header => [{col1 => 'Help Page Settings (logged-in users)',
                    423:                               col2 => 'Value'},
                    424:                              {col1 => 'Helpdesk Roles',
                    425:                               col2 => 'Settings'},],
1.230     raeburn   426:                   print  => \&print_helpsettings,
                    427:                   modify => \&modify_helpsettings,
1.118     jms       428:                  },
1.121     raeburn   429:         'coursedefaults' => 
                    430:                  {text => 'Course/Community defaults',
                    431:                   help => 'Domain_Configuration_Course_Defaults',
1.139     raeburn   432:                   header => [{col1 => 'Defaults which can be overridden in each course by a CC',
                    433:                               col2 => 'Value',},
                    434:                              {col1 => 'Defaults which can be overridden for each course by a DC',
                    435:                               col2 => 'Value',},],
1.230     raeburn   436:                   print => \&print_coursedefaults,
                    437:                   modify => \&modify_coursedefaults,
1.121     raeburn   438:                  },
1.231     raeburn   439:         'selfenrollment' => 
                    440:                  {text   => 'Self-enrollment in Course/Community',
                    441:                   help   => 'Domain_Configuration_Selfenrollment',
                    442:                   header => [{col1 => 'Configuration Rights',
                    443:                               col2 => 'Configured by Course Personnel or Domain Coordinator?'},
                    444:                              {col1 => 'Defaults',
                    445:                               col2 => 'Value'},
                    446:                              {col1 => 'Self-enrollment validation (optional)',
                    447:                               col2 => 'Value'},],
                    448:                   print => \&print_selfenrollment,
                    449:                   modify => \&modify_selfenrollment,
                    450:                  },
1.120     raeburn   451:         'privacy' => 
                    452:                  {text   => 'User Privacy',
                    453:                   help   => 'Domain_Configuration_User_Privacy',
                    454:                   header => [{col1 => 'Setting',
                    455:                               col2 => 'Value',}],
1.230     raeburn   456:                   print => \&print_privacy,
                    457:                   modify => \&modify_privacy,
1.120     raeburn   458:                  },
1.141     raeburn   459:         'usersessions' =>
1.145     raeburn   460:                  {text  => 'User session hosting/offloading',
1.137     raeburn   461:                   help  => 'Domain_Configuration_User_Sessions',
1.145     raeburn   462:                   header => [{col1 => 'Domain server',
                    463:                               col2 => 'Servers to offload sessions to when busy'},
                    464:                              {col1 => 'Hosting of users from other domains',
1.137     raeburn   465:                               col2 => 'Rules'},
                    466:                              {col1 => "Hosting domain's own users elsewhere",
                    467:                               col2 => 'Rules'}],
1.230     raeburn   468:                   print => \&print_usersessions,
                    469:                   modify => \&modify_usersessions,
1.137     raeburn   470:                  },
1.279     raeburn   471:         'loadbalancing' =>
1.185     raeburn   472:                  {text  => 'Dedicated Load Balancer(s)',
1.150     raeburn   473:                   help  => 'Domain_Configuration_Load_Balancing',
1.171     raeburn   474:                   header => [{col1 => 'Balancers',
1.150     raeburn   475:                               col2 => 'Default destinations',
1.183     bisitz    476:                               col3 => 'User affiliation',
1.150     raeburn   477:                               col4 => 'Overrides'},
                    478:                             ],
1.230     raeburn   479:                   print => \&print_loadbalancing,
                    480:                   modify => \&modify_loadbalancing,
1.150     raeburn   481:                  },
1.279     raeburn   482:         'ltitools' => 
1.267     raeburn   483:                  {text => 'External Tools (LTI)',
                    484:                   help => 'Domain_configuration_LTI_Tools',
                    485:                   header => [{col1 => 'Setting',
                    486:                               col2 => 'Value',}],
                    487:                   print => \&print_ltitools,
                    488:                   modify => \&modify_ltitools,
                    489:                  },
1.279     raeburn   490:         'ssl' =>
1.275     raeburn   491:                  {text  => 'LON-CAPA Network (SSL)',
                    492:                   help  => 'Domain_Configuration_Network_SSL',
                    493:                   header => [{col1 => 'Server',
                    494:                               col2 => 'Certificate Status'},
                    495:                              {col1 => 'Connections to other servers',
                    496:                               col2 => 'Rules'},
                    497:                              {col1 => "Replicating domain's published content",
                    498:                               col2 => 'Rules'}],
                    499:                   print => \&print_ssl,
                    500:                   modify => \&modify_ssl,
                    501:                  },
1.279     raeburn   502:         'trust' =>
                    503:                  {text   => 'Trust Settings',
                    504:                   help   => 'Domain_Configuration_Trust',
                    505:                   header => [{col1 => "Access to this domain's content by others",
                    506:                               col2 => 'Rules'},
                    507:                              {col1 => "Access to other domain's content by this domain",
                    508:                               col2 => 'Rules'},
                    509:                              {col1 => "Enrollment in this domain's courses by others",
                    510:                               col2 => 'Rules',},
                    511:                              {col1 => "Co-author roles in this domain for others",
                    512:                               col2 => 'Rules',},
                    513:                              {col1 => "Co-author roles for this domain's users elsewhere",
                    514:                               col2 => 'Rules',},
                    515:                              {col1 => "Domain roles in this domain assignable to others",
                    516:                               col2 => 'Rules'},
                    517:                              {col1 => "Course catalog for this domain displayed elsewhere",
                    518:                               col2 => 'Rules'},
                    519:                              {col1 => "Requests for creation of courses in this domain by others",
                    520:                               col2 => 'Rules'},
                    521:                              {col1 => "Users in other domains can send messages to this domain",
                    522:                               col2 => 'Rules'},],
                    523:                   print => \&print_trust,
                    524:                   modify => \&modify_trust,
                    525:                  },
1.3       raeburn   526:     );
1.110     raeburn   527:     if (keys(%servers) > 1) {
                    528:         $prefs{'login'}  = { text   => 'Log-in page options',
                    529:                              help   => 'Domain_Configuration_Login_Page',
                    530:                             header => [{col1 => 'Log-in Service',
                    531:                                         col2 => 'Server Setting',},
                    532:                                        {col1 => 'Log-in Page Items',
1.168     raeburn   533:                                         col2 => ''},
                    534:                                        {col1 => 'Log-in Help',
1.256     raeburn   535:                                         col2 => 'Value'},
                    536:                                        {col1 => 'Custom HTML in document head',
1.168     raeburn   537:                                         col2 => 'Value'}],
1.230     raeburn   538:                             print => \&print_login,
                    539:                             modify => \&modify_login,
1.110     raeburn   540:                            };
                    541:     }
1.174     foxr      542: 
1.6       raeburn   543:     my @roles = ('student','coordinator','author','admin');
1.30      raeburn   544:     my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3       raeburn   545:     &Apache::lonhtmlcommon::add_breadcrumb
1.30      raeburn   546:     ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133     raeburn   547:       text=>"Settings to display/modify"});
1.9       raeburn   548:     my $confname = $dom.'-domainconfig';
1.174     foxr      549: 
1.3       raeburn   550:     if ($phase eq 'process') {
1.212     raeburn   551:         my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
                    552:                                                               \%prefs,\%domconfig,$confname,\@roles);
1.224     raeburn   553:         if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.205     raeburn   554:             $r->rflush();
1.212     raeburn   555:             &devalidate_remote_domconfs($dom,$result);
1.205     raeburn   556:         }
1.30      raeburn   557:     } elsif ($phase eq 'display') {
1.192     raeburn   558:         my $js = &recaptcha_js().
1.236     raeburn   559:                  &toggle_display_js();
1.171     raeburn   560:         if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152     raeburn   561:             my ($othertitle,$usertypes,$types) =
                    562:                 &Apache::loncommon::sorted_inst_types($dom);
1.171     raeburn   563:             $js .= &lonbalance_targets_js($dom,$types,\%servers,
                    564:                                           $domconfig{'loadbalancing'}).
1.170     raeburn   565:                    &new_spares_js().
                    566:                    &common_domprefs_js().
                    567:                    &Apache::loncommon::javascript_array_indexof();
1.152     raeburn   568:         }
1.216     raeburn   569:         if (grep(/^requestcourses$/,@actions)) {
                    570:             my $javascript_validations;
                    571:             my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'}); 
                    572:             $js .= <<END;
                    573: <script type="text/javascript">
                    574: $javascript_validations
                    575: </script>
                    576: $coursebrowserjs
                    577: END
                    578:         }
1.150     raeburn   579:         &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1       raeburn   580:     } else {
1.180     raeburn   581: # check if domconfig user exists for the domain.
                    582:         my $servadm = $r->dir_config('lonAdmEMail');
                    583:         my ($configuserok,$author_ok,$switchserver) =
                    584:             &config_check($dom,$confname,$servadm);
                    585:         unless ($configuserok eq 'ok') {
1.181     raeburn   586:             &Apache::lonconfigsettings::print_header($r,$phase,$context);
                    587:             $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
1.210     raeburn   588:                           $confname).
1.181     raeburn   589:                       '<br />'
                    590:             );
1.180     raeburn   591:             if ($switchserver) {
1.181     raeburn   592:                 $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
                    593:                           '<br />'.
                    594:                           &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
                    595:                           '<br />'.
                    596:                           &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).
                    597:                           '<br />'.
                    598:                           &mt('To do that now, use the following link: [_1]',$switchserver)
                    599:                 );
                    600:             } else {
                    601:                 $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.').
                    602:                           '<br />'.
                    603:                           &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
                    604:                 );
1.180     raeburn   605:             }
                    606:             $r->print(&Apache::loncommon::end_page());
                    607:             return OK;
                    608:         }
1.21      raeburn   609:         if (keys(%domconfig) == 0) {
                    610:             my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29      raeburn   611:             my @ids=&Apache::lonnet::current_machine_ids();
                    612:             if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21      raeburn   613:                 my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41      raeburn   614:                 my @loginimages = ('img','logo','domlogo','login');
1.21      raeburn   615:                 my $custom_img_count = 0;
                    616:                 foreach my $img (@loginimages) {
                    617:                     if ($designhash{$dom.'.login.'.$img} ne '') {
                    618:                         $custom_img_count ++;
                    619:                     }
                    620:                 }
                    621:                 foreach my $role (@roles) {
                    622:                     if ($designhash{$dom.'.'.$role.'.img'} ne '') {
                    623:                         $custom_img_count ++;
                    624:                     }
                    625:                 }
                    626:                 if ($custom_img_count > 0) {
1.94      raeburn   627:                     &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21      raeburn   628:                     my $switch_server = &check_switchserver($dom,$confname);
1.29      raeburn   629:                     $r->print(
                    630:     &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
                    631:     &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
                    632:     &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 />'.
                    633:     &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
                    634:                     if ($switch_server) {
1.30      raeburn   635:                         $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29      raeburn   636:                     }
1.91      raeburn   637:                     $r->print(&Apache::loncommon::end_page());
1.21      raeburn   638:                     return OK;
                    639:                 }
                    640:             }
                    641:         }
1.91      raeburn   642:         &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3       raeburn   643:     }
                    644:     return OK;
                    645: }
                    646: 
                    647: sub process_changes {
1.205     raeburn   648:     my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92      raeburn   649:     my %domconfig;
                    650:     if (ref($values) eq 'HASH') {
                    651:         %domconfig = %{$values};
                    652:     }
1.3       raeburn   653:     my $output;
                    654:     if ($action eq 'login') {
1.205     raeburn   655:         $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6       raeburn   656:     } elsif ($action eq 'rolecolors') {
1.9       raeburn   657:         $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.205     raeburn   658:                                      $lastactref,%domconfig);
1.3       raeburn   659:     } elsif ($action eq 'quotas') {
1.216     raeburn   660:         $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3       raeburn   661:     } elsif ($action eq 'autoenroll') {
1.205     raeburn   662:         $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3       raeburn   663:     } elsif ($action eq 'autoupdate') {
                    664:         $output = &modify_autoupdate($dom,%domconfig);
1.125     raeburn   665:     } elsif ($action eq 'autocreate') {
                    666:         $output = &modify_autocreate($dom,%domconfig);
1.23      raeburn   667:     } elsif ($action eq 'directorysrch') {
                    668:         $output = &modify_directorysrch($dom,%domconfig);
1.27      raeburn   669:     } elsif ($action eq 'usercreation') {
1.28      raeburn   670:         $output = &modify_usercreation($dom,%domconfig);
1.224     raeburn   671:     } elsif ($action eq 'selfcreation') {
                    672:         $output = &modify_selfcreation($dom,%domconfig);
1.33      raeburn   673:     } elsif ($action eq 'usermodification') {
                    674:         $output = &modify_usermodification($dom,%domconfig);
1.28      raeburn   675:     } elsif ($action eq 'contacts') {
1.205     raeburn   676:         $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43      raeburn   677:     } elsif ($action eq 'defaults') {
1.212     raeburn   678:         $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46      raeburn   679:     } elsif ($action eq 'scantron') {
1.205     raeburn   680:         $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48      raeburn   681:     } elsif ($action eq 'coursecategories') {
1.239     raeburn   682:         $output = &modify_coursecategories($dom,$lastactref,%domconfig);
1.69      raeburn   683:     } elsif ($action eq 'serverstatuses') {
                    684:         $output = &modify_serverstatuses($dom,%domconfig);
1.86      raeburn   685:     } elsif ($action eq 'requestcourses') {
1.216     raeburn   686:         $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.163     raeburn   687:     } elsif ($action eq 'requestauthor') {
1.216     raeburn   688:         $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.118     jms       689:     } elsif ($action eq 'helpsettings') {
1.122     jms       690:         $output = &modify_helpsettings($r,$dom,$confname,%domconfig);
1.121     raeburn   691:     } elsif ($action eq 'coursedefaults') {
1.212     raeburn   692:         $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.231     raeburn   693:     } elsif ($action eq 'selfenrollment') {
                    694:         $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
1.137     raeburn   695:     } elsif ($action eq 'usersessions') {
1.212     raeburn   696:         $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150     raeburn   697:     } elsif ($action eq 'loadbalancing') {
                    698:         $output = &modify_loadbalancing($dom,%domconfig);
1.267     raeburn   699:     } elsif ($action eq 'ltitools') {
                    700:         $output = &modify_ltitools($r,$dom,$action,$lastactref,%domconfig);
1.275     raeburn   701:     } elsif ($action eq 'ssl') {
                    702:         $output = &modify_ssl($dom,$lastactref,%domconfig);
1.279     raeburn   703:     } elsif ($action eq 'trust') {
                    704:         $output = &modify_trust($dom,$lastactref,%domconfig);
1.3       raeburn   705:     }
                    706:     return $output;
                    707: }
                    708: 
                    709: sub print_config_box {
1.9       raeburn   710:     my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30      raeburn   711:     my $rowtotal = 0;
1.49      raeburn   712:     my $output;
                    713:     if ($action eq 'coursecategories') {
                    714:         $output = &coursecategories_javascript($settings);
1.236     raeburn   715:     } elsif ($action eq 'defaults') {
                    716:         $output = &defaults_javascript($settings); 
1.282     raeburn   717:     } elsif ($action eq 'helpsettings') {
                    718:         my (%privs,%levelscurrent);
                    719:         my %full=();
                    720:         my %levels=(
                    721:                      course => {},
                    722:                      domain => {},
                    723:                      system => {},
                    724:                    );
                    725:         my $context = 'domain';
                    726:         my $crstype = 'Course';
                    727:         my $formname = 'display';
                    728:         &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
                    729:         my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
                    730:         $output =
                    731:             &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,\%full, 
                    732:                                                       \@templateroles);
1.91      raeburn   733:     }
1.236     raeburn   734:     $output .=
1.30      raeburn   735:          '<table class="LC_nested_outer">
1.3       raeburn   736:           <tr>
1.66      raeburn   737:            <th align="left" valign="middle"><span class="LC_nobreak">'.
                    738:            &mt($item->{text}).'&nbsp;'.
                    739:            &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
                    740:           '</tr>';
1.30      raeburn   741:     $rowtotal ++;
1.110     raeburn   742:     my $numheaders = 1;
                    743:     if (ref($item->{'header'}) eq 'ARRAY') {
                    744:         $numheaders = scalar(@{$item->{'header'}});
                    745:     }
                    746:     if ($numheaders > 1) {
1.64      raeburn   747:         my $colspan = '';
1.145     raeburn   748:         my $rightcolspan = '';
1.238     raeburn   749:         if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.277     raeburn   750:             ($action eq 'directorysrch') ||
1.256     raeburn   751:             (($action eq 'login') && ($numheaders < 4))) {
1.64      raeburn   752:             $colspan = ' colspan="2"';
                    753:         }
1.145     raeburn   754:         if ($action eq 'usersessions') {
                    755:             $rightcolspan = ' colspan="3"'; 
                    756:         }
1.30      raeburn   757:         $output .= '
1.3       raeburn   758:           <tr>
                    759:            <td>
                    760:             <table class="LC_nested">
                    761:              <tr class="LC_info_row">
1.59      bisitz    762:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145     raeburn   763:               <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30      raeburn   764:              </tr>';
1.69      raeburn   765:         $rowtotal ++;
1.230     raeburn   766:         if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.236     raeburn   767:             ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
1.277     raeburn   768:             ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'ssl') ||
1.282     raeburn   769:             ($action eq 'directorysrch') || ($action eq 'trust') || ($action eq 'helpsettings')) {
1.230     raeburn   770:             $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.57      raeburn   771:         } elsif ($action eq 'coursecategories') {
1.230     raeburn   772:             $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.110     raeburn   773:         } elsif ($action eq 'login') {
1.256     raeburn   774:             if ($numheaders == 4) {
1.168     raeburn   775:                 $colspan = ' colspan="2"';
                    776:                 $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
                    777:             } else {
                    778:                 $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
                    779:             }
1.230     raeburn   780:         } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.163     raeburn   781:             $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122     jms       782:         } elsif ($action eq 'rolecolors') {
1.30      raeburn   783:             $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.6       raeburn   784:         }
1.30      raeburn   785:         $output .= '
1.6       raeburn   786:            </table>
                    787:           </td>
                    788:          </tr>
                    789:          <tr>
                    790:            <td>
                    791:             <table class="LC_nested">
                    792:              <tr class="LC_info_row">
1.230     raeburn   793:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59      bisitz    794:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30      raeburn   795:              </tr>';
                    796:             $rowtotal ++;
1.230     raeburn   797:         if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
                    798:             ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.275     raeburn   799:             ($action eq 'usersessions') || ($action eq 'coursecategories') || 
1.279     raeburn   800:             ($action eq 'ssl') || ($action eq 'trust')) {
1.238     raeburn   801:             if ($action eq 'coursecategories') {
                    802:                 $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
                    803:                 $colspan = ' colspan="2"';
1.279     raeburn   804:             } elsif ($action eq 'trust') {
                    805:                 $output .= $item->{'print'}->('shared',$dom,$settings,\$rowtotal);
1.238     raeburn   806:             } else {
                    807:                 $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
                    808:             }
1.279     raeburn   809:             if ($action eq 'trust') {
                    810:                 $output .= '
                    811:             </table>
                    812:           </td>
                    813:          </tr>';
                    814:                 my @trusthdrs = qw(2 3 4 5 6 7);
                    815:                 my @prefixes = qw(enroll othcoau coaurem domroles catalog reqcrs);
                    816:                 for (my $i=0; $i<@trusthdrs; $i++) {
                    817:                     $output .= '
                    818:          <tr>
                    819:            <td>
                    820:             <table class="LC_nested">
                    821:              <tr class="LC_info_row">
                    822:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col1'}).'</td>
                    823:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col2'}).'</td></tr>'.
                    824:                            $item->{'print'}->($prefixes[$i],$dom,$settings,\$rowtotal).'
                    825:             </table>
                    826:           </td>
                    827:          </tr>';
                    828:                 }
                    829:                 $output .= '
                    830:          <tr>
                    831:            <td>
                    832:             <table class="LC_nested">
                    833:              <tr class="LC_info_row">
                    834:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col1'}).'</td>
                    835:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col2'}).'</td></tr>'.
                    836:                            $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
                    837:             } else {
                    838:                 $output .= '
1.63      raeburn   839:            </table>
                    840:           </td>
                    841:          </tr>
                    842:          <tr>
                    843:            <td>
                    844:             <table class="LC_nested">
                    845:              <tr class="LC_info_row">
                    846:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.224     raeburn   847:               <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.238     raeburn   848:              </tr>'."\n";
1.279     raeburn   849:                 if ($action eq 'coursecategories') {
                    850:                     $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
                    851:                 } else {
                    852:                     $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
                    853:                 }
1.238     raeburn   854:             }
1.63      raeburn   855:             $rowtotal ++;
1.236     raeburn   856:         } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
1.282     raeburn   857:                  ($action eq 'defaults') || ($action eq 'directorysrch') ||
                    858:                  ($action eq 'helpsettings')) {
1.230     raeburn   859:             $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.110     raeburn   860:         } elsif ($action eq 'login') {
1.256     raeburn   861:             if ($numheaders == 4) {
1.168     raeburn   862:                 $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
                    863:            </table>
                    864:           </td>
                    865:          </tr>
                    866:          <tr>
                    867:            <td>
                    868:             <table class="LC_nested">
                    869:              <tr class="LC_info_row">
                    870:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.216     raeburn   871:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.168     raeburn   872:                        &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
                    873:                 $rowtotal ++;
                    874:             } else {
                    875:                 $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
                    876:             }
1.256     raeburn   877:             $output .= '
                    878:            </table>
                    879:           </td>
                    880:          </tr>
                    881:          <tr>
                    882:            <td>
                    883:             <table class="LC_nested">
                    884:              <tr class="LC_info_row">';
                    885:             if ($numheaders == 4) {
                    886:                 $output .= '
                    887:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
                    888:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
                    889:              </tr>';
                    890:             } else {
                    891:                 $output .= '
                    892:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
                    893:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
                    894:              </tr>';
                    895:             }
                    896:             $rowtotal ++;
                    897:             $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal);
1.102     raeburn   898:         } elsif ($action eq 'requestcourses') {
1.247     raeburn   899:             $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
                    900:             $rowtotal ++;
                    901:             $output .= &print_studentcode($settings,\$rowtotal).'
1.216     raeburn   902:            </table>
                    903:           </td>
                    904:          </tr>
                    905:          <tr>
                    906:            <td>
                    907:             <table class="LC_nested">
                    908:              <tr class="LC_info_row">
                    909:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
                    910:               <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.242     raeburn   911:                        &textbookcourses_javascript($settings).
                    912:                        &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
                    913:             </table>
                    914:            </td>
                    915:           </tr>
                    916:          <tr>
                    917:            <td>
                    918:             <table class="LC_nested">
                    919:              <tr class="LC_info_row">
                    920:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
                    921:               <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
                    922:                        &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.235     raeburn   923:             </table>
                    924:            </td>
                    925:           </tr>
                    926:           <tr>
                    927:            <td>
                    928:             <table class="LC_nested">
                    929:              <tr class="LC_info_row">
1.242     raeburn   930:               <td class="LC_left_item"'.$colspan.' valign="top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
                    931:               <td class="LC_right_item" valign="top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.235     raeburn   932:              </tr>'.
                    933:             &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.163     raeburn   934:         } elsif ($action eq 'requestauthor') {
                    935:             $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.247     raeburn   936:             $rowtotal ++;
1.122     jms       937:         } elsif ($action eq 'rolecolors') {
1.30      raeburn   938:             $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6       raeburn   939:            </table>
                    940:           </td>
                    941:          </tr>
                    942:          <tr>
                    943:            <td>
                    944:             <table class="LC_nested">
                    945:              <tr class="LC_info_row">
1.69      raeburn   946:               <td class="LC_left_item"'.$colspan.' valign="top">'.
                    947:                &mt($item->{'header'}->[2]->{'col1'}).'</td>
                    948:               <td class="LC_right_item" valign="top">'.
                    949:                &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3       raeburn   950:              </tr>'.
1.30      raeburn   951:             &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3       raeburn   952:            </table>
                    953:           </td>
                    954:          </tr>
                    955:          <tr>
                    956:            <td>
                    957:             <table class="LC_nested">
                    958:              <tr class="LC_info_row">
1.59      bisitz    959:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
                    960:               <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3       raeburn   961:              </tr>'.
1.30      raeburn   962:             &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
                    963:             $rowtotal += 2;
1.6       raeburn   964:         }
1.3       raeburn   965:     } else {
1.30      raeburn   966:         $output .= '
1.3       raeburn   967:           <tr>
                    968:            <td>
                    969:             <table class="LC_nested">
1.30      raeburn   970:              <tr class="LC_info_row">';
1.277     raeburn   971:         if ($action eq 'login') {
1.30      raeburn   972:             $output .= '  
1.59      bisitz    973:               <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69      raeburn   974:         } elsif ($action eq 'serverstatuses') {
                    975:             $output .= '
                    976:               <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
                    977:               '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
                    978: 
1.6       raeburn   979:         } else {
1.30      raeburn   980:             $output .= '
1.69      raeburn   981:               <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
                    982:         }
1.72      raeburn   983:         if (defined($item->{'header'}->[0]->{'col3'})) {
                    984:             $output .= '<td class="LC_left_item" valign="top">'.
                    985:                        &mt($item->{'header'}->[0]->{'col2'});
                    986:             if ($action eq 'serverstatuses') {
                    987:                 $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
                    988:             } 
1.69      raeburn   989:         } else {
                    990:             $output .= '<td class="LC_right_item" valign="top">'.
                    991:                        &mt($item->{'header'}->[0]->{'col2'});
                    992:         }
                    993:         $output .= '</td>';
                    994:         if ($item->{'header'}->[0]->{'col3'}) {
1.150     raeburn   995:             if (defined($item->{'header'}->[0]->{'col4'})) {
                    996:                 $output .= '<td class="LC_left_item" valign="top">'.
                    997:                             &mt($item->{'header'}->[0]->{'col3'});
                    998:             } else {
                    999:                 $output .= '<td class="LC_right_item" valign="top">'.
                   1000:                            &mt($item->{'header'}->[0]->{'col3'});
                   1001:             }
1.69      raeburn  1002:             if ($action eq 'serverstatuses') {
                   1003:                 $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
                   1004:             }
                   1005:             $output .= '</td>';
1.6       raeburn  1006:         }
1.150     raeburn  1007:         if ($item->{'header'}->[0]->{'col4'}) {
                   1008:             $output .= '<td class="LC_right_item" valign="top">'.
                   1009:                        &mt($item->{'header'}->[0]->{'col4'});
                   1010:         }
1.69      raeburn  1011:         $output .= '</tr>';
1.48      raeburn  1012:         $rowtotal ++;
1.168     raeburn  1013:         if ($action eq 'quotas') {
1.86      raeburn  1014:             $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.277     raeburn  1015:         } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') || 
                   1016:                  ($action eq 'contacts') || ($action eq 'serverstatuses') || 
                   1017:                  ($action eq 'loadbalancing') || ($action eq 'ltitools')) {
1.230     raeburn  1018:             $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.46      raeburn  1019:         } elsif ($action eq 'scantron') {
                   1020:             $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
1.121     raeburn  1021:         }
1.3       raeburn  1022:     }
1.30      raeburn  1023:     $output .= '
1.3       raeburn  1024:    </table>
                   1025:   </td>
                   1026:  </tr>
1.30      raeburn  1027: </table><br />';
                   1028:     return ($output,$rowtotal);
1.1       raeburn  1029: }
                   1030: 
1.3       raeburn  1031: sub print_login {
1.168     raeburn  1032:     my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110     raeburn  1033:     my ($css_class,$datatable);
1.6       raeburn  1034:     my %choices = &login_choices();
1.110     raeburn  1035: 
1.168     raeburn  1036:     if ($caller eq 'service') {
1.149     raeburn  1037:         my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110     raeburn  1038:         my $choice = $choices{'disallowlogin'};
                   1039:         $css_class = ' class="LC_odd_row"';
1.128     raeburn  1040:         $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110     raeburn  1041:                       '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128     raeburn  1042:                       '<th>'.$choices{'server'}.'</th>'.
                   1043:                       '<th>'.$choices{'serverpath'}.'</th>'.
                   1044:                       '<th>'.$choices{'custompath'}.'</th>'.
                   1045:                       '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110     raeburn  1046:         my %disallowed;
                   1047:         if (ref($settings) eq 'HASH') {
                   1048:             if (ref($settings->{'loginvia'}) eq 'HASH') {
                   1049:                %disallowed = %{$settings->{'loginvia'}};
                   1050:             }
                   1051:         }
                   1052:         foreach my $lonhost (sort(keys(%servers))) {
                   1053:             my $direct = 'selected="selected"';
1.128     raeburn  1054:             if (ref($disallowed{$lonhost}) eq 'HASH') {
                   1055:                 if ($disallowed{$lonhost}{'server'} ne '') {
                   1056:                     $direct = '';
                   1057:                 }
1.110     raeburn  1058:             }
1.115     raeburn  1059:             $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128     raeburn  1060:                           '<td><select name="'.$lonhost.'_server">'.
1.110     raeburn  1061:                           '<option value=""'.$direct.'>'.$choices{'directlogin'}.
                   1062:                           '</option>';
1.184     raeburn  1063:             foreach my $hostid (sort(keys(%servers))) {
1.115     raeburn  1064:                 next if ($servers{$hostid} eq $servers{$lonhost});
1.110     raeburn  1065:                 my $selected = '';
1.128     raeburn  1066:                 if (ref($disallowed{$lonhost}) eq 'HASH') {
                   1067:                     if ($hostid eq $disallowed{$lonhost}{'server'}) {
                   1068:                         $selected = 'selected="selected"';
                   1069:                     }
1.110     raeburn  1070:                 }
                   1071:                 $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
                   1072:                               $servers{$hostid}.'</option>';
                   1073:             }
1.128     raeburn  1074:             $datatable .= '</select></td>'.
                   1075:                           '<td><select name="'.$lonhost.'_serverpath">';
                   1076:             foreach my $path ('','/','/adm/login','/adm/roles','custom') {
                   1077:                 my $pathname = $path;
                   1078:                 if ($path eq 'custom') {
                   1079:                     $pathname = &mt('Custom Path').' ->';
                   1080:                 }
                   1081:                 my $selected = '';
                   1082:                 if (ref($disallowed{$lonhost}) eq 'HASH') {
                   1083:                     if ($path eq $disallowed{$lonhost}{'serverpath'}) {
                   1084:                         $selected = 'selected="selected"';
                   1085:                     }
                   1086:                 } elsif ($path eq '') {
                   1087:                     $selected = 'selected="selected"';
                   1088:                 }
                   1089:                 $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
                   1090:             }
                   1091:             $datatable .= '</select></td>';
                   1092:             my ($custom,$exempt);
                   1093:             if (ref($disallowed{$lonhost}) eq 'HASH') {
                   1094:                 $custom = $disallowed{$lonhost}{'custompath'};
                   1095:                 $exempt = $disallowed{$lonhost}{'exempt'};
                   1096:             }
                   1097:             $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
                   1098:                           '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
                   1099:                           '</tr>';
1.110     raeburn  1100:         }
                   1101:         $datatable .= '</table></td></tr>';
                   1102:         return $datatable;
1.168     raeburn  1103:     } elsif ($caller eq 'page') {
                   1104:         my %defaultchecked = ( 
                   1105:                                'coursecatalog' => 'on',
1.188     raeburn  1106:                                'helpdesk'      => 'on',
1.168     raeburn  1107:                                'adminmail'     => 'off',
                   1108:                                'newuser'       => 'off',
                   1109:                              );
1.188     raeburn  1110:         my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.168     raeburn  1111:         my (%checkedon,%checkedoff);
1.42      raeburn  1112:         foreach my $item (@toggles) {
1.168     raeburn  1113:             if ($defaultchecked{$item} eq 'on') { 
                   1114:                 $checkedon{$item} = ' checked="checked" ';
1.42      raeburn  1115:                 $checkedoff{$item} = ' ';
1.168     raeburn  1116:             } elsif ($defaultchecked{$item} eq 'off') {
                   1117:                 $checkedoff{$item} = ' checked="checked" ';
1.42      raeburn  1118:                 $checkedon{$item} = ' ';
                   1119:             }
1.1       raeburn  1120:         }
1.168     raeburn  1121:         my @images = ('img','logo','domlogo','login');
                   1122:         my @logintext = ('textcol','bgcol');
                   1123:         my @bgs = ('pgbg','mainbg','sidebg');
                   1124:         my @links = ('link','alink','vlink');
                   1125:         my %designhash = &Apache::loncommon::get_domainconf($dom);
                   1126:         my %defaultdesign = %Apache::loncommon::defaultdesign;
                   1127:         my (%is_custom,%designs);
                   1128:         my %defaults = (
                   1129:                        font => $defaultdesign{'login.font'},
                   1130:                        );
1.6       raeburn  1131:         foreach my $item (@images) {
1.168     raeburn  1132:             $defaults{$item} = $defaultdesign{'login.'.$item};
                   1133:             $defaults{'showlogo'}{$item} = 1;
                   1134:         }
                   1135:         foreach my $item (@bgs) {
                   1136:             $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6       raeburn  1137:         }
1.41      raeburn  1138:         foreach my $item (@logintext) {
1.168     raeburn  1139:             $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41      raeburn  1140:         }
1.168     raeburn  1141:         foreach my $item (@links) {
                   1142:             $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6       raeburn  1143:         }
1.168     raeburn  1144:         if (ref($settings) eq 'HASH') {
                   1145:             foreach my $item (@toggles) {
                   1146:                 if ($settings->{$item} eq '1') {
                   1147:                     $checkedon{$item} =  ' checked="checked" ';
                   1148:                     $checkedoff{$item} = ' ';
                   1149:                 } elsif ($settings->{$item} eq '0') {
                   1150:                     $checkedoff{$item} =  ' checked="checked" ';
                   1151:                     $checkedon{$item} = ' ';
                   1152:                 }
                   1153:             }
                   1154:             foreach my $item (@images) {
                   1155:                 if (defined($settings->{$item})) {
                   1156:                     $designs{$item} = $settings->{$item};
                   1157:                     $is_custom{$item} = 1;
                   1158:                 }
                   1159:                 if (defined($settings->{'showlogo'}{$item})) {
                   1160:                     $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
                   1161:                 }
                   1162:             }
                   1163:             foreach my $item (@logintext) {
                   1164:                 if ($settings->{$item} ne '') {
                   1165:                     $designs{'logintext'}{$item} = $settings->{$item};
                   1166:                     $is_custom{$item} = 1;
                   1167:                 }
                   1168:             }
                   1169:             if ($settings->{'font'} ne '') {
                   1170:                 $designs{'font'} = $settings->{'font'};
                   1171:                 $is_custom{'font'} = 1;
                   1172:             }
                   1173:             foreach my $item (@bgs) {
                   1174:                 if ($settings->{$item} ne '') {
                   1175:                     $designs{'bgs'}{$item} = $settings->{$item};
                   1176:                     $is_custom{$item} = 1;
                   1177:                 }
                   1178:             }
                   1179:             foreach my $item (@links) {
                   1180:                 if ($settings->{$item} ne '') {
                   1181:                     $designs{'links'}{$item} = $settings->{$item};
                   1182:                     $is_custom{$item} = 1;
                   1183:                 }
                   1184:             }
                   1185:         } else {
                   1186:             if ($designhash{$dom.'.login.font'} ne '') {
                   1187:                 $designs{'font'} = $designhash{$dom.'.login.font'};
                   1188:                 $is_custom{'font'} = 1;
                   1189:             }
                   1190:             foreach my $item (@images) {
                   1191:                 if ($designhash{$dom.'.login.'.$item} ne '') {
                   1192:                     $designs{$item} = $designhash{$dom.'.login.'.$item};
                   1193:                     $is_custom{$item} = 1;
                   1194:                 }
                   1195:             }
                   1196:             foreach my $item (@bgs) {
                   1197:                 if ($designhash{$dom.'.login.'.$item} ne '') {
                   1198:                     $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
                   1199:                     $is_custom{$item} = 1;
                   1200:                 }
1.6       raeburn  1201:             }
1.168     raeburn  1202:             foreach my $item (@links) {
                   1203:                 if ($designhash{$dom.'.login.'.$item} ne '') {
                   1204:                     $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
                   1205:                     $is_custom{$item} = 1;
                   1206:                 }
1.6       raeburn  1207:             }
                   1208:         }
1.168     raeburn  1209:         my %alt_text = &Apache::lonlocal::texthash  ( img => 'Log-in banner',
                   1210:                                                       logo => 'Institution Logo',
                   1211:                                                       domlogo => 'Domain Logo',
                   1212:                                                       login => 'Login box');
                   1213:         my $itemcount = 1;
                   1214:         foreach my $item (@toggles) {
                   1215:             $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   1216:             $datatable .=  
                   1217:                 '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
                   1218:                 '</td><td>'.
                   1219:                 '<span class="LC_nobreak"><label><input type="radio" name="'.
                   1220:                 $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
                   1221:                 '</label>&nbsp;<label><input type="radio" name="'.$item.'"'.
                   1222:                 $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
                   1223:                 '</tr>';
                   1224:             $itemcount ++;
1.6       raeburn  1225:         }
1.168     raeburn  1226:         $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
                   1227:         $datatable .= '</tr></table></td></tr>';
                   1228:     } elsif ($caller eq 'help') {
                   1229:         my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
                   1230:         my $switchserver = &check_switchserver($dom,$confname);
                   1231:         my $itemcount = 1;
                   1232:         $defaulturl = '/adm/loginproblems.html';
                   1233:         $defaulttype = 'default';
                   1234:         %lt = &Apache::lonlocal::texthash (
                   1235:                      del     => 'Delete?',
                   1236:                      rep     => 'Replace:',
                   1237:                      upl     => 'Upload:',
                   1238:                      default => 'Default',
                   1239:                      custom  => 'Custom',
                   1240:                                              );
                   1241:         %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
                   1242:         my @currlangs;
                   1243:         if (ref($settings) eq 'HASH') {
                   1244:             if (ref($settings->{'helpurl'}) eq 'HASH') {
                   1245:                 foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
                   1246:                     next if ($settings->{'helpurl'}{$key} eq '');
                   1247:                     $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
                   1248:                     $type{$key} = 'custom';
                   1249:                     unless ($key eq 'nolang') {
                   1250:                         push(@currlangs,$key);
                   1251:                     }
                   1252:                 }
                   1253:             } elsif ($settings->{'helpurl'} ne '') {
                   1254:                 $type{'nolang'} = 'custom';
                   1255:                 $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8       raeburn  1256:             }
                   1257:         }
1.168     raeburn  1258:         foreach my $lang ('nolang',sort(@currlangs)) {
                   1259:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   1260:             $datatable .= '<tr'.$css_class.'>';
                   1261:             if ($url{$lang} eq '') {
                   1262:                 $url{$lang} = $defaulturl;
                   1263:             }
                   1264:             if ($type{$lang} eq '') {
                   1265:                 $type{$lang} = $defaulttype;
                   1266:             }
                   1267:             $datatable .= '<td colspan="2"><span class="LC_nobreak">';
                   1268:             if ($lang eq 'nolang') {
                   1269:                 $datatable .= &mt('Log-in help page if no specific language file: [_1]',
                   1270:                                   &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
                   1271:             } else {
                   1272:                 $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
                   1273:                                   $langchoices{$lang},
                   1274:                                   &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
                   1275:             }
                   1276:             $datatable .= '</span></td>'."\n".
                   1277:                           '<td class="LC_left_item">';
                   1278:             if ($type{$lang} eq 'custom') {
                   1279:                 $datatable .= '<span class="LC_nobreak"><label>'.
                   1280:                               '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
                   1281:                               $lt{'del'}.'</label>&nbsp;'.$lt{'rep'}.'</span>';
                   1282:             } else {
                   1283:                 $datatable .= $lt{'upl'};
                   1284:             }
                   1285:             $datatable .='<br />';
                   1286:             if ($switchserver) {
                   1287:                 $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   1288:             } else {
                   1289:                 $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6       raeburn  1290:             }
1.168     raeburn  1291:             $datatable .= '</td></tr>';
                   1292:             $itemcount ++;
1.6       raeburn  1293:         }
1.168     raeburn  1294:         my @addlangs;
                   1295:         foreach my $lang (sort(keys(%langchoices))) {
                   1296:             next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
                   1297:             push(@addlangs,$lang);
                   1298:         }
                   1299:         if (@addlangs > 0) {
                   1300:             my %toadd;
                   1301:             map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
                   1302:             $toadd{''} = &mt('Select');
                   1303:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   1304:             $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
                   1305:                           &mt('Add log-in help page for a specific language:').'&nbsp;'.
                   1306:                           &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
                   1307:                           '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
                   1308:             if ($switchserver) {
                   1309:                 $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   1310:             } else {
                   1311:                 $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6       raeburn  1312:             }
1.168     raeburn  1313:             $datatable .= '</td></tr>';
1.169     raeburn  1314:             $itemcount ++;
1.6       raeburn  1315:         }
1.169     raeburn  1316:         $datatable .= &captcha_choice('login',$settings,$itemcount);
1.256     raeburn  1317:     } elsif ($caller eq 'headtag') {
                   1318:         my %domservers = &Apache::lonnet::get_servers($dom);
                   1319:         my $choice = $choices{'headtag'};
                   1320:         $css_class = ' class="LC_odd_row"';
                   1321:         $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
                   1322:                       '<td align="left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
                   1323:                       '<th>'.$choices{'current'}.'</th>'.
                   1324:                       '<th>'.$choices{'action'}.'</th>'.
                   1325:                       '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
                   1326:         my (%currurls,%currexempt);
                   1327:         if (ref($settings) eq 'HASH') {
                   1328:             if (ref($settings->{'headtag'}) eq 'HASH') {
                   1329:                 foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
                   1330:                     if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
                   1331:                         $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
                   1332:                         $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
                   1333:                     }
                   1334:                 }
                   1335:             }
                   1336:         }
                   1337:         my %lt = &Apache::lonlocal::texthash(
                   1338:                                                del  => 'Delete?',
                   1339:                                                rep  => 'Replace:',
                   1340:                                                upl  => 'Upload:',
                   1341:                                                curr => 'View contents',
                   1342:                                                none => 'None',
                   1343:         );
                   1344:         my $switchserver = &check_switchserver($dom,$confname);
                   1345:         foreach my $lonhost (sort(keys(%domservers))) {
                   1346:             my $exempt = &check_exempt_addresses($currexempt{$lonhost});
                   1347:             $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
                   1348:             if ($currurls{$lonhost}) {
                   1349:                 $datatable .= '<td class="LC_right_item"><a href="'.
                   1350:                               "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
                   1351:                               'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
                   1352:                               '">'.$lt{'curr'}.'</a></td>'.
                   1353:                               '<td><span class="LC_nobreak"><label>'.
                   1354:                               '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
                   1355:                               $lt{'del'}.'</label>&nbsp;'.$lt{'rep'}.'</span>';
                   1356:             } else {
                   1357:                 $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
                   1358:             }
                   1359:             $datatable .='<br />';
                   1360:             if ($switchserver) {
                   1361:                 $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   1362:             } else {
                   1363:                 $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
                   1364:             }
                   1365:             $datatable .= '</td><td><input type="textbox" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
                   1366:         }
                   1367:         $datatable .= '</table></td></tr>';
1.1       raeburn  1368:     }
1.6       raeburn  1369:     return $datatable;
                   1370: }
                   1371: 
                   1372: sub login_choices {
                   1373:     my %choices =
                   1374:         &Apache::lonlocal::texthash (
1.116     bisitz   1375:             coursecatalog => 'Display Course/Community Catalog link?',
1.110     raeburn  1376:             adminmail     => "Display Administrator's E-mail Address?",
1.188     raeburn  1377:             helpdesk      => 'Display "Contact Helpdesk" link',
1.110     raeburn  1378:             disallowlogin => "Login page requests redirected",
                   1379:             hostid        => "Server",
1.128     raeburn  1380:             server        => "Redirect to:",
                   1381:             serverpath    => "Path",
                   1382:             custompath    => "Custom", 
                   1383:             exempt        => "Exempt IP(s)",
1.110     raeburn  1384:             directlogin   => "No redirect",
                   1385:             newuser       => "Link to create a user account",
                   1386:             img           => "Header",
                   1387:             logo          => "Main Logo",
                   1388:             domlogo       => "Domain Logo",
                   1389:             login         => "Log-in Header", 
                   1390:             textcol       => "Text color",
                   1391:             bgcol         => "Box color",
                   1392:             bgs           => "Background colors",
                   1393:             links         => "Link colors",
                   1394:             font          => "Font color",
                   1395:             pgbg          => "Header",
                   1396:             mainbg        => "Page",
                   1397:             sidebg        => "Login box",
                   1398:             link          => "Link",
                   1399:             alink         => "Active link",
                   1400:             vlink         => "Visited link",
1.256     raeburn  1401:             headtag       => "Custom markup",
                   1402:             action        => "Action",
                   1403:             current       => "Current",
1.6       raeburn  1404:         );
                   1405:     return %choices;
                   1406: }
                   1407: 
                   1408: sub print_rolecolors {
1.30      raeburn  1409:     my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6       raeburn  1410:     my %choices = &color_font_choices();
                   1411:     my @bgs = ('pgbg','tabbg','sidebg');
                   1412:     my @links = ('link','alink','vlink');
                   1413:     my @images = ('img');
                   1414:     my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7       albertel 1415:     my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6       raeburn  1416:     my %defaultdesign = %Apache::loncommon::defaultdesign;
                   1417:     my (%is_custom,%designs);
1.200     raeburn  1418:     my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6       raeburn  1419:     if (ref($settings) eq 'HASH') {
                   1420:         if (ref($settings->{$role}) eq 'HASH') {
                   1421:             if ($settings->{$role}->{'img'} ne '') {
                   1422:                 $designs{'img'} = $settings->{$role}->{'img'};
                   1423:                 $is_custom{'img'} = 1;
                   1424:             }
                   1425:             if ($settings->{$role}->{'font'} ne '') {
                   1426:                 $designs{'font'} = $settings->{$role}->{'font'};
                   1427:                 $is_custom{'font'} = 1;
                   1428:             }
1.97      tempelho 1429:             if ($settings->{$role}->{'fontmenu'} ne '') {
                   1430:                 $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
                   1431:                 $is_custom{'fontmenu'} = 1;
                   1432:             }
1.6       raeburn  1433:             foreach my $item (@bgs) {
                   1434:                 if ($settings->{$role}->{$item} ne '') {
                   1435:                     $designs{'bgs'}{$item} = $settings->{$role}->{$item};
                   1436:                     $is_custom{$item} = 1;
                   1437:                 }
                   1438:             }
                   1439:             foreach my $item (@links) {
                   1440:                 if ($settings->{$role}->{$item} ne '') {
                   1441:                     $designs{'links'}{$item} = $settings->{$role}->{$item};
                   1442:                     $is_custom{$item} = 1;
                   1443:                 }
                   1444:             }
                   1445:         }
                   1446:     } else {
                   1447:         if ($designhash{$dom.'.'.$role.'.img'} ne '') {
                   1448:             $designs{img} = $designhash{$dom.'.'.$role.'.img'};
                   1449:             $is_custom{'img'} = 1;
                   1450:         }
1.97      tempelho 1451:         if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
                   1452:             $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
                   1453:             $is_custom{'fontmenu'} = 1; 
                   1454:         }
1.6       raeburn  1455:         if ($designhash{$dom.'.'.$role.'.font'} ne '') {
                   1456:             $designs{font} = $designhash{$dom.'.'.$role.'.font'};
                   1457:             $is_custom{'font'} = 1;
                   1458:         }
                   1459:         foreach my $item (@bgs) {
                   1460:             if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
                   1461:                 $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
                   1462:                 $is_custom{$item} = 1;
                   1463:             
                   1464:             }
                   1465:         }
                   1466:         foreach my $item (@links) {
                   1467:             if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
                   1468:                 $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
                   1469:                 $is_custom{$item} = 1;
                   1470:             }
                   1471:         }
                   1472:     }
                   1473:     my $itemcount = 1;
1.30      raeburn  1474:     my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6       raeburn  1475:     $datatable .= '</tr></table></td></tr>';
                   1476:     return $datatable;
                   1477: }
                   1478: 
1.200     raeburn  1479: sub role_defaults {
                   1480:     my ($role,$bgs,$links,$images,$logintext) = @_;
1.202     raeburn  1481:     my %defaults;
                   1482:     unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1.200     raeburn  1483:         return %defaults;
                   1484:     }
                   1485:     my %defaultdesign = %Apache::loncommon::defaultdesign;
                   1486:     if ($role eq 'login') {
                   1487:         %defaults = (
                   1488:                        font => $defaultdesign{$role.'.font'},
                   1489:                     );
                   1490:         if (ref($logintext) eq 'ARRAY') {
                   1491:             foreach my $item (@{$logintext}) {
                   1492:                 $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
                   1493:             }
                   1494:         }
                   1495:         foreach my $item (@{$images}) {
                   1496:             $defaults{'showlogo'}{$item} = 1;
                   1497:         }
                   1498:     } else {
                   1499:         %defaults = (
                   1500:                        img => $defaultdesign{$role.'.img'},
                   1501:                        font => $defaultdesign{$role.'.font'},
                   1502:                        fontmenu => $defaultdesign{$role.'.fontmenu'},
                   1503:                     );
                   1504:     }
                   1505:     foreach my $item (@{$bgs}) {
                   1506:         $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
                   1507:     }
                   1508:     foreach my $item (@{$links}) {
                   1509:         $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
                   1510:     }
                   1511:     foreach my $item (@{$images}) {
                   1512:         $defaults{$item} = $defaultdesign{$role.'.'.$item};
                   1513:     }
                   1514:     return %defaults;
                   1515: }
                   1516: 
1.6       raeburn  1517: sub display_color_options {
1.9       raeburn  1518:     my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135     bisitz   1519:         $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159     raeburn  1520:     my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6       raeburn  1521:     my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.176     raeburn  1522:     my $datatable = '<tr'.$css_class.'>'.
1.6       raeburn  1523:         '<td>'.$choices->{'font'}.'</td>';
                   1524:     if (!$is_custom->{'font'}) {
1.30      raeburn  1525:         $datatable .=  '<td>'.&mt('Default in use:').'&nbsp;<span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6       raeburn  1526:     } else {
                   1527:         $datatable .= '<td>&nbsp;</td>';
                   1528:     }
1.174     foxr     1529:     my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
                   1530: 
1.8       raeburn  1531:     $datatable .= '<td><span class="LC_nobreak">'.
1.174     foxr     1532:                   '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1.202     raeburn  1533:                   ' value="'.$current_color.'" />&nbsp;'.
1.174     foxr     1534:                   '&nbsp;</td></tr>';
1.107     raeburn  1535:     unless ($role eq 'login') { 
                   1536:         $datatable .= '<tr'.$css_class.'>'.
                   1537:                       '<td>'.$choices->{'fontmenu'}.'</td>';
                   1538:         if (!$is_custom->{'fontmenu'}) {
                   1539:             $datatable .=  '<td>'.&mt('Default in use:').'&nbsp;<span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
                   1540:         } else {
                   1541:             $datatable .= '<td>&nbsp;</td>';
                   1542:         }
1.202     raeburn  1543: 	$current_color = $designs->{'fontmenu'} ?
1.174     foxr     1544: 	    $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107     raeburn  1545:         $datatable .= '<td><span class="LC_nobreak">'.
1.174     foxr     1546:                       '<input class="colorchooser" type="text" size="10" name="'
                   1547: 		      .$role.'_fontmenu"'.
                   1548:                       ' value="'.$current_color.'" />&nbsp;'.
                   1549:                       '&nbsp;</td></tr>';
1.97      tempelho 1550:     }
1.9       raeburn  1551:     my $switchserver = &check_switchserver($dom,$confname);
1.6       raeburn  1552:     foreach my $img (@{$images}) {
1.18      albertel 1553: 	$itemcount ++;
1.6       raeburn  1554:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8       raeburn  1555:         $datatable .= '<tr'.$css_class.'>'.
1.70      raeburn  1556:                       '<td>'.$choices->{$img};
1.41      raeburn  1557:         my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70      raeburn  1558:         if ($role eq 'login') {
                   1559:             if ($img eq 'login') {
                   1560:                 $login_hdr_pick =
1.135     bisitz   1561:                     &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70      raeburn  1562:                 $logincolors =
                   1563:                     &login_text_colors($img,$role,$logintext,$phase,$choices,
1.201     raeburn  1564:                                        $designs,$defaults);
1.70      raeburn  1565:             } elsif ($img ne 'domlogo') {
                   1566:                 $datatable.= &logo_display_options($img,$defaults,$designs);
                   1567:             }
                   1568:         }
                   1569:         $datatable .= '</td>';
1.6       raeburn  1570:         if ($designs->{$img} ne '') {
                   1571:             $imgfile = $designs->{$img};
1.18      albertel 1572: 	    $img_import = ($imgfile =~ m{^/adm/});
1.6       raeburn  1573:         } else {
                   1574:             $imgfile = $defaults->{$img};
                   1575:         }
                   1576:         if ($imgfile) {
1.9       raeburn  1577:             my ($showfile,$fullsize);
                   1578:             if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6       raeburn  1579:                 my $urldir = $1;
                   1580:                 my $filename = $2;
                   1581:                 my @info = &Apache::lonnet::stat_file($designs->{$img});
                   1582:                 if (@info) {
                   1583:                     my $thumbfile = 'tn-'.$filename;
                   1584:                     my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
                   1585:                     if (@thumb) {
                   1586:                         $showfile = $urldir.'/'.$thumbfile;
                   1587:                     } else {
                   1588:                         $showfile = $imgfile;
                   1589:                     }
                   1590:                 } else {
                   1591:                     $showfile = '';
                   1592:                 }
                   1593:             } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16      raeburn  1594:                 $showfile = $imgfile;
1.6       raeburn  1595:                 my $imgdir = $1;
                   1596:                 my $filename = $2;
1.159     raeburn  1597:                 if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6       raeburn  1598:                     $showfile = "/$imgdir/tn-".$filename;
                   1599:                 } else {
1.159     raeburn  1600:                     my $input = $londocroot.$imgfile;
                   1601:                     my $output = "$londocroot/$imgdir/tn-".$filename;
1.6       raeburn  1602:                     if (!-e $output) {
1.9       raeburn  1603:                         my ($width,$height) = &thumb_dimensions();
1.16      raeburn  1604:                         my ($fullwidth,$fullheight) = &check_dimensions($input);
                   1605:                         if ($fullwidth ne '' && $fullheight ne '') {
                   1606:                             if ($fullwidth > $width && $fullheight > $height) { 
                   1607:                                 my $size = $width.'x'.$height;
                   1608:                                 system("convert -sample $size $input $output");
1.159     raeburn  1609:                                 $showfile = "/$imgdir/tn-".$filename;
1.16      raeburn  1610:                             }
                   1611:                         }
1.6       raeburn  1612:                     }
                   1613:                 }
1.16      raeburn  1614:             }
1.6       raeburn  1615:             if ($showfile) {
1.40      raeburn  1616:                 if ($showfile =~ m{^/(adm|res)/}) {
                   1617:                     if ($showfile =~ m{^/res/}) {
                   1618:                         my $local_showfile =
                   1619:                             &Apache::lonnet::filelocation('',$showfile);
                   1620:                         &Apache::lonnet::repcopy($local_showfile);
                   1621:                     }
                   1622:                     $showfile = &Apache::loncommon::lonhttpdurl($showfile);
                   1623:                 }
                   1624:                 if ($imgfile) {
                   1625:                     if ($imgfile  =~ m{^/(adm|res)/}) {
                   1626:                         if ($imgfile =~ m{^/res/}) {
                   1627:                             my $local_imgfile =
                   1628:                                 &Apache::lonnet::filelocation('',$imgfile);
                   1629:                             &Apache::lonnet::repcopy($local_imgfile);
                   1630:                         }
                   1631:                         $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
                   1632:                     } else {
                   1633:                         $fullsize = $imgfile;
                   1634:                     }
                   1635:                 }
1.41      raeburn  1636:                 $datatable .= '<td>';
                   1637:                 if ($img eq 'login') {
1.135     bisitz   1638:                     $datatable .= $login_hdr_pick;
                   1639:                 } 
1.41      raeburn  1640:                 $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
                   1641:                                              $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6       raeburn  1642:             } else {
1.201     raeburn  1643:                 $datatable .= '<td>&nbsp;</td><td class="LC_left_item">'.
                   1644:                               &mt('Upload:').'<br />';
1.6       raeburn  1645:             }
                   1646:         } else {
1.201     raeburn  1647:             $datatable .= '<td>&nbsp;</td><td class="LC_left_item">'.
                   1648:                           &mt('Upload:').'<br />';
1.6       raeburn  1649:         }
1.9       raeburn  1650:         if ($switchserver) {
                   1651:             $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   1652:         } else {
1.135     bisitz   1653:             if ($img ne 'login') { # suppress file selection for Log-in header
                   1654:                 $datatable .='&nbsp;<input type="file" name="'.$role.'_'.$img.'" />';
                   1655:             }
1.9       raeburn  1656:         }
                   1657:         $datatable .= '</td></tr>';
1.6       raeburn  1658:     }
                   1659:     $itemcount ++;
                   1660:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   1661:     $datatable .= '<tr'.$css_class.'>'.
                   1662:                   '<td>'.$choices->{'bgs'}.'</td>';
                   1663:     my $bgs_def;
                   1664:     foreach my $item (@{$bgs}) {
                   1665:         if (!$is_custom->{$item}) {
1.70      raeburn  1666:             $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  1667:         }
                   1668:     }
                   1669:     if ($bgs_def) {
1.8       raeburn  1670:         $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6       raeburn  1671:     } else {
                   1672:         $datatable .= '<td>&nbsp;</td>';
                   1673:     }
                   1674:     $datatable .= '<td class="LC_right_item">'.
                   1675:                   '<table border="0"><tr>';
1.174     foxr     1676: 
1.6       raeburn  1677:     foreach my $item (@{$bgs}) {
1.201     raeburn  1678:         $datatable .= '<td align="center">'.$choices->{$item};
1.174     foxr     1679: 	my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6       raeburn  1680:         if ($designs->{'bgs'}{$item}) {
1.174     foxr     1681:             $datatable .= '&nbsp;';
1.6       raeburn  1682:         }
1.174     foxr     1683:         $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41      raeburn  1684:                       '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6       raeburn  1685:     }
                   1686:     $datatable .= '</tr></table></td></tr>';
                   1687:     $itemcount ++;
                   1688:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   1689:     $datatable .= '<tr'.$css_class.'>'.
                   1690:                   '<td>'.$choices->{'links'}.'</td>';
                   1691:     my $links_def;
                   1692:     foreach my $item (@{$links}) {
                   1693:         if (!$is_custom->{$item}) {
1.30      raeburn  1694:             $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  1695:         }
                   1696:     }
                   1697:     if ($links_def) {
1.8       raeburn  1698:         $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6       raeburn  1699:     } else {
                   1700:         $datatable .= '<td>&nbsp;</td>';
                   1701:     }
                   1702:     $datatable .= '<td class="LC_right_item">'.
                   1703:                   '<table border="0"><tr>';
                   1704:     foreach my $item (@{$links}) {
1.234     raeburn  1705: 	my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.201     raeburn  1706:         $datatable .= '<td align="center">'.$choices->{$item}."\n";
1.6       raeburn  1707:         if ($designs->{'links'}{$item}) {
1.174     foxr     1708:             $datatable.='&nbsp;';
1.6       raeburn  1709:         }
1.174     foxr     1710:         $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6       raeburn  1711:                       '" /></td>';
                   1712:     }
1.30      raeburn  1713:     $$rowtotal += $itemcount;
1.3       raeburn  1714:     return $datatable;
                   1715: }
                   1716: 
1.70      raeburn  1717: sub logo_display_options {
                   1718:     my ($img,$defaults,$designs) = @_;
                   1719:     my $checkedon;
                   1720:     if (ref($defaults) eq 'HASH') {
                   1721:         if (ref($defaults->{'showlogo'}) eq 'HASH') {
                   1722:             if ($defaults->{'showlogo'}{$img}) {
                   1723:                 $checkedon = 'checked="checked" ';     
                   1724:             }
                   1725:         } 
                   1726:     }
                   1727:     if (ref($designs) eq 'HASH') {
                   1728:         if (ref($designs->{'showlogo'}) eq 'HASH') {
                   1729:             if (defined($designs->{'showlogo'}{$img})) {
                   1730:                 if ($designs->{'showlogo'}{$img} == 0) {
                   1731:                     $checkedon = '';
                   1732:                 } elsif ($designs->{'showlogo'}{$img} == 1) {
                   1733:                     $checkedon = 'checked="checked" ';
                   1734:                 }
                   1735:             }
                   1736:         }
                   1737:     }
                   1738:     return '<br /><label>&nbsp;&nbsp;<input type="checkbox" name="'.
                   1739:            'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
                   1740:            &mt('show').'</label>'."\n";
                   1741: }
                   1742: 
1.41      raeburn  1743: sub login_header_options  {
1.135     bisitz   1744:     my ($img,$role,$defaults,$is_custom,$choices) = @_;
                   1745:     my $output = '';
1.41      raeburn  1746:     if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135     bisitz   1747:         $output .= &mt('Text default(s):').'<br />';
1.41      raeburn  1748:         if (!$is_custom->{'textcol'}) {
                   1749:             $output .= $choices->{'textcol'}.':&nbsp;'.$defaults->{'logintext'}{'textcol'}.
                   1750:                        '&nbsp;&nbsp;&nbsp;';
                   1751:         }
                   1752:         if (!$is_custom->{'bgcol'}) {
                   1753:             $output .= $choices->{'bgcol'}.':&nbsp;'.
                   1754:                        '<span id="css_'.$role.'_font" style="background-color: '.
                   1755:                        $defaults->{'logintext'}{'bgcol'}.';">&nbsp;&nbsp;&nbsp;</span>';
                   1756:         }
                   1757:         $output .= '<br />';
                   1758:     }
                   1759:     $output .='<br />';
                   1760:     return $output;
                   1761: }
                   1762: 
                   1763: sub login_text_colors {
1.201     raeburn  1764:     my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41      raeburn  1765:     my $color_menu = '<table border="0"><tr>';
                   1766:     foreach my $item (@{$logintext}) {
1.201     raeburn  1767:         $color_menu .= '<td align="center">'.$choices->{$item};
                   1768:         my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
                   1769:         $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
                   1770:                       '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41      raeburn  1771:     }
                   1772:     $color_menu .= '</tr></table><br />';
                   1773:     return $color_menu;
                   1774: }
                   1775: 
                   1776: sub image_changes {
                   1777:     my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
                   1778:     my $output;
1.135     bisitz   1779:     if ($img eq 'login') {
                   1780:             # suppress image for Log-in header
                   1781:     } elsif (!$is_custom) {
1.70      raeburn  1782:         if ($img ne 'domlogo') {
1.41      raeburn  1783:             $output .= &mt('Default image:').'<br />';
                   1784:         } else {
                   1785:             $output .= &mt('Default in use:').'<br />';
                   1786:         }
                   1787:     }
1.135     bisitz   1788:     if ($img eq 'login') { # suppress image for Log-in header
                   1789:         $output .= '<td>'.$logincolors;
1.41      raeburn  1790:     } else {
1.135     bisitz   1791:         if ($img_import) {
                   1792:             $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
                   1793:         }
                   1794:         $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
                   1795:                    $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
                   1796:         if ($is_custom) {
                   1797:             $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
                   1798:                        '<input type="checkbox" name="'.
                   1799:                        $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
                   1800:                        '</label>&nbsp;'.&mt('Replace:').'</span><br />';
                   1801:         } else {
1.201     raeburn  1802:             $output .= '<td valign="middle">'.$logincolors.&mt('Upload:').'<br />';
1.135     bisitz   1803:         }
1.41      raeburn  1804:     }
                   1805:     return $output;
                   1806: }
                   1807: 
1.3       raeburn  1808: sub print_quotas {
1.86      raeburn  1809:     my ($dom,$settings,$rowtotal,$action) = @_;
                   1810:     my $context;
                   1811:     if ($action eq 'quotas') {
                   1812:         $context = 'tools';
                   1813:     } else {
                   1814:         $context = $action;
                   1815:     }
1.197     raeburn  1816:     my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44      raeburn  1817:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3       raeburn  1818:     my $typecount = 0;
1.101     raeburn  1819:     my ($css_class,%titles);
1.86      raeburn  1820:     if ($context eq 'requestcourses') {
1.271     raeburn  1821:         @usertools = ('official','unofficial','community','textbook','placement');
1.106     raeburn  1822:         @options =('norequest','approval','validate','autolimit');
1.101     raeburn  1823:         %validations = &Apache::lonnet::auto_courserequest_checks($dom);
                   1824:         %titles = &courserequest_titles();
1.163     raeburn  1825:     } elsif ($context eq 'requestauthor') {
                   1826:         @usertools = ('author');
                   1827:         @options = ('norequest','approval','automatic');
1.210     raeburn  1828:         %titles = &authorrequest_titles();
1.86      raeburn  1829:     } else {
1.162     raeburn  1830:         @usertools = ('aboutme','blog','webdav','portfolio');
1.101     raeburn  1831:         %titles = &tool_titles();
1.86      raeburn  1832:     }
1.26      raeburn  1833:     if (ref($types) eq 'ARRAY') {
1.23      raeburn  1834:         foreach my $type (@{$types}) {
1.197     raeburn  1835:             my ($currdefquota,$currauthorquota);
1.163     raeburn  1836:             unless (($context eq 'requestcourses') ||
                   1837:                     ($context eq 'requestauthor')) {
1.86      raeburn  1838:                 if (ref($settings) eq 'HASH') {
                   1839:                     if (ref($settings->{defaultquota}) eq 'HASH') {
1.197     raeburn  1840:                         $currdefquota = $settings->{defaultquota}->{$type};
1.86      raeburn  1841:                     } else {
                   1842:                         $currdefquota = $settings->{$type};
                   1843:                     }
1.197     raeburn  1844:                     if (ref($settings->{authorquota}) eq 'HASH') {
                   1845:                         $currauthorquota = $settings->{authorquota}->{$type};
                   1846:                     }
1.78      raeburn  1847:                 }
1.72      raeburn  1848:             }
1.3       raeburn  1849:             if (defined($usertypes->{$type})) {
                   1850:                 $typecount ++;
                   1851:                 $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72      raeburn  1852:                 $datatable .= '<tr'.$css_class.'>'.
1.3       raeburn  1853:                               '<td>'.$usertypes->{$type}.'</td>'.
1.72      raeburn  1854:                               '<td class="LC_left_item">';
1.101     raeburn  1855:                 if ($context eq 'requestcourses') {
                   1856:                     $datatable .= '<table><tr>';
                   1857:                 }
                   1858:                 my %cell;  
1.72      raeburn  1859:                 foreach my $item (@usertools) {
1.101     raeburn  1860:                     if ($context eq 'requestcourses') {
                   1861:                         my ($curroption,$currlimit);
                   1862:                         if (ref($settings) eq 'HASH') {
                   1863:                             if (ref($settings->{$item}) eq 'HASH') {
                   1864:                                 $curroption = $settings->{$item}->{$type};
                   1865:                                 if ($curroption =~ /^autolimit=(\d*)$/) {
                   1866:                                     $currlimit = $1; 
                   1867:                                 }
                   1868:                             }
                   1869:                         }
                   1870:                         if (!$curroption) {
                   1871:                             $curroption = 'norequest';
                   1872:                         }
                   1873:                         $datatable .= '<th>'.$titles{$item}.'</th>';
                   1874:                         foreach my $option (@options) {
                   1875:                             my $val = $option;
                   1876:                             if ($option eq 'norequest') {
                   1877:                                 $val = 0;  
                   1878:                             }
                   1879:                             if ($option eq 'validate') {
                   1880:                                 my $canvalidate = 0;
                   1881:                                 if (ref($validations{$item}) eq 'HASH') { 
                   1882:                                     if ($validations{$item}{$type}) {
                   1883:                                         $canvalidate = 1;
                   1884:                                     }
                   1885:                                 }
                   1886:                                 next if (!$canvalidate);
                   1887:                             }
                   1888:                             my $checked = '';
                   1889:                             if ($option eq $curroption) {
                   1890:                                 $checked = ' checked="checked"';
                   1891:                             } elsif ($option eq 'autolimit') {
                   1892:                                 if ($curroption =~ /^autolimit/) {
                   1893:                                     $checked = ' checked="checked"';
                   1894:                                 }                       
                   1895:                             } 
                   1896:                             $cell{$item} .= '<span class="LC_nobreak"><label>'.
                   1897:                                   '<input type="radio" name="crsreq_'.$item.
                   1898:                                   '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127     raeburn  1899:                                   $titles{$option}.'</label>';
1.101     raeburn  1900:                             if ($option eq 'autolimit') {
1.127     raeburn  1901:                                 $cell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
1.101     raeburn  1902:                                                 $item.'_limit_'.$type.'" size="1" '.
1.103     raeburn  1903:                                                 'value="'.$currlimit.'" />';
1.101     raeburn  1904:                             }
1.127     raeburn  1905:                             $cell{$item} .= '</span> ';
1.103     raeburn  1906:                             if ($option eq 'autolimit') {
1.127     raeburn  1907:                                 $cell{$item} .= $titles{'unlimited'};
1.103     raeburn  1908:                             }
1.101     raeburn  1909:                         }
1.163     raeburn  1910:                     } elsif ($context eq 'requestauthor') {
                   1911:                         my $curroption;
                   1912:                         if (ref($settings) eq 'HASH') {
                   1913:                             $curroption = $settings->{$type};
                   1914:                         }
                   1915:                         if (!$curroption) {
                   1916:                             $curroption = 'norequest';
                   1917:                         }
                   1918:                         foreach my $option (@options) {
                   1919:                             my $val = $option;
                   1920:                             if ($option eq 'norequest') {
                   1921:                                 $val = 0;
                   1922:                             }
                   1923:                             my $checked = '';
                   1924:                             if ($option eq $curroption) {
                   1925:                                 $checked = ' checked="checked"';
                   1926:                             }
                   1927:                             $datatable .= '<span class="LC_nobreak"><label>'.
                   1928:                                   '<input type="radio" name="authorreq_'.$type.
                   1929:                                   '" value="'.$val.'"'.$checked.' />'.
                   1930:                                   $titles{$option}.'</label></span>&nbsp; ';
                   1931:                         }
1.101     raeburn  1932:                     } else {
                   1933:                         my $checked = 'checked="checked" ';
                   1934:                         if (ref($settings) eq 'HASH') {
                   1935:                             if (ref($settings->{$item}) eq 'HASH') {
                   1936:                                 if ($settings->{$item}->{$type} == 0) {
                   1937:                                     $checked = '';
                   1938:                                 } elsif ($settings->{$item}->{$type} == 1) {
                   1939:                                     $checked =  'checked="checked" ';
                   1940:                                 }
1.78      raeburn  1941:                             }
1.72      raeburn  1942:                         }
1.101     raeburn  1943:                         $datatable .= '<span class="LC_nobreak"><label>'.
                   1944:                                       '<input type="checkbox" name="'.$context.'_'.$item.
                   1945:                                       '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
                   1946:                                       '</label></span>&nbsp; ';
1.72      raeburn  1947:                     }
1.101     raeburn  1948:                 }
                   1949:                 if ($context eq 'requestcourses') {
                   1950:                     $datatable .= '</tr><tr>';
                   1951:                     foreach my $item (@usertools) {
1.106     raeburn  1952:                         $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';  
1.101     raeburn  1953:                     }
                   1954:                     $datatable .= '</tr></table>';
1.72      raeburn  1955:                 }
1.86      raeburn  1956:                 $datatable .= '</td>';
1.163     raeburn  1957:                 unless (($context eq 'requestcourses') ||
                   1958:                         ($context eq 'requestauthor')) {
1.86      raeburn  1959:                     $datatable .= 
1.197     raeburn  1960:                               '<td class="LC_right_item">'.
                   1961:                               '<span class="LC_nobreak">'.&mt('Portfolio').':&nbsp;'.
1.3       raeburn  1962:                               '<input type="text" name="quota_'.$type.
1.72      raeburn  1963:                               '" value="'.$currdefquota.
1.197     raeburn  1964:                               '" size="5" /></span>'.('&nbsp;' x 2).
                   1965:                               '<span class="LC_nobreak">'.&mt('Authoring').':&nbsp;'.
                   1966:                               '<input type="text" name="authorquota_'.$type.
                   1967:                               '" value="'.$currauthorquota.
                   1968:                               '" size="5" /></span></td>';
1.86      raeburn  1969:                 }
                   1970:                 $datatable .= '</tr>';
1.3       raeburn  1971:             }
                   1972:         }
                   1973:     }
1.163     raeburn  1974:     unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86      raeburn  1975:         $defaultquota = '20';
1.197     raeburn  1976:         $authorquota = '500';
1.86      raeburn  1977:         if (ref($settings) eq 'HASH') {
                   1978:             if (ref($settings->{'defaultquota'}) eq 'HASH') {
                   1979:                 $defaultquota = $settings->{'defaultquota'}->{'default'};
                   1980:             } elsif (defined($settings->{'default'})) {
                   1981:                 $defaultquota = $settings->{'default'};
                   1982:             }
1.197     raeburn  1983:             if (ref($settings->{'authorquota'}) eq 'HASH') {
                   1984:                 $authorquota = $settings->{'authorquota'}->{'default'};
                   1985:             }
1.3       raeburn  1986:         }
                   1987:     }
                   1988:     $typecount ++;
                   1989:     $css_class = $typecount%2?' class="LC_odd_row"':'';
                   1990:     $datatable .= '<tr'.$css_class.'>'.
1.26      raeburn  1991:                   '<td>'.$othertitle.'</td>'.
1.72      raeburn  1992:                   '<td class="LC_left_item">';
1.101     raeburn  1993:     if ($context eq 'requestcourses') {
                   1994:         $datatable .= '<table><tr>';
                   1995:     }
                   1996:     my %defcell;
1.72      raeburn  1997:     foreach my $item (@usertools) {
1.101     raeburn  1998:         if ($context eq 'requestcourses') {
                   1999:             my ($curroption,$currlimit);
                   2000:             if (ref($settings) eq 'HASH') {
                   2001:                 if (ref($settings->{$item}) eq 'HASH') {
                   2002:                     $curroption = $settings->{$item}->{'default'};
                   2003:                     if ($curroption =~ /^autolimit=(\d*)$/) {
                   2004:                         $currlimit = $1;
                   2005:                     }
                   2006:                 }
                   2007:             }
                   2008:             if (!$curroption) {
                   2009:                 $curroption = 'norequest';
                   2010:             }
                   2011:             $datatable .= '<th>'.$titles{$item}.'</th>';
                   2012:             foreach my $option (@options) {
                   2013:                 my $val = $option;
                   2014:                 if ($option eq 'norequest') {
                   2015:                     $val = 0;
                   2016:                 }
                   2017:                 if ($option eq 'validate') {
                   2018:                     my $canvalidate = 0;
                   2019:                     if (ref($validations{$item}) eq 'HASH') {
                   2020:                         if ($validations{$item}{'default'}) {
                   2021:                             $canvalidate = 1;
                   2022:                         }
                   2023:                     }
                   2024:                     next if (!$canvalidate);
                   2025:                 }
                   2026:                 my $checked = '';
                   2027:                 if ($option eq $curroption) {
                   2028:                     $checked = ' checked="checked"';
                   2029:                 } elsif ($option eq 'autolimit') {
                   2030:                     if ($curroption =~ /^autolimit/) {
                   2031:                         $checked = ' checked="checked"';
                   2032:                     }
                   2033:                 }
                   2034:                 $defcell{$item} .= '<span class="LC_nobreak"><label>'.
                   2035:                                   '<input type="radio" name="crsreq_'.$item.
                   2036:                                   '_default" value="'.$val.'"'.$checked.' />'.
                   2037:                                   $titles{$option}.'</label>';
                   2038:                 if ($option eq 'autolimit') {
1.127     raeburn  2039:                     $defcell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
1.101     raeburn  2040:                                        $item.'_limit_default" size="1" '.
                   2041:                                        'value="'.$currlimit.'" />';
                   2042:                 }
1.127     raeburn  2043:                 $defcell{$item} .= '</span> ';
1.104     raeburn  2044:                 if ($option eq 'autolimit') {
1.127     raeburn  2045:                     $defcell{$item} .= $titles{'unlimited'};
1.104     raeburn  2046:                 }
1.101     raeburn  2047:             }
1.163     raeburn  2048:         } elsif ($context eq 'requestauthor') {
                   2049:             my $curroption;
                   2050:             if (ref($settings) eq 'HASH') {
1.172     raeburn  2051:                 $curroption = $settings->{'default'};
1.163     raeburn  2052:             }
                   2053:             if (!$curroption) {
                   2054:                 $curroption = 'norequest';
                   2055:             }
                   2056:             foreach my $option (@options) {
                   2057:                 my $val = $option;
                   2058:                 if ($option eq 'norequest') {
                   2059:                     $val = 0;
                   2060:                 }
                   2061:                 my $checked = '';
                   2062:                 if ($option eq $curroption) {
                   2063:                     $checked = ' checked="checked"';
                   2064:                 }
                   2065:                 $datatable .= '<span class="LC_nobreak"><label>'.
                   2066:                               '<input type="radio" name="authorreq_default"'.
                   2067:                               ' value="'.$val.'"'.$checked.' />'.
                   2068:                               $titles{$option}.'</label></span>&nbsp; ';
                   2069:             }
1.101     raeburn  2070:         } else {
                   2071:             my $checked = 'checked="checked" ';
                   2072:             if (ref($settings) eq 'HASH') {
                   2073:                 if (ref($settings->{$item}) eq 'HASH') {
                   2074:                     if ($settings->{$item}->{'default'} == 0) {
                   2075:                         $checked = '';
                   2076:                     } elsif ($settings->{$item}->{'default'} == 1) {
                   2077:                         $checked = 'checked="checked" ';
                   2078:                     }
1.78      raeburn  2079:                 }
1.72      raeburn  2080:             }
1.101     raeburn  2081:             $datatable .= '<span class="LC_nobreak"><label>'.
                   2082:                           '<input type="checkbox" name="'.$context.'_'.$item.
                   2083:                           '" value="default" '.$checked.'/>'.$titles{$item}.
                   2084:                           '</label></span>&nbsp; ';
                   2085:         }
                   2086:     }
                   2087:     if ($context eq 'requestcourses') {
                   2088:         $datatable .= '</tr><tr>';
                   2089:         foreach my $item (@usertools) {
1.106     raeburn  2090:             $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72      raeburn  2091:         }
1.101     raeburn  2092:         $datatable .= '</tr></table>';
1.72      raeburn  2093:     }
1.86      raeburn  2094:     $datatable .= '</td>';
1.163     raeburn  2095:     unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.197     raeburn  2096:         $datatable .= '<td class="LC_right_item">'.
                   2097:                       '<span class="LC_nobreak">'.&mt('Portfolio').':&nbsp;'.
1.86      raeburn  2098:                       '<input type="text" name="defaultquota" value="'.
1.197     raeburn  2099:                       $defaultquota.'" size="5" /></span>'.('&nbsp;' x2).
                   2100:                       '<span class="LC_nobreak">'.&mt('Authoring').':&nbsp;'.
                   2101:                       '<input type="text" name="authorquota" value="'.
                   2102:                       $authorquota.'" size="5" /></span></td>';
1.86      raeburn  2103:     }
                   2104:     $datatable .= '</tr>';
1.72      raeburn  2105:     $typecount ++;
                   2106:     $css_class = $typecount%2?' class="LC_odd_row"':'';
                   2107:     $datatable .= '<tr'.$css_class.'>'.
1.197     raeburn  2108:                   '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104     raeburn  2109:     if ($context eq 'requestcourses') {
1.109     raeburn  2110:         $datatable .= &mt('(overrides affiliation, if set)').
                   2111:                       '</td>'.
                   2112:                       '<td class="LC_left_item">'.
                   2113:                       '<table><tr>';
1.101     raeburn  2114:     } else {
1.109     raeburn  2115:         $datatable .= &mt('(overrides affiliation, if checked)').
                   2116:                       '</td>'.
                   2117:                       '<td class="LC_left_item" colspan="2">'.
                   2118:                       '<br />';
1.101     raeburn  2119:     }
                   2120:     my %advcell;
1.72      raeburn  2121:     foreach my $item (@usertools) {
1.101     raeburn  2122:         if ($context eq 'requestcourses') {
                   2123:             my ($curroption,$currlimit);
                   2124:             if (ref($settings) eq 'HASH') {
                   2125:                 if (ref($settings->{$item}) eq 'HASH') {
                   2126:                     $curroption = $settings->{$item}->{'_LC_adv'};
                   2127:                     if ($curroption =~ /^autolimit=(\d*)$/) {
                   2128:                         $currlimit = $1;
                   2129:                     }
                   2130:                 }
                   2131:             }
                   2132:             $datatable .= '<th>'.$titles{$item}.'</th>';
1.104     raeburn  2133:             my $checked = '';
                   2134:             if ($curroption eq '') {
                   2135:                 $checked = ' checked="checked"';
                   2136:             }
                   2137:             $advcell{$item} .= '<span class="LC_nobreak"><label>'.
                   2138:                                '<input type="radio" name="crsreq_'.$item.
                   2139:                                '__LC_adv" value=""'.$checked.' />'.
                   2140:                                &mt('No override set').'</label></span>&nbsp; ';
1.101     raeburn  2141:             foreach my $option (@options) {
                   2142:                 my $val = $option;
                   2143:                 if ($option eq 'norequest') {
                   2144:                     $val = 0;
                   2145:                 }
                   2146:                 if ($option eq 'validate') {
                   2147:                     my $canvalidate = 0;
                   2148:                     if (ref($validations{$item}) eq 'HASH') {
                   2149:                         if ($validations{$item}{'_LC_adv'}) {
                   2150:                             $canvalidate = 1;
                   2151:                         }
                   2152:                     }
                   2153:                     next if (!$canvalidate);
                   2154:                 }
                   2155:                 my $checked = '';
1.104     raeburn  2156:                 if ($val eq $curroption) {
1.101     raeburn  2157:                     $checked = ' checked="checked"';
                   2158:                 } elsif ($option eq 'autolimit') {
                   2159:                     if ($curroption =~ /^autolimit/) {
                   2160:                         $checked = ' checked="checked"';
                   2161:                     }
                   2162:                 }
                   2163:                 $advcell{$item} .= '<span class="LC_nobreak"><label>'.
                   2164:                                   '<input type="radio" name="crsreq_'.$item.
                   2165:                                   '__LC_adv" value="'.$val.'"'.$checked.' />'.
                   2166:                                   $titles{$option}.'</label>';
                   2167:                 if ($option eq 'autolimit') {
1.127     raeburn  2168:                     $advcell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
1.101     raeburn  2169:                                        $item.'_limit__LC_adv" size="1" '.
                   2170:                                        'value="'.$currlimit.'" />';
                   2171:                 }
1.127     raeburn  2172:                 $advcell{$item} .= '</span> ';
1.104     raeburn  2173:                 if ($option eq 'autolimit') {
1.127     raeburn  2174:                     $advcell{$item} .= $titles{'unlimited'};
1.104     raeburn  2175:                 }
1.101     raeburn  2176:             }
1.163     raeburn  2177:         } elsif ($context eq 'requestauthor') {
                   2178:             my $curroption;
                   2179:             if (ref($settings) eq 'HASH') {
                   2180:                 $curroption = $settings->{'_LC_adv'};
                   2181:             }
                   2182:             my $checked = '';
                   2183:             if ($curroption eq '') {
                   2184:                 $checked = ' checked="checked"';
                   2185:             }
                   2186:             $datatable .= '<span class="LC_nobreak"><label>'.
                   2187:                           '<input type="radio" name="authorreq__LC_adv"'.
                   2188:                           ' value=""'.$checked.' />'.
                   2189:                           &mt('No override set').'</label></span>&nbsp; ';
                   2190:             foreach my $option (@options) {
                   2191:                 my $val = $option;
                   2192:                 if ($option eq 'norequest') {
                   2193:                     $val = 0;
                   2194:                 }
                   2195:                 my $checked = '';
                   2196:                 if ($val eq $curroption) {
                   2197:                     $checked = ' checked="checked"';
                   2198:                 }
                   2199:                 $datatable .= '<span class="LC_nobreak"><label>'.
1.173     raeburn  2200:                               '<input type="radio" name="authorreq__LC_adv"'.
                   2201:                               ' value="'.$val.'"'.$checked.' />'.
1.163     raeburn  2202:                               $titles{$option}.'</label></span>&nbsp; ';
                   2203:             }
1.101     raeburn  2204:         } else {
                   2205:             my $checked = 'checked="checked" ';
                   2206:             if (ref($settings) eq 'HASH') {
                   2207:                 if (ref($settings->{$item}) eq 'HASH') {
                   2208:                     if ($settings->{$item}->{'_LC_adv'} == 0) {
                   2209:                         $checked = '';
                   2210:                     } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
                   2211:                         $checked = 'checked="checked" ';
                   2212:                     }
1.79      raeburn  2213:                 }
1.72      raeburn  2214:             }
1.101     raeburn  2215:             $datatable .= '<span class="LC_nobreak"><label>'.
                   2216:                           '<input type="checkbox" name="'.$context.'_'.$item.
                   2217:                           '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
                   2218:                           '</label></span>&nbsp; ';
                   2219:         }
                   2220:     }
                   2221:     if ($context eq 'requestcourses') {
                   2222:         $datatable .= '</tr><tr>';
                   2223:         foreach my $item (@usertools) {
1.106     raeburn  2224:             $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72      raeburn  2225:         }
1.101     raeburn  2226:         $datatable .= '</tr></table>';
1.72      raeburn  2227:     }
1.98      raeburn  2228:     $datatable .= '</td></tr>';
1.30      raeburn  2229:     $$rowtotal += $typecount;
1.3       raeburn  2230:     return $datatable;
                   2231: }
                   2232: 
1.163     raeburn  2233: sub print_requestmail {
                   2234:     my ($dom,$action,$settings,$rowtotal) = @_;
1.208     raeburn  2235:     my ($now,$datatable,%currapp);
1.102     raeburn  2236:     $now = time;
                   2237:     if (ref($settings) eq 'HASH') {
                   2238:         if (ref($settings->{'notify'}) eq 'HASH') {
                   2239:             if ($settings->{'notify'}{'approval'} ne '') {
1.224     raeburn  2240:                 map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102     raeburn  2241:             }
                   2242:         }
                   2243:     }
1.191     raeburn  2244:     my $numinrow = 2;
1.224     raeburn  2245:     my $css_class;
                   2246:     $css_class = ($$rowtotal%2? ' class="LC_odd_row"':'');
1.163     raeburn  2247:     my $text;
                   2248:     if ($action eq 'requestcourses') {
                   2249:         $text = &mt('Receive notification of course requests requiring approval');
1.224     raeburn  2250:     } elsif ($action eq 'requestauthor') {
                   2251:         $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.163     raeburn  2252:     } else {
1.224     raeburn  2253:        $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.163     raeburn  2254:     }
1.224     raeburn  2255:     $datatable = '<tr'.$css_class.'>'.
1.163     raeburn  2256:                  ' <td>'.$text.'</td>'.
1.102     raeburn  2257:                  ' <td class="LC_left_item">';
1.191     raeburn  2258:     my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.224     raeburn  2259:                                                  $action.'notifyapproval',%currapp);
1.191     raeburn  2260:     if ($numdc > 0) {
                   2261:         $datatable .= $table;
1.102     raeburn  2262:     } else {
                   2263:         $datatable .= &mt('There are no active Domain Coordinators');
                   2264:     }
                   2265:     $datatable .='</td></tr>';
                   2266:     return $datatable;
                   2267: }
                   2268: 
1.216     raeburn  2269: sub print_studentcode {
                   2270:     my ($settings,$rowtotal) = @_;
                   2271:     my $rownum = 0; 
1.218     raeburn  2272:     my ($output,%current);
1.271     raeburn  2273:     my @crstypes = ('official','unofficial','community','textbook','placement');
1.248     raeburn  2274:     if (ref($settings) eq 'HASH') {
                   2275:         if (ref($settings->{'uniquecode'}) eq 'HASH') {
                   2276:             foreach my $type (@crstypes) {
                   2277:                 $current{$type} = $settings->{'uniquecode'}{$type};
                   2278:             }
1.218     raeburn  2279:         }
                   2280:     }
                   2281:     $output .= '<tr>'.
                   2282:                '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
                   2283:                '<td class="LC_left_item">';
                   2284:     foreach my $type (@crstypes) {
                   2285:         my $check = ' ';
                   2286:         if ($current{$type}) {
                   2287:             $check = ' checked="checked" ';
                   2288:         }
                   2289:         $output .= '<span class="LC_nobreak"><label>'.
                   2290:                    '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
                   2291:                    &mt($type).'</label></span>'.('&nbsp;'x2).' ';
                   2292:     }
                   2293:     $output .= '</td></tr>';
                   2294:     $$rowtotal ++;
                   2295:     return $output;
1.216     raeburn  2296: }
                   2297: 
                   2298: sub print_textbookcourses {
1.242     raeburn  2299:     my ($dom,$type,$settings,$rowtotal) = @_;
1.216     raeburn  2300:     my $rownum = 0;
                   2301:     my $css_class;
                   2302:     my $itemcount = 1;
                   2303:     my $maxnum = 0;
                   2304:     my $bookshash;
                   2305:     if (ref($settings) eq 'HASH') {
1.242     raeburn  2306:         $bookshash = $settings->{$type};
1.216     raeburn  2307:     }
                   2308:     my %ordered;
                   2309:     if (ref($bookshash) eq 'HASH') {
                   2310:         foreach my $item (keys(%{$bookshash})) {
                   2311:             if (ref($bookshash->{$item}) eq 'HASH') {
                   2312:                 my $num = $bookshash->{$item}{'order'};
                   2313:                 $ordered{$num} = $item;
                   2314:             }
                   2315:         }
                   2316:     }
                   2317:     my $confname = $dom.'-domainconfig';
                   2318:     my $switchserver = &check_switchserver($dom,$confname);
1.242     raeburn  2319:     my $maxnum = scalar(keys(%ordered));
                   2320:     my $datatable;
1.216     raeburn  2321:     if (keys(%ordered)) {
                   2322:         my @items = sort { $a <=> $b } keys(%ordered);
                   2323:         for (my $i=0; $i<@items; $i++) {
                   2324:             $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   2325:             my $key = $ordered{$items[$i]};
                   2326:             my %coursehash=&Apache::lonnet::coursedescription($key);
                   2327:             my $coursetitle = $coursehash{'description'};
1.243     raeburn  2328:             my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.216     raeburn  2329:             if (ref($bookshash->{$key}) eq 'HASH') {
                   2330:                 $subject = $bookshash->{$key}->{'subject'};
                   2331:                 $title = $bookshash->{$key}->{'title'};
1.242     raeburn  2332:                 if ($type eq 'textbooks') {
1.243     raeburn  2333:                     $publisher = $bookshash->{$key}->{'publisher'};
1.242     raeburn  2334:                     $author = $bookshash->{$key}->{'author'};
                   2335:                     $image = $bookshash->{$key}->{'image'};
                   2336:                     if ($image ne '') {
                   2337:                         my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
                   2338:                         my $imagethumb = "$path/tn-".$imagefile;
                   2339:                         $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
                   2340:                     }
1.216     raeburn  2341:                 }
                   2342:             }
1.242     raeburn  2343:             my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.216     raeburn  2344:             $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.242     raeburn  2345:                          .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.216     raeburn  2346:             for (my $k=0; $k<=$maxnum; $k++) {
                   2347:                 my $vpos = $k+1;
                   2348:                 my $selstr;
                   2349:                 if ($k == $i) {
                   2350:                     $selstr = ' selected="selected" ';
                   2351:                 }
                   2352:                 $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   2353:             }
                   2354:             $datatable .= '</select>'.('&nbsp;'x2).
1.242     raeburn  2355:                 '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.216     raeburn  2356:                 &mt('Delete?').'</label></span></td>'.
                   2357:                 '<td colspan="2">'.
1.242     raeburn  2358:                 '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.216     raeburn  2359:                 ('&nbsp;'x2).
1.242     raeburn  2360:                 '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
                   2361:             if ($type eq 'textbooks') {
                   2362:                 $datatable .= ('&nbsp;'x2).
1.243     raeburn  2363:                               '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
                   2364:                               ('&nbsp;'x2).
1.242     raeburn  2365:                               '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
                   2366:                               ('&nbsp;'x2).
                   2367:                               '<span class="LC_nobreak">'.&mt('Thumbnail:');
                   2368:                 if ($image) {
1.267     raeburn  2369:                     $datatable .= $imgsrc.
1.242     raeburn  2370:                                   '<label><input type="checkbox" name="'.$type.'_image_del"'.
                   2371:                                   ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
                   2372:                                   '<span class="LC_nobreak">&nbsp;'.&mt('Replace:').'&nbsp;';
                   2373:                 }
                   2374:                 if ($switchserver) {
                   2375:                     $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   2376:                 } else {
                   2377:                     $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
                   2378:                 }
1.216     raeburn  2379:             }
1.242     raeburn  2380:             $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.216     raeburn  2381:                           '<span class="LC_nobreak">'.&mt('LON-CAPA course:').'&nbsp;'.
                   2382:                           $coursetitle.'</span></td></tr>'."\n";
                   2383:             $itemcount ++;
                   2384:         }
                   2385:     }
                   2386:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.242     raeburn  2387:     my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.216     raeburn  2388:     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.242     raeburn  2389:                   '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
                   2390:                   '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.216     raeburn  2391:     for (my $k=0; $k<$maxnum+1; $k++) {
                   2392:         my $vpos = $k+1;
                   2393:         my $selstr;
                   2394:         if ($k == $maxnum) {
                   2395:             $selstr = ' selected="selected" ';
                   2396:         }
                   2397:         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   2398:     }
                   2399:     $datatable .= '</select>&nbsp;'."\n".
1.242     raeburn  2400:                   '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</td>'."\n".
1.216     raeburn  2401:                   '<td colspan="2">'.
1.242     raeburn  2402:                   '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.216     raeburn  2403:                   ('&nbsp;'x2).
1.242     raeburn  2404:                   '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
                   2405:                   ('&nbsp;'x2);
                   2406:     if ($type eq 'textbooks') {
1.243     raeburn  2407:         $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
                   2408:                       ('&nbsp;'x2).
                   2409:                       '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.242     raeburn  2410:                       ('&nbsp;'x2).
                   2411:                       '<span class="LC_nobreak">'.&mt('Image:').'&nbsp;';
                   2412:         if ($switchserver) {
                   2413:             $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   2414:         } else {
                   2415:             $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
                   2416:         }
1.216     raeburn  2417:     }
                   2418:     $datatable .= '</span>'."\n".
                   2419:                   '<span class="LC_nobreak">'.&mt('LON-CAPA course:').'&nbsp;'.
1.242     raeburn  2420:                   &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
                   2421:                   '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.216     raeburn  2422:                   &Apache::loncommon::selectcourse_link
1.242     raeburn  2423:                       ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course');
1.216     raeburn  2424:                   '</span></td>'."\n".
                   2425:                   '</tr>'."\n";
                   2426:     $itemcount ++;
                   2427:     return $datatable;
                   2428: }
                   2429: 
1.217     raeburn  2430: sub textbookcourses_javascript {
1.242     raeburn  2431:     my ($settings) = @_;
                   2432:     return unless(ref($settings) eq 'HASH');
                   2433:     my (%ordered,%total,%jstext);
                   2434:     foreach my $type ('textbooks','templates') {
                   2435:         $total{$type} = 0;
                   2436:         if (ref($settings->{$type}) eq 'HASH') {
                   2437:             foreach my $item (keys(%{$settings->{$type}})) {
                   2438:                 if (ref($settings->{$type}->{$item}) eq 'HASH') {
                   2439:                     my $num = $settings->{$type}->{$item}{'order'};
                   2440:                     $ordered{$type}{$num} = $item;
                   2441:                 }
                   2442:             }
                   2443:             $total{$type} = scalar(keys(%{$settings->{$type}}));
                   2444:         }
                   2445:         my @jsarray = ();
                   2446:         foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
                   2447:             push(@jsarray,$ordered{$type}{$item});
                   2448:         }
                   2449:         $jstext{$type} = '    var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.217     raeburn  2450:     }
                   2451:     return <<"ENDSCRIPT";
                   2452: <script type="text/javascript">
                   2453: // <![CDATA[
1.242     raeburn  2454: function reorderBooks(form,item,caller) {
1.217     raeburn  2455:     var changedVal;
1.242     raeburn  2456: $jstext{'textbooks'};
                   2457: $jstext{'templates'};
                   2458:     var newpos;
                   2459:     var maxh;
                   2460:     if (caller == 'textbooks') {  
                   2461:         newpos = 'textbooks_addbook_pos';
                   2462:         maxh = 1 + $total{'textbooks'};
                   2463:     } else {
                   2464:         newpos = 'templates_addbook_pos';
                   2465:         maxh = 1 + $total{'templates'};
                   2466:     }
1.217     raeburn  2467:     var current = new Array;
                   2468:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
                   2469:     if (item == newpos) {
                   2470:         changedVal = newitemVal;
                   2471:     } else {
                   2472:         changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
                   2473:         current[newitemVal] = newpos;
                   2474:     }
1.242     raeburn  2475:     if (caller == 'textbooks') {
                   2476:         for (var i=0; i<textbooks.length; i++) {
                   2477:             var elementName = 'textbooks_'+textbooks[i];
                   2478:             if (elementName != item) {
                   2479:                 if (form.elements[elementName]) {
                   2480:                     var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   2481:                     current[currVal] = elementName;
                   2482:                 }
                   2483:             }
                   2484:         }
                   2485:     }
                   2486:     if (caller == 'templates') {
                   2487:         for (var i=0; i<templates.length; i++) {
                   2488:             var elementName = 'templates_'+templates[i];
                   2489:             if (elementName != item) {
                   2490:                 if (form.elements[elementName]) {
                   2491:                     var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   2492:                     current[currVal] = elementName;
                   2493:                 }
1.217     raeburn  2494:             }
                   2495:         }
                   2496:     }
                   2497:     var oldVal;
                   2498:     for (var j=0; j<maxh; j++) {
                   2499:         if (current[j] == undefined) {
                   2500:             oldVal = j;
                   2501:         }
                   2502:     }
                   2503:     if (oldVal < changedVal) {
                   2504:         for (var k=oldVal+1; k<=changedVal ; k++) {
                   2505:            var elementName = current[k];
                   2506:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   2507:         }
                   2508:     } else {
                   2509:         for (var k=changedVal; k<oldVal; k++) {
                   2510:             var elementName = current[k];
                   2511:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   2512:         }
                   2513:     }
                   2514:     return;
                   2515: }
                   2516: 
                   2517: // ]]>
                   2518: </script>
                   2519: 
                   2520: ENDSCRIPT
                   2521: }
                   2522: 
1.267     raeburn  2523: sub ltitools_javascript {
                   2524:     my ($settings) = @_;
                   2525:     return unless(ref($settings) eq 'HASH');
                   2526:     my (%ordered,$total,%jstext);
                   2527:     $total = 0;
                   2528:     foreach my $item (keys(%{$settings})) {
                   2529:         if (ref($settings->{$item}) eq 'HASH') {
                   2530:             my $num = $settings->{$item}{'order'};
                   2531:             $ordered{$num} = $item;
                   2532:         }
                   2533:     }
                   2534:     $total = scalar(keys(%{$settings}));
                   2535:     my @jsarray = ();
                   2536:     foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
                   2537:         push(@jsarray,$ordered{$item});
                   2538:     }
                   2539:     my $jstext = '    var ltitools = Array('."'".join("','",@jsarray)."'".');'."\n";
                   2540:     return <<"ENDSCRIPT";
                   2541: <script type="text/javascript">
                   2542: // <![CDATA[
                   2543: function reorderLTI(form,item) {
                   2544:     var changedVal;
                   2545: $jstext
                   2546:     var newpos = 'ltitools_add_pos';
                   2547:     var maxh = 1 + $total;
                   2548:     var current = new Array;
                   2549:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
                   2550:     if (item == newpos) {
                   2551:         changedVal = newitemVal;
                   2552:     } else {
                   2553:         changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
                   2554:         current[newitemVal] = newpos;
                   2555:     }
                   2556:     for (var i=0; i<ltitools.length; i++) {
                   2557:         var elementName = 'ltitools_'+ltitools[i];
                   2558:         if (elementName != item) {
                   2559:             if (form.elements[elementName]) {
                   2560:                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   2561:                 current[currVal] = elementName;
                   2562:             }
                   2563:         }
                   2564:     }
                   2565:     var oldVal;
                   2566:     for (var j=0; j<maxh; j++) {
                   2567:         if (current[j] == undefined) {
                   2568:             oldVal = j;
                   2569:         }
                   2570:     }
                   2571:     if (oldVal < changedVal) {
                   2572:         for (var k=oldVal+1; k<=changedVal ; k++) {
                   2573:            var elementName = current[k];
                   2574:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   2575:         }
                   2576:     } else {
                   2577:         for (var k=changedVal; k<oldVal; k++) {
                   2578:             var elementName = current[k];
                   2579:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   2580:         }
                   2581:     }
                   2582:     return;
                   2583: }
                   2584: 
                   2585: // ]]>
                   2586: </script>
                   2587: 
                   2588: ENDSCRIPT
                   2589: }
                   2590: 
1.3       raeburn  2591: sub print_autoenroll {
1.30      raeburn  2592:     my ($dom,$settings,$rowtotal) = @_;
1.3       raeburn  2593:     my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.274     raeburn  2594:     my ($defdom,$runon,$runoff,$coownerson,$coownersoff,$failsafe);
1.3       raeburn  2595:     if (ref($settings) eq 'HASH') {
                   2596:         if (exists($settings->{'run'})) {
                   2597:             if ($settings->{'run'} eq '0') {
                   2598:                 $runoff = ' checked="checked" ';
                   2599:                 $runon = ' ';
                   2600:             } else {
                   2601:                 $runon = ' checked="checked" ';
                   2602:                 $runoff = ' ';
                   2603:             }
                   2604:         } else {
                   2605:             if ($autorun) {
                   2606:                 $runon = ' checked="checked" ';
                   2607:                 $runoff = ' ';
                   2608:             } else {
                   2609:                 $runoff = ' checked="checked" ';
                   2610:                 $runon = ' ';
                   2611:             }
                   2612:         }
1.129     raeburn  2613:         if (exists($settings->{'co-owners'})) {
                   2614:             if ($settings->{'co-owners'} eq '0') {
                   2615:                 $coownersoff = ' checked="checked" ';
                   2616:                 $coownerson = ' ';
                   2617:             } else {
                   2618:                 $coownerson = ' checked="checked" ';
                   2619:                 $coownersoff = ' ';
                   2620:             }
                   2621:         } else {
                   2622:             $coownersoff = ' checked="checked" ';
                   2623:             $coownerson = ' ';
                   2624:         }
1.3       raeburn  2625:         if (exists($settings->{'sender_domain'})) {
                   2626:             $defdom = $settings->{'sender_domain'};
                   2627:         }
1.274     raeburn  2628:         if (exists($settings->{'autofailsafe'})) {
                   2629:             $failsafe = $settings->{'autofailsafe'};
                   2630:         }
1.14      raeburn  2631:     } else {
                   2632:         if ($autorun) {
                   2633:             $runon = ' checked="checked" ';
                   2634:             $runoff = ' ';
                   2635:         } else {
                   2636:             $runoff = ' checked="checked" ';
                   2637:             $runon = ' ';
                   2638:         }
1.3       raeburn  2639:     }
                   2640:     my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39      raeburn  2641:     my $notif_sender;
                   2642:     if (ref($settings) eq 'HASH') {
                   2643:         $notif_sender = $settings->{'sender_uname'};
                   2644:     }
1.3       raeburn  2645:     my $datatable='<tr class="LC_odd_row">'.
                   2646:                   '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8       raeburn  2647:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3       raeburn  2648:                   '<input type="radio" name="autoenroll_run"'.
1.8       raeburn  2649:                   $runon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   2650:                   '<label><input type="radio" name="autoenroll_run"'.
1.14      raeburn  2651:                   $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3       raeburn  2652:                   '</tr><tr>'.
                   2653:                   '<td>'.&mt('Notification messages - sender').
1.8       raeburn  2654:                   '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3       raeburn  2655:                   &mt('username').':&nbsp;'.
                   2656:                   '<input type="text" name="sender_uname" value="'.
1.39      raeburn  2657:                   $notif_sender.'" size="10" />&nbsp;&nbsp;'.&mt('domain').
1.129     raeburn  2658:                   ':&nbsp;'.$domform.'</span></td></tr>'.
                   2659:                   '<tr class="LC_odd_row">'.
                   2660:                   '<td>'.&mt('Automatically assign co-ownership').'</td>'.
                   2661:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   2662:                   '<input type="radio" name="autoassign_coowners"'.
                   2663:                   $coownerson.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   2664:                   '<label><input type="radio" name="autoassign_coowners"'.
                   2665:                   $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.274     raeburn  2666:                   '</tr><tr>'.
                   2667:                   '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
                   2668:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
                   2669:                   '<input type="text" name="autoenroll_failsafe"'.
                   2670:                   ' value="'.$failsafe.'" size="4" /></td></tr>';
                   2671:     $$rowtotal += 4;
1.3       raeburn  2672:     return $datatable;
                   2673: }
                   2674: 
                   2675: sub print_autoupdate {
1.30      raeburn  2676:     my ($position,$dom,$settings,$rowtotal) = @_;
1.3       raeburn  2677:     my $datatable;
                   2678:     if ($position eq 'top') {
                   2679:         my $updateon = ' ';
                   2680:         my $updateoff = ' checked="checked" ';
                   2681:         my $classlistson = ' ';
                   2682:         my $classlistsoff = ' checked="checked" ';
                   2683:         if (ref($settings) eq 'HASH') {
                   2684:             if ($settings->{'run'} eq '1') {
                   2685:                 $updateon = $updateoff;
                   2686:                 $updateoff = ' ';
                   2687:             }
                   2688:             if ($settings->{'classlists'} eq '1') {
                   2689:                 $classlistson = $classlistsoff;
                   2690:                 $classlistsoff = ' ';
                   2691:             }
                   2692:         }
                   2693:         my %title = (
                   2694:                    run => 'Auto-update active?',
                   2695:                    classlists => 'Update information in classlists?',
                   2696:                     );
                   2697:         $datatable = '<tr class="LC_odd_row">'. 
                   2698:                   '<td>'.&mt($title{'run'}).'</td>'.
1.8       raeburn  2699:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3       raeburn  2700:                   '<input type="radio" name="autoupdate_run"'.
1.8       raeburn  2701:                   $updateon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   2702:                   '<label><input type="radio" name="autoupdate_run"'.
                   2703:                   $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3       raeburn  2704:                   '</tr><tr>'.
                   2705:                   '<td>'.&mt($title{'classlists'}).'</td>'.
1.8       raeburn  2706:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
                   2707:                   '<label><input type="radio" name="classlists"'.
                   2708:                   $classlistson.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   2709:                   '<label><input type="radio" name="classlists"'.
                   2710:                   $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3       raeburn  2711:                   '</tr>';
1.30      raeburn  2712:         $$rowtotal += 2;
1.131     raeburn  2713:     } elsif ($position eq 'middle') {
                   2714:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   2715:         my $numinrow = 3;
                   2716:         my $locknamesettings;
                   2717:         $datatable .= &insttypes_row($settings,$types,$usertypes,
                   2718:                                      $dom,$numinrow,$othertitle,
                   2719:                                     'lockablenames');
                   2720:         $$rowtotal ++;
1.3       raeburn  2721:     } else {
1.44      raeburn  2722:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132     raeburn  2723:         my @fields = ('lastname','firstname','middlename','generation',
1.20      raeburn  2724:                       'permanentemail','id');
1.33      raeburn  2725:         my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3       raeburn  2726:         my $numrows = 0;
1.26      raeburn  2727:         if (ref($types) eq 'ARRAY') {
                   2728:             if (@{$types} > 0) {
                   2729:                 $datatable = 
                   2730:                     &usertype_update_row($settings,$usertypes,\%fieldtitles,
                   2731:                                          \@fields,$types,\$numrows);
1.30      raeburn  2732:                     $$rowtotal += @{$types}; 
1.26      raeburn  2733:             }
1.3       raeburn  2734:         }
                   2735:         $datatable .= 
                   2736:             &usertype_update_row($settings,{'default' => $othertitle},
                   2737:                                  \%fieldtitles,\@fields,['default'],
                   2738:                                  \$numrows);
1.30      raeburn  2739:         $$rowtotal ++;     
1.3       raeburn  2740:     }
                   2741:     return $datatable;
                   2742: }
                   2743: 
1.125     raeburn  2744: sub print_autocreate {
                   2745:     my ($dom,$settings,$rowtotal) = @_;
1.191     raeburn  2746:     my (%createon,%createoff,%currhash);
1.125     raeburn  2747:     my @types = ('xml','req');
                   2748:     if (ref($settings) eq 'HASH') {
                   2749:         foreach my $item (@types) {
                   2750:             $createoff{$item} = ' checked="checked" ';
                   2751:             $createon{$item} = ' ';
                   2752:             if (exists($settings->{$item})) {
                   2753:                 if ($settings->{$item}) {
                   2754:                     $createon{$item} = ' checked="checked" ';
                   2755:                     $createoff{$item} = ' ';
                   2756:                 }
                   2757:             }
                   2758:         }
1.210     raeburn  2759:         if ($settings->{'xmldc'} ne '') {
1.191     raeburn  2760:             $currhash{$settings->{'xmldc'}} = 1;
                   2761:         }
1.125     raeburn  2762:     } else {
                   2763:         foreach my $item (@types) {
                   2764:             $createoff{$item} = ' checked="checked" ';
                   2765:             $createon{$item} = ' ';
                   2766:         }
                   2767:     }
                   2768:     $$rowtotal += 2;
1.191     raeburn  2769:     my $numinrow = 2;
1.125     raeburn  2770:     my $datatable='<tr class="LC_odd_row">'.
                   2771:                   '<td>'.&mt('Create pending official courses from XML files').'</td>'.
                   2772:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   2773:                   '<input type="radio" name="autocreate_xml"'.
                   2774:                   $createon{'xml'}.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   2775:                   '<label><input type="radio" name="autocreate_xml"'.
1.143     raeburn  2776:                   $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
                   2777:                   '</td></tr><tr>'.
                   2778:                   '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
                   2779:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   2780:                   '<input type="radio" name="autocreate_req"'.
                   2781:                   $createon{'req'}.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   2782:                   '<label><input type="radio" name="autocreate_req"'.
                   2783:                   $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.191     raeburn  2784:     my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
                   2785:                                                    'autocreate_xmldc',%currhash);
1.247     raeburn  2786:     $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125     raeburn  2787:     if ($numdc > 1) {
1.247     raeburn  2788:         $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
                   2789:                       '</td><td class="LC_left_item">';
1.125     raeburn  2790:     } else {
1.247     raeburn  2791:         $datatable .= &mt('Course creation processed as:').
                   2792:                       '</td><td class="LC_right_item">';
1.125     raeburn  2793:     }
1.247     raeburn  2794:     $datatable .= $dctable.'</td></tr>';
1.191     raeburn  2795:     $$rowtotal += $rows;
1.125     raeburn  2796:     return $datatable;
                   2797: }
                   2798: 
1.23      raeburn  2799: sub print_directorysrch {
1.277     raeburn  2800:     my ($position,$dom,$settings,$rowtotal) = @_;
                   2801:     my $datatable;
                   2802:     if ($position eq 'top') {
                   2803:         my $instsrchon = ' ';
                   2804:         my $instsrchoff = ' checked="checked" ';
                   2805:         my ($exacton,$containson,$beginson);
                   2806:         my $instlocalon = ' ';
                   2807:         my $instlocaloff = ' checked="checked" ';
                   2808:         if (ref($settings) eq 'HASH') {
                   2809:             if ($settings->{'available'} eq '1') {
                   2810:                 $instsrchon = $instsrchoff;
                   2811:                 $instsrchoff = ' ';
                   2812:             }
                   2813:             if ($settings->{'localonly'} eq '1') {
                   2814:                 $instlocalon = $instlocaloff;
                   2815:                 $instlocaloff = ' ';
                   2816:             }
                   2817:             if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
                   2818:                 foreach my $type (@{$settings->{'searchtypes'}}) {
                   2819:                     if ($type eq 'exact') {
                   2820:                         $exacton = ' checked="checked" ';
                   2821:                     } elsif ($type eq 'contains') {
                   2822:                         $containson = ' checked="checked" ';
                   2823:                     } elsif ($type eq 'begins') {
                   2824:                         $beginson = ' checked="checked" ';
                   2825:                     }
                   2826:                 }
                   2827:             } else {
                   2828:                 if ($settings->{'searchtypes'} eq 'exact') {
                   2829:                     $exacton = ' checked="checked" ';
                   2830:                 } elsif ($settings->{'searchtypes'} eq 'contains') {
                   2831:                     $containson = ' checked="checked" ';
                   2832:                 } elsif ($settings->{'searchtypes'} eq 'specify') {
1.25      raeburn  2833:                     $exacton = ' checked="checked" ';
                   2834:                     $containson = ' checked="checked" ';
                   2835:                 }
                   2836:             }
1.277     raeburn  2837:         }
                   2838:         my ($searchtitles,$titleorder) = &sorted_searchtitles();
                   2839:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   2840: 
                   2841:         my $numinrow = 4;
                   2842:         my $cansrchrow = 0;
                   2843:         $datatable='<tr class="LC_odd_row">'.
                   2844:                    '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
                   2845:                    '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   2846:                    '<input type="radio" name="dirsrch_available"'.
                   2847:                    $instsrchon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   2848:                    '<label><input type="radio" name="dirsrch_available"'.
                   2849:                    $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
                   2850:                    '</tr><tr>'.
                   2851:                    '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
                   2852:                    '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   2853:                    '<input type="radio" name="dirsrch_instlocalonly"'.
                   2854:                    $instlocaloff.' value="0" />'.&mt('Yes').'</label>&nbsp;'.
                   2855:                    '<label><input type="radio" name="dirsrch_instlocalonly"'.
                   2856:                    $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
                   2857:                    '</tr>';
                   2858:         $$rowtotal += 2;
                   2859:         if (ref($usertypes) eq 'HASH') {
                   2860:             if (keys(%{$usertypes}) > 0) {
                   2861:                 $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
                   2862:                                              $numinrow,$othertitle,'cansearch');
                   2863:                 $cansrchrow = 1;
1.25      raeburn  2864:             }
1.23      raeburn  2865:         }
1.277     raeburn  2866:         if ($cansrchrow) {
                   2867:             $$rowtotal ++;
                   2868:             $datatable .= '<tr>';
                   2869:         } else {
                   2870:             $datatable .= '<tr class="LC_odd_row">';
1.26      raeburn  2871:         }
1.277     raeburn  2872:         $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
                   2873:                       '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
                   2874:         foreach my $title (@{$titleorder}) {
                   2875:             if (defined($searchtitles->{$title})) {
                   2876:                 my $check = ' ';
                   2877:                 if (ref($settings) eq 'HASH') {
                   2878:                     if (ref($settings->{'searchby'}) eq 'ARRAY') {
                   2879:                         if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
                   2880:                             $check = ' checked="checked" ';
                   2881:                         }
1.39      raeburn  2882:                     }
1.25      raeburn  2883:                 }
1.277     raeburn  2884:                 $datatable .= '<td class="LC_left_item">'.
                   2885:                               '<span class="LC_nobreak"><label>'.
                   2886:                               '<input type="checkbox" name="searchby" '.
                   2887:                               'value="'.$title.'"'.$check.'/>'.
                   2888:                               $searchtitles->{$title}.'</label></span></td>';
1.25      raeburn  2889:             }
                   2890:         }
1.277     raeburn  2891:         $datatable .= '</tr></table></td></tr>';
                   2892:         $$rowtotal ++;
                   2893:         if ($cansrchrow) {
                   2894:             $datatable .= '<tr class="LC_odd_row">';
                   2895:         } else {
                   2896:             $datatable .= '<tr>';
                   2897:         }
                   2898:         $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.   
                   2899:                       '<td class="LC_left_item" colspan="2">'.
                   2900:                       '<span class="LC_nobreak"><label>'.
                   2901:                       '<input type="checkbox" name="searchtypes" '.
                   2902:                       $exacton.' value="exact" />'.&mt('Exact match').
                   2903:                       '</label>&nbsp;'.
                   2904:                       '<label><input type="checkbox" name="searchtypes" '.
                   2905:                       $beginson.' value="begins" />'.&mt('Begins with').
                   2906:                       '</label>&nbsp;'.
                   2907:                       '<label><input type="checkbox" name="searchtypes" '.
                   2908:                       $containson.' value="contains" />'.&mt('Contains').
                   2909:                       '</label></span></td></tr>';
                   2910:         $$rowtotal ++;
1.26      raeburn  2911:     } else {
1.277     raeburn  2912:         my $domsrchon = ' checked="checked" ';
                   2913:         my $domsrchoff = ' ';
                   2914:         my $domlocalon = ' ';
                   2915:         my $domlocaloff = ' checked="checked" ';
                   2916:         if (ref($settings) eq 'HASH') {
                   2917:             if ($settings->{'lclocalonly'} eq '1') {
                   2918:                 $domlocalon = $domlocaloff;
                   2919:                 $domlocaloff = ' ';
                   2920:             }
                   2921:             if ($settings->{'lcavailable'} eq '0') {
                   2922:                 $domsrchoff = $domsrchon;
                   2923:                 $domsrchon = ' ';
                   2924:             }
                   2925:         }
                   2926:         $datatable='<tr class="LC_odd_row">'.
                   2927:                       '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
                   2928:                       '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   2929:                       '<input type="radio" name="dirsrch_domavailable"'.
                   2930:                       $domsrchon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   2931:                       '<label><input type="radio" name="dirsrch_domavailable"'.
                   2932:                       $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
                   2933:                       '</tr><tr>'.
                   2934:                       '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
                   2935:                       '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   2936:                       '<input type="radio" name="dirsrch_domlocalonly"'.
                   2937:                       $domlocaloff.' value="0" />'.&mt('Yes').'</label>&nbsp;'.
                   2938:                       '<label><input type="radio" name="dirsrch_domlocalonly"'.
                   2939:                       $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
                   2940:                       '</tr>';
                   2941:         $$rowtotal += 2;
1.26      raeburn  2942:     }
1.25      raeburn  2943:     return $datatable;
                   2944: }
                   2945: 
1.28      raeburn  2946: sub print_contacts {
1.30      raeburn  2947:     my ($dom,$settings,$rowtotal) = @_;
1.28      raeburn  2948:     my $datatable;
                   2949:     my @contacts = ('adminemail','supportemail');
1.134     raeburn  2950:     my (%checked,%to,%otheremails,%bccemails);
1.102     raeburn  2951:     my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail',
1.203     raeburn  2952:                     'requestsmail','updatesmail','idconflictsmail');
1.28      raeburn  2953:     foreach my $type (@mailings) {
                   2954:         $otheremails{$type} = '';
                   2955:     }
1.134     raeburn  2956:     $bccemails{'helpdeskmail'} = '';
1.28      raeburn  2957:     if (ref($settings) eq 'HASH') {
                   2958:         foreach my $item (@contacts) {
                   2959:             if (exists($settings->{$item})) {
                   2960:                 $to{$item} = $settings->{$item};
                   2961:             }
                   2962:         }
                   2963:         foreach my $type (@mailings) {
                   2964:             if (exists($settings->{$type})) {
                   2965:                 if (ref($settings->{$type}) eq 'HASH') {
                   2966:                     foreach my $item (@contacts) {
                   2967:                         if ($settings->{$type}{$item}) {
                   2968:                             $checked{$type}{$item} = ' checked="checked" ';
                   2969:                         }
                   2970:                     }
                   2971:                     $otheremails{$type} = $settings->{$type}{'others'};
1.134     raeburn  2972:                     if ($type eq 'helpdeskmail') {
                   2973:                         $bccemails{$type} = $settings->{$type}{'bcc'};
                   2974:                     }
1.28      raeburn  2975:                 }
1.89      raeburn  2976:             } elsif ($type eq 'lonstatusmail') {
                   2977:                 $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.28      raeburn  2978:             }
                   2979:         }
                   2980:     } else {
                   2981:         $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
                   2982:         $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
                   2983:         $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
                   2984:         $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.89      raeburn  2985:         $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
                   2986:         $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" '; 
1.102     raeburn  2987:         $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
1.190     raeburn  2988:         $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
1.203     raeburn  2989:         $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.28      raeburn  2990:     }
                   2991:     my ($titles,$short_titles) = &contact_titles();
                   2992:     my $rownum = 0;
                   2993:     my $css_class;
                   2994:     foreach my $item (@contacts) {
1.69      raeburn  2995:         $css_class = $rownum%2?' class="LC_odd_row"':'';
1.30      raeburn  2996:         $datatable .= '<tr'.$css_class.'>'. 
                   2997:                   '<td><span class="LC_nobreak">'.$titles->{$item}.
                   2998:                   '</span></td><td class="LC_right_item">'.
1.28      raeburn  2999:                   '<input type="text" name="'.$item.'" value="'.
                   3000:                   $to{$item}.'" /></td></tr>';
1.203     raeburn  3001:         $rownum ++;
1.28      raeburn  3002:     }
                   3003:     foreach my $type (@mailings) {
1.69      raeburn  3004:         $css_class = $rownum%2?' class="LC_odd_row"':'';
1.28      raeburn  3005:         $datatable .= '<tr'.$css_class.'>'.
1.30      raeburn  3006:                       '<td><span class="LC_nobreak">'.
                   3007:                       $titles->{$type}.': </span></td>'.
1.28      raeburn  3008:                       '<td class="LC_left_item">'.
                   3009:                       '<span class="LC_nobreak">';
                   3010:         foreach my $item (@contacts) {
                   3011:             $datatable .= '<label>'.
                   3012:                           '<input type="checkbox" name="'.$type.'"'.
                   3013:                           $checked{$type}{$item}.
                   3014:                           ' value="'.$item.'" />'.$short_titles->{$item}.
                   3015:                           '</label>&nbsp;';
                   3016:         }
                   3017:         $datatable .= '</span><br />'.&mt('Others').':&nbsp;&nbsp;'.
                   3018:                       '<input type="text" name="'.$type.'_others" '.
1.134     raeburn  3019:                       'value="'.$otheremails{$type}.'"  />';
                   3020:         if ($type eq 'helpdeskmail') {
1.136     raeburn  3021:             $datatable .= '<br />'.&mt('Bcc:').('&nbsp;'x6).
1.134     raeburn  3022:                           '<input type="text" name="'.$type.'_bcc" '.
                   3023:                           'value="'.$bccemails{$type}.'"  />';
                   3024:         }
                   3025:         $datatable .= '</td></tr>'."\n";
1.203     raeburn  3026:         $rownum ++;
1.28      raeburn  3027:     }
1.203     raeburn  3028:     my %choices;
                   3029:     $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',
                   3030:                                    &Apache::loncommon::modal_link('http://loncapa.org/core.html',
                   3031:                                    &mt('LON-CAPA core group - MSU'),600,500));
                   3032:     $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
                   3033:                                     &Apache::loncommon::modal_link('http://loncapa.org/core.html',
                   3034:                                     &mt('LON-CAPA core group - MSU'),600,500));
                   3035:     my @toggles = ('reporterrors','reportupdates');
                   3036:     my %defaultchecked = ('reporterrors'  => 'on',
                   3037:                           'reportupdates' => 'on');
                   3038:     (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
                   3039:                                                \%choices,$rownum);
                   3040:     $datatable .= $reports;
1.30      raeburn  3041:     $$rowtotal += $rownum;
1.28      raeburn  3042:     return $datatable;
                   3043: }
                   3044: 
1.118     jms      3045: sub print_helpsettings {
1.282     raeburn  3046:     my ($position,$dom,$settings,$rowtotal) = @_;
                   3047:     my $confname = $dom.'-domainconfig';
1.168     raeburn  3048:     my ($datatable,$itemcount);
1.282     raeburn  3049:     if ($position eq 'top') {
                   3050:         $itemcount = 1;
                   3051:         my (%choices,%defaultchecked,@toggles);
                   3052:         $choices{'submitbugs'} = &mt('Display link to: [_1]?',
                   3053:                                      &Apache::loncommon::modal_link('http://bugs.loncapa.org',
                   3054:                                      &mt('LON-CAPA bug tracker'),600,500));
                   3055:         %defaultchecked = ('submitbugs' => 'on');
                   3056:         @toggles = ('submitbugs');
                   3057:         ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
                   3058:                                                      \%choices,$itemcount);
                   3059:         $$rowtotal ++;
                   3060:     } else {
                   3061:         my $css_class;
                   3062:         my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
                   3063:         my %customroles;
                   3064:         foreach my $key (keys(%existing)) {
                   3065:             if ($key=~/^rolesdef\_(\w+)$/) {
                   3066:                 my $rolename = $1;
                   3067:                 my %privs;
                   3068:                 ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
                   3069:                 $customroles{$rolename} = \%privs;
                   3070:             }
                   3071:         }
                   3072:         my $count = 0;
                   3073:         my $context = 'domprefs';
                   3074:         my $crstype = 'Course';
                   3075:         foreach my $role (sort(keys(%customroles))) {
                   3076:             my $prefix = 'custhelp'.$count;
                   3077:             my %full=();
                   3078:             my %levels= (
                   3079:                          course => {},
                   3080:                          domain => {},
                   3081:                          system => {},
                   3082:                         );
                   3083:             my %levelscurrent=(
                   3084:                                course => {},
                   3085:                                domain => {},
                   3086:                                system => {},
                   3087:                               );
                   3088:             &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
                   3089:             my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
                   3090:             $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   3091:             $datatable .= '<tr '.$css_class.'><td><label>'.
                   3092:                           '<input type="checkbox" name="modifycusthelp" value="'.$count.'" />'.
                   3093:                           '<input type="hidden" name="custhelprole'.$count.'" value="'.$role.'" />'. 
                   3094:                           &mt('Modify').'</label></td>'.
                   3095:                           '<td>'.&mt('Existing helpdesk role:').'&nbsp;'.
                   3096:                           '<b>'.$role.'</b><br />'.
                   3097:                           &Apache::lonuserutils::custom_role_header($context,$crstype,
                   3098:                                                                     \@templateroles,$prefix).
                   3099:                           &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
                   3100:                                                                    \%levelscurrent,$prefix).
                   3101:                           '<br /></td>';
                   3102:             $count ++;
                   3103:             $itemcount ++;
                   3104:         }
                   3105:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   3106:         my $newcust = 'custhelp'.$count;
                   3107:         my (%privs,%levelscurrent);
                   3108:         my %full=();
                   3109:         my %levels= (
                   3110:                      course => {},
                   3111:                      domain => {},
                   3112:                      system => {},
                   3113:                     );
                   3114:         &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
                   3115:         my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
                   3116:         $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><label>'.
                   3117:                       '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
                   3118:                       '</label></span></td>'.
                   3119:                       '<td><span class="LC_nobreak">'.
                   3120:                       '<b>'.&mt('Name of new helpdesk role:').'</b>&nbsp;'.
                   3121:                       '<input type="text" size="20" name="newcusthelpname" value="" />'.
                   3122:                       '</span><br />'.
                   3123:                       &Apache::lonuserutils::custom_role_header($context,$crstype,
                   3124:                                                                 \@templateroles,$newcust).
                   3125:                       &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
                   3126:                                                                \%levelscurrent,$newcust).
                   3127:                       '<br /><br />'.
                   3128:                       '</td></tr>';
                   3129:         $count ++;
                   3130:         $$rowtotal += $count;
                   3131:     }
1.166     raeburn  3132:     return $datatable;
1.121     raeburn  3133: }
                   3134: 
                   3135: sub radiobutton_prefs {
1.192     raeburn  3136:     my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.257     raeburn  3137:         $additional,$align) = @_;
1.121     raeburn  3138:     return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
                   3139:                    (ref($choices) eq 'HASH'));
                   3140: 
1.170     raeburn  3141:     my (%checkedon,%checkedoff,$datatable,$css_class);
1.121     raeburn  3142: 
                   3143:     foreach my $item (@{$toggles}) {
                   3144:         if ($defaultchecked->{$item} eq 'on') {
1.118     jms      3145:             $checkedon{$item} = ' checked="checked" ';
                   3146:             $checkedoff{$item} = ' ';
1.121     raeburn  3147:         } elsif ($defaultchecked->{$item} eq 'off') {
1.118     jms      3148:             $checkedoff{$item} = ' checked="checked" ';
                   3149:             $checkedon{$item} = ' ';
                   3150:         }
                   3151:     }
                   3152:     if (ref($settings) eq 'HASH') {
1.121     raeburn  3153:         foreach my $item (@{$toggles}) {
1.118     jms      3154:             if ($settings->{$item} eq '1') {
                   3155:                 $checkedon{$item} =  ' checked="checked" ';
                   3156:                 $checkedoff{$item} = ' ';
                   3157:             } elsif ($settings->{$item} eq '0') {
                   3158:                 $checkedoff{$item} =  ' checked="checked" ';
                   3159:                 $checkedon{$item} = ' ';
                   3160:             }
                   3161:         }
1.121     raeburn  3162:     }
1.192     raeburn  3163:     if ($onclick) {
                   3164:         $onclick = ' onclick="'.$onclick.'"';
                   3165:     }
1.121     raeburn  3166:     foreach my $item (@{$toggles}) {
1.118     jms      3167:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121     raeburn  3168:         $datatable .=
1.192     raeburn  3169:             '<tr'.$css_class.'><td valign="top">'.
                   3170:             '<span class="LC_nobreak">'.$choices->{$item}.
1.257     raeburn  3171:             '</span></td>';
                   3172:         if ($align eq 'left') {
                   3173:             $datatable .= '<td class="LC_left_item">';
                   3174:         } else {
                   3175:             $datatable .= '<td class="LC_right_item">';
                   3176:         }
                   3177:         $datatable .= 
                   3178:             '<span class="LC_nobreak">'.
1.118     jms      3179:             '<label><input type="radio" name="'.
1.192     raeburn  3180:             $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118     jms      3181:             '</label>&nbsp;<label><input type="radio" name="'.$item.'" '.
1.192     raeburn  3182:             $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
                   3183:             '</span>'.$additional.
                   3184:             '</td>'.
1.118     jms      3185:             '</tr>';
                   3186:         $itemcount ++;
1.121     raeburn  3187:     }
                   3188:     return ($datatable,$itemcount);
                   3189: }
                   3190: 
1.267     raeburn  3191: sub print_ltitools {
                   3192:     my ($dom,$settings,$rowtotal) = @_;
                   3193:     my $rownum = 0;
                   3194:     my $css_class;
                   3195:     my $itemcount = 1;
                   3196:     my $maxnum = 0;
                   3197:     my %ordered;
                   3198:     if (ref($settings) eq 'HASH') {
                   3199:         foreach my $item (keys(%{$settings})) {
                   3200:             if (ref($settings->{$item}) eq 'HASH') {
                   3201:                 my $num = $settings->{$item}{'order'};
                   3202:                 $ordered{$num} = $item;
                   3203:             }
                   3204:         }
                   3205:     }
                   3206:     my $confname = $dom.'-domainconfig';
                   3207:     my $switchserver = &check_switchserver($dom,$confname);
                   3208:     my $maxnum = scalar(keys(%ordered));
                   3209:     my $datatable = &ltitools_javascript($settings);
                   3210:     my %lt = &ltitools_names();
                   3211:     my @courseroles = ('cc','in','ta','ep','st');
                   3212:     my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
                   3213:     my @fields = ('fullname','firstname','lastname','email','user','roles');
                   3214:     if (keys(%ordered)) {
                   3215:         my @items = sort { $a <=> $b } keys(%ordered);
                   3216:         for (my $i=0; $i<@items; $i++) {
                   3217:             $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   3218:             my $item = $ordered{$items[$i]};
                   3219:             my ($title,$key,$secret,$url,$imgsrc,$version);
                   3220:             if (ref($settings->{$item}) eq 'HASH') {
                   3221:                 $title = $settings->{$item}->{'title'};
                   3222:                 $url = $settings->{$item}->{'url'};
                   3223:                 $key = $settings->{$item}->{'key'};
                   3224:                 $secret = $settings->{$item}->{'secret'};
                   3225:                 my $image = $settings->{$item}->{'image'};
                   3226:                 if ($image ne '') {
                   3227:                     $imgsrc = '<img src="'.$image.'" alt="'.&mt('Tool Provider icon').'" />';
                   3228:                 }
                   3229:             }
                   3230:             my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'ltitools_".$item."'".');"';
                   3231:             $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
                   3232:                          .'<select name="ltitools_'.$item.'"'.$chgstr.'>';
                   3233:             for (my $k=0; $k<=$maxnum; $k++) {
                   3234:                 my $vpos = $k+1;
                   3235:                 my $selstr;
                   3236:                 if ($k == $i) {
                   3237:                     $selstr = ' selected="selected" ';
                   3238:                 }
                   3239:                 $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   3240:             }
                   3241:             $datatable .= '</select>'.('&nbsp;'x2).
                   3242:                 '<label><input type="checkbox" name="ltitools_del" value="'.$item.'" />'.
                   3243:                 &mt('Delete?').'</label></span></td>'.
                   3244:                 '<td colspan="2">'.
                   3245:                 '<fieldset><legend>'.&mt('Required settings').'</legend>'.
                   3246:                 '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="30" name="ltitools_title_'.$i.'" value="'.$title.'" /></span> '.
                   3247:                 ('&nbsp;'x2).
                   3248:                 '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_version_'.$i.'">'.
                   3249:                 '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
                   3250:                 ('&nbsp;'x2).
                   3251:                 '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_msgtype_'.$i.'">'.
                   3252:                 '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
                   3253:                 '<br /><br />'.
                   3254:                 '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="30" name="ltitools_url_'.$i.'"'.
                   3255:                 ' value="'.$url.'" /></span>'.
                   3256:                 ('&nbsp;'x2).
                   3257:                 '<span class="LC_nobreak">'.$lt{'key'}.
                   3258:                 '<input type="text" size="25" name="ltitools_key_'.$i.'" value="'.$key.'" /></span> '.
                   3259:                 ('&nbsp;'x2).
                   3260:                 '<span class="LC_nobreak">'.$lt{'secret'}.':'.
                   3261:                 '<input type="password" size="20" name="ltitools_secret_'.$i.'" value="'.$secret.'" />'.
                   3262:                 '<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>'.
                   3263:                 '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" /></span>'.
                   3264:                 '</fieldset>'.
                   3265:                 '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
                   3266:                 '<span class="LC_nobreak">'.&mt('Display target:');
                   3267:             my %currdisp;
                   3268:             if (ref($settings->{$item}->{'display'}) eq 'HASH') {
                   3269:                 if ($settings->{$item}->{'display'}->{'target'} eq 'window') {
                   3270:                     $currdisp{'window'} = ' checked="checked"';
                   3271:                 } else {
                   3272:                     $currdisp{'iframe'} = ' checked="checked"';
                   3273:                 }
                   3274:                 if ($settings->{$item}->{'display'}->{'width'} =~ /^(\d+)$/) {
                   3275:                     $currdisp{'width'} = $1;
                   3276:                 }
                   3277:                 if ($settings->{$item}->{'display'}->{'height'} =~ /^(\d+)$/) {
                   3278:                      $currdisp{'height'} = $1;
                   3279:                 }
                   3280:             } else {
                   3281:                 $currdisp{'iframe'} = ' checked="checked"';
                   3282:             }
                   3283:             foreach my $disp ('iframe','window') {
                   3284:                 $datatable .= '<label><input type="radio" name="ltitools_target_'.$i.'" value="'.$disp.'"'.$currdisp{$disp}.' />'.
                   3285:                               $lt{$disp}.'</label>'.('&nbsp;'x2);
                   3286:             }
                   3287:             $datatable .= ('&nbsp;'x4);
                   3288:             foreach my $dimen ('width','height') {
                   3289:                 $datatable .= '<label>'.$lt{$dimen}.'&nbsp;'.
                   3290:                               '<input type="text" name="ltitools_'.$dimen.'_'.$i.'" size="5" value="'.$currdisp{$dimen}.'" /></label>'.
                   3291:                               ('&nbsp;'x2);
                   3292:             }
                   3293:             $datatable .= '<br />';
                   3294:             foreach my $extra ('passback','roster') {
                   3295:                 my $checkedon = '';
                   3296:                 my $checkedoff = ' checked="checked"';
                   3297:                 if ($settings->{$item}->{$extra}) {
                   3298:                     $checkedon = $checkedoff;
                   3299:                     $checkedoff = '';
                   3300:                 }
                   3301:                 $datatable .= $lt{$extra}.'&nbsp;'.
                   3302:                               '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="1"'.$checkedon.' />'.
                   3303:                               &mt('Yes').'</label>'.('&nbsp;'x2).
                   3304:                               '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="0"'.$checkedoff.' />'.
                   3305:                               &mt('No').'</label>'.('&nbsp;'x4);
                   3306:             }
                   3307:             $datatable .= '<br /><br /><span class="LC_nobreak">'.$lt{'icon'}.':&nbsp;';
                   3308:             if ($imgsrc) {
                   3309:                 $datatable .= $imgsrc.
                   3310:                               '<label><input type="checkbox" name="ltitools_image_del"'.
                   3311:                               ' value="'.$item.'" />'.&mt('Delete?').'</label></span> '.
                   3312:                               '<span class="LC_nobreak">&nbsp;'.&mt('Replace:').'&nbsp;';
                   3313:             } else {
                   3314:                 $datatable .= '('.&mt('if larger than 21x21 pixels, image will be scaled').')&nbsp;';
                   3315:             }
                   3316:             if ($switchserver) {
                   3317:                 $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   3318:             } else {
                   3319:                 $datatable .= '<input type="file" name="ltitools_image_'.$i.'" value="" />';
                   3320:             }
                   3321:             $datatable .= '</span></fieldset>';
                   3322:             my (%checkedfields,%rolemaps);
                   3323:             if (ref($settings->{$item}) eq 'HASH') {
                   3324:                 if (ref($settings->{$item}->{'fields'}) eq 'HASH') {
                   3325:                     %checkedfields = %{$settings->{$item}->{'fields'}};
                   3326:                 }
                   3327:                 if (ref($settings->{$item}->{'roles'}) eq 'HASH') {
                   3328:                     %rolemaps = %{$settings->{$item}->{'roles'}};
                   3329:                     $checkedfields{'roles'} = 1;
                   3330:                 }
                   3331:             }
                   3332:             $datatable .= '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
                   3333:                           '<span class="LC_nobreak">';
                   3334:             foreach my $field (@fields) {
                   3335:                 my $checked;
                   3336:                 if ($checkedfields{$field}) {
                   3337:                     $checked = ' checked="checked"';
                   3338:                 }
                   3339:                 $datatable .= '<label>'.
                   3340:                               '<input type="checkbox" name="ltitools_fields_'.$i.'" value="'.$field.'"'.$checked.' />'.
                   3341:                               $lt{$field}.'</label>'.('&nbsp;' x2);
                   3342:             }
                   3343:             $datatable .= '</span></fieldset>'.
                   3344:                           '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
                   3345:             foreach my $role (@courseroles) {
                   3346:                 my ($selected,$selectnone);
                   3347:                 if (!$rolemaps{$role}) {
                   3348:                     $selectnone = ' selected="selected"';
                   3349:                 }
                   3350:                 $datatable .= '<td align="center">'. 
                   3351:                               &Apache::lonnet::plaintext($role,'Course').'<br />'.
                   3352:                               '<select name="ltitools_roles_'.$role.'_'.$i.'">'.
                   3353:                               '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
                   3354:                 foreach my $ltirole (@ltiroles) {
                   3355:                     unless ($selectnone) {
                   3356:                         if ($rolemaps{$role} eq $ltirole) {
                   3357:                             $selected = ' selected="selected"';
                   3358:                         } else {
                   3359:                             $selected = '';
                   3360:                         }
                   3361:                     }
                   3362:                     $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
                   3363:                 }
                   3364:                 $datatable .= '</select></td>';
                   3365:             }
1.273     raeburn  3366:             $datatable .= '</tr></table></fieldset>';
                   3367:             my %courseconfig;
                   3368:             if (ref($settings->{$item}) eq 'HASH') {
                   3369:                 if (ref($settings->{$item}->{'crsconf'}) eq 'HASH') {
                   3370:                     %courseconfig = %{$settings->{$item}->{'crsconf'}};
                   3371:                 }
                   3372:             }
                   3373:             $datatable .= '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
                   3374:             foreach my $item ('label','title','target') {
                   3375:                 my $checked;
                   3376:                 if ($courseconfig{$item}) {
                   3377:                     $checked = ' checked="checked"';
                   3378:                 }
                   3379:                 $datatable .= '<label>'.
                   3380:                        '<input type="checkbox" name="ltitools_courseconfig_'.$i.'" value="'.$item.'"'.$checked.' />'.
                   3381:                        $lt{'crs'.$item}.'</label>'.('&nbsp;' x2)."\n";
                   3382:             }
                   3383:             $datatable .= '</span></fieldset>'.
1.267     raeburn  3384:                           '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
                   3385:                           '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>';
                   3386:             if (ref($settings->{$item}->{'custom'}) eq 'HASH') {
                   3387:                 my %custom = %{$settings->{$item}->{'custom'}};
                   3388:                 if (keys(%custom) > 0) {
                   3389:                     foreach my $key (sort(keys(%custom))) {
                   3390:                         $datatable .= '<tr><td><span class="LC_nobreak">'.
                   3391:                                       '<label><input type="checkbox" name="ltitools_customdel_'.$i.'" value="'.
                   3392:                                       $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
                   3393:                                       '<td><input type="text" name="ltitools_customval_'.$key.'_'.$i.'"'.
                   3394:                                       ' value="'.$custom{$key}.'" /></td></tr>';
                   3395:                     }
                   3396:                 }
                   3397:             }
                   3398:             $datatable .= '<tr><td><span class="LC_nobreak">'.
                   3399:                           '<label><input type="checkbox" name="ltitools_customadd" value="'.$i.'" />'.
                   3400:                           &mt('Add').'</label></span></td><td><input type="text" name="ltitools_custom_name_'.$i.'" />'.
                   3401:                           '</td><td><input type="text" name="ltitools_custom_value_'.$i.'" /></td></tr>';
                   3402:             $datatable .= '</table></fieldset></td></tr>'."\n";
                   3403:             $itemcount ++;
                   3404:         }
                   3405:     }
                   3406:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   3407:     my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'ltitools_add_pos'".');"';
                   3408:     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
                   3409:                   '<input type="hidden" name="ltitools_maxnum" value="'.$maxnum.'" />'."\n".
                   3410:                   '<select name="ltitools_add_pos"'.$chgstr.'>';
                   3411:     for (my $k=0; $k<$maxnum+1; $k++) {
                   3412:         my $vpos = $k+1;
                   3413:         my $selstr;
                   3414:         if ($k == $maxnum) {
                   3415:             $selstr = ' selected="selected" ';
                   3416:         }
                   3417:         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   3418:     }
                   3419:     $datatable .= '</select>&nbsp;'."\n".
                   3420:                   '<input type="checkbox" name="ltitools_add" value="1" />'.&mt('Add').'</td>'."\n".
                   3421:                   '<td colspan="2">'.
                   3422:                   '<fieldset><legend>'.&mt('Required settings').'</legend>'.
                   3423:                   '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="30" name="ltitools_add_title" value="" /></span> '."\n".
                   3424:                   ('&nbsp;'x2).
                   3425:                   '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_add_version">'.
                   3426:                   '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
                   3427:                   ('&nbsp;'x2).
                   3428:                   '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_add_msgtype">'.
                   3429:                   '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
                   3430:                   '<br />'.
                   3431:                   '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="30" name="ltitools_add_url" value="" /></span> '."\n".
                   3432:                   ('&nbsp;'x2).
                   3433:                   '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="ltitools_add_key" value="" /></span> '."\n".
                   3434:                   ('&nbsp;'x2).
                   3435:                   '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="ltitools_add_secret" value="" />'.
                   3436:                   '<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".
                   3437:                   '</fieldset>'.
                   3438:                   '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
                   3439:                   '<span class="LC_nobreak">'.&mt('Display target:');
                   3440:     my %defaultdisp;
                   3441:     $defaultdisp{'iframe'} = ' checked="checked"';
                   3442:     foreach my $disp ('iframe','window') {
                   3443:         $datatable .= '<label><input type="radio" name="ltitools_add_target" value="'.$disp.'"'.$defaultdisp{$disp}.' />'.
                   3444:                       $lt{$disp}.'</label>'.('&nbsp;'x2);
                   3445:     }
                   3446:     $datatable .= ('&nbsp;'x4);
                   3447:     foreach my $dimen ('width','height') {
                   3448:         $datatable .= '<label>'.$lt{$dimen}.'&nbsp;'.
                   3449:                       '<input type="text" name="ltitools_add_'.$dimen.'" size="5" /></label>'.
                   3450:                       ('&nbsp;'x2);
                   3451:     }
                   3452:     $datatable .= '<br />';
                   3453:     foreach my $extra ('passback','roster') {
                   3454:         $datatable .= $lt{$extra}.'&nbsp;'.
                   3455:                       '<label><input type="radio" name="ltitools_add_'.$extra.'" value="1" />'.
                   3456:                       &mt('Yes').'</label>'.('&nbsp;'x2).
                   3457:                       '<label><input type="radio" name="ltitools_add_'.$extra.'" value="0" checked="checked" />'.
                   3458:                       &mt('No').'</label>'.('&nbsp;'x4);
                   3459:     }
                   3460:     $datatable .= '<br /><br /><span class="LC_nobreak">'.$lt{'icon'}.':&nbsp;'.
                   3461:                   '('.&mt('if larger than 21x21 pixels, image will be scaled').')&nbsp;';
                   3462:     if ($switchserver) {
                   3463:         $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   3464:     } else {
                   3465:         $datatable .= '<input type="file" name="ltitools_add_image" value="" />';
                   3466:     }
                   3467:     $datatable .= '</span></fieldset>'.
                   3468:                   '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
                   3469:                   '<span class="LC_nobreak">';
                   3470:     foreach my $field (@fields) {
                   3471:         $datatable .= '<label>'.
                   3472:                       '<input type="checkbox" name="ltitools_add_fields" value="'.$field.'" />'.
                   3473:                       $lt{$field}.'</label>'.('&nbsp;' x2);
                   3474:     }
                   3475:     $datatable .= '</span></fieldset>'.
                   3476:                   '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
                   3477:     foreach my $role (@courseroles) {
                   3478:         my ($checked,$checkednone);
                   3479:         $datatable .= '<td align="center">'.
                   3480:                       &Apache::lonnet::plaintext($role,'Course').'<br />'.
                   3481:                       '<select name="ltitools_add_roles_'.$role.'">'.
                   3482:                       '<option value="" selected="selected">'.&mt('Select').'</option>';
                   3483:         foreach my $ltirole (@ltiroles) {
                   3484:             $datatable .= '<option value="'.$ltirole.'">'.$ltirole.'</option>';
                   3485:         }
                   3486:         $datatable .= '</select></td>';
                   3487:     }
                   3488:     $datatable .= '</tr></table></fieldset>'.
1.273     raeburn  3489:                   '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
                   3490:     foreach my $item ('label','title','target') {
                   3491:          $datatable .= '<label>'.
                   3492:                        '<input type="checkbox" name="ltitools_courseconfig" value="'.$item.'" checked="checked" />'.
                   3493:                        $lt{'crs'.$item}.'</label>'.('&nbsp;' x2)."\n";
                   3494:     }
                   3495:     $datatable .= '</span></fieldset>'.
1.267     raeburn  3496:                   '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
                   3497:                   '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
                   3498:                   '<tr><td><span class="LC_nobreak">'.
                   3499:                   '<label><input type="checkbox" name="ltitools_add_custom" value="1" />'.
                   3500:                   &mt('Add').'</label></span></td><td><input type="text" name="ltitools_add_custom_name" />'.
                   3501:                   '</td><td><input type="text" name="ltitools_add_custom_value" /></td></tr>'.
                   3502:                   '</table></fieldset></td></tr>'."\n".
                   3503:                   '</td>'."\n".
                   3504:                   '</tr>'."\n";
                   3505:     $itemcount ++;
                   3506:     return $datatable;
                   3507: }
                   3508: 
                   3509: sub ltitools_names {
                   3510:     my %lt = &Apache::lonlocal::texthash(
                   3511:                                           'title'     => 'Title',
                   3512:                                           'version'   => 'Version',
                   3513:                                           'msgtype'   => 'Message Type',
                   3514:                                           'url'       => 'URL',
                   3515:                                           'key'       => 'Key',
                   3516:                                           'secret'    => 'Secret',
                   3517:                                           'icon'      => 'Icon',   
                   3518:                                           'user'      => 'Username:domain',
                   3519:                                           'fullname'  => 'Full Name',
                   3520:                                           'firstname' => 'First Name',
                   3521:                                           'lastname'  => 'Last Name',
                   3522:                                           'email'     => 'E-mail',
                   3523:                                           'roles'     => 'Role',
                   3524:                                           'window'    => 'Window/Tab',
                   3525:                                           'iframe'    => 'iFrame',
                   3526:                                           'height'    => 'Height',
                   3527:                                           'width'     => 'Width',
                   3528:                                           'passback'  => 'Tool can return grades:',
                   3529:                                           'roster'    => 'Tool can retrieve roster:',
1.273     raeburn  3530:                                           'crstarget' => 'Display target',
                   3531:                                           'crslabel'  => 'Course label',
                   3532:                                           'crstitle'  => 'Course title', 
1.267     raeburn  3533:                                         );
                   3534:     return %lt;
                   3535: }
                   3536: 
1.121     raeburn  3537: sub print_coursedefaults {
1.139     raeburn  3538:     my ($position,$dom,$settings,$rowtotal) = @_;
1.192     raeburn  3539:     my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121     raeburn  3540:     my $itemcount = 1;
1.192     raeburn  3541:     my %choices =  &Apache::lonlocal::texthash (
                   3542:         canuse_pdfforms      => 'Course/Community users can create/upload PDF forms',
1.198     raeburn  3543:         uploadquota          => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.192     raeburn  3544:         anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
                   3545:         coursecredits        => 'Credits can be specified for courses',
1.257     raeburn  3546:         uselcmath            => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
                   3547:         usejsme              => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
                   3548:         postsubmit           => 'Disable submit button/keypress following student submission',
1.276     raeburn  3549:         canclone             => "People who may clone a course (besides course's owner and coordinators)",
                   3550:         mysqltables          => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.192     raeburn  3551:     );
1.198     raeburn  3552:     my %staticdefaults = (
                   3553:                            anonsurvey_threshold => 10,
                   3554:                            uploadquota          => 500,
1.257     raeburn  3555:                            postsubmit           => 60,
1.276     raeburn  3556:                            mysqltables          => 172800,
1.198     raeburn  3557:                          );
1.139     raeburn  3558:     if ($position eq 'top') {
1.257     raeburn  3559:         %defaultchecked = (
                   3560:                             'canuse_pdfforms' => 'off',
                   3561:                             'uselcmath'       => 'on',
                   3562:                             'usejsme'         => 'on',
1.264     raeburn  3563:                             'canclone'        => 'none', 
1.257     raeburn  3564:                           );
                   3565:         @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.139     raeburn  3566:         ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.257     raeburn  3567:                                                      \%choices,$itemcount);
1.264     raeburn  3568:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   3569:         $datatable .=
                   3570:             '<tr'.$css_class.'><td valign="top">'.
                   3571:             '<span class="LC_nobreak">'.$choices{'canclone'}.
                   3572:             '</span></td><td class="LC_left_item">';
                   3573:         my $currcanclone = 'none';
                   3574:         my $onclick;
                   3575:         my @cloneoptions = ('none','domain');
                   3576:         my %clonetitles = (
                   3577:                              none     => 'No additional course requesters',
                   3578:                              domain   => "Any course requester in course's domain",
                   3579:                              instcode => 'Course requests for official courses ...',
                   3580:                           );
                   3581:         my (%codedefaults,@code_order,@posscodes);
                   3582:         if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
                   3583:                                                     \@code_order) eq 'ok') {
                   3584:             if (@code_order > 0) {
                   3585:                 push(@cloneoptions,'instcode');
                   3586:                 $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
                   3587:             }
                   3588:         }
                   3589:         if (ref($settings) eq 'HASH') {
                   3590:             if ($settings->{'canclone'}) {
                   3591:                 if (ref($settings->{'canclone'}) eq 'HASH') {
                   3592:                     if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
                   3593:                         if (@code_order > 0) {
                   3594:                             $currcanclone = 'instcode';
                   3595:                             @posscodes = @{$settings->{'canclone'}{'instcode'}};
                   3596:                         }
                   3597:                     }
                   3598:                 } elsif ($settings->{'canclone'} eq 'domain') {
                   3599:                     $currcanclone = $settings->{'canclone'};
                   3600:                 }
                   3601:             }
                   3602:         } 
                   3603:         foreach my $option (@cloneoptions) {
                   3604:             my ($checked,$additional);
                   3605:             if ($currcanclone eq $option) {
                   3606:                 $checked = ' checked="checked"';
                   3607:             }
                   3608:             if ($option eq 'instcode') {
                   3609:                 if (@code_order) {
                   3610:                     my $show = 'none';
                   3611:                     if ($checked) {
                   3612:                         $show = 'block';
                   3613:                     }
                   3614:                     $additional = '<div id="cloneinstcode" style="display:'.$show.'" />'.
                   3615:                                   &mt('Institutional codes for new and cloned course have identical:').
                   3616:                                   '<br />';
                   3617:                     foreach my $item (@code_order) {
                   3618:                         my $codechk;
                   3619:                         if ($checked) {
                   3620:                             if (grep(/^\Q$item\E$/,@posscodes)) {
                   3621:                                 $codechk = ' checked="checked"';
                   3622:                             }
                   3623:                         }
                   3624:                         $additional .= '<label>'.
                   3625:                                        '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
                   3626:                                        $item.'</label>';
                   3627:                     }
                   3628:                     $additional .= ('&nbsp;'x2).'('.&mt('check as many as needed').')</div>';
                   3629:                 }
                   3630:             }
                   3631:             $datatable .=
                   3632:                 '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
                   3633:                 ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
                   3634:                 '</label>&nbsp;'.$additional.'</span><br />';
                   3635:         }
                   3636:         $datatable .= '</td>'.
                   3637:                       '</tr>';
                   3638:         $itemcount ++;
1.139     raeburn  3639:     } else {
                   3640:         $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.276     raeburn  3641:         my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout,%currmysql);
1.192     raeburn  3642:         my $currusecredits = 0;
1.257     raeburn  3643:         my $postsubmitclient = 1;
1.271     raeburn  3644:         my @types = ('official','unofficial','community','textbook','placement');
1.139     raeburn  3645:         if (ref($settings) eq 'HASH') {
                   3646:             $currdefresponder = $settings->{'anonsurvey_threshold'};
1.198     raeburn  3647:             if (ref($settings->{'uploadquota'}) eq 'HASH') {
                   3648:                 foreach my $type (keys(%{$settings->{'uploadquota'}})) {
                   3649:                     $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
                   3650:                 }
                   3651:             }
1.192     raeburn  3652:             if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.257     raeburn  3653:                 foreach my $type (@types) {
                   3654:                     next if ($type eq 'community');
                   3655:                     $defcredits{$type} = $settings->{'coursecredits'}->{$type};
                   3656:                     if ($defcredits{$type} ne '') {
                   3657:                         $currusecredits = 1;
                   3658:                     }
                   3659:                 }
                   3660:             }
                   3661:             if (ref($settings->{'postsubmit'}) eq 'HASH') {
                   3662:                 if ($settings->{'postsubmit'}->{'client'} eq 'off') {
                   3663:                     $postsubmitclient = 0;
                   3664:                     foreach my $type (@types) {
                   3665:                         $deftimeout{$type} = $staticdefaults{'postsubmit'};
                   3666:                     }
                   3667:                 } else {
                   3668:                     foreach my $type (@types) {
                   3669:                         if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
                   3670:                             if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
                   3671:                                 $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type}; 
                   3672:                             } else {
                   3673:                                 $deftimeout{$type} = $staticdefaults{'postsubmit'};
                   3674:                             }
                   3675:                         } else {
                   3676:                             $deftimeout{$type} = $staticdefaults{'postsubmit'};
                   3677:                         }
                   3678:                     }
                   3679:                 }
                   3680:             } else {
                   3681:                 foreach my $type (@types) {
                   3682:                     $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.192     raeburn  3683:                 }
                   3684:             }
1.276     raeburn  3685:             if (ref($settings->{'mysqltables'}) eq 'HASH') {
                   3686:                 foreach my $type (keys(%{$settings->{'mysqltables'}})) {
                   3687:                     $currmysql{$type} = $settings->{'mysqltables'}{$type};
                   3688:                 }
                   3689:             } else {
                   3690:                 foreach my $type (@types) {
                   3691:                     $currmysql{$type} = $staticdefaults{'mysqltables'};
                   3692:                 }
                   3693:             }
1.258     raeburn  3694:         } else {
                   3695:             foreach my $type (@types) {
                   3696:                 $deftimeout{$type} = $staticdefaults{'postsubmit'};
                   3697:             }
1.139     raeburn  3698:         }
                   3699:         if (!$currdefresponder) {
1.198     raeburn  3700:             $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139     raeburn  3701:         } elsif ($currdefresponder < 1) {
                   3702:             $currdefresponder = 1;
                   3703:         }
1.198     raeburn  3704:         foreach my $type (@types) {
                   3705:             if ($curruploadquota{$type} eq '') {
                   3706:                 $curruploadquota{$type} = $staticdefaults{'uploadquota'};
                   3707:             }
                   3708:         }
1.139     raeburn  3709:         $datatable .=
1.192     raeburn  3710:                 '<tr'.$css_class.'><td><span class="LC_nobreak">'.
                   3711:                 $choices{'anonsurvey_threshold'}.
1.139     raeburn  3712:                 '</span></td>'.
                   3713:                 '<td class="LC_right_item"><span class="LC_nobreak">'.
                   3714:                 '<input type="text" name="anonsurvey_threshold"'.
                   3715:                 ' value="'.$currdefresponder.'" size="5" /></span>'.
1.230     raeburn  3716:                 '</td></tr>'."\n";
                   3717:         $itemcount ++;
                   3718:         $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   3719:         $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
                   3720:                       $choices{'uploadquota'}.
                   3721:                       '</span></td>'.
                   3722:                       '<td align="right" class="LC_right_item">'.
                   3723:                       '<table><tr>';
1.198     raeburn  3724:         foreach my $type (@types) {
                   3725:             $datatable .= '<td align="center">'.&mt($type).'<br />'.
                   3726:                            '<input type="text" name="uploadquota_'.$type.'"'.
                   3727:                            ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
                   3728:         }
                   3729:         $datatable .= '</tr></table></td></tr>'."\n";
1.230     raeburn  3730:         $itemcount ++;
1.236     raeburn  3731:         my $onclick = "toggleDisplay(this.form,'credits');";
1.210     raeburn  3732:         my $display = 'none';
1.192     raeburn  3733:         if ($currusecredits) {
                   3734:             $display = 'block';
                   3735:         }
                   3736:         my $additional = '<div id="credits" style="display: '.$display.'">'.
1.257     raeburn  3737:                          '<i>'.&mt('Default credits').'</i><br /><table><tr>';
                   3738:         foreach my $type (@types) {
                   3739:             next if ($type eq 'community');
                   3740:             $additional .= '<td align="center">'.&mt($type).'<br />'.
                   3741:                            '<input type="text" name="'.$type.'_credits"'.
1.258     raeburn  3742:                            ' value="'.$defcredits{$type}.'" size="3" /></td>';
1.257     raeburn  3743:         }
                   3744:         $additional .= '</tr></table></div>'."\n";
1.192     raeburn  3745:         %defaultchecked = ('coursecredits' => 'off');
                   3746:         @toggles = ('coursecredits');
                   3747:         my $current = {
                   3748:                         'coursecredits' => $currusecredits,
                   3749:                       };
                   3750:         (my $table,$itemcount) =
                   3751:             &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.257     raeburn  3752:                                \%choices,$itemcount,$onclick,$additional,'left');
                   3753:         $datatable .= $table;
                   3754:         $onclick = "toggleDisplay(this.form,'studentsubmission');";
                   3755:         my $display = 'none';
                   3756:         if ($postsubmitclient) {
                   3757:             $display = 'block';
                   3758:         }
                   3759:         $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.259     raeburn  3760:                       &mt('Number of seconds submit is disabled').'<br />'.
                   3761:                       '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
                   3762:                       '<table><tr>';
1.257     raeburn  3763:         foreach my $type (@types) {
                   3764:             $additional .= '<td align="center">'.&mt($type).'<br />'.
                   3765:                            '<input type="text" name="'.$type.'_timeout" value="'.
                   3766:                            $deftimeout{$type}.'" size="5" /></td>';
                   3767:         }
                   3768:         $additional .= '</tr></table></div>'."\n";
                   3769:         %defaultchecked = ('postsubmit' => 'on');
                   3770:         @toggles = ('postsubmit');
1.280     raeburn  3771:         $current = {
                   3772:                        'postsubmit' => $postsubmitclient,
                   3773:                    };
1.257     raeburn  3774:         ($table,$itemcount) =
                   3775:             &radiobutton_prefs($current,\@toggles,\%defaultchecked,
                   3776:                                \%choices,$itemcount,$onclick,$additional,'left');
1.192     raeburn  3777:         $datatable .= $table;
1.276     raeburn  3778:         $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   3779:         $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
                   3780:                       $choices{'mysqltables'}.
                   3781:                       '</span></td>'.
                   3782:                       '<td align="right" class="LC_right_item">'.
                   3783:                       '<table><tr>';
                   3784:         foreach my $type (@types) {
                   3785:             $datatable .= '<td align="center">'.&mt($type).'<br />'.
                   3786:                            '<input type="text" name="mysqltables_'.$type.'"'.
                   3787:                            ' value="'.$currmysql{$type}.'" size="5" /></td>';
                   3788:         }
                   3789:         $datatable .= '</tr></table></td></tr>'."\n";
                   3790:         $itemcount ++;
                   3791: 
1.139     raeburn  3792:     }
1.192     raeburn  3793:     $$rowtotal += $itemcount;
1.121     raeburn  3794:     return $datatable;
1.118     jms      3795: }
                   3796: 
1.231     raeburn  3797: sub print_selfenrollment {
                   3798:     my ($position,$dom,$settings,$rowtotal) = @_;
                   3799:     my ($css_class,$datatable);
                   3800:     my $itemcount = 1;
1.271     raeburn  3801:     my @types = ('official','unofficial','community','textbook','placement');
1.231     raeburn  3802:     if (($position eq 'top') || ($position eq 'middle')) {
1.232     raeburn  3803:         my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
                   3804:         my %descs = &Apache::lonuserutils::selfenroll_default_descs();
1.231     raeburn  3805:         my @rows;
                   3806:         my $key;
                   3807:         if ($position eq 'top') {
                   3808:             $key = 'admin'; 
                   3809:             if (ref($rowsref) eq 'ARRAY') {
                   3810:                 @rows = @{$rowsref};
                   3811:             }
                   3812:         } elsif ($position eq 'middle') {
                   3813:             $key = 'default';
                   3814:             @rows = ('types','registered','approval','limit');
                   3815:         }
                   3816:         foreach my $row (@rows) {
                   3817:             if (defined($titlesref->{$row})) {
                   3818:                 $itemcount ++;
                   3819:                 $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   3820:                 $datatable .= '<tr'.$css_class.'>'.
                   3821:                               '<td>'.$titlesref->{$row}.'</td>'.
                   3822:                               '<td class="LC_left_item">'.
                   3823:                               '<table><tr>';
                   3824:                 my (%current,%currentcap);
                   3825:                 if (ref($settings) eq 'HASH') {
                   3826:                     if (ref($settings->{$key}) eq 'HASH') {
                   3827:                         foreach my $type (@types) {
                   3828:                             if (ref($settings->{$key}->{$type}) eq 'HASH') {
                   3829:                                 $current{$type} = $settings->{$key}->{$type}->{$row};
                   3830:                             }
                   3831:                             if (($row eq 'limit') && ($key eq 'default')) {
                   3832:                                 if (ref($settings->{$key}->{$type}) eq 'HASH') {
                   3833:                                     $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
                   3834:                                 }
                   3835:                             }
                   3836:                         }
                   3837:                     }
                   3838:                 }
                   3839:                 my %roles = (
                   3840:                              '0' => &Apache::lonnet::plaintext('dc'),
                   3841:                             ); 
                   3842:             
                   3843:                 foreach my $type (@types) {
                   3844:                     unless (($row eq 'registered') && ($key eq 'default')) {
                   3845:                         $datatable .= '<th>'.&mt($type).'</th>';
                   3846:                     }
                   3847:                 }
                   3848:                 unless (($row eq 'registered') && ($key eq 'default')) {
                   3849:                     $datatable .= '</tr><tr>';
                   3850:                 }
                   3851:                 foreach my $type (@types) {
                   3852:                     if ($type eq 'community') {
                   3853:                         $roles{'1'} = &mt('Community personnel');
                   3854:                     } else {
                   3855:                         $roles{'1'} = &mt('Course personnel');
                   3856:                     }
                   3857:                     $datatable .= '<td style="vertical-align: top">';
                   3858:                     if ($position eq 'top') {
                   3859:                         my %checked;
                   3860:                         if ($current{$type} eq '0') {
                   3861:                             $checked{'0'} = ' checked="checked"';
                   3862:                         } else {
                   3863:                             $checked{'1'} = ' checked="checked"';
                   3864:                         }
                   3865:                         foreach my $role ('1','0') {
                   3866:                             $datatable .= '<span class="LC_nobreak"><label>'.
                   3867:                                           '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
                   3868:                                           'value="'.$role.'"'.$checked{$role}.' />'.
                   3869:                                           $roles{$role}.'</label></span> ';
                   3870:                         }
                   3871:                     } else {
                   3872:                         if ($row eq 'types') {
                   3873:                             my %checked;
                   3874:                             if ($current{$type} =~ /^(all|dom)$/) {
                   3875:                                 $checked{$1} = ' checked="checked"';
                   3876:                             } else {
                   3877:                                 $checked{''} = ' checked="checked"';
                   3878:                             }
                   3879:                             foreach my $val ('','dom','all') {
                   3880:                                 $datatable .= '<span class="LC_nobreak"><label>'.
                   3881:                                               '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
                   3882:                                               'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
                   3883:                             }
                   3884:                         } elsif ($row eq 'registered') {
                   3885:                             my %checked;
                   3886:                             if ($current{$type} eq '1') {
                   3887:                                 $checked{'1'} = ' checked="checked"';
                   3888:                             } else {
                   3889:                                 $checked{'0'} = ' checked="checked"';
                   3890:                             }
                   3891:                             foreach my $val ('0','1') {
                   3892:                                 $datatable .= '<span class="LC_nobreak"><label>'.
                   3893:                                               '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
                   3894:                                               'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
                   3895:                             }
                   3896:                         } elsif ($row eq 'approval') {
                   3897:                             my %checked;
                   3898:                             if ($current{$type} =~ /^([12])$/) {
                   3899:                                 $checked{$1} = ' checked="checked"';
                   3900:                             } else {
                   3901:                                 $checked{'0'} = ' checked="checked"';
                   3902:                             }
                   3903:                             for my $val (0..2) {
                   3904:                                 $datatable .= '<span class="LC_nobreak"><label>'.
                   3905:                                               '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
                   3906:                                               'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
                   3907:                             }
                   3908:                         } elsif ($row eq 'limit') {
                   3909:                             my %checked;
                   3910:                             if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
                   3911:                                 $checked{$1} = ' checked="checked"';
                   3912:                             } else {
                   3913:                                 $checked{'none'} = ' checked="checked"';
                   3914:                             }
                   3915:                             my $cap;
                   3916:                             if ($currentcap{$type} =~ /^\d+$/) {
                   3917:                                 $cap = $currentcap{$type};
                   3918:                             }
                   3919:                             foreach my $val ('none','allstudents','selfenrolled') {
                   3920:                                 $datatable .= '<span class="LC_nobreak"><label>'.
                   3921:                                               '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
                   3922:                                               'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
                   3923:                             }
                   3924:                             $datatable .= '<br />'.
                   3925:                                           '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
                   3926:                                           '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
                   3927:                                           '</span>'; 
                   3928:                         }
                   3929:                     }
                   3930:                     $datatable .= '</td>';
                   3931:                 }
                   3932:                 $datatable .= '</tr>';
                   3933:             }
                   3934:             $datatable .= '</table></td></tr>';
                   3935:         }
                   3936:     } elsif ($position eq 'bottom') {
1.235     raeburn  3937:         $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
                   3938:     }
                   3939:     $$rowtotal += $itemcount;
                   3940:     return $datatable;
                   3941: }
                   3942: 
                   3943: sub print_validation_rows {
                   3944:     my ($caller,$dom,$settings,$rowtotal) = @_;
                   3945:     my ($itemsref,$namesref,$fieldsref);
                   3946:     if ($caller eq 'selfenroll') { 
                   3947:         ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
                   3948:     } elsif ($caller eq 'requestcourses') {
                   3949:         ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
                   3950:     }
                   3951:     my %currvalidation;
                   3952:     if (ref($settings) eq 'HASH') {
                   3953:         if (ref($settings->{'validation'}) eq 'HASH') {
                   3954:             %currvalidation = %{$settings->{'validation'}};
1.231     raeburn  3955:         }
1.235     raeburn  3956:     }
                   3957:     my $datatable;
                   3958:     my $itemcount = 0;
                   3959:     foreach my $item (@{$itemsref}) {
                   3960:         my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   3961:         $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
                   3962:                       $namesref->{$item}.
                   3963:                       '</span></td>'.
                   3964:                       '<td class="LC_left_item">';
                   3965:         if (($item eq 'url') || ($item eq 'button')) {
                   3966:             $datatable .= '<span class="LC_nobreak">'.
                   3967:                           '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
                   3968:                           ' value="'.$currvalidation{$item}.'" size="50" /></span>';
                   3969:         } elsif ($item eq 'fields') {
                   3970:             my @currfields;
                   3971:             if (ref($currvalidation{$item}) eq 'ARRAY') {
                   3972:                 @currfields = @{$currvalidation{$item}};
                   3973:             }
                   3974:             foreach my $field (@{$fieldsref}) {
                   3975:                 my $check = '';
                   3976:                 if (grep(/^\Q$field\E$/,@currfields)) {
                   3977:                     $check = ' checked="checked"';
                   3978:                 }
                   3979:                 $datatable .= '<span class="LC_nobreak"><label>'.
                   3980:                               '<input type="checkbox" name="'.$caller.'_validation_fields"'.
                   3981:                               ' value="'.$field.'"'.$check.' />'.$field.
                   3982:                               '</label></span> ';
                   3983:             }
                   3984:         } elsif ($item eq 'markup') {
                   3985:             $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5" wrap="soft">'.
                   3986:                            $currvalidation{$item}.
1.231     raeburn  3987:                               '</textarea>';
1.235     raeburn  3988:         }
                   3989:         $datatable .= '</td></tr>'."\n";
                   3990:         if (ref($rowtotal)) {
1.231     raeburn  3991:             $itemcount ++;
                   3992:         }
                   3993:     }
1.235     raeburn  3994:     if ($caller eq 'requestcourses') {
                   3995:         my %currhash;
1.248     raeburn  3996:         if (ref($settings) eq 'HASH') {
                   3997:             if (ref($settings->{'validation'}) eq 'HASH') {
                   3998:                 if ($settings->{'validation'}{'dc'} ne '') {
                   3999:                     $currhash{$settings->{'validation'}{'dc'}} = 1;
                   4000:                 }
1.235     raeburn  4001:             }
                   4002:         }
                   4003:         my $numinrow = 2;
                   4004:         my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
                   4005:                                                        'validationdc',%currhash);
1.247     raeburn  4006:         my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   4007:         $datatable .= '</td></tr><tr'.$css_class.'><td>';
1.235     raeburn  4008:         if ($numdc > 1) {
1.247     raeburn  4009:             $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.235     raeburn  4010:         } else {
1.247     raeburn  4011:             $datatable .=  &mt('Course creation processed as: ');
1.235     raeburn  4012:         }
1.247     raeburn  4013:         $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.235     raeburn  4014:         $itemcount ++;
                   4015:     }
                   4016:     if (ref($rowtotal)) {
                   4017:         $$rowtotal += $itemcount;
                   4018:     }
1.231     raeburn  4019:     return $datatable;
                   4020: }
                   4021: 
1.137     raeburn  4022: sub print_usersessions {
                   4023:     my ($position,$dom,$settings,$rowtotal) = @_;
1.279     raeburn  4024:     my ($css_class,$datatable,$itemcount,%checked,%choices);
1.275     raeburn  4025:     my (%by_ip,%by_location,@intdoms,@instdoms);
                   4026:     &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.145     raeburn  4027: 
                   4028:     my @alldoms = &Apache::lonnet::all_domains();
1.152     raeburn  4029:     my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149     raeburn  4030:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152     raeburn  4031:     my %altids = &id_for_thisdom(%servers);
1.145     raeburn  4032:     if ($position eq 'top') {
1.152     raeburn  4033:         if (keys(%serverhomes) > 1) {
1.145     raeburn  4034:             my %spareid = &current_offloads_to($dom,$settings,\%servers);
1.261     raeburn  4035:             my $curroffloadnow;
                   4036:             if (ref($settings) eq 'HASH') {
                   4037:                 if (ref($settings->{'offloadnow'}) eq 'HASH') {
                   4038:                     $curroffloadnow = $settings->{'offloadnow'};
                   4039:                 }
                   4040:             }
                   4041:             $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$curroffloadnow,$rowtotal);
1.145     raeburn  4042:         } else {
1.140     raeburn  4043:             $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.279     raeburn  4044:                           &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.').
                   4045:                           '</td></tr>';
1.140     raeburn  4046:         }
1.137     raeburn  4047:     } else {
1.279     raeburn  4048:         my %titles = &usersession_titles();
                   4049:         my ($prefix,@types);
                   4050:         if ($position eq 'bottom') {
                   4051:             $prefix = 'remote';
                   4052:             @types = ('version','excludedomain','includedomain');
1.145     raeburn  4053:         } else {
1.279     raeburn  4054:             $prefix = 'hosted';
                   4055:             @types = ('excludedomain','includedomain');
                   4056:         }
                   4057:         ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
                   4058:     }
                   4059:     $$rowtotal += $itemcount;
                   4060:     return $datatable;
                   4061: }
                   4062: 
                   4063: sub rules_by_location {
                   4064:     my ($settings,$prefix,$by_location,$by_ip,$types,$titles) = @_; 
                   4065:     my ($datatable,$itemcount,$css_class);
                   4066:     if (keys(%{$by_location}) == 0) {
                   4067:         $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   4068:         $datatable = '<tr'.$css_class.'><td colspan="2">'.
                   4069:                      &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.').
                   4070:                      '</td></tr>';
                   4071:         $itemcount = 1;
                   4072:     } else {
                   4073:         $itemcount = 0;
                   4074:         my $numinrow = 5;
                   4075:         my (%current,%checkedon,%checkedoff);
                   4076:         my @locations = sort(keys(%{$by_location}));
                   4077:         foreach my $type (@{$types}) {
                   4078:             $checkedon{$type} = '';
                   4079:             $checkedoff{$type} = ' checked="checked"';
                   4080:         }
                   4081:         if (ref($settings) eq 'HASH') {
                   4082:             if (ref($settings->{$prefix}) eq 'HASH') {
                   4083:                 foreach my $key (keys(%{$settings->{$prefix}})) {
                   4084:                     $current{$key} = $settings->{$prefix}{$key};
                   4085:                     if ($key eq 'version') {
                   4086:                         if ($current{$key} ne '') {
1.145     raeburn  4087:                             $checkedon{$key} = ' checked="checked"';
                   4088:                             $checkedoff{$key} = '';
                   4089:                         }
1.279     raeburn  4090:                     } elsif (ref($current{$key}) eq 'ARRAY') {
                   4091:                         $checkedon{$key} = ' checked="checked"';
                   4092:                         $checkedoff{$key} = '';
1.137     raeburn  4093:                     }
                   4094:                 }
                   4095:             }
1.279     raeburn  4096:         }
                   4097:         foreach my $type (@{$types}) {
                   4098:             next if ($type ne 'version' && !@locations);
                   4099:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   4100:             $datatable .= '<tr'.$css_class.'>
                   4101:                            <td><span class="LC_nobreak">'.$titles->{$type}.'</span><br />
                   4102:                            <span class="LC_nobreak">&nbsp;
                   4103:                            <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>&nbsp;
                   4104:                            <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
                   4105:             if ($type eq 'version') {
                   4106:                 my @lcversions = &Apache::lonnet::all_loncaparevs();
                   4107:                 my $selector = '<select name="'.$prefix.'_version">';
                   4108:                 foreach my $version (@lcversions) {
                   4109:                     my $selected = '';
                   4110:                     if ($current{'version'} eq $version) {
                   4111:                         $selected = ' selected="selected"';
1.145     raeburn  4112:                     }
1.279     raeburn  4113:                     $selector .= ' <option value="'.$version.'"'.
                   4114:                                  $selected.'>'.$version.'</option>';
                   4115:                 }
                   4116:                 $selector .= '</select> ';
                   4117:                 $datatable .= &mt('remote server must be version: [_1] or later',$selector);
                   4118:             } else {
                   4119:                 $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
                   4120:                              'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
                   4121:                              ' />'.('&nbsp;'x2).
                   4122:                              '<input type="button" value="'.&mt('uncheck all').'" '.
                   4123:                              'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
                   4124:                              "\n".
                   4125:                              '</div><div><table>';
                   4126:                 my $rem;
                   4127:                 for (my $i=0; $i<@locations; $i++) {
                   4128:                     my ($showloc,$value,$checkedtype);
                   4129:                     if (ref($by_location->{$locations[$i]}) eq 'ARRAY') {
                   4130:                         my $ip = $by_location->{$locations[$i]}->[0];
                   4131:                         if (ref($by_ip->{$ip}) eq 'ARRAY') {
                   4132:                             $value = join(':',@{$by_ip->{$ip}});
                   4133:                             $showloc = join(', ',@{$by_ip->{$ip}});
                   4134:                             if (ref($current{$type}) eq 'ARRAY') {
                   4135:                                 foreach my $loc (@{$by_ip->{$ip}}) {
                   4136:                                     if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
                   4137:                                         $checkedtype = ' checked="checked"';
                   4138:                                         last;
1.145     raeburn  4139:                                     }
1.138     raeburn  4140:                                 }
                   4141:                             }
                   4142:                         }
1.137     raeburn  4143:                     }
1.279     raeburn  4144:                     $rem = $i%($numinrow);
                   4145:                     if ($rem == 0) {
                   4146:                         if ($i > 0) {
                   4147:                             $datatable .= '</tr>';
                   4148:                         }
                   4149:                         $datatable .= '<tr>';
                   4150:                     }
                   4151:                     $datatable .= '<td class="LC_left_item">'.
                   4152:                                   '<span class="LC_nobreak"><label>'.
                   4153:                                   '<input type="checkbox" name="'.$prefix.'_'.$type.
                   4154:                                   '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
                   4155:                                   '</label></span></td>';
                   4156:                 }
                   4157:                 $rem = @locations%($numinrow);
                   4158:                 my $colsleft = $numinrow - $rem;
                   4159:                 if ($colsleft > 1 ) {
                   4160:                     $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   4161:                                   '&nbsp;</td>';
                   4162:                 } elsif ($colsleft == 1) {
                   4163:                     $datatable .= '<td class="LC_left_item">&nbsp;</td>';
1.137     raeburn  4164:                 }
1.279     raeburn  4165:                 $datatable .= '</tr></table>';
1.137     raeburn  4166:             }
1.279     raeburn  4167:             $datatable .= '</td></tr>';
                   4168:             $itemcount ++;
1.137     raeburn  4169:         }
                   4170:     }
1.279     raeburn  4171:     return ($datatable,$itemcount);
1.137     raeburn  4172: }
                   4173: 
1.275     raeburn  4174: sub print_ssl {
                   4175:     my ($position,$dom,$settings,$rowtotal) = @_;
                   4176:     my ($css_class,$datatable);
                   4177:     my $itemcount = 1;
                   4178:     if ($position eq 'top') {
1.281     raeburn  4179:         my $primary_id = &Apache::lonnet::domain($dom,'primary');
                   4180:         my $intdom = &Apache::lonnet::internet_dom($primary_id);
                   4181:         my $same_institution;
                   4182:         if ($intdom ne '') {
                   4183:             my $internet_names = &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
                   4184:             if (ref($internet_names) eq 'ARRAY') {
                   4185:                 if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
                   4186:                     $same_institution = 1;
                   4187:                 }
                   4188:             }
                   4189:         }
1.275     raeburn  4190:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.281     raeburn  4191:         $datatable = '<tr'.$css_class.'><td colspan="2">';
                   4192:         if ($same_institution) {
                   4193:             my %domservers = &Apache::lonnet::get_servers($dom);
                   4194:             $datatable .= &LONCAPA::SSL::print_certstatus(\%domservers,'web','domprefs');
                   4195:         } else {
                   4196:             $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.");
                   4197:         }
                   4198:         $datatable .= '</td></tr>';
1.275     raeburn  4199:         $itemcount ++;
                   4200:     } else {
                   4201:         my %titles = &ssl_titles();
                   4202:         my (%by_ip,%by_location,@intdoms,@instdoms);
                   4203:         &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
                   4204:         my @alldoms = &Apache::lonnet::all_domains();
                   4205:         my %serverhomes = %Apache::lonnet::serverhomeIDs;
                   4206:         my @domservers = &Apache::lonnet::get_servers($dom);
                   4207:         my %servers = &Apache::lonnet::internet_dom_servers($dom);
                   4208:         my %altids = &id_for_thisdom(%servers);
                   4209:         if ($position eq 'middle') {
                   4210:             foreach my $type ('dom','intdom','other') {
                   4211:                 my %checked;
                   4212:                 $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   4213:                 $datatable .= '<tr'.$css_class.'><td>'.$titles{$type}.'</td>'.
                   4214:                               '<td class="LC_right_item">';
                   4215:                 my $skip; 
                   4216:                 if ($type eq 'dom') {
                   4217:                     unless (keys(%servers) > 1) {
                   4218:                         $datatable .= &mt('Nothing to set here, as there are no other servers/VMs');    
                   4219:                         $skip = 1;
                   4220:                     }
                   4221:                 }
                   4222:                 if ($type eq 'intdom') {
                   4223:                     unless (@instdoms > 1) {
                   4224:                         $datatable .= &mt('Nothing to set here, as there are no other domains for this institution');
                   4225:                         $skip = 1;
                   4226:                     } 
                   4227:                 } elsif ($type eq 'other') {
                   4228:                     if (keys(%by_location) == 0) {
                   4229:                         $datatable .= &mt('Nothing to set here, as there are no other institutions');
                   4230:                         $skip = 1;
                   4231:                     }
                   4232:                 }
                   4233:                 unless ($skip) {
                   4234:                     $checked{'yes'} = ' checked="checked"'; 
                   4235:                     if (ref($settings) eq 'HASH') {
                   4236:                         if (ref($settings->{'connect'}) eq 'HASH') {
                   4237:                             if ($settings->{'connect'}->{$type} =~ /^(no|req)$/) {
                   4238:                                 $checked{$1} = $checked{'yes'};
                   4239:                                 delete($checked{'yes'}); 
                   4240:                             }
                   4241:                         }
                   4242:                     }
                   4243:                     foreach my $option ('no','yes','req') {
                   4244:                         $datatable .= '<span class="LC_nobreak"><label>'.
                   4245:                                       '<input type="radio" name="connect_'.$type.'" '.
                   4246:                                       'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
                   4247:                                       '</label></span>'.('&nbsp;'x2);
                   4248:                     }
                   4249:                 }
                   4250:                 $datatable .= '</td></tr>';
                   4251:                 $itemcount ++; 
                   4252:             }
                   4253:         } else {
                   4254:             my $prefix = 'replication';
                   4255:             my @types = ('certreq','nocertreq');
1.279     raeburn  4256:             if (keys(%by_location) == 0) {
                   4257:                 $datatable .= '<tr'.$css_class.'><td>'.
                   4258:                               &mt('Nothing to set here, as there are no other institutions').
                   4259:                               '</td></tr>';
                   4260:                 $itemcount ++;
1.275     raeburn  4261:             } else {
1.279     raeburn  4262:                 ($datatable,$itemcount) = 
                   4263:                     &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
1.275     raeburn  4264:             }
                   4265:         }
                   4266:     }
                   4267:     $$rowtotal += $itemcount;
                   4268:     return $datatable;
                   4269: }
                   4270: 
                   4271: sub ssl_titles {
                   4272:     return &Apache::lonlocal::texthash (
                   4273:                dom           => 'LON-CAPA servers/VMs from same domain',
                   4274:                intdom        => 'LON-CAPA servers/VMs from same "internet" domain',
                   4275:                other         => 'External LON-CAPA servers/VMs',
                   4276:                connect       => 'Connections to other servers',
                   4277:                replication   => 'Replicating content to other institutions',
                   4278:                certreq       => 'Client certificate required, but specific domains exempt',
                   4279:                nocertreq     => 'No client certificate required, except for specific domains',
                   4280:                no            => 'SSL not used',
                   4281:                yes           => 'SSL Optional (used if available)',
                   4282:                req           => 'SSL Required',
                   4283:     );
1.279     raeburn  4284: }
                   4285: 
                   4286: sub print_trust {
                   4287:     my ($prefix,$dom,$settings,$rowtotal) = @_;
                   4288:     my ($css_class,$datatable,%checked,%choices);
                   4289:     my (%by_ip,%by_location,@intdoms,@instdoms);
                   4290:     &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
                   4291:     my $itemcount = 1;
                   4292:     my %titles = &trust_titles();
                   4293:     my @types = ('exc','inc');
                   4294:     if ($prefix eq 'top') {
                   4295:         $prefix = 'content';
                   4296:     } elsif ($prefix eq 'bottom') {
                   4297:         $prefix = 'msg';
                   4298:     }
                   4299:     ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
                   4300:     $$rowtotal += $itemcount;
                   4301:     return $datatable;
                   4302: }
                   4303: 
                   4304: sub trust_titles {
                   4305:     return &Apache::lonlocal::texthash(
                   4306:                content  => "Access to this domain's content by others",
                   4307:                shared   => "Access to other domain's content by this domain",
                   4308:                enroll   => "Enrollment in this domain's courses by others", 
                   4309:                othcoau  => "Co-author roles in this domain for others",
                   4310:                coaurem  => "Co-author roles for this domain's users elsewhere", 
                   4311:                domroles => "Domain roles in this domain assignable to others",
                   4312:                catalog  => "Course Catalog for this domain displayed elsewhere",
                   4313:                reqcrs   => "Requests for creation of courses in this domain by others",
                   4314:                msg      => "Users in other domains can send messages to this domain",
                   4315:                exc      => "Allow all, but exclude specific domains",
                   4316:                inc      => "Deny all, but include specific domains",
                   4317:            );
1.275     raeburn  4318: } 
                   4319: 
1.138     raeburn  4320: sub build_location_hashes {
1.275     raeburn  4321:     my ($intdoms,$by_ip,$by_location,$instdoms) = @_;
1.138     raeburn  4322:     return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
1.275     raeburn  4323:                   (ref($by_location) eq 'HASH') && (ref($instdoms) eq 'ARRAY'));
1.138     raeburn  4324:     my %iphost = &Apache::lonnet::get_iphost();
                   4325:     my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
                   4326:     my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
                   4327:     if (ref($iphost{$primary_ip}) eq 'ARRAY') {
                   4328:         foreach my $id (@{$iphost{$primary_ip}}) {
                   4329:             my $intdom = &Apache::lonnet::internet_dom($id);
                   4330:             unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
                   4331:                 push(@{$intdoms},$intdom);
                   4332:             }
                   4333:         }
                   4334:     }
                   4335:     foreach my $ip (keys(%iphost)) {
                   4336:         if (ref($iphost{$ip}) eq 'ARRAY') {
                   4337:             foreach my $id (@{$iphost{$ip}}) {
                   4338:                 my $location = &Apache::lonnet::internet_dom($id);
                   4339:                 if ($location) {
1.275     raeburn  4340:                     if (grep(/^\Q$location\E$/,@{$intdoms})) {
                   4341:                         my $dom = &Apache::lonnet::host_domain($id);
                   4342:                         unless (grep(/^\Q$dom\E/,@{$instdoms})) {
                   4343:                             push(@{$instdoms},$dom);
                   4344:                         }
                   4345:                         next;
                   4346:                     }
1.138     raeburn  4347:                     if (ref($by_ip->{$ip}) eq 'ARRAY') {
                   4348:                         unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
                   4349:                             push(@{$by_ip->{$ip}},$location);
                   4350:                         }
                   4351:                     } else {
                   4352:                         $by_ip->{$ip} = [$location];
                   4353:                     }
                   4354:                 }
                   4355:             }
                   4356:         }
                   4357:     }
                   4358:     foreach my $ip (sort(keys(%{$by_ip}))) {
                   4359:         if (ref($by_ip->{$ip}) eq 'ARRAY') {
                   4360:             @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
                   4361:             my $first = $by_ip->{$ip}->[0];
                   4362:             if (ref($by_location->{$first}) eq 'ARRAY') {
                   4363:                 unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
                   4364:                     push(@{$by_location->{$first}},$ip);
                   4365:                 }
                   4366:             } else {
                   4367:                 $by_location->{$first} = [$ip];
                   4368:             }
                   4369:         }
                   4370:     }
                   4371:     return;
                   4372: }
                   4373: 
1.145     raeburn  4374: sub current_offloads_to {
                   4375:     my ($dom,$settings,$servers) = @_;
                   4376:     my (%spareid,%otherdomconfigs);
1.152     raeburn  4377:     if (ref($servers) eq 'HASH') {
1.145     raeburn  4378:         foreach my $lonhost (sort(keys(%{$servers}))) {
                   4379:             my $gotspares;
1.152     raeburn  4380:             if (ref($settings) eq 'HASH') {
                   4381:                 if (ref($settings->{'spares'}) eq 'HASH') {
                   4382:                     if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
                   4383:                         $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
                   4384:                         $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
                   4385:                         $gotspares = 1;
                   4386:                     }
1.145     raeburn  4387:                 }
                   4388:             }
                   4389:             unless ($gotspares) {
                   4390:                 my $gotspares;
                   4391:                 my $serverhomeID =
                   4392:                     &Apache::lonnet::get_server_homeID($servers->{$lonhost});
                   4393:                 my $serverhomedom =
                   4394:                     &Apache::lonnet::host_domain($serverhomeID);
                   4395:                 if ($serverhomedom ne $dom) {
                   4396:                     if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
                   4397:                         if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
                   4398:                             if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
                   4399:                                 $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
                   4400:                                 $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
                   4401:                                 $gotspares = 1;
                   4402:                             }
                   4403:                         }
                   4404:                     } else {
                   4405:                         $otherdomconfigs{$serverhomedom} =
                   4406:                             &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
                   4407:                         if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
                   4408:                             if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
                   4409:                                 if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
                   4410:                                     if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
                   4411:                                         $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
                   4412:                                         $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
                   4413:                                         $gotspares = 1;
                   4414:                                     }
                   4415:                                 }
                   4416:                             }
                   4417:                         }
                   4418:                     }
                   4419:                 }
                   4420:             }
                   4421:             unless ($gotspares) {
                   4422:                 if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
                   4423:                     $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
                   4424:                     $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
                   4425:                } else {
                   4426:                     my $server_hostname = &Apache::lonnet::hostname($lonhost);
                   4427:                     my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
                   4428:                     if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
                   4429:                         $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
                   4430:                         $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
                   4431:                     } else {
1.150     raeburn  4432:                         my %what = (
                   4433:                              spareid => 1,
                   4434:                         );
                   4435:                         my ($result,$returnhash) = 
                   4436:                             &Apache::lonnet::get_remote_globals($lonhost,\%what);
                   4437:                         if ($result eq 'ok') { 
                   4438:                             if (ref($returnhash) eq 'HASH') {
                   4439:                                 if (ref($returnhash->{'spareid'}) eq 'HASH') {
                   4440:                                     $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
                   4441:                                     $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
                   4442:                                 }
                   4443:                             }
1.145     raeburn  4444:                         }
                   4445:                     }
                   4446:                 }
                   4447:             }
                   4448:         }
                   4449:     }
                   4450:     return %spareid;
                   4451: }
                   4452: 
                   4453: sub spares_row {
1.261     raeburn  4454:     my ($dom,$servers,$spareid,$serverhomes,$altids,$curroffloadnow,$rowtotal) = @_;
1.145     raeburn  4455:     my $css_class;
                   4456:     my $numinrow = 4;
                   4457:     my $itemcount = 1;
                   4458:     my $datatable;
1.152     raeburn  4459:     my %typetitles = &sparestype_titles();
                   4460:     if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145     raeburn  4461:         foreach my $server (sort(keys(%{$servers}))) {
1.152     raeburn  4462:             my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
                   4463:             my ($othercontrol,$serverdom);
                   4464:             if ($serverhome ne $server) {
                   4465:                 $serverdom = &Apache::lonnet::host_domain($serverhome);
                   4466:                 $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
                   4467:             } else {
                   4468:                 $serverdom = &Apache::lonnet::host_domain($server);
                   4469:                 if ($serverdom ne $dom) {
                   4470:                     $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
                   4471:                 }
                   4472:             }
                   4473:             next unless (ref($spareid->{$server}) eq 'HASH');
1.261     raeburn  4474:             my $checkednow;
                   4475:             if (ref($curroffloadnow) eq 'HASH') {
                   4476:                 if ($curroffloadnow->{$server}) {
                   4477:                     $checkednow = ' checked="checked"';
                   4478:                 }
                   4479:             }
1.145     raeburn  4480:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   4481:             $datatable .= '<tr'.$css_class.'>
                   4482:                            <td rowspan="2">
1.183     bisitz   4483:                             <span class="LC_nobreak">'.
                   4484:                           &mt('[_1] when busy, offloads to:'
1.261     raeburn  4485:                               ,'<b>'.$server.'</b>').'</span><br />'.
                   4486:                           '<span class="LC_nobreak">'."\n". 
                   4487:                           '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
                   4488:                           '&nbsp;'.&mt('Switch active users on next access').'</label></span>'.
1.183     bisitz   4489:                           "\n";
1.145     raeburn  4490:             my (%current,%canselect);
1.152     raeburn  4491:             my @choices = 
                   4492:                 &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
                   4493:             foreach my $type ('primary','default') {
                   4494:                 if (ref($spareid->{$server}) eq 'HASH') {
1.145     raeburn  4495:                     if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
                   4496:                         my @spares = @{$spareid->{$server}{$type}};
                   4497:                         if (@spares > 0) {
1.152     raeburn  4498:                             if ($othercontrol) {
                   4499:                                 $current{$type} = join(', ',@spares);
                   4500:                             } else {
                   4501:                                 $current{$type} .= '<table>';
                   4502:                                 my $numspares = scalar(@spares);
                   4503:                                 for (my $i=0;  $i<@spares; $i++) {
                   4504:                                     my $rem = $i%($numinrow);
                   4505:                                     if ($rem == 0) {
                   4506:                                         if ($i > 0) {
                   4507:                                             $current{$type} .= '</tr>';
                   4508:                                         }
                   4509:                                         $current{$type} .= '<tr>';
1.145     raeburn  4510:                                     }
1.152     raeburn  4511:                                     $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;'.
                   4512:                                                        $spareid->{$server}{$type}[$i].
                   4513:                                                        '</label></td>'."\n";
                   4514:                                 }
                   4515:                                 my $rem = @spares%($numinrow);
                   4516:                                 my $colsleft = $numinrow - $rem;
                   4517:                                 if ($colsleft > 1 ) {
                   4518:                                     $current{$type} .= '<td colspan="'.$colsleft.
                   4519:                                                        '" class="LC_left_item">'.
                   4520:                                                        '&nbsp;</td>';
                   4521:                                 } elsif ($colsleft == 1) {
                   4522:                                     $current{$type} .= '<td class="LC_left_item">&nbsp;</td>'."\n";
1.145     raeburn  4523:                                 }
1.152     raeburn  4524:                                 $current{$type} .= '</tr></table>';
1.150     raeburn  4525:                             }
1.145     raeburn  4526:                         }
                   4527:                     }
                   4528:                     if ($current{$type} eq '') {
                   4529:                         $current{$type} = &mt('None specified');
                   4530:                     }
1.152     raeburn  4531:                     if ($othercontrol) {
                   4532:                         if ($type eq 'primary') {
                   4533:                             $canselect{$type} = $othercontrol;
                   4534:                         }
                   4535:                     } else {
                   4536:                         $canselect{$type} = 
                   4537:                             &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').'&nbsp;'.
                   4538:                             '<select name="newspare_'.$type.'_'.$server.'" '.
                   4539:                             'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
                   4540:                             '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
                   4541:                         if (@choices > 0) {
                   4542:                             foreach my $lonhost (@choices) {
                   4543:                                 $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
                   4544:                             }
                   4545:                         }
                   4546:                         $canselect{$type} .= '</select>'."\n";
                   4547:                     }
                   4548:                 } else {
                   4549:                     $current{$type} = &mt('Could not be determined');
                   4550:                     if ($type eq 'primary') {
                   4551:                         $canselect{$type} =  $othercontrol;
                   4552:                     }
1.145     raeburn  4553:                 }
1.152     raeburn  4554:                 if ($type eq 'default') {
                   4555:                     $datatable .= '<tr'.$css_class.'>';
                   4556:                 }
                   4557:                 $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
                   4558:                               '<td>'.$current{$type}.'</td>'."\n".
                   4559:                               '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145     raeburn  4560:             }
                   4561:             $itemcount ++;
                   4562:         }
                   4563:     }
                   4564:     $$rowtotal += $itemcount;
                   4565:     return $datatable;
                   4566: }
                   4567: 
1.152     raeburn  4568: sub possible_newspares {
                   4569:     my ($server,$currspares,$serverhomes,$altids) = @_;
                   4570:     my $serverhostname = &Apache::lonnet::hostname($server);
                   4571:     my %excluded;
                   4572:     if ($serverhostname ne '') {
                   4573:         %excluded = (
                   4574:                        $serverhostname => 1,
                   4575:                     );
                   4576:     }
                   4577:     if (ref($currspares) eq 'HASH') {
                   4578:         foreach my $type (keys(%{$currspares})) {
                   4579:             if (ref($currspares->{$type}) eq 'ARRAY') {
                   4580:                 if (@{$currspares->{$type}} > 0) {
                   4581:                     foreach my $curr (@{$currspares->{$type}}) {
                   4582:                         my $hostname = &Apache::lonnet::hostname($curr);
                   4583:                         $excluded{$hostname} = 1;
                   4584:                     }
                   4585:                 }
                   4586:             }
                   4587:         }
                   4588:     }
                   4589:     my @choices;
                   4590:     if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
                   4591:         if (keys(%{$serverhomes}) > 1) {
                   4592:             foreach my $name (sort(keys(%{$serverhomes}))) {
                   4593:                 unless ($excluded{$name}) {
                   4594:                     if (exists($altids->{$serverhomes->{$name}})) {
                   4595:                         push(@choices,$altids->{$serverhomes->{$name}});
                   4596:                     } else {
                   4597:                         push(@choices,$serverhomes->{$name});
1.145     raeburn  4598:                     }
                   4599:                 }
                   4600:             }
                   4601:         }
                   4602:     }
1.152     raeburn  4603:     return sort(@choices);
1.145     raeburn  4604: }
                   4605: 
1.150     raeburn  4606: sub print_loadbalancing {
                   4607:     my ($dom,$settings,$rowtotal) = @_;
                   4608:     my $primary_id = &Apache::lonnet::domain($dom,'primary');
                   4609:     my $intdom = &Apache::lonnet::internet_dom($primary_id);
                   4610:     my $numinrow = 1;
                   4611:     my $datatable;
                   4612:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.171     raeburn  4613:     my (%currbalancer,%currtargets,%currrules,%existing);
                   4614:     if (ref($settings) eq 'HASH') {
                   4615:         %existing = %{$settings};
                   4616:     }
                   4617:     if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
                   4618:         &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
                   4619:                                   \%currtargets,\%currrules);
1.150     raeburn  4620:     } else {
                   4621:         return;
                   4622:     }
                   4623:     my ($othertitle,$usertypes,$types) =
                   4624:         &Apache::loncommon::sorted_inst_types($dom);
1.209     raeburn  4625:     my $rownum = 8;
1.150     raeburn  4626:     if (ref($types) eq 'ARRAY') {
                   4627:         $rownum += scalar(@{$types});
                   4628:     }
1.171     raeburn  4629:     my @css_class = ('LC_odd_row','LC_even_row');
                   4630:     my $balnum = 0;
                   4631:     my $islast;
                   4632:     my (@toshow,$disabledtext);
                   4633:     if (keys(%currbalancer) > 0) {
                   4634:         @toshow = sort(keys(%currbalancer));
                   4635:         if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
                   4636:             push(@toshow,'');
                   4637:         }
                   4638:     } else {
                   4639:         @toshow = ('');
                   4640:         $disabledtext = &mt('No existing load balancer');
                   4641:     }
                   4642:     foreach my $lonhost (@toshow) {
                   4643:         if ($balnum == scalar(@toshow)-1) {
                   4644:             $islast = 1;
                   4645:         } else {
                   4646:             $islast = 0;
                   4647:         }
                   4648:         my $cssidx = $balnum%2;
                   4649:         my $targets_div_style = 'display: none';
                   4650:         my $disabled_div_style = 'display: block';
                   4651:         my $homedom_div_style = 'display: none';
                   4652:         $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
                   4653:                       '<td rowspan="'.$rownum.'" valign="top">'.
                   4654:                       '<p>';
                   4655:         if ($lonhost eq '') {
1.210     raeburn  4656:             $datatable .= '<span class="LC_nobreak">';
1.171     raeburn  4657:             if (keys(%currbalancer) > 0) {
                   4658:                 $datatable .= &mt('Add balancer:');
                   4659:             } else {
                   4660:                 $datatable .= &mt('Enable balancer:');
                   4661:             }
                   4662:             $datatable .= '&nbsp;'.
                   4663:                           '<select name="loadbalancing_lonhost_'.$balnum.'"'.
                   4664:                           ' id="loadbalancing_lonhost_'.$balnum.'"'.
                   4665:                           ' onchange="toggleTargets('."'$balnum'".');">'."\n".
                   4666:                           '<option value="" selected="selected">'.&mt('None').
                   4667:                           '</option>'."\n";
                   4668:             foreach my $server (sort(keys(%servers))) {
                   4669:                 next if ($currbalancer{$server});
                   4670:                 $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
                   4671:             }
1.210     raeburn  4672:             $datatable .=
1.171     raeburn  4673:                 '</select>'."\n".
                   4674:                 '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" />&nbsp;</span>'."\n";
                   4675:         } else {
                   4676:             $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
                   4677:                           '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" />&nbsp;'.
                   4678:                            &mt('Stop balancing').'</label>'.
                   4679:                            '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
                   4680:             $targets_div_style = 'display: block';
                   4681:             $disabled_div_style = 'display: none';
                   4682:             if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
                   4683:                 $homedom_div_style = 'display: block';
                   4684:             }
                   4685:         }
                   4686:         $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
                   4687:                   '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
                   4688:                   $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
                   4689:                   '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
                   4690:         my ($numspares,@spares) = &count_servers($lonhost,%servers);
                   4691:         my @sparestypes = ('primary','default');
                   4692:         my %typetitles = &sparestype_titles();
                   4693:         foreach my $sparetype (@sparestypes) {
                   4694:             my $targettable;
                   4695:             for (my $i=0; $i<$numspares; $i++) {
                   4696:                 my $checked;
                   4697:                 if (ref($currtargets{$lonhost}) eq 'HASH') {
                   4698:                     if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
                   4699:                         if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
                   4700:                             $checked = ' checked="checked"';
                   4701:                         }
                   4702:                     }
                   4703:                 }
                   4704:                 my ($chkboxval,$disabled);
                   4705:                 if (($lonhost ne '') && (exists($servers{$lonhost}))) {
                   4706:                     $chkboxval = $spares[$i];
                   4707:                 }
                   4708:                 if (exists($currbalancer{$spares[$i]})) {
                   4709:                     $disabled = ' disabled="disabled"';
                   4710:                 }
1.210     raeburn  4711:                 $targettable .=
1.253     raeburn  4712:                     '<td><span class="LC_nobreak"><label>'.
                   4713:                     '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.171     raeburn  4714:                     $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  4715:                     '</span></label></span></td>';
1.171     raeburn  4716:                 my $rem = $i%($numinrow);
                   4717:                 if ($rem == 0) {
                   4718:                     if (($i > 0) && ($i < $numspares-1)) {
                   4719:                         $targettable .= '</tr>';
                   4720:                     }
                   4721:                     if ($i < $numspares-1) {
                   4722:                         $targettable .= '<tr>';
1.150     raeburn  4723:                     }
                   4724:                 }
                   4725:             }
1.171     raeburn  4726:             if ($targettable ne '') {
                   4727:                 my $rem = $numspares%($numinrow);
                   4728:                 my $colsleft = $numinrow - $rem;
                   4729:                 if ($colsleft > 1 ) {
                   4730:                     $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   4731:                                     '&nbsp;</td>';
                   4732:                 } elsif ($colsleft == 1) {
                   4733:                     $targettable .= '<td class="LC_left_item">&nbsp;</td>';
                   4734:                 }
                   4735:                 $datatable .=  '<i>'.$typetitles{$sparetype}.'</i><br />'.
                   4736:                                '<table><tr>'.$targettable.'</tr></table><br />';
                   4737:             }
                   4738:         }
                   4739:         $datatable .= '</div></td></tr>'.
                   4740:                       &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
                   4741:                                            $othertitle,$usertypes,$types,\%servers,
                   4742:                                            \%currbalancer,$lonhost,
                   4743:                                            $targets_div_style,$homedom_div_style,
                   4744:                                            $css_class[$cssidx],$balnum,$islast);
                   4745:         $$rowtotal += $rownum;
                   4746:         $balnum ++;
                   4747:     }
                   4748:     $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
                   4749:     return $datatable;
                   4750: }
                   4751: 
                   4752: sub get_loadbalancers_config {
                   4753:     my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
                   4754:     return unless ((ref($servers) eq 'HASH') &&
                   4755:                    (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
                   4756:                    (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
                   4757:     if (keys(%{$existing}) > 0) {
                   4758:         my $oldlonhost;
                   4759:         foreach my $key (sort(keys(%{$existing}))) {
                   4760:             if ($key eq 'lonhost') {
                   4761:                 $oldlonhost = $existing->{'lonhost'};
                   4762:                 $currbalancer->{$oldlonhost} = 1;
                   4763:             } elsif ($key eq 'targets') {
                   4764:                 if ($oldlonhost) {
                   4765:                     $currtargets->{$oldlonhost} = $existing->{'targets'};
                   4766:                 }
                   4767:             } elsif ($key eq 'rules') {
                   4768:                 if ($oldlonhost) {
                   4769:                     $currrules->{$oldlonhost} = $existing->{'rules'};
                   4770:                 }
                   4771:             } elsif (ref($existing->{$key}) eq 'HASH') {
                   4772:                 $currbalancer->{$key} = 1;
                   4773:                 $currtargets->{$key} = $existing->{$key}{'targets'};
                   4774:                 $currrules->{$key} = $existing->{$key}{'rules'};
1.150     raeburn  4775:             }
                   4776:         }
1.171     raeburn  4777:     } else {
                   4778:         my ($balancerref,$targetsref) =
                   4779:                 &Apache::lonnet::get_lonbalancer_config($servers);
                   4780:         if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
                   4781:             foreach my $server (sort(keys(%{$balancerref}))) {
                   4782:                 $currbalancer->{$server} = 1;
                   4783:                 $currtargets->{$server} = $targetsref->{$server};
1.150     raeburn  4784:             }
                   4785:         }
                   4786:     }
1.171     raeburn  4787:     return;
1.150     raeburn  4788: }
                   4789: 
                   4790: sub loadbalancing_rules {
                   4791:     my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171     raeburn  4792:         $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
                   4793:         $css_class,$balnum,$islast) = @_;
1.150     raeburn  4794:     my $output;
1.171     raeburn  4795:     my $num = 0;
1.210     raeburn  4796:     my ($alltypes,$othertypes,$titles) =
1.150     raeburn  4797:         &loadbalancing_titles($dom,$intdom,$usertypes,$types);
                   4798:     if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH'))  {
                   4799:         foreach my $type (@{$alltypes}) {
1.171     raeburn  4800:             $num ++;
1.150     raeburn  4801:             my $current;
                   4802:             if (ref($currrules) eq 'HASH') {
                   4803:                 $current = $currrules->{$type};
                   4804:             }
1.253     raeburn  4805:             if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.171     raeburn  4806:                 if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150     raeburn  4807:                     $current = '';
                   4808:                 }
                   4809:             }
                   4810:             $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171     raeburn  4811:                                              $servers,$currbalancer,$lonhost,$dom,
                   4812:                                              $targets_div_style,$homedom_div_style,
                   4813:                                              $css_class,$balnum,$num,$islast);
1.150     raeburn  4814:         }
                   4815:     }
                   4816:     return $output;
                   4817: }
                   4818: 
                   4819: sub loadbalancing_titles {
                   4820:     my ($dom,$intdom,$usertypes,$types) = @_;
                   4821:     my %othertypes = (
                   4822:            '_LC_adv'         => &mt('Advanced users from [_1]',$dom),
                   4823:            '_LC_author'      => &mt('Users from [_1] with author role',$dom),
                   4824:            '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
                   4825:            '_LC_external'    => &mt('Users not from [_1]',$intdom),
1.209     raeburn  4826:            '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
                   4827:            '_LC_ipchange'    => &mt('Non-SSO users with IP mismatch'),
1.150     raeburn  4828:                      );
1.209     raeburn  4829:     my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.150     raeburn  4830:     if (ref($types) eq 'ARRAY') {
                   4831:         unshift(@alltypes,@{$types},'default');
                   4832:     }
                   4833:     my %titles;
                   4834:     foreach my $type (@alltypes) {
                   4835:         if ($type =~ /^_LC_/) {
                   4836:             $titles{$type} = $othertypes{$type};
                   4837:         } elsif ($type eq 'default') {
                   4838:             $titles{$type} = &mt('All users from [_1]',$dom);
                   4839:             if (ref($types) eq 'ARRAY') {
                   4840:                 if (@{$types} > 0) {
                   4841:                     $titles{$type} = &mt('Other users from [_1]',$dom);
                   4842:                 }
                   4843:             }
                   4844:         } elsif (ref($usertypes) eq 'HASH') {
                   4845:             $titles{$type} = $usertypes->{$type};
                   4846:         }
                   4847:     }
                   4848:     return (\@alltypes,\%othertypes,\%titles);
                   4849: }
                   4850: 
                   4851: sub loadbalance_rule_row {
1.171     raeburn  4852:     my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
                   4853:         $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.209     raeburn  4854:     my @rulenames;
1.150     raeburn  4855:     my %ruletitles = &offloadtype_text();
1.209     raeburn  4856:     if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.254     raeburn  4857:         @rulenames = ('balancer','offloadedto','specific');
1.150     raeburn  4858:     } else {
1.209     raeburn  4859:         @rulenames = ('default','homeserver');
                   4860:         if ($type eq '_LC_external') {
                   4861:             push(@rulenames,'externalbalancer');
                   4862:         } else {
                   4863:             push(@rulenames,'specific');
                   4864:         }
                   4865:         push(@rulenames,'none');
1.150     raeburn  4866:     }
                   4867:     my $style = $targets_div_style;
1.253     raeburn  4868:     if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150     raeburn  4869:         $style = $homedom_div_style;
                   4870:     }
1.171     raeburn  4871:     my $space;
                   4872:     if ($islast && $num == 1) {
                   4873:         $space = '<div display="inline-block">&nbsp;</div>';
                   4874:     }
1.210     raeburn  4875:     my $output =
1.171     raeburn  4876:         '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
                   4877:         '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
                   4878:         '<td valaign="top">'.$space.
                   4879:         '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150     raeburn  4880:     for (my $i=0; $i<@rulenames; $i++) {
                   4881:         my $rule = $rulenames[$i];
                   4882:         my ($checked,$extra);
                   4883:         if ($rulenames[$i] eq 'default') {
                   4884:             $rule = '';
                   4885:         }
                   4886:         if ($rulenames[$i] eq 'specific') {
                   4887:             if (ref($servers) eq 'HASH') {
                   4888:                 my $default;
                   4889:                 if (($current ne '') && (exists($servers->{$current}))) {
                   4890:                     $checked = ' checked="checked"';
                   4891:                 }
                   4892:                 unless ($checked) {
                   4893:                     $default = ' selected="selected"';
                   4894:                 }
1.210     raeburn  4895:                 $extra =
1.171     raeburn  4896:                     ':&nbsp;<select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
                   4897:                     '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
                   4898:                     '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
                   4899:                     '<option value=""'.$default.'></option>'."\n";
                   4900:                 foreach my $server (sort(keys(%{$servers}))) {
                   4901:                     if (ref($currbalancer) eq 'HASH') {
                   4902:                         next if (exists($currbalancer->{$server}));
                   4903:                     }
1.150     raeburn  4904:                     my $selected;
1.171     raeburn  4905:                     if ($server eq $current) {
1.150     raeburn  4906:                         $selected = ' selected="selected"';
                   4907:                     }
1.171     raeburn  4908:                     $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150     raeburn  4909:                 }
                   4910:                 $extra .= '</select>';
                   4911:             }
                   4912:         } elsif ($rule eq $current) {
                   4913:             $checked = ' checked="checked"';
                   4914:         }
                   4915:         $output .= '<span class="LC_nobreak"><label>'.
1.171     raeburn  4916:                    '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
                   4917:                    '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
                   4918:                    $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.254     raeburn  4919:                    ')"'.$checked.' />&nbsp;';
                   4920:         if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
                   4921:             $output .= $ruletitles{'particular'};
                   4922:         } else {
                   4923:             $output .= $ruletitles{$rulenames[$i]};
                   4924:         }
                   4925:         $output .= '</label>'.$extra.'</span><br />'."\n";
1.150     raeburn  4926:     }
                   4927:     $output .= '</div></td></tr>'."\n";
                   4928:     return $output;
                   4929: }
                   4930: 
                   4931: sub offloadtype_text {
                   4932:     my %ruletitles = &Apache::lonlocal::texthash (
                   4933:            'default'          => 'Offloads to default destinations',
                   4934:            'homeserver'       => "Offloads to user's home server",
                   4935:            'externalbalancer' => "Offloads to Load Balancer in user's domain",
                   4936:            'specific'         => 'Offloads to specific server',
1.161     raeburn  4937:            'none'             => 'No offload',
1.209     raeburn  4938:            'balancer'         => 'Session hosted on Load Balancer, after re-authentication',
                   4939:            'offloadedto'      => 'Session hosted on offload server, after re-authentication',
1.254     raeburn  4940:            'particular'       => 'Session hosted (after re-auth) on server:',
1.150     raeburn  4941:     );
                   4942:     return %ruletitles;
                   4943: }
                   4944: 
                   4945: sub sparestype_titles {
                   4946:     my %typestitles = &Apache::lonlocal::texthash (
                   4947:                           'primary' => 'primary',
                   4948:                           'default' => 'default',
                   4949:                       );
                   4950:     return %typestitles;
                   4951: }
                   4952: 
1.28      raeburn  4953: sub contact_titles {
                   4954:     my %titles = &Apache::lonlocal::texthash (
                   4955:                    'supportemail' => 'Support E-mail address',
1.69      raeburn  4956:                    'adminemail'   => 'Default Server Admin E-mail address',
1.28      raeburn  4957:                    'errormail'    => 'Error reports to be e-mailed to',
                   4958:                    'packagesmail' => 'Package update alerts to be e-mailed to',
1.89      raeburn  4959:                    'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
                   4960:                    'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
1.102     raeburn  4961:                    'requestsmail' => 'E-mail from course requests requiring approval',
1.190     raeburn  4962:                    'updatesmail'  => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.203     raeburn  4963:                    'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.28      raeburn  4964:                  );
                   4965:     my %short_titles = &Apache::lonlocal::texthash (
                   4966:                            adminemail   => 'Admin E-mail address',
                   4967:                            supportemail => 'Support E-mail',
                   4968:                        );   
                   4969:     return (\%titles,\%short_titles);
                   4970: }
                   4971: 
1.72      raeburn  4972: sub tool_titles {
                   4973:     my %titles = &Apache::lonlocal::texthash (
1.162     raeburn  4974:                      aboutme    => 'Personal web page',
1.86      raeburn  4975:                      blog       => 'Blog',
1.162     raeburn  4976:                      webdav     => 'WebDAV',
1.86      raeburn  4977:                      portfolio  => 'Portfolio',
1.88      bisitz   4978:                      official   => 'Official courses (with institutional codes)',
                   4979:                      unofficial => 'Unofficial courses',
1.98      raeburn  4980:                      community  => 'Communities',
1.216     raeburn  4981:                      textbook   => 'Textbook courses',
1.271     raeburn  4982:                      placement  => 'Placement tests',
1.86      raeburn  4983:                  );
1.72      raeburn  4984:     return %titles;
                   4985: }
                   4986: 
1.101     raeburn  4987: sub courserequest_titles {
                   4988:     my %titles = &Apache::lonlocal::texthash (
                   4989:                                    official   => 'Official',
                   4990:                                    unofficial => 'Unofficial',
                   4991:                                    community  => 'Communities',
1.216     raeburn  4992:                                    textbook   => 'Textbook',
1.271     raeburn  4993:                                    placement  => 'Placement tests',
1.101     raeburn  4994:                                    norequest  => 'Not allowed',
1.104     raeburn  4995:                                    approval   => 'Approval by Dom. Coord.',
1.101     raeburn  4996:                                    validate   => 'With validation',
                   4997:                                    autolimit  => 'Numerical limit',
1.103     raeburn  4998:                                    unlimited  => '(blank for unlimited)',
1.101     raeburn  4999:                  );
                   5000:     return %titles;
                   5001: }
                   5002: 
1.163     raeburn  5003: sub authorrequest_titles {
                   5004:     my %titles = &Apache::lonlocal::texthash (
                   5005:                                    norequest  => 'Not allowed',
                   5006:                                    approval   => 'Approval by Dom. Coord.',
                   5007:                                    automatic  => 'Automatic approval',
                   5008:                  );
                   5009:     return %titles;
1.210     raeburn  5010: }
1.163     raeburn  5011: 
1.101     raeburn  5012: sub courserequest_conditions {
                   5013:     my %conditions = &Apache::lonlocal::texthash (
1.104     raeburn  5014:        approval    => '(Processing of request subject to approval by Domain Coordinator).',
1.193     bisitz   5015:        validate   => '(Processing of request subject to institutional validation).',
1.101     raeburn  5016:                  );
                   5017:     return %conditions;
                   5018: }
                   5019: 
                   5020: 
1.27      raeburn  5021: sub print_usercreation {
1.30      raeburn  5022:     my ($position,$dom,$settings,$rowtotal) = @_;
1.27      raeburn  5023:     my $numinrow = 4;
1.28      raeburn  5024:     my $datatable;
                   5025:     if ($position eq 'top') {
1.30      raeburn  5026:         $$rowtotal ++;
1.34      raeburn  5027:         my $rowcount = 0;
1.32      raeburn  5028:         my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28      raeburn  5029:         if (ref($rules) eq 'HASH') {
                   5030:             if (keys(%{$rules}) > 0) {
1.32      raeburn  5031:                 $datatable .= &user_formats_row('username',$settings,$rules,
                   5032:                                                 $ruleorder,$numinrow,$rowcount);
1.30      raeburn  5033:                 $$rowtotal ++;
1.32      raeburn  5034:                 $rowcount ++;
                   5035:             }
                   5036:         }
                   5037:         my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
                   5038:         if (ref($idrules) eq 'HASH') {
                   5039:             if (keys(%{$idrules}) > 0) {
                   5040:                 $datatable .= &user_formats_row('id',$settings,$idrules,
                   5041:                                                 $idruleorder,$numinrow,$rowcount);
                   5042:                 $$rowtotal ++;
                   5043:                 $rowcount ++;
1.28      raeburn  5044:             }
                   5045:         }
1.39      raeburn  5046:         if ($rowcount == 0) {
                   5047:             $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';  
                   5048:             $$rowtotal ++;
                   5049:             $rowcount ++;
                   5050:         }
1.34      raeburn  5051:     } elsif ($position eq 'middle') {
1.224     raeburn  5052:         my @creators = ('author','course','requestcrs');
1.37      raeburn  5053:         my ($rules,$ruleorder) =
                   5054:             &Apache::lonnet::inst_userrules($dom,'username');
1.34      raeburn  5055:         my %lt = &usercreation_types();
                   5056:         my %checked;
                   5057:         if (ref($settings) eq 'HASH') {
                   5058:             if (ref($settings->{'cancreate'}) eq 'HASH') {
                   5059:                 foreach my $item (@creators) {
                   5060:                     $checked{$item} = $settings->{'cancreate'}{$item};
                   5061:                 }
                   5062:             } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
                   5063:                 foreach my $item (@creators) {
                   5064:                     if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
                   5065:                         $checked{$item} = 'none';
                   5066:                     }
                   5067:                 }
                   5068:             }
                   5069:         }
                   5070:         my $rownum = 0;
                   5071:         foreach my $item (@creators) {
                   5072:             $rownum ++;
1.224     raeburn  5073:             if ($checked{$item} eq '') {
                   5074:                 $checked{$item} = 'any';
1.34      raeburn  5075:             }
                   5076:             my $css_class;
                   5077:             if ($rownum%2) {
                   5078:                 $css_class = '';
                   5079:             } else {
                   5080:                 $css_class = ' class="LC_odd_row" ';
                   5081:             }
                   5082:             $datatable .= '<tr'.$css_class.'>'.
                   5083:                          '<td><span class="LC_nobreak">'.$lt{$item}.
                   5084:                          '</span></td><td align="right">';
1.224     raeburn  5085:             my @options = ('any');
                   5086:             if (ref($rules) eq 'HASH') {
                   5087:                 if (keys(%{$rules}) > 0) {
                   5088:                     push(@options,('official','unofficial'));
1.37      raeburn  5089:                 }
                   5090:             }
1.224     raeburn  5091:             push(@options,'none');
1.37      raeburn  5092:             foreach my $option (@options) {
1.50      raeburn  5093:                 my $type = 'radio';
1.34      raeburn  5094:                 my $check = ' ';
1.224     raeburn  5095:                 if ($checked{$item} eq $option) {
                   5096:                     $check = ' checked="checked" ';
1.34      raeburn  5097:                 } 
                   5098:                 $datatable .= '<span class="LC_nobreak"><label>'.
1.50      raeburn  5099:                               '<input type="'.$type.'" name="can_createuser_'.
1.34      raeburn  5100:                               $item.'" value="'.$option.'"'.$check.'/>&nbsp;'.
                   5101:                               $lt{$option}.'</label>&nbsp;&nbsp;</span>';
                   5102:             }
                   5103:             $datatable .= '</td></tr>';
                   5104:         }
1.28      raeburn  5105:     } else {
                   5106:         my @contexts = ('author','course','domain');
                   5107:         my @authtypes = ('int','krb4','krb5','loc');
                   5108:         my %checked;
                   5109:         if (ref($settings) eq 'HASH') {
                   5110:             if (ref($settings->{'authtypes'}) eq 'HASH') {
                   5111:                 foreach my $item (@contexts) {
                   5112:                     if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
                   5113:                         foreach my $auth (@authtypes) {
                   5114:                             if ($settings->{'authtypes'}{$item}{$auth}) {
                   5115:                                 $checked{$item}{$auth} = ' checked="checked" ';
                   5116:                             }
                   5117:                         }
                   5118:                     }
                   5119:                 }
1.27      raeburn  5120:             }
1.35      raeburn  5121:         } else {
                   5122:             foreach my $item (@contexts) {
1.36      raeburn  5123:                 foreach my $auth (@authtypes) {
1.35      raeburn  5124:                     $checked{$item}{$auth} = ' checked="checked" ';
                   5125:                 }
                   5126:             }
1.27      raeburn  5127:         }
1.28      raeburn  5128:         my %title = &context_names();
                   5129:         my %authname = &authtype_names();
                   5130:         my $rownum = 0;
                   5131:         my $css_class; 
                   5132:         foreach my $item (@contexts) {
                   5133:             if ($rownum%2) {
                   5134:                 $css_class = '';
                   5135:             } else {
                   5136:                 $css_class = ' class="LC_odd_row" ';
                   5137:             }
1.30      raeburn  5138:             $datatable .=   '<tr'.$css_class.'>'.
1.28      raeburn  5139:                             '<td>'.$title{$item}.
                   5140:                             '</td><td class="LC_left_item">'.
                   5141:                             '<span class="LC_nobreak">';
                   5142:             foreach my $auth (@authtypes) {
                   5143:                 $datatable .= '<label>'. 
                   5144:                               '<input type="checkbox" name="'.$item.'_auth" '.
                   5145:                               $checked{$item}{$auth}.' value="'.$auth.'" />'.
                   5146:                               $authname{$auth}.'</label>&nbsp;';
                   5147:             }
                   5148:             $datatable .= '</span></td></tr>';
                   5149:             $rownum ++;
1.27      raeburn  5150:         }
1.30      raeburn  5151:         $$rowtotal += $rownum;
1.27      raeburn  5152:     }
                   5153:     return $datatable;
                   5154: }
                   5155: 
1.224     raeburn  5156: sub print_selfcreation {
                   5157:     my ($position,$dom,$settings,$rowtotal) = @_;
1.236     raeburn  5158:     my (@selfcreate,$createsettings,$processing,$datatable);
1.224     raeburn  5159:     if (ref($settings) eq 'HASH') {
                   5160:         if (ref($settings->{'cancreate'}) eq 'HASH') {
                   5161:             $createsettings = $settings->{'cancreate'};
1.236     raeburn  5162:             if (ref($createsettings) eq 'HASH') {
                   5163:                 if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
                   5164:                     @selfcreate = @{$createsettings->{'selfcreate'}};
                   5165:                 } elsif ($createsettings->{'selfcreate'} ne '') {
                   5166:                     if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
                   5167:                         @selfcreate = ('email','login','sso');
                   5168:                     } elsif ($createsettings->{'selfcreate'} ne 'none') {
                   5169:                         @selfcreate = ($createsettings->{'selfcreate'});
                   5170:                     }
                   5171:                 }
                   5172:                 if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
                   5173:                     $processing = $createsettings->{'selfcreateprocessing'};
1.224     raeburn  5174:                 }
                   5175:             }
                   5176:         }
                   5177:     }
                   5178:     my %radiohash;
                   5179:     my $numinrow = 4;
                   5180:     map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
                   5181:     if ($position eq 'top') {
                   5182:         my %choices = &Apache::lonlocal::texthash (
                   5183:                                                       cancreate_login      => 'Institutional Login',
                   5184:                                                       cancreate_sso        => 'Institutional Single Sign On',
                   5185:                                                   );
                   5186:         my @toggles = sort(keys(%choices));
                   5187:         my %defaultchecked = (
                   5188:                                'cancreate_login' => 'off',
                   5189:                                'cancreate_sso'   => 'off',
                   5190:                              );
1.228     raeburn  5191:         my ($onclick,$itemcount);
1.224     raeburn  5192:         ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
                   5193:                                                      \%choices,$itemcount,$onclick);
1.228     raeburn  5194:         $$rowtotal += $itemcount;
                   5195:         
1.224     raeburn  5196:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   5197: 
                   5198:         if (ref($usertypes) eq 'HASH') {
                   5199:             if (keys(%{$usertypes}) > 0) {
                   5200:                 $datatable .= &insttypes_row($createsettings,$types,$usertypes,
                   5201:                                              $dom,$numinrow,$othertitle,
1.228     raeburn  5202:                                              'statustocreate',$$rowtotal);
1.224     raeburn  5203:                 $$rowtotal ++;
                   5204:             }
                   5205:         }
1.240     raeburn  5206:         my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
                   5207:         my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
                   5208:         $fieldtitles{'inststatus'} = &mt('Institutional status');
                   5209:         my $rem;
                   5210:         my $numperrow = 2;
                   5211:         my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
                   5212:         $datatable .= '<tr'.$css_class.'>'.
1.241     raeburn  5213:                      '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.240     raeburn  5214:                      '<td class="LC_left_item">'."\n".
                   5215:                      '<table><tr><td>'."\n";
                   5216:         for (my $i=0; $i<@fields; $i++) {
                   5217:             $rem = $i%($numperrow);
                   5218:             if ($rem == 0) {
                   5219:                 if ($i > 0) {
                   5220:                     $datatable .= '</tr>';
                   5221:                 }
                   5222:                 $datatable .= '<tr>';
                   5223:             }
                   5224:             my $currval;
1.248     raeburn  5225:             if (ref($createsettings) eq 'HASH') {
                   5226:                 if (ref($createsettings->{'shibenv'}) eq 'HASH') {
                   5227:                     $currval = $createsettings->{'shibenv'}{$fields[$i]};
                   5228:                 }
1.240     raeburn  5229:             }
                   5230:             $datatable .= '<td class="LC_left_item">'.
                   5231:                           '<span class="LC_nobreak">'.
                   5232:                           '<input type="text" name="shibenv_'.$fields[$i].'" '.
                   5233:                           'value="'.$currval.'" size="10" />&nbsp;'.
                   5234:                           $fieldtitles{$fields[$i]}.'</span></td>';
                   5235:         }
                   5236:         my $colsleft = $numperrow - $rem;
                   5237:         if ($colsleft > 1 ) {
                   5238:             $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   5239:                          '&nbsp;</td>';
                   5240:         } elsif ($colsleft == 1) {
                   5241:             $datatable .= '<td class="LC_left_item">&nbsp;</td>';
                   5242:         }
                   5243:         $datatable .= '</tr></table></td></tr>';
                   5244:         $$rowtotal ++;
1.224     raeburn  5245:     } elsif ($position eq 'middle') {
                   5246:         my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
                   5247:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   5248:         $usertypes->{'default'} = $othertitle;
                   5249:         if (ref($types) eq 'ARRAY') {
                   5250:             push(@{$types},'default');
                   5251:             $usertypes->{'default'} = $othertitle;
                   5252:             foreach my $status (@{$types}) {
                   5253:                 $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
1.228     raeburn  5254:                                                        $numinrow,$$rowtotal,$usertypes);
1.240     raeburn  5255:                 $$rowtotal ++;
1.224     raeburn  5256:             }
                   5257:         }
                   5258:     } else {
1.236     raeburn  5259:         my %choices = &Apache::lonlocal::texthash (
                   5260:                                                       cancreate_email => 'E-mail address as username',
                   5261:                                                   );
                   5262:         my @toggles = sort(keys(%choices));
                   5263:         my %defaultchecked = (
                   5264:                                'cancreate_email' => 'off',
                   5265:                              );
                   5266:         my $itemcount = 0;
                   5267:         my $display = 'none';
                   5268:         if (grep(/^\Qemail\E$/,@selfcreate)) {
                   5269:             $display = 'block';
                   5270:         }
                   5271:         my $onclick = "toggleDisplay(this.form,'emailoptions');";
                   5272:         my $additional = '<div id="emailoptions" style="display: '.$display.'">';
                   5273:         my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
                   5274:         my $usertypes = {};
                   5275:         my $order = [];
                   5276:         if ((ref($domdefaults{'inststatustypes'}) eq 'HASH') && (ref($domdefaults{'inststatusguest'}) eq 'ARRAY')) {
                   5277:             $usertypes = $domdefaults{'inststatustypes'};
                   5278:             $order = $domdefaults{'inststatusguest'};
                   5279:         }
                   5280:         if (ref($order) eq 'ARRAY') {
                   5281:             push(@{$order},'default');
                   5282:             if (@{$order} > 1) {
                   5283:                 $usertypes->{'default'} = &mt('Other users');
                   5284:                 $additional .= '<table><tr>';
                   5285:                 foreach my $status (@{$order}) {
                   5286:                     $additional .= '<th>'.$usertypes->{$status}.'</th>';
                   5287:                 }
                   5288:                 $additional .= '</tr><tr>';
                   5289:                 foreach my $status (@{$order}) {
                   5290:                     $additional .= '<td>'.&email_as_username($rowtotal,$processing,$status).'</td>';
1.224     raeburn  5291:                 }
1.236     raeburn  5292:                 $additional .= '</tr></table>';
1.224     raeburn  5293:             } else {
1.236     raeburn  5294:                 $usertypes->{'default'} = &mt('All users');
                   5295:                 $additional .= &email_as_username($rowtotal,$processing);
1.224     raeburn  5296:             }
                   5297:         }
1.236     raeburn  5298:         $additional .= '</div>'."\n";
                   5299: 
                   5300:         ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
1.240     raeburn  5301:                                                      \%choices,$$rowtotal,$onclick,$additional);
                   5302:         $$rowtotal ++;
1.236     raeburn  5303:         $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal);
1.228     raeburn  5304:         $$rowtotal ++;
1.224     raeburn  5305:         my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.228     raeburn  5306:         $numinrow = 1;
1.236     raeburn  5307:         if (ref($order) eq 'ARRAY') {
                   5308:             foreach my $status (@{$order}) {
1.228     raeburn  5309:                 $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
                   5310:                                                        $numinrow,$$rowtotal,$usertypes,$infofields,$infotitles);
                   5311:                 $$rowtotal ++;
                   5312:             }
                   5313:         }
1.224     raeburn  5314:         my ($emailrules,$emailruleorder) =
                   5315:             &Apache::lonnet::inst_userrules($dom,'email');
                   5316:         if (ref($emailrules) eq 'HASH') {
                   5317:             if (keys(%{$emailrules}) > 0) {
                   5318:                 $datatable .= &user_formats_row('email',$settings,$emailrules,
1.228     raeburn  5319:                                                 $emailruleorder,$numinrow,$$rowtotal);
1.224     raeburn  5320:                 $$rowtotal ++;
                   5321:             }
                   5322:         }
1.228     raeburn  5323:         $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal);
1.224     raeburn  5324:     }
                   5325:     return $datatable;
                   5326: }
                   5327: 
1.236     raeburn  5328: sub email_as_username {
                   5329:     my ($rowtotal,$processing,$type) = @_;
                   5330:     my %choices =
                   5331:         &Apache::lonlocal::texthash (
                   5332:                                       automatic => 'Automatic approval',
                   5333:                                       approval  => 'Queued for approval',
                   5334:                                     );
                   5335:     my $output;
                   5336:     foreach my $option ('automatic','approval') {
                   5337:         my $checked;
                   5338:         if (ref($processing) eq 'HASH') {
                   5339:             if ($type eq '') {   
                   5340:                 if (!exists($processing->{'default'})) {
                   5341:                     if ($option eq 'automatic') {
                   5342:                         $checked = ' checked="checked"';
                   5343:                     }
                   5344:                 } else {
                   5345:                     if ($processing->{'default'} eq $option) {
                   5346:                         $checked = ' checked="checked"';
                   5347:                     }
                   5348:                 }
                   5349:             } else {
                   5350:                 if (!exists($processing->{$type})) {
                   5351:                     if ($option eq 'automatic') {
                   5352:                         $checked = ' checked="checked"';
                   5353:                     }
                   5354:                 } else {
                   5355:                     if ($processing->{$type} eq $option) {
                   5356:                         $checked = ' checked="checked"';
                   5357:                     }
                   5358:                 }
                   5359:             }
                   5360:         } elsif ($option eq 'automatic') {
                   5361:             $checked = ' checked="checked"'; 
                   5362:         }
                   5363:         my $name = 'cancreate_emailprocess';
                   5364:         if (($type ne '') && ($type ne 'default')) {
                   5365:             $name .= '_'.$type;
                   5366:         }
                   5367:         $output .= '<span class="LC_nobreak"><label>'.
                   5368:                    '<input type="radio" name="'.$name.'"'.
                   5369:                    $checked.' value="'.$option.'" />'.
                   5370:                    $choices{$option}.'</label></span>';
                   5371:         if ($type eq '') {
                   5372:             $output .= '&nbsp;';
                   5373:         } else {
                   5374:             $output .= '<br />';
                   5375:         }
                   5376:     }
                   5377:     $$rowtotal ++;
                   5378:     return $output;
                   5379: }
                   5380: 
1.165     raeburn  5381: sub captcha_choice {
1.169     raeburn  5382:     my ($context,$settings,$itemcount) = @_;
1.269     raeburn  5383:     my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
                   5384:         $vertext,$currver);
1.165     raeburn  5385:     my %lt = &captcha_phrases();
                   5386:     $keyentry = 'hidden';
                   5387:     if ($context eq 'cancreate') {
1.224     raeburn  5388:         $rowname = &mt('CAPTCHA validation');
1.169     raeburn  5389:     } elsif ($context eq 'login') {
                   5390:         $rowname =  &mt('"Contact helpdesk" CAPTCHA validation');
1.165     raeburn  5391:     }
                   5392:     if (ref($settings) eq 'HASH') {
                   5393:         if ($settings->{'captcha'}) {
                   5394:             $checked{$settings->{'captcha'}} = ' checked="checked"';
                   5395:         } else {
                   5396:             $checked{'original'} = ' checked="checked"';
                   5397:         }
                   5398:         if ($settings->{'captcha'} eq 'recaptcha') {
                   5399:             $pubtext = $lt{'pub'};
                   5400:             $privtext = $lt{'priv'};
                   5401:             $keyentry = 'text';
1.269     raeburn  5402:             $vertext = $lt{'ver'};
                   5403:             $currver = $settings->{'recaptchaversion'};
                   5404:             if ($currver ne '2') {
                   5405:                 $currver = 1;
                   5406:             }
1.165     raeburn  5407:         }
                   5408:         if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
                   5409:             $currpub = $settings->{'recaptchakeys'}{'public'};
                   5410:             $currpriv = $settings->{'recaptchakeys'}{'private'};
                   5411:         }
                   5412:     } else {
                   5413:         $checked{'original'} = ' checked="checked"';
                   5414:     }
1.169     raeburn  5415:     my $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   5416:     my $output = '<tr'.$css_class.'>'.
                   5417:                  '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
1.165     raeburn  5418:                  '<table><tr><td>'."\n";
                   5419:     foreach my $option ('original','recaptcha','notused') {
                   5420:         $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
                   5421:                    $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
                   5422:                    $lt{$option}.'</label></span>';
                   5423:         unless ($option eq 'notused') {
                   5424:             $output .= ('&nbsp;'x2)."\n";
                   5425:         }
                   5426:     }
                   5427: #
                   5428: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
                   5429: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
1.210     raeburn  5430: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
1.165     raeburn  5431: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
1.210     raeburn  5432: #
1.165     raeburn  5433:     $output .= '</td></tr>'."\n".
                   5434:                '<tr><td>'."\n".
                   5435:                '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span>&nbsp;'."\n".
                   5436:                '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
                   5437:                $currpub.'" size="40" /></span><br />'."\n".
                   5438:                '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span>&nbsp;'."\n".
                   5439:                '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.269     raeburn  5440:                $currpriv.'" size="40" /></span><br />'.
                   5441:                '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span>&nbsp;'."\n".
                   5442:                '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
                   5443:                $currver.'" size="3" /></span><br />'.
                   5444:                '</td></tr></table>'."\n".
1.165     raeburn  5445:                '</td></tr>';
                   5446:     return $output;
                   5447: }
                   5448: 
1.32      raeburn  5449: sub user_formats_row {
                   5450:     my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
                   5451:     my $output;
                   5452:     my %text = (
                   5453:                    'username' => 'new usernames',
                   5454:                    'id'       => 'IDs',
1.45      raeburn  5455:                    'email'    => 'self-created accounts (e-mail)',
1.32      raeburn  5456:                );
                   5457:     my $css_class = $rowcount%2?' class="LC_odd_row"':'';
                   5458:     $output = '<tr '.$css_class.'>'.
1.63      raeburn  5459:               '<td><span class="LC_nobreak">';
                   5460:     if ($type eq 'email') {
                   5461:         $output .= &mt("Formats disallowed for $text{$type}: ");
                   5462:     } else {
                   5463:         $output .= &mt("Format rules to check for $text{$type}: ");
                   5464:     }
                   5465:     $output .= '</span></td>'.
                   5466:                '<td class="LC_left_item" colspan="2"><table>';
1.27      raeburn  5467:     my $rem;
                   5468:     if (ref($ruleorder) eq 'ARRAY') {
                   5469:         for (my $i=0; $i<@{$ruleorder}; $i++) {
                   5470:             if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
                   5471:                 my $rem = $i%($numinrow);
                   5472:                 if ($rem == 0) {
                   5473:                     if ($i > 0) {
                   5474:                         $output .= '</tr>';
                   5475:                     }
                   5476:                     $output .= '<tr>';
                   5477:                 }
                   5478:                 my $check = ' ';
1.39      raeburn  5479:                 if (ref($settings) eq 'HASH') {
                   5480:                     if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
                   5481:                         if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
                   5482:                             $check = ' checked="checked" ';
                   5483:                         }
1.27      raeburn  5484:                     }
                   5485:                 }
                   5486:                 $output .= '<td class="LC_left_item">'.
                   5487:                            '<span class="LC_nobreak"><label>'.
1.32      raeburn  5488:                            '<input type="checkbox" name="'.$type.'_rule" '.
1.27      raeburn  5489:                            'value="'.$ruleorder->[$i].'"'.$check.'/>'.
                   5490:                            $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
                   5491:             }
                   5492:         }
                   5493:         $rem = @{$ruleorder}%($numinrow);
                   5494:     }
                   5495:     my $colsleft = $numinrow - $rem;
                   5496:     if ($colsleft > 1 ) {
                   5497:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   5498:                    '&nbsp;</td>';
                   5499:     } elsif ($colsleft == 1) {
                   5500:         $output .= '<td class="LC_left_item">&nbsp;</td>';
                   5501:     }
                   5502:     $output .= '</tr></table></td></tr>';
                   5503:     return $output;
                   5504: }
                   5505: 
1.34      raeburn  5506: sub usercreation_types {
                   5507:     my %lt = &Apache::lonlocal::texthash (
                   5508:                     author     => 'When adding a co-author',
                   5509:                     course     => 'When adding a user to a course',
1.100     raeburn  5510:                     requestcrs => 'When requesting a course',
1.34      raeburn  5511:                     any        => 'Any',
                   5512:                     official   => 'Institutional only ',
                   5513:                     unofficial => 'Non-institutional only',
                   5514:                     none       => 'None',
                   5515:     );
                   5516:     return %lt;
1.48      raeburn  5517: }
1.34      raeburn  5518: 
1.224     raeburn  5519: sub selfcreation_types {
                   5520:     my %lt = &Apache::lonlocal::texthash (
                   5521:                     selfcreate => 'User creates own account',
                   5522:                     any        => 'Any',
                   5523:                     official   => 'Institutional only ',
                   5524:                     unofficial => 'Non-institutional only',
                   5525:                     email      => 'E-mail address',
                   5526:                     login      => 'Institutional Login',
                   5527:                     sso        => 'SSO',
                   5528:              );
                   5529: }
                   5530: 
1.28      raeburn  5531: sub authtype_names {
                   5532:     my %lt = &Apache::lonlocal::texthash(
                   5533:                       int    => 'Internal',
                   5534:                       krb4   => 'Kerberos 4',
                   5535:                       krb5   => 'Kerberos 5',
                   5536:                       loc    => 'Local',
                   5537:                   );
                   5538:     return %lt;
                   5539: }
                   5540: 
                   5541: sub context_names {
                   5542:     my %context_title = &Apache::lonlocal::texthash(
                   5543:        author => 'Creating users when an Author',
                   5544:        course => 'Creating users when in a course',
                   5545:        domain => 'Creating users when a Domain Coordinator',
                   5546:     );
                   5547:     return %context_title;
                   5548: }
                   5549: 
1.33      raeburn  5550: sub print_usermodification {
                   5551:     my ($position,$dom,$settings,$rowtotal) = @_;
                   5552:     my $numinrow = 4;
                   5553:     my ($context,$datatable,$rowcount);
                   5554:     if ($position eq 'top') {
                   5555:         $rowcount = 0;
                   5556:         $context = 'author'; 
                   5557:         foreach my $role ('ca','aa') {
                   5558:             $datatable .= &modifiable_userdata_row($context,$role,$settings,
                   5559:                                                    $numinrow,$rowcount);
                   5560:             $$rowtotal ++;
                   5561:             $rowcount ++;
                   5562:         }
1.230     raeburn  5563:     } elsif ($position eq 'bottom') {
1.33      raeburn  5564:         $context = 'course';
                   5565:         $rowcount = 0;
                   5566:         foreach my $role ('st','ep','ta','in','cr') {
                   5567:             $datatable .= &modifiable_userdata_row($context,$role,$settings,
                   5568:                                                    $numinrow,$rowcount);
                   5569:             $$rowtotal ++;
                   5570:             $rowcount ++;
                   5571:         }
                   5572:     }
                   5573:     return $datatable;
                   5574: }
                   5575: 
1.43      raeburn  5576: sub print_defaults {
1.236     raeburn  5577:     my ($position,$dom,$settings,$rowtotal) = @_;
1.43      raeburn  5578:     my $rownum = 0;
                   5579:     my ($datatable,$css_class);
1.236     raeburn  5580:     if ($position eq 'top') {
                   5581:         my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
                   5582:                      'datelocale_def','portal_def');
                   5583:         my %defaults;
                   5584:         if (ref($settings) eq 'HASH') {
                   5585:             %defaults = %{$settings};
1.43      raeburn  5586:         } else {
1.236     raeburn  5587:             my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
                   5588:             foreach my $item (@items) {
                   5589:                 $defaults{$item} = $domdefaults{$item};
                   5590:             }
1.43      raeburn  5591:         }
1.236     raeburn  5592:         my $titles = &defaults_titles($dom);
                   5593:         foreach my $item (@items) {
                   5594:             if ($rownum%2) {
                   5595:                 $css_class = '';
                   5596:             } else {
                   5597:                 $css_class = ' class="LC_odd_row" ';
                   5598:             }
                   5599:             $datatable .= '<tr'.$css_class.'>'.
                   5600:                           '<td><span class="LC_nobreak">'.$titles->{$item}.
                   5601:                           '</span></td><td class="LC_right_item" colspan="3">';
                   5602:             if ($item eq 'auth_def') {
                   5603:                 my @authtypes = ('internal','krb4','krb5','localauth');
                   5604:                 my %shortauth = (
                   5605:                                  internal => 'int',
                   5606:                                  krb4 => 'krb4',
                   5607:                                  krb5 => 'krb5',
                   5608:                                  localauth  => 'loc'
                   5609:                                 );
                   5610:                 my %authnames = &authtype_names();
                   5611:                 foreach my $auth (@authtypes) {
                   5612:                     my $checked = ' ';
                   5613:                     if ($defaults{$item} eq $auth) {
                   5614:                         $checked = ' checked="checked" ';
                   5615:                     }
                   5616:                     $datatable .= '<label><input type="radio" name="'.$item.
                   5617:                                   '" value="'.$auth.'"'.$checked.'/>'.
                   5618:                                   $authnames{$shortauth{$auth}}.'</label>&nbsp;&nbsp;';
                   5619:                 }
                   5620:             } elsif ($item eq 'timezone_def') {
                   5621:                 my $includeempty = 1;
                   5622:                 $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
                   5623:             } elsif ($item eq 'datelocale_def') {
                   5624:                 my $includeempty = 1;
                   5625:                 $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
                   5626:             } elsif ($item eq 'lang_def') {
1.263     raeburn  5627:                 my $includeempty = 1;
                   5628:                 $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.236     raeburn  5629:             } else {
                   5630:                 my $size;
                   5631:                 if ($item eq 'portal_def') {
                   5632:                     $size = ' size="25"';
                   5633:                 }
                   5634:                 $datatable .= '<input type="text" name="'.$item.'" value="'.
                   5635:                               $defaults{$item}.'"'.$size.' />';
1.43      raeburn  5636:             }
1.236     raeburn  5637:             $datatable .= '</td></tr>';
                   5638:             $rownum ++;
                   5639:         }
                   5640:     } else {
                   5641:         my (%defaults);
                   5642:         if (ref($settings) eq 'HASH') {
                   5643:             if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH') &&
                   5644:                 (ref($settings->{'inststatusguest'}) eq 'ARRAY')) {
                   5645:                 my $maxnum = @{$settings->{'inststatusorder'}};
                   5646:                 for (my $i=0; $i<$maxnum; $i++) {
                   5647:                     $css_class = $rownum%2?' class="LC_odd_row"':'';
                   5648:                     my $item = $settings->{'inststatusorder'}->[$i];
                   5649:                     my $title = $settings->{'inststatustypes'}->{$item};
                   5650:                     my $guestok;
                   5651:                     if (grep(/^\Q$item\E$/,@{$settings->{'inststatusguest'}})) {
                   5652:                         $guestok = 1;
                   5653:                     }
                   5654:                     my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
                   5655:                     $datatable .= '<tr'.$css_class.'>'.
                   5656:                                   '<td><span class="LC_nobreak">'.
                   5657:                                   '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
                   5658:                     for (my $k=0; $k<=$maxnum; $k++) {
                   5659:                         my $vpos = $k+1;
                   5660:                         my $selstr;
                   5661:                         if ($k == $i) {
                   5662:                             $selstr = ' selected="selected" ';
                   5663:                         }
                   5664:                         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   5665:                     }
                   5666:                     my ($checkedon,$checkedoff);
                   5667:                     $checkedoff = ' checked="checked"';
                   5668:                     if ($guestok) {
                   5669:                         $checkedon = $checkedoff;
                   5670:                         $checkedoff = ''; 
                   5671:                     }
                   5672:                     $datatable .= '</select>&nbsp;'.&mt('Internal ID:').'&nbsp;<b>'.$item.'</b>&nbsp;'.
                   5673:                                   '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
                   5674:                                   &mt('delete').'</span></td>'.
                   5675:                                   '<td class="LC_left_item"><span class="LC_nobreak">'.&mt('Name displayed:').
                   5676:                                   '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
                   5677:                                   '</span></td>'.
                   5678:                                   '<td class="LC_right_item"><span class="LC_nobreak">'.
                   5679:                                   '<label><input type="radio" value="1" name="inststatus_guest_'.$item.'"'.$checkedon.' />'.
                   5680:                                   &mt('Yes').'</label>'.('&nbsp;'x2).
                   5681:                                   '<label><input type="radio" value="0" name="inststatus_guest_'.$item.'"'.$checkedoff.' />'.
                   5682:                                   &mt('No').'</label></span></td></tr>';
                   5683:                 }
                   5684:                 $css_class = $rownum%2?' class="LC_odd_row"':'';
                   5685:                 my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
                   5686:                 $datatable .= '<tr '.$css_class.'>'.
                   5687:                               '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
                   5688:                 for (my $k=0; $k<=$maxnum; $k++) {
                   5689:                     my $vpos = $k+1;
                   5690:                     my $selstr;
                   5691:                     if ($k == $maxnum) {
                   5692:                         $selstr = ' selected="selected" ';
                   5693:                     }
                   5694:                     $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   5695:                 }
                   5696:                 $datatable .= '</select>&nbsp;'.&mt('Internal ID:').
1.263     raeburn  5697:                               '<input type="text" size="10" name="addinststatus" value="" />'.
1.236     raeburn  5698:                               '&nbsp;'.&mt('(new)').
                   5699:                               '</span></td><td class="LC_left_item"><span class="LC_nobreak">'.
                   5700:                               &mt('Name displayed:').
                   5701:                               '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
                   5702:                               '<td class="LC_right_item"><span class="LC_nobreak">'.
                   5703:                               '<label><input type="radio" value="1" name="addinststatus_guest" />'.
                   5704:                               &mt('Yes').'</label>'.('&nbsp;'x2).
                   5705:                               '<label><input type="radio" value="0" name="addinststatus_guest" />'.
                   5706:                               &mt('No').'</label></span></td></tr>';
                   5707:                               '</tr>'."\n";
                   5708:                 $rownum ++;
1.141     raeburn  5709:             }
1.43      raeburn  5710:         }
                   5711:     }
                   5712:     $$rowtotal += $rownum;
                   5713:     return $datatable;
                   5714: }
                   5715: 
1.168     raeburn  5716: sub get_languages_hash {
                   5717:     my %langchoices;
                   5718:     foreach my $id (&Apache::loncommon::languageids()) {
                   5719:         my $code = &Apache::loncommon::supportedlanguagecode($id);
                   5720:         if ($code ne '') {
                   5721:             $langchoices{$code} =  &Apache::loncommon::plainlanguagedescription($id);
                   5722:         }
                   5723:     }
                   5724:     return %langchoices;
                   5725: }
                   5726: 
1.43      raeburn  5727: sub defaults_titles {
1.141     raeburn  5728:     my ($dom) = @_;
1.43      raeburn  5729:     my %titles = &Apache::lonlocal::texthash (
                   5730:                    'auth_def'      => 'Default authentication type',
                   5731:                    'auth_arg_def'  => 'Default authentication argument',
                   5732:                    'lang_def'      => 'Default language',
1.54      raeburn  5733:                    'timezone_def'  => 'Default timezone',
1.68      raeburn  5734:                    'datelocale_def' => 'Default locale for dates',
1.141     raeburn  5735:                    'portal_def'     => 'Portal/Default URL',
1.43      raeburn  5736:                  );
1.141     raeburn  5737:     if ($dom) {
                   5738:         my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
                   5739:         my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
                   5740:         my $protocol = $Apache::lonnet::protocol{$uprimary_id};
                   5741:         $protocol = 'http' if ($protocol ne 'https');
                   5742:         if ($uint_dom) {
                   5743:             $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
                   5744:                                          $uint_dom);
                   5745:         }
                   5746:     }
1.43      raeburn  5747:     return (\%titles);
                   5748: }
                   5749: 
1.46      raeburn  5750: sub print_scantronformat {
                   5751:     my ($r,$dom,$confname,$settings,$rowtotal) = @_;
                   5752:     my $itemcount = 1;
1.60      raeburn  5753:     my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
                   5754:         %confhash);
1.46      raeburn  5755:     my $switchserver = &check_switchserver($dom,$confname);
                   5756:     my %lt = &Apache::lonlocal::texthash (
1.95      www      5757:                 default => 'Default bubblesheet format file error',
                   5758:                 custom  => 'Custom bubblesheet format file error',
1.46      raeburn  5759:              );
                   5760:     my %scantronfiles = (
                   5761:         default => 'default.tab',
                   5762:         custom => 'custom.tab',
                   5763:     );
                   5764:     foreach my $key (keys(%scantronfiles)) {
                   5765:         $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
                   5766:                               .$scantronfiles{$key};
                   5767:     }
                   5768:     my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
                   5769:     if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
                   5770:         if (!$switchserver) {
                   5771:             my $servadm = $r->dir_config('lonAdmEMail');
                   5772:             my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
                   5773:             if ($configuserok eq 'ok') {
                   5774:                 if ($author_ok eq 'ok') {
                   5775:                     my %legacyfile = (
                   5776:  default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab', 
                   5777:  custom  => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab', 
                   5778:                     );
                   5779:                     my %md5chk;
                   5780:                     foreach my $type (keys(%legacyfile)) {
1.60      raeburn  5781:                         ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
                   5782:                         chomp($md5chk{$type});
1.46      raeburn  5783:                     }
                   5784:                     if ($md5chk{'default'} ne $md5chk{'custom'}) {
                   5785:                         foreach my $type (keys(%legacyfile)) {
1.60      raeburn  5786:                             ($scantronurls{$type},my $error) = 
1.46      raeburn  5787:                                 &legacy_scantronformat($r,$dom,$confname,
                   5788:                                                  $type,$legacyfile{$type},
                   5789:                                                  $scantronurls{$type},
                   5790:                                                  $scantronfiles{$type});
1.60      raeburn  5791:                             if ($error ne '') {
                   5792:                                 $error{$type} = $error;
                   5793:                             }
                   5794:                         }
                   5795:                         if (keys(%error) == 0) {
                   5796:                             $is_custom = 1;
                   5797:                             $confhash{'scantron'}{'scantronformat'} = 
                   5798:                                 $scantronurls{'custom'};
                   5799:                             my $putresult = 
                   5800:                                 &Apache::lonnet::put_dom('configuration',
                   5801:                                                          \%confhash,$dom);
                   5802:                             if ($putresult ne 'ok') {
                   5803:                                 $error{'custom'} = 
                   5804:                                     '<span class="LC_error">'.
                   5805:                                     &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
                   5806:                             }
1.46      raeburn  5807:                         }
                   5808:                     } else {
1.60      raeburn  5809:                         ($scantronurls{'default'},my $error) =
1.46      raeburn  5810:                             &legacy_scantronformat($r,$dom,$confname,
                   5811:                                           'default',$legacyfile{'default'},
                   5812:                                           $scantronurls{'default'},
                   5813:                                           $scantronfiles{'default'});
1.60      raeburn  5814:                         if ($error eq '') {
                   5815:                             $confhash{'scantron'}{'scantronformat'} = ''; 
                   5816:                             my $putresult =
                   5817:                                 &Apache::lonnet::put_dom('configuration',
                   5818:                                                          \%confhash,$dom);
                   5819:                             if ($putresult ne 'ok') {
                   5820:                                 $error{'default'} =
                   5821:                                     '<span class="LC_error">'.
                   5822:                                     &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
                   5823:                             }
                   5824:                         } else {
                   5825:                             $error{'default'} = $error;
                   5826:                         }
1.46      raeburn  5827:                     }
                   5828:                 }
                   5829:             }
                   5830:         } else {
1.95      www      5831:             $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46      raeburn  5832:         }
                   5833:     }
                   5834:     if (ref($settings) eq 'HASH') {
                   5835:         if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
                   5836:             my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
                   5837:             if ((!@info) || ($info[0] eq 'no_such_dir')) {
                   5838:                 $scantronurl = '';
                   5839:             } else {
                   5840:                 $scantronurl = $settings->{'scantronformat'};
                   5841:             }
                   5842:             $is_custom = 1;
                   5843:         } else {
                   5844:             $scantronurl = $scantronurls{'default'};
                   5845:         }
                   5846:     } else {
1.60      raeburn  5847:         if ($is_custom) {
                   5848:             $scantronurl = $scantronurls{'custom'};
                   5849:         } else {
                   5850:             $scantronurl = $scantronurls{'default'};
                   5851:         }
1.46      raeburn  5852:     }
                   5853:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   5854:     $datatable .= '<tr'.$css_class.'>';
                   5855:     if (!$is_custom) {
1.65      raeburn  5856:         $datatable .= '<td>'.&mt('Default in use:').'<br />'.
                   5857:                       '<span class="LC_nobreak">';
1.46      raeburn  5858:         if ($scantronurl) {
1.199     raeburn  5859:             $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
                   5860:                                                          undef,undef,undef,undef,'background-color:#ffffff');
1.46      raeburn  5861:         } else {
                   5862:             $datatable = &mt('File unavailable for display');
                   5863:         }
1.65      raeburn  5864:         $datatable .= '</span></td>';
1.60      raeburn  5865:         if (keys(%error) == 0) { 
                   5866:             $datatable .= '<td valign="bottom">';
                   5867:             if (!$switchserver) {
                   5868:                 $datatable .= &mt('Upload:').'<br />';
                   5869:             }
                   5870:         } else {
                   5871:             my $errorstr;
                   5872:             foreach my $key (sort(keys(%error))) {
                   5873:                 $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
                   5874:             }
                   5875:             $datatable .= '<td>'.$errorstr;
                   5876:         }
1.46      raeburn  5877:     } else {
                   5878:         if (keys(%error) > 0) {
                   5879:             my $errorstr;
                   5880:             foreach my $key (sort(keys(%error))) {
                   5881:                 $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
                   5882:             } 
1.60      raeburn  5883:             $datatable .= '<td>'.$errorstr.'</td><td>&nbsp;';
1.46      raeburn  5884:         } elsif ($scantronurl) {
1.199     raeburn  5885:             my $link =  &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
                   5886:                                                        undef,undef,undef,undef,'background-color:#ffffff');
1.65      raeburn  5887:             $datatable .= '<td><span class="LC_nobreak">'.
1.199     raeburn  5888:                           $link.
                   5889:                           '<label><input type="checkbox" name="scantronformat_del"'.
                   5890:                           ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65      raeburn  5891:                           '<td><span class="LC_nobreak">&nbsp;'.
                   5892:                           &mt('Replace:').'</span><br />';
1.46      raeburn  5893:         }
                   5894:     }
                   5895:     if (keys(%error) == 0) {
                   5896:         if ($switchserver) {
                   5897:             $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   5898:         } else {
1.65      raeburn  5899:             $datatable .='<span class="LC_nobreak">&nbsp;'.
                   5900:                          '<input type="file" name="scantronformat" /></span>';
1.46      raeburn  5901:         }
                   5902:     }
                   5903:     $datatable .= '</td></tr>';
                   5904:     $$rowtotal ++;
                   5905:     return $datatable;
                   5906: }
                   5907: 
                   5908: sub legacy_scantronformat {
                   5909:     my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
                   5910:     my ($url,$error);
                   5911:     my @statinfo = &Apache::lonnet::stat_file($newurl);
                   5912:     if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
                   5913:         (my $result,$url) =
                   5914:             &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
                   5915:                          '','',$newfile);
                   5916:         if ($result ne 'ok') {
1.130     raeburn  5917:             $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46      raeburn  5918:         }
                   5919:     }
                   5920:     return ($url,$error);
                   5921: }
1.43      raeburn  5922: 
1.49      raeburn  5923: sub print_coursecategories {
1.57      raeburn  5924:     my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
                   5925:     my $datatable;
                   5926:     if ($position eq 'top') {
1.238     raeburn  5927:         my (%checked);
                   5928:         my @catitems = ('unauth','auth');
                   5929:         my @cattypes = ('std','domonly','codesrch','none');
                   5930:         $checked{'unauth'} = 'std';
                   5931:         $checked{'auth'} = 'std';
                   5932:         if (ref($settings) eq 'HASH') {
                   5933:             foreach my $type (@cattypes) {
                   5934:                 if ($type eq $settings->{'unauth'}) {
                   5935:                     $checked{'unauth'} = $type;
                   5936:                 }
                   5937:                 if ($type eq $settings->{'auth'}) {
                   5938:                     $checked{'auth'} = $type;
                   5939:                 }
                   5940:             }
                   5941:         }
                   5942:         my %lt = &Apache::lonlocal::texthash (
                   5943:                                                unauth   => 'Catalog type for unauthenticated users',
                   5944:                                                auth     => 'Catalog type for authenticated users',
                   5945:                                                none     => 'No catalog',
                   5946:                                                std      => 'Standard catalog',
                   5947:                                                domonly  => 'Domain-only catalog',
                   5948:                                                codesrch => "Code search form",
                   5949:                                              );
                   5950:        my $itemcount = 0;
                   5951:        foreach my $item (@catitems) {
                   5952:            my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
                   5953:            $datatable .= '<tr '.$css_class.'>'.
                   5954:                          '<td>'.$lt{$item}.'</td>'.
                   5955:                          '<td class="LC_right_item"><span class="LC_nobreak">';
                   5956:            foreach my $type (@cattypes) {
                   5957:                my $ischecked;
                   5958:                if ($checked{$item} eq $type) {
                   5959:                    $ischecked=' checked="checked"';
                   5960:                }
                   5961:                $datatable .= '<label>'.
                   5962:                              '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
                   5963:                              ' />'.$lt{$type}.'</label>&nbsp;';
                   5964:            }
                   5965:            $datatable .= '</td></tr>';
                   5966:            $itemcount ++;
                   5967:         }
                   5968:         $$rowtotal += $itemcount;
                   5969:     } elsif ($position eq 'middle') {
1.57      raeburn  5970:         my $toggle_cats_crs = ' ';
                   5971:         my $toggle_cats_dom = ' checked="checked" ';
                   5972:         my $can_cat_crs = ' ';
                   5973:         my $can_cat_dom = ' checked="checked" ';
1.120     raeburn  5974:         my $toggle_catscomm_comm = ' ';
                   5975:         my $toggle_catscomm_dom = ' checked="checked" ';
                   5976:         my $can_catcomm_comm = ' ';
                   5977:         my $can_catcomm_dom = ' checked="checked" ';
1.272     raeburn  5978:         my $toggle_catsplace_place = ' ';
                   5979:         my $toggle_catsplace_dom = ' checked="checked" ';
                   5980:         my $can_catplace_place = ' ';
                   5981:         my $can_catplace_dom = ' checked="checked" ';
1.120     raeburn  5982: 
1.57      raeburn  5983:         if (ref($settings) eq 'HASH') {
                   5984:             if ($settings->{'togglecats'} eq 'crs') {
                   5985:                 $toggle_cats_crs = $toggle_cats_dom;
                   5986:                 $toggle_cats_dom = ' ';
                   5987:             }
                   5988:             if ($settings->{'categorize'} eq 'crs') {
                   5989:                 $can_cat_crs = $can_cat_dom;
                   5990:                 $can_cat_dom = ' ';
                   5991:             }
1.120     raeburn  5992:             if ($settings->{'togglecatscomm'} eq 'comm') {
                   5993:                 $toggle_catscomm_comm = $toggle_catscomm_dom;
                   5994:                 $toggle_catscomm_dom = ' ';
                   5995:             }
                   5996:             if ($settings->{'categorizecomm'} eq 'comm') {
                   5997:                 $can_catcomm_comm = $can_catcomm_dom;
                   5998:                 $can_catcomm_dom = ' ';
                   5999:             }
1.272     raeburn  6000:             if ($settings->{'togglecatsplace'} eq 'place') {
                   6001:                 $toggle_catsplace_place = $toggle_catsplace_dom;
                   6002:                 $toggle_catsplace_dom = ' ';
                   6003:             }
                   6004:             if ($settings->{'categorizeplace'} eq 'place') {
                   6005:                 $can_catplace_place = $can_catplace_dom;
                   6006:                 $can_catplace_dom = ' ';
                   6007:             }
1.57      raeburn  6008:         }
                   6009:         my %title = &Apache::lonlocal::texthash (
1.272     raeburn  6010:                      togglecats      => 'Show/Hide a course in catalog',
                   6011:                      togglecatscomm  => 'Show/Hide a community in catalog',
                   6012:                      togglecatsplace => 'Show/Hide a placement test in catalog',
                   6013:                      categorize      => 'Assign a category to a course',
                   6014:                      categorizecomm  => 'Assign a category to a community',
                   6015:                      categorizeplace => 'Assign a category to a placement test',
1.57      raeburn  6016:                     );
                   6017:         my %level = &Apache::lonlocal::texthash (
1.272     raeburn  6018:                      dom   => 'Set in Domain',
                   6019:                      crs   => 'Set in Course',
                   6020:                      comm  => 'Set in Community',
                   6021:                      place => 'Set in Placement Test',
1.57      raeburn  6022:                     );
                   6023:         $datatable = '<tr class="LC_odd_row">'.
                   6024:                   '<td>'.$title{'togglecats'}.'</td>'.
                   6025:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   6026:                   '<input type="radio" name="togglecats"'.
                   6027:                   $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   6028:                   '<label><input type="radio" name="togglecats"'.
                   6029:                   $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
                   6030:                   '</tr><tr>'.
                   6031:                   '<td>'.$title{'categorize'}.'</td>'.
                   6032:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
                   6033:                   '<label><input type="radio" name="categorize"'.
                   6034:                   $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   6035:                   '<label><input type="radio" name="categorize"'.
                   6036:                   $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120     raeburn  6037:                   '</tr><tr class="LC_odd_row">'.
                   6038:                   '<td>'.$title{'togglecatscomm'}.'</td>'.
                   6039:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   6040:                   '<input type="radio" name="togglecatscomm"'.
                   6041:                   $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   6042:                   '<label><input type="radio" name="togglecatscomm"'.
                   6043:                   $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
                   6044:                   '</tr><tr>'.
                   6045:                   '<td>'.$title{'categorizecomm'}.'</td>'.
                   6046:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
                   6047:                   '<label><input type="radio" name="categorizecomm"'.
                   6048:                   $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   6049:                   '<label><input type="radio" name="categorizecomm"'.
                   6050:                   $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.272     raeburn  6051:                   '</tr><tr>'.
                   6052:                   '<td>'.$title{'togglecatsplace'}.'</td>'.
                   6053:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   6054:                   '<input type="radio" name="togglecatsplace"'.
                   6055:                   $toggle_catsplace_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   6056:                   '<label><input type="radio" name="togglecatscomm"'.
                   6057:                   $toggle_catsplace_place.' value="comm" />'.$level{'place'}.'</label></span></td>'.
                   6058:                   '</tr><tr>'.
                   6059:                   '<td>'.$title{'categorizeplace'}.'</td>'.
                   6060:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
                   6061:                   '<label><input type="radio" name="categorizeplace"'.
                   6062:                   $can_catplace_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   6063:                   '<label><input type="radio" name="categorizeplace"'.
                   6064:                   $can_catplace_place.'value="place" />'.$level{'place'}.'</label></span></td>'.
1.57      raeburn  6065:                   '</tr>';
1.272     raeburn  6066:         $$rowtotal += 6;
1.57      raeburn  6067:     } else {
                   6068:         my $css_class;
                   6069:         my $itemcount = 1;
                   6070:         my $cathash; 
                   6071:         if (ref($settings) eq 'HASH') {
                   6072:             $cathash = $settings->{'cats'};
                   6073:         }
                   6074:         if (ref($cathash) eq 'HASH') {
                   6075:             my (@cats,@trails,%allitems,%idx,@jsarray);
                   6076:             &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
                   6077:                                                    \%allitems,\%idx,\@jsarray);
                   6078:             my $maxdepth = scalar(@cats);
                   6079:             my $colattrib = '';
                   6080:             if ($maxdepth > 2) {
                   6081:                 $colattrib = ' colspan="2" ';
                   6082:             }
                   6083:             my @path;
                   6084:             if (@cats > 0) {
                   6085:                 if (ref($cats[0]) eq 'ARRAY') {
                   6086:                     my $numtop = @{$cats[0]};
                   6087:                     my $maxnum = $numtop;
1.120     raeburn  6088:                     my %default_names = (
                   6089:                           instcode    => &mt('Official courses'),
                   6090:                           communities => &mt('Communities'),
1.272     raeburn  6091:                           placement   => &mt('Placement Tests'),
1.120     raeburn  6092:                     );
                   6093: 
                   6094:                     if ((!grep(/^instcode$/,@{$cats[0]})) || 
                   6095:                         ($cathash->{'instcode::0'} eq '') ||
                   6096:                         (!grep(/^communities$/,@{$cats[0]})) || 
1.272     raeburn  6097:                         ($cathash->{'communities::0'} eq '') ||
                   6098:                         (!grep(/^placement$/,@{$cats[0]})) ||
                   6099:                         ($cathash->{'placement::0'} eq '')) {
1.57      raeburn  6100:                         $maxnum ++;
                   6101:                     }
                   6102:                     my $lastidx;
                   6103:                     for (my $i=0; $i<$numtop; $i++) {
                   6104:                         my $parent = $cats[0][$i];
                   6105:                         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   6106:                         my $item = &escape($parent).'::0';
                   6107:                         my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
                   6108:                         $lastidx = $idx{$item};
                   6109:                         $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
                   6110:                                       .'<select name="'.$item.'"'.$chgstr.'>';
                   6111:                         for (my $k=0; $k<=$maxnum; $k++) {
                   6112:                             my $vpos = $k+1;
                   6113:                             my $selstr;
                   6114:                             if ($k == $i) {
                   6115:                                 $selstr = ' selected="selected" ';
                   6116:                             }
                   6117:                             $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   6118:                         }
1.214     raeburn  6119:                         $datatable .= '</select></span></td><td>';
1.272     raeburn  6120:                         if ($parent eq 'instcode' || $parent eq 'communities' || $parent eq 'placement') {
1.120     raeburn  6121:                             $datatable .=  '<span class="LC_nobreak">'
                   6122:                                            .$default_names{$parent}.'</span>';
                   6123:                             if ($parent eq 'instcode') {
                   6124:                                 $datatable .= '<br /><span class="LC_nobreak">('
                   6125:                                               .&mt('with institutional codes')
                   6126:                                               .')</span></td><td'.$colattrib.'>';
                   6127:                             } else {
                   6128:                                 $datatable .= '<table><tr><td>';
                   6129:                             }
                   6130:                             $datatable .= '<span class="LC_nobreak">'
                   6131:                                           .'<label><input type="radio" name="'
                   6132:                                           .$parent.'" value="1" checked="checked" />'
                   6133:                                           .&mt('Display').'</label>';
                   6134:                             if ($parent eq 'instcode') {
                   6135:                                 $datatable .= '&nbsp;';
                   6136:                             } else {
                   6137:                                 $datatable .= '</span></td></tr><tr><td>'
                   6138:                                               .'<span class="LC_nobreak">';
                   6139:                             }
                   6140:                             $datatable .= '<label><input type="radio" name="'
                   6141:                                           .$parent.'" value="0" />'
                   6142:                                           .&mt('Do not display').'</label></span>';
1.272     raeburn  6143:                             if (($parent eq 'communities') || ($parent eq 'placement')) {
1.120     raeburn  6144:                                 $datatable .= '</td></tr></table>';
                   6145:                             }
                   6146:                             $datatable .= '</td>';
1.57      raeburn  6147:                         } else {
                   6148:                             $datatable .= $parent
1.214     raeburn  6149:                                           .'&nbsp;<span class="LC_nobreak"><label>'
                   6150:                                           .'<input type="checkbox" name="deletecategory" '
1.57      raeburn  6151:                                           .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
                   6152:                         }
                   6153:                         my $depth = 1;
                   6154:                         push(@path,$parent);
                   6155:                         $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
                   6156:                         pop(@path);
                   6157:                         $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
                   6158:                         $itemcount ++;
                   6159:                     }
1.48      raeburn  6160:                     $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57      raeburn  6161:                     my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
                   6162:                     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48      raeburn  6163:                     for (my $k=0; $k<=$maxnum; $k++) {
                   6164:                         my $vpos = $k+1;
                   6165:                         my $selstr;
1.57      raeburn  6166:                         if ($k == $numtop) {
1.48      raeburn  6167:                             $selstr = ' selected="selected" ';
                   6168:                         }
                   6169:                         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   6170:                     }
1.59      bisitz   6171:                     $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').'&nbsp;'
1.57      raeburn  6172:                                   .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
                   6173:                                   .'</tr>'."\n";
1.48      raeburn  6174:                     $itemcount ++;
1.272     raeburn  6175:                     foreach my $default ('instcode','communities','placement') {
1.120     raeburn  6176:                         if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
                   6177:                             $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   6178:                             my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
                   6179:                             $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
                   6180:                                           '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
                   6181:                             for (my $k=0; $k<=$maxnum; $k++) {
                   6182:                                 my $vpos = $k+1;
                   6183:                                 my $selstr;
                   6184:                                 if ($k == $maxnum) {
                   6185:                                     $selstr = ' selected="selected" ';
                   6186:                                 }
                   6187:                                 $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57      raeburn  6188:                             }
1.120     raeburn  6189:                             $datatable .= '</select></span></td>'.
                   6190:                                           '<td><span class="LC_nobreak">'.
                   6191:                                           $default_names{$default}.'</span>';
                   6192:                             if ($default eq 'instcode') {
                   6193:                                 $datatable .= '<br /><span class="LC_nobreak">(' 
                   6194:                                               .&mt('with institutional codes').')</span>';
                   6195:                             }
                   6196:                             $datatable .= '</td>'
                   6197:                                           .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
                   6198:                                           .&mt('Display').'</label>&nbsp;'
                   6199:                                           .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
                   6200:                                           .&mt('Do not display').'</label></span></td></tr>';
1.48      raeburn  6201:                         }
                   6202:                     }
                   6203:                 }
1.57      raeburn  6204:             } else {
                   6205:                 $datatable .= &initialize_categories($itemcount);
1.48      raeburn  6206:             }
                   6207:         } else {
1.238     raeburn  6208:             $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td>'
1.57      raeburn  6209:                           .&initialize_categories($itemcount);
1.48      raeburn  6210:         }
1.57      raeburn  6211:         $$rowtotal += $itemcount;
1.48      raeburn  6212:     }
                   6213:     return $datatable;
                   6214: }
                   6215: 
1.69      raeburn  6216: sub print_serverstatuses {
                   6217:     my ($dom,$settings,$rowtotal) = @_;
                   6218:     my $datatable;
                   6219:     my @pages = &serverstatus_pages();
                   6220:     my (%namedaccess,%machineaccess);
                   6221:     foreach my $type (@pages) {
                   6222:         $namedaccess{$type} = '';
                   6223:         $machineaccess{$type}= '';
                   6224:     }
                   6225:     if (ref($settings) eq 'HASH') {
                   6226:         foreach my $type (@pages) {
                   6227:             if (exists($settings->{$type})) {
                   6228:                 if (ref($settings->{$type}) eq 'HASH') {
                   6229:                     foreach my $key (keys(%{$settings->{$type}})) {
                   6230:                         if ($key eq 'namedusers') {
                   6231:                             $namedaccess{$type} = $settings->{$type}->{$key};
                   6232:                         } elsif ($key eq 'machines') {
                   6233:                             $machineaccess{$type} = $settings->{$type}->{$key};
                   6234:                         }
                   6235:                     }
                   6236:                 }
                   6237:             }
                   6238:         }
                   6239:     }
1.81      raeburn  6240:     my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69      raeburn  6241:     my $rownum = 0;
                   6242:     my $css_class;
                   6243:     foreach my $type (@pages) {
                   6244:         $rownum ++;
                   6245:         $css_class = $rownum%2?' class="LC_odd_row"':'';
                   6246:         $datatable .= '<tr'.$css_class.'>'.
                   6247:                       '<td><span class="LC_nobreak">'.
                   6248:                       $titles->{$type}.'</span></td>'.
                   6249:                       '<td class="LC_left_item">'.
                   6250:                       '<input type="text" name="'.$type.'_namedusers" '.
                   6251:                       'value="'.$namedaccess{$type}.'" size="30" /></td>'.
                   6252:                       '<td class="LC_right_item">'.
                   6253:                       '<span class="LC_nobreak">'.
                   6254:                       '<input type="text" name="'.$type.'_machines" '.
                   6255:                       'value="'.$machineaccess{$type}.'" size="10" />'.
                   6256:                       '</td></tr>'."\n";
                   6257:     }
                   6258:     $$rowtotal += $rownum;
                   6259:     return $datatable;
                   6260: }
                   6261: 
                   6262: sub serverstatus_pages {
                   6263:     return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.275     raeburn  6264:             'checksums','clusterstatus','certstatus','metadata_keywords',
                   6265:             'metadata_harvest','takeoffline','takeonline','showenv','toggledebug',
                   6266:             'ping','domconf','uniquecodes','diskusage','coursecatalog');
1.69      raeburn  6267: }
                   6268: 
1.236     raeburn  6269: sub defaults_javascript {
                   6270:     my ($settings) = @_;
1.248     raeburn  6271:     return unless (ref($settings) eq 'HASH'); 
1.236     raeburn  6272:     if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
                   6273:         my $maxnum = scalar(@{$settings->{'inststatusorder'}});
                   6274:         if ($maxnum eq '') {
                   6275:             $maxnum = 0;
                   6276:         }
                   6277:         $maxnum ++;
1.249     raeburn  6278:         my $jstext = '    var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';  
1.236     raeburn  6279:         return <<"ENDSCRIPT";
                   6280: <script type="text/javascript">
                   6281: // <![CDATA[
                   6282: function reorderTypes(form,caller) {
                   6283:     var changedVal;
                   6284: $jstext 
                   6285:     var newpos = 'addinststatus_pos';
                   6286:     var current = new Array;
                   6287:     var maxh = $maxnum;
                   6288:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
                   6289:     var oldVal;
                   6290:     if (caller == newpos) {
                   6291:         changedVal = newitemVal;
                   6292:     } else {
                   6293:         var curritem = 'inststatus_pos_'+caller;
                   6294:         changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
                   6295:         current[newitemVal] = newpos;
                   6296:     }
                   6297:     for (var i=0; i<inststatuses.length; i++) {
                   6298:         if (inststatuses[i] != caller) {
                   6299:             var elementName = 'inststatus_pos_'+inststatuses[i];
                   6300:             if (form.elements[elementName]) {
                   6301:                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   6302:                 current[currVal] = elementName;
                   6303:             }
                   6304:         }
                   6305:     }
                   6306:     for (var j=0; j<maxh; j++) {
                   6307:         if (current[j] == undefined) {
                   6308:             oldVal = j;
                   6309:         }
                   6310:     }
                   6311:     if (oldVal < changedVal) {
                   6312:         for (var k=oldVal+1; k<=changedVal ; k++) {
                   6313:            var elementName = current[k];
                   6314:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   6315:         }
                   6316:     } else {
                   6317:         for (var k=changedVal; k<oldVal; k++) {
                   6318:             var elementName = current[k];
                   6319:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   6320:         }
                   6321:     }
                   6322:     return;
                   6323: }
                   6324: 
                   6325: // ]]>
                   6326: </script>
                   6327: 
                   6328: ENDSCRIPT
                   6329:     }
                   6330: }
                   6331: 
1.49      raeburn  6332: sub coursecategories_javascript {
                   6333:     my ($settings) = @_;
1.57      raeburn  6334:     my ($output,$jstext,$cathash);
1.49      raeburn  6335:     if (ref($settings) eq 'HASH') {
1.57      raeburn  6336:         $cathash = $settings->{'cats'};
                   6337:     }
                   6338:     if (ref($cathash) eq 'HASH') {
1.49      raeburn  6339:         my (@cats,@jsarray,%idx);
1.57      raeburn  6340:         &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49      raeburn  6341:         if (@jsarray > 0) {
                   6342:             $jstext = '    var categories = Array('.scalar(@jsarray).');'."\n";
                   6343:             for (my $i=0; $i<@jsarray; $i++) {
                   6344:                 if (ref($jsarray[$i]) eq 'ARRAY') {
                   6345:                     my $catstr = join('","',@{$jsarray[$i]});
                   6346:                     $jstext .= '    categories['.$i.'] = Array("'.$catstr.'");'."\n";
                   6347:                 }
                   6348:             }
                   6349:         }
                   6350:     } else {
                   6351:         $jstext  = '    var categories = Array(1);'."\n".
                   6352:                    '    categories[0] = Array("instcode_pos");'."\n"; 
                   6353:     }
1.237     bisitz   6354:     my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
                   6355:     my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.272     raeburn  6356:     my $placement_reserved = &mt('The name: [_1] is a reserved category.','"placement"');
1.265     damieng  6357:     my $choose_again = "\n".&mt('Please use a different name for the new top level category.'); 
                   6358:     &js_escape(\$instcode_reserved);
                   6359:     &js_escape(\$communities_reserved);
1.272     raeburn  6360:     &js_escape(\$placement_reserved);
1.265     damieng  6361:     &js_escape(\$choose_again);
1.49      raeburn  6362:     $output = <<"ENDSCRIPT";
                   6363: <script type="text/javascript">
1.109     raeburn  6364: // <![CDATA[
1.49      raeburn  6365: function reorderCats(form,parent,item,idx) {
                   6366:     var changedVal;
                   6367: $jstext
                   6368:     var newpos = 'addcategory_pos';
                   6369:     if (parent == '') {
                   6370:         var has_instcode = 0;
                   6371:         var maxtop = categories[idx].length;
                   6372:         for (var j=0; j<maxtop; j++) {
                   6373:             if (categories[idx][j] == 'instcode::0') {
                   6374:                 has_instcode == 1;
                   6375:             }
                   6376:         }
                   6377:         if (has_instcode == 0) {
                   6378:             categories[idx][maxtop] = 'instcode_pos';
                   6379:         }
                   6380:     } else {
                   6381:         newpos += '_'+parent;
                   6382:     }
                   6383:     var maxh = 1 + categories[idx].length;
                   6384:     var current = new Array;
                   6385:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
                   6386:     if (item == newpos) {
                   6387:         changedVal = newitemVal;
                   6388:     } else {
                   6389:         changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
                   6390:         current[newitemVal] = newpos;
                   6391:     }
                   6392:     for (var i=0; i<categories[idx].length; i++) {
                   6393:         var elementName = categories[idx][i];
                   6394:         if (elementName != item) {
                   6395:             if (form.elements[elementName]) {
                   6396:                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   6397:                 current[currVal] = elementName;
                   6398:             }
                   6399:         }
                   6400:     }
                   6401:     var oldVal;
                   6402:     for (var j=0; j<maxh; j++) {
                   6403:         if (current[j] == undefined) {
                   6404:             oldVal = j;
                   6405:         }
                   6406:     }
                   6407:     if (oldVal < changedVal) {
                   6408:         for (var k=oldVal+1; k<=changedVal ; k++) {
                   6409:            var elementName = current[k];
                   6410:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   6411:         }
                   6412:     } else {
                   6413:         for (var k=changedVal; k<oldVal; k++) {
                   6414:             var elementName = current[k];
                   6415:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   6416:         }
                   6417:     }
                   6418:     return;
                   6419: }
1.120     raeburn  6420: 
                   6421: function categoryCheck(form) {
                   6422:     if (form.elements['addcategory_name'].value == 'instcode') {
                   6423:         alert('$instcode_reserved\\n$choose_again');
                   6424:         return false;
                   6425:     }
                   6426:     if (form.elements['addcategory_name'].value == 'communities') {
                   6427:         alert('$communities_reserved\\n$choose_again');
                   6428:         return false;
                   6429:     }
1.272     raeburn  6430:     if (form.elements['addcategory_name'].value == 'placement') {
                   6431:         alert('$placement_reserved\\n$choose_again');
                   6432:         return false;
                   6433:     }
1.120     raeburn  6434:     return true;
                   6435: }
                   6436: 
1.109     raeburn  6437: // ]]>
1.49      raeburn  6438: </script>
                   6439: 
                   6440: ENDSCRIPT
                   6441:     return $output;
                   6442: }
                   6443: 
1.48      raeburn  6444: sub initialize_categories {
                   6445:     my ($itemcount) = @_;
1.120     raeburn  6446:     my ($datatable,$css_class,$chgstr);
                   6447:     my %default_names = (
                   6448:                       instcode    => 'Official courses (with institutional codes)',
                   6449:                       communities => 'Communities',
1.272     raeburn  6450:                       placement   => 'Placement Tests',
1.120     raeburn  6451:                         );
                   6452:     my $select0 = ' selected="selected"';
                   6453:     my $select1 = '';
1.272     raeburn  6454:     foreach my $default ('instcode','communities','placement') {
1.120     raeburn  6455:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   6456:         $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
1.272     raeburn  6457:         if (($default eq 'communities') || ($default eq 'placement')) {
1.120     raeburn  6458:             $select1 = $select0;
                   6459:             $select0 = '';
                   6460:         }
                   6461:         $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
                   6462:                      .'<select name="'.$default.'_pos">'
                   6463:                      .'<option value="0"'.$select0.'>1</option>'
                   6464:                      .'<option value="1"'.$select1.'>2</option>'
                   6465:                      .'<option value="2">3</option></select>&nbsp;'
                   6466:                      .$default_names{$default}
                   6467:                      .'</span></td><td><span class="LC_nobreak">'
                   6468:                      .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
                   6469:                      .&mt('Display').'</label>&nbsp;<label>'
                   6470:                      .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48      raeburn  6471:                  .'</label></span></td></tr>';
1.120     raeburn  6472:         $itemcount ++;
                   6473:     }
1.48      raeburn  6474:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49      raeburn  6475:     $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48      raeburn  6476:     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120     raeburn  6477:                   .'<select name="addcategory_pos"'.$chgstr.'>'
                   6478:                   .'<option value="0">1</option>'
                   6479:                   .'<option value="1">2</option>'
                   6480:                   .'<option value="2" selected="selected">3</option></select>&nbsp;'
1.48      raeburn  6481:                   .&mt('Add category').'</td><td>'.&mt('Name:')
                   6482:                   .'&nbsp;<input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
                   6483:     return $datatable;
                   6484: }
                   6485: 
                   6486: sub build_category_rows {
1.49      raeburn  6487:     my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
                   6488:     my ($text,$name,$item,$chgstr);
1.48      raeburn  6489:     if (ref($cats) eq 'ARRAY') {
                   6490:         my $maxdepth = scalar(@{$cats});
                   6491:         if (ref($cats->[$depth]) eq 'HASH') {
                   6492:             if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
                   6493:                 my $numchildren = @{$cats->[$depth]{$parent}};
                   6494:                 my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204     raeburn  6495:                 $text .= '<td><table class="LC_data_table">';
1.49      raeburn  6496:                 my ($idxnum,$parent_name,$parent_item);
                   6497:                 my $higher = $depth - 1;
                   6498:                 if ($higher == 0) {
                   6499:                     $parent_name = &escape($parent).'::'.$higher;
                   6500:                 } else {
                   6501:                     if (ref($path) eq 'ARRAY') {
                   6502:                         $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
                   6503:                     }
                   6504:                 }
                   6505:                 $parent_item = 'addcategory_pos_'.$parent_name;
1.48      raeburn  6506:                 for (my $j=0; $j<=$numchildren; $j++) {
1.49      raeburn  6507:                     if ($j < $numchildren) {
1.48      raeburn  6508:                         $name = $cats->[$depth]{$parent}[$j];
                   6509:                         $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49      raeburn  6510:                         $idxnum = $idx->{$item};
                   6511:                     } else {
                   6512:                         $name = $parent_name;
                   6513:                         $item = $parent_item;
1.48      raeburn  6514:                     }
1.49      raeburn  6515:                     $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
                   6516:                     $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48      raeburn  6517:                     for (my $i=0; $i<=$numchildren; $i++) {
                   6518:                         my $vpos = $i+1;
                   6519:                         my $selstr;
                   6520:                         if ($j == $i) {
                   6521:                             $selstr = ' selected="selected" ';
                   6522:                         }
                   6523:                         $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
                   6524:                     }
                   6525:                     $text .= '</select>&nbsp;';
                   6526:                     if ($j < $numchildren) {
                   6527:                         my $deeper = $depth+1;
                   6528:                         $text .= $name.'&nbsp;'
                   6529:                                  .'<label><input type="checkbox" name="deletecategory" value="'
                   6530:                                  .$item.'" />'.&mt('Delete').'</label></span></td><td>';
                   6531:                         if(ref($path) eq 'ARRAY') {
                   6532:                             push(@{$path},$name);
1.49      raeburn  6533:                             $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48      raeburn  6534:                             pop(@{$path});
                   6535:                         }
                   6536:                     } else {
1.59      bisitz   6537:                         $text .= &mt('Add subcategory:').'&nbsp;</span><input type="textbox" size="20" name="addcategory_name_';
1.48      raeburn  6538:                         if ($j == $numchildren) {
                   6539:                             $text .= $name;
                   6540:                         } else {
                   6541:                             $text .= $item;
                   6542:                         }
                   6543:                         $text .= '" value="" />';
                   6544:                     }
                   6545:                     $text .= '</td></tr>';
                   6546:                 }
                   6547:                 $text .= '</table></td>';
                   6548:             } else {
                   6549:                 my $higher = $depth-1;
                   6550:                 if ($higher == 0) {
                   6551:                     $name = &escape($parent).'::'.$higher;
                   6552:                 } else {
                   6553:                     if (ref($path) eq 'ARRAY') {
                   6554:                         $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
                   6555:                     }
                   6556:                 }
                   6557:                 my $colspan;
                   6558:                 if ($parent ne 'instcode') {
                   6559:                     $colspan = $maxdepth - $depth - 1;
                   6560:                     $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
                   6561:                 }
                   6562:             }
                   6563:         }
                   6564:     }
                   6565:     return $text;
                   6566: }
                   6567: 
1.33      raeburn  6568: sub modifiable_userdata_row {
1.228     raeburn  6569:     my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref) = @_;
                   6570:     my ($role,$rolename,$statustype);
                   6571:     $role = $item;
1.224     raeburn  6572:     if ($context eq 'cancreate') {
1.228     raeburn  6573:         if ($item =~ /^emailusername_(.+)$/) {
                   6574:             $statustype = $1;
                   6575:             $role = 'emailusername';
                   6576:             if (ref($usertypes) eq 'HASH') {
                   6577:                 if ($usertypes->{$statustype}) {
                   6578:                     $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
                   6579:                 } else {
                   6580:                     $rolename = &mt('Data provided by user');
                   6581:                 }
                   6582:             }
1.224     raeburn  6583:         }
                   6584:     } elsif ($context eq 'selfcreate') {
1.63      raeburn  6585:         if (ref($usertypes) eq 'HASH') {
                   6586:             $rolename = $usertypes->{$role};
                   6587:         } else {
                   6588:             $rolename = $role;
                   6589:         }
1.33      raeburn  6590:     } else {
1.63      raeburn  6591:         if ($role eq 'cr') {
                   6592:             $rolename = &mt('Custom role');
                   6593:         } else {
                   6594:             $rolename = &Apache::lonnet::plaintext($role);
                   6595:         }
1.33      raeburn  6596:     }
1.224     raeburn  6597:     my (@fields,%fieldtitles);
                   6598:     if (ref($fieldsref) eq 'ARRAY') {
                   6599:         @fields = @{$fieldsref};
                   6600:     } else {
                   6601:         @fields = ('lastname','firstname','middlename','generation',
                   6602:                    'permanentemail','id');
                   6603:     }
                   6604:     if ((ref($titlesref) eq 'HASH')) {
                   6605:         %fieldtitles = %{$titlesref};
                   6606:     } else {
                   6607:         %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
                   6608:     }
1.33      raeburn  6609:     my $output;
                   6610:     my $css_class = $rowcount%2?' class="LC_odd_row"':'';
                   6611:     $output = '<tr '.$css_class.'>'.
                   6612:               '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
                   6613:               '<td class="LC_left_item" colspan="2"><table>';
                   6614:     my $rem;
                   6615:     my %checks;
                   6616:     if (ref($settings) eq 'HASH') {
                   6617:         if (ref($settings->{$context}) eq 'HASH') {
                   6618:             if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.228     raeburn  6619:                 my $hashref = $settings->{$context}->{$role};
                   6620:                 if ($role eq 'emailusername') {
                   6621:                     if ($statustype) {
                   6622:                         if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
                   6623:                             $hashref = $settings->{$context}->{$role}->{$statustype};
                   6624:                             if (ref($hashref) eq 'HASH') { 
                   6625:                                 foreach my $field (@fields) {
                   6626:                                     if ($hashref->{$field}) {
                   6627:                                         $checks{$field} = $hashref->{$field};
                   6628:                                     }
                   6629:                                 }
                   6630:                             }
                   6631:                         }
                   6632:                     }
                   6633:                 } else {
                   6634:                     if (ref($hashref) eq 'HASH') {
                   6635:                         foreach my $field (@fields) {
                   6636:                             if ($hashref->{$field}) {
                   6637:                                 $checks{$field} = ' checked="checked" ';
                   6638:                             }
                   6639:                         }
1.33      raeburn  6640:                     }
                   6641:                 }
                   6642:             }
                   6643:         }
                   6644:     }
1.228     raeburn  6645:      
1.33      raeburn  6646:     for (my $i=0; $i<@fields; $i++) {
                   6647:         my $rem = $i%($numinrow);
                   6648:         if ($rem == 0) {
                   6649:             if ($i > 0) {
                   6650:                 $output .= '</tr>';
                   6651:             }
                   6652:             $output .= '<tr>';
                   6653:         }
                   6654:         my $check = ' ';
1.228     raeburn  6655:         unless ($role eq 'emailusername') {
                   6656:             if (exists($checks{$fields[$i]})) {
                   6657:                 $check = $checks{$fields[$i]}
                   6658:             } else {
                   6659:                 if ($role eq 'st') {
                   6660:                     if (ref($settings) ne 'HASH') {
                   6661:                         $check = ' checked="checked" '; 
                   6662:                     }
1.33      raeburn  6663:                 }
                   6664:             }
                   6665:         }
                   6666:         $output .= '<td class="LC_left_item">'.
1.228     raeburn  6667:                    '<span class="LC_nobreak">';
                   6668:         if ($role eq 'emailusername') {
                   6669:             unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
                   6670:                 $checks{$fields[$i]} = 'omit';
                   6671:             }
                   6672:             foreach my $option ('required','optional','omit') {
                   6673:                 my $checked='';
                   6674:                 if ($checks{$fields[$i]} eq $option) {
                   6675:                     $checked='checked="checked" ';
                   6676:                 }
                   6677:                 $output .= '<label>'.
                   6678:                            '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
                   6679:                            &mt($option).'</label>'.('&nbsp;' x2);
                   6680:             }
                   6681:             $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
                   6682:         } else {
                   6683:             $output .= '<label>'.
                   6684:                        '<input type="checkbox" name="canmodify_'.$role.'" '.
                   6685:                        'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
                   6686:                        '</label>';
                   6687:         }
                   6688:         $output .= '</span></td>';
1.33      raeburn  6689:         $rem = @fields%($numinrow);
                   6690:     }
                   6691:     my $colsleft = $numinrow - $rem;
                   6692:     if ($colsleft > 1 ) {
                   6693:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   6694:                    '&nbsp;</td>';
                   6695:     } elsif ($colsleft == 1) {
                   6696:         $output .= '<td class="LC_left_item">&nbsp;</td>';
                   6697:     }
                   6698:     $output .= '</tr></table></td></tr>';
                   6699:     return $output;
                   6700: }
1.28      raeburn  6701: 
1.93      raeburn  6702: sub insttypes_row {
1.224     raeburn  6703:     my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rownum) = @_;
1.93      raeburn  6704:     my %lt = &Apache::lonlocal::texthash (
                   6705:                       cansearch => 'Users allowed to search',
                   6706:                       statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131     raeburn  6707:                       lockablenames => 'User preference to lock name',
1.93      raeburn  6708:              );
                   6709:     my $showdom;
                   6710:     if ($context eq 'cansearch') {
                   6711:         $showdom = ' ('.$dom.')';
                   6712:     }
1.165     raeburn  6713:     my $class = 'LC_left_item';
                   6714:     if ($context eq 'statustocreate') {
                   6715:         $class = 'LC_right_item';
                   6716:     }
1.224     raeburn  6717:     my $css_class = ' class="LC_odd_row"';
                   6718:     if ($rownum ne '') { 
                   6719:         $css_class = ($rownum%2? ' class="LC_odd_row"':'');
                   6720:     }
                   6721:     my $output = '<tr'.$css_class.'>'.
                   6722:                  '<td>'.$lt{$context}.$showdom.
                   6723:                  '</td><td class="'.$class.'" colspan="2"><table>';
1.26      raeburn  6724:     my $rem;
                   6725:     if (ref($types) eq 'ARRAY') {
                   6726:         for (my $i=0; $i<@{$types}; $i++) {
                   6727:             if (defined($usertypes->{$types->[$i]})) {
                   6728:                 my $rem = $i%($numinrow);
                   6729:                 if ($rem == 0) {
                   6730:                     if ($i > 0) {
                   6731:                         $output .= '</tr>';
                   6732:                     }
                   6733:                     $output .= '<tr>';
1.23      raeburn  6734:                 }
1.26      raeburn  6735:                 my $check = ' ';
1.99      raeburn  6736:                 if (ref($settings) eq 'HASH') {
                   6737:                     if (ref($settings->{$context}) eq 'ARRAY') {
                   6738:                         if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
                   6739:                             $check = ' checked="checked" ';
                   6740:                         }
                   6741:                     } elsif ($context eq 'statustocreate') {
1.26      raeburn  6742:                         $check = ' checked="checked" ';
                   6743:                     }
1.23      raeburn  6744:                 }
1.26      raeburn  6745:                 $output .= '<td class="LC_left_item">'.
                   6746:                            '<span class="LC_nobreak"><label>'.
1.93      raeburn  6747:                            '<input type="checkbox" name="'.$context.'" '.
1.26      raeburn  6748:                            'value="'.$types->[$i].'"'.$check.'/>'.
                   6749:                            $usertypes->{$types->[$i]}.'</label></span></td>';
1.23      raeburn  6750:             }
                   6751:         }
1.26      raeburn  6752:         $rem = @{$types}%($numinrow);
1.23      raeburn  6753:     }
                   6754:     my $colsleft = $numinrow - $rem;
1.131     raeburn  6755:     if (($rem == 0) && (@{$types} > 0)) {
                   6756:         $output .= '<tr>';
                   6757:     }
1.23      raeburn  6758:     if ($colsleft > 1) {
1.25      raeburn  6759:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23      raeburn  6760:     } else {
1.25      raeburn  6761:         $output .= '<td class="LC_left_item">';
1.23      raeburn  6762:     }
                   6763:     my $defcheck = ' ';
1.99      raeburn  6764:     if (ref($settings) eq 'HASH') {  
                   6765:         if (ref($settings->{$context}) eq 'ARRAY') {
                   6766:             if (grep(/^default$/,@{$settings->{$context}})) {
                   6767:                 $defcheck = ' checked="checked" ';
                   6768:             }
                   6769:         } elsif ($context eq 'statustocreate') {
1.26      raeburn  6770:             $defcheck = ' checked="checked" ';
                   6771:         }
1.23      raeburn  6772:     }
1.25      raeburn  6773:     $output .= '<span class="LC_nobreak"><label>'.
1.93      raeburn  6774:                '<input type="checkbox" name="'.$context.'" '.
1.25      raeburn  6775:                'value="default"'.$defcheck.'/>'.
                   6776:                $othertitle.'</label></span></td>'.
                   6777:                '</tr></table></td></tr>';
                   6778:     return $output;
1.23      raeburn  6779: }
                   6780: 
                   6781: sub sorted_searchtitles {
                   6782:     my %searchtitles = &Apache::lonlocal::texthash(
                   6783:                          'uname' => 'username',
                   6784:                          'lastname' => 'last name',
                   6785:                          'lastfirst' => 'last name, first name',
                   6786:                      );
                   6787:     my @titleorder = ('uname','lastname','lastfirst');
                   6788:     return (\%searchtitles,\@titleorder);
                   6789: }
                   6790: 
1.25      raeburn  6791: sub sorted_searchtypes {
                   6792:     my %srchtypes_desc = (
                   6793:                            exact    => 'is exact match',
                   6794:                            contains => 'contains ..',
                   6795:                            begins   => 'begins with ..',
                   6796:                          );
                   6797:     my @srchtypeorder = ('exact','begins','contains');
                   6798:     return (\%srchtypes_desc,\@srchtypeorder);
                   6799: }
                   6800: 
1.3       raeburn  6801: sub usertype_update_row {
                   6802:     my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
                   6803:     my $datatable;
                   6804:     my $numinrow = 4;
                   6805:     foreach my $type (@{$types}) {
                   6806:         if (defined($usertypes->{$type})) {
                   6807:             $$rownums ++;
                   6808:             my $css_class = $$rownums%2?' class="LC_odd_row"':'';
                   6809:             $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
                   6810:                           '</td><td class="LC_left_item"><table>';
                   6811:             for (my $i=0; $i<@{$fields}; $i++) {
                   6812:                 my $rem = $i%($numinrow);
                   6813:                 if ($rem == 0) {
                   6814:                     if ($i > 0) {
                   6815:                         $datatable .= '</tr>';
                   6816:                     }
                   6817:                     $datatable .= '<tr>';
                   6818:                 }
                   6819:                 my $check = ' ';
1.39      raeburn  6820:                 if (ref($settings) eq 'HASH') {
                   6821:                     if (ref($settings->{'fields'}) eq 'HASH') {
                   6822:                         if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
                   6823:                             if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
                   6824:                                 $check = ' checked="checked" ';
                   6825:                             }
1.3       raeburn  6826:                         }
                   6827:                     }
                   6828:                 }
                   6829: 
                   6830:                 if ($i == @{$fields}-1) {
                   6831:                     my $colsleft = $numinrow - $rem;
                   6832:                     if ($colsleft > 1) {
                   6833:                         $datatable .= '<td colspan="'.$colsleft.'">';
                   6834:                     } else {
                   6835:                         $datatable .= '<td>';
                   6836:                     }
                   6837:                 } else {
                   6838:                     $datatable .= '<td>';
                   6839:                 }
1.8       raeburn  6840:                 $datatable .= '<span class="LC_nobreak"><label>'.
                   6841:                               '<input type="checkbox" name="updateable_'.$type.
                   6842:                               '_'.$fields->[$i].'" value="1"'.$check.'/>'.
                   6843:                               $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3       raeburn  6844:             }
                   6845:             $datatable .= '</tr></table></td></tr>';
                   6846:         }
                   6847:     }
                   6848:     return $datatable;
1.1       raeburn  6849: }
                   6850: 
                   6851: sub modify_login {
1.205     raeburn  6852:     my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168     raeburn  6853:     my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
                   6854:         %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
                   6855:     %title = ( coursecatalog => 'Display course catalog',
                   6856:                adminmail => 'Display administrator E-mail address',
1.188     raeburn  6857:                helpdesk  => 'Display "Contact Helpdesk" link',
1.168     raeburn  6858:                newuser => 'Link for visitors to create a user account',
                   6859:                loginheader => 'Log-in box header');
                   6860:     @offon = ('off','on');
1.112     raeburn  6861:     if (ref($domconfig{login}) eq 'HASH') {
                   6862:         if (ref($domconfig{login}{loginvia}) eq 'HASH') {
                   6863:             foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
                   6864:                 $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
                   6865:             }
                   6866:         }
                   6867:     }
1.9       raeburn  6868:     ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
                   6869:                                            \%domconfig,\%loginhash);
1.188     raeburn  6870:     my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42      raeburn  6871:     foreach my $item (@toggles) {
                   6872:         $loginhash{login}{$item} = $env{'form.'.$item};
                   6873:     }
1.41      raeburn  6874:     $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6       raeburn  6875:     if (ref($colchanges{'login'}) eq 'HASH') {  
                   6876:         $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
                   6877:                                          \%loginhash);
                   6878:     }
1.110     raeburn  6879: 
1.149     raeburn  6880:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.256     raeburn  6881:     my %domservers = &Apache::lonnet::get_servers($dom);
1.128     raeburn  6882:     my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110     raeburn  6883:     if (keys(%servers) > 1) {
                   6884:         foreach my $lonhost (keys(%servers)) {
1.128     raeburn  6885:             next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
                   6886:             if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
                   6887:                 if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
                   6888:                     $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
                   6889:                 } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
                   6890:                     if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
                   6891:                         $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
                   6892:                         $changes{'loginvia'}{$lonhost} = 1;
                   6893:                     } else {
                   6894:                         $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
                   6895:                         $changes{'loginvia'}{$lonhost} = 1;
                   6896:                     }
                   6897:                 } else {
                   6898:                     if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
                   6899:                         $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
                   6900:                         $changes{'loginvia'}{$lonhost} = 1;
                   6901:                     }
                   6902:                 }
                   6903:                 if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
                   6904:                     foreach my $item (@loginvia_attribs) {
                   6905:                         $loginhash{login}{loginvia}{$lonhost}{$item} = '';
                   6906:                     }
                   6907:                 } else {
                   6908:                     foreach my $item (@loginvia_attribs) {
                   6909:                         my $new = $env{'form.'.$lonhost.'_'.$item};
                   6910:                         if (($item eq 'serverpath') && ($new eq 'custom')) {
                   6911:                             $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
                   6912:                             if ($env{'form.'.$lonhost.'_custompath'} eq '') {
                   6913:                                 $new = '/';
                   6914:                             }
                   6915:                         }
                   6916:                         if (($item eq 'custompath') && 
                   6917:                             ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
                   6918:                             $new = '';
                   6919:                         }
                   6920:                         if ($new ne $curr_loginvia{$lonhost}{$item}) {
                   6921:                             $changes{'loginvia'}{$lonhost} = 1;
                   6922:                         }
                   6923:                         if ($item eq 'exempt') {
1.256     raeburn  6924:                             $new = &check_exempt_addresses($new);
1.128     raeburn  6925:                         }
                   6926:                         $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
                   6927:                     }
                   6928:                 }
1.112     raeburn  6929:             } else {
1.128     raeburn  6930:                 if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
                   6931:                     $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112     raeburn  6932:                     $changes{'loginvia'}{$lonhost} = 1;
1.128     raeburn  6933:                     foreach my $item (@loginvia_attribs) {
                   6934:                         my $new = $env{'form.'.$lonhost.'_'.$item};
                   6935:                         if (($item eq 'serverpath') && ($new eq 'custom')) {
                   6936:                             if ($env{'form.'.$lonhost.'_custompath'} eq '') {
                   6937:                                 $new = '/';
                   6938:                             }
                   6939:                         }
                   6940:                         if (($item eq 'custompath') && 
                   6941:                             ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
                   6942:                             $new = '';
                   6943:                         }
                   6944:                         $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
                   6945:                     }
1.110     raeburn  6946:                 }
                   6947:             }
                   6948:         }
                   6949:     }
1.119     raeburn  6950: 
1.168     raeburn  6951:     my $servadm = $r->dir_config('lonAdmEMail');
                   6952:     my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
                   6953:     if (ref($domconfig{'login'}) eq 'HASH') {
                   6954:         if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
                   6955:             foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
                   6956:                 if ($lang eq 'nolang') {
                   6957:                     push(@currlangs,$lang);
                   6958:                 } elsif (defined($langchoices{$lang})) {
                   6959:                     push(@currlangs,$lang);
                   6960:                 } else {
                   6961:                     next;
                   6962:                 }
                   6963:             }
                   6964:         }
                   6965:     }
                   6966:     my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
                   6967:     if (@currlangs > 0) {
                   6968:         foreach my $lang (@currlangs) {
                   6969:             if (grep(/^\Q$lang\E$/,@delurls)) {
                   6970:                 $changes{'helpurl'}{$lang} = 1;
                   6971:             } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
                   6972:                 $changes{'helpurl'}{$lang} = 1;
                   6973:                 $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
                   6974:                 push(@newlangs,$lang);
                   6975:             } else {
                   6976:                 $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
                   6977:             }
                   6978:         }
                   6979:     }
                   6980:     unless (grep(/^nolang$/,@currlangs)) {
                   6981:         if ($env{'form.loginhelpurl_nolang.filename'}) {
                   6982:             $changes{'helpurl'}{'nolang'} = 1;
                   6983:             $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
                   6984:             push(@newlangs,'nolang');
                   6985:         }
                   6986:     }
                   6987:     if ($env{'form.loginhelpurl_add_lang'}) {
                   6988:         if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
                   6989:             ($env{'form.loginhelpurl_add_file.filename'})) {
                   6990:             $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
                   6991:             $addedfile = $env{'form.loginhelpurl_add_lang'};
                   6992:         }
                   6993:     }
                   6994:     if ((@newlangs > 0) || ($addedfile)) {
                   6995:         my $error;
                   6996:         my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
                   6997:         if ($configuserok eq 'ok') {
                   6998:             if ($switchserver) {
                   6999:                 $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
                   7000:             } elsif ($author_ok eq 'ok') {
                   7001:                 my @allnew = @newlangs;
                   7002:                 if ($addedfile ne '') {
                   7003:                     push(@allnew,$addedfile);
                   7004:                 }
                   7005:                 foreach my $lang (@allnew) {
                   7006:                     my $formelem = 'loginhelpurl_'.$lang;
                   7007:                     if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
                   7008:                         $formelem = 'loginhelpurl_add_file';
                   7009:                     }
                   7010:                     (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
                   7011:                                                                "help/$lang",'','',$newfile{$lang});
                   7012:                     if ($result eq 'ok') {
                   7013:                         $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
                   7014:                         $changes{'helpurl'}{$lang} = 1;
                   7015:                     } else {
                   7016:                         my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
                   7017:                         $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210     raeburn  7018:                         if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168     raeburn  7019:                             (!grep(/^\Q$lang\E$/,@delurls))) {
                   7020:                             $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
                   7021:                         }
                   7022:                     }
                   7023:                 }
                   7024:             } else {
                   7025:                 $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);
                   7026:             }
                   7027:         } else {
                   7028:             $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);
                   7029:         }
                   7030:         if ($error) {
                   7031:             &Apache::lonnet::logthis($error);
                   7032:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   7033:         }
                   7034:     }
1.256     raeburn  7035: 
                   7036:     my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
                   7037:     if (ref($domconfig{'login'}) eq 'HASH') {
                   7038:         if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
                   7039:             foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
                   7040:                 if ($domservers{$lonhost}) {
                   7041:                     if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
                   7042:                         $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.268     raeburn  7043:                         $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.256     raeburn  7044:                     }
                   7045:                 }
                   7046:             }
                   7047:         }
                   7048:     }
                   7049:     my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
                   7050:     foreach my $lonhost (sort(keys(%domservers))) {
                   7051:         if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
                   7052:             $changes{'headtag'}{$lonhost} = 1;
                   7053:         } else {
                   7054:             if ($env{'form.loginheadtagexempt_'.$lonhost}) {
                   7055:                 $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
                   7056:             }
                   7057:             if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
                   7058:                 push(@newhosts,$lonhost);
                   7059:             } elsif ($currheadtagurls{$lonhost}) {
                   7060:                 $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
                   7061:                 if ($currexempt{$lonhost}) {
                   7062:                     if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) { 
                   7063:                         $changes{'headtag'}{$lonhost} = 1;
                   7064:                     }
                   7065:                 } elsif ($possexempt{$lonhost}) {
                   7066:                     $changes{'headtag'}{$lonhost} = 1;
                   7067:                 }
                   7068:                 if ($possexempt{$lonhost}) {
                   7069:                     $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
                   7070:                 }
                   7071:             }
                   7072:         }
                   7073:     }
                   7074:     if (@newhosts) {
                   7075:         my $error;
                   7076:         my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
                   7077:         if ($configuserok eq 'ok') {
                   7078:             if ($switchserver) {
                   7079:                 $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
                   7080:             } elsif ($author_ok eq 'ok') {
                   7081:                 foreach my $lonhost (@newhosts) {
                   7082:                     my $formelem = 'loginheadtag_'.$lonhost;
                   7083:                     (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
                   7084:                                                                           "login/headtag/$lonhost",'','',
                   7085:                                                                           $env{'form.loginheadtag_'.$lonhost.'.filename'});
                   7086:                     if ($result eq 'ok') {
                   7087:                         $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
                   7088:                         $changes{'headtag'}{$lonhost} = 1;
                   7089:                         if ($possexempt{$lonhost}) {
                   7090:                             $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
                   7091:                         }
                   7092:                     } else {
                   7093:                         my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
                   7094:                                            $newheadtagurls{$lonhost},$result);
                   7095:                         $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
                   7096:                         if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
                   7097:                             (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
                   7098:                             $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
                   7099:                         }
                   7100:                     }
                   7101:                 }
                   7102:             } else {
                   7103:                 $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);
                   7104:             }
                   7105:         } else {
                   7106:             $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);
                   7107:         }
                   7108:         if ($error) {
                   7109:             &Apache::lonnet::logthis($error);
                   7110:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   7111:         }
                   7112:     }
1.169     raeburn  7113:     &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168     raeburn  7114: 
                   7115:     my $defaulthelpfile = '/adm/loginproblems.html';
                   7116:     my $defaulttext = &mt('Default in use');
                   7117: 
1.1       raeburn  7118:     my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
                   7119:                                              $dom);
                   7120:     if ($putresult eq 'ok') {
1.188     raeburn  7121:         my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42      raeburn  7122:         my %defaultchecked = (
                   7123:                     'coursecatalog' => 'on',
1.188     raeburn  7124:                     'helpdesk'      => 'on',
1.42      raeburn  7125:                     'adminmail'     => 'off',
1.43      raeburn  7126:                     'newuser'       => 'off',
1.42      raeburn  7127:         );
1.55      raeburn  7128:         if (ref($domconfig{'login'}) eq 'HASH') {
                   7129:             foreach my $item (@toggles) {
                   7130:                 if ($defaultchecked{$item} eq 'on') { 
                   7131:                     if (($domconfig{'login'}{$item} eq '0') &&
                   7132:                         ($env{'form.'.$item} eq '1')) {
                   7133:                         $changes{$item} = 1;
                   7134:                     } elsif (($domconfig{'login'}{$item} eq '' ||
                   7135:                               $domconfig{'login'}{$item} eq '1') &&
                   7136:                              ($env{'form.'.$item} eq '0')) {
                   7137:                         $changes{$item} = 1;
                   7138:                     }
                   7139:                 } elsif ($defaultchecked{$item} eq 'off') {
                   7140:                     if (($domconfig{'login'}{$item} eq '1') &&
                   7141:                         ($env{'form.'.$item} eq '0')) {
                   7142:                         $changes{$item} = 1;
                   7143:                     } elsif (($domconfig{'login'}{$item} eq '' ||
                   7144:                               $domconfig{'login'}{$item} eq '0') &&
                   7145:                              ($env{'form.'.$item} eq '1')) {
                   7146:                         $changes{$item} = 1;
                   7147:                     }
1.42      raeburn  7148:                 }
                   7149:             }
1.41      raeburn  7150:         }
1.6       raeburn  7151:         if (keys(%changes) > 0 || $colchgtext) {
1.41      raeburn  7152:             &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212     raeburn  7153:             if (ref($lastactref) eq 'HASH') {
                   7154:                 $lastactref->{'domainconfig'} = 1;
                   7155:             }
1.1       raeburn  7156:             $resulttext = &mt('Changes made:').'<ul>';
                   7157:             foreach my $item (sort(keys(%changes))) {
1.135     bisitz   7158:                 if ($item eq 'loginvia') {
1.112     raeburn  7159:                     if (ref($changes{$item}) eq 'HASH') {
                   7160:                         $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
                   7161:                         foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128     raeburn  7162:                             if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
                   7163:                                 if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
                   7164:                                     my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
                   7165:                                     $protocol = 'http' if ($protocol ne 'https');
                   7166:                                     my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
                   7167: 
                   7168:                                     if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
                   7169:                                         $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
                   7170:                                     } else {
                   7171:                                         $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'}; 
                   7172:                                     }
                   7173:                                     $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
                   7174:                                     if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
                   7175:                                         $resulttext .= '&nbsp;'.&mt('No redirection for clients from following IPs:').'&nbsp;'.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
                   7176:                                     }
                   7177:                                     $resulttext .= '</li>';
                   7178:                                 } else {
                   7179:                                     $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
                   7180:                                 }
1.112     raeburn  7181:                             } else {
1.128     raeburn  7182:                                 $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112     raeburn  7183:                             }
                   7184:                         }
1.128     raeburn  7185:                         $resulttext .= '</ul></li>';
1.112     raeburn  7186:                     }
1.168     raeburn  7187:                 } elsif ($item eq 'helpurl') {
                   7188:                     if (ref($changes{$item}) eq 'HASH') {
                   7189:                         foreach my $lang (sort(keys(%{$changes{$item}}))) {
                   7190:                             if (grep(/^\Q$lang\E$/,@delurls)) {
                   7191:                                 my ($chg,$link);
                   7192:                                 $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
                   7193:                                 if ($lang eq 'nolang') {
                   7194:                                     $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
                   7195:                                 } else {
                   7196:                                     $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
                   7197:                                 }
                   7198:                                 $resulttext .= '<li>'.$chg.'</li>';
                   7199:                             } else {
                   7200:                                 my $chg;
                   7201:                                 if ($lang eq 'nolang') {
                   7202:                                     $chg = &mt('custom log-in help file for no preferred language');
                   7203:                                 } else {
                   7204:                                     $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
                   7205:                                 }
                   7206:                                 $resulttext .= '<li>'.&Apache::loncommon::modal_link(
                   7207:                                                       $loginhash{'login'}{'helpurl'}{$lang}.
                   7208:                                                       '?inhibitmenu=yes',$chg,600,500).
                   7209:                                                '</li>';
                   7210:                             }
                   7211:                         }
                   7212:                     }
1.256     raeburn  7213:                 } elsif ($item eq 'headtag') {
                   7214:                     if (ref($changes{$item}) eq 'HASH') {
                   7215:                         foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
                   7216:                             if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
                   7217:                                 $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
                   7218:                             } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
                   7219:                                 $resulttext .= '<li><a href="'.
                   7220:                                                "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
                   7221:                                                'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
                   7222:                                                '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
                   7223:                                 if ($possexempt{$lonhost}) {
                   7224:                                     $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
                   7225:                                 } else {
                   7226:                                     $resulttext .= &mt('included for any client IP');
                   7227:                                 }
                   7228:                                 $resulttext .= '</li>';
                   7229:                             }
                   7230:                         }
                   7231:                     }
1.169     raeburn  7232:                 } elsif ($item eq 'captcha') {
                   7233:                     if (ref($loginhash{'login'}) eq 'HASH') {
1.210     raeburn  7234:                         my $chgtxt;
1.169     raeburn  7235:                         if ($loginhash{'login'}{$item} eq 'notused') {
                   7236:                             $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
                   7237:                         } else {
                   7238:                             my %captchas = &captcha_phrases();
                   7239:                             if ($captchas{$loginhash{'login'}{$item}}) {
                   7240:                                 $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
                   7241:                             } else {
                   7242:                                 $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
                   7243:                             }
                   7244:                         }
                   7245:                         $resulttext .= '<li>'.$chgtxt.'</li>';
                   7246:                     }
                   7247:                 } elsif ($item eq 'recaptchakeys') {
                   7248:                     if (ref($loginhash{'login'}) eq 'HASH') {
                   7249:                         my ($privkey,$pubkey);
                   7250:                         if (ref($loginhash{'login'}{$item}) eq 'HASH') {
                   7251:                             $pubkey = $loginhash{'login'}{$item}{'public'};
                   7252:                             $privkey = $loginhash{'login'}{$item}{'private'};
                   7253:                         }
                   7254:                         my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
                   7255:                         if (!$pubkey) {
                   7256:                             $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
                   7257:                         } else {
                   7258:                             $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
                   7259:                         }
                   7260:                         if (!$privkey) {
                   7261:                             $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
                   7262:                         } else {
1.251     raeburn  7263:                             $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.169     raeburn  7264:                         }
                   7265:                         $chgtxt .= '</ul>';
                   7266:                         $resulttext .= '<li>'.$chgtxt.'</li>';
                   7267:                     }
1.269     raeburn  7268:                 } elsif ($item eq 'recaptchaversion') {
                   7269:                     if (ref($loginhash{'login'}) eq 'HASH') {
                   7270:                         if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
1.270     raeburn  7271:                             $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
1.269     raeburn  7272:                                            '</li>';
                   7273:                         }
                   7274:                     }
1.41      raeburn  7275:                 } else {
                   7276:                     $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
                   7277:                 }
1.1       raeburn  7278:             }
1.6       raeburn  7279:             $resulttext .= $colchgtext.'</ul>';
1.1       raeburn  7280:         } else {
                   7281:             $resulttext = &mt('No changes made to log-in page settings');
                   7282:         }
                   7283:     } else {
1.11      albertel 7284:         $resulttext = '<span class="LC_error">'.
                   7285: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  7286:     }
1.6       raeburn  7287:     if ($errors) {
1.9       raeburn  7288:         $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6       raeburn  7289:                        $errors.'</ul>';
                   7290:     }
                   7291:     return $resulttext;
                   7292: }
                   7293: 
1.256     raeburn  7294: 
                   7295: sub check_exempt_addresses {
                   7296:     my ($iplist) = @_;
                   7297:     $iplist =~ s/^\s+//;
                   7298:     $iplist =~ s/\s+$//;
                   7299:     my @poss_ips = split(/\s*[,:]\s*/,$iplist);
                   7300:     my (@okips,$new);
                   7301:     foreach my $ip (@poss_ips) {
                   7302:         if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
                   7303:             if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
                   7304:                 push(@okips,$ip);
                   7305:             }
                   7306:         }
                   7307:     }
                   7308:     if (@okips > 0) {
                   7309:         $new = join(',',@okips);
                   7310:     } else {
                   7311:         $new = '';
                   7312:     }
                   7313:     return $new;
                   7314: }
                   7315: 
1.6       raeburn  7316: sub color_font_choices {
                   7317:     my %choices =
                   7318:         &Apache::lonlocal::texthash (
                   7319:             img => "Header",
                   7320:             bgs => "Background colors",
                   7321:             links => "Link colors",
1.55      raeburn  7322:             images => "Images",
1.6       raeburn  7323:             font => "Font color",
1.201     raeburn  7324:             fontmenu => "Font menu",
1.76      raeburn  7325:             pgbg => "Page",
1.6       raeburn  7326:             tabbg => "Header",
                   7327:             sidebg => "Border",
                   7328:             link => "Link",
                   7329:             alink => "Active link",
                   7330:             vlink => "Visited link",
                   7331:         );
                   7332:     return %choices;
                   7333: }
                   7334: 
                   7335: sub modify_rolecolors {
1.205     raeburn  7336:     my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6       raeburn  7337:     my ($resulttext,%rolehash);
                   7338:     $rolehash{'rolecolors'} = {};
1.55      raeburn  7339:     if (ref($domconfig{'rolecolors'}) ne 'HASH') {
                   7340:         if ($domconfig{'rolecolors'} eq '') {
                   7341:             $domconfig{'rolecolors'} = {};
                   7342:         }
                   7343:     }
1.9       raeburn  7344:     my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6       raeburn  7345:                          $domconfig{'rolecolors'},$rolehash{'rolecolors'});
                   7346:     my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
                   7347:                                              $dom);
                   7348:     if ($putresult eq 'ok') {
                   7349:         if (keys(%changes) > 0) {
1.41      raeburn  7350:             &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212     raeburn  7351:             if (ref($lastactref) eq 'HASH') {
                   7352:                 $lastactref->{'domainconfig'} = 1;
                   7353:             }
1.6       raeburn  7354:             $resulttext = &display_colorchgs($dom,\%changes,$roles,
                   7355:                                              $rolehash{'rolecolors'});
                   7356:         } else {
                   7357:             $resulttext = &mt('No changes made to default color schemes');
                   7358:         }
                   7359:     } else {
1.11      albertel 7360:         $resulttext = '<span class="LC_error">'.
                   7361: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.6       raeburn  7362:     }
                   7363:     if ($errors) {
                   7364:         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
                   7365:                        $errors.'</ul>';
                   7366:     }
                   7367:     return $resulttext;
                   7368: }
                   7369: 
                   7370: sub modify_colors {
1.9       raeburn  7371:     my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12      raeburn  7372:     my (%changes,%choices);
1.51      raeburn  7373:     my @bgs;
1.6       raeburn  7374:     my @links = ('link','alink','vlink');
1.41      raeburn  7375:     my @logintext;
1.6       raeburn  7376:     my @images;
                   7377:     my $servadm = $r->dir_config('lonAdmEMail');
                   7378:     my $errors;
1.200     raeburn  7379:     my %defaults;
1.6       raeburn  7380:     foreach my $role (@{$roles}) {
                   7381:         if ($role eq 'login') {
1.12      raeburn  7382:             %choices = &login_choices();
1.41      raeburn  7383:             @logintext = ('textcol','bgcol');
1.12      raeburn  7384:         } else {
                   7385:             %choices = &color_font_choices();
                   7386:         }
                   7387:         if ($role eq 'login') {
1.41      raeburn  7388:             @images = ('img','logo','domlogo','login');
1.51      raeburn  7389:             @bgs = ('pgbg','mainbg','sidebg');
1.6       raeburn  7390:         } else {
                   7391:             @images = ('img');
1.200     raeburn  7392:             @bgs = ('pgbg','tabbg','sidebg');
                   7393:         }
                   7394:         my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
                   7395:         unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
                   7396:             $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
                   7397:         }
                   7398:         if ($role eq 'login') {
                   7399:             foreach my $item (@logintext) {
1.234     raeburn  7400:                 $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
                   7401:                 if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
                   7402:                     $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
                   7403:                 }
                   7404:                 unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.200     raeburn  7405:                     $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
                   7406:                 }
                   7407:             }
                   7408:         } else {
1.234     raeburn  7409:             $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
                   7410:             if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
                   7411:                 $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
                   7412:             }
                   7413:             unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.200     raeburn  7414:                 $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
                   7415:             }
1.6       raeburn  7416:         }
1.200     raeburn  7417:         foreach my $item (@bgs) {
1.234     raeburn  7418:             $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
                   7419:             if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
                   7420:                 $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
                   7421:             }
                   7422:             unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.200     raeburn  7423:                 $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
                   7424:             }
                   7425:         }
                   7426:         foreach my $item (@links) {
1.234     raeburn  7427:             $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
                   7428:             if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
                   7429:                 $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
                   7430:             }
                   7431:             unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.200     raeburn  7432:                 $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
                   7433:             }
1.6       raeburn  7434:         }
1.46      raeburn  7435:         my ($configuserok,$author_ok,$switchserver) = 
                   7436:             &config_check($dom,$confname,$servadm);
1.9       raeburn  7437:         my ($width,$height) = &thumb_dimensions();
1.40      raeburn  7438:         if (ref($domconfig->{$role}) ne 'HASH') {
                   7439:             $domconfig->{$role} = {};
                   7440:         }
1.8       raeburn  7441:         foreach my $img (@images) {
1.70      raeburn  7442:             if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {  
                   7443:                 if (defined($env{'form.login_showlogo_'.$img})) {
                   7444:                     $confhash->{$role}{'showlogo'}{$img} = 1;
                   7445:                 } else { 
                   7446:                     $confhash->{$role}{'showlogo'}{$img} = 0;
                   7447:                 }
                   7448:             } 
1.18      albertel 7449: 	    if ( ! $env{'form.'.$role.'_'.$img.'.filename'} 
                   7450: 		 && !defined($domconfig->{$role}{$img})
                   7451: 		 && !$env{'form.'.$role.'_del_'.$img}
                   7452: 		 && $env{'form.'.$role.'_import_'.$img}) {
                   7453: 		# import the old configured image from the .tab setting
                   7454: 		# if they haven't provided a new one 
                   7455: 		$domconfig->{$role}{$img} = 
                   7456: 		    $env{'form.'.$role.'_import_'.$img};
                   7457: 	    }
1.6       raeburn  7458:             if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9       raeburn  7459:                 my $error;
1.6       raeburn  7460:                 if ($configuserok eq 'ok') {
1.9       raeburn  7461:                     if ($switchserver) {
1.12      raeburn  7462:                         $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9       raeburn  7463:                     } else {
                   7464:                         if ($author_ok eq 'ok') {
                   7465:                             my ($result,$logourl) = 
                   7466:                                 &publishlogo($r,'upload',$role.'_'.$img,
                   7467:                                            $dom,$confname,$img,$width,$height);
                   7468:                             if ($result eq 'ok') {
                   7469:                                 $confhash->{$role}{$img} = $logourl;
1.12      raeburn  7470:                                 $changes{$role}{'images'}{$img} = 1;
1.9       raeburn  7471:                             } else {
1.12      raeburn  7472:                                 $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  7473:                             }
                   7474:                         } else {
1.46      raeburn  7475:                             $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  7476:                         }
                   7477:                     }
                   7478:                 } else {
1.46      raeburn  7479:                     $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  7480:                 }
                   7481:                 if ($error) {
1.8       raeburn  7482:                     &Apache::lonnet::logthis($error);
1.11      albertel 7483:                     $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8       raeburn  7484:                 }
                   7485:             } elsif ($domconfig->{$role}{$img} ne '') {
1.9       raeburn  7486:                 if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
                   7487:                     my $error;
                   7488:                     if ($configuserok eq 'ok') {
                   7489: # is confname an author?
                   7490:                         if ($switchserver eq '') {
                   7491:                             if ($author_ok eq 'ok') {
                   7492:                                 my ($result,$logourl) = 
                   7493:                                &publishlogo($r,'copy',$domconfig->{$role}{$img},
                   7494:                                             $dom,$confname,$img,$width,$height);
                   7495:                                 if ($result eq 'ok') {
                   7496:                                     $confhash->{$role}{$img} = $logourl;
1.18      albertel 7497: 				    $changes{$role}{'images'}{$img} = 1;
1.9       raeburn  7498:                                 }
                   7499:                             }
                   7500:                         }
                   7501:                     }
1.6       raeburn  7502:                 }
                   7503:             }
                   7504:         }
                   7505:         if (ref($domconfig) eq 'HASH') {
                   7506:             if (ref($domconfig->{$role}) eq 'HASH') {
                   7507:                 foreach my $img (@images) {
                   7508:                     if ($domconfig->{$role}{$img} ne '') {
                   7509:                         if ($env{'form.'.$role.'_del_'.$img}) {
                   7510:                             $confhash->{$role}{$img} = '';
1.12      raeburn  7511:                             $changes{$role}{'images'}{$img} = 1;
1.6       raeburn  7512:                         } else {
1.9       raeburn  7513:                             if ($confhash->{$role}{$img} eq '') {
                   7514:                                 $confhash->{$role}{$img} = $domconfig->{$role}{$img};
                   7515:                             }
1.6       raeburn  7516:                         }
                   7517:                     } else {
                   7518:                         if ($env{'form.'.$role.'_del_'.$img}) {
                   7519:                             $confhash->{$role}{$img} = '';
1.12      raeburn  7520:                             $changes{$role}{'images'}{$img} = 1;
1.6       raeburn  7521:                         } 
                   7522:                     }
1.70      raeburn  7523:                     if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
                   7524:                         if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
                   7525:                             if ($confhash->{$role}{'showlogo'}{$img} ne 
                   7526:                                 $domconfig->{$role}{'showlogo'}{$img}) {
                   7527:                                 $changes{$role}{'showlogo'}{$img} = 1; 
                   7528:                             }
                   7529:                         } else {
                   7530:                             if ($confhash->{$role}{'showlogo'}{$img} == 0) {
                   7531:                                 $changes{$role}{'showlogo'}{$img} = 1;
                   7532:                             }
                   7533:                         }
                   7534:                     }
                   7535:                 }
1.6       raeburn  7536:                 if ($domconfig->{$role}{'font'} ne '') {
                   7537:                     if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
                   7538:                         $changes{$role}{'font'} = 1;
                   7539:                     }
                   7540:                 } else {
                   7541:                     if ($confhash->{$role}{'font'}) {
                   7542:                         $changes{$role}{'font'} = 1;
                   7543:                     }
                   7544:                 }
1.107     raeburn  7545:                 if ($role ne 'login') {
                   7546:                     if ($domconfig->{$role}{'fontmenu'} ne '') {
                   7547:                         if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
                   7548:                             $changes{$role}{'fontmenu'} = 1;
                   7549:                         }
                   7550:                     } else {
                   7551:                         if ($confhash->{$role}{'fontmenu'}) {
                   7552:                             $changes{$role}{'fontmenu'} = 1;
                   7553:                         }
1.97      tempelho 7554:                     }
                   7555:                 }
1.6       raeburn  7556:                 foreach my $item (@bgs) {
                   7557:                     if ($domconfig->{$role}{$item} ne '') {
                   7558:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
                   7559:                             $changes{$role}{'bgs'}{$item} = 1;
                   7560:                         } 
                   7561:                     } else {
                   7562:                         if ($confhash->{$role}{$item}) {
                   7563:                             $changes{$role}{'bgs'}{$item} = 1;
                   7564:                         }
                   7565:                     }
                   7566:                 }
                   7567:                 foreach my $item (@links) {
                   7568:                     if ($domconfig->{$role}{$item} ne '') {
                   7569:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
                   7570:                             $changes{$role}{'links'}{$item} = 1;
                   7571:                         }
                   7572:                     } else {
                   7573:                         if ($confhash->{$role}{$item}) {
                   7574:                             $changes{$role}{'links'}{$item} = 1;
                   7575:                         }
                   7576:                     }
                   7577:                 }
1.41      raeburn  7578:                 foreach my $item (@logintext) {
                   7579:                     if ($domconfig->{$role}{$item} ne '') {
                   7580:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
                   7581:                             $changes{$role}{'logintext'}{$item} = 1;
                   7582:                         }
                   7583:                     } else {
                   7584:                         if ($confhash->{$role}{$item}) {
                   7585:                             $changes{$role}{'logintext'}{$item} = 1;
                   7586:                         }
                   7587:                     }
                   7588:                 }
1.6       raeburn  7589:             } else {
                   7590:                 &default_change_checker($role,\@images,\@links,\@bgs,
1.41      raeburn  7591:                                         \@logintext,$confhash,\%changes); 
1.6       raeburn  7592:             }
                   7593:         } else {
                   7594:             &default_change_checker($role,\@images,\@links,\@bgs,
1.41      raeburn  7595:                                     \@logintext,$confhash,\%changes); 
1.6       raeburn  7596:         }
                   7597:     }
                   7598:     return ($errors,%changes);
                   7599: }
                   7600: 
1.46      raeburn  7601: sub config_check {
                   7602:     my ($dom,$confname,$servadm) = @_;
                   7603:     my ($configuserok,$author_ok,$switchserver,%currroles);
                   7604:     my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
                   7605:     ($configuserok,%currroles) = &check_configuser($uhome,$dom,
                   7606:                                                    $confname,$servadm);
                   7607:     if ($configuserok eq 'ok') {
                   7608:         $switchserver = &check_switchserver($dom,$confname);
                   7609:         if ($switchserver eq '') {
                   7610:             $author_ok = &check_authorstatus($dom,$confname,%currroles);
                   7611:         }
                   7612:     }
                   7613:     return ($configuserok,$author_ok,$switchserver);
                   7614: }
                   7615: 
1.6       raeburn  7616: sub default_change_checker {
1.41      raeburn  7617:     my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6       raeburn  7618:     foreach my $item (@{$links}) {
                   7619:         if ($confhash->{$role}{$item}) {
                   7620:             $changes->{$role}{'links'}{$item} = 1;
                   7621:         }
                   7622:     }
                   7623:     foreach my $item (@{$bgs}) {
                   7624:         if ($confhash->{$role}{$item}) {
                   7625:             $changes->{$role}{'bgs'}{$item} = 1;
                   7626:         }
                   7627:     }
1.41      raeburn  7628:     foreach my $item (@{$logintext}) {
                   7629:         if ($confhash->{$role}{$item}) {
                   7630:             $changes->{$role}{'logintext'}{$item} = 1;
                   7631:         }
                   7632:     }
1.6       raeburn  7633:     foreach my $img (@{$images}) {
                   7634:         if ($env{'form.'.$role.'_del_'.$img}) {
                   7635:             $confhash->{$role}{$img} = '';
1.12      raeburn  7636:             $changes->{$role}{'images'}{$img} = 1;
1.6       raeburn  7637:         }
1.70      raeburn  7638:         if ($role eq 'login') {
                   7639:             if ($confhash->{$role}{'showlogo'}{$img} == 0) {
                   7640:                 $changes->{$role}{'showlogo'}{$img} = 1;
                   7641:             }
                   7642:         }
1.6       raeburn  7643:     }
                   7644:     if ($confhash->{$role}{'font'}) {
                   7645:         $changes->{$role}{'font'} = 1;
                   7646:     }
1.48      raeburn  7647: }
1.6       raeburn  7648: 
                   7649: sub display_colorchgs {
                   7650:     my ($dom,$changes,$roles,$confhash) = @_;
                   7651:     my (%choices,$resulttext);
                   7652:     if (!grep(/^login$/,@{$roles})) {
                   7653:         $resulttext = &mt('Changes made:').'<br />';
                   7654:     }
                   7655:     foreach my $role (@{$roles}) {
                   7656:         if ($role eq 'login') {
                   7657:             %choices = &login_choices();
                   7658:         } else {
                   7659:             %choices = &color_font_choices();
                   7660:         }
                   7661:         if (ref($changes->{$role}) eq 'HASH') {
                   7662:             if ($role ne 'login') {
                   7663:                 $resulttext .= '<h4>'.&mt($role).'</h4>';
                   7664:             }
                   7665:             foreach my $key (sort(keys(%{$changes->{$role}}))) {
                   7666:                 if ($role ne 'login') {
                   7667:                     $resulttext .= '<ul>';
                   7668:                 }
                   7669:                 if (ref($changes->{$role}{$key}) eq 'HASH') {
                   7670:                     if ($role ne 'login') {
                   7671:                         $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
                   7672:                     }
                   7673:                     foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70      raeburn  7674:                         if (($role eq 'login') && ($key eq 'showlogo')) {
                   7675:                             if ($confhash->{$role}{$key}{$item}) {
                   7676:                                 $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
                   7677:                             } else {
                   7678:                                 $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
                   7679:                             }
                   7680:                         } elsif ($confhash->{$role}{$item} eq '') {
1.6       raeburn  7681:                             $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
                   7682:                         } else {
1.12      raeburn  7683:                             my $newitem = $confhash->{$role}{$item};
                   7684:                             if ($key eq 'images') {
                   7685:                                 $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
                   7686:                             }
                   7687:                             $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6       raeburn  7688:                         }
                   7689:                     }
                   7690:                     if ($role ne 'login') {
                   7691:                         $resulttext .= '</ul></li>';
                   7692:                     }
                   7693:                 } else {
                   7694:                     if ($confhash->{$role}{$key} eq '') {
                   7695:                         $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
                   7696:                     } else {
                   7697:                         $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
                   7698:                     }
                   7699:                 }
                   7700:                 if ($role ne 'login') {
                   7701:                     $resulttext .= '</ul>';
                   7702:                 }
                   7703:             }
                   7704:         }
                   7705:     }
1.3       raeburn  7706:     return $resulttext;
1.1       raeburn  7707: }
                   7708: 
1.9       raeburn  7709: sub thumb_dimensions {
                   7710:     return ('200','50');
                   7711: }
                   7712: 
1.16      raeburn  7713: sub check_dimensions {
                   7714:     my ($inputfile) = @_;
                   7715:     my ($fullwidth,$fullheight);
                   7716:     if ($inputfile =~ m|^[/\w.\-]+$|) {
                   7717:         if (open(PIPE,"identify $inputfile 2>&1 |")) {
                   7718:             my $imageinfo = <PIPE>;
                   7719:             if (!close(PIPE)) {
                   7720:                 &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
                   7721:             }
                   7722:             chomp($imageinfo);
                   7723:             my ($fullsize) = 
1.21      raeburn  7724:                 ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16      raeburn  7725:             if ($fullsize) {
                   7726:                 ($fullwidth,$fullheight) = split(/x/,$fullsize);
                   7727:             }
                   7728:         }
                   7729:     }
                   7730:     return ($fullwidth,$fullheight);
                   7731: }
                   7732: 
1.9       raeburn  7733: sub check_configuser {
                   7734:     my ($uhome,$dom,$confname,$servadm) = @_;
                   7735:     my ($configuserok,%currroles);
                   7736:     if ($uhome eq 'no_host') {
                   7737:         srand( time() ^ ($$ + ($$ << 15))  ); # Seed rand.
                   7738:         my $configpass = &LONCAPA::Enrollment::create_password();
                   7739:         $configuserok = 
                   7740:             &Apache::lonnet::modifyuser($dom,$confname,'','internal',
                   7741:                              $configpass,'','','','','',undef,$servadm);
                   7742:     } else {
                   7743:         $configuserok = 'ok';
                   7744:         %currroles = 
                   7745:             &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
                   7746:     }
                   7747:     return ($configuserok,%currroles);
                   7748: }
                   7749: 
                   7750: sub check_authorstatus {
                   7751:     my ($dom,$confname,%currroles) = @_;
                   7752:     my $author_ok;
1.40      raeburn  7753:     if (!$currroles{':'.$dom.':au'}) {
1.9       raeburn  7754:         my $start = time;
                   7755:         my $end = 0;
                   7756:         $author_ok = 
                   7757:             &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47      raeburn  7758:                                         'au',$end,$start,'','','domconfig');
1.9       raeburn  7759:     } else {
                   7760:         $author_ok = 'ok';
                   7761:     }
                   7762:     return $author_ok;
                   7763: }
                   7764: 
                   7765: sub publishlogo {
1.46      raeburn  7766:     my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.267     raeburn  7767:     my ($output,$fname,$logourl,$madethumb);
1.9       raeburn  7768:     if ($action eq 'upload') {
                   7769:         $fname=$env{'form.'.$formname.'.filename'};
                   7770:         chop($env{'form.'.$formname});
                   7771:     } else {
                   7772:         ($fname) = ($formname =~ /([^\/]+)$/);
                   7773:     }
1.46      raeburn  7774:     if ($savefileas ne '') {
                   7775:         $fname = $savefileas;
                   7776:     }
1.9       raeburn  7777:     $fname=&Apache::lonnet::clean_filename($fname);
                   7778: # See if there is anything left
                   7779:     unless ($fname) { return ('error: no uploaded file'); }
                   7780:     $fname="$subdir/$fname";
1.210     raeburn  7781:     my $docroot=$r->dir_config('lonDocRoot');
1.164     raeburn  7782:     my $filepath="$docroot/priv";
                   7783:     my $relpath = "$dom/$confname";
1.9       raeburn  7784:     my ($fnamepath,$file,$fetchthumb);
                   7785:     $file=$fname;
                   7786:     if ($fname=~m|/|) {
                   7787:         ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
                   7788:     }
1.164     raeburn  7789:     my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9       raeburn  7790:     my $count;
1.164     raeburn  7791:     for ($count=5;$count<=$#parts;$count++) {
1.9       raeburn  7792:         $filepath.="/$parts[$count]";
                   7793:         if ((-e $filepath)!=1) {
                   7794:             mkdir($filepath,02770);
                   7795:         }
                   7796:     }
                   7797:     # Check for bad extension and disallow upload
                   7798:     if ($file=~/\.(\w+)$/ &&
                   7799:         (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
                   7800:         $output = 
1.207     bisitz   7801:             &mt('Invalid file extension ([_1]) - reserved for internal use.',$1); 
1.9       raeburn  7802:     } elsif ($file=~/\.(\w+)$/ &&
                   7803:         !defined(&Apache::loncommon::fileembstyle($1))) {
                   7804:         $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
                   7805:     } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.195     bisitz   7806:         $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  7807:     } elsif (-d "$filepath/$file") {
1.195     bisitz   7808:         $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9       raeburn  7809:     } else {
                   7810:         my $source = $filepath.'/'.$file;
                   7811:         my $logfile;
                   7812:         if (!open($logfile,">>$source".'.log')) {
1.196     raeburn  7813:             return (&mt('No write permission to Authoring Space'));
1.9       raeburn  7814:         }
                   7815:         print $logfile
                   7816: "\n================= Publish ".localtime()." ================\n".
                   7817: $env{'user.name'}.':'.$env{'user.domain'}."\n";
                   7818: # Save the file
                   7819:         if (!open(FH,'>'.$source)) {
                   7820:             &Apache::lonnet::logthis('Failed to create '.$source);
                   7821:             return (&mt('Failed to create file'));
                   7822:         }
                   7823:         if ($action eq 'upload') {
                   7824:             if (!print FH ($env{'form.'.$formname})) {
                   7825:                 &Apache::lonnet::logthis('Failed to write to '.$source);
                   7826:                 return (&mt('Failed to write file'));
                   7827:             }
                   7828:         } else {
                   7829:             my $original = &Apache::lonnet::filelocation('',$formname);
                   7830:             if(!copy($original,$source)) {
                   7831:                 &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
                   7832:                 return (&mt('Failed to write file'));
                   7833:             }
                   7834:         }
                   7835:         close(FH);
                   7836:         chmod(0660, $source); # Permissions to rw-rw---.
                   7837: 
                   7838:         my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
                   7839:         my $copyfile=$targetdir.'/'.$file;
                   7840: 
                   7841:         my @parts=split(/\//,$targetdir);
                   7842:         my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
                   7843:         for (my $count=5;$count<=$#parts;$count++) {
                   7844:             $path.="/$parts[$count]";
                   7845:             if (!-e $path) {
                   7846:                 print $logfile "\nCreating directory ".$path;
                   7847:                 mkdir($path,02770);
                   7848:             }
                   7849:         }
                   7850:         my $versionresult;
                   7851:         if (-e $copyfile) {
                   7852:             $versionresult = &logo_versioning($targetdir,$file,$logfile);
                   7853:         } else {
                   7854:             $versionresult = 'ok';
                   7855:         }
                   7856:         if ($versionresult eq 'ok') {
                   7857:             if (copy($source,$copyfile)) {
                   7858:                 print $logfile "\nCopied original source to ".$copyfile."\n";
                   7859:                 $output = 'ok';
                   7860:                 $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155     raeburn  7861:                 push(@{$modified_urls},[$copyfile,$source]);
                   7862:                 my $metaoutput = 
                   7863:                     &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
                   7864:                 unless ($registered_cleanup) {
                   7865:                     my $handlers = $r->get_handlers('PerlCleanupHandler');
                   7866:                     $r->set_handlers('PerlCleanupHandler' => [\&notifysubscribed,@{$handlers}]);
                   7867:                     $registered_cleanup=1;
                   7868:                 }
1.9       raeburn  7869:             } else {
                   7870:                 print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
                   7871:                 $output = &mt('Failed to copy file to RES space').", $!";
                   7872:             }
                   7873:             if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
                   7874:                 my $inputfile = $filepath.'/'.$file;
                   7875:                 my $outfile = $filepath.'/'.'tn-'.$file;
1.16      raeburn  7876:                 my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
                   7877:                 if ($fullwidth ne '' && $fullheight ne '') { 
                   7878:                     if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
                   7879:                         my $thumbsize = $thumbwidth.'x'.$thumbheight;
                   7880:                         system("convert -sample $thumbsize $inputfile $outfile");
                   7881:                         chmod(0660, $filepath.'/tn-'.$file);
                   7882:                         if (-e $outfile) {
                   7883:                             my $copyfile=$targetdir.'/tn-'.$file;
                   7884:                             if (copy($outfile,$copyfile)) {
                   7885:                                 print $logfile "\nCopied source to ".$copyfile."\n";
1.155     raeburn  7886:                                 my $thumb_metaoutput = 
                   7887:                                     &write_metadata($dom,$confname,$formname,
                   7888:                                                     $targetdir,'tn-'.$file,$logfile);
                   7889:                                 push(@{$modified_urls},[$copyfile,$outfile]);
                   7890:                                 unless ($registered_cleanup) {
                   7891:                                     my $handlers = $r->get_handlers('PerlCleanupHandler');
                   7892:                                     $r->set_handlers('PerlCleanupHandler' => [\&notifysubscribed,@{$handlers}]);
                   7893:                                     $registered_cleanup=1;
                   7894:                                 }
1.267     raeburn  7895:                                 $madethumb = 1;
1.16      raeburn  7896:                             } else {
                   7897:                                 print $logfile "\nUnable to write ".$copyfile.
                   7898:                                                ':'.$!."\n";
                   7899:                             }
                   7900:                         }
1.9       raeburn  7901:                     }
                   7902:                 }
                   7903:             }
                   7904:         } else {
                   7905:             $output = $versionresult;
                   7906:         }
                   7907:     }
1.267     raeburn  7908:     return ($output,$logourl,$madethumb);
1.9       raeburn  7909: }
                   7910: 
                   7911: sub logo_versioning {
                   7912:     my ($targetdir,$file,$logfile) = @_;
                   7913:     my $target = $targetdir.'/'.$file;
                   7914:     my ($maxversion,$fn,$extn,$output);
                   7915:     $maxversion = 0;
                   7916:     if ($file =~ /^(.+)\.(\w+)$/) {
                   7917:         $fn=$1;
                   7918:         $extn=$2;
                   7919:     }
                   7920:     opendir(DIR,$targetdir);
                   7921:     while (my $filename=readdir(DIR)) {
                   7922:         if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
                   7923:             $maxversion=($1>$maxversion)?$1:$maxversion;
                   7924:         }
                   7925:     }
                   7926:     $maxversion++;
                   7927:     print $logfile "\nCreating old version ".$maxversion."\n";
                   7928:     my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
                   7929:     if (copy($target,$copyfile)) {
                   7930:         print $logfile "Copied old target to ".$copyfile."\n";
                   7931:         $copyfile=$copyfile.'.meta';
                   7932:         if (copy($target.'.meta',$copyfile)) {
                   7933:             print $logfile "Copied old target metadata to ".$copyfile."\n";
                   7934:             $output = 'ok';
                   7935:         } else {
                   7936:             print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
                   7937:             $output = &mt('Failed to copy old meta').", $!, ";
                   7938:         }
                   7939:     } else {
                   7940:         print $logfile "Unable to write ".$copyfile.':'.$!."\n";
                   7941:         $output = &mt('Failed to copy old target').", $!, ";
                   7942:     }
                   7943:     return $output;
                   7944: }
                   7945: 
                   7946: sub write_metadata {
                   7947:     my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
                   7948:     my (%metadatafields,%metadatakeys,$output);
                   7949:     $metadatafields{'title'}=$formname;
                   7950:     $metadatafields{'creationdate'}=time;
                   7951:     $metadatafields{'lastrevisiondate'}=time;
                   7952:     $metadatafields{'copyright'}='public';
                   7953:     $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
                   7954:                                          $env{'user.domain'};
                   7955:     $metadatafields{'authorspace'}=$confname.':'.$dom;
                   7956:     $metadatafields{'domain'}=$dom;
                   7957:     {
                   7958:         print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
                   7959:         my $mfh;
1.155     raeburn  7960:         if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
1.184     raeburn  7961:             foreach (sort(keys(%metadatafields))) {
1.155     raeburn  7962:                 unless ($_=~/\./) {
                   7963:                     my $unikey=$_;
                   7964:                     $unikey=~/^([A-Za-z]+)/;
                   7965:                     my $tag=$1;
                   7966:                     $tag=~tr/A-Z/a-z/;
                   7967:                     print $mfh "\n\<$tag";
                   7968:                     foreach (split(/\,/,$metadatakeys{$unikey})) {
                   7969:                         my $value=$metadatafields{$unikey.'.'.$_};
                   7970:                         $value=~s/\"/\'\'/g;
                   7971:                         print $mfh ' '.$_.'="'.$value.'"';
                   7972:                     }
                   7973:                     print $mfh '>'.
                   7974:                         &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
                   7975:                             .'</'.$tag.'>';
                   7976:                 }
                   7977:             }
                   7978:             $output = 'ok';
                   7979:             print $logfile "\nWrote metadata";
                   7980:             close($mfh);
                   7981:         } else {
                   7982:             print $logfile "\nFailed to open metadata file";
1.9       raeburn  7983:             $output = &mt('Could not write metadata');
                   7984:         }
                   7985:     }
1.155     raeburn  7986:     return $output;
                   7987: }
                   7988: 
                   7989: sub notifysubscribed {
                   7990:     foreach my $targetsource (@{$modified_urls}){
                   7991:         next unless (ref($targetsource) eq 'ARRAY');
                   7992:         my ($target,$source)=@{$targetsource};
                   7993:         if ($source ne '') {
                   7994:             if (open(my $logfh,'>>'.$source.'.log')) {
                   7995:                 print $logfh "\nCleanup phase: Notifications\n";
                   7996:                 my @subscribed=&subscribed_hosts($target);
                   7997:                 foreach my $subhost (@subscribed) {
                   7998:                     print $logfh "\nNotifying host ".$subhost.':';
                   7999:                     my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
                   8000:                     print $logfh $reply;
                   8001:                 }
                   8002:                 my @subscribedmeta=&subscribed_hosts("$target.meta");
                   8003:                 foreach my $subhost (@subscribedmeta) {
                   8004:                     print $logfh "\nNotifying host for metadata only ".$subhost.':';
                   8005:                     my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
                   8006:                                                         $subhost);
                   8007:                     print $logfh $reply;
                   8008:                 }
                   8009:                 print $logfh "\n============ Done ============\n";
1.160     raeburn  8010:                 close($logfh);
1.155     raeburn  8011:             }
                   8012:         }
                   8013:     }
                   8014:     return OK;
                   8015: }
                   8016: 
                   8017: sub subscribed_hosts {
                   8018:     my ($target) = @_;
                   8019:     my @subscribed;
                   8020:     if (open(my $fh,"<$target.subscription")) {
                   8021:         while (my $subline=<$fh>) {
                   8022:             if ($subline =~ /^($match_lonid):/) {
                   8023:                 my $host = $1;
                   8024:                 if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
                   8025:                     unless (grep(/^\Q$host\E$/,@subscribed)) {
                   8026:                         push(@subscribed,$host);
                   8027:                     }
                   8028:                 }
                   8029:             }
                   8030:         }
                   8031:     }
                   8032:     return @subscribed;
1.9       raeburn  8033: }
                   8034: 
                   8035: sub check_switchserver {
                   8036:     my ($dom,$confname) = @_;
                   8037:     my ($allowed,$switchserver);
                   8038:     my $home = &Apache::lonnet::homeserver($confname,$dom);
                   8039:     if ($home eq 'no_host') {
                   8040:         $home = &Apache::lonnet::domain($dom,'primary');
                   8041:     }
                   8042:     my @ids=&Apache::lonnet::current_machine_ids();
1.10      albertel 8043:     foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
                   8044:     if (!$allowed) {
1.180     raeburn  8045: 	$switchserver='<a href="/adm/switchserver?otherserver='.$home.'&amp;role=dc./'.$dom.'/&amp;destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9       raeburn  8046:     }
                   8047:     return $switchserver;
                   8048: }
                   8049: 
1.1       raeburn  8050: sub modify_quotas {
1.216     raeburn  8051:     my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101     raeburn  8052:     my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216     raeburn  8053:         %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.235     raeburn  8054:         $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
                   8055:         $validationfieldsref);
1.86      raeburn  8056:     if ($action eq 'quotas') {
                   8057:         $context = 'tools'; 
1.163     raeburn  8058:     } else {
1.86      raeburn  8059:         $context = $action;
                   8060:     }
                   8061:     if ($context eq 'requestcourses') {
1.271     raeburn  8062:         @usertools = ('official','unofficial','community','textbook','placement');
1.106     raeburn  8063:         @options =('norequest','approval','validate','autolimit');
1.101     raeburn  8064:         %validations = &Apache::lonnet::auto_courserequest_checks($dom);
                   8065:         %titles = &courserequest_titles();
                   8066:         $toolregexp = join('|',@usertools);
                   8067:         %conditions = &courserequest_conditions();
1.216     raeburn  8068:         $confname = $dom.'-domainconfig';
                   8069:         my $servadm = $r->dir_config('lonAdmEMail');
                   8070:         ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.235     raeburn  8071:         ($validationitemsref,$validationnamesref,$validationfieldsref) = 
                   8072:             &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.163     raeburn  8073:     } elsif ($context eq 'requestauthor') {
                   8074:         @usertools = ('author');
                   8075:         %titles = &authorrequest_titles();
1.86      raeburn  8076:     } else {
1.162     raeburn  8077:         @usertools = ('aboutme','blog','webdav','portfolio');
1.101     raeburn  8078:         %titles = &tool_titles();
1.86      raeburn  8079:     }
1.212     raeburn  8080:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44      raeburn  8081:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1       raeburn  8082:     foreach my $key (keys(%env)) {
1.101     raeburn  8083:         if ($context eq 'requestcourses') {
                   8084:             if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
                   8085:                 my $item = $1;
                   8086:                 my $type = $2;
                   8087:                 if ($type =~ /^limit_(.+)/) {
                   8088:                     $limithash{$item}{$1} = $env{$key};
                   8089:                 } else {
                   8090:                     $confhash{$item}{$type} = $env{$key};
                   8091:                 }
                   8092:             }
1.163     raeburn  8093:         } elsif ($context eq 'requestauthor') {
                   8094:             if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
                   8095:                 $confhash{$1} = $env{$key};
                   8096:             }
1.101     raeburn  8097:         } else {
1.86      raeburn  8098:             if ($key =~ /^form\.quota_(.+)$/) {
                   8099:                 $confhash{'defaultquota'}{$1} = $env{$key};
1.197     raeburn  8100:             } elsif ($key =~ /^form\.authorquota_(.+)$/) {
                   8101:                 $confhash{'authorquota'}{$1} = $env{$key};
                   8102:             } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101     raeburn  8103:                 @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
                   8104:             }
1.72      raeburn  8105:         }
                   8106:     }
1.163     raeburn  8107:     if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.224     raeburn  8108:         my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102     raeburn  8109:         @approvalnotify = sort(@approvalnotify);
                   8110:         $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.271     raeburn  8111:         my @crstypes = ('official','unofficial','community','textbook','placement');
1.218     raeburn  8112:         my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
                   8113:         foreach my $type (@hasuniquecode) {
                   8114:             if (grep(/^\Q$type\E$/,@crstypes)) {
                   8115:                 $confhash{'uniquecode'}{$type} = 1;
                   8116:             }
1.216     raeburn  8117:         }
1.242     raeburn  8118:         my (%newbook,%allpos);
1.216     raeburn  8119:         if ($context eq 'requestcourses') {
1.242     raeburn  8120:             foreach my $type ('textbooks','templates') {
                   8121:                 @{$allpos{$type}} = (); 
                   8122:                 my $invalid;
                   8123:                 if ($type eq 'textbooks') {
                   8124:                     $invalid = &mt('Invalid LON-CAPA course for textbook');
                   8125:                 } else {
                   8126:                     $invalid = &mt('Invalid LON-CAPA course for template');
                   8127:                 }
                   8128:                 if ($env{'form.'.$type.'_addbook'}) {
                   8129:                     if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
                   8130:                         ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
                   8131:                         if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
                   8132:                                                         $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
                   8133:                             $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
                   8134:                         } else {
                   8135:                             $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
                   8136:                             my $position = $env{'form.'.$type.'_addbook_pos'};
                   8137:                             $position =~ s/\D+//g;
                   8138:                             if ($position ne '') {
                   8139:                                 $allpos{$type}[$position] = $newbook{$type};
                   8140:                             }
1.216     raeburn  8141:                         }
1.242     raeburn  8142:                     } else {
                   8143:                         $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.216     raeburn  8144:                     }
                   8145:                 }
1.242     raeburn  8146:             } 
1.216     raeburn  8147:         }
1.102     raeburn  8148:         if (ref($domconfig{$action}) eq 'HASH') {
                   8149:             if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
                   8150:                 if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
                   8151:                     $changes{'notify'}{'approval'} = 1;
                   8152:                 }
                   8153:             } else {
1.144     raeburn  8154:                 if ($confhash{'notify'}{'approval'}) {
1.102     raeburn  8155:                     $changes{'notify'}{'approval'} = 1;
                   8156:                 }
                   8157:             }
1.218     raeburn  8158:             if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
                   8159:                 if (ref($confhash{'uniquecode'}) eq 'HASH') {
                   8160:                     foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
                   8161:                         unless ($confhash{'uniquecode'}{$crstype}) {
                   8162:                             $changes{'uniquecode'} = 1;
                   8163:                         }
                   8164:                     }
                   8165:                     unless ($changes{'uniquecode'}) {
                   8166:                         foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
                   8167:                             unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
                   8168:                                 $changes{'uniquecode'} = 1;
                   8169:                             }
                   8170:                         }
                   8171:                     }
                   8172:                } else {
                   8173:                    $changes{'uniquecode'} = 1;
                   8174:                }
                   8175:             } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
                   8176:                 $changes{'uniquecode'} = 1;
1.216     raeburn  8177:             }
                   8178:             if ($context eq 'requestcourses') {
1.242     raeburn  8179:                 foreach my $type ('textbooks','templates') {
                   8180:                     if (ref($domconfig{$action}{$type}) eq 'HASH') {
                   8181:                         my %deletions;
                   8182:                         my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
                   8183:                         if (@todelete) {
                   8184:                             map { $deletions{$_} = 1; } @todelete;
                   8185:                         }
                   8186:                         my %imgdeletions;
                   8187:                         my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
                   8188:                         if (@todeleteimages) {
                   8189:                             map { $imgdeletions{$_} = 1; } @todeleteimages;
                   8190:                         }
                   8191:                         my $maxnum = $env{'form.'.$type.'_maxnum'};
                   8192:                         for (my $i=0; $i<=$maxnum; $i++) {
                   8193:                             my $itemid = $env{'form.'.$type.'_id_'.$i};
                   8194:                             my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/); 
                   8195:                             if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
                   8196:                                 if ($deletions{$key}) {
                   8197:                                     if ($domconfig{$action}{$type}{$key}{'image'}) {
                   8198:                                         #FIXME need to obsolete item in RES space
                   8199:                                     }
                   8200:                                     next;
                   8201:                                 } else {
                   8202:                                     my $newpos = $env{'form.'.$itemid};
                   8203:                                     $newpos =~ s/\D+//g;
1.243     raeburn  8204:                                     foreach my $item ('subject','title','publisher','author') {
                   8205:                                         next if ((($item eq 'author') || ($item eq 'publisher')) && 
                   8206:                                                  ($type eq 'templates'));
1.242     raeburn  8207:                                         $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
                   8208:                                         if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
                   8209:                                             $changes{$type}{$key} = 1;
                   8210:                                         }
                   8211:                                     }
                   8212:                                     $allpos{$type}[$newpos] = $key;
                   8213:                                 }
                   8214:                                 if ($imgdeletions{$key}) {
                   8215:                                     $changes{$type}{$key} = 1;
1.216     raeburn  8216:                                     #FIXME need to obsolete item in RES space
1.242     raeburn  8217:                                 } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
                   8218:                                     my ($cdom,$cnum) = split(/_/,$key);
                   8219:                                     my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
                   8220:                                                                                   $cdom,$cnum,$type,$configuserok,
                   8221:                                                                                   $switchserver,$author_ok);
                   8222:                                     if ($imgurl) {
                   8223:                                         $confhash{$type}{$key}{'image'} = $imgurl;
                   8224:                                         $changes{$type}{$key} = 1; 
1.216     raeburn  8225:                                     }
1.242     raeburn  8226:                                     if ($error) {
                   8227:                                         &Apache::lonnet::logthis($error);
                   8228:                                         $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   8229:                                     } 
                   8230:                                 } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
                   8231:                                     $confhash{$type}{$key}{'image'} = 
                   8232:                                         $domconfig{$action}{$type}{$key}{'image'};
1.216     raeburn  8233:                                 }
                   8234:                             }
                   8235:                         }
                   8236:                     }
                   8237:                 }
                   8238:             }
1.102     raeburn  8239:         } else {
1.144     raeburn  8240:             if ($confhash{'notify'}{'approval'}) {
1.102     raeburn  8241:                 $changes{'notify'}{'approval'} = 1;
                   8242:             }
1.218     raeburn  8243:             if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216     raeburn  8244:                 $changes{'uniquecode'} = 1;
                   8245:             }
                   8246:         }
                   8247:         if ($context eq 'requestcourses') {
1.242     raeburn  8248:             foreach my $type ('textbooks','templates') {
                   8249:                 if ($newbook{$type}) {
                   8250:                     $changes{$type}{$newbook{$type}} = 1;
1.243     raeburn  8251:                     foreach my $item ('subject','title','publisher','author') {
                   8252:                         next if ((($item eq 'author') || ($item eq 'publisher')) &&
                   8253:                                  ($type eq 'template'));
1.242     raeburn  8254:                         $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
                   8255:                         if ($env{'form.'.$type.'_addbook_'.$item}) {
                   8256:                             $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
                   8257:                         }
                   8258:                     }
                   8259:                     if ($type eq 'textbooks') {
                   8260:                         if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
                   8261:                             my ($cdom,$cnum) = split(/_/,$newbook{$type});
                   8262:                             my ($imageurl,$error) =
                   8263:                                 &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
                   8264:                                                         $configuserok,$switchserver,$author_ok);
                   8265:                             if ($imageurl) {
                   8266:                                 $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
                   8267:                             }
                   8268:                             if ($error) {
                   8269:                                 &Apache::lonnet::logthis($error);
                   8270:                                 $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   8271:                             }
                   8272:                         }
1.216     raeburn  8273:                     }
                   8274:                 }
1.242     raeburn  8275:                 if (@{$allpos{$type}} > 0) {
                   8276:                     my $idx = 0;
                   8277:                     foreach my $item (@{$allpos{$type}}) {
                   8278:                         if ($item ne '') {
                   8279:                             $confhash{$type}{$item}{'order'} = $idx;
                   8280:                             if (ref($domconfig{$action}) eq 'HASH') {
                   8281:                                 if (ref($domconfig{$action}{$type}) eq 'HASH') {
                   8282:                                     if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
                   8283:                                         if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
                   8284:                                             $changes{$type}{$item} = 1;
                   8285:                                         }
1.216     raeburn  8286:                                     }
                   8287:                                 }
                   8288:                             }
1.242     raeburn  8289:                             $idx ++;
1.216     raeburn  8290:                         }
                   8291:                     }
                   8292:                 }
                   8293:             }
1.235     raeburn  8294:             if (ref($validationitemsref) eq 'ARRAY') {
                   8295:                 foreach my $item (@{$validationitemsref}) {
                   8296:                     if ($item eq 'fields') {
                   8297:                         my @changed;
                   8298:                         @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
                   8299:                         if (@{$confhash{'validation'}{$item}} > 0) {
                   8300:                             @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
                   8301:                         }
1.266     raeburn  8302:                         if (ref($domconfig{'requestcourses'}) eq 'HASH') {
                   8303:                             if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
                   8304:                                 if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
                   8305:                                     @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
                   8306:                                                                                   $domconfig{'requestcourses'}{'validation'}{$item});
                   8307:                                 } else {
                   8308:                                     @changed = @{$confhash{'validation'}{$item}};
                   8309:                                 }
1.235     raeburn  8310:                             } else {
                   8311:                                 @changed = @{$confhash{'validation'}{$item}};
                   8312:                             }
                   8313:                         } else {
                   8314:                             @changed = @{$confhash{'validation'}{$item}};
                   8315:                         }
                   8316:                         if (@changed) {
                   8317:                             if ($confhash{'validation'}{$item}) {
                   8318:                                 $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
                   8319:                             } else {
                   8320:                                 $changes{'validation'}{$item} = &mt('None');
                   8321:                             }
                   8322:                         }
                   8323:                     } else {
                   8324:                         $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
                   8325:                         if ($item eq 'markup') {
                   8326:                             if ($env{'form.requestcourses_validation_'.$item}) {
                   8327:                                 $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
                   8328:                             }
                   8329:                         }
1.266     raeburn  8330:                         if (ref($domconfig{'requestcourses'}) eq 'HASH') {
                   8331:                             if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
                   8332:                                 if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
                   8333:                                     $changes{'validation'}{$item} = $confhash{'validation'}{$item};
                   8334:                                 }
                   8335:                             } else {
                   8336:                                 if ($confhash{'validation'}{$item} ne '') {
                   8337:                                     $changes{'validation'}{$item} = $confhash{'validation'}{$item};
                   8338:                                 }
1.235     raeburn  8339:                             }
                   8340:                         } else {
                   8341:                             if ($confhash{'validation'}{$item} ne '') {
                   8342:                                 $changes{'validation'}{$item} = $confhash{'validation'}{$item};
                   8343:                             }
                   8344:                         }
                   8345:                     }
                   8346:                 }
                   8347:             }
                   8348:             if ($env{'form.validationdc'}) {
                   8349:                 my $newval = $env{'form.validationdc'};
                   8350:                 my %domcoords = &get_active_dcs($dom);
                   8351:                 if (exists($domcoords{$newval})) {
                   8352:                     $confhash{'validation'}{'dc'} = $newval;
                   8353:                 }
                   8354:             }
                   8355:             if (ref($confhash{'validation'}) eq 'HASH') {
1.266     raeburn  8356:                 if (ref($domconfig{'requestcourses'}) eq 'HASH') {
                   8357:                     if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
                   8358:                         if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
                   8359:                             unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
                   8360:                                 if ($confhash{'validation'}{'dc'} eq '') {
                   8361:                                     $changes{'validation'}{'dc'} = &mt('None');
                   8362:                                 } else {
                   8363:                                     $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
                   8364:                                 }
1.235     raeburn  8365:                             }
1.266     raeburn  8366:                         } elsif ($confhash{'validation'}{'dc'} ne '') {
                   8367:                             $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.235     raeburn  8368:                         }
                   8369:                     } elsif ($confhash{'validation'}{'dc'} ne '') {
                   8370:                         $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
                   8371:                     }
                   8372:                 } elsif ($confhash{'validation'}{'dc'} ne '') {
                   8373:                     $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.266     raeburn  8374:                 }  
                   8375:             } else {
                   8376:                 if (ref($domconfig{'requestcourses'}) eq 'HASH') {
                   8377:                     if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
                   8378:                         if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
                   8379:                             $changes{'validation'}{'dc'} = &mt('None');
                   8380:                         }
                   8381:                     }
1.235     raeburn  8382:                 }
                   8383:             }
1.102     raeburn  8384:         }
                   8385:     } else {
1.86      raeburn  8386:         $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.197     raeburn  8387:         $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86      raeburn  8388:     }
1.72      raeburn  8389:     foreach my $item (@usertools) {
                   8390:         foreach my $type (@{$types},'default','_LC_adv') {
1.104     raeburn  8391:             my $unset; 
1.101     raeburn  8392:             if ($context eq 'requestcourses') {
1.104     raeburn  8393:                 $unset = '0';
                   8394:                 if ($type eq '_LC_adv') {
                   8395:                     $unset = '';
                   8396:                 }
1.101     raeburn  8397:                 if ($confhash{$item}{$type} eq 'autolimit') {
                   8398:                     $confhash{$item}{$type} .= '=';
                   8399:                     unless ($limithash{$item}{$type} =~ /\D/) {
                   8400:                         $confhash{$item}{$type} .= $limithash{$item}{$type};
                   8401:                     }
                   8402:                 }
1.163     raeburn  8403:             } elsif ($context eq 'requestauthor') {
                   8404:                 $unset = '0';
                   8405:                 if ($type eq '_LC_adv') {
                   8406:                     $unset = '';
                   8407:                 }
1.72      raeburn  8408:             } else {
1.101     raeburn  8409:                 if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
                   8410:                     $confhash{$item}{$type} = 1;
                   8411:                 } else {
                   8412:                     $confhash{$item}{$type} = 0;
                   8413:                 }
1.72      raeburn  8414:             }
1.86      raeburn  8415:             if (ref($domconfig{$action}) eq 'HASH') {
1.163     raeburn  8416:                 if ($action eq 'requestauthor') {
                   8417:                     if ($domconfig{$action}{$type} ne $confhash{$type}) {
                   8418:                         $changes{$type} = 1;
                   8419:                     }
                   8420:                 } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86      raeburn  8421:                     if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
                   8422:                         $changes{$item}{$type} = 1;
                   8423:                     }
                   8424:                 } else {
                   8425:                     if ($context eq 'requestcourses') {
1.104     raeburn  8426:                         if ($confhash{$item}{$type} ne $unset) {
1.86      raeburn  8427:                             $changes{$item}{$type} = 1;
                   8428:                         }
                   8429:                     } else {
                   8430:                         if (!$confhash{$item}{$type}) {
                   8431:                             $changes{$item}{$type} = 1;
                   8432:                         }
                   8433:                     }
                   8434:                 }
                   8435:             } else {
                   8436:                 if ($context eq 'requestcourses') {
1.104     raeburn  8437:                     if ($confhash{$item}{$type} ne $unset) {
1.72      raeburn  8438:                         $changes{$item}{$type} = 1;
                   8439:                     }
1.163     raeburn  8440:                 } elsif ($context eq 'requestauthor') {
                   8441:                     if ($confhash{$type} ne $unset) {
                   8442:                         $changes{$type} = 1;
                   8443:                     }
1.72      raeburn  8444:                 } else {
                   8445:                     if (!$confhash{$item}{$type}) {
                   8446:                         $changes{$item}{$type} = 1;
                   8447:                     }
                   8448:                 }
                   8449:             }
1.1       raeburn  8450:         }
                   8451:     }
1.163     raeburn  8452:     unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86      raeburn  8453:         if (ref($domconfig{'quotas'}) eq 'HASH') {
                   8454:             if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
                   8455:                 foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
                   8456:                     if (exists($confhash{'defaultquota'}{$key})) {
                   8457:                         if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
                   8458:                             $changes{'defaultquota'}{$key} = 1;
                   8459:                         }
                   8460:                     } else {
                   8461:                         $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72      raeburn  8462:                     }
                   8463:                 }
1.86      raeburn  8464:             } else {
                   8465:                 foreach my $key (keys(%{$domconfig{'quotas'}})) {
                   8466:                     if (exists($confhash{'defaultquota'}{$key})) {
                   8467:                         if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
                   8468:                             $changes{'defaultquota'}{$key} = 1;
                   8469:                         }
                   8470:                     } else {
                   8471:                         $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72      raeburn  8472:                     }
1.1       raeburn  8473:                 }
                   8474:             }
1.197     raeburn  8475:             if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
                   8476:                 foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
                   8477:                     if (exists($confhash{'authorquota'}{$key})) {
                   8478:                         if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
                   8479:                             $changes{'authorquota'}{$key} = 1;
                   8480:                         }
                   8481:                     } else {
                   8482:                         $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
                   8483:                     }
                   8484:                 }
                   8485:             }
1.1       raeburn  8486:         }
1.86      raeburn  8487:         if (ref($confhash{'defaultquota'}) eq 'HASH') {
                   8488:             foreach my $key (keys(%{$confhash{'defaultquota'}})) {
                   8489:                 if (ref($domconfig{'quotas'}) eq 'HASH') {
                   8490:                     if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
                   8491:                         if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
                   8492:                             $changes{'defaultquota'}{$key} = 1;
                   8493:                         }
                   8494:                     } else {
                   8495:                         if (!exists($domconfig{'quotas'}{$key})) {
                   8496:                             $changes{'defaultquota'}{$key} = 1;
                   8497:                         }
1.72      raeburn  8498:                     }
                   8499:                 } else {
1.86      raeburn  8500:                     $changes{'defaultquota'}{$key} = 1;
1.55      raeburn  8501:                 }
1.1       raeburn  8502:             }
                   8503:         }
1.197     raeburn  8504:         if (ref($confhash{'authorquota'}) eq 'HASH') {
                   8505:             foreach my $key (keys(%{$confhash{'authorquota'}})) {
                   8506:                 if (ref($domconfig{'quotas'}) eq 'HASH') {
                   8507:                     if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
                   8508:                         if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
                   8509:                             $changes{'authorquota'}{$key} = 1;
                   8510:                         }
                   8511:                     } else {
                   8512:                         $changes{'authorquota'}{$key} = 1;
                   8513:                     }
                   8514:                 } else {
                   8515:                     $changes{'authorquota'}{$key} = 1;
                   8516:                 }
                   8517:             }
                   8518:         }
1.1       raeburn  8519:     }
1.72      raeburn  8520: 
1.163     raeburn  8521:     if ($context eq 'requestauthor') {
                   8522:         $domdefaults{'requestauthor'} = \%confhash;
                   8523:     } else {
                   8524:         foreach my $key (keys(%confhash)) {
1.242     raeburn  8525:             unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.216     raeburn  8526:                 $domdefaults{$key} = $confhash{$key};
                   8527:             }
1.163     raeburn  8528:         }
1.72      raeburn  8529:     }
1.163     raeburn  8530: 
1.1       raeburn  8531:     my %quotahash = (
1.86      raeburn  8532:                       $action => { %confhash }
1.1       raeburn  8533:                     );
                   8534:     my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
                   8535:                                              $dom);
                   8536:     if ($putresult eq 'ok') {
                   8537:         if (keys(%changes) > 0) {
1.72      raeburn  8538:             my $cachetime = 24*60*60;
                   8539:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212     raeburn  8540:             if (ref($lastactref) eq 'HASH') {
                   8541:                 $lastactref->{'domdefaults'} = 1;
                   8542:             }
1.1       raeburn  8543:             $resulttext = &mt('Changes made:').'<ul>';
1.210     raeburn  8544:             unless (($context eq 'requestcourses') ||
1.163     raeburn  8545:                     ($context eq 'requestauthor')) {
1.86      raeburn  8546:                 if (ref($changes{'defaultquota'}) eq 'HASH') {
                   8547:                     $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
                   8548:                     foreach my $type (@{$types},'default') {
                   8549:                         if (defined($changes{'defaultquota'}{$type})) {
                   8550:                             my $typetitle = $usertypes->{$type};
                   8551:                             if ($type eq 'default') {
                   8552:                                 $typetitle = $othertitle;
                   8553:                             }
1.213     raeburn  8554:                             $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72      raeburn  8555:                         }
                   8556:                     }
1.86      raeburn  8557:                     $resulttext .= '</ul></li>';
1.72      raeburn  8558:                 }
1.197     raeburn  8559:                 if (ref($changes{'authorquota'}) eq 'HASH') {
1.223     bisitz   8560:                     $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.197     raeburn  8561:                     foreach my $type (@{$types},'default') {
                   8562:                         if (defined($changes{'authorquota'}{$type})) {
                   8563:                             my $typetitle = $usertypes->{$type};
                   8564:                             if ($type eq 'default') {
                   8565:                                 $typetitle = $othertitle;
                   8566:                             }
1.213     raeburn  8567:                             $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.197     raeburn  8568:                         }
                   8569:                     }
                   8570:                     $resulttext .= '</ul></li>';
                   8571:                 }
1.72      raeburn  8572:             }
1.80      raeburn  8573:             my %newenv;
1.72      raeburn  8574:             foreach my $item (@usertools) {
1.163     raeburn  8575:                 my (%haschgs,%inconf);
                   8576:                 if ($context eq 'requestauthor') {
                   8577:                     %haschgs = %changes;
1.210     raeburn  8578:                     %inconf = %confhash;
1.163     raeburn  8579:                 } else {
                   8580:                     if (ref($changes{$item}) eq 'HASH') {
                   8581:                         %haschgs = %{$changes{$item}};
                   8582:                     }
                   8583:                     if (ref($confhash{$item}) eq 'HASH') {
                   8584:                         %inconf = %{$confhash{$item}};
                   8585:                     }
                   8586:                 }
                   8587:                 if (keys(%haschgs) > 0) {
1.80      raeburn  8588:                     my $newacc = 
                   8589:                         &Apache::lonnet::usertools_access($env{'user.name'},
                   8590:                                                           $env{'user.domain'},
1.86      raeburn  8591:                                                           $item,'reload',$context);
1.210     raeburn  8592:                     if (($context eq 'requestcourses') ||
1.163     raeburn  8593:                         ($context eq 'requestauthor')) {
1.108     raeburn  8594:                         if ($env{'environment.canrequest.'.$item} ne $newacc) {
                   8595:                             $newenv{'environment.canrequest.'.$item} = $newacc;
1.86      raeburn  8596:                         }
                   8597:                     } else {
                   8598:                         if ($env{'environment.availabletools.'.$item} ne $newacc) { 
                   8599:                             $newenv{'environment.availabletools.'.$item} = $newacc;
                   8600:                         }
1.80      raeburn  8601:                     }
1.163     raeburn  8602:                     unless ($context eq 'requestauthor') {
                   8603:                         $resulttext .= '<li>'.$titles{$item}.'<ul>';
                   8604:                     }
1.72      raeburn  8605:                     foreach my $type (@{$types},'default','_LC_adv') {
1.163     raeburn  8606:                         if ($haschgs{$type}) {
1.72      raeburn  8607:                             my $typetitle = $usertypes->{$type};
                   8608:                             if ($type eq 'default') {
                   8609:                                 $typetitle = $othertitle;
                   8610:                             } elsif ($type eq '_LC_adv') {
                   8611:                                 $typetitle = 'LON-CAPA Advanced Users'; 
                   8612:                             }
1.163     raeburn  8613:                             if ($inconf{$type}) {
1.101     raeburn  8614:                                 if ($context eq 'requestcourses') {
                   8615:                                     my $cond;
1.163     raeburn  8616:                                     if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101     raeburn  8617:                                         if ($1 eq '') {
                   8618:                                             $cond = &mt('(Automatic processing of any request).');
                   8619:                                         } else {
                   8620:                                             $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
                   8621:                                         }
                   8622:                                     } else { 
1.163     raeburn  8623:                                         $cond = $conditions{$inconf{$type}};
1.101     raeburn  8624:                                     }
                   8625:                                     $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172     raeburn  8626:                                 } elsif ($context eq 'requestauthor') {
                   8627:                                     $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
                   8628:                                                              $titles{$inconf{$type}},$typetitle);
                   8629: 
1.101     raeburn  8630:                                 } else {
                   8631:                                     $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
                   8632:                                 }
1.72      raeburn  8633:                             } else {
1.104     raeburn  8634:                                 if ($type eq '_LC_adv') {
1.163     raeburn  8635:                                     if ($inconf{$type} eq '0') {
1.104     raeburn  8636:                                         $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
                   8637:                                     } else { 
                   8638:                                         $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
                   8639:                                     }
                   8640:                                 } else {
                   8641:                                     $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
                   8642:                                 }
1.72      raeburn  8643:                             }
                   8644:                         }
1.26      raeburn  8645:                     }
1.163     raeburn  8646:                     unless ($context eq 'requestauthor') {
                   8647:                         $resulttext .= '</ul></li>';
                   8648:                     }
1.26      raeburn  8649:                 }
1.1       raeburn  8650:             }
1.163     raeburn  8651:             if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102     raeburn  8652:                 if (ref($changes{'notify'}) eq 'HASH') {
                   8653:                     if ($changes{'notify'}{'approval'}) {
                   8654:                         if (ref($confhash{'notify'}) eq 'HASH') {
                   8655:                             if ($confhash{'notify'}{'approval'}) {
                   8656:                                 $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
                   8657:                             } else {
1.163     raeburn  8658:                                 $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102     raeburn  8659:                             }
                   8660:                         }
                   8661:                     }
                   8662:                 }
                   8663:             }
1.216     raeburn  8664:             if ($action eq 'requestcourses') {
                   8665:                 my @offon = ('off','on');
                   8666:                 if ($changes{'uniquecode'}) {
1.218     raeburn  8667:                     if (ref($confhash{'uniquecode'}) eq 'HASH') {
                   8668:                         my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
                   8669:                         $resulttext .= '<li>'.
                   8670:                                        &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
                   8671:                                        '</li>';
                   8672:                     } else {
                   8673:                         $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
                   8674:                                        '</li>';
                   8675:                     }
1.216     raeburn  8676:                 }
1.242     raeburn  8677:                 foreach my $type ('textbooks','templates') {
                   8678:                     if (ref($changes{$type}) eq 'HASH') {
                   8679:                         $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
                   8680:                         foreach my $key (sort(keys(%{$changes{$type}}))) {
                   8681:                             my %coursehash = &Apache::lonnet::coursedescription($key);
                   8682:                             my $coursetitle = $coursehash{'description'};
                   8683:                             my $position = $confhash{$type}{$key}{'order'} + 1;
                   8684:                             $resulttext .= '<li>';
1.243     raeburn  8685:                             foreach my $item ('subject','title','publisher','author') {
                   8686:                                 next if ((($item eq 'author') || ($item eq 'publisher')) &&
                   8687:                                          ($type eq 'templates'));
1.242     raeburn  8688:                                 my $name = $item.':';
                   8689:                                 $name =~ s/^(\w)/\U$1/;
                   8690:                                 $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
                   8691:                             }
                   8692:                             $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
                   8693:                             if ($type eq 'textbooks') {
                   8694:                                 if ($confhash{$type}{$key}{'image'}) {
                   8695:                                     $resulttext .= ' '.&mt('Image: [_1]',
                   8696:                                                    '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
                   8697:                                                    ' alt="Textbook cover" />').'<br />';
                   8698:                                 }
                   8699:                             }
                   8700:                             $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.216     raeburn  8701:                         }
1.242     raeburn  8702:                         $resulttext .= '</ul></li>';
1.216     raeburn  8703:                     }
                   8704:                 }
1.235     raeburn  8705:                 if (ref($changes{'validation'}) eq 'HASH') {
                   8706:                     if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
                   8707:                         $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
                   8708:                         foreach my $item (@{$validationitemsref}) {
                   8709:                             if (exists($changes{'validation'}{$item})) {
                   8710:                                 if ($item eq 'markup') {
                   8711:                                     $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
                   8712:                                                               '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
                   8713:                                 } else {
                   8714:                                     $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
                   8715:                                                               '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
                   8716:                                 }
                   8717:                             }
                   8718:                         }
                   8719:                         if (exists($changes{'validation'}{'dc'})) {
                   8720:                             $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
                   8721:                                                      '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
                   8722:                         }
                   8723:                     }
                   8724:                 }
1.216     raeburn  8725:             }
1.1       raeburn  8726:             $resulttext .= '</ul>';
1.80      raeburn  8727:             if (keys(%newenv)) {
                   8728:                 &Apache::lonnet::appenv(\%newenv);
                   8729:             }
1.1       raeburn  8730:         } else {
1.86      raeburn  8731:             if ($context eq 'requestcourses') {
                   8732:                 $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163     raeburn  8733:             } elsif ($context eq 'requestauthor') {
                   8734:                 $resulttext = &mt('No changes made to rights to request author space.');
1.86      raeburn  8735:             } else {
1.90      weissno  8736:                 $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86      raeburn  8737:             }
1.1       raeburn  8738:         }
                   8739:     } else {
1.11      albertel 8740:         $resulttext = '<span class="LC_error">'.
                   8741: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  8742:     }
1.216     raeburn  8743:     if ($errors) {
                   8744:         $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
                   8745:                        '<ul>'.$errors.'</ul></p>';
                   8746:     }
1.3       raeburn  8747:     return $resulttext;
1.1       raeburn  8748: }
                   8749: 
1.216     raeburn  8750: sub process_textbook_image {
1.242     raeburn  8751:     my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.216     raeburn  8752:     my $filename = $env{'form.'.$caller.'.filename'};
                   8753:     my ($error,$url);
                   8754:     my ($width,$height) = (50,50);
                   8755:     if ($configuserok eq 'ok') {
                   8756:         if ($switchserver) {
                   8757:             $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
                   8758:                          $switchserver);
                   8759:         } elsif ($author_ok eq 'ok') {
                   8760:             my ($result,$imageurl) =
                   8761:                 &publishlogo($r,'upload',$caller,$dom,$confname,
1.242     raeburn  8762:                              "$type/$dom/$cnum/cover",$width,$height);
1.216     raeburn  8763:             if ($result eq 'ok') {
                   8764:                 $url = $imageurl;
                   8765:             } else {
                   8766:                 $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
                   8767:             }
                   8768:         } else {
                   8769:             $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);
                   8770:         }
                   8771:     } else {
                   8772:         $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);
                   8773:     }
                   8774:     return ($url,$error);
                   8775: }
                   8776: 
1.267     raeburn  8777: sub modify_ltitools {
                   8778:     my ($r,$dom,$action,$lastactref,%domconfig) = @_;
                   8779:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
                   8780:     my ($newid,@allpos,%changes,%confhash,$errors,$resulttext);
                   8781:     my $confname = $dom.'-domainconfig';
                   8782:     my $servadm = $r->dir_config('lonAdmEMail');
                   8783:     my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
                   8784:     my (%posslti,%possfield);
                   8785:     my @courseroles = ('cc','in','ta','ep','st');
                   8786:     my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
                   8787:     map { $posslti{$_} = 1; } @ltiroles;
                   8788:     my @allfields = ('fullname','firstname','lastname','email','user','roles');
                   8789:     map { $possfield{$_} = 1; } @allfields;
                   8790:     my %lt = &ltitools_names(); 
                   8791:     if ($env{'form.ltitools_add'}) {
                   8792:         my $title = $env{'form.ltitools_add_title'};
                   8793:         $title =~ s/(`)/'/g;
                   8794:         ($newid,my $error) = &get_ltitools_id($dom,$title);
                   8795:         if ($newid) {
                   8796:             my $position = $env{'form.ltitools_add_pos'};
                   8797:             $position =~ s/\D+//g;
                   8798:             if ($position ne '') {
                   8799:                 $allpos[$position] = $newid;
                   8800:             }
                   8801:             $changes{$newid} = 1;
                   8802:             foreach my $item ('title','url','key','secret') {
                   8803:                 $env{'form.ltitools_add_'.$item} =~ s/(`)/'/g;
                   8804:                 if ($env{'form.ltitools_add_'.$item}) {
                   8805:                     $confhash{$newid}{$item} = $env{'form.ltitools_add_'.$item};
                   8806:                 }
                   8807:             }
                   8808:             if ($env{'form.ltitools_add_version'} eq 'LTI-1p0') {
                   8809:                 $confhash{$newid}{'version'} = $env{'form.ltitools_add_version'};
                   8810:             }
                   8811:             if ($env{'form.ltitools_add_msgtype'} eq 'basic-lti-launch-request') {
                   8812:                 $confhash{$newid}{'msgtype'} = $env{'form.ltitools_add_msgtype'};
                   8813:             }
                   8814:             foreach my $item ('width','height') {
                   8815:                 $env{'form.ltitools_add_'.$item} =~ s/^\s+//;
                   8816:                 $env{'form.ltitools_add_'.$item} =~ s/\s+$//;
                   8817:                 if ($env{'form.ltitools_add_'.$item} =~ /^\d+$/) {
                   8818:                     $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
                   8819:                 }
                   8820:             }
                   8821:             if ($env{'form.ltitools_add_target'} eq 'window') {
                   8822:                 $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
                   8823:             } else {
                   8824:                 $confhash{$newid}{'display'}{'target'} = 'iframe';
                   8825:             }
                   8826:             foreach my $item ('passback','roster') {
                   8827:                 if ($env{'form.ltitools_add_'.$item}) {
                   8828:                     $confhash{$newid}{$item} = 1;
                   8829:                 }
                   8830:             }
                   8831:             if ($env{'form.ltitools_add_image.filename'} ne '') {
                   8832:                 my ($imageurl,$error) =
                   8833:                     &process_ltitools_image($r,$dom,$confname,'ltitools_add_image',$dom,
                   8834:                                             $configuserok,$switchserver,$author_ok);
                   8835:                 if ($imageurl) {
                   8836:                     $confhash{$newid}{'image'} = $imageurl;
                   8837:                 }
                   8838:                 if ($error) {
                   8839:                     &Apache::lonnet::logthis($error);
                   8840:                     $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   8841:                 }
                   8842:             }
                   8843:             my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_add_fields');
                   8844:             foreach my $field (@fields) {
                   8845:                 if ($possfield{$field}) {
                   8846:                     if ($field eq 'roles') {
                   8847:                         foreach my $role (@courseroles) {
                   8848:                             my $choice = $env{'form.ltitools_add_roles_'.$role};
                   8849:                             if (($choice ne '') && ($posslti{$choice})) {
                   8850:                                 $confhash{$newid}{'roles'}{$role} = $choice;
                   8851:                                 if ($role eq 'cc') {
                   8852:                                     $confhash{$newid}{'roles'}{'co'} = $choice; 
                   8853:                                 }
                   8854:                             }
                   8855:                         }
                   8856:                     } else {
                   8857:                         $confhash{$newid}{'fields'}{$field} = 1;
                   8858:                     }
                   8859:                 }
                   8860:             }
1.273     raeburn  8861:             my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig');
                   8862:             foreach my $item (@courseconfig) {
                   8863:                 $confhash{$newid}{'crsconf'}{$item} = 1;
                   8864:             }
1.267     raeburn  8865:             if ($env{'form.ltitools_add_custom'}) {
                   8866:                 my $name = $env{'form.ltitools_add_custom_name'};
                   8867:                 my $value = $env{'form.ltitools_add_custom_value'};
                   8868:                 $value =~ s/(`)/'/g;
                   8869:                 $name =~ s/(`)/'/g;
                   8870:                 $confhash{$newid}{'custom'}{$name} = $value;
                   8871:             }
                   8872:         } else {
                   8873:             my $error = &mt('Failed to acquire unique ID for new external tool');   
                   8874:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   8875:         }
                   8876:     }
                   8877:     if (ref($domconfig{$action}) eq 'HASH') {
                   8878:         my %deletions;
                   8879:         my @todelete = &Apache::loncommon::get_env_multiple('form.ltitools_del');
                   8880:         if (@todelete) {
                   8881:             map { $deletions{$_} = 1; } @todelete;
                   8882:         }
                   8883:         my %customadds;
                   8884:         my @newcustom = &Apache::loncommon::get_env_multiple('form.ltitools_customadd');
                   8885:         if (@newcustom) {
                   8886:             map { $customadds{$_} = 1; } @newcustom;
                   8887:         } 
                   8888:         my %imgdeletions;
                   8889:         my @todeleteimages = &Apache::loncommon::get_env_multiple('form.ltitools_image_del');
                   8890:         if (@todeleteimages) {
                   8891:             map { $imgdeletions{$_} = 1; } @todeleteimages;
                   8892:         }
                   8893:         my $maxnum = $env{'form.ltitools_maxnum'};
                   8894:         for (my $i=0; $i<=$maxnum; $i++) {
                   8895:             my $itemid = $env{'form.ltitools_id_'.$i};
                   8896:             if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
                   8897:                 if ($deletions{$itemid}) {
                   8898:                     if ($domconfig{$action}{$itemid}{'image'}) {
                   8899:                         #FIXME need to obsolete item in RES space
                   8900:                     }
                   8901:                     $changes{$itemid} = $domconfig{$action}{$itemid}{'title'};
                   8902:                     next;
                   8903:                 } else {
                   8904:                     my $newpos = $env{'form.ltitools_'.$itemid};
                   8905:                     $newpos =~ s/\D+//g;
                   8906:                     foreach my $item ('title','url','key','secret') {
                   8907:                         $confhash{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
                   8908:                         if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
                   8909:                             $changes{$itemid} = 1;
                   8910:                         }
                   8911:                     }
                   8912:                     if ($env{'form.ltitools_version_'.$i} eq 'LTI-1p0') {
                   8913:                         $confhash{$itemid}{'version'} = $env{'form.ltitools_version_'.$i};
                   8914:                     }
                   8915:                     if ($env{'form.ltitools_msgtype_'.$i} eq 'basic-lti-launch-request') {
                   8916:                         $confhash{$itemid}{'msgtype'} = $env{'form.ltitools_msgtype_'.$i};
                   8917:                     }
                   8918:                     foreach my $size ('width','height') {
                   8919:                         $env{'form.ltitools_'.$size.'_'.$i} =~ s/^\s+//;
                   8920:                         $env{'form.ltitools_'.$size.'_'.$i} =~ s/\s+$//;
                   8921:                         if ($env{'form.ltitools_'.$size.'_'.$i} =~ /^\d+$/) {
                   8922:                             $confhash{$itemid}{'display'}{$size} = $env{'form.ltitools_'.$size.'_'.$i};
                   8923:                             if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
                   8924:                                 if ($domconfig{$action}{$itemid}{'display'}{$size} ne $confhash{$itemid}{'display'}{$size}) {
                   8925:                                     $changes{$itemid} = 1;
                   8926:                                 }
                   8927:                             } else {
                   8928:                                 $changes{$itemid} = 1;
                   8929:                             }
                   8930:                         }
                   8931:                     }
                   8932:                     if ($env{'form.ltitools_target_'.$i} eq 'window') {
                   8933:                         $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
                   8934:                     } else {
                   8935:                         $confhash{$itemid}{'display'}{'target'} = 'iframe';
                   8936:                     }
                   8937:                     if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
                   8938:                         if ($domconfig{$action}{$itemid}{'display'}{'target'} ne $confhash{$itemid}{'display'}{'target'}) {
                   8939:                             $changes{$itemid} = 1;
                   8940:                         }
                   8941:                     } else {
                   8942:                         $changes{$itemid} = 1;
                   8943:                     }
                   8944:                     foreach my $extra ('passback','roster') {
                   8945:                         if ($env{'form.ltitools_'.$extra.'_'.$i}) {
                   8946:                             $confhash{$itemid}{$extra} = 1;
                   8947:                         }
                   8948:                         if ($domconfig{$action}{$itemid}{$extra} ne $confhash{$itemid}{$extra}) {
                   8949:                             $changes{$itemid} = 1;
                   8950:                         }
                   8951:                     }
1.273     raeburn  8952:                     my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig_'.$i);
                   8953:                     foreach my $item ('label','title','target') {
                   8954:                         if (grep(/^\Q$item\E$/,@courseconfig)) {
                   8955:                             $confhash{$itemid}{'crsconf'}{$item} = 1;
                   8956:                             if (ref($domconfig{$action}{$itemid}{'crsconf'}) eq 'HASH') {
                   8957:                                 if ($domconfig{$action}{$itemid}{'crsconf'}{$item} ne $confhash{$itemid}{'crsconf'}{$item}) {
                   8958:                                     $changes{$itemid} = 1;
                   8959:                                 }
                   8960:                             } else {
                   8961:                                 $changes{$itemid} = 1;
                   8962:                             }
                   8963:                         }
                   8964:                     }
1.267     raeburn  8965:                     my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_fields_'.$i);
                   8966:                     foreach my $field (@fields) {
                   8967:                         if ($possfield{$field}) {
                   8968:                             if ($field eq 'roles') {
                   8969:                                 foreach my $role (@courseroles) {
                   8970:                                     my $choice = $env{'form.ltitools_roles_'.$role.'_'.$i};
                   8971:                                     if (($choice ne '') && ($posslti{$choice})) {
                   8972:                                         $confhash{$itemid}{'roles'}{$role} = $choice;
                   8973:                                         if ($role eq 'cc') {
                   8974:                                             $confhash{$itemid}{'roles'}{'co'} = $choice;
                   8975:                                         }
                   8976:                                     }
                   8977:                                     if (ref($domconfig{$action}{$itemid}{'roles'}) eq 'HASH') {
                   8978:                                         if ($domconfig{$action}{$itemid}{'roles'}{$role} ne $confhash{$itemid}{'roles'}{$role}) {
                   8979:                                             $changes{$itemid} = 1;
                   8980:                                         }
                   8981:                                     } elsif ($confhash{$itemid}{'roles'}{$role}) {
                   8982:                                         $changes{$itemid} = 1;
                   8983:                                     }
                   8984:                                 }
                   8985:                             } else {
                   8986:                                 $confhash{$itemid}{'fields'}{$field} = 1;
                   8987:                                 if (ref($domconfig{$action}{$itemid}{'fields'}) eq 'HASH') {
                   8988:                                     if ($domconfig{$action}{$itemid}{'fields'}{$field} ne $confhash{$itemid}{'fields'}{$field}) {
                   8989:                                         $changes{$itemid} = 1;
                   8990:                                     }
                   8991:                                 } else {
                   8992:                                     $changes{$itemid} = 1;
                   8993:                                 }
                   8994:                             }
                   8995:                         }
                   8996:                     }
                   8997:                     $allpos[$newpos] = $itemid;
                   8998:                 }
                   8999:                 if ($imgdeletions{$itemid}) {
                   9000:                     $changes{$itemid} = 1;
                   9001:                     #FIXME need to obsolete item in RES space
                   9002:                 } elsif ($env{'form.ltitools_image_'.$i.'.filename'}) {
                   9003:                     my ($imgurl,$error) = &process_ltitools_image($r,$dom,$confname,'ltitools_image_'.$i,
                   9004:                                                                  $itemid,$configuserok,$switchserver,
                   9005:                                                                  $author_ok);
                   9006:                     if ($imgurl) {
                   9007:                         $confhash{$itemid}{'image'} = $imgurl;
                   9008:                         $changes{$itemid} = 1;
                   9009:                     }
                   9010:                     if ($error) {
                   9011:                         &Apache::lonnet::logthis($error);
                   9012:                         $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   9013:                     }
                   9014:                 } elsif ($domconfig{$action}{$itemid}{'image'}) {
                   9015:                     $confhash{$itemid}{'image'} =
                   9016:                        $domconfig{$action}{$itemid}{'image'};
                   9017:                 }
                   9018:                 if ($customadds{$i}) {
                   9019:                     my $name = $env{'form.ltitools_custom_name_'.$i};
                   9020:                     $name =~ s/(`)/'/g;
                   9021:                     $name =~ s/^\s+//;
                   9022:                     $name =~ s/\s+$//;
                   9023:                     my $value = $env{'form.ltitools_custom_value_'.$i};
                   9024:                     $value =~ s/(`)/'/g;
                   9025:                     $value =~ s/^\s+//;
                   9026:                     $value =~ s/\s+$//;
                   9027:                     if ($name ne '') {
                   9028:                         $confhash{$itemid}{'custom'}{$name} = $value;
                   9029:                         $changes{$itemid} = 1;
                   9030:                     }
                   9031:                 }
                   9032:                 my %customdels;
                   9033:                 my @customdeletions = &Apache::loncommon::get_env_multiple('form.ltitools_customdel_'.$i); 
                   9034:                 if (@customdeletions) {
                   9035:                     $changes{$itemid} = 1;
                   9036:                 }
                   9037:                 map { $customdels{$_} = 1; } @customdeletions;
                   9038:                 if (ref($domconfig{$action}{$itemid}{'custom'}) eq 'HASH') {
                   9039:                     foreach my $key (keys(%{$domconfig{$action}{$itemid}{'custom'}})) {
                   9040:                         unless ($customdels{$key}) {
                   9041:                             if ($env{'form.ltitools_customval_'.$key.'_'.$i} ne '') {
                   9042:                                 $confhash{$itemid}{'custom'}{$key} = $env{'form.ltitools_customval_'.$key.'_'.$i}; 
                   9043:                             }
                   9044:                             if ($domconfig{$action}{$itemid}{'custom'}{$key} ne $env{'form.ltitools_customval_'.$key.'_'.$i}) {
                   9045:                                 $changes{$itemid} = 1;
                   9046:                             }
                   9047:                         }
                   9048:                     }
                   9049:                 }
                   9050:                 unless ($changes{$itemid}) {
                   9051:                     foreach my $key (keys(%{$domconfig{$action}{$itemid}})) {
                   9052:                         if (ref($domconfig{$action}{$itemid}{$key}) eq 'HASH') {
                   9053:                             if (ref($confhash{$itemid}{$key}) eq 'HASH') {
                   9054:                                 foreach my $innerkey (keys(%{$domconfig{$action}{$itemid}{$key}})) {
                   9055:                                     unless (exists($confhash{$itemid}{$key}{$innerkey})) {
                   9056:                                         $changes{$itemid} = 1;
                   9057:                                         last;
                   9058:                                     }
                   9059:                                 }
                   9060:                             } elsif (keys(%{$domconfig{$action}{$itemid}{$key}}) > 0) {
                   9061:                                 $changes{$itemid} = 1;
                   9062:                             }
                   9063:                         }
                   9064:                         last if ($changes{$itemid});
                   9065:                     }
                   9066:                 }
                   9067:             }
                   9068:         }
                   9069:     }
                   9070:     if (@allpos > 0) {
                   9071:         my $idx = 0;
                   9072:         foreach my $itemid (@allpos) {
                   9073:             if ($itemid ne '') {
                   9074:                 $confhash{$itemid}{'order'} = $idx;
                   9075:                 if (ref($domconfig{$action}) eq 'HASH') {
                   9076:                     if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
                   9077:                         if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
                   9078:                             $changes{$itemid} = 1;
                   9079:                         }
                   9080:                     }
                   9081:                 }
                   9082:                 $idx ++;
                   9083:             }
                   9084:         }
                   9085:     }
                   9086:     my %ltitoolshash = (
                   9087:                           $action => { %confhash }
                   9088:                        );
                   9089:     my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,
                   9090:                                              $dom);
                   9091:     if ($putresult eq 'ok') {
                   9092:         if (keys(%changes) > 0) {
                   9093:             my $cachetime = 24*60*60;
                   9094:             &Apache::lonnet::do_cache_new('ltitools',$dom,\%confhash,$cachetime);
                   9095:             if (ref($lastactref) eq 'HASH') {
                   9096:                 $lastactref->{'ltitools'} = 1;
                   9097:             }
                   9098:             $resulttext = &mt('Changes made:').'<ul>';
                   9099:             my %bynum;
                   9100:             foreach my $itemid (sort(keys(%changes))) {
                   9101:                 my $position = $confhash{$itemid}{'order'};
                   9102:                 $bynum{$position} = $itemid;
                   9103:             }
                   9104:             foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
                   9105:                 my $itemid = $bynum{$pos}; 
                   9106:                 if (ref($confhash{$itemid}) ne 'HASH') {
                   9107:                     $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
                   9108:                 } else {
                   9109:                     $resulttext .= '<li><b>'.$confhash{$itemid}{'title'}.'</b>';
                   9110:                     if ($confhash{$itemid}{'image'}) {
                   9111:                         $resulttext .= '&nbsp;'.
                   9112:                                        '<img src="'.$confhash{$itemid}{'image'}.'"'.
                   9113:                                        ' alt="'.&mt('Tool Provider icon').'" />';
                   9114:                     }
                   9115:                     $resulttext .= '</li><ul>';
                   9116:                     my $position = $pos + 1;
                   9117:                     $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
                   9118:                     foreach my $item ('version','msgtype','url','key') {
                   9119:                         if ($confhash{$itemid}{$item} ne '') {
                   9120:                             $resulttext .= '<li>'.$lt{$item}.':&nbsp;'.$confhash{$itemid}{$item}.'</li>';
                   9121:                         }
                   9122:                     }
                   9123:                     if ($confhash{$itemid}{'secret'} ne '') {
                   9124:                         $resulttext .= '<li>'.$lt{'secret'}.':&nbsp;';
                   9125:                         my $num = length($confhash{$itemid}{'secret'});
                   9126:                         $resulttext .= ('*'x$num).'</li>';
                   9127:                     }
1.273     raeburn  9128:                     $resulttext .= '<li>'.&mt('Configurable in course:');
                   9129:                     my @possconfig = ('label','title','target');
                   9130:                     my $numconfig = 0; 
                   9131:                     if (ref($confhash{$itemid}{'crsconf'}) eq 'HASH') { 
                   9132:                         foreach my $item (@possconfig) {
                   9133:                             if ($confhash{$itemid}{'crsconf'}{$item}) {
                   9134:                                 $numconfig ++;
                   9135:                                 $resulttext .= ' '.$lt{'crs'.$item};
                   9136:                             }
                   9137:                         }
                   9138:                     }
                   9139:                     if (!$numconfig) {
                   9140:                         $resulttext .= &mt('None');
                   9141:                     }
                   9142:                     $resulttext .= '</li>';
1.267     raeburn  9143:                     foreach my $item ('passback','roster') {
                   9144:                         $resulttext .= '<li>'.$lt{$item}.'&nbsp;';
                   9145:                         if ($confhash{$itemid}{$item}) {
                   9146:                             $resulttext .= &mt('Yes');
                   9147:                         } else {
                   9148:                             $resulttext .= &mt('No');
                   9149:                         }
                   9150:                         $resulttext .= '</li>';
                   9151:                     }
                   9152:                     if (ref($confhash{$itemid}{'display'}) eq 'HASH') {
                   9153:                         my $displaylist;
                   9154:                         if ($confhash{$itemid}{'display'}{'target'}) {
                   9155:                             $displaylist = &mt('Display target').':&nbsp;'.
                   9156:                                            $confhash{$itemid}{'display'}{'target'}.',';
                   9157:                         }
                   9158:                         foreach my $size ('width','height') { 
                   9159:                             if ($confhash{$itemid}{'display'}{$size}) {
                   9160:                                 $displaylist .= ('&nbsp;'x2).$lt{$size}.':&nbsp;'.
                   9161:                                                 $confhash{$itemid}{'display'}{$size}.',';
                   9162:                             }
                   9163:                         }
                   9164:                         if ($displaylist) {
                   9165:                             $displaylist =~ s/,$//;
                   9166:                             $resulttext .= '<li>'.$displaylist.'</li>';
                   9167:                         }
                   9168:                     } 
                   9169:                     if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
                   9170:                         my $fieldlist;
                   9171:                         foreach my $field (@allfields) {
                   9172:                             if ($confhash{$itemid}{'fields'}{$field}) {
                   9173:                                 $fieldlist .= ('&nbsp;'x2).$lt{$field}.',';
                   9174:                             }
                   9175:                         }
                   9176:                         if ($fieldlist) {
                   9177:                             $fieldlist =~ s/,$//;
                   9178:                             $resulttext .= '<li>'.&mt('Data sent').':'.$fieldlist.'</li>';
                   9179:                         }
                   9180:                     }
                   9181:                     if (ref($confhash{$itemid}{'roles'}) eq 'HASH') {
                   9182:                         my $rolemaps;
                   9183:                         foreach my $role (@courseroles) {
                   9184:                             if ($confhash{$itemid}{'roles'}{$role}) {
                   9185:                                 $rolemaps .= ('&nbsp;'x2).&Apache::lonnet::plaintext($role,'Course').'='.
                   9186:                                              $confhash{$itemid}{'roles'}{$role}.',';
                   9187:                             }
                   9188:                         }
                   9189:                         if ($rolemaps) {
                   9190:                             $rolemaps =~ s/,$//; 
                   9191:                             $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
                   9192:                         }
                   9193:                     }
                   9194:                     if (ref($confhash{$itemid}{'custom'}) eq 'HASH') {
                   9195:                         my $customlist;
                   9196:                         if (keys(%{$confhash{$itemid}{'custom'}})) {
                   9197:                             foreach my $key (sort(keys(%{$confhash{$itemid}{'custom'}}))) {
                   9198:                                 $customlist .= $key.':'.$confhash{$itemid}{'custom'}{$key}.('&nbsp;'x2);
                   9199:                             } 
                   9200:                         }
                   9201:                         if ($customlist) {
                   9202:                             $resulttext .= '<li>'.&mt('Custom items').':'.$customlist.'</li>';
                   9203:                         }
                   9204:                     } 
                   9205:                     $resulttext .= '</ul></li>';
                   9206:                 }
                   9207:             }
                   9208:             $resulttext .= '</ul>';
                   9209:         } else {
                   9210:             $resulttext = &mt('No changes made.');
                   9211:         }
                   9212:     } else {
                   9213:         $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
                   9214:     }
                   9215:     if ($errors) {
                   9216:         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
                   9217:                        $errors.'</ul>';
                   9218:     }
                   9219:     return $resulttext;
                   9220: }
                   9221: 
                   9222: sub process_ltitools_image {
                   9223:     my ($r,$dom,$confname,$caller,$itemid,$configuserok,$switchserver,$author_ok) = @_;
                   9224:     my $filename = $env{'form.'.$caller.'.filename'};
                   9225:     my ($error,$url);
                   9226:     my ($width,$height) = (21,21);
                   9227:     if ($configuserok eq 'ok') {
                   9228:         if ($switchserver) {
                   9229:             $error = &mt('Upload of Tool Provider (LTI) icon is not permitted to this server: [_1]',
                   9230:                          $switchserver);
                   9231:         } elsif ($author_ok eq 'ok') {
                   9232:             my ($result,$imageurl,$madethumb) =
                   9233:                 &publishlogo($r,'upload',$caller,$dom,$confname,
                   9234:                              "ltitools/$itemid/icon",$width,$height);
                   9235:             if ($result eq 'ok') {
                   9236:                 if ($madethumb) {
                   9237:                     my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
                   9238:                     my $imagethumb = "$path/tn-".$imagefile;
                   9239:                     $url = $imagethumb;
                   9240:                 } else {
                   9241:                     $url = $imageurl;
                   9242:                 }
                   9243:             } else {
                   9244:                 $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
                   9245:             }
                   9246:         } else {
                   9247:             $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);
                   9248:         }
                   9249:     } else {
                   9250:         $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);
                   9251:     }
                   9252:     return ($url,$error);
                   9253: }
                   9254: 
                   9255: sub get_ltitools_id {
                   9256:     my ($cdom,$title) = @_;
                   9257:     # get lock on ltitools db
                   9258:     my $lockhash = {
                   9259:                       lock => $env{'user.name'}.
                   9260:                               ':'.$env{'user.domain'},
                   9261:                    };
                   9262:     my $tries = 0;
                   9263:     my $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
                   9264:     my ($id,$error);
                   9265:  
                   9266:     while (($gotlock ne 'ok') && ($tries<10)) {
                   9267:         $tries ++;
                   9268:         sleep (0.1);
                   9269:         $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
                   9270:     }
                   9271:     if ($gotlock eq 'ok') {
                   9272:         my %currids = &Apache::lonnet::dump_dom('ltitools',$cdom);
                   9273:         if ($currids{'lock'}) {
                   9274:             delete($currids{'lock'});
                   9275:             if (keys(%currids)) {
                   9276:                 my @curr = sort { $a <=> $b } keys(%currids);
                   9277:                 if ($curr[-1] =~ /^\d+$/) {
                   9278:                     $id = 1 + $curr[-1];
                   9279:                 }
                   9280:             } else {
                   9281:                 $id = 1;
                   9282:             }
                   9283:             if ($id) {
                   9284:                 unless (&Apache::lonnet::newput_dom('ltitools',{ $id => $title },$cdom) eq 'ok') {
                   9285:                     $error = 'nostore';
                   9286:                 }
                   9287:             } else {
                   9288:                 $error = 'nonumber';
                   9289:             }
                   9290:         }
                   9291:         my $dellockoutcome = &Apache::lonnet::del_dom('ltitools',['lock'],$cdom);
                   9292:     } else {
                   9293:         $error = 'nolock';
                   9294:     }
                   9295:     return ($id,$error);
                   9296: }
                   9297: 
1.3       raeburn  9298: sub modify_autoenroll {
1.205     raeburn  9299:     my ($dom,$lastactref,%domconfig) = @_;
1.1       raeburn  9300:     my ($resulttext,%changes);
                   9301:     my %currautoenroll;
                   9302:     if (ref($domconfig{'autoenroll'}) eq 'HASH') {
                   9303:         foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
                   9304:             $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
                   9305:         }
                   9306:     }
                   9307:     my $autorun = &Apache::lonnet::auto_run(undef,$dom),
                   9308:     my %title = ( run => 'Auto-enrollment active',
1.129     raeburn  9309:                   sender => 'Sender for notification messages',
1.274     raeburn  9310:                   coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
                   9311:                   failsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1       raeburn  9312:     my @offon = ('off','on');
1.17      raeburn  9313:     my $sender_uname = $env{'form.sender_uname'};
                   9314:     my $sender_domain = $env{'form.sender_domain'};
                   9315:     if ($sender_domain eq '') {
                   9316:         $sender_uname = '';
                   9317:     } elsif ($sender_uname eq '') {
                   9318:         $sender_domain = '';
                   9319:     }
1.129     raeburn  9320:     my $coowners = $env{'form.autoassign_coowners'};
1.274     raeburn  9321:     my $failsafe = $env{'form.autoenroll_failsafe'};
                   9322:     $failsafe =~ s{^\s+|\s+$}{}g;
                   9323:     if ($failsafe =~ /\D/) {
                   9324:         undef($failsafe);
                   9325:     }
1.1       raeburn  9326:     my %autoenrollhash =  (
1.129     raeburn  9327:                        autoenroll => { 'run' => $env{'form.autoenroll_run'},
                   9328:                                        'sender_uname' => $sender_uname,
                   9329:                                        'sender_domain' => $sender_domain,
                   9330:                                        'co-owners' => $coowners,
1.274     raeburn  9331:                                        'autofailsafe' => $failsafe,
1.1       raeburn  9332:                                 }
                   9333:                      );
1.4       raeburn  9334:     my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
                   9335:                                              $dom);
1.1       raeburn  9336:     if ($putresult eq 'ok') {
                   9337:         if (exists($currautoenroll{'run'})) {
                   9338:              if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
                   9339:                  $changes{'run'} = 1;
                   9340:              }
                   9341:         } elsif ($autorun) {
                   9342:             if ($env{'form.autoenroll_run'} ne '1') {
1.23      raeburn  9343:                  $changes{'run'} = 1;
1.1       raeburn  9344:             }
                   9345:         }
1.17      raeburn  9346:         if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1       raeburn  9347:             $changes{'sender'} = 1;
                   9348:         }
1.17      raeburn  9349:         if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1       raeburn  9350:             $changes{'sender'} = 1;
                   9351:         }
1.129     raeburn  9352:         if ($currautoenroll{'co-owners'} ne '') {
                   9353:             if ($currautoenroll{'co-owners'} ne $coowners) {
                   9354:                 $changes{'coowners'} = 1;
                   9355:             }
                   9356:         } elsif ($coowners) {
                   9357:             $changes{'coowners'} = 1;
1.274     raeburn  9358:         }
                   9359:         if ($currautoenroll{'autofailsafe'} ne $failsafe) {
                   9360:             $changes{'autofailsafe'} = 1;
                   9361:         }
1.1       raeburn  9362:         if (keys(%changes) > 0) {
                   9363:             $resulttext = &mt('Changes made:').'<ul>';
1.3       raeburn  9364:             if ($changes{'run'}) {
1.1       raeburn  9365:                 $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
                   9366:             }
                   9367:             if ($changes{'sender'}) {
1.17      raeburn  9368:                 if ($sender_uname eq '' || $sender_domain eq '') {
                   9369:                     $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
                   9370:                 } else {
                   9371:                     $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
                   9372:                 }
1.1       raeburn  9373:             }
1.129     raeburn  9374:             if ($changes{'coowners'}) {
                   9375:                 $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
                   9376:                 &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212     raeburn  9377:                 if (ref($lastactref) eq 'HASH') {
                   9378:                     $lastactref->{'domainconfig'} = 1;
                   9379:                 }
1.129     raeburn  9380:             }
1.274     raeburn  9381:             if ($changes{'autofailsafe'}) {
                   9382:                 if ($failsafe ne '') {
                   9383:                     $resulttext .= '<li>'.&mt("$title{'failsafe'} set to [_1]",$failsafe).'</li>';
                   9384:                 } else {
                   9385:                     $resulttext .= '<li>'.&mt("$title{'failsafe'} deleted");
                   9386:                 }
                   9387:                 &Apache::lonnet::get_domain_defaults($dom,1);
                   9388:                 if (ref($lastactref) eq 'HASH') {
                   9389:                     $lastactref->{'domdefaults'} = 1;
                   9390:                 }
                   9391:             }
1.1       raeburn  9392:             $resulttext .= '</ul>';
                   9393:         } else {
                   9394:             $resulttext = &mt('No changes made to auto-enrollment settings');
                   9395:         }
                   9396:     } else {
1.11      albertel 9397:         $resulttext = '<span class="LC_error">'.
                   9398: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  9399:     }
1.3       raeburn  9400:     return $resulttext;
1.1       raeburn  9401: }
                   9402: 
                   9403: sub modify_autoupdate {
1.3       raeburn  9404:     my ($dom,%domconfig) = @_;
1.1       raeburn  9405:     my ($resulttext,%currautoupdate,%fields,%changes);
                   9406:     if (ref($domconfig{'autoupdate'}) eq 'HASH') {
                   9407:         foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
                   9408:             $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
                   9409:         }
                   9410:     }
                   9411:     my @offon = ('off','on');
                   9412:     my %title = &Apache::lonlocal::texthash (
                   9413:                    run => 'Auto-update:',
                   9414:                    classlists => 'Updates to user information in classlists?'
                   9415:                 );
1.44      raeburn  9416:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1       raeburn  9417:     my %fieldtitles = &Apache::lonlocal::texthash (
                   9418:                         id => 'Student/Employee ID',
1.20      raeburn  9419:                         permanentemail => 'E-mail address',
1.1       raeburn  9420:                         lastname => 'Last Name',
                   9421:                         firstname => 'First Name',
                   9422:                         middlename => 'Middle Name',
1.132     raeburn  9423:                         generation => 'Generation',
1.1       raeburn  9424:                       );
1.142     raeburn  9425:     $othertitle = &mt('All users');
1.1       raeburn  9426:     if (keys(%{$usertypes}) >  0) {
1.26      raeburn  9427:         $othertitle = &mt('Other users');
1.1       raeburn  9428:     }
                   9429:     foreach my $key (keys(%env)) {
                   9430:         if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132     raeburn  9431:             my ($usertype,$item) = ($1,$2);
                   9432:             if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
                   9433:                 if ($usertype eq 'default') {   
                   9434:                     push(@{$fields{$1}},$2);
                   9435:                 } elsif (ref($types) eq 'ARRAY') {
                   9436:                     if (grep(/^\Q$usertype\E$/,@{$types})) {
                   9437:                         push(@{$fields{$1}},$2);
                   9438:                     }
                   9439:                 }
                   9440:             }
1.1       raeburn  9441:         }
                   9442:     }
1.131     raeburn  9443:     my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
                   9444:     @lockablenames = sort(@lockablenames);
                   9445:     if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
                   9446:         my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
                   9447:         if (@changed) {
                   9448:             $changes{'lockablenames'} = 1;
                   9449:         }
                   9450:     } else {
                   9451:         if (@lockablenames) {
                   9452:             $changes{'lockablenames'} = 1;
                   9453:         }
                   9454:     }
1.1       raeburn  9455:     my %updatehash = (
                   9456:                       autoupdate => { run => $env{'form.autoupdate_run'},
                   9457:                                       classlists => $env{'form.classlists'},
                   9458:                                       fields => {%fields},
1.131     raeburn  9459:                                       lockablenames => \@lockablenames,
1.1       raeburn  9460:                                     }
                   9461:                      );
                   9462:     foreach my $key (keys(%currautoupdate)) {
                   9463:         if (($key eq 'run') || ($key eq 'classlists')) {
                   9464:             if (exists($updatehash{autoupdate}{$key})) {
                   9465:                 if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
                   9466:                     $changes{$key} = 1;
                   9467:                 }
                   9468:             }
                   9469:         } elsif ($key eq 'fields') {
                   9470:             if (ref($currautoupdate{$key}) eq 'HASH') {
1.26      raeburn  9471:                 foreach my $item (@{$types},'default') {
1.1       raeburn  9472:                     if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
                   9473:                         my $change = 0;
                   9474:                         foreach my $type (@{$currautoupdate{$key}{$item}}) {
                   9475:                             if (!exists($fields{$item})) {
                   9476:                                 $change = 1;
1.132     raeburn  9477:                                 last;
1.1       raeburn  9478:                             } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26      raeburn  9479:                                 if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1       raeburn  9480:                                     $change = 1;
1.132     raeburn  9481:                                     last;
1.1       raeburn  9482:                                 }
                   9483:                             }
                   9484:                         }
                   9485:                         if ($change) {
                   9486:                             push(@{$changes{$key}},$item);
                   9487:                         }
1.26      raeburn  9488:                     } 
1.1       raeburn  9489:                 }
                   9490:             }
1.131     raeburn  9491:         } elsif ($key eq 'lockablenames') {
                   9492:             if (ref($currautoupdate{$key}) eq 'ARRAY') {
                   9493:                 my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
                   9494:                 if (@changed) {
                   9495:                     $changes{'lockablenames'} = 1;
                   9496:                 }
                   9497:             } else {
                   9498:                 if (@lockablenames) {
                   9499:                     $changes{'lockablenames'} = 1;
                   9500:                 }
                   9501:             }
                   9502:         }
                   9503:     }
                   9504:     unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
                   9505:         if (@lockablenames) {
                   9506:             $changes{'lockablenames'} = 1;
1.1       raeburn  9507:         }
                   9508:     }
1.26      raeburn  9509:     foreach my $item (@{$types},'default') {
                   9510:         if (defined($fields{$item})) {
                   9511:             if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132     raeburn  9512:                 if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
                   9513:                     my $change = 0;
                   9514:                     if (ref($fields{$item}) eq 'ARRAY') {
                   9515:                         foreach my $type (@{$fields{$item}}) {
                   9516:                             if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
                   9517:                                 $change = 1;
                   9518:                                 last;
                   9519:                             }
                   9520:                         }
                   9521:                     }
                   9522:                     if ($change) {
                   9523:                         push(@{$changes{'fields'}},$item);
                   9524:                     }
                   9525:                 } else {
1.26      raeburn  9526:                     push(@{$changes{'fields'}},$item);
                   9527:                 }
                   9528:             } else {
                   9529:                 push(@{$changes{'fields'}},$item);
1.1       raeburn  9530:             }
                   9531:         }
                   9532:     }
                   9533:     my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
                   9534:                                              $dom);
                   9535:     if ($putresult eq 'ok') {
                   9536:         if (keys(%changes) > 0) {
                   9537:             $resulttext = &mt('Changes made:').'<ul>';
                   9538:             foreach my $key (sort(keys(%changes))) {
1.131     raeburn  9539:                 if ($key eq 'lockablenames') {
                   9540:                     $resulttext .= '<li>';
                   9541:                     if (@lockablenames) {
                   9542:                         $usertypes->{'default'} = $othertitle;
                   9543:                         $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
                   9544:                                    join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
                   9545:                     } else {
                   9546:                         $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
                   9547:                     }
                   9548:                     $resulttext .= '</li>';
                   9549:                 } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1       raeburn  9550:                     foreach my $item (@{$changes{$key}}) {
                   9551:                         my @newvalues;
                   9552:                         foreach my $type (@{$fields{$item}}) {
                   9553:                             push(@newvalues,$fieldtitles{$type});
                   9554:                         }
1.3       raeburn  9555:                         my $newvaluestr;
                   9556:                         if (@newvalues > 0) {
                   9557:                             $newvaluestr = join(', ',@newvalues);
                   9558:                         } else {
                   9559:                             $newvaluestr = &mt('none');
1.6       raeburn  9560:                         }
1.1       raeburn  9561:                         if ($item eq 'default') {
1.26      raeburn  9562:                             $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1       raeburn  9563:                         } else {
1.26      raeburn  9564:                             $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1       raeburn  9565:                         }
                   9566:                     }
                   9567:                 } else {
                   9568:                     my $newvalue;
                   9569:                     if ($key eq 'run') {
                   9570:                         $newvalue = $offon[$env{'form.autoupdate_run'}];
                   9571:                     } else {
                   9572:                         $newvalue = $offon[$env{'form.'.$key}];
1.3       raeburn  9573:                     }
1.1       raeburn  9574:                     $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
                   9575:                 }
                   9576:             }
                   9577:             $resulttext .= '</ul>';
                   9578:         } else {
1.3       raeburn  9579:             $resulttext = &mt('No changes made to autoupdates');
1.1       raeburn  9580:         }
                   9581:     } else {
1.11      albertel 9582:         $resulttext = '<span class="LC_error">'.
                   9583: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  9584:     }
1.3       raeburn  9585:     return $resulttext;
1.1       raeburn  9586: }
                   9587: 
1.125     raeburn  9588: sub modify_autocreate {
                   9589:     my ($dom,%domconfig) = @_;
                   9590:     my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
                   9591:     if (ref($domconfig{'autocreate'}) eq 'HASH') {
                   9592:         foreach my $key (keys(%{$domconfig{'autocreate'}})) {
                   9593:             $currautocreate{$key} = $domconfig{'autocreate'}{$key};
                   9594:         }
                   9595:     }
                   9596:     my %title= ( xml => 'Auto-creation of courses in XML course description files',
                   9597:                  req => 'Auto-creation of validated requests for official courses',
                   9598:                  xmldc => 'Identity of course creator of courses from XML files',
                   9599:                );
                   9600:     my @types = ('xml','req');
                   9601:     foreach my $item (@types) {
                   9602:         $newvals{$item} = $env{'form.autocreate_'.$item};
                   9603:         $newvals{$item} =~ s/\D//g;
                   9604:         $newvals{$item} = 0 if ($newvals{$item} eq '');
                   9605:     }
                   9606:     $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
                   9607:     my %domcoords = &get_active_dcs($dom);
                   9608:     unless (exists($domcoords{$newvals{'xmldc'}})) {
                   9609:         $newvals{'xmldc'} = '';
                   9610:     } 
                   9611:     %autocreatehash =  (
                   9612:                         autocreate => { xml => $newvals{'xml'},
                   9613:                                         req => $newvals{'req'},
                   9614:                                       }
                   9615:                        );
                   9616:     if ($newvals{'xmldc'} ne '') {
                   9617:         $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
                   9618:     }
                   9619:     my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
                   9620:                                              $dom);
                   9621:     if ($putresult eq 'ok') {
                   9622:         my @items = @types;
                   9623:         if ($newvals{'xml'}) {
                   9624:             push(@items,'xmldc');
                   9625:         }
                   9626:         foreach my $item (@items) {
                   9627:             if (exists($currautocreate{$item})) {
                   9628:                 if ($currautocreate{$item} ne $newvals{$item}) {
                   9629:                     $changes{$item} = 1;
                   9630:                 }
                   9631:             } elsif ($newvals{$item}) {
                   9632:                 $changes{$item} = 1;
                   9633:             }
                   9634:         }
                   9635:         if (keys(%changes) > 0) {
                   9636:             my @offon = ('off','on'); 
                   9637:             $resulttext = &mt('Changes made:').'<ul>';
                   9638:             foreach my $item (@types) {
                   9639:                 if ($changes{$item}) {
                   9640:                     my $newtxt = $offon[$newvals{$item}];
1.178     raeburn  9641:                     $resulttext .= '<li>'.
                   9642:                                    &mt("$title{$item} set to [_1]$newtxt [_2]",
                   9643:                                        '<b>','</b>').
                   9644:                                    '</li>';
1.125     raeburn  9645:                 }
                   9646:             }
                   9647:             if ($changes{'xmldc'}) {
                   9648:                 my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
                   9649:                 my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178     raeburn  9650:                 $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>'; 
1.125     raeburn  9651:             }
                   9652:             $resulttext .= '</ul>';
                   9653:         } else {
                   9654:             $resulttext = &mt('No changes made to auto-creation settings');
                   9655:         }
                   9656:     } else {
                   9657:         $resulttext = '<span class="LC_error">'.
                   9658:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   9659:     }
                   9660:     return $resulttext;
                   9661: }
                   9662: 
1.23      raeburn  9663: sub modify_directorysrch {
                   9664:     my ($dom,%domconfig) = @_;
                   9665:     my ($resulttext,%changes);
                   9666:     my %currdirsrch;
                   9667:     if (ref($domconfig{'directorysrch'}) eq 'HASH') {
                   9668:         foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
                   9669:             $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
                   9670:         }
                   9671:     }
1.277     raeburn  9672:     my %title = ( available => 'Institutional directory search available',
                   9673:                   localonly => 'Other domains can search institution',
                   9674:                   lcavailable => 'LON-CAPA directory search available',
                   9675:                   lclocalonly => 'Other domains can search LON-CAPA domain', 
1.23      raeburn  9676:                   searchby => 'Search types',
                   9677:                   searchtypes => 'Search latitude');
                   9678:     my @offon = ('off','on');
1.24      raeburn  9679:     my @otherdoms = ('Yes','No');
1.23      raeburn  9680: 
1.25      raeburn  9681:     my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');  
1.23      raeburn  9682:     my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
                   9683:     my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
                   9684: 
1.44      raeburn  9685:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26      raeburn  9686:     if (keys(%{$usertypes}) == 0) {
                   9687:         @cansearch = ('default');
                   9688:     } else {
                   9689:         if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
                   9690:             foreach my $type (@{$currdirsrch{'cansearch'}}) {
                   9691:                 if (!grep(/^\Q$type\E$/,@cansearch)) {
                   9692:                     push(@{$changes{'cansearch'}},$type);
                   9693:                 }
1.23      raeburn  9694:             }
1.26      raeburn  9695:             foreach my $type (@cansearch) {
                   9696:                 if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
                   9697:                     push(@{$changes{'cansearch'}},$type);
                   9698:                 }
1.23      raeburn  9699:             }
1.26      raeburn  9700:         } else {
                   9701:             push(@{$changes{'cansearch'}},@cansearch);
1.23      raeburn  9702:         }
                   9703:     }
                   9704: 
                   9705:     if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
                   9706:         foreach my $by (@{$currdirsrch{'searchby'}}) {
                   9707:             if (!grep(/^\Q$by\E$/,@searchby)) {
                   9708:                 push(@{$changes{'searchby'}},$by);
                   9709:             }
                   9710:         }
                   9711:         foreach my $by (@searchby) {
                   9712:             if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
                   9713:                 push(@{$changes{'searchby'}},$by);
                   9714:             }
                   9715:         }
                   9716:     } else {
                   9717:         push(@{$changes{'searchby'}},@searchby);
                   9718:     }
1.25      raeburn  9719: 
                   9720:     if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
                   9721:         foreach my $type (@{$currdirsrch{'searchtypes'}}) {
                   9722:             if (!grep(/^\Q$type\E$/,@searchtypes)) {
                   9723:                 push(@{$changes{'searchtypes'}},$type);
                   9724:             }
                   9725:         }
                   9726:         foreach my $type (@searchtypes) {
                   9727:             if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
                   9728:                 push(@{$changes{'searchtypes'}},$type);
                   9729:             }
                   9730:         }
                   9731:     } else {
                   9732:         if (exists($currdirsrch{'searchtypes'})) {
                   9733:             foreach my $type (@searchtypes) {  
                   9734:                 if ($type ne $currdirsrch{'searchtypes'}) { 
                   9735:                     push(@{$changes{'searchtypes'}},$type);
                   9736:                 }
                   9737:             }
                   9738:             if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
                   9739:                 push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
                   9740:             }   
                   9741:         } else {
                   9742:             push(@{$changes{'searchtypes'}},@searchtypes); 
                   9743:         }
                   9744:     }
                   9745: 
1.23      raeburn  9746:     my %dirsrch_hash =  (
                   9747:             directorysrch => { available => $env{'form.dirsrch_available'},
                   9748:                                cansearch => \@cansearch,
1.277     raeburn  9749:                                localonly => $env{'form.dirsrch_instlocalonly'},
                   9750:                                lclocalonly => $env{'form.dirsrch_domlocalonly'},
                   9751:                                lcavailable => $env{'form.dirsrch_domavailable'},
1.23      raeburn  9752:                                searchby => \@searchby,
1.25      raeburn  9753:                                searchtypes => \@searchtypes,
1.23      raeburn  9754:                              }
                   9755:             );
                   9756:     my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
                   9757:                                              $dom);
                   9758:     if ($putresult eq 'ok') {
                   9759:         if (exists($currdirsrch{'available'})) {
                   9760:              if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
                   9761:                  $changes{'available'} = 1;
                   9762:              }
                   9763:         } else {
                   9764:             if ($env{'form.dirsrch_available'} eq '1') {
                   9765:                 $changes{'available'} = 1;
                   9766:             }
                   9767:         }
1.277     raeburn  9768:         if (exists($currdirsrch{'lcavailable'})) {
                   9769:              if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
                   9770:                  $changes{'lcavailable'} = 1;
                   9771:              }
                   9772:         } else {
                   9773:             if ($env{'form.dirsrch_lcavailable'} eq '1') {
                   9774:                 $changes{'lcavailable'} = 1;
                   9775:             }
                   9776:         }
1.24      raeburn  9777:         if (exists($currdirsrch{'localonly'})) {
1.277     raeburn  9778:              if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
1.24      raeburn  9779:                  $changes{'localonly'} = 1;
                   9780:              }
                   9781:         } else {
1.277     raeburn  9782:             if ($env{'form.dirsrch_instlocalonly'} eq '1') {
1.24      raeburn  9783:                 $changes{'localonly'} = 1;
                   9784:             }
                   9785:         }
1.277     raeburn  9786:         if (exists($currdirsrch{'lclocalonly'})) {
                   9787:              if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
                   9788:                  $changes{'lclocalonly'} = 1;
                   9789:              }
                   9790:         } else {
                   9791:             if ($env{'form.dirsrch_domlocalonly'} eq '1') {
                   9792:                 $changes{'lclocalonly'} = 1;
                   9793:             }
                   9794:         }
1.23      raeburn  9795:         if (keys(%changes) > 0) {
                   9796:             $resulttext = &mt('Changes made:').'<ul>';
                   9797:             if ($changes{'available'}) {
                   9798:                 $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
                   9799:             }
1.277     raeburn  9800:             if ($changes{'lcavailable'}) {
                   9801:                 $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
                   9802:             }
1.24      raeburn  9803:             if ($changes{'localonly'}) {
1.277     raeburn  9804:                 $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
1.24      raeburn  9805:             }
1.277     raeburn  9806:             if ($changes{'lclocalonly'}) {
                   9807:                 $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
                   9808:             }   
1.23      raeburn  9809:             if (ref($changes{'cansearch'}) eq 'ARRAY') {
                   9810:                 my $chgtext;
1.26      raeburn  9811:                 if (ref($usertypes) eq 'HASH') {
                   9812:                     if (keys(%{$usertypes}) > 0) {
                   9813:                         foreach my $type (@{$types}) {
                   9814:                             if (grep(/^\Q$type\E$/,@cansearch)) {
                   9815:                                 $chgtext .= $usertypes->{$type}.'; ';
                   9816:                             }
                   9817:                         }
                   9818:                         if (grep(/^default$/,@cansearch)) {
                   9819:                             $chgtext .= $othertitle;
                   9820:                         } else {
                   9821:                             $chgtext =~ s/\; $//;
                   9822:                         }
1.210     raeburn  9823:                         $resulttext .=
1.178     raeburn  9824:                             '<li>'.
                   9825:                             &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
                   9826:                                 '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
                   9827:                             '</li>';
1.23      raeburn  9828:                     }
                   9829:                 }
                   9830:             }
                   9831:             if (ref($changes{'searchby'}) eq 'ARRAY') {
                   9832:                 my ($searchtitles,$titleorder) = &sorted_searchtitles();
                   9833:                 my $chgtext;
                   9834:                 foreach my $type (@{$titleorder}) {
                   9835:                     if (grep(/^\Q$type\E$/,@searchby)) {
                   9836:                         if (defined($searchtitles->{$type})) {
                   9837:                             $chgtext .= $searchtitles->{$type}.'; ';
                   9838:                         }
                   9839:                     }
                   9840:                 }
                   9841:                 $chgtext =~ s/\; $//;
                   9842:                 $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
                   9843:             }
1.25      raeburn  9844:             if (ref($changes{'searchtypes'}) eq 'ARRAY') {
                   9845:                 my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes(); 
                   9846:                 my $chgtext;
                   9847:                 foreach my $type (@{$srchtypeorder}) {
                   9848:                     if (grep(/^\Q$type\E$/,@searchtypes)) {
                   9849:                         if (defined($srchtypes_desc->{$type})) {
                   9850:                             $chgtext .= $srchtypes_desc->{$type}.'; ';
                   9851:                         }
                   9852:                     }
                   9853:                 }
                   9854:                 $chgtext =~ s/\; $//;
1.178     raeburn  9855:                 $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23      raeburn  9856:             }
                   9857:             $resulttext .= '</ul>';
                   9858:         } else {
1.277     raeburn  9859:             $resulttext = &mt('No changes made to directory search settings');
1.23      raeburn  9860:         }
                   9861:     } else {
                   9862:         $resulttext = '<span class="LC_error">'.
1.27      raeburn  9863:                       &mt('An error occurred: [_1]',$putresult).'</span>';
                   9864:     }
                   9865:     return $resulttext;
                   9866: }
                   9867: 
1.28      raeburn  9868: sub modify_contacts {
1.205     raeburn  9869:     my ($dom,$lastactref,%domconfig) = @_;
1.28      raeburn  9870:     my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
                   9871:     if (ref($domconfig{'contacts'}) eq 'HASH') {
                   9872:         foreach my $key (keys(%{$domconfig{'contacts'}})) {
                   9873:             $currsetting{$key} = $domconfig{'contacts'}{$key};
                   9874:         }
                   9875:     }
1.134     raeburn  9876:     my (%others,%to,%bcc);
1.28      raeburn  9877:     my @contacts = ('supportemail','adminemail');
1.102     raeburn  9878:     my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
1.203     raeburn  9879:                     'requestsmail','updatesmail','idconflictsmail');
                   9880:     my @toggles = ('reporterrors','reportupdates');
1.28      raeburn  9881:     foreach my $type (@mailings) {
                   9882:         @{$newsetting{$type}} = 
                   9883:             &Apache::loncommon::get_env_multiple('form.'.$type);
                   9884:         foreach my $item (@contacts) {
                   9885:             if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
                   9886:                 $contacts_hash{contacts}{$type}{$item} = 1;
                   9887:             } else {
                   9888:                 $contacts_hash{contacts}{$type}{$item} = 0;
                   9889:             }
                   9890:         }  
                   9891:         $others{$type} = $env{'form.'.$type.'_others'};
                   9892:         $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.134     raeburn  9893:         if ($type eq 'helpdeskmail') {
                   9894:             $bcc{$type} = $env{'form.'.$type.'_bcc'};
                   9895:             $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
                   9896:         }
1.28      raeburn  9897:     }
                   9898:     foreach my $item (@contacts) {
                   9899:         $to{$item} = $env{'form.'.$item};
                   9900:         $contacts_hash{'contacts'}{$item} = $to{$item};
                   9901:     }
1.203     raeburn  9902:     foreach my $item (@toggles) {
                   9903:         if ($env{'form.'.$item} =~ /^(0|1)$/) {
                   9904:             $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
                   9905:         }
                   9906:     }
1.28      raeburn  9907:     if (keys(%currsetting) > 0) {
                   9908:         foreach my $item (@contacts) {
                   9909:             if ($to{$item} ne $currsetting{$item}) {
                   9910:                 $changes{$item} = 1;
                   9911:             }
                   9912:         }
                   9913:         foreach my $type (@mailings) {
                   9914:             foreach my $item (@contacts) {
                   9915:                 if (ref($currsetting{$type}) eq 'HASH') {
                   9916:                     if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
                   9917:                         push(@{$changes{$type}},$item);
                   9918:                     }
                   9919:                 } else {
                   9920:                     push(@{$changes{$type}},@{$newsetting{$type}});
                   9921:                 }
                   9922:             }
                   9923:             if ($others{$type} ne $currsetting{$type}{'others'}) {
                   9924:                 push(@{$changes{$type}},'others');
                   9925:             }
1.134     raeburn  9926:             if ($type eq 'helpdeskmail') {   
                   9927:                 if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
                   9928:                     push(@{$changes{$type}},'bcc'); 
                   9929:                 }
                   9930:             }
1.28      raeburn  9931:         }
                   9932:     } else {
                   9933:         my %default;
                   9934:         $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
                   9935:         $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
                   9936:         $default{'errormail'} = 'adminemail';
                   9937:         $default{'packagesmail'} = 'adminemail';
                   9938:         $default{'helpdeskmail'} = 'supportemail';
1.89      raeburn  9939:         $default{'lonstatusmail'} = 'adminemail';
1.102     raeburn  9940:         $default{'requestsmail'} = 'adminemail';
1.190     raeburn  9941:         $default{'updatesmail'} = 'adminemail';
1.28      raeburn  9942:         foreach my $item (@contacts) {
                   9943:            if ($to{$item} ne $default{$item}) {
                   9944:               $changes{$item} = 1;
1.203     raeburn  9945:            }
1.28      raeburn  9946:         }
                   9947:         foreach my $type (@mailings) {
                   9948:             if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
                   9949:                
                   9950:                 push(@{$changes{$type}},@{$newsetting{$type}});
                   9951:             }
                   9952:             if ($others{$type} ne '') {
                   9953:                 push(@{$changes{$type}},'others');
1.134     raeburn  9954:             }
                   9955:             if ($type eq 'helpdeskmail') {
                   9956:                 if ($bcc{$type} ne '') {
                   9957:                     push(@{$changes{$type}},'bcc');
                   9958:                 }
                   9959:             }
1.28      raeburn  9960:         }
                   9961:     }
1.203     raeburn  9962:     foreach my $item (@toggles) {
                   9963:         if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
                   9964:             $changes{$item} = 1;
                   9965:         } elsif ((!$env{'form.'.$item}) &&
                   9966:                  (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
                   9967:             $changes{$item} = 1;
                   9968:         }
                   9969:     }
1.28      raeburn  9970:     my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
                   9971:                                              $dom);
                   9972:     if ($putresult eq 'ok') {
                   9973:         if (keys(%changes) > 0) {
1.205     raeburn  9974:             &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212     raeburn  9975:             if (ref($lastactref) eq 'HASH') {
                   9976:                 $lastactref->{'domainconfig'} = 1;
                   9977:             }
1.28      raeburn  9978:             my ($titles,$short_titles)  = &contact_titles();
                   9979:             $resulttext = &mt('Changes made:').'<ul>';
                   9980:             foreach my $item (@contacts) {
                   9981:                 if ($changes{$item}) {
                   9982:                     $resulttext .= '<li>'.$titles->{$item}.
                   9983:                                     &mt(' set to: ').
                   9984:                                     '<span class="LC_cusr_emph">'.
                   9985:                                     $to{$item}.'</span></li>';
                   9986:                 }
                   9987:             }
                   9988:             foreach my $type (@mailings) {
                   9989:                 if (ref($changes{$type}) eq 'ARRAY') {
                   9990:                     $resulttext .= '<li>'.$titles->{$type}.': ';
                   9991:                     my @text;
                   9992:                     foreach my $item (@{$newsetting{$type}}) {
                   9993:                         push(@text,$short_titles->{$item});
                   9994:                     }
                   9995:                     if ($others{$type} ne '') {
                   9996:                         push(@text,$others{$type});
                   9997:                     }
                   9998:                     $resulttext .= '<span class="LC_cusr_emph">'.
1.134     raeburn  9999:                                    join(', ',@text).'</span>';
                   10000:                     if ($type eq 'helpdeskmail') {
                   10001:                         if ($bcc{$type} ne '') {
                   10002:                             $resulttext .= '&nbsp;'.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
                   10003:                         }
                   10004:                     }
                   10005:                     $resulttext .= '</li>';
1.28      raeburn  10006:                 }
                   10007:             }
1.203     raeburn  10008:             my @offon = ('off','on');
                   10009:             if ($changes{'reporterrors'}) {
                   10010:                 $resulttext .= '<li>'.
                   10011:                                &mt('E-mail error reports to [_1] set to "'.
                   10012:                                    $offon[$env{'form.reporterrors'}].'".',
                   10013:                                    &Apache::loncommon::modal_link('http://loncapa.org/core.html',
                   10014:                                        &mt('LON-CAPA core group - MSU'),600,500)).
                   10015:                                '</li>';
                   10016:             }
                   10017:             if ($changes{'reportupdates'}) {
                   10018:                 $resulttext .= '<li>'.
                   10019:                                 &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
                   10020:                                     $offon[$env{'form.reportupdates'}].'".',
                   10021:                                     &Apache::loncommon::modal_link('http://loncapa.org/core.html',
                   10022:                                         &mt('LON-CAPA core group - MSU'),600,500)).
                   10023:                                 '</li>';
                   10024:             }
1.28      raeburn  10025:             $resulttext .= '</ul>';
                   10026:         } else {
1.34      raeburn  10027:             $resulttext = &mt('No changes made to contact information');
1.28      raeburn  10028:         }
                   10029:     } else {
                   10030:         $resulttext = '<span class="LC_error">'.
                   10031:             &mt('An error occurred: [_1].',$putresult).'</span>';
                   10032:     }
                   10033:     return $resulttext;
                   10034: }
                   10035: 
                   10036: sub modify_usercreation {
1.27      raeburn  10037:     my ($dom,%domconfig) = @_;
1.224     raeburn  10038:     my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43      raeburn  10039:     my $warningmsg;
1.27      raeburn  10040:     if (ref($domconfig{'usercreation'}) eq 'HASH') {
                   10041:         foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224     raeburn  10042:             if ($key eq 'cancreate') {
                   10043:                 if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
                   10044:                     foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
                   10045:                         if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.269     raeburn  10046:                             ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
                   10047:                             ($item eq 'recaptchaversion')) {
1.224     raeburn  10048:                             $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
                   10049:                         } else {
                   10050:                             $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
                   10051:                         }
                   10052:                     }
                   10053:                 }
                   10054:             } elsif ($key eq 'email_rule') {
                   10055:                 $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
                   10056:             } else {
                   10057:                 $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
                   10058:             }
1.27      raeburn  10059:         }
                   10060:     }
                   10061:     my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32      raeburn  10062:     my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224     raeburn  10063:     my @contexts = ('author','course','requestcrs');
1.34      raeburn  10064:     foreach my $item(@contexts) {
1.224     raeburn  10065:         $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93      raeburn  10066:     }
1.34      raeburn  10067:     if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
                   10068:         foreach my $item (@contexts) {
1.224     raeburn  10069:             if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
                   10070:                 push(@{$changes{'cancreate'}},$item);
1.50      raeburn  10071:             }
1.27      raeburn  10072:         }
1.34      raeburn  10073:     } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
                   10074:         foreach my $item (@contexts) {
1.43      raeburn  10075:             if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34      raeburn  10076:                 if ($cancreate{$item} ne 'any') {
                   10077:                     push(@{$changes{'cancreate'}},$item);
                   10078:                 }
                   10079:             } else {
                   10080:                 if ($cancreate{$item} ne 'none') {
                   10081:                     push(@{$changes{'cancreate'}},$item);
                   10082:                 }
1.27      raeburn  10083:             }
                   10084:         }
                   10085:     } else {
1.43      raeburn  10086:         foreach my $item (@contexts)  {
1.34      raeburn  10087:             push(@{$changes{'cancreate'}},$item);
                   10088:         }
1.27      raeburn  10089:     }
1.34      raeburn  10090: 
1.27      raeburn  10091:     if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
                   10092:         foreach my $type (@{$curr_usercreation{'username_rule'}}) {
                   10093:             if (!grep(/^\Q$type\E$/,@username_rule)) {
                   10094:                 push(@{$changes{'username_rule'}},$type);
                   10095:             }
                   10096:         }
                   10097:         foreach my $type (@username_rule) {
                   10098:             if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
                   10099:                 push(@{$changes{'username_rule'}},$type);
                   10100:             }
                   10101:         }
                   10102:     } else {
                   10103:         push(@{$changes{'username_rule'}},@username_rule);
                   10104:     }
                   10105: 
1.32      raeburn  10106:     if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
                   10107:         foreach my $type (@{$curr_usercreation{'id_rule'}}) {
                   10108:             if (!grep(/^\Q$type\E$/,@id_rule)) {
                   10109:                 push(@{$changes{'id_rule'}},$type);
                   10110:             }
                   10111:         }
                   10112:         foreach my $type (@id_rule) {
                   10113:             if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
                   10114:                 push(@{$changes{'id_rule'}},$type);
                   10115:             }
                   10116:         }
                   10117:     } else {
                   10118:         push(@{$changes{'id_rule'}},@id_rule);
                   10119:     }
                   10120: 
1.43      raeburn  10121:     my @authen_contexts = ('author','course','domain');
1.28      raeburn  10122:     my @authtypes = ('int','krb4','krb5','loc');
                   10123:     my %authhash;
1.43      raeburn  10124:     foreach my $item (@authen_contexts) {
1.28      raeburn  10125:         my @authallowed =  &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
                   10126:         foreach my $auth (@authtypes) {
                   10127:             if (grep(/^\Q$auth\E$/,@authallowed)) {
                   10128:                 $authhash{$item}{$auth} = 1;
                   10129:             } else {
                   10130:                 $authhash{$item}{$auth} = 0;
                   10131:             }
                   10132:         }
                   10133:     }
                   10134:     if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43      raeburn  10135:         foreach my $item (@authen_contexts) {
1.28      raeburn  10136:             if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
                   10137:                 foreach my $auth (@authtypes) {
                   10138:                     if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
                   10139:                         push(@{$changes{'authtypes'}},$item);
                   10140:                         last;
                   10141:                     }
                   10142:                 }
                   10143:             }
                   10144:         }
                   10145:     } else {
1.43      raeburn  10146:         foreach my $item (@authen_contexts) {
1.28      raeburn  10147:             push(@{$changes{'authtypes'}},$item);
                   10148:         }
                   10149:     }
                   10150: 
1.224     raeburn  10151:     $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'}; 
                   10152:     $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
                   10153:     $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
                   10154:     $save_usercreate{'id_rule'} = \@id_rule;
                   10155:     $save_usercreate{'username_rule'} = \@username_rule,
                   10156:     $save_usercreate{'authtypes'} = \%authhash;
                   10157: 
1.27      raeburn  10158:     my %usercreation_hash =  (
1.224     raeburn  10159:         usercreation     => \%save_usercreate,
                   10160:     );
1.27      raeburn  10161: 
                   10162:     my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
                   10163:                                              $dom);
1.50      raeburn  10164: 
1.224     raeburn  10165:     if ($putresult eq 'ok') {
                   10166:         if (keys(%changes) > 0) {
                   10167:             $resulttext = &mt('Changes made:').'<ul>';
                   10168:             if (ref($changes{'cancreate'}) eq 'ARRAY') {
                   10169:                 my %lt = &usercreation_types();
                   10170:                 foreach my $type (@{$changes{'cancreate'}}) {
                   10171:                     my $chgtext = $lt{$type}.', ';
                   10172:                     if ($cancreate{$type} eq 'none') {
                   10173:                         $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
                   10174:                     } elsif ($cancreate{$type} eq 'any') {
                   10175:                         $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
                   10176:                     } elsif ($cancreate{$type} eq 'official') {
                   10177:                         $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
                   10178:                     } elsif ($cancreate{$type} eq 'unofficial') {
                   10179:                         $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
                   10180:                     }
                   10181:                     $resulttext .= '<li>'.$chgtext.'</li>';
                   10182:                 }
                   10183:             }
                   10184:             if (ref($changes{'username_rule'}) eq 'ARRAY') {
                   10185:                 my ($rules,$ruleorder) = 
                   10186:                     &Apache::lonnet::inst_userrules($dom,'username');
                   10187:                 my $chgtext = '<ul>';
                   10188:                 foreach my $type (@username_rule) {
                   10189:                     if (ref($rules->{$type}) eq 'HASH') {
                   10190:                         $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
                   10191:                     }
                   10192:                 }
                   10193:                 $chgtext .= '</ul>';
                   10194:                 if (@username_rule > 0) {
                   10195:                     $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';     
                   10196:                 } else {
                   10197:                     $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>'; 
                   10198:                 }
                   10199:             }
                   10200:             if (ref($changes{'id_rule'}) eq 'ARRAY') {
                   10201:                 my ($idrules,$idruleorder) = 
                   10202:                     &Apache::lonnet::inst_userrules($dom,'id');
                   10203:                 my $chgtext = '<ul>';
                   10204:                 foreach my $type (@id_rule) {
                   10205:                     if (ref($idrules->{$type}) eq 'HASH') {
                   10206:                         $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
                   10207:                     }
                   10208:                 }
                   10209:                 $chgtext .= '</ul>';
                   10210:                 if (@id_rule > 0) {
                   10211:                     $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
                   10212:                 } else {
                   10213:                     $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
                   10214:                 }
                   10215:             }
                   10216:             my %authname = &authtype_names();
                   10217:             my %context_title = &context_names();
                   10218:             if (ref($changes{'authtypes'}) eq 'ARRAY') {
                   10219:                 my $chgtext = '<ul>';
                   10220:                 foreach my $type (@{$changes{'authtypes'}}) {
                   10221:                     my @allowed;
                   10222:                     $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
                   10223:                     foreach my $auth (@authtypes) {
                   10224:                         if ($authhash{$type}{$auth}) {
                   10225:                             push(@allowed,$authname{$auth});
                   10226:                         }
                   10227:                     }
                   10228:                     if (@allowed > 0) {
                   10229:                         $chgtext .= join(', ',@allowed).'</li>';
                   10230:                     } else {
                   10231:                         $chgtext .= &mt('none').'</li>';
                   10232:                     }
                   10233:                 }
                   10234:                 $chgtext .= '</ul>';
                   10235:                 $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
                   10236:                 $resulttext .= '</li>';
                   10237:             }
                   10238:             $resulttext .= '</ul>';
                   10239:         } else {
                   10240:             $resulttext = &mt('No changes made to user creation settings');
                   10241:         }
                   10242:     } else {
                   10243:         $resulttext = '<span class="LC_error">'.
                   10244:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   10245:     }
                   10246:     if ($warningmsg ne '') {
                   10247:         $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
                   10248:     }
                   10249:     return $resulttext;
                   10250: }
                   10251: 
                   10252: sub modify_selfcreation {
                   10253:     my ($dom,%domconfig) = @_;
                   10254:     my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%changes,%cancreate);
                   10255:     my (%save_usercreate,%save_usermodify);
1.228     raeburn  10256:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   10257:     if (ref($types) eq 'ARRAY') {
                   10258:         $usertypes->{'default'} = $othertitle;
                   10259:         push(@{$types},'default');
                   10260:     }
1.224     raeburn  10261: #
                   10262: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
                   10263: #
                   10264:     if (ref($domconfig{'usercreation'}) eq 'HASH') {
                   10265:         foreach my $key (keys(%{$domconfig{'usercreation'}})) {
                   10266:             if ($key eq 'cancreate') {
                   10267:                 if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
                   10268:                     foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
                   10269:                         if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
                   10270:                             ($item eq 'captcha') || ($item eq 'recaptchakeys') || 
1.269     raeburn  10271:                             ($item eq 'recaptchaversion') ||
1.236     raeburn  10272:                             ($item eq 'emailusername') || ($item eq 'notify') ||
1.240     raeburn  10273:                             ($item eq 'selfcreateprocessing') || ($item eq 'shibenv')) {
1.224     raeburn  10274:                             $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
                   10275:                         } else {
                   10276:                             $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
                   10277:                         }
                   10278:                     }
                   10279:                 }
                   10280:             } elsif ($key eq 'email_rule') {
                   10281:                 $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
                   10282:             } else {
                   10283:                 $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
                   10284:             }
                   10285:         }
                   10286:     }
                   10287: #
                   10288: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
                   10289: #
                   10290:     if (ref($domconfig{'usermodification'}) eq 'HASH') {
                   10291:         foreach my $key (keys(%{$domconfig{'usermodification'}})) {
                   10292:             if ($key eq 'selfcreate') {
                   10293:                 $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
                   10294:             } else {
                   10295:                 $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
                   10296:             }
                   10297:         }
                   10298:     }
                   10299: 
                   10300:     my @contexts = ('selfcreate');
                   10301:     @{$cancreate{'selfcreate'}} = ();
                   10302:     %{$cancreate{'emailusername'}} = ();
                   10303:     @{$cancreate{'statustocreate'}} = ();
1.236     raeburn  10304:     %{$cancreate{'selfcreateprocessing'}} = ();
1.240     raeburn  10305:     %{$cancreate{'shibenv'}} = ();
1.50      raeburn  10306:     my %selfcreatetypes = (
                   10307:                              sso   => 'users authenticated by institutional single sign on',
                   10308:                              login => 'users authenticated by institutional log-in',
1.236     raeburn  10309:                              email => 'users who provide a valid e-mail address for use as username',
1.50      raeburn  10310:                           );
1.224     raeburn  10311: #
                   10312: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
                   10313: # is permitted.
                   10314: #
1.236     raeburn  10315: 
                   10316:     my @statuses;
                   10317:     if (ref($domconfig{'inststatus'}) eq 'HASH') {
                   10318:         if (ref($domconfig{'inststatus'}{'inststatusguest'}) eq 'ARRAY') {
                   10319:             @statuses = @{$domconfig{'inststatus'}{'inststatusguest'}};
                   10320:         }
                   10321:     }
                   10322:     push(@statuses,'default');
                   10323: 
1.228     raeburn  10324:     foreach my $item ('login','sso','email') {
1.224     raeburn  10325:         if ($item eq 'email') {
1.236     raeburn  10326:             if ($env{'form.cancreate_email'}) {
1.224     raeburn  10327:                 push(@{$cancreate{'selfcreate'}},'email');
1.236     raeburn  10328:                 push(@contexts,'selfcreateprocessing');
                   10329:                 foreach my $type (@statuses) {
                   10330:                     if ($type eq 'default') {
                   10331:                         $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess'};
                   10332:                     } else { 
                   10333:                         $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
                   10334:                     }
                   10335:                 }
1.224     raeburn  10336:             }
                   10337:         } else {
                   10338:             if ($env{'form.cancreate_'.$item}) {
                   10339:                 push(@{$cancreate{'selfcreate'}},$item);
                   10340:             }
                   10341:         }
                   10342:     }
                   10343:     my (@email_rule,%userinfo,%savecaptcha);
                   10344:     my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
                   10345: #
1.228     raeburn  10346: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
                   10347: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.224     raeburn  10348: #
1.236     raeburn  10349: 
1.244     raeburn  10350:     if ($env{'form.cancreate_email'}) {
1.228     raeburn  10351:         push(@contexts,'emailusername');
                   10352:         if (ref($types) eq 'ARRAY') {
                   10353:             foreach my $type (@{$types}) {
                   10354:                 if (ref($infofields) eq 'ARRAY') {
                   10355:                     foreach my $field (@{$infofields}) {
                   10356:                         if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
                   10357:                             $cancreate{'emailusername'}{$type}{$field} = $1;
                   10358:                         }
                   10359:                     }
1.224     raeburn  10360:                 }
                   10361:             }
                   10362:         }
                   10363: #
                   10364: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
                   10365: # queued requests for self-creation of account using e-mail address as username
                   10366: #
                   10367: 
                   10368:         my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
                   10369:         @approvalnotify = sort(@approvalnotify);
                   10370:         $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
                   10371:         if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
                   10372:             if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
                   10373:                 if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
                   10374:                     push(@{$changes{'cancreate'}},'notify');
                   10375:                 }
                   10376:             } else {
                   10377:                 if ($cancreate{'notify'}{'approval'}) {
                   10378:                     push(@{$changes{'cancreate'}},'notify');
                   10379:                 }
                   10380:             }
                   10381:         } elsif ($cancreate{'notify'}{'approval'}) {
                   10382:             push(@{$changes{'cancreate'}},'notify');
                   10383:         }
                   10384: 
                   10385: #
                   10386: # Retrieve rules (if any) governing types of e-mail address which may be used as a username
                   10387: #
                   10388:         @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
                   10389:         &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
                   10390:         if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
                   10391:             if (@{$curr_usercreation{'email_rule'}} > 0) {
                   10392:                 foreach my $type (@{$curr_usercreation{'email_rule'}}) {
                   10393:                     if (!grep(/^\Q$type\E$/,@email_rule)) {
                   10394:                         push(@{$changes{'email_rule'}},$type);
                   10395:                     }
                   10396:                 }
                   10397:             }
                   10398:             if (@email_rule > 0) {
                   10399:                 foreach my $type (@email_rule) {
                   10400:                     if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
                   10401:                         push(@{$changes{'email_rule'}},$type);
                   10402:                     }
                   10403:                 }
                   10404:             }
                   10405:         } elsif (@email_rule > 0) {
                   10406:             push(@{$changes{'email_rule'}},@email_rule);
                   10407:         }
                   10408:     }
                   10409: #  
1.236     raeburn  10410: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.224     raeburn  10411: # institutional log-in.
                   10412: #
                   10413:     if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
                   10414:         my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
                   10415:         if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) || 
                   10416:                ($domdefaults{'auth_def'} eq 'localauth'))) {
                   10417:             $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.').' '.
                   10418:                           &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.');
                   10419:         }
                   10420:     }
                   10421:     my @fields = ('lastname','firstname','middlename','generation',
                   10422:                   'permanentemail','id');
1.240     raeburn  10423:     my @shibfields = (@fields,'inststatus');
1.224     raeburn  10424:     my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
                   10425: #
                   10426: # Where usernames may created for institutional log-in and/or institutional single sign on:
                   10427: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
                   10428: # may self-create accounts 
                   10429: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
                   10430: # which the user may supply, if institutional data is unavailable.
                   10431: #
                   10432:     if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
                   10433:         if (ref($types) eq 'ARRAY') {
1.228     raeburn  10434:             if (@{$types} > 1) {
1.224     raeburn  10435:                 @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
                   10436:                 push(@contexts,'statustocreate');
                   10437:             } else {
                   10438:                 undef($cancreate{'statustocreate'});
                   10439:             } 
                   10440:             foreach my $type (@{$types}) {
                   10441:                 my @modifiable =  &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
                   10442:                 foreach my $field (@fields) {
                   10443:                     if (grep(/^\Q$field\E$/,@modifiable)) {
                   10444:                         $save_usermodify{'selfcreate'}{$type}{$field} = 1;
                   10445:                     } else {
                   10446:                         $save_usermodify{'selfcreate'}{$type}{$field} = 0;
                   10447:                     }
                   10448:                 }
                   10449:             }
                   10450:             if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
                   10451:                 foreach my $type (@{$types}) {
                   10452:                     if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
                   10453:                         foreach my $field (@fields) {
                   10454:                             if ($save_usermodify{'selfcreate'}{$type}{$field} ne
                   10455:                                 $curr_usermodify{'selfcreate'}{$type}{$field}) {
                   10456:                                 push(@{$changes{'selfcreate'}},$type);
                   10457:                                 last;
                   10458:                             }
                   10459:                         }
                   10460:                     }
                   10461:                 }
                   10462:             } else {
                   10463:                 foreach my $type (@{$types}) {
                   10464:                     push(@{$changes{'selfcreate'}},$type);
                   10465:                 }
                   10466:             }
                   10467:         }
1.240     raeburn  10468:         foreach my $field (@shibfields) {
                   10469:             if ($env{'form.shibenv_'.$field} ne '') {
                   10470:                 $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
                   10471:             }
                   10472:         }
                   10473:         if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
                   10474:             if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
                   10475:                 foreach my $field (@shibfields) {
                   10476:                     if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
                   10477:                         push(@{$changes{'cancreate'}},'shibenv');
                   10478:                     }
                   10479:                 }
                   10480:             } else {
                   10481:                 foreach my $field (@shibfields) {
                   10482:                     if ($env{'form.shibenv_'.$field}) {
                   10483:                         push(@{$changes{'cancreate'}},'shibenv');
                   10484:                         last;
                   10485:                     }
                   10486:                 }
                   10487:             }
                   10488:         }
1.224     raeburn  10489:     }
                   10490:     foreach my $item (@contexts) {
                   10491:         if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
                   10492:             foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
                   10493:                 if (ref($cancreate{$item}) eq 'ARRAY') {
                   10494:                     if (!grep(/^$curr$/,@{$cancreate{$item}})) {
                   10495:                         if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   10496:                             push(@{$changes{'cancreate'}},$item);
                   10497:                         }
                   10498:                     }
                   10499:                 }
                   10500:             }
                   10501:             if (ref($cancreate{$item}) eq 'ARRAY') {
                   10502:                 foreach my $type (@{$cancreate{$item}}) {
                   10503:                     if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
                   10504:                         if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   10505:                             push(@{$changes{'cancreate'}},$item);
                   10506:                         }
                   10507:                     }
                   10508:                 }
                   10509:             }
                   10510:         } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
                   10511:             if (ref($cancreate{$item}) eq 'HASH') {
                   10512:                 foreach my $curr (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
1.228     raeburn  10513:                     if (ref($curr_usercreation{'cancreate'}{$item}{$curr}) eq 'HASH') {
                   10514:                         foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$curr}})) {
                   10515:                             unless ($curr_usercreation{'cancreate'}{$item}{$curr}{$field} eq $cancreate{$item}{$curr}{$field}) {
                   10516:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   10517:                                     push(@{$changes{'cancreate'}},$item);
                   10518:                                 }
                   10519:                             }
                   10520:                         }
1.236     raeburn  10521:                     } elsif ($item eq 'selfcreateprocessing') {
                   10522:                         if ($cancreate{$item}{$curr} ne $curr_usercreation{'cancreate'}{$item}{$curr}) {
                   10523:                             if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   10524:                                 push(@{$changes{'cancreate'}},$item);
                   10525:                             }
                   10526:                         }
1.228     raeburn  10527:                     } else {
                   10528:                         if (!$cancreate{$item}{$curr}) {
                   10529:                             if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   10530:                                 push(@{$changes{'cancreate'}},$item);
                   10531:                             }
1.224     raeburn  10532:                         }
                   10533:                     }
                   10534:                 }
                   10535:                 foreach my $field (keys(%{$cancreate{$item}})) {
1.228     raeburn  10536:                     if (ref($cancreate{$item}{$field}) eq 'HASH') {
                   10537:                         foreach my $inner (keys(%{$cancreate{$item}{$field}})) {
                   10538:                             if (ref($curr_usercreation{'cancreate'}{$item}{$field}) eq 'HASH') {
                   10539:                                 unless ($curr_usercreation{'cancreate'}{$item}{$field}{$inner} eq $cancreate{$item}{$field}{$inner}) {
                   10540:                                     if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   10541:                                         push(@{$changes{'cancreate'}},$item);
                   10542:                                     }
                   10543:                                 }
                   10544:                             } else {
                   10545:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   10546:                                     push(@{$changes{'cancreate'}},$item);
                   10547:                                 }
                   10548:                             }
                   10549:                         }
1.236     raeburn  10550:                     } elsif ($item eq 'selfcreateprocessing') {
                   10551:                         if ($cancreate{$item}{$field} ne $curr_usercreation{'cancreate'}{$item}{$field}) {
                   10552:                             if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   10553:                                 push(@{$changes{'cancreate'}},$item);
                   10554:                             }
                   10555:                         }
1.228     raeburn  10556:                     } else {
                   10557:                         if (!$curr_usercreation{'cancreate'}{$item}{$field}) {
                   10558:                             if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   10559:                                 push(@{$changes{'cancreate'}},$item);
                   10560:                             }
1.224     raeburn  10561:                         }
                   10562:                     }
                   10563:                 }
                   10564:             }
                   10565:         } elsif ($curr_usercreation{'cancreate'}{$item}) {
                   10566:             if (ref($cancreate{$item}) eq 'ARRAY') {
                   10567:                 if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
                   10568:                     if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   10569:                         push(@{$changes{'cancreate'}},$item);
                   10570:                     }
                   10571:                 }
                   10572:             } elsif (ref($cancreate{$item}) eq 'HASH') {
                   10573:                 if (!$cancreate{$item}{$curr_usercreation{'cancreate'}{$item}}) {
                   10574:                     if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   10575:                         push(@{$changes{'cancreate'}},$item);
                   10576:                     }
                   10577:                 }
                   10578:             }
                   10579:         } elsif ($item eq 'emailusername') {
1.228     raeburn  10580:             if (ref($cancreate{$item}) eq 'HASH') {
                   10581:                 foreach my $type (keys(%{$cancreate{$item}})) {
                   10582:                     if (ref($cancreate{$item}{$type}) eq 'HASH') {
                   10583:                         foreach my $field (keys(%{$cancreate{$item}{$type}})) {
                   10584:                             if ($cancreate{$item}{$type}{$field}) {
                   10585:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   10586:                                     push(@{$changes{'cancreate'}},$item);
                   10587:                                 }
                   10588:                                 last;
                   10589:                             }
                   10590:                         }
                   10591:                     }
                   10592:                 }
1.224     raeburn  10593:             }
                   10594:         }
                   10595:     }
                   10596: #
                   10597: # Populate %save_usercreate hash with updates to self-creation configuration.
                   10598: #
                   10599:     $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
                   10600:     $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.269     raeburn  10601:     $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.224     raeburn  10602:     $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
                   10603:     if (ref($cancreate{'notify'}) eq 'HASH') {
                   10604:         $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
                   10605:     }
1.236     raeburn  10606:     if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
                   10607:         $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
                   10608:     }
1.224     raeburn  10609:     if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
                   10610:         $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
                   10611:     }
1.240     raeburn  10612:     if (ref($cancreate{'shibenv'}) eq 'HASH') {
                   10613:         $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
                   10614:     }
1.224     raeburn  10615:     $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
                   10616:     $save_usercreate{'emailrule'} = \@email_rule;
                   10617: 
                   10618:     my %userconfig_hash = (
                   10619:             usercreation     => \%save_usercreate,
                   10620:             usermodification => \%save_usermodify,
                   10621:     );
                   10622:     my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
                   10623:                                              $dom);
                   10624: #
                   10625: # Accumulate details of changes to domain cofiguration for self-creation of usernames in $resulttext
                   10626: #
1.27      raeburn  10627:     if ($putresult eq 'ok') {
                   10628:         if (keys(%changes) > 0) {
                   10629:             $resulttext = &mt('Changes made:').'<ul>';
                   10630:             if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224     raeburn  10631:                 my %lt = &selfcreation_types();
1.34      raeburn  10632:                 foreach my $type (@{$changes{'cancreate'}}) {
1.100     raeburn  10633:                     my $chgtext;
1.45      raeburn  10634:                     if ($type eq 'selfcreate') {
1.50      raeburn  10635:                         if (@{$cancreate{$type}} == 0) {
1.224     raeburn  10636:                             $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50      raeburn  10637:                         } else {
1.224     raeburn  10638:                             $chgtext .= &mt('Self-creation of a new account is permitted for:').
                   10639:                                         '<ul>';
1.50      raeburn  10640:                             foreach my $case (@{$cancreate{$type}}) {
                   10641:                                 $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
                   10642:                             }
                   10643:                             $chgtext .= '</ul>';
1.100     raeburn  10644:                             if (ref($cancreate{$type}) eq 'ARRAY') {
                   10645:                                 if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
                   10646:                                     if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
                   10647:                                         if (@{$cancreate{'statustocreate'}} == 0) {
1.224     raeburn  10648:                                             $chgtext .= '<br />'.
                   10649:                                                         '<span class="LC_warning">'.
                   10650:                                                         &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
                   10651:                                                         '</span>';
1.100     raeburn  10652:                                         }
                   10653:                                     }
                   10654:                                 }
                   10655:                             }
1.43      raeburn  10656:                         }
1.240     raeburn  10657:                     } elsif ($type eq 'shibenv') {
                   10658:                         if (keys(%{$cancreate{$type}}) == 0) {
                   10659:                             $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information'); 
                   10660:                         } else {
                   10661:                             $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
                   10662:                                         '<ul>';
                   10663:                             foreach my $field (@shibfields) {
                   10664:                                 next if ($cancreate{$type}{$field} eq '');
                   10665:                                 if ($field eq 'inststatus') {
                   10666:                                     $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
                   10667:                                 } else {
                   10668:                                     $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
                   10669:                                 }
                   10670:                             }
                   10671:                             $chgtext .= '</ul>';
                   10672:                         }  
1.93      raeburn  10673:                     } elsif ($type eq 'statustocreate') {
1.96      raeburn  10674:                         if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
                   10675:                             (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
                   10676:                             if (@{$cancreate{'selfcreate'}} > 0) {
                   10677:                                 if (@{$cancreate{'statustocreate'}} == 0) {
1.100     raeburn  10678:                                     $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96      raeburn  10679:                                     if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224     raeburn  10680:                                         $chgtext .= '<br />'.
                   10681:                                                     '<span class="LC_warning">'.
                   10682:                                                     &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
                   10683:                                                     '</span>';
                   10684:                                     }
1.96      raeburn  10685:                                 } elsif (ref($usertypes) eq 'HASH') {
                   10686:                                     if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100     raeburn  10687:                                         $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
                   10688:                                     } else {
                   10689:                                         $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
                   10690:                                     }
                   10691:                                     $chgtext .= '<ul>';
                   10692:                                     foreach my $case (@{$cancreate{$type}}) {
                   10693:                                         if ($case eq 'default') {
                   10694:                                             $chgtext .= '<li>'.$othertitle.'</li>';
                   10695:                                         } else {
                   10696:                                             $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93      raeburn  10697:                                         }
                   10698:                                     }
1.100     raeburn  10699:                                     $chgtext .= '</ul>';
                   10700:                                     if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.224     raeburn  10701:                                         $chgtext .= '<br /><span class="LC_warning">'.
                   10702:                                                     &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
                   10703:                                                     '</span>';
1.100     raeburn  10704:                                     }
                   10705:                                 }
                   10706:                             } else {
                   10707:                                 if (@{$cancreate{$type}} == 0) {
                   10708:                                     $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
                   10709:                                 } else {
                   10710:                                     $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  10711:                                 }
                   10712:                             }
                   10713:                         }
1.236     raeburn  10714:                     } elsif ($type eq 'selfcreateprocessing') {
                   10715:                         my %choices = &Apache::lonlocal::texthash (
                   10716:                                                                     automatic => 'Automatic approval',
                   10717:                                                                     approval  => 'Queued for approval',
                   10718:                                                                   );
                   10719:                         if (@statuses > 1) {
                   10720:                             $chgtext .= &mt('Processing of requests to create account with e-mail address as username set as follows:'). 
                   10721:                                         '<ul>';
                   10722:                            foreach my $type (@statuses) {
                   10723:                                if ($type eq 'default') {
                   10724:                                    $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
                   10725:                                } else {
                   10726:                                    $chgtext .= '<li>'.$usertypes->{$type}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
                   10727:                                }
                   10728:                            }
                   10729:                            $chgtext .= '</ul>';
                   10730:                         } else {
                   10731:                            $chgtext .= &mt('Processing of requests to create account with e-mail address as username set to: "[_1]"',
                   10732:                                          $choices{$cancreate{'selfcreateprocessing'}{'default'}});
                   10733:                         }
1.165     raeburn  10734:                     } elsif ($type eq 'captcha') {
1.224     raeburn  10735:                         if ($savecaptcha{$type} eq 'notused') {
1.165     raeburn  10736:                             $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
                   10737:                         } else {
                   10738:                             my %captchas = &captcha_phrases();
1.224     raeburn  10739:                             if ($captchas{$savecaptcha{$type}}) {
                   10740:                                 $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165     raeburn  10741:                             } else {
1.210     raeburn  10742:                                 $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165     raeburn  10743:                             }
                   10744:                         }
                   10745:                     } elsif ($type eq 'recaptchakeys') {
                   10746:                         my ($privkey,$pubkey);
1.224     raeburn  10747:                         if (ref($savecaptcha{$type}) eq 'HASH') {
                   10748:                             $pubkey = $savecaptcha{$type}{'public'};
                   10749:                             $privkey = $savecaptcha{$type}{'private'};
1.165     raeburn  10750:                         }
                   10751:                         $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
                   10752:                         if (!$pubkey) {
                   10753:                             $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
                   10754:                         } else {
                   10755:                             $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
                   10756:                         }
                   10757:                         if (!$privkey) {
                   10758:                             $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
                   10759:                         } else {
                   10760:                             $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
                   10761:                         }
                   10762:                         $chgtext .= '</ul>';
1.269     raeburn  10763:                     } elsif ($type eq 'recaptchaversion') {
                   10764:                         if ($savecaptcha{'captcha'} eq 'recaptcha') {
1.270     raeburn  10765:                             $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
1.269     raeburn  10766:                         }
1.224     raeburn  10767:                     } elsif ($type eq 'emailusername') {
                   10768:                         if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.228     raeburn  10769:                             if (ref($types) eq 'ARRAY') {
                   10770:                                 foreach my $type (@{$types}) {
                   10771:                                     if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
                   10772:                                         if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.245     raeburn  10773:                                             $chgtext .= &mt('When self-creating account with e-mail as username, the following information will be provided by [_1]:',"'$usertypes->{$type}'").
1.228     raeburn  10774:                                                     '<ul>';
                   10775:                                             foreach my $field (@{$infofields}) {
                   10776:                                                 if ($cancreate{'emailusername'}{$type}{$field}) {
                   10777:                                                     $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
                   10778:                                                 }
                   10779:                                             }
1.245     raeburn  10780:                                             $chgtext .= '</ul>';
                   10781:                                         } else {
                   10782:                                             $chgtext .= &mt('When self creating account with e-mail as username, no information besides e-mail address will be provided by [_1].',"'$usertypes->{$type}'").'<br />';
1.228     raeburn  10783:                                         }
                   10784:                                     } else {
1.245     raeburn  10785:                                         $chgtext .= &mt('When self creating account with e-mail as username, no information besides e-mail address will be provided by [_1].',"'$usertypes->{$type}'").'<br />';
1.224     raeburn  10786:                                     }
                   10787:                                 }
                   10788:                             }
                   10789:                         }
                   10790:                     } elsif ($type eq 'notify') {
                   10791:                         $chgtext = &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
                   10792:                         if (ref($changes{'cancreate'}) eq 'ARRAY') {
                   10793:                             if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
                   10794:                                 if ($cancreate{'notify'}{'approval'}) {
                   10795:                                     $chgtext = &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
                   10796:                                 }
                   10797:                             }
1.43      raeburn  10798:                         }
1.34      raeburn  10799:                     }
1.224     raeburn  10800:                     if ($chgtext) {
                   10801:                         $resulttext .= '<li>'.$chgtext.'</li>';
1.32      raeburn  10802:                     }
                   10803:                 }
                   10804:             }
1.43      raeburn  10805:             if (ref($changes{'email_rule'}) eq 'ARRAY') {
                   10806:                 my ($emailrules,$emailruleorder) =
                   10807:                     &Apache::lonnet::inst_userrules($dom,'email');
                   10808:                 my $chgtext = '<ul>';
                   10809:                 foreach my $type (@email_rule) {
                   10810:                     if (ref($emailrules->{$type}) eq 'HASH') {
                   10811:                         $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
                   10812:                     }
                   10813:                 }
                   10814:                 $chgtext .= '</ul>';
                   10815:                 if (@email_rule > 0) {
1.224     raeburn  10816:                     $resulttext .= '<li>'.
                   10817:                                    &mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').
                   10818:                                        $chgtext.
                   10819:                                    '</li>';
1.43      raeburn  10820:                 } else {
1.224     raeburn  10821:                     $resulttext .= '<li>'.
                   10822:                                    &mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').
                   10823:                                    '</li>';
1.43      raeburn  10824:                 }
                   10825:             }
1.224     raeburn  10826:             if (ref($changes{'selfcreate'}) eq 'ARRAY') {
                   10827:                 $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
                   10828:                 my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
                   10829:                 foreach my $type (@{$changes{'selfcreate'}}) {
                   10830:                     my $typename = $type;
                   10831:                     if (ref($usertypes) eq 'HASH') {
                   10832:                         if ($usertypes->{$type} ne '') {
                   10833:                             $typename = $usertypes->{$type};
                   10834:                         }
                   10835:                     }
                   10836:                     my @modifiable;
                   10837:                     $resulttext .= '<li>'.
                   10838:                                     &mt('Self-creation of account by users with status: [_1]',
                   10839:                                         '<span class="LC_cusr_emph">'.$typename.'</span>').
                   10840:                                     ' - '.&mt('modifiable fields (if institutional data blank): ');
                   10841:                     foreach my $field (@fields) {
                   10842:                         if ($save_usermodify{'selfcreate'}{$type}{$field}) {
                   10843:                             push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28      raeburn  10844:                         }
                   10845:                     }
1.224     raeburn  10846:                     if (@modifiable > 0) {
                   10847:                         $resulttext .= join(', ',@modifiable);
1.43      raeburn  10848:                     } else {
1.224     raeburn  10849:                         $resulttext .= &mt('none');
1.43      raeburn  10850:                     }
1.224     raeburn  10851:                     $resulttext .= '</li>';
1.28      raeburn  10852:                 }
1.224     raeburn  10853:                 $resulttext .= '</ul></li>';
1.28      raeburn  10854:             }
1.27      raeburn  10855:             $resulttext .= '</ul>';
                   10856:         } else {
1.224     raeburn  10857:             $resulttext = &mt('No changes made to self-creation settings');
1.27      raeburn  10858:         }
                   10859:     } else {
                   10860:         $resulttext = '<span class="LC_error">'.
1.23      raeburn  10861:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   10862:     }
1.43      raeburn  10863:     if ($warningmsg ne '') {
                   10864:         $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
                   10865:     }
1.23      raeburn  10866:     return $resulttext;
                   10867: }
                   10868: 
1.165     raeburn  10869: sub process_captcha {
                   10870:     my ($container,$changes,$newsettings,$current) = @_;
                   10871:     return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
                   10872:     $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
                   10873:     unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
                   10874:         $newsettings->{'captcha'} = 'original';
                   10875:     }
                   10876:     if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
1.210     raeburn  10877:         if ($container eq 'cancreate') {
1.169     raeburn  10878:             if (ref($changes->{'cancreate'}) eq 'ARRAY') {
                   10879:                 push(@{$changes->{'cancreate'}},'captcha');
                   10880:             } elsif (!defined($changes->{'cancreate'})) {
                   10881:                 $changes->{'cancreate'} = ['captcha'];
                   10882:             }
                   10883:         } else {
                   10884:             $changes->{'captcha'} = 1;
1.165     raeburn  10885:         }
                   10886:     }
1.269     raeburn  10887:     my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.165     raeburn  10888:     if ($newsettings->{'captcha'} eq 'recaptcha') {
                   10889:         $newpub = $env{'form.'.$container.'_recaptchapub'};
                   10890:         $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.250     raeburn  10891:         $newpub =~ s/[^\w\-]//g;
                   10892:         $newpriv =~ s/[^\w\-]//g;
1.169     raeburn  10893:         $newsettings->{'recaptchakeys'} = {
                   10894:                                              public  => $newpub,
                   10895:                                              private => $newpriv,
                   10896:                                           };
1.269     raeburn  10897:         $newversion = $env{'form.'.$container.'_recaptchaversion'};
                   10898:         $newversion =~ s/\D//g;
                   10899:         if ($newversion ne '2') {
                   10900:             $newversion = 1;
                   10901:         }
                   10902:         $newsettings->{'recaptchaversion'} = $newversion;
1.165     raeburn  10903:     }
                   10904:     if (ref($current->{'recaptchakeys'}) eq 'HASH') {
                   10905:         $currpub = $current->{'recaptchakeys'}{'public'};
                   10906:         $currpriv = $current->{'recaptchakeys'}{'private'};
1.179     raeburn  10907:         unless ($newsettings->{'captcha'} eq 'recaptcha') {
                   10908:             $newsettings->{'recaptchakeys'} = {
                   10909:                                                  public  => '',
                   10910:                                                  private => '',
                   10911:                                               }
                   10912:         }
1.165     raeburn  10913:     }
1.269     raeburn  10914:     if ($current->{'captcha'} eq 'recaptcha') {
                   10915:         $currversion = $current->{'recaptchaversion'};
                   10916:         if ($currversion ne '2') {
                   10917:             $currversion = 1;
                   10918:         }
                   10919:     }
                   10920:     if ($currversion ne $newversion) {
                   10921:         if ($container eq 'cancreate') {
                   10922:             if (ref($changes->{'cancreate'}) eq 'ARRAY') {
                   10923:                 push(@{$changes->{'cancreate'}},'recaptchaversion');
                   10924:             } elsif (!defined($changes->{'cancreate'})) {
                   10925:                 $changes->{'cancreate'} = ['recaptchaversion'];
                   10926:             }
                   10927:         } else {
                   10928:             $changes->{'recaptchaversion'} = 1;
                   10929:         }
                   10930:     }
1.165     raeburn  10931:     if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169     raeburn  10932:         if ($container eq 'cancreate') {
                   10933:             if (ref($changes->{'cancreate'}) eq 'ARRAY') {
                   10934:                 push(@{$changes->{'cancreate'}},'recaptchakeys');
                   10935:             } elsif (!defined($changes->{'cancreate'})) {
                   10936:                 $changes->{'cancreate'} = ['recaptchakeys'];
                   10937:             }
                   10938:         } else {
1.210     raeburn  10939:             $changes->{'recaptchakeys'} = 1;
1.165     raeburn  10940:         }
                   10941:     }
                   10942:     return;
                   10943: }
                   10944: 
1.33      raeburn  10945: sub modify_usermodification {
                   10946:     my ($dom,%domconfig) = @_;
1.224     raeburn  10947:     my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33      raeburn  10948:     if (ref($domconfig{'usermodification'}) eq 'HASH') {
                   10949:         foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224     raeburn  10950:             if ($key eq 'selfcreate') {
                   10951:                 $modifyhash{$key} = $domconfig{'usermodification'}{$key};
                   10952:             } else {  
                   10953:                 $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
                   10954:             }
1.33      raeburn  10955:         }
                   10956:     }
1.224     raeburn  10957:     my @contexts = ('author','course');
1.33      raeburn  10958:     my %context_title = (
                   10959:                            author => 'In author context',
                   10960:                            course => 'In course context',
                   10961:                         );
                   10962:     my @fields = ('lastname','firstname','middlename','generation',
                   10963:                   'permanentemail','id');
                   10964:     my %roles = (
                   10965:                   author => ['ca','aa'],
                   10966:                   course => ['st','ep','ta','in','cr'],
                   10967:                 );
                   10968:     my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
                   10969:     foreach my $context (@contexts) {
                   10970:         foreach my $role (@{$roles{$context}}) {
                   10971:             my @modifiable =  &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
                   10972:             foreach my $item (@fields) {
                   10973:                 if (grep(/^\Q$item\E$/,@modifiable)) {
                   10974:                     $modifyhash{$context}{$role}{$item} = 1;
                   10975:                 } else {
                   10976:                     $modifyhash{$context}{$role}{$item} = 0;
                   10977:                 }
                   10978:             }
                   10979:         }
                   10980:         if (ref($curr_usermodification{$context}) eq 'HASH') {
                   10981:             foreach my $role (@{$roles{$context}}) {
                   10982:                 if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
                   10983:                     foreach my $field (@fields) {
                   10984:                         if ($modifyhash{$context}{$role}{$field} ne 
                   10985:                                 $curr_usermodification{$context}{$role}{$field}) {
                   10986:                             push(@{$changes{$context}},$role);
                   10987:                             last;
                   10988:                         }
                   10989:                     }
                   10990:                 }
                   10991:             }
                   10992:         } else {
                   10993:             foreach my $context (@contexts) {
                   10994:                 foreach my $role (@{$roles{$context}}) {
                   10995:                     push(@{$changes{$context}},$role);
                   10996:                 }
                   10997:             }
                   10998:         }
                   10999:     }
                   11000:     my %usermodification_hash =  (
                   11001:                                    usermodification => \%modifyhash,
                   11002:                                  );
                   11003:     my $putresult = &Apache::lonnet::put_dom('configuration',
                   11004:                                              \%usermodification_hash,$dom);
                   11005:     if ($putresult eq 'ok') {
                   11006:         if (keys(%changes) > 0) {
                   11007:             $resulttext = &mt('Changes made: ').'<ul>';
                   11008:             foreach my $context (@contexts) {
                   11009:                 if (ref($changes{$context}) eq 'ARRAY') {
                   11010:                     $resulttext .= '<li>'.$context_title{$context}.':<ul>';
                   11011:                     if (ref($changes{$context}) eq 'ARRAY') {
                   11012:                         foreach my $role (@{$changes{$context}}) {
                   11013:                             my $rolename;
1.224     raeburn  11014:                             if ($role eq 'cr') {
                   11015:                                 $rolename = &mt('Custom');
1.33      raeburn  11016:                             } else {
1.224     raeburn  11017:                                 $rolename = &Apache::lonnet::plaintext($role);
1.33      raeburn  11018:                             }
                   11019:                             my @modifiable;
1.224     raeburn  11020:                             $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33      raeburn  11021:                             foreach my $field (@fields) {
                   11022:                                 if ($modifyhash{$context}{$role}{$field}) {
                   11023:                                     push(@modifiable,$fieldtitles{$field});
                   11024:                                 }
                   11025:                             }
                   11026:                             if (@modifiable > 0) {
                   11027:                                 $resulttext .= join(', ',@modifiable);
                   11028:                             } else {
                   11029:                                 $resulttext .= &mt('none'); 
                   11030:                             }
                   11031:                             $resulttext .= '</li>';
                   11032:                         }
                   11033:                         $resulttext .= '</ul></li>';
                   11034:                     }
                   11035:                 }
                   11036:             }
                   11037:             $resulttext .= '</ul>';
                   11038:         } else {
                   11039:             $resulttext = &mt('No changes made to user modification settings');
                   11040:         }
                   11041:     } else {
                   11042:         $resulttext = '<span class="LC_error">'.
                   11043:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   11044:     }
                   11045:     return $resulttext;
                   11046: }
                   11047: 
1.43      raeburn  11048: sub modify_defaults {
1.212     raeburn  11049:     my ($dom,$lastactref,%domconfig) = @_;
1.43      raeburn  11050:     my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212     raeburn  11051:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.141     raeburn  11052:     my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
1.43      raeburn  11053:     my @authtypes = ('internal','krb4','krb5','localauth');
                   11054:     foreach my $item (@items) {
                   11055:         $newvalues{$item} = $env{'form.'.$item};
                   11056:         if ($item eq 'auth_def') {
                   11057:             if ($newvalues{$item} ne '') {
                   11058:                 if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
                   11059:                     push(@errors,$item);
                   11060:                 }
                   11061:             }
                   11062:         } elsif ($item eq 'lang_def') {
                   11063:             if ($newvalues{$item} ne '') {
                   11064:                 if ($newvalues{$item} =~ /^(\w+)/) {
                   11065:                     my $langcode = $1;
1.103     raeburn  11066:                     if ($langcode ne 'x_chef') {
                   11067:                         if (code2language($langcode) eq '') {
                   11068:                             push(@errors,$item);
                   11069:                         }
1.43      raeburn  11070:                     }
                   11071:                 } else {
                   11072:                     push(@errors,$item);
                   11073:                 }
                   11074:             }
1.54      raeburn  11075:         } elsif ($item eq 'timezone_def') {
                   11076:             if ($newvalues{$item} ne '') {
1.62      raeburn  11077:                 if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54      raeburn  11078:                     push(@errors,$item);   
                   11079:                 }
                   11080:             }
1.68      raeburn  11081:         } elsif ($item eq 'datelocale_def') {
                   11082:             if ($newvalues{$item} ne '') {
                   11083:                 my @datelocale_ids = DateTime::Locale->ids();
                   11084:                 if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
                   11085:                     push(@errors,$item);
                   11086:                 }
                   11087:             }
1.141     raeburn  11088:         } elsif ($item eq 'portal_def') {
                   11089:             if ($newvalues{$item} ne '') {
                   11090:                 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])\/?$/) {
                   11091:                     push(@errors,$item);
                   11092:                 }
                   11093:             }
1.43      raeburn  11094:         }
                   11095:         if (grep(/^\Q$item\E$/,@errors)) {
                   11096:             $newvalues{$item} = $domdefaults{$item};
                   11097:         } elsif ($domdefaults{$item} ne $newvalues{$item}) {
                   11098:             $changes{$item} = 1;
                   11099:         }
1.72      raeburn  11100:         $domdefaults{$item} = $newvalues{$item};
1.43      raeburn  11101:     }
                   11102:     my %defaults_hash = (
1.72      raeburn  11103:                          defaults => \%newvalues,
                   11104:                         );
1.43      raeburn  11105:     my $title = &defaults_titles();
1.236     raeburn  11106: 
                   11107:     my $currinststatus;
                   11108:     if (ref($domconfig{'inststatus'}) eq 'HASH') {
                   11109:         $currinststatus = $domconfig{'inststatus'};
                   11110:     } else {
                   11111:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   11112:         $currinststatus = {
                   11113:                              inststatustypes => $usertypes,
                   11114:                              inststatusorder => $types,
                   11115:                              inststatusguest => [],
                   11116:                           };
                   11117:     }
                   11118:     my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
                   11119:     my @allpos;
                   11120:     my %guests;
                   11121:     my %alltypes;
                   11122:     my ($currtitles,$currguests,$currorder);
                   11123:     if (ref($currinststatus) eq 'HASH') {
                   11124:         if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
                   11125:             foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
                   11126:                 if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
                   11127:                     if ($currinststatus->{inststatustypes}->{$type} ne '') {
                   11128:                         $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
                   11129:                     }
                   11130:                 }
                   11131:                 unless (grep(/^\Q$type\E$/,@todelete)) { 
                   11132:                     my $position = $env{'form.inststatus_pos_'.$type};
                   11133:                     $position =~ s/\D+//g;
                   11134:                     $allpos[$position] = $type;
                   11135:                     $alltypes{$type} = $env{'form.inststatus_title_'.$type};
                   11136:                     $alltypes{$type} =~ s/`//g;
                   11137:                     if ($env{'form.inststatus_guest_'.$type}) {
                   11138:                         $guests{$type} = 1;
                   11139:                     }
                   11140:                 }
                   11141:             }
                   11142:             if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
                   11143:                 $currguests = join(',',@{$currinststatus->{'inststatusguest'}});
                   11144:             }
                   11145:             $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
                   11146:             $currtitles =~ s/,$//;
                   11147:         }
                   11148:     }
                   11149:     if ($env{'form.addinststatus'}) {
                   11150:         my $newtype = $env{'form.addinststatus'};
                   11151:         $newtype =~ s/\W//g;
                   11152:         unless (exists($alltypes{$newtype})) {
                   11153:             if ($env{'form.addinststatus_guest'}) {
                   11154:                 $guests{$newtype} = 1;
                   11155:             }
                   11156:             $alltypes{$newtype} = $env{'form.addinststatus_title'};
                   11157:             $alltypes{$newtype} =~ s/`//g; 
                   11158:             my $position = $env{'form.addinststatus_pos'};
                   11159:             $position =~ s/\D+//g;
                   11160:             if ($position ne '') {
                   11161:                 $allpos[$position] = $newtype;
                   11162:             }
                   11163:         }
                   11164:     }
                   11165:     my (@orderedstatus,@orderedguests);
                   11166:     foreach my $type (@allpos) {
                   11167:         unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
                   11168:             push(@orderedstatus,$type);
                   11169:             if ($guests{$type}) {
                   11170:                 push(@orderedguests,$type);
                   11171:             }
                   11172:         }
                   11173:     }
                   11174:     foreach my $type (keys(%alltypes)) {
                   11175:         unless (grep(/^\Q$type\E$/,@orderedstatus)) {
                   11176:             delete($alltypes{$type});
                   11177:         }
                   11178:     }
                   11179:     $defaults_hash{'inststatus'} = {
                   11180:                                      inststatustypes => \%alltypes,
                   11181:                                      inststatusorder => \@orderedstatus,
                   11182:                                      inststatusguest => \@orderedguests,
                   11183:                                    };
                   11184:     if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
                   11185:         foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
                   11186:             $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
                   11187:         }
                   11188:     }
                   11189:     if ($currorder ne join(',',@orderedstatus)) {
                   11190:         $changes{'inststatus'}{'inststatusorder'} = 1;
                   11191:     }
                   11192:     if ($currguests ne join(',',@orderedguests)) {
                   11193:         $changes{'inststatus'}{'inststatusguest'} = 1;
                   11194:     }
                   11195:     my $newtitles;
                   11196:     foreach my $item (@orderedstatus) {
                   11197:         $newtitles .= $alltypes{$item}.',';
                   11198:     }
                   11199:     $newtitles =~ s/,$//;
                   11200:     if ($currtitles ne $newtitles) {
                   11201:         $changes{'inststatus'}{'inststatustypes'} = 1;
                   11202:     }
1.43      raeburn  11203:     my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
                   11204:                                              $dom);
                   11205:     if ($putresult eq 'ok') {
                   11206:         if (keys(%changes) > 0) {
                   11207:             $resulttext = &mt('Changes made:').'<ul>';
1.212     raeburn  11208:             my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43      raeburn  11209:             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";
                   11210:             foreach my $item (sort(keys(%changes))) {
1.236     raeburn  11211:                 if ($item eq 'inststatus') {
                   11212:                     if (ref($changes{'inststatus'}) eq 'HASH') {
                   11213:                         if (($changes{'inststatus'}{'inststatustypes'}) || $changes{'inststatus'}{'inststatusorder'}) {
                   11214:                             $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
                   11215:                             foreach my $type (@orderedstatus) { 
                   11216:                                 $resulttext .= $alltypes{$type}.', ';
                   11217:                             }
                   11218:                             $resulttext =~ s/, $//;
                   11219:                             $resulttext .= '</li>';
                   11220:                         }
                   11221:                         if ($changes{'inststatus'}{'inststatusguest'}) {
                   11222:                             $resulttext .= '<li>'; 
                   11223:                             if (@orderedguests) {
                   11224:                                 $resulttext .= &mt('Types assignable to "non-institutional" usernames set to:').' ';
                   11225:                                 foreach my $type (@orderedguests) {
                   11226:                                     $resulttext .= $alltypes{$type}.', ';
                   11227:                                 }
                   11228:                                 $resulttext =~ s/, $//;
                   11229:                             } else {
                   11230:                                 $resulttext .= &mt('Types assignable to "non-institutional" usernames set to none.');
                   11231:                             }
                   11232:                             $resulttext .= '</li>';
                   11233:                         }
                   11234:                     }
                   11235:                 } else {
                   11236:                     my $value = $env{'form.'.$item};
                   11237:                     if ($value eq '') {
                   11238:                         $value = &mt('none');
                   11239:                     } elsif ($item eq 'auth_def') {
                   11240:                         my %authnames = &authtype_names();
                   11241:                         my %shortauth = (
                   11242:                                           internal   => 'int',
                   11243:                                           krb4       => 'krb4',
                   11244:                                           krb5       => 'krb5',
                   11245:                                           localauth  => 'loc',
                   11246:                         );
                   11247:                         $value = $authnames{$shortauth{$value}};
                   11248:                     }
                   11249:                     $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
                   11250:                     $mailmsgtext .= "$title->{$item} set to $value\n";  
1.43      raeburn  11251:                 }
                   11252:             }
                   11253:             $resulttext .= '</ul>';
                   11254:             $mailmsgtext .= "\n";
                   11255:             my $cachetime = 24*60*60;
1.72      raeburn  11256:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212     raeburn  11257:             if (ref($lastactref) eq 'HASH') {
                   11258:                 $lastactref->{'domdefaults'} = 1;
                   11259:             }
1.68      raeburn  11260:             if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203     raeburn  11261:                 my $notify = 1;
                   11262:                 if (ref($domconfig{'contacts'}) eq 'HASH') {
                   11263:                     if ($domconfig{'contacts'}{'reportupdates'} == 0) {
                   11264:                         $notify = 0;
                   11265:                     }
                   11266:                 }
                   11267:                 if ($notify) {
                   11268:                     &Apache::lonmsg::sendemail('installrecord@loncapa.org',
                   11269:                                                "LON-CAPA Domain Settings Change - $dom",
                   11270:                                                $mailmsgtext);
                   11271:                 }
1.54      raeburn  11272:             }
1.43      raeburn  11273:         } else {
1.54      raeburn  11274:             $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43      raeburn  11275:         }
                   11276:     } else {
                   11277:         $resulttext = '<span class="LC_error">'.
                   11278:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   11279:     }
                   11280:     if (@errors > 0) {
                   11281:         $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
                   11282:         foreach my $item (@errors) {
                   11283:             $resulttext .= ' "'.$title->{$item}.'",';
                   11284:         }
                   11285:         $resulttext =~ s/,$//;
                   11286:     }
                   11287:     return $resulttext;
                   11288: }
                   11289: 
1.46      raeburn  11290: sub modify_scantron {
1.205     raeburn  11291:     my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46      raeburn  11292:     my ($resulttext,%confhash,%changes,$errors);
                   11293:     my $custom = 'custom.tab';
                   11294:     my $default = 'default.tab';
                   11295:     my $servadm = $r->dir_config('lonAdmEMail');
                   11296:     my ($configuserok,$author_ok,$switchserver) = 
                   11297:         &config_check($dom,$confname,$servadm);
                   11298:     if ($env{'form.scantronformat.filename'} ne '') {
                   11299:         my $error;
                   11300:         if ($configuserok eq 'ok') {
                   11301:             if ($switchserver) {
1.130     raeburn  11302:                 $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46      raeburn  11303:             } else {
                   11304:                 if ($author_ok eq 'ok') {
                   11305:                     my ($result,$scantronurl) =
                   11306:                         &publishlogo($r,'upload','scantronformat',$dom,
                   11307:                                      $confname,'scantron','','',$custom);
                   11308:                     if ($result eq 'ok') {
                   11309:                         $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48      raeburn  11310:                         $changes{'scantronformat'} = 1;
1.46      raeburn  11311:                     } else {
                   11312:                         $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
                   11313:                     }
                   11314:                 } else {
                   11315:                     $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);
                   11316:                 }
                   11317:             }
                   11318:         } else {
                   11319:             $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);
                   11320:         }
                   11321:         if ($error) {
                   11322:             &Apache::lonnet::logthis($error);
                   11323:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   11324:         }
                   11325:     }
1.48      raeburn  11326:     if (ref($domconfig{'scantron'}) eq 'HASH') {
                   11327:         if ($domconfig{'scantron'}{'scantronformat'} ne '') {
                   11328:             if ($env{'form.scantronformat_del'}) {
                   11329:                 $confhash{'scantron'}{'scantronformat'} = '';
                   11330:                 $changes{'scantronformat'} = 1;
1.46      raeburn  11331:             }
                   11332:         }
                   11333:     }
                   11334:     if (keys(%confhash) > 0) {
                   11335:         my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
                   11336:                                                  $dom);
                   11337:         if ($putresult eq 'ok') {
                   11338:             if (keys(%changes) > 0) {
1.48      raeburn  11339:                 if (ref($confhash{'scantron'}) eq 'HASH') {
                   11340:                     $resulttext = &mt('Changes made:').'<ul>';
                   11341:                     if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130     raeburn  11342:                         $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48      raeburn  11343:                     } else {
1.130     raeburn  11344:                         $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46      raeburn  11345:                     }
1.48      raeburn  11346:                     $resulttext .= '</ul>';
                   11347:                 } else {
1.130     raeburn  11348:                     $resulttext = &mt('Changes made to bubblesheet format file.');
1.46      raeburn  11349:                 }
                   11350:                 $resulttext .= '</ul>';
                   11351:                 &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212     raeburn  11352:                 if (ref($lastactref) eq 'HASH') {
                   11353:                     $lastactref->{'domainconfig'} = 1;
                   11354:                 }
1.46      raeburn  11355:             } else {
1.130     raeburn  11356:                 $resulttext = &mt('No changes made to bubblesheet format file');
1.46      raeburn  11357:             }
                   11358:         } else {
                   11359:             $resulttext = '<span class="LC_error">'.
                   11360:                 &mt('An error occurred: [_1]',$putresult).'</span>';
                   11361:         }
                   11362:     } else {
1.130     raeburn  11363:         $resulttext = &mt('No changes made to bubblesheet format file'); 
1.46      raeburn  11364:     }
                   11365:     if ($errors) {
                   11366:         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
                   11367:                        $errors.'</ul>';
                   11368:     }
                   11369:     return $resulttext;
                   11370: }
                   11371: 
1.48      raeburn  11372: sub modify_coursecategories {
1.239     raeburn  11373:     my ($dom,$lastactref,%domconfig) = @_;
1.57      raeburn  11374:     my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
                   11375:         $cathash);
1.48      raeburn  11376:     my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.238     raeburn  11377:     my @catitems = ('unauth','auth');
                   11378:     my @cattypes = ('std','domonly','codesrch','none');
1.55      raeburn  11379:     if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57      raeburn  11380:         $cathash = $domconfig{'coursecategories'}{'cats'};
                   11381:         if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
                   11382:             $changes{'togglecats'} = 1;
                   11383:             $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
                   11384:         }
                   11385:         if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
                   11386:             $changes{'categorize'} = 1;
                   11387:             $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
                   11388:         }
1.120     raeburn  11389:         if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
                   11390:             $changes{'togglecatscomm'} = 1;
                   11391:             $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
                   11392:         }
                   11393:         if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
                   11394:             $changes{'categorizecomm'} = 1;
                   11395:             $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
1.272     raeburn  11396: 
                   11397:         }
                   11398:         if ($domconfig{'coursecategories'}{'togglecatsplace'} ne $env{'form.togglecatsplace'}) {
                   11399:             $changes{'togglecatsplace'} = 1;
                   11400:             $domconfig{'coursecategories'}{'togglecatsplace'} = $env{'form.togglecatsplace'};
                   11401:         }
                   11402:         if ($domconfig{'coursecategories'}{'categorizeplace'} ne $env{'form.categorizeplace'}) {
                   11403:             $changes{'categorizeplace'} = 1;
                   11404:             $domconfig{'coursecategories'}{'categorizeplace'} = $env{'form.categorizeplace'};
1.120     raeburn  11405:         }
1.238     raeburn  11406:         foreach my $item (@catitems) {
                   11407:             if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
                   11408:                 if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
                   11409:                     $changes{$item} = 1;
                   11410:                     $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
                   11411:                 }
                   11412:             }
                   11413:         }
1.57      raeburn  11414:     } else {
                   11415:         $changes{'togglecats'} = 1;
                   11416:         $changes{'categorize'} = 1;
1.124     raeburn  11417:         $changes{'togglecatscomm'} = 1;
                   11418:         $changes{'categorizecomm'} = 1;
1.272     raeburn  11419:         $changes{'togglecatsplace'} = 1;
                   11420:         $changes{'categorizeplace'} = 1;
1.87      raeburn  11421:         $domconfig{'coursecategories'} = {
                   11422:                                              togglecats => $env{'form.togglecats'},
                   11423:                                              categorize => $env{'form.categorize'},
1.124     raeburn  11424:                                              togglecatscomm => $env{'form.togglecatscomm'},
                   11425:                                              categorizecomm => $env{'form.categorizecomm'},
1.272     raeburn  11426:                                              togglecatsplace => $env{'form.togglecatsplace'},
                   11427:                                              categorizeplace => $env{'form.categorizeplace'},
1.120     raeburn  11428:                                          };
1.238     raeburn  11429:         foreach my $item (@catitems) {
                   11430:             if ($env{'form.coursecat_'.$item} ne 'std') {
                   11431:                 $changes{$item} = 1;
                   11432:             }
                   11433:             if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
                   11434:                 $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
                   11435:             }
                   11436:         }
1.57      raeburn  11437:     }
                   11438:     if (ref($cathash) eq 'HASH') {
                   11439:         if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '')  && ($env{'form.instcode'} == 0)) {
1.55      raeburn  11440:             push (@deletecategory,'instcode::0');
                   11441:         }
1.120     raeburn  11442:         if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '')  && ($env{'form.communities'} == 0)) {
                   11443:             push(@deletecategory,'communities::0');
                   11444:         }
1.272     raeburn  11445:         if (($domconfig{'coursecategories'}{'cats'}{'placement::0'} ne '')  && ($env{'form.placement'} == 0)) {
                   11446:             push(@deletecategory,'placement::0');
                   11447:         }
1.48      raeburn  11448:     }
1.57      raeburn  11449:     my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
                   11450:     if (ref($cathash) eq 'HASH') {
1.48      raeburn  11451:         if (@deletecategory > 0) {
                   11452:             #FIXME Need to remove category from all courses using a deleted category 
1.57      raeburn  11453:             &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48      raeburn  11454:             foreach my $item (@deletecategory) {
1.57      raeburn  11455:                 if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
                   11456:                     delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48      raeburn  11457:                     $deletions{$item} = 1;
1.57      raeburn  11458:                     &recurse_cat_deletes($item,$cathash,\%deletions);
1.48      raeburn  11459:                 }
                   11460:             }
                   11461:         }
1.57      raeburn  11462:         foreach my $item (keys(%{$cathash})) {
1.48      raeburn  11463:             my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57      raeburn  11464:             if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48      raeburn  11465:                 $reorderings{$item} = 1;
1.57      raeburn  11466:                 $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48      raeburn  11467:             }
                   11468:             if ($env{'form.addcategory_name_'.$item} ne '') {
                   11469:                 my $newcat = $env{'form.addcategory_name_'.$item};
                   11470:                 my $newdepth = $depth+1;
                   11471:                 my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57      raeburn  11472:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48      raeburn  11473:                 $adds{$newitem} = 1; 
                   11474:             }
                   11475:             if ($env{'form.subcat_'.$item} ne '') {
                   11476:                 my $newcat = $env{'form.subcat_'.$item};
                   11477:                 my $newdepth = $depth+1;
                   11478:                 my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57      raeburn  11479:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48      raeburn  11480:                 $adds{$newitem} = 1;
                   11481:             }
                   11482:         }
                   11483:     }
                   11484:     if ($env{'form.instcode'} eq '1') {
1.57      raeburn  11485:         if (ref($cathash) eq 'HASH') {
1.48      raeburn  11486:             my $newitem = 'instcode::0';
1.57      raeburn  11487:             if ($cathash->{$newitem} eq '') {  
                   11488:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48      raeburn  11489:                 $adds{$newitem} = 1;
                   11490:             }
                   11491:         } else {
                   11492:             my $newitem = 'instcode::0';
1.57      raeburn  11493:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48      raeburn  11494:             $adds{$newitem} = 1;
                   11495:         }
                   11496:     }
1.120     raeburn  11497:     if ($env{'form.communities'} eq '1') {
                   11498:         if (ref($cathash) eq 'HASH') {
                   11499:             my $newitem = 'communities::0';
                   11500:             if ($cathash->{$newitem} eq '') {
                   11501:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
                   11502:                 $adds{$newitem} = 1;
                   11503:             }
                   11504:         } else {
                   11505:             my $newitem = 'communities::0';
                   11506:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
                   11507:             $adds{$newitem} = 1;
                   11508:         }
                   11509:     }
1.272     raeburn  11510:     if ($env{'form.placement'} eq '1') {
                   11511:         if (ref($cathash) eq 'HASH') {
                   11512:             my $newitem = 'placement::0';
                   11513:             if ($cathash->{$newitem} eq '') {
                   11514:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
                   11515:                 $adds{$newitem} = 1;
                   11516:             }
                   11517:         } else {
                   11518:             my $newitem = 'placement::0';
                   11519:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
                   11520:             $adds{$newitem} = 1;
                   11521:         }
                   11522:     }
1.48      raeburn  11523:     if ($env{'form.addcategory_name'} ne '') {
1.120     raeburn  11524:         if (($env{'form.addcategory_name'} ne 'instcode') &&
1.272     raeburn  11525:             ($env{'form.addcategory_name'} ne 'communities') &&
                   11526:             ($env{'form.addcategory_name'} ne 'placement')) {
1.120     raeburn  11527:             my $newitem = &escape($env{'form.addcategory_name'}).'::0';
                   11528:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
                   11529:             $adds{$newitem} = 1;
                   11530:         }
1.48      raeburn  11531:     }
1.57      raeburn  11532:     my $putresult;
1.48      raeburn  11533:     if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
                   11534:         if (keys(%deletions) > 0) {
                   11535:             foreach my $key (keys(%deletions)) {
                   11536:                 if ($predelallitems{$key} ne '') {
                   11537:                     $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
                   11538:                 }
                   11539:             }
                   11540:         }
                   11541:         my (@chkcats,@chktrails,%chkallitems);
1.57      raeburn  11542:         &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48      raeburn  11543:         if (ref($chkcats[0]) eq 'ARRAY') {
                   11544:             my $depth = 0;
                   11545:             my $chg = 0;
                   11546:             for (my $i=0; $i<@{$chkcats[0]}; $i++) {
                   11547:                 my $name = $chkcats[0][$i];
                   11548:                 my $item;
                   11549:                 if ($name eq '') {
                   11550:                     $chg ++;
                   11551:                 } else {
                   11552:                     $item = &escape($name).'::0';
                   11553:                     if ($chg) {
1.57      raeburn  11554:                         $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48      raeburn  11555:                     }
                   11556:                     $depth ++; 
1.57      raeburn  11557:                     &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48      raeburn  11558:                     $depth --;
                   11559:                 }
                   11560:             }
                   11561:         }
1.57      raeburn  11562:     }
                   11563:     if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
                   11564:         $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48      raeburn  11565:         if ($putresult eq 'ok') {
1.57      raeburn  11566:             my %title = (
1.120     raeburn  11567:                          togglecats     => 'Show/Hide a course in catalog',
                   11568:                          categorize     => 'Assign a category to a course',
                   11569:                          togglecatscomm => 'Show/Hide a community in catalog',
                   11570:                          categorizecomm => 'Assign a category to a community',
1.57      raeburn  11571:                         );
                   11572:             my %level = (
1.120     raeburn  11573:                          dom  => 'set in Domain ("Modify Course/Community")',
                   11574:                          crs  => 'set in Course ("Course Configuration")',
                   11575:                          comm => 'set in Community ("Community Configuration")',
1.238     raeburn  11576:                          none     => 'No catalog',
                   11577:                          std      => 'Standard catalog',
                   11578:                          domonly  => 'Domain-only catalog',
                   11579:                          codesrch => 'Code search form',
1.57      raeburn  11580:                         );
1.48      raeburn  11581:             $resulttext = &mt('Changes made:').'<ul>';
1.57      raeburn  11582:             if ($changes{'togglecats'}) {
                   11583:                 $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>'; 
                   11584:             }
                   11585:             if ($changes{'categorize'}) {
                   11586:                 $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48      raeburn  11587:             }
1.120     raeburn  11588:             if ($changes{'togglecatscomm'}) {
                   11589:                 $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
                   11590:             }
                   11591:             if ($changes{'categorizecomm'}) {
                   11592:                 $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
                   11593:             }
1.238     raeburn  11594:             if ($changes{'unauth'}) {
                   11595:                 $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
                   11596:             }
                   11597:             if ($changes{'auth'}) {
                   11598:                 $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
                   11599:             }
1.57      raeburn  11600:             if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
                   11601:                 my $cathash;
                   11602:                 if (ref($domconfig{'coursecategories'}) eq 'HASH') {
                   11603:                     $cathash = $domconfig{'coursecategories'}{'cats'};
                   11604:                 } else {
                   11605:                     $cathash = {};
                   11606:                 } 
                   11607:                 my (@cats,@trails,%allitems);
                   11608:                     &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
                   11609:                 if (keys(%deletions) > 0) {
                   11610:                     $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
                   11611:                     foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) { 
                   11612:                         $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
                   11613:                     }
                   11614:                     $resulttext .= '</ul></li>';
                   11615:                 }
                   11616:                 if (keys(%reorderings) > 0) {
                   11617:                     my %sort_by_trail;
                   11618:                     $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
                   11619:                     foreach my $key (keys(%reorderings)) {
                   11620:                         if ($allitems{$key} ne '') {
                   11621:                             $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
                   11622:                         }
1.48      raeburn  11623:                     }
1.57      raeburn  11624:                     foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
                   11625:                         $resulttext .= '<li>'.$trails[$trail].'</li>';
                   11626:                     }
                   11627:                     $resulttext .= '</ul></li>';
1.48      raeburn  11628:                 }
1.57      raeburn  11629:                 if (keys(%adds) > 0) {
                   11630:                     my %sort_by_trail;
                   11631:                     $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
                   11632:                     foreach my $key (keys(%adds)) {
                   11633:                         if ($allitems{$key} ne '') {
                   11634:                             $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
                   11635:                         }
                   11636:                     }
                   11637:                     foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
                   11638:                         $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48      raeburn  11639:                     }
1.57      raeburn  11640:                     $resulttext .= '</ul></li>';
1.48      raeburn  11641:                 }
                   11642:             }
                   11643:             $resulttext .= '</ul>';
1.239     raeburn  11644:             if ($changes{'unauth'} || $changes{'auth'}) {
1.246     raeburn  11645:                 my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
                   11646:                 if ($changes{'auth'}) {
                   11647:                     $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
                   11648:                 }
                   11649:                 if ($changes{'unauth'}) {
                   11650:                     $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
                   11651:                 }
                   11652:                 my $cachetime = 24*60*60;
                   11653:                 &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.239     raeburn  11654:                 if (ref($lastactref) eq 'HASH') {
1.246     raeburn  11655:                     $lastactref->{'domdefaults'} = 1;
1.239     raeburn  11656:                 }
                   11657:             }
1.48      raeburn  11658:         } else {
                   11659:             $resulttext = '<span class="LC_error">'.
1.57      raeburn  11660:                           &mt('An error occurred: [_1]',$putresult).'</span>';
1.48      raeburn  11661:         }
                   11662:     } else {
1.120     raeburn  11663:         $resulttext = &mt('No changes made to course and community categories');
1.48      raeburn  11664:     }
                   11665:     return $resulttext;
                   11666: }
                   11667: 
1.69      raeburn  11668: sub modify_serverstatuses {
                   11669:     my ($dom,%domconfig) = @_;
                   11670:     my ($resulttext,%changes,%currserverstatus,%newserverstatus);
                   11671:     if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
                   11672:         %currserverstatus = %{$domconfig{'serverstatuses'}};
                   11673:     }
                   11674:     my @pages = &serverstatus_pages();
                   11675:     foreach my $type (@pages) {
                   11676:         $newserverstatus{$type}{'namedusers'} = '';
                   11677:         $newserverstatus{$type}{'machines'} = '';
                   11678:         if (defined($env{'form.'.$type.'_namedusers'})) {
                   11679:             my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
                   11680:             my @okusers;
                   11681:             foreach my $user (@users) {
                   11682:                 my ($uname,$udom) = split(/:/,$user);
                   11683:                 if (($udom =~ /^$match_domain$/) &&   
                   11684:                     (&Apache::lonnet::domain($udom)) &&
                   11685:                     ($uname =~ /^$match_username$/)) {
                   11686:                     if (!grep(/^\Q$user\E/,@okusers)) {
                   11687:                         push(@okusers,$user);
                   11688:                     }
                   11689:                 }
                   11690:             }
                   11691:             if (@okusers > 0) {
                   11692:                  @okusers = sort(@okusers);
                   11693:                  $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
                   11694:             }
                   11695:         }
                   11696:         if (defined($env{'form.'.$type.'_machines'})) {
                   11697:             my @machines = split(/,/,$env{'form.'.$type.'_machines'});
                   11698:             my @okmachines;
                   11699:             foreach my $ip (@machines) {
                   11700:                 my @parts = split(/\./,$ip);
                   11701:                 next if (@parts < 4);
                   11702:                 my $badip = 0;
                   11703:                 for (my $i=0; $i<4; $i++) {
                   11704:                     if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
                   11705:                         $badip = 1;
                   11706:                         last;
                   11707:                     }
                   11708:                 }
                   11709:                 if (!$badip) {
                   11710:                     push(@okmachines,$ip);     
                   11711:                 }
                   11712:             }
                   11713:             @okmachines = sort(@okmachines);
                   11714:             $newserverstatus{$type}{'machines'} = join(',',@okmachines);
                   11715:         }
                   11716:     }
                   11717:     my %serverstatushash =  (
                   11718:                                 serverstatuses => \%newserverstatus,
                   11719:                             );
                   11720:     foreach my $type (@pages) {
1.83      raeburn  11721:         foreach my $setting ('namedusers','machines') {
1.84      raeburn  11722:             my (@current,@new);
1.83      raeburn  11723:             if (ref($currserverstatus{$type}) eq 'HASH') {
1.84      raeburn  11724:                 if ($currserverstatus{$type}{$setting} ne '') { 
                   11725:                     @current = split(/,/,$currserverstatus{$type}{$setting});
                   11726:                 }
                   11727:             }
                   11728:             if ($newserverstatus{$type}{$setting} ne '') {
                   11729:                 @new = split(/,/,$newserverstatus{$type}{$setting});
1.83      raeburn  11730:             }
                   11731:             if (@current > 0) {
                   11732:                 if (@new > 0) {
                   11733:                     foreach my $item (@current) {
                   11734:                         if (!grep(/^\Q$item\E$/,@new)) {
                   11735:                             $changes{$type}{$setting} = 1;
1.82      raeburn  11736:                             last;
                   11737:                         }
                   11738:                     }
1.84      raeburn  11739:                     foreach my $item (@new) {
                   11740:                         if (!grep(/^\Q$item\E$/,@current)) {
                   11741:                             $changes{$type}{$setting} = 1;
                   11742:                             last;
1.82      raeburn  11743:                         }
                   11744:                     }
                   11745:                 } else {
1.83      raeburn  11746:                     $changes{$type}{$setting} = 1;
1.69      raeburn  11747:                 }
1.83      raeburn  11748:             } elsif (@new > 0) {
                   11749:                 $changes{$type}{$setting} = 1;
1.69      raeburn  11750:             }
                   11751:         }
                   11752:     }
                   11753:     if (keys(%changes) > 0) {
1.81      raeburn  11754:         my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69      raeburn  11755:         my $putresult = &Apache::lonnet::put_dom('configuration',
                   11756:                                                  \%serverstatushash,$dom);
                   11757:         if ($putresult eq 'ok') {
                   11758:             $resulttext .= &mt('Changes made:').'<ul>';
                   11759:             foreach my $type (@pages) {
1.84      raeburn  11760:                 if (ref($changes{$type}) eq 'HASH') {
1.69      raeburn  11761:                     $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84      raeburn  11762:                     if ($changes{$type}{'namedusers'}) {
1.69      raeburn  11763:                         if ($newserverstatus{$type}{'namedusers'} eq '') {
                   11764:                             $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
                   11765:                         } else {
                   11766:                             $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
                   11767:                         }
1.84      raeburn  11768:                     }
                   11769:                     if ($changes{$type}{'machines'}) {
1.69      raeburn  11770:                         if ($newserverstatus{$type}{'machines'} eq '') {
                   11771:                             $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
                   11772:                         } else {
                   11773:                             $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
                   11774:                         }
                   11775: 
                   11776:                     }
                   11777:                     $resulttext .= '</ul></li>';
                   11778:                 }
                   11779:             }
                   11780:             $resulttext .= '</ul>';
                   11781:         } else {
                   11782:             $resulttext = '<span class="LC_error">'.
                   11783:                           &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
                   11784: 
                   11785:         }
                   11786:     } else {
                   11787:         $resulttext = &mt('No changes made to access to server status pages');
                   11788:     }
                   11789:     return $resulttext;
                   11790: }
                   11791: 
1.118     jms      11792: sub modify_helpsettings {
1.122     jms      11793:     my ($r,$dom,$confname,%domconfig) = @_;
1.166     raeburn  11794:     my ($resulttext,$errors,%changes,%helphash);
                   11795:     my %defaultchecked = ('submitbugs' => 'on');
                   11796:     my @offon = ('off','on');
1.118     jms      11797:     my @toggles = ('submitbugs');
1.282     raeburn  11798:     my %current = ('submitbugs' => '');  
1.118     jms      11799:     if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.282     raeburn  11800:         %current = %{$domconfig{'helpsettings'}};
                   11801:     }
                   11802:     foreach my $item (@toggles) {
                   11803:         if ($defaultchecked{$item} eq 'on') { 
                   11804:             if ($current{$item} eq '') {
                   11805:                 if ($env{'form.'.$item} eq '0') {
                   11806:                     $changes{$item} = 1;
                   11807:                 }
                   11808:             } elsif ($current{$item} ne $env{'form.'.$item}) {
                   11809:                 $changes{$item} = 1;
                   11810:             }
                   11811:         } elsif ($defaultchecked{$item} eq 'off') {
                   11812:             if ($current{$item} eq '') {
                   11813:                 if ($env{'form.'.$item} eq '1') {
1.166     raeburn  11814:                     $changes{$item} = 1;
                   11815:                 }
1.282     raeburn  11816:             } elsif ($current{$item} ne $env{'form.'.$item}) {
                   11817:                 $changes{$item} = 1;
                   11818:             }
                   11819:         }
                   11820:         if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
                   11821:             $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
                   11822:         }
                   11823:     }
                   11824: 
                   11825:     my @modify = &Apache::loncommon::get_env_multiple('form.modifycusthelp');
                   11826:     my $confname = $dom.'-domainconfig';
                   11827:     my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
                   11828:     if (@modify) {
                   11829:         foreach my $num (@modify) {
                   11830:             my $rolename = $env{'form.custhelprole'.$num};
                   11831:             if ($rolename ne '') {
                   11832:                 if (exists($existing{'rolesdef_'.$rolename})) {
                   11833:                     my $prefix = 'custhelp'.$num;
                   11834:                     my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$prefix);
                   11835:                     my %currprivs;
                   11836:                     ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) = 
                   11837:                         split(/\_/,$existing{'rolesdef_'.$rolename});
                   11838:                     foreach my $level ('c','d','s') {
                   11839:                         if ($newprivs{$level} ne $currprivs{$level}) {
                   11840:                             $changes{'customrole'}{$rolename} = 1;
                   11841:                             my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
                   11842:                                                                      $newprivs{'c'},$confname,$dom);
                   11843:                             last;
                   11844:                         }
1.166     raeburn  11845:                     }
                   11846:                 }
                   11847:             }
1.282     raeburn  11848:         }
                   11849:     }
                   11850:     if ($env{'form.newcusthelp'} ne '') {
                   11851:         my $prefix = 'custhelp'.$env{'form.newcusthelp'};
                   11852:         my $rolename = $env{'form.newcusthelpname'};
                   11853:         $rolename=~s/[^A-Za-z0-9]//gs;
                   11854:         if ($rolename ne '') {
                   11855:             unless(exists($existing{'rolesdef_'.$rolename})) {
1.283   ! raeburn  11856:                 my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$prefix);
        !          11857:                 my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
        !          11858:                                                          $newprivs{'c'},$confname,$dom);
1.282     raeburn  11859:                 if ($result eq 'ok') {
                   11860:                     $changes{'newcustomrole'} = $rolename;
                   11861:                 } else {
1.283   ! raeburn  11862:                     $errors .= '<li><span class="LC_error">'.
        !          11863:                                &mt('An error occurred storing the new custom role: [_1]',
        !          11864:                                    $result).'</span></li>';
1.282     raeburn  11865:                 }
1.166     raeburn  11866:             }
                   11867:         }
1.118     jms      11868:     }
1.282     raeburn  11869: 
1.123     jms      11870:     my $putresult;
                   11871:     if (keys(%changes) > 0) {
1.166     raeburn  11872:         $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168     raeburn  11873:         if ($putresult eq 'ok') {
1.166     raeburn  11874:             $resulttext = &mt('Changes made:').'<ul>';
                   11875:             foreach my $item (sort(keys(%changes))) {
                   11876:                 if ($item eq 'submitbugs') {
                   11877:                     $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
                   11878:                                               &Apache::loncommon::modal_link('http://bugs.loncapa.org',
                   11879:                                               &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.282     raeburn  11880:                 } elsif ($item eq 'customrole') {
                   11881:                     if (ref($changes{'customrole'}) eq 'HASH') {
                   11882:                         foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
                   11883:                             $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
                   11884:                                                      $role).'</li>';
                   11885:                         }
                   11886:                     }
                   11887:                 } elsif ($item eq 'newcustomrole') {
                   11888:                     $resulttext .= '<li>'.&mt('New custom role added: [_1]',
                   11889:                                               $changes{'newcustomrole'}).'</li>';
1.166     raeburn  11890:                 }
                   11891:             }
                   11892:             $resulttext .= '</ul>';
                   11893:         } else {
                   11894:             $resulttext = &mt('No changes made to help settings');
1.168     raeburn  11895:             $errors .= '<li><span class="LC_error">'.
                   11896:                        &mt('An error occurred storing the settings: [_1]',
                   11897:                            $putresult).'</span></li>';
1.166     raeburn  11898:         }
1.118     jms      11899:     }
                   11900:     if ($errors) {
1.168     raeburn  11901:         $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.118     jms      11902:                        $errors.'</ul>';
                   11903:     }
                   11904:     return $resulttext;
                   11905: }
                   11906: 
1.121     raeburn  11907: sub modify_coursedefaults {
1.212     raeburn  11908:     my ($dom,$lastactref,%domconfig) = @_;
1.121     raeburn  11909:     my ($resulttext,$errors,%changes,%defaultshash);
1.257     raeburn  11910:     my %defaultchecked = (
                   11911:                            'canuse_pdfforms' => 'off',
                   11912:                            'uselcmath'       => 'on',
                   11913:                            'usejsme'         => 'on'
                   11914:                          );
                   11915:     my @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.198     raeburn  11916:     my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.276     raeburn  11917:                    'uploadquota_community','uploadquota_textbook','uploadquota_placement',
                   11918:                    'mysqltables_official','mysqltables_unofficial','mysqltables_community',
                   11919:                    'mysqltables_textbook','mysqltables_placement');
1.271     raeburn  11920:     my @types = ('official','unofficial','community','textbook','placement');
1.198     raeburn  11921:     my %staticdefaults = (
                   11922:                            anonsurvey_threshold => 10,
                   11923:                            uploadquota          => 500,
1.257     raeburn  11924:                            postsubmit           => 60,
1.276     raeburn  11925:                            mysqltables          => 172800,
1.198     raeburn  11926:                          );
1.121     raeburn  11927: 
                   11928:     $defaultshash{'coursedefaults'} = {};
                   11929: 
                   11930:     if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
                   11931:         if ($domconfig{'coursedefaults'} eq '') {
                   11932:             $domconfig{'coursedefaults'} = {};
                   11933:         }
                   11934:     }
                   11935: 
                   11936:     if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
                   11937:         foreach my $item (@toggles) {
                   11938:             if ($defaultchecked{$item} eq 'on') {
                   11939:                 if (($domconfig{'coursedefaults'}{$item} eq '') &&
                   11940:                     ($env{'form.'.$item} eq '0')) {
                   11941:                     $changes{$item} = 1;
1.192     raeburn  11942:                 } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121     raeburn  11943:                     $changes{$item} = 1;
                   11944:                 }
                   11945:             } elsif ($defaultchecked{$item} eq 'off') {
                   11946:                 if (($domconfig{'coursedefaults'}{$item} eq '') &&
                   11947:                     ($env{'form.'.$item} eq '1')) {
                   11948:                     $changes{$item} = 1;
                   11949:                 } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
                   11950:                     $changes{$item} = 1;
                   11951:                 }
                   11952:             }
                   11953:             $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
                   11954:         }
1.198     raeburn  11955:         foreach my $item (@numbers) {
                   11956:             my ($currdef,$newdef);
1.208     raeburn  11957:             $newdef = $env{'form.'.$item};
1.198     raeburn  11958:             if ($item eq 'anonsurvey_threshold') {
                   11959:                 $currdef = $domconfig{'coursedefaults'}{$item};
                   11960:                 $newdef =~ s/\D//g;
                   11961:                 if ($newdef eq '' || $newdef < 1) {
                   11962:                     $newdef = 1;
                   11963:                 }
                   11964:                 $defaultshash{'coursedefaults'}{$item} = $newdef;
                   11965:             } else {
1.276     raeburn  11966:                 my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
                   11967:                 if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
                   11968:                     $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.198     raeburn  11969:                 }
                   11970:                 $newdef =~ s/[^\w.\-]//g;
1.276     raeburn  11971:                 $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.198     raeburn  11972:             }
                   11973:             if ($currdef ne $newdef) {
                   11974:                 my $staticdef;
                   11975:                 if ($item eq 'anonsurvey_threshold') {
                   11976:                     unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
                   11977:                         $changes{$item} = 1;
                   11978:                     }
1.276     raeburn  11979:                 } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
                   11980:                     my $setting = $1; 
                   11981:                     unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
                   11982:                         $changes{$setting} = 1;
1.198     raeburn  11983:                     }
                   11984:                 }
1.139     raeburn  11985:             }
                   11986:         }
1.264     raeburn  11987:         my $currclone = $domconfig{'coursedefaults'}{'canclone'};
                   11988:         my @currclonecode;
                   11989:         if (ref($currclone) eq 'HASH') {
                   11990:             if (ref($currclone->{'instcode'}) eq 'ARRAY') {
                   11991:                 @currclonecode = @{$currclone->{'instcode'}};
                   11992:             }
                   11993:         }
                   11994:         my $newclone;
                   11995:         if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) { 
                   11996:             $newclone = $env{'form.canclone'};
                   11997:         }
                   11998:         if ($newclone eq 'instcode') {
                   11999:             my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
                   12000:             my (%codedefaults,@code_order,@clonecode);
                   12001:             &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
                   12002:                                                     \@code_order);
                   12003:             foreach my $item (@code_order) {
                   12004:                 if (grep(/^\Q$item\E$/,@newcodes)) {
                   12005:                     push(@clonecode,$item);
                   12006:                 }
                   12007:             }
                   12008:             if (@clonecode) {
                   12009:                 $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
                   12010:                 my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
                   12011:                 if (@diffs) {
                   12012:                     $changes{'canclone'} = 1;
                   12013:                 }
                   12014:             } else {
                   12015:                 $newclone eq '';
                   12016:             }
                   12017:         } elsif ($newclone ne '') {
                   12018:             $defaultshash{'coursedefaults'}{'canclone'} = $newclone; 
                   12019:         } 
                   12020:         if ($newclone ne $currclone) {
                   12021:             $changes{'canclone'} = 1;
                   12022:         }
1.257     raeburn  12023:         my %credits;
                   12024:         foreach my $type (@types) {
                   12025:             unless ($type eq 'community') {
                   12026:                 $credits{$type} = $env{'form.'.$type.'_credits'};
                   12027:                 $credits{$type} =~ s/[^\d.]+//g;
                   12028:             }
                   12029:         }
                   12030:         if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
                   12031:             ($env{'form.coursecredits'} eq '1')) {
                   12032:             $changes{'coursecredits'} = 1;
                   12033:             foreach my $type (keys(%credits)) {
                   12034:                 $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
                   12035:             }
                   12036:         } else {
                   12037:             if ($env{'form.coursecredits'} eq '1') { 
                   12038:                 foreach my $type (@types) {
                   12039:                     unless ($type eq 'community') {
                   12040:                         if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {        
                   12041:                             $changes{'coursecredits'} = 1;
                   12042:                         }
                   12043:                         $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
                   12044:                     }
                   12045:                 }
                   12046:             } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
                   12047:                 foreach my $type (@types) {
                   12048:                     unless ($type eq 'community') {
                   12049:                         if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
                   12050:                             $changes{'coursecredits'} = 1;
                   12051:                             last;
                   12052:                         }
                   12053:                     }
                   12054:                 }
                   12055:             }
                   12056:         }
                   12057:         if ($env{'form.postsubmit'} eq '1') {
                   12058:             $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
                   12059:             my %currtimeout;
                   12060:             if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
                   12061:                 if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
                   12062:                     $changes{'postsubmit'} = 1;
                   12063:                 }
                   12064:                 if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
                   12065:                     %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
                   12066:                 }
                   12067:             } else {
                   12068:                 $changes{'postsubmit'} = 1;
                   12069:             }
                   12070:             foreach my $type (@types) {
                   12071:                 my $timeout = $env{'form.'.$type.'_timeout'};
                   12072:                 $timeout =~ s/\D//g;
                   12073:                 if ($timeout == $staticdefaults{'postsubmit'}) {
                   12074:                     $timeout = '';
                   12075:                 } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
                   12076:                     $timeout = '0';
                   12077:                 }
                   12078:                 unless ($timeout eq '') {
                   12079:                     $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
                   12080:                 }
                   12081:                 if (exists($currtimeout{$type})) {
                   12082:                     if ($timeout ne $currtimeout{$type}) {
                   12083:                         $changes{'postsubmit'} = 1; 
                   12084:                     }
                   12085:                 } elsif ($timeout ne '') {
                   12086:                     $changes{'postsubmit'} = 1;
                   12087:                 }
                   12088:             }
                   12089:         } else {
                   12090:             $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
                   12091:             if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
                   12092:                 if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
                   12093:                     $changes{'postsubmit'} = 1;
                   12094:                 }
                   12095:             } else {
                   12096:                 $changes{'postsubmit'} = 1;
                   12097:             }
1.192     raeburn  12098:         }
1.121     raeburn  12099:     }
                   12100:     my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
                   12101:                                              $dom);
                   12102:     if ($putresult eq 'ok') {
                   12103:         if (keys(%changes) > 0) {
1.213     raeburn  12104:             my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.257     raeburn  12105:             if (($changes{'canuse_pdfforms'}) || ($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.264     raeburn  12106:                 ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.276     raeburn  12107:                 ($changes{'canclone'}) || ($changes{'mysqltables'})) {
1.257     raeburn  12108:                 foreach my $item ('canuse_pdfforms','uselcmath','usejsme') { 
                   12109:                     if ($changes{$item}) {
                   12110:                         $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
                   12111:                     }
                   12112:                 } 
1.192     raeburn  12113:                 if ($changes{'coursecredits'}) {
                   12114:                     if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.257     raeburn  12115:                         foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
                   12116:                             $domdefaults{$type.'credits'} =
                   12117:                                 $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
                   12118:                         }
                   12119:                     }
                   12120:                 }
                   12121:                 if ($changes{'postsubmit'}) {
                   12122:                     if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
                   12123:                         $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
                   12124:                         if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
                   12125:                             foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
                   12126:                                 $domdefaults{$type.'postsubtimeout'} =
                   12127:                                     $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
                   12128:                             }
                   12129:                         }
1.192     raeburn  12130:                     }
                   12131:                 }
1.198     raeburn  12132:                 if ($changes{'uploadquota'}) {
                   12133:                     if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
                   12134:                         foreach my $type (@types) {
                   12135:                             $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
                   12136:                         }
                   12137:                     }
                   12138:                 }
1.264     raeburn  12139:                 if ($changes{'canclone'}) {
                   12140:                     if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
                   12141:                         if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
                   12142:                             my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
                   12143:                             if (@clonecodes) {
                   12144:                                 $domdefaults{'canclone'} = join('+',@clonecodes);
                   12145:                             }
                   12146:                         }
                   12147:                     } else {
                   12148:                         $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
                   12149:                     }
                   12150:                 }
1.121     raeburn  12151:                 my $cachetime = 24*60*60;
                   12152:                 &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212     raeburn  12153:                 if (ref($lastactref) eq 'HASH') {
                   12154:                     $lastactref->{'domdefaults'} = 1;
                   12155:                 }
1.121     raeburn  12156:             }
                   12157:             $resulttext = &mt('Changes made:').'<ul>';
                   12158:             foreach my $item (sort(keys(%changes))) {
                   12159:                 if ($item eq 'canuse_pdfforms') {
                   12160:                     if ($env{'form.'.$item} eq '1') {
                   12161:                         $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
                   12162:                     } else {
                   12163:                         $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
                   12164:                     }
1.257     raeburn  12165:                 } elsif ($item eq 'uselcmath') {
                   12166:                     if ($env{'form.'.$item} eq '1') {
                   12167:                         $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
                   12168:                     } else {
                   12169:                         $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
                   12170:                     }
                   12171:                 } elsif ($item eq 'usejsme') {
                   12172:                     if ($env{'form.'.$item} eq '1') {
                   12173:                         $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
                   12174:                     } else {
                   12175:                         $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>'; 
                   12176:                     }
1.139     raeburn  12177:                 } elsif ($item eq 'anonsurvey_threshold') {
1.192     raeburn  12178:                     $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198     raeburn  12179:                 } elsif ($item eq 'uploadquota') {
                   12180:                     if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
                   12181:                         $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
                   12182:                                        '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
                   12183:                                        '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216     raeburn  12184:                                        '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
1.271     raeburn  12185:                                        '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'placement'}.'</b>').'</li>'. 
1.198     raeburn  12186:                                        '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
                   12187:                                        '</ul>'.
                   12188:                                        '</li>';
                   12189:                     } else {
                   12190:                         $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
                   12191:                     }
1.276     raeburn  12192:                 } elsif ($item eq 'mysqltables') {
                   12193:                     if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
                   12194:                         $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
                   12195:                                        '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
                   12196:                                        '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
                   12197:                                        '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
                   12198:                                        '<li>'.&mt('Placement tests: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'placement'}.'</b>').'</li>'.
                   12199:                                        '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
                   12200:                                        '</ul>'.
                   12201:                                        '</li>';
                   12202:                     } else {
                   12203:                         $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
                   12204:                     }
1.257     raeburn  12205:                 } elsif ($item eq 'postsubmit') {
                   12206:                     if ($domdefaults{'postsubmit'} eq 'off') {
                   12207:                         $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
                   12208:                     } else {
                   12209:                         $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
                   12210:                         if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') { 
                   12211:                             $resulttext .= &mt('durations:').'<ul>';
                   12212:                             foreach my $type (@types) {
                   12213:                                 $resulttext .= '<li>';
                   12214:                                 my $timeout;
                   12215:                                 if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
                   12216:                                     $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
                   12217:                                 }
                   12218:                                 my $display;
                   12219:                                 if ($timeout eq '0') {
                   12220:                                     $display = &mt('unlimited');
                   12221:                                 } elsif ($timeout eq '') {
                   12222:                                     $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
                   12223:                                 } else {
                   12224:                                     $display = &mt('[quant,_1,second]',$timeout);
                   12225:                                 }
                   12226:                                 if ($type eq 'community') {
                   12227:                                     $resulttext .= &mt('Communities');
                   12228:                                 } elsif ($type eq 'official') {
                   12229:                                     $resulttext .= &mt('Official courses');
                   12230:                                 } elsif ($type eq 'unofficial') {
                   12231:                                     $resulttext .= &mt('Unofficial courses');
                   12232:                                 } elsif ($type eq 'textbook') {
                   12233:                                     $resulttext .= &mt('Textbook courses');
1.271     raeburn  12234:                                 } elsif ($type eq 'placement') {
                   12235:                                     $resulttext .= &mt('Placement tests');
1.257     raeburn  12236:                                 }
                   12237:                                 $resulttext .= ' -- '.$display.'</li>';
                   12238:                             }
                   12239:                             $resulttext .= '</ul>';
                   12240:                         }
                   12241:                         $resulttext .= '</li>';    
                   12242:                     }
1.192     raeburn  12243:                 } elsif ($item eq 'coursecredits') {
                   12244:                     if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
                   12245:                         if (($domdefaults{'officialcredits'} eq '') &&
1.216     raeburn  12246:                             ($domdefaults{'unofficialcredits'} eq '') &&
                   12247:                             ($domdefaults{'textbookcredits'} eq '')) {
1.192     raeburn  12248:                             $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
                   12249:                         } else {
                   12250:                             $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
                   12251:                                            '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
                   12252:                                            '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216     raeburn  12253:                                            '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192     raeburn  12254:                                            '</ul>'.
                   12255:                                            '</li>';
                   12256:                         }
                   12257:                     } else {
                   12258:                         $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
                   12259:                     }
1.264     raeburn  12260:                 } elsif ($item eq 'canclone') {
                   12261:                     if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
                   12262:                         if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
                   12263:                             my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
                   12264:                             $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
                   12265:                         }
                   12266:                     } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
                   12267:                         $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
                   12268:                     } else {
                   12269:                         $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>'; 
                   12270:                     }
1.140     raeburn  12271:                 }
1.121     raeburn  12272:             }
                   12273:             $resulttext .= '</ul>';
                   12274:         } else {
                   12275:             $resulttext = &mt('No changes made to course defaults');
                   12276:         }
                   12277:     } else {
                   12278:         $resulttext = '<span class="LC_error">'.
                   12279:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   12280:     }
                   12281:     return $resulttext;
                   12282: }
                   12283: 
1.231     raeburn  12284: sub modify_selfenrollment {
                   12285:     my ($dom,$lastactref,%domconfig) = @_;
                   12286:     my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
1.271     raeburn  12287:     my @types = ('official','unofficial','community','textbook','placement');
1.231     raeburn  12288:     my %titles = &tool_titles();
1.232     raeburn  12289:     my %descs = &Apache::lonuserutils::selfenroll_default_descs();
                   12290:     ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
1.231     raeburn  12291:     $ordered{'default'} = ['types','registered','approval','limit'];
                   12292: 
                   12293:     my (%roles,%shown,%toplevel);
                   12294:     $roles{'0'} = &Apache::lonnet::plaintext('dc');
                   12295: 
                   12296:     if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
                   12297:         if ($domconfig{'selfenrollment'} eq '') {
                   12298:             $domconfig{'selfenrollment'} = {};
                   12299:         }
                   12300:     }
                   12301:     %toplevel = (
                   12302:                   admin      => 'Configuration Rights',
                   12303:                   default    => 'Default settings',
                   12304:                   validation => 'Validation of self-enrollment requests',
                   12305:                 );
1.233     raeburn  12306:     my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
1.231     raeburn  12307: 
                   12308:     if (ref($ordered{'admin'}) eq 'ARRAY') {
                   12309:         foreach my $item (@{$ordered{'admin'}}) {
                   12310:             foreach my $type (@types) {
                   12311:                 if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
                   12312:                     $selfenrollhash{'admin'}{$type}{$item} = 1;
                   12313:                 } else {
                   12314:                     $selfenrollhash{'admin'}{$type}{$item} = 0;
                   12315:                 }
                   12316:                 if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
                   12317:                     if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
                   12318:                         if ($selfenrollhash{'admin'}{$type}{$item} ne
                   12319:                             $domconfig{'selfenrollment'}{'admin'}{$type}{$item})  {
                   12320:                             push(@{$changes{'admin'}{$type}},$item);
                   12321:                         }
                   12322:                     } else {
                   12323:                         if (!$selfenrollhash{'admin'}{$type}{$item}) {
                   12324:                             push(@{$changes{'admin'}{$type}},$item);
                   12325:                         }
                   12326:                     }
                   12327:                 } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
                   12328:                     push(@{$changes{'admin'}{$type}},$item);
                   12329:                 }
                   12330:             }
                   12331:         }
                   12332:     }
                   12333: 
                   12334:     foreach my $item (@{$ordered{'default'}}) {
                   12335:         foreach my $type (@types) {
                   12336:             my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
                   12337:             if ($item eq 'types') {
                   12338:                 unless (($value eq 'all') || ($value eq 'dom')) {
                   12339:                     $value = '';
                   12340:                 }
                   12341:             } elsif ($item eq 'registered') {
                   12342:                 unless ($value eq '1') {
                   12343:                     $value = 0;
                   12344:                 }
                   12345:             } elsif ($item eq 'approval') {
                   12346:                 unless ($value =~ /^[012]$/) {
                   12347:                     $value = 0;
                   12348:                 }
                   12349:             } else {
                   12350:                 unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
                   12351:                     $value = 'none';
                   12352:                 }
                   12353:             }
                   12354:             $selfenrollhash{'default'}{$type}{$item} = $value;
                   12355:             if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
                   12356:                 if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
                   12357:                     if ($selfenrollhash{'default'}{$type}{$item} ne
                   12358:                          $domconfig{'selfenrollment'}{'default'}{$type}{$item})  {
                   12359:                          push(@{$changes{'default'}{$type}},$item);
                   12360:                     }
                   12361:                 } else {
                   12362:                     push(@{$changes{'default'}{$type}},$item);
                   12363:                 }
                   12364:             } else {
                   12365:                 push(@{$changes{'default'}{$type}},$item);
                   12366:             }
                   12367:             if ($item eq 'limit') {
                   12368:                 if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
                   12369:                     $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
                   12370:                     if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
                   12371:                         $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
                   12372:                     }
                   12373:                 } else {
                   12374:                     $selfenrollhash{'default'}{$type}{'cap'} = '';
                   12375:                 }
                   12376:                 if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
                   12377:                     if ($selfenrollhash{'default'}{$type}{'cap'} ne
                   12378:                          $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'})  {
                   12379:                          push(@{$changes{'default'}{$type}},'cap');
                   12380:                     }
                   12381:                 } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
                   12382:                     push(@{$changes{'default'}{$type}},'cap');
                   12383:                 }
                   12384:             }
                   12385:         }
                   12386:     }
                   12387: 
                   12388:     foreach my $item (@{$itemsref}) {
                   12389:         if ($item eq 'fields') {
                   12390:             my @changed;
                   12391:             @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
                   12392:             if (@{$selfenrollhash{'validation'}{$item}} > 0) {
                   12393:                 @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
                   12394:             }
                   12395:             if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
                   12396:                 if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
                   12397:                     @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
                   12398:                                                                   $domconfig{'selfenrollment'}{'validation'}{$item});
                   12399:                 } else {
                   12400:                     @changed = @{$selfenrollhash{'validation'}{$item}};
                   12401:                 }
                   12402:             } else {
                   12403:                 @changed = @{$selfenrollhash{'validation'}{$item}};
                   12404:             }
                   12405:             if (@changed) {
                   12406:                 if ($selfenrollhash{'validation'}{$item}) { 
                   12407:                     $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
                   12408:                 } else {
                   12409:                     $changes{'validation'}{$item} = &mt('None');
                   12410:                 }
                   12411:             }
                   12412:         } else {
                   12413:             $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
                   12414:             if ($item eq 'markup') {
                   12415:                if ($env{'form.selfenroll_validation_'.$item}) {
                   12416:                    $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
                   12417:                }
                   12418:             }
                   12419:             if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
                   12420:                 if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
                   12421:                     $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
                   12422:                 }
                   12423:             }
                   12424:         }
                   12425:     }
                   12426: 
                   12427:     my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
                   12428:                                              $dom);
                   12429:     if ($putresult eq 'ok') {
                   12430:         if (keys(%changes) > 0) {
                   12431:             my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
                   12432:             $resulttext = &mt('Changes made:').'<ul>';
                   12433:             foreach my $key ('admin','default','validation') {
                   12434:                 if (ref($changes{$key}) eq 'HASH') {
                   12435:                     $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
                   12436:                     if ($key eq 'validation') {
                   12437:                         foreach my $item (@{$itemsref}) {
                   12438:                             if (exists($changes{$key}{$item})) {
                   12439:                                 if ($item eq 'markup') {
                   12440:                                     $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
                   12441:                                                               '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
                   12442:                                 } else {  
                   12443:                                     $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
                   12444:                                                               '<b>'.$changes{$key}{$item}.'</b>').'</li>';
                   12445:                                 }
                   12446:                             }
                   12447:                         }
                   12448:                     } else {
                   12449:                         foreach my $type (@types) {
                   12450:                             if ($type eq 'community') {
                   12451:                                 $roles{'1'} = &mt('Community personnel');
                   12452:                             } else {
                   12453:                                 $roles{'1'} = &mt('Course personnel');
                   12454:                             }
                   12455:                             if (ref($changes{$key}{$type}) eq 'ARRAY') {
1.232     raeburn  12456:                                 if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
                   12457:                                     if ($key eq 'admin') {
                   12458:                                         my @mgrdc = ();
                   12459:                                         if (ref($ordered{$key}) eq 'ARRAY') {
                   12460:                                             foreach my $item (@{$ordered{'admin'}}) {
                   12461:                                                 if (ref($selfenrollhash{$key}{$type}) eq 'HASH') { 
                   12462:                                                     if ($selfenrollhash{$key}{$type}{$item} eq '0') {
                   12463:                                                         push(@mgrdc,$item);
                   12464:                                                     }
                   12465:                                                 }
                   12466:                                             }
                   12467:                                             if (@mgrdc) {
                   12468:                                                 $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
                   12469:                                             } else {
                   12470:                                                 delete($domdefaults{$type.'selfenrolladmdc'});
                   12471:                                             }
                   12472:                                         }
                   12473:                                     } else {
                   12474:                                         if (ref($ordered{$key}) eq 'ARRAY') {
                   12475:                                             foreach my $item (@{$ordered{$key}}) {
                   12476:                                                 if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
                   12477:                                                     $domdefaults{$type.'selfenroll'.$item} =
                   12478:                                                         $selfenrollhash{$key}{$type}{$item};
                   12479:                                                 }
                   12480:                                             }
                   12481:                                         }
                   12482:                                     }
                   12483:                                 }
1.231     raeburn  12484:                                 $resulttext .= '<li>'.$titles{$type}.'<ul>';
                   12485:                                 foreach my $item (@{$ordered{$key}}) {
                   12486:                                     if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
                   12487:                                         $resulttext .= '<li>';
                   12488:                                         if ($key eq 'admin') {
                   12489:                                             $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
                   12490:                                                                '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
                   12491:                                         } else {
                   12492:                                             $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
                   12493:                                                                '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
                   12494:                                         }
                   12495:                                         $resulttext .= '</li>';
                   12496:                                     }
                   12497:                                 }
                   12498:                                 $resulttext .= '</ul></li>';
                   12499:                             }
                   12500:                         }
                   12501:                         $resulttext .= '</ul></li>'; 
                   12502:                     }
                   12503:                 }
1.232     raeburn  12504:                 if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
                   12505:                     my $cachetime = 24*60*60;
                   12506:                     &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
                   12507:                     if (ref($lastactref) eq 'HASH') {
                   12508:                         $lastactref->{'domdefaults'} = 1;
                   12509:                     }
                   12510:                 }
1.231     raeburn  12511:             }
                   12512:             $resulttext .= '</ul>';
                   12513:         } else {
                   12514:             $resulttext = &mt('No changes made to self-enrollment settings');
                   12515:         }
                   12516:     } else {
                   12517:         $resulttext = '<span class="LC_error">'.
                   12518:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   12519:     }
                   12520:     return $resulttext;
                   12521: }
                   12522: 
1.137     raeburn  12523: sub modify_usersessions {
1.212     raeburn  12524:     my ($dom,$lastactref,%domconfig) = @_;
1.145     raeburn  12525:     my @hostingtypes = ('version','excludedomain','includedomain');
                   12526:     my @offloadtypes = ('primary','default');
                   12527:     my %types = (
                   12528:                   remote => \@hostingtypes,
                   12529:                   hosted => \@hostingtypes,
                   12530:                   spares => \@offloadtypes,
                   12531:                 );
                   12532:     my @prefixes = ('remote','hosted','spares');
1.137     raeburn  12533:     my @lcversions = &Apache::lonnet::all_loncaparevs();
1.275     raeburn  12534:     my (%by_ip,%by_location,@intdoms,@instdoms);
                   12535:     &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.138     raeburn  12536:     my @locations = sort(keys(%by_location));
1.137     raeburn  12537:     my (%defaultshash,%changes);
                   12538:     foreach my $prefix (@prefixes) {
                   12539:         $defaultshash{'usersessions'}{$prefix} = {};
                   12540:     }
1.212     raeburn  12541:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137     raeburn  12542:     my $resulttext;
1.138     raeburn  12543:     my %iphost = &Apache::lonnet::get_iphost();
1.137     raeburn  12544:     foreach my $prefix (@prefixes) {
1.145     raeburn  12545:         next if ($prefix eq 'spares');
                   12546:         foreach my $type (@{$types{$prefix}}) {
1.137     raeburn  12547:             my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
                   12548:             if ($type eq 'version') {
                   12549:                 my $value = $env{'form.'.$prefix.'_'.$type};
                   12550:                 my $okvalue;
                   12551:                 if ($value ne '') {
                   12552:                     if (grep(/^\Q$value\E$/,@lcversions)) {
                   12553:                         $okvalue = $value;
                   12554:                     }
                   12555:                 }
                   12556:                 if (ref($domconfig{'usersessions'}) eq 'HASH') {
                   12557:                     if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
                   12558:                         if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
                   12559:                             if ($inuse == 0) {
                   12560:                                 $changes{$prefix}{$type} = 1;
                   12561:                             } else {
                   12562:                                 if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
                   12563:                                     $changes{$prefix}{$type} = 1;
                   12564:                                 }
                   12565:                                 if ($okvalue ne '') {
                   12566:                                     $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
                   12567:                                 } 
                   12568:                             }
                   12569:                         } else {
                   12570:                             if (($inuse == 1) && ($okvalue ne '')) {
                   12571:                                 $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
                   12572:                                 $changes{$prefix}{$type} = 1;
                   12573:                             }
                   12574:                         }
                   12575:                     } else {
                   12576:                         if (($inuse == 1) && ($okvalue ne '')) {
                   12577:                             $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
                   12578:                             $changes{$prefix}{$type} = 1;
                   12579:                         }
                   12580:                     }
                   12581:                 } else {
                   12582:                     if (($inuse == 1) && ($okvalue ne '')) {
                   12583:                         $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
                   12584:                         $changes{$prefix}{$type} = 1;
                   12585:                     }
                   12586:                 }
                   12587:             } else {
                   12588:                 my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
                   12589:                 my @okvals;
                   12590:                 foreach my $val (@vals) {
1.138     raeburn  12591:                     if ($val =~ /:/) {
                   12592:                         my @items = split(/:/,$val);
                   12593:                         foreach my $item (@items) {
                   12594:                             if (ref($by_location{$item}) eq 'ARRAY') {
                   12595:                                 push(@okvals,$item);
                   12596:                             }
                   12597:                         }
                   12598:                     } else {
                   12599:                         if (ref($by_location{$val}) eq 'ARRAY') {
                   12600:                             push(@okvals,$val);
                   12601:                         }
1.137     raeburn  12602:                     }
                   12603:                 }
                   12604:                 @okvals = sort(@okvals);
                   12605:                 if (ref($domconfig{'usersessions'}) eq 'HASH') {
                   12606:                     if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
                   12607:                         if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
                   12608:                             if ($inuse == 0) {
                   12609:                                 $changes{$prefix}{$type} = 1; 
                   12610:                             } else {
                   12611:                                 $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
                   12612:                                 my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
                   12613:                                 if (@changed > 0) {
                   12614:                                     $changes{$prefix}{$type} = 1;
                   12615:                                 }
                   12616:                             }
                   12617:                         } else {
                   12618:                             if ($inuse == 1) {
                   12619:                                 $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
                   12620:                                 $changes{$prefix}{$type} = 1;
                   12621:                             }
                   12622:                         } 
                   12623:                     } else {
                   12624:                         if ($inuse == 1) {
                   12625:                             $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
                   12626:                             $changes{$prefix}{$type} = 1;
                   12627:                         }
                   12628:                     }
                   12629:                 } else {
                   12630:                     if ($inuse == 1) {
                   12631:                         $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
                   12632:                         $changes{$prefix}{$type} = 1;
                   12633:                     }
                   12634:                 }
                   12635:             }
                   12636:         }
                   12637:     }
1.145     raeburn  12638: 
                   12639:     my @alldoms = &Apache::lonnet::all_domains();
1.149     raeburn  12640:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145     raeburn  12641:     my %spareid = &current_offloads_to($dom,$domconfig{'usersessions'},\%servers);
                   12642:     my $savespares;
                   12643: 
                   12644:     foreach my $lonhost (sort(keys(%servers))) {
                   12645:         my $serverhomeID =
                   12646:             &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152     raeburn  12647:         my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145     raeburn  12648:         $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
                   12649:         my %spareschg;
                   12650:         foreach my $type (@{$types{'spares'}}) {
                   12651:             my @okspares;
                   12652:             my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
                   12653:             foreach my $server (@checked) {
1.152     raeburn  12654:                 if (&Apache::lonnet::hostname($server) ne '') {
                   12655:                     unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
                   12656:                         unless (grep(/^\Q$server\E$/,@okspares)) {
                   12657:                             push(@okspares,$server);
                   12658:                         }
1.145     raeburn  12659:                     }
                   12660:                 }
                   12661:             }
                   12662:             my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
                   12663:             my $newspare;
1.152     raeburn  12664:             if (($new ne '') && (&Apache::lonnet::hostname($new))) {
                   12665:                 unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145     raeburn  12666:                     $newspare = $new;
                   12667:                 }
                   12668:             }
1.152     raeburn  12669:             my @spares;
                   12670:             if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
                   12671:                 @spares = sort(@okspares,$newspare);
                   12672:             } else {
                   12673:                 @spares = sort(@okspares);
                   12674:             }
                   12675:             $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145     raeburn  12676:             if (ref($spareid{$lonhost}) eq 'HASH') {
                   12677:                 if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152     raeburn  12678:                     my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145     raeburn  12679:                     if (@diffs > 0) {
                   12680:                         $spareschg{$type} = 1;
                   12681:                     }
                   12682:                 }
                   12683:             }
                   12684:         }
                   12685:         if (keys(%spareschg) > 0) {
                   12686:             $changes{'spares'}{$lonhost} = \%spareschg;
                   12687:         }
                   12688:     }
1.261     raeburn  12689:     $defaultshash{'usersessions'}{'offloadnow'} = {};
                   12690:     my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
                   12691:     my @okoffload;
                   12692:     if (@offloadnow) {
                   12693:         foreach my $server (@offloadnow) {
                   12694:             if (&Apache::lonnet::hostname($server) ne '') {
                   12695:                 unless (grep(/^\Q$server\E$/,@okoffload)) {
                   12696:                     push(@okoffload,$server);
                   12697:                 }
                   12698:             }
                   12699:         }
                   12700:         if (@okoffload) {
                   12701:             foreach my $lonhost (@okoffload) {
                   12702:                 $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
                   12703:             }
                   12704:         }
                   12705:     }
1.145     raeburn  12706:     if (ref($domconfig{'usersessions'}) eq 'HASH') {
                   12707:         if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
                   12708:             if (ref($changes{'spares'}) eq 'HASH') {
                   12709:                 if (keys(%{$changes{'spares'}}) > 0) {
                   12710:                     $savespares = 1;
                   12711:                 }
                   12712:             }
                   12713:         } else {
                   12714:             $savespares = 1;
                   12715:         }
1.261     raeburn  12716:         if (ref($domconfig{'usersessions'}{'offloadnow'}) eq 'HASH') {
                   12717:             foreach my $lonhost (keys(%{$domconfig{'usersessions'}{'offloadnow'}})) {
                   12718:                 unless ($defaultshash{'usersessions'}{'offloadnow'}{$lonhost}) {
                   12719:                     $changes{'offloadnow'} = 1;
                   12720:                     last;
                   12721:                 }
                   12722:             }
                   12723:             unless ($changes{'offloadnow'}) {
                   12724:                 foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{'offloadnow'}})) { 
                   12725:                     unless ($domconfig{'usersessions'}{'offloadnow'}{$lonhost}) {
                   12726:                         $changes{'offloadnow'} = 1;
                   12727:                         last;
                   12728:                     }
                   12729:                 }
                   12730:             }
                   12731:         } elsif (@okoffload) {
                   12732:             $changes{'offloadnow'} = 1;
                   12733:         }
                   12734:     } elsif (@okoffload) {
                   12735:         $changes{'offloadnow'} = 1;
1.145     raeburn  12736:     }
1.147     raeburn  12737:     my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
                   12738:     if ((keys(%changes) > 0) || ($savespares)) {
1.137     raeburn  12739:         my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
                   12740:                                                  $dom);
                   12741:         if ($putresult eq 'ok') {
                   12742:             if (ref($defaultshash{'usersessions'}) eq 'HASH') {
                   12743:                 if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
                   12744:                     $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
                   12745:                 }
                   12746:                 if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
                   12747:                     $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
                   12748:                 }
1.261     raeburn  12749:                 if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
                   12750:                     $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
                   12751:                 }
1.137     raeburn  12752:             }
                   12753:             my $cachetime = 24*60*60;
                   12754:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212     raeburn  12755:             if (ref($lastactref) eq 'HASH') {
                   12756:                 $lastactref->{'domdefaults'} = 1;
                   12757:             }
1.147     raeburn  12758:             if (keys(%changes) > 0) {
                   12759:                 my %lt = &usersession_titles();
                   12760:                 $resulttext = &mt('Changes made:').'<ul>';
                   12761:                 foreach my $prefix (@prefixes) {
                   12762:                     if (ref($changes{$prefix}) eq 'HASH') {
                   12763:                         $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
                   12764:                         if ($prefix eq 'spares') {
                   12765:                             if (ref($changes{$prefix}) eq 'HASH') {
                   12766:                                 foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
                   12767:                                     $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148     raeburn  12768:                                     my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211     raeburn  12769:                                     my $cachekey = &escape('spares').':'.&escape($lonhostdom);
                   12770:                                     &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147     raeburn  12771:                                     if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
                   12772:                                         foreach my $type (@{$types{$prefix}}) {
                   12773:                                             if ($changes{$prefix}{$lonhost}{$type}) {
                   12774:                                                 my $offloadto = &mt('None');
                   12775:                                                 if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
                   12776:                                                     if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {   
                   12777:                                                         $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
                   12778:                                                     }
1.145     raeburn  12779:                                                 }
1.147     raeburn  12780:                                                 $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).('&nbsp;'x3);
1.145     raeburn  12781:                                             }
1.137     raeburn  12782:                                         }
                   12783:                                     }
1.147     raeburn  12784:                                     $resulttext .= '</li>';
1.137     raeburn  12785:                                 }
                   12786:                             }
1.147     raeburn  12787:                         } else {
                   12788:                             foreach my $type (@{$types{$prefix}}) {
                   12789:                                 if (defined($changes{$prefix}{$type})) {
                   12790:                                     my $newvalue;
                   12791:                                     if (ref($defaultshash{'usersessions'}) eq 'HASH') {
                   12792:                                         if (ref($defaultshash{'usersessions'}{$prefix})) {
                   12793:                                             if ($type eq 'version') {
                   12794:                                                 $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
                   12795:                                             } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
                   12796:                                                 if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
                   12797:                                                     $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
                   12798:                                                 }
1.145     raeburn  12799:                                             }
                   12800:                                         }
                   12801:                                     }
1.147     raeburn  12802:                                     if ($newvalue eq '') {
                   12803:                                         if ($type eq 'version') {
                   12804:                                             $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
                   12805:                                         } else {
                   12806:                                             $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
                   12807:                                         }
1.145     raeburn  12808:                                     } else {
1.147     raeburn  12809:                                         if ($type eq 'version') {
                   12810:                                             $newvalue .= ' '.&mt('(or later)'); 
                   12811:                                         }
                   12812:                                         $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145     raeburn  12813:                                     }
1.137     raeburn  12814:                                 }
                   12815:                             }
                   12816:                         }
1.147     raeburn  12817:                         $resulttext .= '</ul>';
1.137     raeburn  12818:                     }
                   12819:                 }
1.261     raeburn  12820:                 if ($changes{'offloadnow'}) {
                   12821:                     if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
                   12822:                         if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
                   12823:                             $resulttext .= '<li>'.&mt('Switch active users on next access, for server(s):').'<ul>';
                   12824:                             foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
                   12825:                                 $resulttext .= '<li>'.$lonhost.'</li>';
                   12826:                             }
                   12827:                             $resulttext .= '</ul>';
                   12828:                         } else {
                   12829:                             $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.');
                   12830:                         }
                   12831:                     } else {
                   12832:                         $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.').'</li>';
                   12833:                     }
                   12834:                 }
1.147     raeburn  12835:                 $resulttext .= '</ul>';
                   12836:             } else {
                   12837:                 $resulttext = $nochgmsg;
1.137     raeburn  12838:             }
                   12839:         } else {
                   12840:             $resulttext = '<span class="LC_error">'.
                   12841:                           &mt('An error occurred: [_1]',$putresult).'</span>';
                   12842:         }
                   12843:     } else {
1.147     raeburn  12844:         $resulttext = $nochgmsg;
1.137     raeburn  12845:     }
                   12846:     return $resulttext;
                   12847: }
                   12848: 
1.275     raeburn  12849: sub modify_ssl {
                   12850:     my ($dom,$lastactref,%domconfig) = @_;
                   12851:     my (%by_ip,%by_location,@intdoms,@instdoms);
                   12852:     &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
                   12853:     my @locations = sort(keys(%by_location));
                   12854:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
                   12855:     my (%defaultshash,%changes);
                   12856:     my $action = 'ssl';
                   12857:     my @prefixes = ('connect','replication');
                   12858:     foreach my $prefix (@prefixes) {
                   12859:         $defaultshash{$action}{$prefix} = {};
                   12860:     }
                   12861:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
                   12862:     my $resulttext;
                   12863:     my %iphost = &Apache::lonnet::get_iphost();
                   12864:     my @reptypes = ('certreq','nocertreq');
                   12865:     my @connecttypes = ('dom','intdom','other');
                   12866:     my %types = (
                   12867:                   connect      => \@connecttypes,
                   12868:                   replication  => \@reptypes,
                   12869:                 );
                   12870:     foreach my $prefix (sort(keys(%types))) {
                   12871:         foreach my $type (@{$types{$prefix}}) {
                   12872:             if ($prefix eq 'connect') {
                   12873:                 my $value = 'yes';
                   12874:                 if ($env{'form.'.$prefix.'_'.$type} =~ /^(no|req)$/) {
                   12875:                     $value = $env{'form.'.$prefix.'_'.$type};
                   12876:                 }
                   12877:                 if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
                   12878:                     if ($domconfig{$action}{$prefix}{$type} ne '') {
                   12879:                         if ($value ne $domconfig{$action}{$prefix}{$type}) {
                   12880:                             $changes{$prefix}{$type} = 1;
                   12881:                         }
                   12882:                         $defaultshash{$action}{$prefix}{$type} = $value;
                   12883:                     } else {
                   12884:                         $defaultshash{$action}{$prefix}{$type} = $value;
                   12885:                         $changes{$prefix}{$type} = 1;
                   12886:                     }
                   12887:                 } else {
                   12888:                     $defaultshash{$action}{$prefix}{$type} = $value;
                   12889:                     $changes{$prefix}{$type} = 1;
                   12890:                 }
                   12891:                 if (($type eq 'dom') && (keys(%servers) == 1)) {
                   12892:                     delete($changes{$prefix}{$type});
                   12893:                 } elsif (($type eq 'intdom') && (@instdoms == 1)) {
                   12894:                     delete($changes{$prefix}{$type});
                   12895:                 } elsif (($type eq 'other') && (keys(%by_location) == 0)) { 
                   12896:                     delete($changes{$prefix}{$type});
                   12897:                 }
                   12898:             } elsif ($prefix eq 'replication') {
                   12899:                 if (@locations > 0) {
                   12900:                     my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
                   12901:                     my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
                   12902:                     my @okvals;
                   12903:                     foreach my $val (@vals) {
                   12904:                         if ($val =~ /:/) {
                   12905:                             my @items = split(/:/,$val);
                   12906:                             foreach my $item (@items) {
                   12907:                                 if (ref($by_location{$item}) eq 'ARRAY') {
                   12908:                                     push(@okvals,$item);
                   12909:                                 }
                   12910:                             }
                   12911:                         } else {
                   12912:                             if (ref($by_location{$val}) eq 'ARRAY') {
                   12913:                                 push(@okvals,$val);
                   12914:                             }
                   12915:                         }
                   12916:                     }
                   12917:                     @okvals = sort(@okvals);
                   12918:                     if (ref($domconfig{$action}) eq 'HASH') {
                   12919:                         if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
                   12920:                             if (ref($domconfig{$action}{$prefix}{$type}) eq 'ARRAY') {
                   12921:                                 if ($inuse == 0) {
                   12922:                                     $changes{$prefix}{$type} = 1;
                   12923:                                 } else {
                   12924:                                     $defaultshash{$action}{$prefix}{$type} = \@okvals;
                   12925:                                     my @changed = &Apache::loncommon::compare_arrays($domconfig{$action}{$prefix}{$type},$defaultshash{$action}{$prefix}{$type});
                   12926:                                     if (@changed > 0) {
                   12927:                                         $changes{$prefix}{$type} = 1;
                   12928:                                     }
                   12929:                                 }
                   12930:                             } else {
                   12931:                                 if ($inuse == 1) {
                   12932:                                     $defaultshash{$action}{$prefix}{$type} = \@okvals;
                   12933:                                     $changes{$prefix}{$type} = 1;
                   12934:                                 }
                   12935:                             }
                   12936:                         } else {
                   12937:                             if ($inuse == 1) {
                   12938:                                 $defaultshash{$action}{$prefix}{$type} = \@okvals;
                   12939:                                 $changes{$prefix}{$type} = 1;
                   12940:                             }
                   12941:                         }
                   12942:                     } else {
                   12943:                         if ($inuse == 1) {
                   12944:                             $defaultshash{$action}{$prefix}{$type} = \@okvals;
                   12945:                             $changes{$prefix}{$type} = 1;
                   12946:                         }
                   12947:                     }
                   12948:                 }
                   12949:             }
                   12950:         }
                   12951:     }
                   12952:     my $nochgmsg = &mt('No changes made to LON-CAPA SSL settings');
                   12953:     if (keys(%changes) > 0) {
                   12954:         my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
                   12955:                                                  $dom);
                   12956:         if ($putresult eq 'ok') {
                   12957:             if (ref($defaultshash{$action}) eq 'HASH') {
                   12958:                 if (ref($defaultshash{$action}{'replication'}) eq 'HASH') {
                   12959:                     $domdefaults{'replication'} = $defaultshash{$action}{'replication'};
                   12960:                 }
                   12961:                 if (ref($defaultshash{$action}{'connect'}) eq 'HASH') {
                   12962:                     $domdefaults{'connect'} = $domconfig{$action}{'connect'};
                   12963:                 }
                   12964:             }
                   12965:             my $cachetime = 24*60*60;
                   12966:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
                   12967:             if (ref($lastactref) eq 'HASH') {
                   12968:                 $lastactref->{'domdefaults'} = 1;
                   12969:             }
                   12970:             if (keys(%changes) > 0) {
                   12971:                 my %titles = &ssl_titles();
                   12972:                 $resulttext = &mt('Changes made:').'<ul>';
                   12973:                 foreach my $prefix (@prefixes) {
                   12974:                     if (ref($changes{$prefix}) eq 'HASH') {
                   12975:                         $resulttext .= '<li>'.$titles{$prefix}.'<ul>';
                   12976:                         foreach my $type (@{$types{$prefix}}) {
                   12977:                             if (defined($changes{$prefix}{$type})) {
                   12978:                                 my $newvalue;
                   12979:                                 if (ref($defaultshash{$action}) eq 'HASH') {
                   12980:                                     if (ref($defaultshash{$action}{$prefix})) {
                   12981:                                         if ($prefix eq 'connect') {
                   12982:                                             $newvalue = $titles{$defaultshash{$action}{$prefix}{$type}};
                   12983:                                         } elsif (ref($defaultshash{$action}{$prefix}{$type}) eq 'ARRAY') {
                   12984:                                             if (@{$defaultshash{$action}{$prefix}{$type}} > 0) {
                   12985:                                                 $newvalue = join(', ',@{$defaultshash{$action}{$prefix}{$type}});
                   12986:                                             }
                   12987:                                         }
                   12988:                                     }
                   12989:                                     if ($newvalue eq '') {
                   12990:                                         $resulttext .= '<li>'.&mt('[_1] set to: none',$titles{$type}).'</li>';
                   12991:                                     } else {
                   12992:                                         $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$titles{$type},$newvalue).'</li>';
                   12993:                                     }
                   12994:                                 }
                   12995:                             }
                   12996:                         }
                   12997:                         $resulttext .= '</ul>';
                   12998:                     }
                   12999:                 }
                   13000:             } else {
                   13001:                 $resulttext = $nochgmsg;
                   13002:             }
                   13003:         } else {
                   13004:             $resulttext = '<span class="LC_error">'.
                   13005:                           &mt('An error occurred: [_1]',$putresult).'</span>';
                   13006:         }
                   13007:     } else {
                   13008:         $resulttext = $nochgmsg;
                   13009:     }
                   13010:     return $resulttext;
                   13011: }
                   13012: 
1.279     raeburn  13013: sub modify_trust {
                   13014:     my ($dom,$lastactref,%domconfig) = @_;
                   13015:     my (%by_ip,%by_location,@intdoms,@instdoms);
                   13016:     &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
                   13017:     my @locations = sort(keys(%by_location));
                   13018:     my @prefixes = qw(content shared enroll othcoau coaurem domroles catalog reqcrs msg);
                   13019:     my @types = ('exc','inc');
                   13020:     my (%defaultshash,%changes);
                   13021:     foreach my $prefix (@prefixes) {
                   13022:         $defaultshash{'trust'}{$prefix} = {};
                   13023:     }
                   13024:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
                   13025:     my $resulttext;
                   13026:     foreach my $prefix (@prefixes) {
                   13027:         foreach my $type (@types) {
                   13028:             my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
                   13029:             my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
                   13030:             my @okvals;
                   13031:             foreach my $val (@vals) {
                   13032:                 if ($val =~ /:/) {
                   13033:                     my @items = split(/:/,$val);
                   13034:                     foreach my $item (@items) {
                   13035:                         if (ref($by_location{$item}) eq 'ARRAY') {
                   13036:                             push(@okvals,$item);
                   13037:                         }
                   13038:                     }
                   13039:                 } else {
                   13040:                     if (ref($by_location{$val}) eq 'ARRAY') {
                   13041:                         push(@okvals,$val);
                   13042:                     }
                   13043:                 }
                   13044:             }
                   13045:             @okvals = sort(@okvals);
                   13046:             if (ref($domconfig{'trust'}) eq 'HASH') {
                   13047:                 if (ref($domconfig{'trust'}{$prefix}) eq 'HASH') {
                   13048:                     if (ref($domconfig{'trust'}{$prefix}{$type}) eq 'ARRAY') {
                   13049:                         if ($inuse == 0) {
                   13050:                             $changes{$prefix}{$type} = 1;
                   13051:                         } else {
                   13052:                             $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
                   13053:                             my @changed = &Apache::loncommon::compare_arrays($domconfig{'trust'}{$prefix}{$type},$defaultshash{'trust'}{$prefix}{$type});
                   13054:                             if (@changed > 0) {
                   13055:                                 $changes{$prefix}{$type} = 1;
                   13056:                             }
                   13057:                         }
                   13058:                     } else {
                   13059:                         if ($inuse == 1) {
                   13060:                             $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
                   13061:                             $changes{$prefix}{$type} = 1;
                   13062:                         }
                   13063:                     }
                   13064:                 } else {
                   13065:                     if ($inuse == 1) {
                   13066:                         $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
                   13067:                         $changes{$prefix}{$type} = 1;
                   13068:                     }
                   13069:                 }
                   13070:             } else {
                   13071:                 if ($inuse == 1) {
                   13072:                     $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
                   13073:                     $changes{$prefix}{$type} = 1;
                   13074:                 }
                   13075:             }
                   13076:         }
                   13077:     }
                   13078:     my $nochgmsg = &mt('No changes made to trust settings.');
                   13079:     if (keys(%changes) > 0) {
                   13080:         my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
                   13081:                                                  $dom);
                   13082:         if ($putresult eq 'ok') {
                   13083:             if (ref($defaultshash{'trust'}) eq 'HASH') {
                   13084:                 foreach my $prefix (@prefixes) {
                   13085:                     if (ref($defaultshash{'trust'}{$prefix}) eq 'HASH') {
                   13086:                         $domdefaults{'trust'.$prefix} = $defaultshash{'trust'}{$prefix};
                   13087:                     }
                   13088:                 }
                   13089:             }
                   13090:             my $cachetime = 24*60*60;
                   13091:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
                   13092:             if (ref($lastactref) eq 'HASH') {
                   13093:                 $lastactref->{'domdefaults'} = 1;
                   13094:             }
                   13095:             if (keys(%changes) > 0) {
                   13096:                 my %lt = &trust_titles();
                   13097:                 $resulttext = &mt('Changes made:').'<ul>';
                   13098:                 foreach my $prefix (@prefixes) {
                   13099:                     if (ref($changes{$prefix}) eq 'HASH') {
                   13100:                         $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
                   13101:                         foreach my $type (@types) {
                   13102:                             if (defined($changes{$prefix}{$type})) {
                   13103:                                 my $newvalue;
                   13104:                                 if (ref($defaultshash{'trust'}) eq 'HASH') {
                   13105:                                     if (ref($defaultshash{'trust'}{$prefix})) {
                   13106:                                         if (ref($defaultshash{'trust'}{$prefix}{$type}) eq 'ARRAY') {
                   13107:                                             if (@{$defaultshash{'trust'}{$prefix}{$type}} > 0) {
                   13108:                                                 $newvalue = join(', ',@{$defaultshash{'trust'}{$prefix}{$type}});
                   13109:                                             }
                   13110:                                         }
                   13111:                                     }
                   13112:                                 }
                   13113:                                 if ($newvalue eq '') {
                   13114:                                     $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
                   13115:                                 } else {
                   13116:                                     $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
                   13117:                                 }
                   13118:                             }
                   13119:                         }
                   13120:                         $resulttext .= '</ul>';
                   13121:                     }
                   13122:                 }
                   13123:                 $resulttext .= '</ul>';
                   13124:             } else {
                   13125:                 $resulttext = $nochgmsg;
                   13126:             }
                   13127:         } else {
                   13128:             $resulttext = '<span class="LC_error">'.
                   13129:                           &mt('An error occurred: [_1]',$putresult).'</span>';
                   13130:         }
                   13131:     } else {
                   13132:         $resulttext = $nochgmsg;
                   13133:     }
                   13134:     return $resulttext;
                   13135: }
                   13136: 
1.150     raeburn  13137: sub modify_loadbalancing {
                   13138:     my ($dom,%domconfig) = @_;
                   13139:     my $primary_id = &Apache::lonnet::domain($dom,'primary');
                   13140:     my $intdom = &Apache::lonnet::internet_dom($primary_id);
                   13141:     my ($othertitle,$usertypes,$types) =
                   13142:         &Apache::loncommon::sorted_inst_types($dom);
                   13143:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.253     raeburn  13144:     my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150     raeburn  13145:     my @sparestypes = ('primary','default');
                   13146:     my %typetitles = &sparestype_titles();
                   13147:     my $resulttext;
1.171     raeburn  13148:     my (%currbalancer,%currtargets,%currrules,%existing);
                   13149:     if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
                   13150:         %existing = %{$domconfig{'loadbalancing'}};
                   13151:     }
                   13152:     &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
                   13153:                               \%currtargets,\%currrules);
                   13154:     my ($saveloadbalancing,%defaultshash,%changes);
                   13155:     my ($alltypes,$othertypes,$titles) =
                   13156:         &loadbalancing_titles($dom,$intdom,$usertypes,$types);
                   13157:     my %ruletitles = &offloadtype_text();
                   13158:     my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
                   13159:     for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
                   13160:         my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
                   13161:         if ($balancer eq '') {
                   13162:             next;
                   13163:         }
1.210     raeburn  13164:         if (!exists($servers{$balancer})) {
1.171     raeburn  13165:             if (exists($currbalancer{$balancer})) {
                   13166:                 push(@{$changes{'delete'}},$balancer);
1.150     raeburn  13167:             }
1.171     raeburn  13168:             next;
                   13169:         }
                   13170:         if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
                   13171:             push(@{$changes{'delete'}},$balancer);
                   13172:             next;
                   13173:         }
                   13174:         if (!exists($currbalancer{$balancer})) {
                   13175:             push(@{$changes{'add'}},$balancer);
                   13176:         }
                   13177:         $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
                   13178:         $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
                   13179:         $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
                   13180:         unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
                   13181:             $saveloadbalancing = 1;
                   13182:         }
                   13183:         foreach my $sparetype (@sparestypes) {
                   13184:             my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
                   13185:             my @offloadto;
                   13186:             foreach my $target (@targets) {
                   13187:                 if (($servers{$target}) && ($target ne $balancer)) {
                   13188:                     if ($sparetype eq 'default') {
                   13189:                         if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
                   13190:                             next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150     raeburn  13191:                         }
                   13192:                     }
1.171     raeburn  13193:                     unless(grep(/^\Q$target\E$/,@offloadto)) {
                   13194:                         push(@offloadto,$target);
                   13195:                     }
1.150     raeburn  13196:                 }
1.171     raeburn  13197:                 $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150     raeburn  13198:             }
                   13199:         }
1.171     raeburn  13200:         if (ref($currtargets{$balancer}) eq 'HASH') {
1.150     raeburn  13201:             foreach my $sparetype (@sparestypes) {
1.171     raeburn  13202:                 if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
                   13203:                     my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150     raeburn  13204:                     if (@targetdiffs > 0) {
1.171     raeburn  13205:                         $changes{'curr'}{$balancer}{'targets'} = 1;
1.150     raeburn  13206:                     }
1.171     raeburn  13207:                 } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
                   13208:                     if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
                   13209:                         $changes{'curr'}{$balancer}{'targets'} = 1;
1.150     raeburn  13210:                     }
                   13211:                 }
                   13212:             }
                   13213:         } else {
1.171     raeburn  13214:             if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210     raeburn  13215:                 foreach my $sparetype (@sparestypes) {
1.171     raeburn  13216:                     if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
                   13217:                         if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
                   13218:                             $changes{'curr'}{$balancer}{'targets'} = 1;
                   13219:                         }
1.150     raeburn  13220:                     }
                   13221:                 }
1.210     raeburn  13222:             }
1.150     raeburn  13223:         }
                   13224:         my $ishomedom;
1.171     raeburn  13225:         if (&Apache::lonnet::host_domain($balancer) eq $dom) {
                   13226:             $ishomedom = 1;
1.150     raeburn  13227:         }
                   13228:         if (ref($alltypes) eq 'ARRAY') {
                   13229:             foreach my $type (@{$alltypes}) {
                   13230:                 my $rule;
1.210     raeburn  13231:                 unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150     raeburn  13232:                          (!$ishomedom)) {
1.171     raeburn  13233:                     $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
                   13234:                 }
                   13235:                 if ($rule eq 'specific') {
1.255     raeburn  13236:                     my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
                   13237:                     if (exists($servers{$specifiedhost})) { 
                   13238:                         $rule = $specifiedhost;
                   13239:                     }
1.150     raeburn  13240:                 }
1.171     raeburn  13241:                 $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
                   13242:                 if (ref($currrules{$balancer}) eq 'HASH') {
                   13243:                     if ($rule ne $currrules{$balancer}{$type}) {
                   13244:                         $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150     raeburn  13245:                     }
                   13246:                 } elsif ($rule ne '') {
1.171     raeburn  13247:                     $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150     raeburn  13248:                 }
                   13249:             }
                   13250:         }
1.171     raeburn  13251:     }
                   13252:     my $nochgmsg = &mt('No changes made to Load Balancer settings.');
                   13253:     if ((keys(%changes) > 0) || ($saveloadbalancing)) {
                   13254:         unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
                   13255:             $defaultshash{'loadbalancing'} = {};
                   13256:         }
                   13257:         my $putresult = &Apache::lonnet::put_dom('configuration',
                   13258:                                                  \%defaultshash,$dom);
                   13259:         if ($putresult eq 'ok') {
                   13260:             if (keys(%changes) > 0) {
1.252     raeburn  13261:                 my %toupdate;
1.171     raeburn  13262:                 if (ref($changes{'delete'}) eq 'ARRAY') {
                   13263:                     foreach my $balancer (sort(@{$changes{'delete'}})) {
                   13264:                         $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.252     raeburn  13265:                         $toupdate{$balancer} = 1;
1.150     raeburn  13266:                     }
1.171     raeburn  13267:                 }
                   13268:                 if (ref($changes{'add'}) eq 'ARRAY') {
1.210     raeburn  13269:                     foreach my $balancer (sort(@{$changes{'add'}})) {
1.171     raeburn  13270:                         $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.252     raeburn  13271:                         $toupdate{$balancer} = 1;
1.171     raeburn  13272:                     }
                   13273:                 }
                   13274:                 if (ref($changes{'curr'}) eq 'HASH') {
                   13275:                     foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.253     raeburn  13276:                         $toupdate{$balancer} = 1;
1.171     raeburn  13277:                         if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
                   13278:                             if ($changes{'curr'}{$balancer}{'targets'}) {
                   13279:                                 my %offloadstr;
                   13280:                                 foreach my $sparetype (@sparestypes) {
                   13281:                                     if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
                   13282:                                         if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
                   13283:                                             $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
                   13284:                                         }
                   13285:                                     }
1.150     raeburn  13286:                                 }
1.171     raeburn  13287:                                 if (keys(%offloadstr) == 0) {
                   13288:                                     $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150     raeburn  13289:                                 } else {
1.171     raeburn  13290:                                     my $showoffload;
                   13291:                                     foreach my $sparetype (@sparestypes) {
                   13292:                                         $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>:&nbsp;';
                   13293:                                         if (defined($offloadstr{$sparetype})) {
                   13294:                                             $showoffload .= $offloadstr{$sparetype};
                   13295:                                         } else {
                   13296:                                             $showoffload .= &mt('None');
                   13297:                                         }
                   13298:                                         $showoffload .= ('&nbsp;'x3);
                   13299:                                     }
                   13300:                                     $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150     raeburn  13301:                                 }
                   13302:                             }
                   13303:                         }
1.171     raeburn  13304:                         if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
                   13305:                             if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
                   13306:                                 foreach my $type (@{$alltypes}) {
                   13307:                                     if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
                   13308:                                         my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
                   13309:                                         my $balancetext;
                   13310:                                         if ($rule eq '') {
                   13311:                                             $balancetext =  $ruletitles{'default'};
1.209     raeburn  13312:                                         } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.254     raeburn  13313:                                                  ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) { 
                   13314:                                             if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.252     raeburn  13315:                                                 foreach my $sparetype (@sparestypes) {
                   13316:                                                     if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
                   13317:                                                         map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
                   13318:                                                     }
                   13319:                                                 }
1.253     raeburn  13320:                                                 foreach my $item (@{$alltypes}) {
                   13321:                                                     next if ($item =~  /^_LC_ipchange/);
                   13322:                                                     my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
                   13323:                                                     if ($hasrule eq 'homeserver') {
                   13324:                                                         map { $toupdate{$_} = 1; } (keys(%libraryservers));
                   13325:                                                     } else {
                   13326:                                                         unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
                   13327:                                                             if ($servers{$hasrule}) {
                   13328:                                                                 $toupdate{$hasrule} = 1;
                   13329:                                                             }
                   13330:                                                         }
                   13331:                                                     }
                   13332:                                                 }
1.254     raeburn  13333:                                                 if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
                   13334:                                                     $balancetext =  $ruletitles{$rule};
                   13335:                                                 } else {
                   13336:                                                     my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
                   13337:                                                     $balancetext = $ruletitles{'particular'}.' '.$receiver;
                   13338:                                                     if ($receiver) {
                   13339:                                                         $toupdate{$receiver};
                   13340:                                                     }
                   13341:                                                 }
                   13342:                                             } else {
                   13343:                                                 $balancetext =  $ruletitles{$rule};
1.252     raeburn  13344:                                             }
1.171     raeburn  13345:                                         } else {
                   13346:                                             $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
                   13347:                                         }
1.210     raeburn  13348:                                         $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150     raeburn  13349:                                     }
                   13350:                                 }
                   13351:                             }
                   13352:                         }
1.252     raeburn  13353:                         if (keys(%toupdate)) {
                   13354:                             my %thismachine;
                   13355:                             my $updatedhere;
                   13356:                             my $cachetime = 60*60*24;
                   13357:                             map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
                   13358:                             foreach my $lonhost (keys(%toupdate)) {
                   13359:                                 if ($thismachine{$lonhost}) {
                   13360:                                     unless ($updatedhere) {
                   13361:                                         &Apache::lonnet::do_cache_new('loadbalancing',$dom,
                   13362:                                                                       $defaultshash{'loadbalancing'},
                   13363:                                                                       $cachetime);
                   13364:                                         $updatedhere = 1;
                   13365:                                     }
                   13366:                                 } else {
                   13367:                                     my $cachekey = &escape('loadbalancing').':'.&escape($dom);
                   13368:                                     &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
                   13369:                                 }
                   13370:                             }
                   13371:                         }
1.150     raeburn  13372:                     }
1.171     raeburn  13373:                 }
                   13374:                 if ($resulttext ne '') {
                   13375:                     $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150     raeburn  13376:                 } else {
                   13377:                     $resulttext = $nochgmsg;
                   13378:                 }
                   13379:             } else {
1.171     raeburn  13380:                 $resulttext = $nochgmsg;
1.150     raeburn  13381:             }
                   13382:         } else {
1.171     raeburn  13383:             $resulttext = '<span class="LC_error">'.
                   13384:                           &mt('An error occurred: [_1]',$putresult).'</span>';
1.150     raeburn  13385:         }
                   13386:     } else {
1.171     raeburn  13387:         $resulttext = $nochgmsg;
1.150     raeburn  13388:     }
                   13389:     return $resulttext;
                   13390: }
                   13391: 
1.48      raeburn  13392: sub recurse_check {
                   13393:     my ($chkcats,$categories,$depth,$name) = @_;
                   13394:     if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
                   13395:         my $chg = 0;
                   13396:         for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
                   13397:             my $category = $chkcats->[$depth]{$name}[$j];
                   13398:             my $item;
                   13399:             if ($category eq '') {
                   13400:                 $chg ++;
                   13401:             } else {
                   13402:                 my $deeper = $depth + 1;
                   13403:                 $item = &escape($category).':'.&escape($name).':'.$depth;
                   13404:                 if ($chg) {
                   13405:                     $categories->{$item} -= $chg;
                   13406:                 }
                   13407:                 &recurse_check($chkcats,$categories,$deeper,$category);
                   13408:                 $deeper --;
                   13409:             }
                   13410:         }
                   13411:     }
                   13412:     return;
                   13413: }
                   13414: 
                   13415: sub recurse_cat_deletes {
                   13416:     my ($item,$coursecategories,$deletions) = @_;
                   13417:     my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
                   13418:     my $subdepth = $depth + 1;
                   13419:     if (ref($coursecategories) eq 'HASH') {
                   13420:         foreach my $subitem (keys(%{$coursecategories})) {
                   13421:             my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
                   13422:             if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
                   13423:                 delete($coursecategories->{$subitem});
                   13424:                 $deletions->{$subitem} = 1;
                   13425:                 &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168     raeburn  13426:             }
1.48      raeburn  13427:         }
                   13428:     }
                   13429:     return;
                   13430: }
                   13431: 
1.125     raeburn  13432: sub get_active_dcs {
                   13433:     my ($dom) = @_;
1.191     raeburn  13434:     my $now = time;
                   13435:     my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
1.125     raeburn  13436:     my %domcoords;
                   13437:     my $numdcs = 0;
                   13438:     foreach my $server (keys(%dompersonnel)) {
                   13439:         foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
                   13440:             my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
1.191     raeburn  13441:             $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
1.125     raeburn  13442:         }
                   13443:     }
                   13444:     return %domcoords;
                   13445: }
                   13446: 
                   13447: sub active_dc_picker {
1.191     raeburn  13448:     my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.235     raeburn  13449:     my %domcoords = &get_active_dcs($dom);
1.191     raeburn  13450:     my @domcoord = keys(%domcoords);
                   13451:     if (keys(%currhash)) {
                   13452:         foreach my $dc (keys(%currhash)) {
                   13453:             unless (exists($domcoords{$dc})) {
                   13454:                 push(@domcoord,$dc);
                   13455:             }
                   13456:         }
                   13457:     }
                   13458:     @domcoord = sort(@domcoord);
1.210     raeburn  13459:     my $numdcs = scalar(@domcoord);
1.191     raeburn  13460:     my $rows = 0;
                   13461:     my $table;
1.125     raeburn  13462:     if ($numdcs > 1) {
1.191     raeburn  13463:         $table = '<table>';
                   13464:         for (my $i=0; $i<@domcoord; $i++) {
1.125     raeburn  13465:             my $rem = $i%($numinrow);
                   13466:             if ($rem == 0) {
                   13467:                 if ($i > 0) {
1.191     raeburn  13468:                     $table .= '</tr>';
1.125     raeburn  13469:                 }
1.191     raeburn  13470:                 $table .= '<tr>';
                   13471:                 $rows ++;
1.125     raeburn  13472:             }
1.191     raeburn  13473:             my $check = '';
                   13474:             if ($inputtype eq 'radio') {
                   13475:                 if (keys(%currhash) == 0) {
                   13476:                     if (!$i) {
                   13477:                         $check = ' checked="checked"';
                   13478:                     }
                   13479:                 } elsif (exists($currhash{$domcoord[$i]})) {
                   13480:                     $check = ' checked="checked"';
                   13481:                 }
                   13482:             } else {
                   13483:                 if (exists($currhash{$domcoord[$i]})) {
                   13484:                     $check = ' checked="checked"';
1.125     raeburn  13485:                 }
                   13486:             }
1.191     raeburn  13487:             if ($i == @domcoord - 1) {
1.125     raeburn  13488:                 my $colsleft = $numinrow - $rem;
                   13489:                 if ($colsleft > 1) {
1.191     raeburn  13490:                     $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125     raeburn  13491:                 } else {
1.191     raeburn  13492:                     $table .= '<td class="LC_left_item">';
1.125     raeburn  13493:                 }
                   13494:             } else {
1.191     raeburn  13495:                 $table .= '<td class="LC_left_item">';
                   13496:             }
                   13497:             my ($dcname,$dcdom) = split(':',$domcoord[$i]);
                   13498:             my $user = &Apache::loncommon::plainname($dcname,$dcdom);
                   13499:             $table .= '<span class="LC_nobreak"><label>'.
                   13500:                       '<input type="'.$inputtype.'" name="'.$name.'"'.
                   13501:                       ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
                   13502:             if ($user ne $dcname.':'.$dcdom) {
1.219     raeburn  13503:                 $table .=  ' ('.$dcname.':'.$dcdom.')';
1.191     raeburn  13504:             }
1.219     raeburn  13505:             $table .= '</label></span></td>';
1.191     raeburn  13506:         }
                   13507:         $table .= '</tr></table>';
                   13508:     } elsif ($numdcs == 1) {
1.219     raeburn  13509:         my ($dcname,$dcdom) = split(':',$domcoord[0]);
                   13510:         my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191     raeburn  13511:         if ($inputtype eq 'radio') {
1.247     raeburn  13512:             $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.219     raeburn  13513:             if ($user ne $dcname.':'.$dcdom) {
                   13514:                 $table .=  ' ('.$dcname.':'.$dcdom.')';
                   13515:             }
1.191     raeburn  13516:         } else {
                   13517:             my $check;
                   13518:             if (exists($currhash{$domcoord[0]})) {
                   13519:                 $check = ' checked="checked"';
1.125     raeburn  13520:             }
1.247     raeburn  13521:             $table = '<span class="LC_nobreak"><label>'.
                   13522:                      '<input type="checkbox" name="'.$name.'" '.
                   13523:                      'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.219     raeburn  13524:             if ($user ne $dcname.':'.$dcdom) {
1.220     raeburn  13525:                 $table .=  ' ('.$dcname.':'.$dcdom.')';
1.219     raeburn  13526:             }
1.220     raeburn  13527:             $table .= '</label></span>';
1.191     raeburn  13528:             $rows ++;
1.125     raeburn  13529:         }
                   13530:     }
1.191     raeburn  13531:     return ($numdcs,$table,$rows);
1.125     raeburn  13532: }
                   13533: 
1.137     raeburn  13534: sub usersession_titles {
                   13535:     return &Apache::lonlocal::texthash(
                   13536:                hosted => 'Hosting of sessions for users from other domains on servers in this domain',
                   13537:                remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145     raeburn  13538:                spares => 'Servers offloaded to, when busy',
1.137     raeburn  13539:                version => 'LON-CAPA version requirement',
1.138     raeburn  13540:                excludedomain => 'Allow all, but exclude specific domains',
                   13541:                includedomain => 'Deny all, but include specific domains',
1.145     raeburn  13542:                primary => 'Primary (checked first)',
1.154     raeburn  13543:                default => 'Default',
1.137     raeburn  13544:            );
                   13545: }
                   13546: 
1.152     raeburn  13547: sub id_for_thisdom {
                   13548:     my (%servers) = @_;
                   13549:     my %altids;
                   13550:     foreach my $server (keys(%servers)) {
                   13551:         my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
                   13552:         if ($serverhome ne $server) {
                   13553:             $altids{$serverhome} = $server;
                   13554:         }
                   13555:     }
                   13556:     return %altids;
                   13557: }
                   13558: 
1.150     raeburn  13559: sub count_servers {
                   13560:     my ($currbalancer,%servers) = @_;
                   13561:     my (@spares,$numspares);
                   13562:     foreach my $lonhost (sort(keys(%servers))) {
                   13563:         next if ($currbalancer eq $lonhost);
                   13564:         push(@spares,$lonhost);
                   13565:     }
                   13566:     if ($currbalancer) {
                   13567:         $numspares = scalar(@spares);
                   13568:     } else {
                   13569:         $numspares = scalar(@spares) - 1;
                   13570:     }
                   13571:     return ($numspares,@spares);
                   13572: }
                   13573: 
                   13574: sub lonbalance_targets_js {
1.171     raeburn  13575:     my ($dom,$types,$servers,$settings) = @_;
1.150     raeburn  13576:     my $select = &mt('Select');
                   13577:     my ($alltargets,$allishome,$allinsttypes,@alltypes);
                   13578:     if (ref($servers) eq 'HASH') {
                   13579:         $alltargets = join("','",sort(keys(%{$servers})));
                   13580:         my @homedoms;
                   13581:         foreach my $server (sort(keys(%{$servers}))) {
                   13582:             if (&Apache::lonnet::host_domain($server) eq $dom) {
                   13583:                 push(@homedoms,'1');
                   13584:             } else {
                   13585:                 push(@homedoms,'0');
                   13586:             }
                   13587:         }
                   13588:         $allishome = join("','",@homedoms);
                   13589:     }
                   13590:     if (ref($types) eq 'ARRAY') {
                   13591:         if (@{$types} > 0) {
                   13592:             @alltypes = @{$types};
                   13593:         }
                   13594:     }
                   13595:     push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
                   13596:     $allinsttypes = join("','",@alltypes);
1.171     raeburn  13597:     my (%currbalancer,%currtargets,%currrules,%existing);
                   13598:     if (ref($settings) eq 'HASH') {
                   13599:         %existing = %{$settings};
                   13600:     }
                   13601:     &get_loadbalancers_config($servers,\%existing,\%currbalancer,
                   13602:                               \%currtargets,\%currrules);
1.210     raeburn  13603:     my $balancers = join("','",sort(keys(%currbalancer)));
1.150     raeburn  13604:     return <<"END";
                   13605: 
                   13606: <script type="text/javascript">
                   13607: // <![CDATA[
                   13608: 
1.171     raeburn  13609: currBalancers = new Array('$balancers');
                   13610: 
                   13611: function toggleTargets(balnum) {
                   13612:     var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
                   13613:     var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
                   13614:     var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
                   13615:     var prevbalancer = prevhostitem.value;
                   13616:     var baltotal = document.getElementById('loadbalancing_total').value;
                   13617:     prevhostitem.value = balancer;
                   13618:     if (prevbalancer != '') {
                   13619:         var prevIdx = currBalancers.indexOf(prevbalancer);
                   13620:         if (prevIdx != -1) {
                   13621:             currBalancers.splice(prevIdx,1);
                   13622:         }
                   13623:     }
1.150     raeburn  13624:     if (balancer == '') {
1.171     raeburn  13625:         hideSpares(balnum);
1.150     raeburn  13626:     } else {
1.171     raeburn  13627:         var currIdx = currBalancers.indexOf(balancer);
                   13628:         if (currIdx == -1) {
                   13629:             currBalancers.push(balancer);
                   13630:         }
1.150     raeburn  13631:         var homedoms = new Array('$allishome');
1.171     raeburn  13632:         var ishomedom = homedoms[lonhostitem.selectedIndex];
                   13633:         showSpares(balancer,ishomedom,balnum);
1.150     raeburn  13634:     }
1.171     raeburn  13635:     balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150     raeburn  13636:     return;
                   13637: }
                   13638: 
1.171     raeburn  13639: function showSpares(balancer,ishomedom,balnum) {
1.150     raeburn  13640:     var alltargets = new Array('$alltargets');
                   13641:     var insttypes = new Array('$allinsttypes');
1.151     raeburn  13642:     var offloadtypes = new Array('primary','default');
                   13643: 
1.171     raeburn  13644:     document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
                   13645:     document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152     raeburn  13646:  
1.151     raeburn  13647:     for (var i=0; i<offloadtypes.length; i++) {
                   13648:         var count = 0;
                   13649:         for (var j=0; j<alltargets.length; j++) {
                   13650:             if (alltargets[j] != balancer) {
1.171     raeburn  13651:                 var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
                   13652:                 item.value = alltargets[j];
                   13653:                 item.style.textAlign='left';
                   13654:                 item.style.textFace='normal';
                   13655:                 document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
                   13656:                 if (currBalancers.indexOf(alltargets[j]) == -1) {
                   13657:                     item.disabled = '';
                   13658:                 } else {
                   13659:                     item.disabled = 'disabled';
                   13660:                     item.checked = false;
                   13661:                 }
1.151     raeburn  13662:                 count ++;
                   13663:             }
1.150     raeburn  13664:         }
                   13665:     }
1.151     raeburn  13666:     for (var k=0; k<insttypes.length; k++) {
                   13667:         if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150     raeburn  13668:             if (ishomedom == 1) {
1.171     raeburn  13669:                 document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
                   13670:                 document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150     raeburn  13671:             } else {
1.171     raeburn  13672:                 document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
                   13673:                 document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150     raeburn  13674:             }
                   13675:         } else {
1.171     raeburn  13676:             document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
                   13677:             document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150     raeburn  13678:         }
1.151     raeburn  13679:         if ((insttypes[k] != '_LC_external') && 
                   13680:             ((insttypes[k] != '_LC_internetdom') ||
                   13681:              ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171     raeburn  13682:             var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
                   13683:             item.options.length = 0;
                   13684:             item.options[0] = new Option("","",true,true);
1.210     raeburn  13685:             var idx = 0;
1.151     raeburn  13686:             for (var m=0; m<alltargets.length; m++) {
1.171     raeburn  13687:                 if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
                   13688:                     idx ++;
                   13689:                     item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150     raeburn  13690:                 }
                   13691:             }
                   13692:         }
                   13693:     }
                   13694:     return;
                   13695: }
                   13696: 
1.171     raeburn  13697: function hideSpares(balnum) {
1.150     raeburn  13698:     var alltargets = new Array('$alltargets');
                   13699:     var insttypes = new Array('$allinsttypes');
                   13700:     var offloadtypes = new Array('primary','default');
                   13701: 
1.171     raeburn  13702:     document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
                   13703:     document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150     raeburn  13704: 
                   13705:     var total = alltargets.length - 1;
                   13706:     for (var i=0; i<offloadtypes; i++) {
                   13707:         for (var j=0; j<total; j++) {
1.171     raeburn  13708:            document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
                   13709:            document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
                   13710:            document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151     raeburn  13711:         }
1.150     raeburn  13712:     }
                   13713:     for (var k=0; k<insttypes.length; k++) {
1.171     raeburn  13714:         document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
                   13715:         document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151     raeburn  13716:         if (insttypes[k] != '_LC_external') {
1.171     raeburn  13717:             document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
                   13718:             document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150     raeburn  13719:         }
                   13720:     }
                   13721:     return;
                   13722: }
                   13723: 
1.171     raeburn  13724: function checkOffloads(item,balnum,type) {
1.150     raeburn  13725:     var alltargets = new Array('$alltargets');
                   13726:     var offloadtypes = new Array('primary','default');
                   13727:     if (item.checked) {
                   13728:         var total = alltargets.length - 1;
                   13729:         var other;
                   13730:         if (type == offloadtypes[0]) {
1.151     raeburn  13731:             other = offloadtypes[1];
1.150     raeburn  13732:         } else {
1.151     raeburn  13733:             other = offloadtypes[0];
1.150     raeburn  13734:         }
                   13735:         for (var i=0; i<total; i++) {
1.171     raeburn  13736:             var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150     raeburn  13737:             if (server == item.value) {
1.171     raeburn  13738:                 if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
                   13739:                     document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150     raeburn  13740:                 }
                   13741:             }
                   13742:         }
                   13743:     }
                   13744:     return;
                   13745: }
                   13746: 
1.171     raeburn  13747: function singleServerToggle(balnum,type) {
                   13748:     var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150     raeburn  13749:     if (offloadtoSelIdx == 0) {
1.171     raeburn  13750:         document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
                   13751:         document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150     raeburn  13752: 
                   13753:     } else {
1.171     raeburn  13754:         document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
                   13755:         document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150     raeburn  13756:     }
                   13757:     return;
                   13758: }
                   13759: 
1.171     raeburn  13760: function balanceruleChange(formname,balnum,type) {
1.150     raeburn  13761:     if (type == '_LC_external') {
1.171     raeburn  13762:         return;
1.150     raeburn  13763:     }
1.171     raeburn  13764:     var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150     raeburn  13765:     for (var i=0; i<typesRules.length; i++) {
                   13766:         if (formname.elements[typesRules[i]].checked) {
                   13767:             if (formname.elements[typesRules[i]].value != 'specific') {
1.171     raeburn  13768:                 document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
                   13769:                 document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150     raeburn  13770:             } else {
1.171     raeburn  13771:                 document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
                   13772:             }
                   13773:         }
                   13774:     }
                   13775:     return;
                   13776: }
                   13777: 
                   13778: function balancerDeleteChange(balnum) {
                   13779:     var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
                   13780:     var baltotal = document.getElementById('loadbalancing_total').value;
                   13781:     var addtarget;
                   13782:     var removetarget;
                   13783:     var action = 'delete';
                   13784:     if (document.getElementById('loadbalancing_delete_'+balnum)) {
                   13785:         var lonhost = hostitem.value;
                   13786:         var currIdx = currBalancers.indexOf(lonhost);
                   13787:         if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
                   13788:             if (currIdx != -1) {
                   13789:                 currBalancers.splice(currIdx,1);
                   13790:             }
                   13791:             addtarget = lonhost;
                   13792:         } else {
                   13793:             if (currIdx == -1) {
                   13794:                 currBalancers.push(lonhost);
                   13795:             }
                   13796:             removetarget = lonhost;
                   13797:             action = 'undelete';
                   13798:         }
                   13799:         balancerChange(balnum,baltotal,action,addtarget,removetarget);
                   13800:     }
                   13801:     return;
                   13802: }
                   13803: 
                   13804: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
                   13805:     if (baltotal > 1) {
                   13806:         var offloadtypes = new Array('primary','default');
                   13807:         var alltargets = new Array('$alltargets');
                   13808:         var insttypes = new Array('$allinsttypes');
                   13809:         for (var i=0; i<baltotal; i++) {
                   13810:             if (i != balnum) {
                   13811:                 for (var j=0; j<offloadtypes.length; j++) {
                   13812:                     var total = alltargets.length - 1;
                   13813:                     for (var k=0; k<total; k++) {
                   13814:                         var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
                   13815:                         var server = serveritem.value;
                   13816:                         if ((action == 'delete') || (action == 'change' && addtarget != ''))  {
                   13817:                             if (server == addtarget) {
                   13818:                                 serveritem.disabled = '';
                   13819:                             }
                   13820:                         }
                   13821:                         if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
                   13822:                             if (server == removetarget) {
                   13823:                                 serveritem.disabled = 'disabled';
                   13824:                                 serveritem.checked = false;
                   13825:                             }
                   13826:                         }
                   13827:                     }
                   13828:                 }
                   13829:                 for (var j=0; j<insttypes.length; j++) {
                   13830:                     if (insttypes[j] != '_LC_external') {
                   13831:                         if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
                   13832:                             var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
                   13833:                             var currSel = singleserver.selectedIndex;
                   13834:                             var currVal = singleserver.options[currSel].value;
                   13835:                             if ((action == 'delete') || (action == 'change' && addtarget != '')) {
                   13836:                                 var numoptions = singleserver.options.length;
                   13837:                                 var needsnew = 1;
                   13838:                                 for (var k=0; k<numoptions; k++) {
                   13839:                                     if (singleserver.options[k] == addtarget) {
                   13840:                                         needsnew = 0;
                   13841:                                         break;
                   13842:                                     }
                   13843:                                 }
                   13844:                                 if (needsnew == 1) {
                   13845:                                     singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
                   13846:                                 }
                   13847:                             }
                   13848:                             if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
                   13849:                                 singleserver.options.length = 0;
                   13850:                                 if ((currVal) && (currVal != removetarget)) {
                   13851:                                     singleserver.options[0] = new Option("","",false,false);
                   13852:                                 } else {
                   13853:                                     singleserver.options[0] = new Option("","",true,true);
                   13854:                                 }
                   13855:                                 var idx = 0;
                   13856:                                 for (var m=0; m<alltargets.length; m++) {
                   13857:                                     if (currBalancers.indexOf(alltargets[m]) == -1) {
                   13858:                                         idx ++;
                   13859:                                         if (currVal == alltargets[m]) {
                   13860:                                             singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
                   13861:                                         } else {
                   13862:                                             singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
                   13863:                                         }
                   13864:                                     }
                   13865:                                 }
                   13866:                             }
                   13867:                         }
                   13868:                     }
                   13869:                 }
1.150     raeburn  13870:             }
                   13871:         }
                   13872:     }
                   13873:     return;
                   13874: }
                   13875: 
1.152     raeburn  13876: // ]]>
                   13877: </script>
                   13878: 
                   13879: END
                   13880: }
                   13881: 
                   13882: sub new_spares_js {
                   13883:     my @sparestypes = ('primary','default');
                   13884:     my $types = join("','",@sparestypes);
                   13885:     my $select = &mt('Select');
                   13886:     return <<"END";
                   13887: 
                   13888: <script type="text/javascript">
                   13889: // <![CDATA[
                   13890: 
                   13891: function updateNewSpares(formname,lonhost) {
                   13892:     var types = new Array('$types');
                   13893:     var include = new Array();
                   13894:     var exclude = new Array();
                   13895:     for (var i=0; i<types.length; i++) {
                   13896:         var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
                   13897:         for (var j=0; j<spareboxes.length; j++) {
                   13898:             if (formname.elements[spareboxes[j]].checked) {
                   13899:                 exclude.push(formname.elements[spareboxes[j]].value);
                   13900:             } else {
                   13901:                 include.push(formname.elements[spareboxes[j]].value);
                   13902:             }
                   13903:         }
                   13904:     }
                   13905:     for (var i=0; i<types.length; i++) {
                   13906:         var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
                   13907:         var selIdx = newSpare.selectedIndex;
                   13908:         var currnew = newSpare.options[selIdx].value;
                   13909:         var okSpares = new Array();
                   13910:         for (var j=0; j<newSpare.options.length; j++) {
                   13911:             var possible = newSpare.options[j].value;
                   13912:             if (possible != '') {
                   13913:                 if (exclude.indexOf(possible) == -1) {
                   13914:                     okSpares.push(possible);
                   13915:                 } else {
                   13916:                     if (currnew == possible) {
                   13917:                         selIdx = 0;
                   13918:                     }
                   13919:                 }
                   13920:             }
                   13921:         }
                   13922:         for (var k=0; k<include.length; k++) {
                   13923:             if (okSpares.indexOf(include[k]) == -1) {
                   13924:                 okSpares.push(include[k]);
                   13925:             }
                   13926:         }
                   13927:         okSpares.sort();
                   13928:         newSpare.options.length = 0;
                   13929:         if (selIdx == 0) {
                   13930:             newSpare.options[0] = new Option("$select","",true,true);
                   13931:         } else {
                   13932:             newSpare.options[0] = new Option("$select","",false,false);
                   13933:         }
                   13934:         for (var m=0; m<okSpares.length; m++) {
                   13935:             var idx = m+1;
                   13936:             var selThis = 0;
                   13937:             if (selIdx != 0) {
                   13938:                 if (okSpares[m] == currnew) {
                   13939:                     selThis = 1;
                   13940:                 }
                   13941:             }
                   13942:             if (selThis == 1) {
                   13943:                 newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
                   13944:             } else {
                   13945:                 newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
                   13946:             }
                   13947:         }
                   13948:     }
                   13949:     return;
                   13950: }
                   13951: 
                   13952: function checkNewSpares(lonhost,type) {
                   13953:     var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
                   13954:     var chosen =  newSpare.options[newSpare.selectedIndex].value;
                   13955:     if (chosen != '') { 
                   13956:         var othertype;
                   13957:         var othernewSpare;
                   13958:         if (type == 'primary') {
                   13959:             othernewSpare = document.getElementById('newspare_default_'+lonhost);
                   13960:         }
                   13961:         if (type == 'default') {
                   13962:             othernewSpare = document.getElementById('newspare_primary_'+lonhost);
                   13963:         }
                   13964:         if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
                   13965:             othernewSpare.selectedIndex = 0;
                   13966:         }
                   13967:     }
                   13968:     return;
                   13969: }
                   13970: 
                   13971: // ]]>
                   13972: </script>
                   13973: 
                   13974: END
                   13975: 
                   13976: }
                   13977: 
                   13978: sub common_domprefs_js {
                   13979:     return <<"END";
                   13980: 
                   13981: <script type="text/javascript">
                   13982: // <![CDATA[
                   13983: 
1.150     raeburn  13984: function getIndicesByName(formname,item) {
1.152     raeburn  13985:     var group = new Array();
1.150     raeburn  13986:     for (var i=0;i<formname.elements.length;i++) {
                   13987:         if (formname.elements[i].name == item) {
1.152     raeburn  13988:             group.push(formname.elements[i].id);
1.150     raeburn  13989:         }
                   13990:     }
1.152     raeburn  13991:     return group;
1.150     raeburn  13992: }
                   13993: 
                   13994: // ]]>
                   13995: </script>
                   13996: 
                   13997: END
1.152     raeburn  13998: 
1.150     raeburn  13999: }
                   14000: 
1.165     raeburn  14001: sub recaptcha_js {
                   14002:     my %lt = &captcha_phrases();
                   14003:     return <<"END";
                   14004: 
                   14005: <script type="text/javascript">
                   14006: // <![CDATA[
                   14007: 
                   14008: function updateCaptcha(caller,context) {
                   14009:     var privitem;
                   14010:     var pubitem;
                   14011:     var privtext;
                   14012:     var pubtext;
1.269     raeburn  14013:     var versionitem;
                   14014:     var versiontext;
1.165     raeburn  14015:     if (document.getElementById(context+'_recaptchapub')) {
                   14016:         pubitem = document.getElementById(context+'_recaptchapub');
                   14017:     } else {
                   14018:         return;
                   14019:     }
                   14020:     if (document.getElementById(context+'_recaptchapriv')) {
                   14021:         privitem = document.getElementById(context+'_recaptchapriv');
                   14022:     } else {
                   14023:         return;
                   14024:     }
                   14025:     if (document.getElementById(context+'_recaptchapubtxt')) {
                   14026:         pubtext = document.getElementById(context+'_recaptchapubtxt');
                   14027:     } else {
                   14028:         return;
                   14029:     }
                   14030:     if (document.getElementById(context+'_recaptchaprivtxt')) {
                   14031:         privtext = document.getElementById(context+'_recaptchaprivtxt');
                   14032:     } else {
                   14033:         return;
                   14034:     }
1.269     raeburn  14035:     if (document.getElementById(context+'_recaptchaversion')) {
                   14036:         versionitem = document.getElementById(context+'_recaptchaversion');
                   14037:     } else {
                   14038:         return;
                   14039:     }
                   14040:     if (document.getElementById(context+'_recaptchavertxt')) {
                   14041:         versiontext = document.getElementById(context+'_recaptchavertxt');
                   14042:     } else {
                   14043:         return;
                   14044:     }
1.165     raeburn  14045:     if (caller.checked) {
                   14046:         if (caller.value == 'recaptcha') {
                   14047:             pubitem.type = 'text';
                   14048:             privitem.type = 'text';
                   14049:             pubitem.size = '40';
                   14050:             privitem.size = '40';
                   14051:             pubtext.innerHTML = "$lt{'pub'}";
                   14052:             privtext.innerHTML = "$lt{'priv'}";
1.269     raeburn  14053:             versionitem.type = 'text';
                   14054:             versionitem.size = '3';
                   14055:             versiontext.innerHTML = "$lt{'ver'}"; 
1.165     raeburn  14056:         } else {
                   14057:             pubitem.type = 'hidden';
                   14058:             privitem.type = 'hidden';
1.269     raeburn  14059:             versionitem.type = 'hidden';
1.165     raeburn  14060:             pubtext.innerHTML = '';
                   14061:             privtext.innerHTML = '';
1.269     raeburn  14062:             versiontext.innerHTML = '';
1.165     raeburn  14063:         }
                   14064:     }
                   14065:     return;
                   14066: }
                   14067: 
                   14068: // ]]>
                   14069: </script>
                   14070: 
                   14071: END
                   14072: 
                   14073: }
                   14074: 
1.236     raeburn  14075: sub toggle_display_js {
1.192     raeburn  14076:     return <<"END";
                   14077: 
                   14078: <script type="text/javascript">
                   14079: // <![CDATA[
                   14080: 
1.236     raeburn  14081: function toggleDisplay(domForm,caller) {
                   14082:     if (document.getElementById(caller)) {
                   14083:         var divitem = document.getElementById(caller);
                   14084:         var optionsElement = domForm.coursecredits;
1.264     raeburn  14085:         var checkval = 1;
                   14086:         var dispval = 'block';
1.236     raeburn  14087:         if (caller == 'emailoptions') {
                   14088:             optionsElement = domForm.cancreate_email; 
                   14089:         }
1.257     raeburn  14090:         if (caller == 'studentsubmission') {
                   14091:             optionsElement = domForm.postsubmit;
                   14092:         }
1.264     raeburn  14093:         if (caller == 'cloneinstcode') {
                   14094:             optionsElement = domForm.canclone;
                   14095:             checkval = 'instcode';
                   14096:         }
1.236     raeburn  14097:         if (optionsElement.length) {
1.192     raeburn  14098:             var currval;
1.236     raeburn  14099:             for (var i=0; i<optionsElement.length; i++) {
                   14100:                 if (optionsElement[i].checked) {
                   14101:                    currval = optionsElement[i].value;
1.192     raeburn  14102:                 }
                   14103:             }
1.264     raeburn  14104:             if (currval == checkval) {
                   14105:                 divitem.style.display = dispval;
1.192     raeburn  14106:             } else {
1.236     raeburn  14107:                 divitem.style.display = 'none';
1.192     raeburn  14108:             }
                   14109:         }
                   14110:     }
                   14111:     return;
                   14112: }
                   14113: 
                   14114: // ]]>
                   14115: </script>
                   14116: 
                   14117: END
                   14118: 
                   14119: }
                   14120: 
1.165     raeburn  14121: sub captcha_phrases {
                   14122:     return &Apache::lonlocal::texthash (
                   14123:                  priv => 'Private key',
                   14124:                  pub  => 'Public key',
                   14125:                  original  => 'original (CAPTCHA)',
                   14126:                  recaptcha => 'successor (ReCAPTCHA)',
                   14127:                  notused   => 'unused',
1.269     raeburn  14128:                  ver => 'ReCAPTCHA version (1 or 2)', 
1.165     raeburn  14129:     );
                   14130: }
                   14131: 
1.205     raeburn  14132: sub devalidate_remote_domconfs {
1.212     raeburn  14133:     my ($dom,$cachekeys) = @_;
                   14134:     return unless (ref($cachekeys) eq 'HASH');
1.205     raeburn  14135:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
                   14136:     my %thismachine;
                   14137:     map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.267     raeburn  14138:     my @posscached = ('domainconfig','domdefaults','ltitools');
1.260     raeburn  14139:     if (keys(%servers)) {
1.205     raeburn  14140:         foreach my $server (keys(%servers)) {
                   14141:             next if ($thismachine{$server});
1.212     raeburn  14142:             my @cached;
                   14143:             foreach my $name (@posscached) {
                   14144:                 if ($cachekeys->{$name}) {
                   14145:                     push(@cached,&escape($name).':'.&escape($dom));
                   14146:                 }
                   14147:             }
                   14148:             if (@cached) {
                   14149:                 &Apache::lonnet::remote_devalidate_cache($server,\@cached);
                   14150:             }
1.205     raeburn  14151:         }
                   14152:     }
                   14153:     return;
                   14154: }
                   14155: 
1.3       raeburn  14156: 1;

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