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

1.1       raeburn     1: # The LearningOnline Network with CAPA
                      2: # Handler to set domain-wide configuration settings
                      3: #
1.160.6.90! raeburn     4: # $Id: domainprefs.pm,v 1.160.6.89 2018/09/15 15:15:32 raeburn Exp $
1.160.6.40  raeburn     5: #
1.1       raeburn     6: # Copyright Michigan State University Board of Trustees
                      7: #
                      8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                      9: #
                     10: # LON-CAPA is free software; you can redistribute it and/or modify
                     11: # it under the terms of the GNU General Public License as published by
                     12: # the Free Software Foundation; either version 2 of the License, or
                     13: # (at your option) any later version.
                     14: #
                     15: # LON-CAPA is distributed in the hope that it will be useful,
                     16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     18: # GNU General Public License for more details.
                     19: #
                     20: # You should have received a copy of the GNU General Public License
                     21: # along with LON-CAPA; if not, write to the Free Software
1.160.6.78  raeburn    22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     23: #
1.1       raeburn    24: # /home/httpd/html/adm/gpl.txt
                     25: #
                     26: # http://www.lon-capa.org/
                     27: #
                     28: #
                     29: ###############################################################
                     30: ##############################################################
                     31: 
1.101     raeburn    32: =pod
                     33: 
                     34: =head1 NAME
                     35: 
                     36: Apache::domainprefs.pm
                     37: 
                     38: =head1 SYNOPSIS
                     39: 
                     40: Handles configuration of a LON-CAPA domain.  
                     41: 
                     42: This is part of the LearningOnline Network with CAPA project
                     43: described at http://www.lon-capa.org.
                     44: 
                     45: 
                     46: =head1 OVERVIEW
                     47: 
                     48: Each institution using LON-CAPA will typically have a single domain designated 
1.160.6.13  raeburn    49: for use by individuals affiliated with the institution.  Accordingly, each domain
1.101     raeburn    50: may define a default set of logos and a color scheme which can be used to "brand"
                     51: the LON-CAPA instance. In addition, an institution will typically have a language
                     52: and timezone which are used for the majority of courses.
                     53: 
                     54: LON-CAPA provides a mechanism to display and modify these defaults, as well as a 
                     55: host of other domain-wide settings which determine the types of functionality
                     56: available to users and courses in the domain.
                     57: 
                     58: There is also a mechanism to configure cataloging of courses in the domain, and
                     59: controls on the operation of automated processes which govern such things as
                     60: roster updates, user directory updates and processing of course requests.
                     61: 
                     62: The domain coordination manual which is built dynamically on install/update of 
                     63: LON-CAPA from the relevant help items provides more information about domain 
                     64: configuration.
                     65: 
                     66: Most of the domain settings are stored in the configuration.db GDBM file which is
                     67: housed on the primary library server for the domain in /home/httpd/lonUsers/$dom,
                     68: where $dom is the domain.  The configuration.db stores settings in a number of 
                     69: frozen hashes of hashes.  In a few cases, domain information must be uploaded to
                     70: the domain as files (e.g., image files for logos etc., or plain text files for
                     71: bubblesheet formats).  In this case the domainprefs.pm must be running in a user
                     72: session hosted on the primary library server in the domain, as these files are 
                     73: stored in author space belonging to a special $dom-domainconfig user.   
                     74: 
                     75: domainprefs.pm in combination with lonconfigsettings.pm will retrieve and display
                     76: the current settings, and provides an interface to make modifications.
                     77: 
                     78: =head1 SUBROUTINES
                     79: 
                     80: =over
                     81: 
                     82: =item print_quotas()
                     83: 
                     84: Inputs: 4 
                     85: 
                     86: $dom,$settings,$rowtotal,$action.
                     87: 
                     88: $dom is the domain, $settings is a reference to a hash of current settings for
                     89: the current context, $rowtotal is a reference to the scalar used to record the 
1.160.6.27  raeburn    90: number of rows displayed on the page, and $action is the context (quotas, 
1.160.6.5  raeburn    91: requestcourses or requestauthor).
1.101     raeburn    92: 
                     93: The print_quotas routine was orginally created to display/store information
                     94: about default quota sizes for portfolio spaces for the different types of 
                     95: institutional affiliation in the domain (e.g., Faculty, Staff, Student etc.), 
                     96: but is now also used to manage availability of user tools: 
                     97: i.e., blogs, aboutme page, and portfolios, and the course request tool,
1.160.6.20  raeburn    98: used by course owners to request creation of a course, and to display/store
1.160.6.34  raeburn    99: default quota sizes for Authoring Spaces.
1.160.6.20  raeburn   100: 
1.101     raeburn   101: Outputs: 1
                    102: 
                    103: $datatable  - HTML containing form elements which allow settings to be changed. 
                    104: 
                    105: In the case of course requests, radio buttons are displayed for each institutional
                    106: affiliate type (and also default, and _LC_adv) for each of the course types 
1.160.6.30  raeburn   107: (official, unofficial, community, and textbook).  In each case the radio buttons 
                    108: allow the selection of one of four values:
1.101     raeburn   109: 
1.104     raeburn   110: 0, approval, validate, autolimit=N (where N is blank, or a positive integer).
1.101     raeburn   111: which have the following effects:
                    112: 
                    113: 0
                    114: 
                    115: =over
                    116: 
                    117: - course requests are not allowed for this course types/affiliation
                    118: 
                    119: =back
                    120: 
1.104     raeburn   121: approval 
1.101     raeburn   122: 
                    123: =over 
                    124: 
                    125: - course requests must be approved by a Doman Coordinator in the 
                    126: course's domain
                    127: 
                    128: =back
                    129: 
                    130: validate 
                    131: 
                    132: =over
                    133: 
                    134: - an institutional validation (e.g., check requestor is instructor
                    135: of record) needs to be passed before the course will be created.  The required
                    136: validation is in localenroll.pm on the primary library server for the course 
                    137: domain.
                    138: 
                    139: =back
                    140: 
                    141: autolimit 
                    142: 
                    143: =over
                    144:  
1.143     raeburn   145: - course requests will be processed automatically up to a limit of
1.101     raeburn   146: N requests for the course type for the particular requestor.
                    147: If N is undefined, there is no limit to the number of course requests
                    148: which a course owner may submit and have processed automatically. 
                    149: 
                    150: =back
                    151: 
                    152: =item modify_quotas() 
                    153: 
                    154: =back
                    155: 
                    156: =cut
                    157: 
1.1       raeburn   158: package Apache::domainprefs;
                    159: 
                    160: use strict;
                    161: use Apache::Constants qw(:common :http);
                    162: use Apache::lonnet;
                    163: use Apache::loncommon();
                    164: use Apache::lonhtmlcommon();
                    165: use Apache::lonlocal;
1.43      raeburn   166: use Apache::lonmsg();
1.91      raeburn   167: use Apache::lonconfigsettings;
1.160.6.37  raeburn   168: use Apache::lonuserutils();
1.160.6.39  raeburn   169: use Apache::loncoursequeueadmin();
1.69      raeburn   170: use LONCAPA qw(:DEFAULT :match);
1.6       raeburn   171: use LONCAPA::Enrollment;
1.81      raeburn   172: use LONCAPA::lonauthcgi();
1.9       raeburn   173: use File::Copy;
1.43      raeburn   174: use Locale::Language;
1.62      raeburn   175: use DateTime::TimeZone;
1.68      raeburn   176: use DateTime::Locale;
1.1       raeburn   177: 
1.155     raeburn   178: my $registered_cleanup;
                    179: my $modified_urls;
                    180: 
1.1       raeburn   181: sub handler {
                    182:     my $r=shift;
                    183:     if ($r->header_only) {
                    184:         &Apache::loncommon::content_type($r,'text/html');
                    185:         $r->send_http_header;
                    186:         return OK;
                    187:     }
                    188: 
1.91      raeburn   189:     my $context = 'domain';
1.1       raeburn   190:     my $dom = $env{'request.role.domain'};
1.5       albertel  191:     my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1       raeburn   192:     if (&Apache::lonnet::allowed('mau',$dom)) {
                    193:         &Apache::loncommon::content_type($r,'text/html');
                    194:         $r->send_http_header;
                    195:     } else {
                    196:         $env{'user.error.msg'}=
                    197:         "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
                    198:         return HTTP_NOT_ACCEPTABLE;
                    199:     }
1.155     raeburn   200: 
                    201:     $registered_cleanup=0;
                    202:     @{$modified_urls}=();
                    203: 
1.1       raeburn   204:     &Apache::lonhtmlcommon::clear_breadcrumbs();
                    205:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.58      raeburn   206:                                             ['phase','actions']);
1.30      raeburn   207:     my $phase = 'pickactions';
1.3       raeburn   208:     if ( exists($env{'form.phase'}) ) {
                    209:         $phase = $env{'form.phase'};
                    210:     }
1.150     raeburn   211:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.3       raeburn   212:     my %domconfig =
1.6       raeburn   213:       &Apache::lonnet::get_dom('configuration',['login','rolecolors',
1.125     raeburn   214:                 'quotas','autoenroll','autoupdate','autocreate',
                    215:                 'directorysrch','usercreation','usermodification',
                    216:                 'contacts','defaults','scantron','coursecategories',
1.160.6.73  raeburn   217:                 'serverstatuses','requestcourses','helpsettings',
                    218:                 'coursedefaults','usersessions','loadbalancing',
                    219:                 'requestauthor','selfenrollment','inststatus'],$dom);
1.43      raeburn   220:     my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll',
1.125     raeburn   221:                        'autoupdate','autocreate','directorysrch','contacts',
1.160.6.34  raeburn   222:                        'usercreation','selfcreation','usermodification','scantron',
1.160.6.5  raeburn   223:                        'requestcourses','requestauthor','coursecategories',
1.160.6.73  raeburn   224:                        'serverstatuses','helpsettings','coursedefaults',
                    225:                        'selfenrollment','usersessions');
1.160.6.7  raeburn   226:     my %existing;
                    227:     if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
                    228:         %existing = %{$domconfig{'loadbalancing'}};
                    229:     }
                    230:     if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.150     raeburn   231:         push(@prefs_order,'loadbalancing');
                    232:     }
1.30      raeburn   233:     my %prefs = (
                    234:         'rolecolors' =>
                    235:                    { text => 'Default color schemes',
1.67      raeburn   236:                      help => 'Domain_Configuration_Color_Schemes',
1.30      raeburn   237:                      header => [{col1 => 'Student Settings',
                    238:                                  col2 => '',},
                    239:                                 {col1 => 'Coordinator Settings',
                    240:                                  col2 => '',},
                    241:                                 {col1 => 'Author Settings',
                    242:                                  col2 => '',},
                    243:                                 {col1 => 'Administrator Settings',
                    244:                                  col2 => '',}],
1.160.6.37  raeburn   245:                       print => \&print_rolecolors,
                    246:                       modify => \&modify_rolecolors,
1.30      raeburn   247:                     },
1.110     raeburn   248:         'login' =>
1.30      raeburn   249:                     { text => 'Log-in page options',
1.67      raeburn   250:                       help => 'Domain_Configuration_Login_Page',
1.160.6.5  raeburn   251:                       header => [{col1 => 'Log-in Page Items',
                    252:                                   col2 => '',},
                    253:                                  {col1 => 'Log-in Help',
1.160.6.56  raeburn   254:                                   col2 => 'Value'},
                    255:                                  {col1 => 'Custom HTML in document head',
1.160.6.5  raeburn   256:                                   col2 => 'Value'}],
1.160.6.37  raeburn   257:                       print => \&print_login,
                    258:                       modify => \&modify_login,
1.30      raeburn   259:                     },
1.43      raeburn   260:         'defaults' => 
1.160.6.40  raeburn   261:                     { text => 'Default authentication/language/timezone/portal/types',
1.67      raeburn   262:                       help => 'Domain_Configuration_LangTZAuth',
1.43      raeburn   263:                       header => [{col1 => 'Setting',
1.160.6.40  raeburn   264:                                   col2 => 'Value'},
1.160.6.80  raeburn   265:                                  {col1 => 'Internal Authentication',
                    266:                                   col2 => 'Value'},
1.160.6.40  raeburn   267:                                  {col1 => 'Institutional user types',
                    268:                                   col2 => 'Assignable to e-mail usernames'}],
1.160.6.37  raeburn   269:                       print => \&print_defaults,
                    270:                       modify => \&modify_defaults,
1.43      raeburn   271:                     },
1.30      raeburn   272:         'quotas' => 
1.160.6.20  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.160.6.28  raeburn   277:                                   col3 => 'Quotas, MB; (Authoring requires role)',}],
1.160.6.37  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.160.6.37  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.160.6.35  raeburn   297:                                  col2 => 'Updatable user data'}],
1.160.6.37  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.160.6.37  raeburn   306:                      print => \&print_autocreate,
                    307:                      modify => \&modify_autocreate,
1.125     raeburn   308:                   },
1.30      raeburn   309:         'directorysrch' => 
1.160.6.72  raeburn   310:                   { text => 'Directory searches',
1.67      raeburn   311:                     help => 'Domain_Configuration_InstDirectory_Search',
1.160.6.72  raeburn   312:                     header => [{col1 => 'Institutional Directory Setting',
                    313:                                 col2 => 'Value',},
                    314:                                {col1 => 'LON-CAPA Directory Setting',
1.30      raeburn   315:                                 col2 => 'Value',}],
1.160.6.37  raeburn   316:                     print => \&print_directorysrch,
                    317:                     modify => \&modify_directorysrch,
1.30      raeburn   318:                   },
                    319:         'contacts' =>
1.160.6.78  raeburn   320:                   { text => 'E-mail addresses and helpform',
1.67      raeburn   321:                     help => 'Domain_Configuration_Contact_Info',
1.160.6.78  raeburn   322:                     header => [{col1 => 'Default e-mail addresses',
                    323:                                 col2 => 'Value',},
                    324:                                {col1 => 'Recipient(s) for notifications',
                    325:                                 col2 => 'Value',},
                    326:                                {col1 => 'Ask helpdesk form settings',
                    327:                                 col2 => 'Value',},],
1.160.6.37  raeburn   328:                     print => \&print_contacts,
                    329:                     modify => \&modify_contacts,
1.30      raeburn   330:                   },
                    331:         'usercreation' => 
                    332:                   { text => 'User creation',
1.67      raeburn   333:                     help => 'Domain_Configuration_User_Creation',
1.43      raeburn   334:                     header => [{col1 => 'Format rule type',
                    335:                                 col2 => 'Format rules in force'},
1.34      raeburn   336:                                {col1 => 'User account creation',
                    337:                                 col2 => 'Usernames which may be created',},
1.30      raeburn   338:                                {col1 => 'Context',
1.43      raeburn   339:                                 col2 => 'Assignable authentication types'}],
1.160.6.37  raeburn   340:                     print => \&print_usercreation,
                    341:                     modify => \&modify_usercreation,
1.30      raeburn   342:                   },
1.160.6.34  raeburn   343:         'selfcreation' => 
                    344:                   { text => 'Users self-creating accounts',
                    345:                     help => 'Domain_Configuration_Self_Creation', 
                    346:                     header => [{col1 => 'Self-creation with institutional username',
                    347:                                 col2 => 'Enabled?'},
                    348:                                {col1 => 'Institutional user type (login/SSO self-creation)',
                    349:                                 col2 => 'Information user can enter'},
                    350:                                {col1 => 'Self-creation with e-mail as username',
                    351:                                 col2 => 'Settings'}],
1.160.6.37  raeburn   352:                     print => \&print_selfcreation,
                    353:                     modify => \&modify_selfcreation,
1.160.6.34  raeburn   354:                   },
1.69      raeburn   355:         'usermodification' =>
1.33      raeburn   356:                   { text => 'User modification',
1.67      raeburn   357:                     help => 'Domain_Configuration_User_Modification',
1.33      raeburn   358:                     header => [{col1 => 'Target user has role',
1.160.6.35  raeburn   359:                                 col2 => 'User information updatable in author context'},
1.33      raeburn   360:                                {col1 => 'Target user has role',
1.160.6.35  raeburn   361:                                 col2 => 'User information updatable in course context'}],
1.160.6.37  raeburn   362:                     print => \&print_usermodification,
                    363:                     modify => \&modify_usermodification,
1.33      raeburn   364:                   },
1.69      raeburn   365:         'scantron' =>
1.95      www       366:                   { text => 'Bubblesheet format file',
1.67      raeburn   367:                     help => 'Domain_Configuration_Scantron_Format',
1.46      raeburn   368:                     header => [ {col1 => 'Item',
                    369:                                  col2 => '',
                    370:                               }],
1.160.6.37  raeburn   371:                     print => \&print_scantron,
                    372:                     modify => \&modify_scantron,
1.46      raeburn   373:                   },
1.86      raeburn   374:         'requestcourses' => 
                    375:                  {text => 'Request creation of courses',
                    376:                   help => 'Domain_Configuration_Request_Courses',
                    377:                   header => [{col1 => 'User affiliation',
1.102     raeburn   378:                               col2 => 'Availability/Processing of requests',},
                    379:                              {col1 => 'Setting',
1.160.6.30  raeburn   380:                               col2 => 'Value'},
                    381:                              {col1 => 'Available textbooks',
1.160.6.39  raeburn   382:                               col2 => ''},
1.160.6.46  raeburn   383:                              {col1 => 'Available templates',
                    384:                               col2 => ''},
1.160.6.39  raeburn   385:                              {col1 => 'Validation (not official courses)',
                    386:                               col2 => 'Value'},],
1.160.6.37  raeburn   387:                   print => \&print_quotas,
                    388:                   modify => \&modify_quotas,
1.86      raeburn   389:                  },
1.160.6.5  raeburn   390:         'requestauthor' =>
1.160.6.34  raeburn   391:                  {text => 'Request Authoring Space',
1.160.6.5  raeburn   392:                   help => 'Domain_Configuration_Request_Author',
                    393:                   header => [{col1 => 'User affiliation',
                    394:                               col2 => 'Availability/Processing of requests',},
                    395:                              {col1 => 'Setting',
                    396:                               col2 => 'Value'}],
1.160.6.37  raeburn   397:                   print => \&print_quotas,
                    398:                   modify => \&modify_quotas,
1.160.6.5  raeburn   399:                  },
1.69      raeburn   400:         'coursecategories' =>
1.120     raeburn   401:                   { text => 'Cataloging of courses/communities',
1.67      raeburn   402:                     help => 'Domain_Configuration_Cataloging_Courses',
1.160.6.42  raeburn   403:                     header => [{col1 => 'Catalog type/availability',
                    404:                                 col2 => '',},
                    405:                                {col1 => 'Category settings for standard catalog',
1.57      raeburn   406:                                 col2 => '',},
                    407:                                {col1 => 'Categories',
                    408:                                 col2 => '',
                    409:                                }],
1.160.6.37  raeburn   410:                     print => \&print_coursecategories,
                    411:                     modify => \&modify_coursecategories,
1.69      raeburn   412:                   },
                    413:         'serverstatuses' =>
1.77      raeburn   414:                  {text   => 'Access to server status pages',
1.69      raeburn   415:                   help   => 'Domain_Configuration_Server_Status',
                    416:                   header => [{col1 => 'Status Page',
                    417:                               col2 => 'Other named users',
                    418:                               col3 => 'Specific IPs',
                    419:                             }],
1.160.6.37  raeburn   420:                   print => \&print_serverstatuses,
                    421:                   modify => \&modify_serverstatuses,
1.69      raeburn   422:                  },
1.160.6.73  raeburn   423:         'helpsettings' =>
                    424:                  {text   => 'Support settings',
                    425:                   help   => 'Domain_Configuration_Help_Settings',
                    426:                   header => [{col1 => 'Help Page Settings (logged-in users)',
                    427:                               col2 => 'Value'},
                    428:                              {col1 => 'Helpdesk Roles',
                    429:                               col2 => 'Settings'},],
                    430:                   print  => \&print_helpsettings,
                    431:                   modify => \&modify_helpsettings,
                    432:                  },
1.160.6.39  raeburn   433:         'coursedefaults' => 
1.160.6.16  raeburn   434:                  {text => 'Course/Community defaults',
                    435:                   help => 'Domain_Configuration_Course_Defaults',
1.160.6.57  raeburn   436:                   header => [{col1 => 'Defaults which can be overridden in each course by a CC',
                    437:                               col2 => 'Value',},
                    438:                              {col1 => 'Defaults which can be overridden for each course by a DC',
1.160.6.16  raeburn   439:                               col2 => 'Value',},],
1.160.6.37  raeburn   440:                   print => \&print_coursedefaults,
                    441:                   modify => \&modify_coursedefaults,
                    442:                  },
1.160.6.39  raeburn   443:         'selfenrollment' => 
1.160.6.37  raeburn   444:                  {text   => 'Self-enrollment in Course/Community',
                    445:                   help   => 'Domain_Configuration_Selfenrollment',
                    446:                   header => [{col1 => 'Configuration Rights',
                    447:                               col2 => 'Configured by Course Personnel or Domain Coordinator?'},
                    448:                              {col1 => 'Defaults',
                    449:                               col2 => 'Value'},
                    450:                              {col1 => 'Self-enrollment validation (optional)',
                    451:                               col2 => 'Value'},],
                    452:                   print => \&print_selfenrollment,
                    453:                   modify => \&modify_selfenrollment,
1.160.6.16  raeburn   454:                  },
1.141     raeburn   455:         'usersessions' =>
1.145     raeburn   456:                  {text  => 'User session hosting/offloading',
1.137     raeburn   457:                   help  => 'Domain_Configuration_User_Sessions',
1.145     raeburn   458:                   header => [{col1 => 'Domain server',
                    459:                               col2 => 'Servers to offload sessions to when busy'},
                    460:                              {col1 => 'Hosting of users from other domains',
1.137     raeburn   461:                               col2 => 'Rules'},
                    462:                              {col1 => "Hosting domain's own users elsewhere",
                    463:                               col2 => 'Rules'}],
1.160.6.37  raeburn   464:                   print => \&print_usersessions,
                    465:                   modify => \&modify_usersessions,
1.137     raeburn   466:                  },
1.160.6.78  raeburn   467:         'loadbalancing' =>
1.160.6.7  raeburn   468:                  {text  => 'Dedicated Load Balancer(s)',
1.150     raeburn   469:                   help  => 'Domain_Configuration_Load_Balancing',
1.160.6.7  raeburn   470:                   header => [{col1 => 'Balancers',
1.150     raeburn   471:                               col2 => 'Default destinations',
1.160.6.13  raeburn   472:                               col3 => 'User affiliation',
1.150     raeburn   473:                               col4 => 'Overrides'},
                    474:                             ],
1.160.6.37  raeburn   475:                   print => \&print_loadbalancing,
                    476:                   modify => \&modify_loadbalancing,
1.150     raeburn   477:                  },
1.3       raeburn   478:     );
1.110     raeburn   479:     if (keys(%servers) > 1) {
                    480:         $prefs{'login'}  = { text   => 'Log-in page options',
                    481:                              help   => 'Domain_Configuration_Login_Page',
                    482:                             header => [{col1 => 'Log-in Service',
                    483:                                         col2 => 'Server Setting',},
                    484:                                        {col1 => 'Log-in Page Items',
1.160.6.5  raeburn   485:                                         col2 => ''},
                    486:                                        {col1 => 'Log-in Help',
1.160.6.56  raeburn   487:                                         col2 => 'Value'},
                    488:                                        {col1 => 'Custom HTML in document head',
1.160.6.5  raeburn   489:                                         col2 => 'Value'}],
1.160.6.37  raeburn   490:                             print => \&print_login,
                    491:                             modify => \&modify_login,
1.110     raeburn   492:                            };
                    493:     }
1.160.6.13  raeburn   494: 
1.6       raeburn   495:     my @roles = ('student','coordinator','author','admin');
1.30      raeburn   496:     my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3       raeburn   497:     &Apache::lonhtmlcommon::add_breadcrumb
1.30      raeburn   498:     ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133     raeburn   499:       text=>"Settings to display/modify"});
1.9       raeburn   500:     my $confname = $dom.'-domainconfig';
1.160.6.13  raeburn   501: 
1.3       raeburn   502:     if ($phase eq 'process') {
1.160.6.27  raeburn   503:         my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
                    504:                                                               \%prefs,\%domconfig,$confname,\@roles);
1.160.6.33  raeburn   505:         if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.160.6.24  raeburn   506:             $r->rflush();
1.160.6.27  raeburn   507:             &devalidate_remote_domconfs($dom,$result);
1.160.6.24  raeburn   508:         }
1.30      raeburn   509:     } elsif ($phase eq 'display') {
1.160.6.16  raeburn   510:         my $js = &recaptcha_js().
1.160.6.40  raeburn   511:                  &toggle_display_js();
1.160.6.7  raeburn   512:         if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152     raeburn   513:             my ($othertitle,$usertypes,$types) =
                    514:                 &Apache::loncommon::sorted_inst_types($dom);
1.160.6.7  raeburn   515:             $js .= &lonbalance_targets_js($dom,$types,\%servers,
                    516:                                           $domconfig{'loadbalancing'}).
1.160.6.6  raeburn   517:                    &new_spares_js().
                    518:                    &common_domprefs_js().
                    519:                    &Apache::loncommon::javascript_array_indexof();
1.152     raeburn   520:         }
1.160.6.30  raeburn   521:         if (grep(/^requestcourses$/,@actions)) {
                    522:             my $javascript_validations;
                    523:             my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'}); 
                    524:             $js .= <<END;
                    525: <script type="text/javascript">
                    526: $javascript_validations
                    527: </script>
                    528: $coursebrowserjs
                    529: END
                    530:         }
1.160.6.78  raeburn   531:         if (grep(/^contacts$/,@actions)) {
                    532:             $js .= &contacts_javascript();
                    533:         }
1.150     raeburn   534:         &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1       raeburn   535:     } else {
1.160.6.11  raeburn   536: # check if domconfig user exists for the domain.
                    537:         my $servadm = $r->dir_config('lonAdmEMail');
1.160.6.26  raeburn   538:         my ($configuserok,$author_ok,$switchserver) =
1.160.6.11  raeburn   539:             &config_check($dom,$confname,$servadm);
                    540:         unless ($configuserok eq 'ok') {
                    541:             &Apache::lonconfigsettings::print_header($r,$phase,$context);
                    542:             $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
                    543:                           $confname).
                    544:                       '<br />'
                    545:             );
                    546:             if ($switchserver) {
                    547:                 $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
                    548:                           '<br />'.
                    549:                           &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
                    550:                           '<br />'.
                    551:                           &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).
                    552:                           '<br />'.
                    553:                           &mt('To do that now, use the following link: [_1]',$switchserver)
                    554:                 );
                    555:             } else {
                    556:                 $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.').
                    557:                           '<br />'.
                    558:                           &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
                    559:                 );
                    560:             }
                    561:             $r->print(&Apache::loncommon::end_page());
                    562:             return OK;
                    563:         }
1.21      raeburn   564:         if (keys(%domconfig) == 0) {
                    565:             my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29      raeburn   566:             my @ids=&Apache::lonnet::current_machine_ids();
                    567:             if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21      raeburn   568:                 my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41      raeburn   569:                 my @loginimages = ('img','logo','domlogo','login');
1.21      raeburn   570:                 my $custom_img_count = 0;
                    571:                 foreach my $img (@loginimages) {
                    572:                     if ($designhash{$dom.'.login.'.$img} ne '') {
                    573:                         $custom_img_count ++;
                    574:                     }
                    575:                 }
                    576:                 foreach my $role (@roles) {
                    577:                     if ($designhash{$dom.'.'.$role.'.img'} ne '') {
                    578:                         $custom_img_count ++;
                    579:                     }
                    580:                 }
                    581:                 if ($custom_img_count > 0) {
1.94      raeburn   582:                     &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21      raeburn   583:                     my $switch_server = &check_switchserver($dom,$confname);
1.29      raeburn   584:                     $r->print(
                    585:     &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
                    586:     &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
                    587:     &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 />'.
                    588:     &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
                    589:                     if ($switch_server) {
1.30      raeburn   590:                         $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29      raeburn   591:                     }
1.91      raeburn   592:                     $r->print(&Apache::loncommon::end_page());
1.21      raeburn   593:                     return OK;
                    594:                 }
                    595:             }
                    596:         }
1.91      raeburn   597:         &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3       raeburn   598:     }
                    599:     return OK;
                    600: }
                    601: 
                    602: sub process_changes {
1.160.6.24  raeburn   603:     my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92      raeburn   604:     my %domconfig;
                    605:     if (ref($values) eq 'HASH') {
                    606:         %domconfig = %{$values};
                    607:     }
1.3       raeburn   608:     my $output;
                    609:     if ($action eq 'login') {
1.160.6.24  raeburn   610:         $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6       raeburn   611:     } elsif ($action eq 'rolecolors') {
1.9       raeburn   612:         $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.160.6.24  raeburn   613:                                      $lastactref,%domconfig);
1.3       raeburn   614:     } elsif ($action eq 'quotas') {
1.160.6.30  raeburn   615:         $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3       raeburn   616:     } elsif ($action eq 'autoenroll') {
1.160.6.24  raeburn   617:         $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3       raeburn   618:     } elsif ($action eq 'autoupdate') {
                    619:         $output = &modify_autoupdate($dom,%domconfig);
1.125     raeburn   620:     } elsif ($action eq 'autocreate') {
                    621:         $output = &modify_autocreate($dom,%domconfig);
1.23      raeburn   622:     } elsif ($action eq 'directorysrch') {
1.160.6.81  raeburn   623:         $output = &modify_directorysrch($dom,$lastactref,%domconfig);
1.27      raeburn   624:     } elsif ($action eq 'usercreation') {
1.28      raeburn   625:         $output = &modify_usercreation($dom,%domconfig);
1.160.6.34  raeburn   626:     } elsif ($action eq 'selfcreation') {
                    627:         $output = &modify_selfcreation($dom,%domconfig);
1.33      raeburn   628:     } elsif ($action eq 'usermodification') {
                    629:         $output = &modify_usermodification($dom,%domconfig);
1.28      raeburn   630:     } elsif ($action eq 'contacts') {
1.160.6.24  raeburn   631:         $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43      raeburn   632:     } elsif ($action eq 'defaults') {
1.160.6.27  raeburn   633:         $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46      raeburn   634:     } elsif ($action eq 'scantron') {
1.160.6.24  raeburn   635:         $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48      raeburn   636:     } elsif ($action eq 'coursecategories') {
1.160.6.43  raeburn   637:         $output = &modify_coursecategories($dom,$lastactref,%domconfig);
1.69      raeburn   638:     } elsif ($action eq 'serverstatuses') {
                    639:         $output = &modify_serverstatuses($dom,%domconfig);
1.86      raeburn   640:     } elsif ($action eq 'requestcourses') {
1.160.6.30  raeburn   641:         $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.160.6.5  raeburn   642:     } elsif ($action eq 'requestauthor') {
1.160.6.30  raeburn   643:         $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.160.6.73  raeburn   644:     } elsif ($action eq 'helpsettings') {
1.160.6.77  raeburn   645:         $output = &modify_helpsettings($r,$dom,$confname,$lastactref,%domconfig);
1.160.6.16  raeburn   646:     } elsif ($action eq 'coursedefaults') {
1.160.6.27  raeburn   647:         $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.160.6.37  raeburn   648:     } elsif ($action eq 'selfenrollment') {
                    649:         $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
1.137     raeburn   650:     } elsif ($action eq 'usersessions') {
1.160.6.27  raeburn   651:         $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150     raeburn   652:     } elsif ($action eq 'loadbalancing') {
                    653:         $output = &modify_loadbalancing($dom,%domconfig);
1.3       raeburn   654:     }
                    655:     return $output;
                    656: }
                    657: 
                    658: sub print_config_box {
1.9       raeburn   659:     my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30      raeburn   660:     my $rowtotal = 0;
1.49      raeburn   661:     my $output;
                    662:     if ($action eq 'coursecategories') {
                    663:         $output = &coursecategories_javascript($settings);
1.160.6.40  raeburn   664:     } elsif ($action eq 'defaults') {
                    665:         $output = &defaults_javascript($settings); 
1.160.6.73  raeburn   666:     } elsif ($action eq 'helpsettings') {
                    667:         my (%privs,%levelscurrent);
                    668:         my %full=();
                    669:         my %levels=(
                    670:                      course => {},
                    671:                      domain => {},
                    672:                      system => {},
                    673:                    );
                    674:         my $context = 'domain';
                    675:         my $crstype = 'Course';
                    676:         my $formname = 'display';
                    677:         &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
                    678:         my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
                    679:         $output =
                    680:             &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,\%full,
                    681:                                                       \@templateroles);
1.91      raeburn   682:     }
1.160.6.40  raeburn   683:     $output .=
1.30      raeburn   684:          '<table class="LC_nested_outer">
1.3       raeburn   685:           <tr>
1.66      raeburn   686:            <th align="left" valign="middle"><span class="LC_nobreak">'.
                    687:            &mt($item->{text}).'&nbsp;'.
                    688:            &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
                    689:           '</tr>';
1.30      raeburn   690:     $rowtotal ++;
1.110     raeburn   691:     my $numheaders = 1;
                    692:     if (ref($item->{'header'}) eq 'ARRAY') {
                    693:         $numheaders = scalar(@{$item->{'header'}});
                    694:     }
                    695:     if ($numheaders > 1) {
1.64      raeburn   696:         my $colspan = '';
1.145     raeburn   697:         my $rightcolspan = '';
1.160.6.42  raeburn   698:         if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.160.6.72  raeburn   699:             ($action eq 'directorysrch') ||
1.160.6.56  raeburn   700:             (($action eq 'login') && ($numheaders < 4))) {
1.64      raeburn   701:             $colspan = ' colspan="2"';
                    702:         }
1.145     raeburn   703:         if ($action eq 'usersessions') {
                    704:             $rightcolspan = ' colspan="3"'; 
                    705:         }
1.30      raeburn   706:         $output .= '
1.3       raeburn   707:           <tr>
                    708:            <td>
                    709:             <table class="LC_nested">
                    710:              <tr class="LC_info_row">
1.59      bisitz    711:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145     raeburn   712:               <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30      raeburn   713:              </tr>';
1.69      raeburn   714:         $rowtotal ++;
1.160.6.37  raeburn   715:         if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.160.6.57  raeburn   716:             ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
1.160.6.73  raeburn   717:             ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'directorysrch') ||
1.160.6.78  raeburn   718:             ($action eq 'helpsettings') || ($action eq 'contacts')) {
1.160.6.37  raeburn   719:             $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.57      raeburn   720:         } elsif ($action eq 'coursecategories') {
1.160.6.37  raeburn   721:             $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.110     raeburn   722:         } elsif ($action eq 'login') {
1.160.6.56  raeburn   723:             if ($numheaders == 4) {
1.160.6.5  raeburn   724:                 $colspan = ' colspan="2"';
                    725:                 $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
                    726:             } else {
                    727:                 $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
                    728:             }
1.160.6.37  raeburn   729:         } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102     raeburn   730:             $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122     jms       731:         } elsif ($action eq 'rolecolors') {
1.30      raeburn   732:             $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.160.6.2  raeburn   733:         }
1.30      raeburn   734:         $output .= '
1.6       raeburn   735:            </table>
                    736:           </td>
                    737:          </tr>
                    738:          <tr>
                    739:            <td>
                    740:             <table class="LC_nested">
                    741:              <tr class="LC_info_row">
1.160.6.37  raeburn   742:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59      bisitz    743:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30      raeburn   744:              </tr>';
                    745:             $rowtotal ++;
1.160.6.37  raeburn   746:         if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
                    747:             ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.160.6.78  raeburn   748:             ($action eq 'usersessions') || ($action eq 'coursecategories') ||
1.160.6.80  raeburn   749:             ($action eq 'contacts') || ($action eq 'defaults')) {
1.160.6.42  raeburn   750:             if ($action eq 'coursecategories') {
                    751:                 $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
                    752:                 $colspan = ' colspan="2"';
                    753:             } else {
                    754:                 $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
                    755:             }
                    756:             $output .= '
1.63      raeburn   757:            </table>
                    758:           </td>
                    759:          </tr>
                    760:          <tr>
                    761:            <td>
                    762:             <table class="LC_nested">
                    763:              <tr class="LC_info_row">
                    764:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.160.6.34  raeburn   765:               <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.160.6.42  raeburn   766:              </tr>'."\n";
                    767:             if ($action eq 'coursecategories') {
                    768:                 $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
                    769:             } else {
                    770:                 $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
                    771:             }
1.63      raeburn   772:             $rowtotal ++;
1.160.6.57  raeburn   773:         } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
1.160.6.73  raeburn   774:                  ($action eq 'defaults') || ($action eq 'directorysrch') ||
                    775:                  ($action eq 'helpsettings')) {
1.160.6.37  raeburn   776:             $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.110     raeburn   777:         } elsif ($action eq 'login') {
1.160.6.56  raeburn   778:             if ($numheaders == 4) {
1.160.6.5  raeburn   779:                 $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
                    780:            </table>
                    781:           </td>
                    782:          </tr>
                    783:          <tr>
                    784:            <td>
                    785:             <table class="LC_nested">
                    786:              <tr class="LC_info_row">
                    787:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.160.6.30  raeburn   788:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.160.6.5  raeburn   789:                        &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
                    790:                 $rowtotal ++;
                    791:             } else {
                    792:                 $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
                    793:             }
1.160.6.56  raeburn   794:             $output .= '
                    795:            </table>
                    796:           </td>
                    797:          </tr>
                    798:          <tr>
                    799:            <td>
                    800:             <table class="LC_nested">
                    801:              <tr class="LC_info_row">';
                    802:             if ($numheaders == 4) {
                    803:                 $output .= '
                    804:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
                    805:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
                    806:              </tr>';
                    807:             } else {
                    808:                 $output .= '
                    809:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
                    810:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
                    811:              </tr>';
                    812:             }
                    813:             $rowtotal ++;
                    814:             $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal);
1.102     raeburn   815:         } elsif ($action eq 'requestcourses') {
1.160.6.50  raeburn   816:             $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
                    817:             $rowtotal ++;
                    818:             $output .= &print_studentcode($settings,\$rowtotal).'
1.160.6.30  raeburn   819:            </table>
                    820:           </td>
                    821:          </tr>
                    822:          <tr>
                    823:            <td>
                    824:             <table class="LC_nested">
                    825:              <tr class="LC_info_row">
                    826:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
                    827:               <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.160.6.46  raeburn   828:                        &textbookcourses_javascript($settings).
                    829:                        &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
                    830:             </table>
                    831:            </td>
                    832:           </tr>
                    833:          <tr>
                    834:            <td>
                    835:             <table class="LC_nested">
                    836:              <tr class="LC_info_row">
                    837:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
                    838:               <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
                    839:                        &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.160.6.39  raeburn   840:             </table>
                    841:            </td>
                    842:           </tr>
                    843:           <tr>
                    844:            <td>
                    845:             <table class="LC_nested">
                    846:              <tr class="LC_info_row">
1.160.6.46  raeburn   847:               <td class="LC_left_item"'.$colspan.' valign="top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
                    848:               <td class="LC_right_item" valign="top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.160.6.39  raeburn   849:              </tr>'.
                    850:             &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.160.6.5  raeburn   851:         } elsif ($action eq 'requestauthor') {
                    852:             $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.160.6.50  raeburn   853:             $rowtotal ++;
1.122     jms       854:         } elsif ($action eq 'rolecolors') {
1.30      raeburn   855:             $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6       raeburn   856:            </table>
                    857:           </td>
                    858:          </tr>
                    859:          <tr>
                    860:            <td>
                    861:             <table class="LC_nested">
                    862:              <tr class="LC_info_row">
1.69      raeburn   863:               <td class="LC_left_item"'.$colspan.' valign="top">'.
                    864:                &mt($item->{'header'}->[2]->{'col1'}).'</td>
                    865:               <td class="LC_right_item" valign="top">'.
                    866:                &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3       raeburn   867:              </tr>'.
1.30      raeburn   868:             &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3       raeburn   869:            </table>
                    870:           </td>
                    871:          </tr>
                    872:          <tr>
                    873:            <td>
                    874:             <table class="LC_nested">
                    875:              <tr class="LC_info_row">
1.59      bisitz    876:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
                    877:               <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3       raeburn   878:              </tr>'.
1.30      raeburn   879:             &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
                    880:             $rowtotal += 2;
1.6       raeburn   881:         }
1.3       raeburn   882:     } else {
1.30      raeburn   883:         $output .= '
1.3       raeburn   884:           <tr>
                    885:            <td>
                    886:             <table class="LC_nested">
1.30      raeburn   887:              <tr class="LC_info_row">';
1.160.6.72  raeburn   888:         if ($action eq 'login') {
1.30      raeburn   889:             $output .= '  
1.59      bisitz    890:               <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69      raeburn   891:         } elsif ($action eq 'serverstatuses') {
                    892:             $output .= '
                    893:               <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
                    894:               '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
                    895: 
1.6       raeburn   896:         } else {
1.30      raeburn   897:             $output .= '
1.69      raeburn   898:               <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
                    899:         }
1.72      raeburn   900:         if (defined($item->{'header'}->[0]->{'col3'})) {
                    901:             $output .= '<td class="LC_left_item" valign="top">'.
                    902:                        &mt($item->{'header'}->[0]->{'col2'});
                    903:             if ($action eq 'serverstatuses') {
                    904:                 $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
                    905:             } 
1.69      raeburn   906:         } else {
                    907:             $output .= '<td class="LC_right_item" valign="top">'.
                    908:                        &mt($item->{'header'}->[0]->{'col2'});
                    909:         }
                    910:         $output .= '</td>';
                    911:         if ($item->{'header'}->[0]->{'col3'}) {
1.150     raeburn   912:             if (defined($item->{'header'}->[0]->{'col4'})) {
                    913:                 $output .= '<td class="LC_left_item" valign="top">'.
                    914:                             &mt($item->{'header'}->[0]->{'col3'});
                    915:             } else {
                    916:                 $output .= '<td class="LC_right_item" valign="top">'.
                    917:                            &mt($item->{'header'}->[0]->{'col3'});
                    918:             }
1.69      raeburn   919:             if ($action eq 'serverstatuses') {
                    920:                 $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
                    921:             }
                    922:             $output .= '</td>';
1.6       raeburn   923:         }
1.150     raeburn   924:         if ($item->{'header'}->[0]->{'col4'}) {
                    925:             $output .= '<td class="LC_right_item" valign="top">'.
                    926:                        &mt($item->{'header'}->[0]->{'col4'});
                    927:         }
1.69      raeburn   928:         $output .= '</tr>';
1.48      raeburn   929:         $rowtotal ++;
1.160.6.5  raeburn   930:         if ($action eq 'quotas') {
1.86      raeburn   931:             $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.160.6.72  raeburn   932:         } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') || 
1.160.6.78  raeburn   933:                  ($action eq 'serverstatuses') || ($action eq 'loadbalancing')) {
1.160.6.37  raeburn   934:             $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.46      raeburn   935:         } elsif ($action eq 'scantron') {
                    936:             $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
1.121     raeburn   937:         }
1.3       raeburn   938:     }
1.30      raeburn   939:     $output .= '
1.3       raeburn   940:    </table>
                    941:   </td>
                    942:  </tr>
1.30      raeburn   943: </table><br />';
                    944:     return ($output,$rowtotal);
1.1       raeburn   945: }
                    946: 
1.3       raeburn   947: sub print_login {
1.160.6.5  raeburn   948:     my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110     raeburn   949:     my ($css_class,$datatable);
1.6       raeburn   950:     my %choices = &login_choices();
1.110     raeburn   951: 
1.160.6.5  raeburn   952:     if ($caller eq 'service') {
1.149     raeburn   953:         my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110     raeburn   954:         my $choice = $choices{'disallowlogin'};
                    955:         $css_class = ' class="LC_odd_row"';
1.128     raeburn   956:         $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110     raeburn   957:                       '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128     raeburn   958:                       '<th>'.$choices{'server'}.'</th>'.
                    959:                       '<th>'.$choices{'serverpath'}.'</th>'.
                    960:                       '<th>'.$choices{'custompath'}.'</th>'.
                    961:                       '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110     raeburn   962:         my %disallowed;
                    963:         if (ref($settings) eq 'HASH') {
                    964:             if (ref($settings->{'loginvia'}) eq 'HASH') {
                    965:                %disallowed = %{$settings->{'loginvia'}};
                    966:             }
                    967:         }
                    968:         foreach my $lonhost (sort(keys(%servers))) {
                    969:             my $direct = 'selected="selected"';
1.128     raeburn   970:             if (ref($disallowed{$lonhost}) eq 'HASH') {
                    971:                 if ($disallowed{$lonhost}{'server'} ne '') {
                    972:                     $direct = '';
                    973:                 }
1.110     raeburn   974:             }
1.115     raeburn   975:             $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128     raeburn   976:                           '<td><select name="'.$lonhost.'_server">'.
1.110     raeburn   977:                           '<option value=""'.$direct.'>'.$choices{'directlogin'}.
                    978:                           '</option>';
1.160.6.13  raeburn   979:             foreach my $hostid (sort(keys(%servers))) {
1.115     raeburn   980:                 next if ($servers{$hostid} eq $servers{$lonhost});
1.110     raeburn   981:                 my $selected = '';
1.128     raeburn   982:                 if (ref($disallowed{$lonhost}) eq 'HASH') {
                    983:                     if ($hostid eq $disallowed{$lonhost}{'server'}) {
                    984:                         $selected = 'selected="selected"';
                    985:                     }
1.110     raeburn   986:                 }
                    987:                 $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
                    988:                               $servers{$hostid}.'</option>';
                    989:             }
1.128     raeburn   990:             $datatable .= '</select></td>'.
                    991:                           '<td><select name="'.$lonhost.'_serverpath">';
                    992:             foreach my $path ('','/','/adm/login','/adm/roles','custom') {
                    993:                 my $pathname = $path;
                    994:                 if ($path eq 'custom') {
                    995:                     $pathname = &mt('Custom Path').' ->';
                    996:                 }
                    997:                 my $selected = '';
                    998:                 if (ref($disallowed{$lonhost}) eq 'HASH') {
                    999:                     if ($path eq $disallowed{$lonhost}{'serverpath'}) {
                   1000:                         $selected = 'selected="selected"';
                   1001:                     }
                   1002:                 } elsif ($path eq '') {
                   1003:                     $selected = 'selected="selected"';
                   1004:                 }
                   1005:                 $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
                   1006:             }
                   1007:             $datatable .= '</select></td>';
                   1008:             my ($custom,$exempt);
                   1009:             if (ref($disallowed{$lonhost}) eq 'HASH') {
                   1010:                 $custom = $disallowed{$lonhost}{'custompath'};
                   1011:                 $exempt = $disallowed{$lonhost}{'exempt'};
                   1012:             }
                   1013:             $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
                   1014:                           '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
                   1015:                           '</tr>';
1.110     raeburn  1016:         }
                   1017:         $datatable .= '</table></td></tr>';
                   1018:         return $datatable;
1.160.6.5  raeburn  1019:     } elsif ($caller eq 'page') {
                   1020:         my %defaultchecked = ( 
                   1021:                                'coursecatalog' => 'on',
1.160.6.14  raeburn  1022:                                'helpdesk'      => 'on',
1.160.6.5  raeburn  1023:                                'adminmail'     => 'off',
                   1024:                                'newuser'       => 'off',
                   1025:                              );
1.160.6.14  raeburn  1026:         my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.160.6.5  raeburn  1027:         my (%checkedon,%checkedoff);
1.42      raeburn  1028:         foreach my $item (@toggles) {
1.160.6.5  raeburn  1029:             if ($defaultchecked{$item} eq 'on') { 
                   1030:                 $checkedon{$item} = ' checked="checked" ';
1.42      raeburn  1031:                 $checkedoff{$item} = ' ';
1.160.6.5  raeburn  1032:             } elsif ($defaultchecked{$item} eq 'off') {
                   1033:                 $checkedoff{$item} = ' checked="checked" ';
1.42      raeburn  1034:                 $checkedon{$item} = ' ';
                   1035:             }
1.1       raeburn  1036:         }
1.160.6.5  raeburn  1037:         my @images = ('img','logo','domlogo','login');
                   1038:         my @logintext = ('textcol','bgcol');
                   1039:         my @bgs = ('pgbg','mainbg','sidebg');
                   1040:         my @links = ('link','alink','vlink');
                   1041:         my %designhash = &Apache::loncommon::get_domainconf($dom);
                   1042:         my %defaultdesign = %Apache::loncommon::defaultdesign;
                   1043:         my (%is_custom,%designs);
                   1044:         my %defaults = (
                   1045:                        font => $defaultdesign{'login.font'},
                   1046:                        );
1.6       raeburn  1047:         foreach my $item (@images) {
1.160.6.5  raeburn  1048:             $defaults{$item} = $defaultdesign{'login.'.$item};
                   1049:             $defaults{'showlogo'}{$item} = 1;
                   1050:         }
                   1051:         foreach my $item (@bgs) {
                   1052:             $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6       raeburn  1053:         }
1.41      raeburn  1054:         foreach my $item (@logintext) {
1.160.6.5  raeburn  1055:             $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41      raeburn  1056:         }
1.160.6.5  raeburn  1057:         foreach my $item (@links) {
                   1058:             $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6       raeburn  1059:         }
1.160.6.5  raeburn  1060:         if (ref($settings) eq 'HASH') {
                   1061:             foreach my $item (@toggles) {
                   1062:                 if ($settings->{$item} eq '1') {
                   1063:                     $checkedon{$item} =  ' checked="checked" ';
                   1064:                     $checkedoff{$item} = ' ';
                   1065:                 } elsif ($settings->{$item} eq '0') {
                   1066:                     $checkedoff{$item} =  ' checked="checked" ';
                   1067:                     $checkedon{$item} = ' ';
                   1068:                 }
1.6       raeburn  1069:             }
1.160.6.5  raeburn  1070:             foreach my $item (@images) {
                   1071:                 if (defined($settings->{$item})) {
                   1072:                     $designs{$item} = $settings->{$item};
                   1073:                     $is_custom{$item} = 1;
                   1074:                 }
                   1075:                 if (defined($settings->{'showlogo'}{$item})) {
                   1076:                     $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
                   1077:                 }
                   1078:             }
                   1079:             foreach my $item (@logintext) {
                   1080:                 if ($settings->{$item} ne '') {
                   1081:                     $designs{'logintext'}{$item} = $settings->{$item};
                   1082:                     $is_custom{$item} = 1;
                   1083:                 }
                   1084:             }
                   1085:             if ($settings->{'font'} ne '') {
                   1086:                 $designs{'font'} = $settings->{'font'};
                   1087:                 $is_custom{'font'} = 1;
                   1088:             }
                   1089:             foreach my $item (@bgs) {
                   1090:                 if ($settings->{$item} ne '') {
                   1091:                     $designs{'bgs'}{$item} = $settings->{$item};
                   1092:                     $is_custom{$item} = 1;
                   1093:                 }
                   1094:             }
                   1095:             foreach my $item (@links) {
                   1096:                 if ($settings->{$item} ne '') {
                   1097:                     $designs{'links'}{$item} = $settings->{$item};
                   1098:                     $is_custom{$item} = 1;
                   1099:                 }
                   1100:             }
                   1101:         } else {
                   1102:             if ($designhash{$dom.'.login.font'} ne '') {
                   1103:                 $designs{'font'} = $designhash{$dom.'.login.font'};
                   1104:                 $is_custom{'font'} = 1;
                   1105:             }
                   1106:             foreach my $item (@images) {
                   1107:                 if ($designhash{$dom.'.login.'.$item} ne '') {
                   1108:                     $designs{$item} = $designhash{$dom.'.login.'.$item};
                   1109:                     $is_custom{$item} = 1;
                   1110:                 }
                   1111:             }
                   1112:             foreach my $item (@bgs) {
                   1113:                 if ($designhash{$dom.'.login.'.$item} ne '') {
                   1114:                     $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
                   1115:                     $is_custom{$item} = 1;
                   1116:                 }
                   1117:             }
                   1118:             foreach my $item (@links) {
                   1119:                 if ($designhash{$dom.'.login.'.$item} ne '') {
                   1120:                     $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
                   1121:                     $is_custom{$item} = 1;
                   1122:                 }
1.6       raeburn  1123:             }
                   1124:         }
1.160.6.5  raeburn  1125:         my %alt_text = &Apache::lonlocal::texthash  ( img => 'Log-in banner',
                   1126:                                                       logo => 'Institution Logo',
                   1127:                                                       domlogo => 'Domain Logo',
                   1128:                                                       login => 'Login box');
                   1129:         my $itemcount = 1;
                   1130:         foreach my $item (@toggles) {
                   1131:             $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   1132:             $datatable .=  
                   1133:                 '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
                   1134:                 '</td><td>'.
                   1135:                 '<span class="LC_nobreak"><label><input type="radio" name="'.
                   1136:                 $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
                   1137:                 '</label>&nbsp;<label><input type="radio" name="'.$item.'"'.
                   1138:                 $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
                   1139:                 '</tr>';
                   1140:             $itemcount ++;
1.6       raeburn  1141:         }
1.160.6.5  raeburn  1142:         $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
                   1143:         $datatable .= '</tr></table></td></tr>';
                   1144:     } elsif ($caller eq 'help') {
                   1145:         my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
                   1146:         my $switchserver = &check_switchserver($dom,$confname);
                   1147:         my $itemcount = 1;
                   1148:         $defaulturl = '/adm/loginproblems.html';
                   1149:         $defaulttype = 'default';
                   1150:         %lt = &Apache::lonlocal::texthash (
                   1151:                      del     => 'Delete?',
                   1152:                      rep     => 'Replace:',
                   1153:                      upl     => 'Upload:',
                   1154:                      default => 'Default',
                   1155:                      custom  => 'Custom',
                   1156:                                              );
                   1157:         %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
                   1158:         my @currlangs;
                   1159:         if (ref($settings) eq 'HASH') {
                   1160:             if (ref($settings->{'helpurl'}) eq 'HASH') {
                   1161:                 foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
                   1162:                     next if ($settings->{'helpurl'}{$key} eq '');
                   1163:                     $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
                   1164:                     $type{$key} = 'custom';
                   1165:                     unless ($key eq 'nolang') {
                   1166:                         push(@currlangs,$key);
                   1167:                     }
                   1168:                 }
                   1169:             } elsif ($settings->{'helpurl'} ne '') {
                   1170:                 $type{'nolang'} = 'custom';
                   1171:                 $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8       raeburn  1172:             }
                   1173:         }
1.160.6.5  raeburn  1174:         foreach my $lang ('nolang',sort(@currlangs)) {
                   1175:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   1176:             $datatable .= '<tr'.$css_class.'>';
                   1177:             if ($url{$lang} eq '') {
                   1178:                 $url{$lang} = $defaulturl;
                   1179:             }
                   1180:             if ($type{$lang} eq '') {
                   1181:                 $type{$lang} = $defaulttype;
                   1182:             }
                   1183:             $datatable .= '<td colspan="2"><span class="LC_nobreak">';
                   1184:             if ($lang eq 'nolang') {
                   1185:                 $datatable .= &mt('Log-in help page if no specific language file: [_1]',
                   1186:                                   &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
                   1187:             } else {
                   1188:                 $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
                   1189:                                   $langchoices{$lang},
                   1190:                                   &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
                   1191:             }
                   1192:             $datatable .= '</span></td>'."\n".
                   1193:                           '<td class="LC_left_item">';
                   1194:             if ($type{$lang} eq 'custom') {
                   1195:                 $datatable .= '<span class="LC_nobreak"><label>'.
                   1196:                               '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
                   1197:                               $lt{'del'}.'</label>&nbsp;'.$lt{'rep'}.'</span>';
                   1198:             } else {
                   1199:                 $datatable .= $lt{'upl'};
                   1200:             }
                   1201:             $datatable .='<br />';
                   1202:             if ($switchserver) {
                   1203:                 $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   1204:             } else {
                   1205:                 $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6       raeburn  1206:             }
1.160.6.5  raeburn  1207:             $datatable .= '</td></tr>';
                   1208:             $itemcount ++;
1.6       raeburn  1209:         }
1.160.6.5  raeburn  1210:         my @addlangs;
                   1211:         foreach my $lang (sort(keys(%langchoices))) {
                   1212:             next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
                   1213:             push(@addlangs,$lang);
                   1214:         }
                   1215:         if (@addlangs > 0) {
                   1216:             my %toadd;
                   1217:             map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
                   1218:             $toadd{''} = &mt('Select');
                   1219:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   1220:             $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
                   1221:                           &mt('Add log-in help page for a specific language:').'&nbsp;'.
                   1222:                           &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
                   1223:                           '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
                   1224:             if ($switchserver) {
                   1225:                 $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   1226:             } else {
                   1227:                 $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6       raeburn  1228:             }
1.160.6.5  raeburn  1229:             $datatable .= '</td></tr>';
                   1230:             $itemcount ++;
1.6       raeburn  1231:         }
1.160.6.5  raeburn  1232:         $datatable .= &captcha_choice('login',$settings,$itemcount);
1.160.6.56  raeburn  1233:     } elsif ($caller eq 'headtag') {
                   1234:         my %domservers = &Apache::lonnet::get_servers($dom);
                   1235:         my $choice = $choices{'headtag'};
                   1236:         $css_class = ' class="LC_odd_row"';
                   1237:         $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
                   1238:                       '<td align="left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
                   1239:                       '<th>'.$choices{'current'}.'</th>'.
                   1240:                       '<th>'.$choices{'action'}.'</th>'.
                   1241:                       '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
                   1242:         my (%currurls,%currexempt);
                   1243:         if (ref($settings) eq 'HASH') {
                   1244:             if (ref($settings->{'headtag'}) eq 'HASH') {
                   1245:                 foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
                   1246:                     if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
                   1247:                         $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
                   1248:                         $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
                   1249:                     }
                   1250:                 }
                   1251:             }
                   1252:         }
                   1253:         my %lt = &Apache::lonlocal::texthash(
                   1254:                                                del  => 'Delete?',
                   1255:                                                rep  => 'Replace:',
                   1256:                                                upl  => 'Upload:',
                   1257:                                                curr => 'View contents',
                   1258:                                                none => 'None',
                   1259:         );
                   1260:         my $switchserver = &check_switchserver($dom,$confname);
                   1261:         foreach my $lonhost (sort(keys(%domservers))) {
                   1262:             my $exempt = &check_exempt_addresses($currexempt{$lonhost});
                   1263:             $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
                   1264:             if ($currurls{$lonhost}) {
                   1265:                 $datatable .= '<td class="LC_right_item"><a href="'.
                   1266:                               "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
                   1267:                               'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
                   1268:                               '">'.$lt{'curr'}.'</a></td>'.
                   1269:                               '<td><span class="LC_nobreak"><label>'.
                   1270:                               '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
                   1271:                               $lt{'del'}.'</label>&nbsp;'.$lt{'rep'}.'</span>';
                   1272:             } else {
                   1273:                 $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
                   1274:             }
                   1275:             $datatable .='<br />';
                   1276:             if ($switchserver) {
                   1277:                 $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   1278:             } else {
                   1279:                 $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
                   1280:             }
1.160.6.87  raeburn  1281:             $datatable .= '</td><td><input type="text" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1.160.6.56  raeburn  1282:         }
                   1283:         $datatable .= '</table></td></tr>';
1.1       raeburn  1284:     }
1.6       raeburn  1285:     return $datatable;
                   1286: }
                   1287: 
                   1288: sub login_choices {
                   1289:     my %choices =
                   1290:         &Apache::lonlocal::texthash (
1.116     bisitz   1291:             coursecatalog => 'Display Course/Community Catalog link?',
1.110     raeburn  1292:             adminmail     => "Display Administrator's E-mail Address?",
1.160.6.14  raeburn  1293:             helpdesk      => 'Display "Contact Helpdesk" link',
1.110     raeburn  1294:             disallowlogin => "Login page requests redirected",
                   1295:             hostid        => "Server",
1.128     raeburn  1296:             server        => "Redirect to:",
                   1297:             serverpath    => "Path",
                   1298:             custompath    => "Custom", 
                   1299:             exempt        => "Exempt IP(s)",
1.110     raeburn  1300:             directlogin   => "No redirect",
                   1301:             newuser       => "Link to create a user account",
                   1302:             img           => "Header",
                   1303:             logo          => "Main Logo",
                   1304:             domlogo       => "Domain Logo",
                   1305:             login         => "Log-in Header", 
                   1306:             textcol       => "Text color",
                   1307:             bgcol         => "Box color",
                   1308:             bgs           => "Background colors",
                   1309:             links         => "Link colors",
                   1310:             font          => "Font color",
                   1311:             pgbg          => "Header",
                   1312:             mainbg        => "Page",
                   1313:             sidebg        => "Login box",
                   1314:             link          => "Link",
                   1315:             alink         => "Active link",
                   1316:             vlink         => "Visited link",
1.160.6.56  raeburn  1317:             headtag       => "Custom markup",
                   1318:             action        => "Action",
                   1319:             current       => "Current",
1.6       raeburn  1320:         );
                   1321:     return %choices;
                   1322: }
                   1323: 
                   1324: sub print_rolecolors {
1.30      raeburn  1325:     my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6       raeburn  1326:     my %choices = &color_font_choices();
                   1327:     my @bgs = ('pgbg','tabbg','sidebg');
                   1328:     my @links = ('link','alink','vlink');
                   1329:     my @images = ('img');
                   1330:     my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7       albertel 1331:     my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6       raeburn  1332:     my %defaultdesign = %Apache::loncommon::defaultdesign;
                   1333:     my (%is_custom,%designs);
1.160.6.22  raeburn  1334:     my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6       raeburn  1335:     if (ref($settings) eq 'HASH') {
                   1336:         if (ref($settings->{$role}) eq 'HASH') {
                   1337:             if ($settings->{$role}->{'img'} ne '') {
                   1338:                 $designs{'img'} = $settings->{$role}->{'img'};
                   1339:                 $is_custom{'img'} = 1;
                   1340:             }
                   1341:             if ($settings->{$role}->{'font'} ne '') {
                   1342:                 $designs{'font'} = $settings->{$role}->{'font'};
                   1343:                 $is_custom{'font'} = 1;
                   1344:             }
1.97      tempelho 1345:             if ($settings->{$role}->{'fontmenu'} ne '') {
                   1346:                 $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
                   1347:                 $is_custom{'fontmenu'} = 1;
                   1348:             }
1.6       raeburn  1349:             foreach my $item (@bgs) {
                   1350:                 if ($settings->{$role}->{$item} ne '') {
                   1351:                     $designs{'bgs'}{$item} = $settings->{$role}->{$item};
                   1352:                     $is_custom{$item} = 1;
                   1353:                 }
                   1354:             }
                   1355:             foreach my $item (@links) {
                   1356:                 if ($settings->{$role}->{$item} ne '') {
                   1357:                     $designs{'links'}{$item} = $settings->{$role}->{$item};
                   1358:                     $is_custom{$item} = 1;
                   1359:                 }
                   1360:             }
                   1361:         }
                   1362:     } else {
                   1363:         if ($designhash{$dom.'.'.$role.'.img'} ne '') {
                   1364:             $designs{img} = $designhash{$dom.'.'.$role.'.img'};
                   1365:             $is_custom{'img'} = 1;
                   1366:         }
1.97      tempelho 1367:         if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
                   1368:             $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
                   1369:             $is_custom{'fontmenu'} = 1; 
                   1370:         }
1.6       raeburn  1371:         if ($designhash{$dom.'.'.$role.'.font'} ne '') {
                   1372:             $designs{font} = $designhash{$dom.'.'.$role.'.font'};
                   1373:             $is_custom{'font'} = 1;
                   1374:         }
                   1375:         foreach my $item (@bgs) {
                   1376:             if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
                   1377:                 $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
                   1378:                 $is_custom{$item} = 1;
                   1379:             
                   1380:             }
                   1381:         }
                   1382:         foreach my $item (@links) {
                   1383:             if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
                   1384:                 $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
                   1385:                 $is_custom{$item} = 1;
                   1386:             }
                   1387:         }
                   1388:     }
                   1389:     my $itemcount = 1;
1.30      raeburn  1390:     my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6       raeburn  1391:     $datatable .= '</tr></table></td></tr>';
                   1392:     return $datatable;
                   1393: }
                   1394: 
1.160.6.22  raeburn  1395: sub role_defaults {
                   1396:     my ($role,$bgs,$links,$images,$logintext) = @_;
                   1397:     my %defaults;
                   1398:     unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
                   1399:         return %defaults;
                   1400:     }
                   1401:     my %defaultdesign = %Apache::loncommon::defaultdesign;
                   1402:     if ($role eq 'login') {
                   1403:         %defaults = (
                   1404:                        font => $defaultdesign{$role.'.font'},
                   1405:                     );
                   1406:         if (ref($logintext) eq 'ARRAY') {
                   1407:             foreach my $item (@{$logintext}) {
                   1408:                 $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
                   1409:             }
                   1410:         }
                   1411:         foreach my $item (@{$images}) {
                   1412:             $defaults{'showlogo'}{$item} = 1;
                   1413:         }
                   1414:     } else {
                   1415:         %defaults = (
                   1416:                        img => $defaultdesign{$role.'.img'},
                   1417:                        font => $defaultdesign{$role.'.font'},
                   1418:                        fontmenu => $defaultdesign{$role.'.fontmenu'},
                   1419:                     );
                   1420:     }
                   1421:     foreach my $item (@{$bgs}) {
                   1422:         $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
                   1423:     }
                   1424:     foreach my $item (@{$links}) {
                   1425:         $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
                   1426:     }
                   1427:     foreach my $item (@{$images}) {
                   1428:         $defaults{$item} = $defaultdesign{$role.'.'.$item};
                   1429:     }
                   1430:     return %defaults;
                   1431: }
                   1432: 
1.6       raeburn  1433: sub display_color_options {
1.9       raeburn  1434:     my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135     bisitz   1435:         $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159     raeburn  1436:     my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6       raeburn  1437:     my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.134     raeburn  1438:     my $datatable = '<tr'.$css_class.'>'.
1.6       raeburn  1439:         '<td>'.$choices->{'font'}.'</td>';
                   1440:     if (!$is_custom->{'font'}) {
1.160.6.87  raeburn  1441:         $datatable .=  '<td>'.&mt('Default in use:').'&nbsp;<span class="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6       raeburn  1442:     } else {
                   1443:         $datatable .= '<td>&nbsp;</td>';
                   1444:     }
1.160.6.9  raeburn  1445:     my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
                   1446: 
1.8       raeburn  1447:     $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9  raeburn  1448:                   '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
                   1449:                   ' value="'.$current_color.'" />&nbsp;'.
1.160.6.87  raeburn  1450:                   '&nbsp;</span></td></tr>';
1.107     raeburn  1451:     unless ($role eq 'login') { 
                   1452:         $datatable .= '<tr'.$css_class.'>'.
                   1453:                       '<td>'.$choices->{'fontmenu'}.'</td>';
                   1454:         if (!$is_custom->{'fontmenu'}) {
1.160.6.87  raeburn  1455:             $datatable .=  '<td>'.&mt('Default in use:').'&nbsp;<span class="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1.107     raeburn  1456:         } else {
                   1457:             $datatable .= '<td>&nbsp;</td>';
                   1458:         }
1.160.6.22  raeburn  1459: 	$current_color = $designs->{'fontmenu'} ?
                   1460: 	    $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107     raeburn  1461:         $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9  raeburn  1462:                       '<input class="colorchooser" type="text" size="10" name="'
1.160.6.22  raeburn  1463: 		      .$role.'_fontmenu"'.
1.160.6.9  raeburn  1464:                       ' value="'.$current_color.'" />&nbsp;'.
1.160.6.87  raeburn  1465:                       '&nbsp;</span></td></tr>';
1.97      tempelho 1466:     }
1.9       raeburn  1467:     my $switchserver = &check_switchserver($dom,$confname);
1.6       raeburn  1468:     foreach my $img (@{$images}) {
1.18      albertel 1469: 	$itemcount ++;
1.6       raeburn  1470:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8       raeburn  1471:         $datatable .= '<tr'.$css_class.'>'.
1.70      raeburn  1472:                       '<td>'.$choices->{$img};
1.41      raeburn  1473:         my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70      raeburn  1474:         if ($role eq 'login') {
                   1475:             if ($img eq 'login') {
                   1476:                 $login_hdr_pick =
1.135     bisitz   1477:                     &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70      raeburn  1478:                 $logincolors =
                   1479:                     &login_text_colors($img,$role,$logintext,$phase,$choices,
1.160.6.22  raeburn  1480:                                        $designs,$defaults);
1.70      raeburn  1481:             } elsif ($img ne 'domlogo') {
                   1482:                 $datatable.= &logo_display_options($img,$defaults,$designs);
                   1483:             }
                   1484:         }
                   1485:         $datatable .= '</td>';
1.6       raeburn  1486:         if ($designs->{$img} ne '') {
                   1487:             $imgfile = $designs->{$img};
1.18      albertel 1488: 	    $img_import = ($imgfile =~ m{^/adm/});
1.6       raeburn  1489:         } else {
                   1490:             $imgfile = $defaults->{$img};
                   1491:         }
                   1492:         if ($imgfile) {
1.9       raeburn  1493:             my ($showfile,$fullsize);
                   1494:             if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6       raeburn  1495:                 my $urldir = $1;
                   1496:                 my $filename = $2;
                   1497:                 my @info = &Apache::lonnet::stat_file($designs->{$img});
                   1498:                 if (@info) {
                   1499:                     my $thumbfile = 'tn-'.$filename;
                   1500:                     my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
                   1501:                     if (@thumb) {
                   1502:                         $showfile = $urldir.'/'.$thumbfile;
                   1503:                     } else {
                   1504:                         $showfile = $imgfile;
                   1505:                     }
                   1506:                 } else {
                   1507:                     $showfile = '';
                   1508:                 }
                   1509:             } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16      raeburn  1510:                 $showfile = $imgfile;
1.6       raeburn  1511:                 my $imgdir = $1;
                   1512:                 my $filename = $2;
1.159     raeburn  1513:                 if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6       raeburn  1514:                     $showfile = "/$imgdir/tn-".$filename;
                   1515:                 } else {
1.159     raeburn  1516:                     my $input = $londocroot.$imgfile;
                   1517:                     my $output = "$londocroot/$imgdir/tn-".$filename;
1.6       raeburn  1518:                     if (!-e $output) {
1.9       raeburn  1519:                         my ($width,$height) = &thumb_dimensions();
1.16      raeburn  1520:                         my ($fullwidth,$fullheight) = &check_dimensions($input);
                   1521:                         if ($fullwidth ne '' && $fullheight ne '') {
                   1522:                             if ($fullwidth > $width && $fullheight > $height) { 
                   1523:                                 my $size = $width.'x'.$height;
1.160.6.88  raeburn  1524:                                 my @args = ('convert','-sample',$size,$input,$output);
                   1525:                                 system({$args[0]} @args);
1.159     raeburn  1526:                                 $showfile = "/$imgdir/tn-".$filename;
1.16      raeburn  1527:                             }
                   1528:                         }
1.6       raeburn  1529:                     }
                   1530:                 }
1.16      raeburn  1531:             }
1.6       raeburn  1532:             if ($showfile) {
1.40      raeburn  1533:                 if ($showfile =~ m{^/(adm|res)/}) {
                   1534:                     if ($showfile =~ m{^/res/}) {
                   1535:                         my $local_showfile =
                   1536:                             &Apache::lonnet::filelocation('',$showfile);
                   1537:                         &Apache::lonnet::repcopy($local_showfile);
                   1538:                     }
                   1539:                     $showfile = &Apache::loncommon::lonhttpdurl($showfile);
                   1540:                 }
                   1541:                 if ($imgfile) {
                   1542:                     if ($imgfile  =~ m{^/(adm|res)/}) {
                   1543:                         if ($imgfile =~ m{^/res/}) {
                   1544:                             my $local_imgfile =
                   1545:                                 &Apache::lonnet::filelocation('',$imgfile);
                   1546:                             &Apache::lonnet::repcopy($local_imgfile);
                   1547:                         }
                   1548:                         $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
                   1549:                     } else {
                   1550:                         $fullsize = $imgfile;
                   1551:                     }
                   1552:                 }
1.41      raeburn  1553:                 $datatable .= '<td>';
                   1554:                 if ($img eq 'login') {
1.135     bisitz   1555:                     $datatable .= $login_hdr_pick;
                   1556:                 } 
1.41      raeburn  1557:                 $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
                   1558:                                              $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6       raeburn  1559:             } else {
1.160.6.22  raeburn  1560:                 $datatable .= '<td>&nbsp;</td><td class="LC_left_item">'.
                   1561:                               &mt('Upload:').'<br />';
1.6       raeburn  1562:             }
                   1563:         } else {
1.160.6.22  raeburn  1564:             $datatable .= '<td>&nbsp;</td><td class="LC_left_item">'.
                   1565:                           &mt('Upload:').'<br />';
1.6       raeburn  1566:         }
1.9       raeburn  1567:         if ($switchserver) {
                   1568:             $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   1569:         } else {
1.135     bisitz   1570:             if ($img ne 'login') { # suppress file selection for Log-in header
                   1571:                 $datatable .='&nbsp;<input type="file" name="'.$role.'_'.$img.'" />';
                   1572:             }
1.9       raeburn  1573:         }
                   1574:         $datatable .= '</td></tr>';
1.6       raeburn  1575:     }
                   1576:     $itemcount ++;
                   1577:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   1578:     $datatable .= '<tr'.$css_class.'>'.
                   1579:                   '<td>'.$choices->{'bgs'}.'</td>';
                   1580:     my $bgs_def;
                   1581:     foreach my $item (@{$bgs}) {
                   1582:         if (!$is_custom->{$item}) {
1.160.6.87  raeburn  1583:             $bgs_def .= '<td><span class="LC_nobreak">'.$choices->{$item}.'</span>&nbsp;<span class="css_default_'.$role.'_'.$item.'" style="background-color: '.$defaults->{'bgs'}{$item}.';">&nbsp;&nbsp;&nbsp;</span><br />'.$defaults->{'bgs'}{$item}.'</td>';
1.6       raeburn  1584:         }
                   1585:     }
                   1586:     if ($bgs_def) {
1.8       raeburn  1587:         $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6       raeburn  1588:     } else {
                   1589:         $datatable .= '<td>&nbsp;</td>';
                   1590:     }
                   1591:     $datatable .= '<td class="LC_right_item">'.
                   1592:                   '<table border="0"><tr>';
1.160.6.13  raeburn  1593: 
1.6       raeburn  1594:     foreach my $item (@{$bgs}) {
1.160.6.22  raeburn  1595:         $datatable .= '<td align="center">'.$choices->{$item};
                   1596: 	my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6       raeburn  1597:         if ($designs->{'bgs'}{$item}) {
1.160.6.9  raeburn  1598:             $datatable .= '&nbsp;';
1.6       raeburn  1599:         }
1.160.6.9  raeburn  1600:         $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41      raeburn  1601:                       '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6       raeburn  1602:     }
                   1603:     $datatable .= '</tr></table></td></tr>';
                   1604:     $itemcount ++;
                   1605:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   1606:     $datatable .= '<tr'.$css_class.'>'.
                   1607:                   '<td>'.$choices->{'links'}.'</td>';
                   1608:     my $links_def;
                   1609:     foreach my $item (@{$links}) {
                   1610:         if (!$is_custom->{$item}) {
1.160.6.87  raeburn  1611:             $links_def .= '<td>'.$choices->{$item}.'<br /><span class="css_default_'.$role.'_'.$item.'" style="color: '.$defaults->{'links'}{$item}.';">'.$defaults->{'links'}{$item}.'</span></td>';
1.6       raeburn  1612:         }
                   1613:     }
                   1614:     if ($links_def) {
1.8       raeburn  1615:         $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6       raeburn  1616:     } else {
                   1617:         $datatable .= '<td>&nbsp;</td>';
                   1618:     }
                   1619:     $datatable .= '<td class="LC_right_item">'.
                   1620:                   '<table border="0"><tr>';
                   1621:     foreach my $item (@{$links}) {
1.160.6.39  raeburn  1622: 	my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.160.6.22  raeburn  1623:         $datatable .= '<td align="center">'.$choices->{$item}."\n";
1.6       raeburn  1624:         if ($designs->{'links'}{$item}) {
1.160.6.9  raeburn  1625:             $datatable.='&nbsp;';
1.6       raeburn  1626:         }
1.160.6.9  raeburn  1627:         $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6       raeburn  1628:                       '" /></td>';
                   1629:     }
1.30      raeburn  1630:     $$rowtotal += $itemcount;
1.3       raeburn  1631:     return $datatable;
                   1632: }
                   1633: 
1.70      raeburn  1634: sub logo_display_options {
                   1635:     my ($img,$defaults,$designs) = @_;
                   1636:     my $checkedon;
                   1637:     if (ref($defaults) eq 'HASH') {
                   1638:         if (ref($defaults->{'showlogo'}) eq 'HASH') {
                   1639:             if ($defaults->{'showlogo'}{$img}) {
                   1640:                 $checkedon = 'checked="checked" ';     
                   1641:             }
                   1642:         } 
                   1643:     }
                   1644:     if (ref($designs) eq 'HASH') {
                   1645:         if (ref($designs->{'showlogo'}) eq 'HASH') {
                   1646:             if (defined($designs->{'showlogo'}{$img})) {
                   1647:                 if ($designs->{'showlogo'}{$img} == 0) {
                   1648:                     $checkedon = '';
                   1649:                 } elsif ($designs->{'showlogo'}{$img} == 1) {
                   1650:                     $checkedon = 'checked="checked" ';
                   1651:                 }
                   1652:             }
                   1653:         }
                   1654:     }
                   1655:     return '<br /><label>&nbsp;&nbsp;<input type="checkbox" name="'.
                   1656:            'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
                   1657:            &mt('show').'</label>'."\n";
                   1658: }
                   1659: 
1.41      raeburn  1660: sub login_header_options  {
1.135     bisitz   1661:     my ($img,$role,$defaults,$is_custom,$choices) = @_;
                   1662:     my $output = '';
1.41      raeburn  1663:     if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135     bisitz   1664:         $output .= &mt('Text default(s):').'<br />';
1.41      raeburn  1665:         if (!$is_custom->{'textcol'}) {
                   1666:             $output .= $choices->{'textcol'}.':&nbsp;'.$defaults->{'logintext'}{'textcol'}.
                   1667:                        '&nbsp;&nbsp;&nbsp;';
                   1668:         }
                   1669:         if (!$is_custom->{'bgcol'}) {
                   1670:             $output .= $choices->{'bgcol'}.':&nbsp;'.
                   1671:                        '<span id="css_'.$role.'_font" style="background-color: '.
                   1672:                        $defaults->{'logintext'}{'bgcol'}.';">&nbsp;&nbsp;&nbsp;</span>';
                   1673:         }
                   1674:         $output .= '<br />';
                   1675:     }
                   1676:     $output .='<br />';
                   1677:     return $output;
                   1678: }
                   1679: 
                   1680: sub login_text_colors {
1.160.6.22  raeburn  1681:     my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41      raeburn  1682:     my $color_menu = '<table border="0"><tr>';
                   1683:     foreach my $item (@{$logintext}) {
1.160.6.22  raeburn  1684:         $color_menu .= '<td align="center">'.$choices->{$item};
                   1685:         my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
                   1686:         $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
                   1687:                       '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41      raeburn  1688:     }
                   1689:     $color_menu .= '</tr></table><br />';
                   1690:     return $color_menu;
                   1691: }
                   1692: 
                   1693: sub image_changes {
                   1694:     my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
                   1695:     my $output;
1.135     bisitz   1696:     if ($img eq 'login') {
1.160.6.87  raeburn  1697:         $output = '</td><td>'.$logincolors; # suppress image for Log-in header
1.135     bisitz   1698:     } elsif (!$is_custom) {
1.70      raeburn  1699:         if ($img ne 'domlogo') {
1.160.6.87  raeburn  1700:             $output = &mt('Default image:').'<br />';
1.41      raeburn  1701:         } else {
1.160.6.87  raeburn  1702:             $output = &mt('Default in use:').'<br />';
1.41      raeburn  1703:         }
                   1704:     }
1.160.6.87  raeburn  1705:     if ($img ne 'login') {
1.135     bisitz   1706:         if ($img_import) {
                   1707:             $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
                   1708:         }
                   1709:         $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
                   1710:                    $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
                   1711:         if ($is_custom) {
                   1712:             $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
                   1713:                        '<input type="checkbox" name="'.
                   1714:                        $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
                   1715:                        '</label>&nbsp;'.&mt('Replace:').'</span><br />';
                   1716:         } else {
1.160.6.22  raeburn  1717:             $output .= '<td valign="middle">'.$logincolors.&mt('Upload:').'<br />';
1.135     bisitz   1718:         }
1.41      raeburn  1719:     }
                   1720:     return $output;
                   1721: }
                   1722: 
1.3       raeburn  1723: sub print_quotas {
1.86      raeburn  1724:     my ($dom,$settings,$rowtotal,$action) = @_;
                   1725:     my $context;
                   1726:     if ($action eq 'quotas') {
                   1727:         $context = 'tools';
                   1728:     } else {
                   1729:         $context = $action;
                   1730:     }
1.160.6.20  raeburn  1731:     my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44      raeburn  1732:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3       raeburn  1733:     my $typecount = 0;
1.101     raeburn  1734:     my ($css_class,%titles);
1.86      raeburn  1735:     if ($context eq 'requestcourses') {
1.160.6.30  raeburn  1736:         @usertools = ('official','unofficial','community','textbook');
1.106     raeburn  1737:         @options =('norequest','approval','validate','autolimit');
1.101     raeburn  1738:         %validations = &Apache::lonnet::auto_courserequest_checks($dom);
                   1739:         %titles = &courserequest_titles();
1.160.6.5  raeburn  1740:     } elsif ($context eq 'requestauthor') {
                   1741:         @usertools = ('author');
                   1742:         @options = ('norequest','approval','automatic');
                   1743:         %titles = &authorrequest_titles();
1.86      raeburn  1744:     } else {
1.160.6.4  raeburn  1745:         @usertools = ('aboutme','blog','webdav','portfolio');
1.101     raeburn  1746:         %titles = &tool_titles();
1.86      raeburn  1747:     }
1.26      raeburn  1748:     if (ref($types) eq 'ARRAY') {
1.23      raeburn  1749:         foreach my $type (@{$types}) {
1.160.6.20  raeburn  1750:             my ($currdefquota,$currauthorquota);
1.160.6.5  raeburn  1751:             unless (($context eq 'requestcourses') ||
                   1752:                     ($context eq 'requestauthor')) {
1.86      raeburn  1753:                 if (ref($settings) eq 'HASH') {
                   1754:                     if (ref($settings->{defaultquota}) eq 'HASH') {
1.160.6.20  raeburn  1755:                         $currdefquota = $settings->{defaultquota}->{$type};
1.86      raeburn  1756:                     } else {
                   1757:                         $currdefquota = $settings->{$type};
                   1758:                     }
1.160.6.20  raeburn  1759:                     if (ref($settings->{authorquota}) eq 'HASH') {
                   1760:                         $currauthorquota = $settings->{authorquota}->{$type};
                   1761:                     }
1.78      raeburn  1762:                 }
1.72      raeburn  1763:             }
1.3       raeburn  1764:             if (defined($usertypes->{$type})) {
                   1765:                 $typecount ++;
                   1766:                 $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72      raeburn  1767:                 $datatable .= '<tr'.$css_class.'>'.
1.3       raeburn  1768:                               '<td>'.$usertypes->{$type}.'</td>'.
1.72      raeburn  1769:                               '<td class="LC_left_item">';
1.101     raeburn  1770:                 if ($context eq 'requestcourses') {
                   1771:                     $datatable .= '<table><tr>';
                   1772:                 }
                   1773:                 my %cell;  
1.72      raeburn  1774:                 foreach my $item (@usertools) {
1.101     raeburn  1775:                     if ($context eq 'requestcourses') {
                   1776:                         my ($curroption,$currlimit);
                   1777:                         if (ref($settings) eq 'HASH') {
                   1778:                             if (ref($settings->{$item}) eq 'HASH') {
                   1779:                                 $curroption = $settings->{$item}->{$type};
                   1780:                                 if ($curroption =~ /^autolimit=(\d*)$/) {
                   1781:                                     $currlimit = $1; 
                   1782:                                 }
                   1783:                             }
                   1784:                         }
                   1785:                         if (!$curroption) {
                   1786:                             $curroption = 'norequest';
                   1787:                         }
                   1788:                         $datatable .= '<th>'.$titles{$item}.'</th>';
                   1789:                         foreach my $option (@options) {
                   1790:                             my $val = $option;
                   1791:                             if ($option eq 'norequest') {
                   1792:                                 $val = 0;  
                   1793:                             }
                   1794:                             if ($option eq 'validate') {
                   1795:                                 my $canvalidate = 0;
                   1796:                                 if (ref($validations{$item}) eq 'HASH') { 
                   1797:                                     if ($validations{$item}{$type}) {
                   1798:                                         $canvalidate = 1;
                   1799:                                     }
                   1800:                                 }
                   1801:                                 next if (!$canvalidate);
                   1802:                             }
                   1803:                             my $checked = '';
                   1804:                             if ($option eq $curroption) {
                   1805:                                 $checked = ' checked="checked"';
                   1806:                             } elsif ($option eq 'autolimit') {
                   1807:                                 if ($curroption =~ /^autolimit/) {
                   1808:                                     $checked = ' checked="checked"';
                   1809:                                 }                       
                   1810:                             } 
                   1811:                             $cell{$item} .= '<span class="LC_nobreak"><label>'.
                   1812:                                   '<input type="radio" name="crsreq_'.$item.
                   1813:                                   '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127     raeburn  1814:                                   $titles{$option}.'</label>';
1.101     raeburn  1815:                             if ($option eq 'autolimit') {
1.127     raeburn  1816:                                 $cell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
1.101     raeburn  1817:                                                 $item.'_limit_'.$type.'" size="1" '.
1.103     raeburn  1818:                                                 'value="'.$currlimit.'" />';
1.101     raeburn  1819:                             }
1.127     raeburn  1820:                             $cell{$item} .= '</span> ';
1.103     raeburn  1821:                             if ($option eq 'autolimit') {
1.127     raeburn  1822:                                 $cell{$item} .= $titles{'unlimited'};
1.103     raeburn  1823:                             }
1.101     raeburn  1824:                         }
1.160.6.5  raeburn  1825:                     } elsif ($context eq 'requestauthor') {
                   1826:                         my $curroption;
                   1827:                         if (ref($settings) eq 'HASH') {
                   1828:                             $curroption = $settings->{$type};
                   1829:                         }
                   1830:                         if (!$curroption) {
                   1831:                             $curroption = 'norequest';
                   1832:                         }
                   1833:                         foreach my $option (@options) {
                   1834:                             my $val = $option;
                   1835:                             if ($option eq 'norequest') {
                   1836:                                 $val = 0;
                   1837:                             }
                   1838:                             my $checked = '';
                   1839:                             if ($option eq $curroption) {
                   1840:                                 $checked = ' checked="checked"';
                   1841:                             }
                   1842:                             $datatable .= '<span class="LC_nobreak"><label>'.
                   1843:                                   '<input type="radio" name="authorreq_'.$type.
                   1844:                                   '" value="'.$val.'"'.$checked.' />'.
                   1845:                                   $titles{$option}.'</label></span>&nbsp; ';
                   1846:                         }
1.101     raeburn  1847:                     } else {
                   1848:                         my $checked = 'checked="checked" ';
                   1849:                         if (ref($settings) eq 'HASH') {
                   1850:                             if (ref($settings->{$item}) eq 'HASH') {
                   1851:                                 if ($settings->{$item}->{$type} == 0) {
                   1852:                                     $checked = '';
                   1853:                                 } elsif ($settings->{$item}->{$type} == 1) {
                   1854:                                     $checked =  'checked="checked" ';
                   1855:                                 }
1.78      raeburn  1856:                             }
1.72      raeburn  1857:                         }
1.101     raeburn  1858:                         $datatable .= '<span class="LC_nobreak"><label>'.
                   1859:                                       '<input type="checkbox" name="'.$context.'_'.$item.
                   1860:                                       '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
                   1861:                                       '</label></span>&nbsp; ';
1.72      raeburn  1862:                     }
1.101     raeburn  1863:                 }
                   1864:                 if ($context eq 'requestcourses') {
                   1865:                     $datatable .= '</tr><tr>';
                   1866:                     foreach my $item (@usertools) {
1.106     raeburn  1867:                         $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';  
1.101     raeburn  1868:                     }
                   1869:                     $datatable .= '</tr></table>';
1.72      raeburn  1870:                 }
1.86      raeburn  1871:                 $datatable .= '</td>';
1.160.6.5  raeburn  1872:                 unless (($context eq 'requestcourses') ||
                   1873:                         ($context eq 'requestauthor')) {
1.86      raeburn  1874:                     $datatable .= 
1.160.6.20  raeburn  1875:                               '<td class="LC_right_item">'.
                   1876:                               '<span class="LC_nobreak">'.&mt('Portfolio').':&nbsp;'.
1.3       raeburn  1877:                               '<input type="text" name="quota_'.$type.
1.72      raeburn  1878:                               '" value="'.$currdefquota.
1.160.6.20  raeburn  1879:                               '" size="5" /></span>'.('&nbsp;' x 2).
                   1880:                               '<span class="LC_nobreak">'.&mt('Authoring').':&nbsp;'.
                   1881:                               '<input type="text" name="authorquota_'.$type.
                   1882:                               '" value="'.$currauthorquota.
                   1883:                               '" size="5" /></span></td>';
1.86      raeburn  1884:                 }
                   1885:                 $datatable .= '</tr>';
1.3       raeburn  1886:             }
                   1887:         }
                   1888:     }
1.160.6.5  raeburn  1889:     unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86      raeburn  1890:         $defaultquota = '20';
1.160.6.20  raeburn  1891:         $authorquota = '500';
1.86      raeburn  1892:         if (ref($settings) eq 'HASH') {
                   1893:             if (ref($settings->{'defaultquota'}) eq 'HASH') {
                   1894:                 $defaultquota = $settings->{'defaultquota'}->{'default'};
                   1895:             } elsif (defined($settings->{'default'})) {
                   1896:                 $defaultquota = $settings->{'default'};
                   1897:             }
1.160.6.20  raeburn  1898:             if (ref($settings->{'authorquota'}) eq 'HASH') {
                   1899:                 $authorquota = $settings->{'authorquota'}->{'default'};
                   1900:             }
1.3       raeburn  1901:         }
                   1902:     }
                   1903:     $typecount ++;
                   1904:     $css_class = $typecount%2?' class="LC_odd_row"':'';
                   1905:     $datatable .= '<tr'.$css_class.'>'.
1.26      raeburn  1906:                   '<td>'.$othertitle.'</td>'.
1.72      raeburn  1907:                   '<td class="LC_left_item">';
1.101     raeburn  1908:     if ($context eq 'requestcourses') {
                   1909:         $datatable .= '<table><tr>';
                   1910:     }
                   1911:     my %defcell;
1.72      raeburn  1912:     foreach my $item (@usertools) {
1.101     raeburn  1913:         if ($context eq 'requestcourses') {
                   1914:             my ($curroption,$currlimit);
                   1915:             if (ref($settings) eq 'HASH') {
                   1916:                 if (ref($settings->{$item}) eq 'HASH') {
                   1917:                     $curroption = $settings->{$item}->{'default'};
                   1918:                     if ($curroption =~ /^autolimit=(\d*)$/) {
                   1919:                         $currlimit = $1;
                   1920:                     }
                   1921:                 }
                   1922:             }
                   1923:             if (!$curroption) {
                   1924:                 $curroption = 'norequest';
                   1925:             }
                   1926:             $datatable .= '<th>'.$titles{$item}.'</th>';
                   1927:             foreach my $option (@options) {
                   1928:                 my $val = $option;
                   1929:                 if ($option eq 'norequest') {
                   1930:                     $val = 0;
                   1931:                 }
                   1932:                 if ($option eq 'validate') {
                   1933:                     my $canvalidate = 0;
                   1934:                     if (ref($validations{$item}) eq 'HASH') {
                   1935:                         if ($validations{$item}{'default'}) {
                   1936:                             $canvalidate = 1;
                   1937:                         }
                   1938:                     }
                   1939:                     next if (!$canvalidate);
                   1940:                 }
                   1941:                 my $checked = '';
                   1942:                 if ($option eq $curroption) {
                   1943:                     $checked = ' checked="checked"';
                   1944:                 } elsif ($option eq 'autolimit') {
                   1945:                     if ($curroption =~ /^autolimit/) {
                   1946:                         $checked = ' checked="checked"';
                   1947:                     }
                   1948:                 }
                   1949:                 $defcell{$item} .= '<span class="LC_nobreak"><label>'.
                   1950:                                   '<input type="radio" name="crsreq_'.$item.
                   1951:                                   '_default" value="'.$val.'"'.$checked.' />'.
                   1952:                                   $titles{$option}.'</label>';
                   1953:                 if ($option eq 'autolimit') {
1.127     raeburn  1954:                     $defcell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
1.101     raeburn  1955:                                        $item.'_limit_default" size="1" '.
                   1956:                                        'value="'.$currlimit.'" />';
                   1957:                 }
1.127     raeburn  1958:                 $defcell{$item} .= '</span> ';
1.104     raeburn  1959:                 if ($option eq 'autolimit') {
1.127     raeburn  1960:                     $defcell{$item} .= $titles{'unlimited'};
1.104     raeburn  1961:                 }
1.101     raeburn  1962:             }
1.160.6.5  raeburn  1963:         } elsif ($context eq 'requestauthor') {
                   1964:             my $curroption;
                   1965:             if (ref($settings) eq 'HASH') {
1.160.6.8  raeburn  1966:                 $curroption = $settings->{'default'};
1.160.6.5  raeburn  1967:             }
                   1968:             if (!$curroption) {
                   1969:                 $curroption = 'norequest';
                   1970:             }
                   1971:             foreach my $option (@options) {
                   1972:                 my $val = $option;
                   1973:                 if ($option eq 'norequest') {
                   1974:                     $val = 0;
                   1975:                 }
                   1976:                 my $checked = '';
                   1977:                 if ($option eq $curroption) {
                   1978:                     $checked = ' checked="checked"';
                   1979:                 }
                   1980:                 $datatable .= '<span class="LC_nobreak"><label>'.
                   1981:                               '<input type="radio" name="authorreq_default"'.
                   1982:                               ' value="'.$val.'"'.$checked.' />'.
                   1983:                               $titles{$option}.'</label></span>&nbsp; ';
                   1984:             }
1.101     raeburn  1985:         } else {
                   1986:             my $checked = 'checked="checked" ';
                   1987:             if (ref($settings) eq 'HASH') {
                   1988:                 if (ref($settings->{$item}) eq 'HASH') {
                   1989:                     if ($settings->{$item}->{'default'} == 0) {
                   1990:                         $checked = '';
                   1991:                     } elsif ($settings->{$item}->{'default'} == 1) {
                   1992:                         $checked = 'checked="checked" ';
                   1993:                     }
1.78      raeburn  1994:                 }
1.72      raeburn  1995:             }
1.101     raeburn  1996:             $datatable .= '<span class="LC_nobreak"><label>'.
                   1997:                           '<input type="checkbox" name="'.$context.'_'.$item.
                   1998:                           '" value="default" '.$checked.'/>'.$titles{$item}.
                   1999:                           '</label></span>&nbsp; ';
                   2000:         }
                   2001:     }
                   2002:     if ($context eq 'requestcourses') {
                   2003:         $datatable .= '</tr><tr>';
                   2004:         foreach my $item (@usertools) {
1.106     raeburn  2005:             $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72      raeburn  2006:         }
1.101     raeburn  2007:         $datatable .= '</tr></table>';
1.72      raeburn  2008:     }
1.86      raeburn  2009:     $datatable .= '</td>';
1.160.6.5  raeburn  2010:     unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.20  raeburn  2011:         $datatable .= '<td class="LC_right_item">'.
                   2012:                       '<span class="LC_nobreak">'.&mt('Portfolio').':&nbsp;'.
1.86      raeburn  2013:                       '<input type="text" name="defaultquota" value="'.
1.160.6.20  raeburn  2014:                       $defaultquota.'" size="5" /></span>'.('&nbsp;' x2).
                   2015:                       '<span class="LC_nobreak">'.&mt('Authoring').':&nbsp;'.
                   2016:                       '<input type="text" name="authorquota" value="'.
                   2017:                       $authorquota.'" size="5" /></span></td>';
1.86      raeburn  2018:     }
                   2019:     $datatable .= '</tr>';
1.72      raeburn  2020:     $typecount ++;
                   2021:     $css_class = $typecount%2?' class="LC_odd_row"':'';
                   2022:     $datatable .= '<tr'.$css_class.'>'.
1.160.6.20  raeburn  2023:                   '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104     raeburn  2024:     if ($context eq 'requestcourses') {
1.109     raeburn  2025:         $datatable .= &mt('(overrides affiliation, if set)').
                   2026:                       '</td>'.
                   2027:                       '<td class="LC_left_item">'.
                   2028:                       '<table><tr>';
1.101     raeburn  2029:     } else {
1.109     raeburn  2030:         $datatable .= &mt('(overrides affiliation, if checked)').
                   2031:                       '</td>'.
                   2032:                       '<td class="LC_left_item" colspan="2">'.
                   2033:                       '<br />';
1.101     raeburn  2034:     }
                   2035:     my %advcell;
1.72      raeburn  2036:     foreach my $item (@usertools) {
1.101     raeburn  2037:         if ($context eq 'requestcourses') {
                   2038:             my ($curroption,$currlimit);
                   2039:             if (ref($settings) eq 'HASH') {
                   2040:                 if (ref($settings->{$item}) eq 'HASH') {
                   2041:                     $curroption = $settings->{$item}->{'_LC_adv'};
                   2042:                     if ($curroption =~ /^autolimit=(\d*)$/) {
                   2043:                         $currlimit = $1;
                   2044:                     }
                   2045:                 }
                   2046:             }
                   2047:             $datatable .= '<th>'.$titles{$item}.'</th>';
1.104     raeburn  2048:             my $checked = '';
                   2049:             if ($curroption eq '') {
                   2050:                 $checked = ' checked="checked"';
                   2051:             }
                   2052:             $advcell{$item} .= '<span class="LC_nobreak"><label>'.
                   2053:                                '<input type="radio" name="crsreq_'.$item.
                   2054:                                '__LC_adv" value=""'.$checked.' />'.
                   2055:                                &mt('No override set').'</label></span>&nbsp; ';
1.101     raeburn  2056:             foreach my $option (@options) {
                   2057:                 my $val = $option;
                   2058:                 if ($option eq 'norequest') {
                   2059:                     $val = 0;
                   2060:                 }
                   2061:                 if ($option eq 'validate') {
                   2062:                     my $canvalidate = 0;
                   2063:                     if (ref($validations{$item}) eq 'HASH') {
                   2064:                         if ($validations{$item}{'_LC_adv'}) {
                   2065:                             $canvalidate = 1;
                   2066:                         }
                   2067:                     }
                   2068:                     next if (!$canvalidate);
                   2069:                 }
                   2070:                 my $checked = '';
1.104     raeburn  2071:                 if ($val eq $curroption) {
1.101     raeburn  2072:                     $checked = ' checked="checked"';
                   2073:                 } elsif ($option eq 'autolimit') {
                   2074:                     if ($curroption =~ /^autolimit/) {
                   2075:                         $checked = ' checked="checked"';
                   2076:                     }
                   2077:                 }
                   2078:                 $advcell{$item} .= '<span class="LC_nobreak"><label>'.
                   2079:                                   '<input type="radio" name="crsreq_'.$item.
                   2080:                                   '__LC_adv" value="'.$val.'"'.$checked.' />'.
                   2081:                                   $titles{$option}.'</label>';
                   2082:                 if ($option eq 'autolimit') {
1.127     raeburn  2083:                     $advcell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
1.101     raeburn  2084:                                        $item.'_limit__LC_adv" size="1" '.
                   2085:                                        'value="'.$currlimit.'" />';
                   2086:                 }
1.127     raeburn  2087:                 $advcell{$item} .= '</span> ';
1.104     raeburn  2088:                 if ($option eq 'autolimit') {
1.127     raeburn  2089:                     $advcell{$item} .= $titles{'unlimited'};
1.104     raeburn  2090:                 }
1.101     raeburn  2091:             }
1.160.6.5  raeburn  2092:         } elsif ($context eq 'requestauthor') {
                   2093:             my $curroption;
                   2094:             if (ref($settings) eq 'HASH') {
                   2095:                 $curroption = $settings->{'_LC_adv'};
                   2096:             }
                   2097:             my $checked = '';
                   2098:             if ($curroption eq '') {
                   2099:                 $checked = ' checked="checked"';
                   2100:             }
                   2101:             $datatable .= '<span class="LC_nobreak"><label>'.
                   2102:                           '<input type="radio" name="authorreq__LC_adv"'.
                   2103:                           ' value=""'.$checked.' />'.
                   2104:                           &mt('No override set').'</label></span>&nbsp; ';
                   2105:             foreach my $option (@options) {
                   2106:                 my $val = $option;
                   2107:                 if ($option eq 'norequest') {
                   2108:                     $val = 0;
                   2109:                 }
                   2110:                 my $checked = '';
                   2111:                 if ($val eq $curroption) {
                   2112:                     $checked = ' checked="checked"';
                   2113:                 }
                   2114:                 $datatable .= '<span class="LC_nobreak"><label>'.
1.160.6.8  raeburn  2115:                               '<input type="radio" name="authorreq__LC_adv"'.
                   2116:                               ' value="'.$val.'"'.$checked.' />'.
1.160.6.5  raeburn  2117:                               $titles{$option}.'</label></span>&nbsp; ';
                   2118:             }
1.101     raeburn  2119:         } else {
                   2120:             my $checked = 'checked="checked" ';
                   2121:             if (ref($settings) eq 'HASH') {
                   2122:                 if (ref($settings->{$item}) eq 'HASH') {
                   2123:                     if ($settings->{$item}->{'_LC_adv'} == 0) {
                   2124:                         $checked = '';
                   2125:                     } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
                   2126:                         $checked = 'checked="checked" ';
                   2127:                     }
1.79      raeburn  2128:                 }
1.72      raeburn  2129:             }
1.101     raeburn  2130:             $datatable .= '<span class="LC_nobreak"><label>'.
                   2131:                           '<input type="checkbox" name="'.$context.'_'.$item.
                   2132:                           '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
                   2133:                           '</label></span>&nbsp; ';
                   2134:         }
                   2135:     }
                   2136:     if ($context eq 'requestcourses') {
                   2137:         $datatable .= '</tr><tr>';
                   2138:         foreach my $item (@usertools) {
1.106     raeburn  2139:             $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72      raeburn  2140:         }
1.101     raeburn  2141:         $datatable .= '</tr></table>';
1.72      raeburn  2142:     }
1.98      raeburn  2143:     $datatable .= '</td></tr>';
1.30      raeburn  2144:     $$rowtotal += $typecount;
1.3       raeburn  2145:     return $datatable;
                   2146: }
                   2147: 
1.160.6.5  raeburn  2148: sub print_requestmail {
                   2149:     my ($dom,$action,$settings,$rowtotal) = @_;
1.160.6.25  raeburn  2150:     my ($now,$datatable,%currapp);
1.102     raeburn  2151:     $now = time;
                   2152:     if (ref($settings) eq 'HASH') {
                   2153:         if (ref($settings->{'notify'}) eq 'HASH') {
                   2154:             if ($settings->{'notify'}{'approval'} ne '') {
1.160.6.34  raeburn  2155:                 map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102     raeburn  2156:             }
                   2157:         }
                   2158:     }
1.160.6.16  raeburn  2159:     my $numinrow = 2;
1.160.6.34  raeburn  2160:     my $css_class;
                   2161:     $css_class = ($$rowtotal%2? ' class="LC_odd_row"':'');
1.160.6.5  raeburn  2162:     my $text;
                   2163:     if ($action eq 'requestcourses') {
                   2164:         $text = &mt('Receive notification of course requests requiring approval');
1.160.6.34  raeburn  2165:     } elsif ($action eq 'requestauthor') {
                   2166:         $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.160.6.5  raeburn  2167:     } else {
1.160.6.34  raeburn  2168:        $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.160.6.5  raeburn  2169:     }
1.160.6.34  raeburn  2170:     $datatable = '<tr'.$css_class.'>'.
1.160.6.5  raeburn  2171:                  ' <td>'.$text.'</td>'.
1.102     raeburn  2172:                  ' <td class="LC_left_item">';
1.160.6.16  raeburn  2173:     my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.160.6.34  raeburn  2174:                                                  $action.'notifyapproval',%currapp);
1.160.6.16  raeburn  2175:     if ($numdc > 0) {
                   2176:         $datatable .= $table;
1.102     raeburn  2177:     } else {
                   2178:         $datatable .= &mt('There are no active Domain Coordinators');
                   2179:     }
                   2180:     $datatable .='</td></tr>';
                   2181:     return $datatable;
                   2182: }
                   2183: 
1.160.6.30  raeburn  2184: sub print_studentcode {
                   2185:     my ($settings,$rowtotal) = @_;
                   2186:     my $rownum = 0; 
                   2187:     my ($output,%current);
                   2188:     my @crstypes = ('official','unofficial','community','textbook');
1.160.6.51  raeburn  2189:     if (ref($settings) eq 'HASH') {
                   2190:         if (ref($settings->{'uniquecode'}) eq 'HASH') {
                   2191:             foreach my $type (@crstypes) {
                   2192:                 $current{$type} = $settings->{'uniquecode'}{$type};
                   2193:             }
1.160.6.30  raeburn  2194:         }
                   2195:     }
                   2196:     $output .= '<tr>'.
                   2197:                '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
                   2198:                '<td class="LC_left_item">';
                   2199:     foreach my $type (@crstypes) {
                   2200:         my $check = ' ';
                   2201:         if ($current{$type}) {
                   2202:             $check = ' checked="checked" ';
                   2203:         }
                   2204:         $output .= '<span class="LC_nobreak"><label>'.
                   2205:                    '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
                   2206:                    &mt($type).'</label></span>'.('&nbsp;'x2).' ';
                   2207:     }
                   2208:     $output .= '</td></tr>';
                   2209:     $$rowtotal ++;
                   2210:     return $output;
                   2211: }
                   2212: 
                   2213: sub print_textbookcourses {
1.160.6.46  raeburn  2214:     my ($dom,$type,$settings,$rowtotal) = @_;
1.160.6.30  raeburn  2215:     my $rownum = 0;
                   2216:     my $css_class;
                   2217:     my $itemcount = 1;
                   2218:     my $maxnum = 0;
                   2219:     my $bookshash;
                   2220:     if (ref($settings) eq 'HASH') {
1.160.6.46  raeburn  2221:         $bookshash = $settings->{$type};
1.160.6.30  raeburn  2222:     }
                   2223:     my %ordered;
                   2224:     if (ref($bookshash) eq 'HASH') {
                   2225:         foreach my $item (keys(%{$bookshash})) {
                   2226:             if (ref($bookshash->{$item}) eq 'HASH') {
                   2227:                 my $num = $bookshash->{$item}{'order'};
                   2228:                 $ordered{$num} = $item;
                   2229:             }
                   2230:         }
                   2231:     }
                   2232:     my $confname = $dom.'-domainconfig';
                   2233:     my $switchserver = &check_switchserver($dom,$confname);
1.160.6.46  raeburn  2234:     my $maxnum = scalar(keys(%ordered));
                   2235:     my $datatable;
1.160.6.30  raeburn  2236:     if (keys(%ordered)) {
                   2237:         my @items = sort { $a <=> $b } keys(%ordered);
                   2238:         for (my $i=0; $i<@items; $i++) {
                   2239:             $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   2240:             my $key = $ordered{$items[$i]};
                   2241:             my %coursehash=&Apache::lonnet::coursedescription($key);
                   2242:             my $coursetitle = $coursehash{'description'};
1.160.6.47  raeburn  2243:             my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.160.6.30  raeburn  2244:             if (ref($bookshash->{$key}) eq 'HASH') {
                   2245:                 $subject = $bookshash->{$key}->{'subject'};
                   2246:                 $title = $bookshash->{$key}->{'title'};
1.160.6.46  raeburn  2247:                 if ($type eq 'textbooks') {
1.160.6.47  raeburn  2248:                     $publisher = $bookshash->{$key}->{'publisher'};
1.160.6.46  raeburn  2249:                     $author = $bookshash->{$key}->{'author'};
                   2250:                     $image = $bookshash->{$key}->{'image'};
                   2251:                     if ($image ne '') {
                   2252:                         my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
                   2253:                         my $imagethumb = "$path/tn-".$imagefile;
                   2254:                         $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
                   2255:                     }
1.160.6.30  raeburn  2256:                 }
                   2257:             }
1.160.6.46  raeburn  2258:             my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.160.6.30  raeburn  2259:             $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.160.6.46  raeburn  2260:                          .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.160.6.30  raeburn  2261:             for (my $k=0; $k<=$maxnum; $k++) {
                   2262:                 my $vpos = $k+1;
                   2263:                 my $selstr;
                   2264:                 if ($k == $i) {
                   2265:                     $selstr = ' selected="selected" ';
                   2266:                 }
                   2267:                 $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   2268:             }
                   2269:             $datatable .= '</select>'.('&nbsp;'x2).
1.160.6.46  raeburn  2270:                 '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.160.6.30  raeburn  2271:                 &mt('Delete?').'</label></span></td>'.
                   2272:                 '<td colspan="2">'.
1.160.6.46  raeburn  2273:                 '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.160.6.30  raeburn  2274:                 ('&nbsp;'x2).
1.160.6.46  raeburn  2275:                 '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
                   2276:             if ($type eq 'textbooks') {
                   2277:                 $datatable .= ('&nbsp;'x2).
1.160.6.47  raeburn  2278:                               '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
                   2279:                               ('&nbsp;'x2).
1.160.6.46  raeburn  2280:                               '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
                   2281:                               ('&nbsp;'x2).
                   2282:                               '<span class="LC_nobreak">'.&mt('Thumbnail:');
                   2283:                 if ($image) {
                   2284:                     $datatable .= '<span class="LC_nobreak">'.
                   2285:                                   $imgsrc.
                   2286:                                   '<label><input type="checkbox" name="'.$type.'_image_del"'.
                   2287:                                   ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
                   2288:                                   '<span class="LC_nobreak">&nbsp;'.&mt('Replace:').'&nbsp;';
                   2289:                 }
                   2290:                 if ($switchserver) {
                   2291:                     $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   2292:                 } else {
                   2293:                     $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
                   2294:                 }
1.160.6.30  raeburn  2295:             }
1.160.6.46  raeburn  2296:             $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.160.6.30  raeburn  2297:                           '<span class="LC_nobreak">'.&mt('LON-CAPA course:').'&nbsp;'.
                   2298:                           $coursetitle.'</span></td></tr>'."\n";
                   2299:             $itemcount ++;
                   2300:         }
                   2301:     }
                   2302:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.46  raeburn  2303:     my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.160.6.30  raeburn  2304:     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.160.6.46  raeburn  2305:                   '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
                   2306:                   '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.160.6.30  raeburn  2307:     for (my $k=0; $k<$maxnum+1; $k++) {
                   2308:         my $vpos = $k+1;
                   2309:         my $selstr;
                   2310:         if ($k == $maxnum) {
                   2311:             $selstr = ' selected="selected" ';
                   2312:         }
                   2313:         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   2314:     }
                   2315:     $datatable .= '</select>&nbsp;'."\n".
1.160.6.87  raeburn  2316:                   '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</span></td>'."\n".
1.160.6.30  raeburn  2317:                   '<td colspan="2">'.
1.160.6.46  raeburn  2318:                   '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.160.6.30  raeburn  2319:                   ('&nbsp;'x2).
1.160.6.46  raeburn  2320:                   '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
                   2321:                   ('&nbsp;'x2);
                   2322:     if ($type eq 'textbooks') {
1.160.6.47  raeburn  2323:         $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
                   2324:                       ('&nbsp;'x2).
                   2325:                       '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.160.6.46  raeburn  2326:                       ('&nbsp;'x2).
                   2327:                       '<span class="LC_nobreak">'.&mt('Image:').'&nbsp;';
                   2328:         if ($switchserver) {
                   2329:             $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   2330:         } else {
                   2331:             $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
                   2332:         }
1.160.6.87  raeburn  2333:         $datatable .= '</span>'."\n";
1.160.6.30  raeburn  2334:     }
1.160.6.87  raeburn  2335:     $datatable .= '<span class="LC_nobreak">'.&mt('LON-CAPA course:').'&nbsp;'.
1.160.6.46  raeburn  2336:                   &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
                   2337:                   '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.160.6.30  raeburn  2338:                   &Apache::loncommon::selectcourse_link
1.160.6.87  raeburn  2339:                       ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course').
1.160.6.30  raeburn  2340:                   '</span></td>'."\n".
                   2341:                   '</tr>'."\n";
                   2342:     $itemcount ++;
                   2343:     return $datatable;
                   2344: }
                   2345: 
                   2346: sub textbookcourses_javascript {
1.160.6.46  raeburn  2347:     my ($settings) = @_;
                   2348:     return unless(ref($settings) eq 'HASH');
                   2349:     my (%ordered,%total,%jstext);
                   2350:     foreach my $type ('textbooks','templates') {
                   2351:         $total{$type} = 0;
                   2352:         if (ref($settings->{$type}) eq 'HASH') {
                   2353:             foreach my $item (keys(%{$settings->{$type}})) {
                   2354:                 if (ref($settings->{$type}->{$item}) eq 'HASH') {
                   2355:                     my $num = $settings->{$type}->{$item}{'order'};
                   2356:                     $ordered{$type}{$num} = $item;
                   2357:                 }
                   2358:             }
                   2359:             $total{$type} = scalar(keys(%{$settings->{$type}}));
                   2360:         }
                   2361:         my @jsarray = ();
                   2362:         foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
                   2363:             push(@jsarray,$ordered{$type}{$item});
                   2364:         }
                   2365:         $jstext{$type} = '    var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.160.6.30  raeburn  2366:     }
                   2367:     return <<"ENDSCRIPT";
                   2368: <script type="text/javascript">
                   2369: // <![CDATA[
1.160.6.46  raeburn  2370: function reorderBooks(form,item,caller) {
1.160.6.30  raeburn  2371:     var changedVal;
1.160.6.46  raeburn  2372: $jstext{'textbooks'};
                   2373: $jstext{'templates'};
                   2374:     var newpos;
                   2375:     var maxh;
                   2376:     if (caller == 'textbooks') {  
                   2377:         newpos = 'textbooks_addbook_pos';
                   2378:         maxh = 1 + $total{'textbooks'};
                   2379:     } else {
                   2380:         newpos = 'templates_addbook_pos';
                   2381:         maxh = 1 + $total{'templates'};
                   2382:     }
1.160.6.30  raeburn  2383:     var current = new Array;
                   2384:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
                   2385:     if (item == newpos) {
                   2386:         changedVal = newitemVal;
                   2387:     } else {
                   2388:         changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
                   2389:         current[newitemVal] = newpos;
                   2390:     }
1.160.6.46  raeburn  2391:     if (caller == 'textbooks') {
                   2392:         for (var i=0; i<textbooks.length; i++) {
                   2393:             var elementName = 'textbooks_'+textbooks[i];
                   2394:             if (elementName != item) {
                   2395:                 if (form.elements[elementName]) {
                   2396:                     var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   2397:                     current[currVal] = elementName;
                   2398:                 }
                   2399:             }
                   2400:         }
                   2401:     }
                   2402:     if (caller == 'templates') {
                   2403:         for (var i=0; i<templates.length; i++) {
                   2404:             var elementName = 'templates_'+templates[i];
                   2405:             if (elementName != item) {
                   2406:                 if (form.elements[elementName]) {
                   2407:                     var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   2408:                     current[currVal] = elementName;
                   2409:                 }
1.160.6.30  raeburn  2410:             }
                   2411:         }
                   2412:     }
                   2413:     var oldVal;
                   2414:     for (var j=0; j<maxh; j++) {
                   2415:         if (current[j] == undefined) {
                   2416:             oldVal = j;
                   2417:         }
                   2418:     }
                   2419:     if (oldVal < changedVal) {
                   2420:         for (var k=oldVal+1; k<=changedVal ; k++) {
                   2421:            var elementName = current[k];
                   2422:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   2423:         }
                   2424:     } else {
                   2425:         for (var k=changedVal; k<oldVal; k++) {
                   2426:             var elementName = current[k];
                   2427:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   2428:         }
                   2429:     }
                   2430:     return;
                   2431: }
                   2432: 
                   2433: // ]]>
                   2434: </script>
                   2435: 
                   2436: ENDSCRIPT
                   2437: }
                   2438: 
1.3       raeburn  2439: sub print_autoenroll {
1.30      raeburn  2440:     my ($dom,$settings,$rowtotal) = @_;
1.3       raeburn  2441:     my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.160.6.68  raeburn  2442:     my ($defdom,$runon,$runoff,$coownerson,$coownersoff,$failsafe);
1.3       raeburn  2443:     if (ref($settings) eq 'HASH') {
                   2444:         if (exists($settings->{'run'})) {
                   2445:             if ($settings->{'run'} eq '0') {
                   2446:                 $runoff = ' checked="checked" ';
                   2447:                 $runon = ' ';
                   2448:             } else {
                   2449:                 $runon = ' checked="checked" ';
                   2450:                 $runoff = ' ';
                   2451:             }
                   2452:         } else {
                   2453:             if ($autorun) {
                   2454:                 $runon = ' checked="checked" ';
                   2455:                 $runoff = ' ';
                   2456:             } else {
                   2457:                 $runoff = ' checked="checked" ';
                   2458:                 $runon = ' ';
                   2459:             }
                   2460:         }
1.129     raeburn  2461:         if (exists($settings->{'co-owners'})) {
                   2462:             if ($settings->{'co-owners'} eq '0') {
                   2463:                 $coownersoff = ' checked="checked" ';
                   2464:                 $coownerson = ' ';
                   2465:             } else {
                   2466:                 $coownerson = ' checked="checked" ';
                   2467:                 $coownersoff = ' ';
                   2468:             }
                   2469:         } else {
                   2470:             $coownersoff = ' checked="checked" ';
                   2471:             $coownerson = ' ';
                   2472:         }
1.3       raeburn  2473:         if (exists($settings->{'sender_domain'})) {
                   2474:             $defdom = $settings->{'sender_domain'};
                   2475:         }
1.160.6.68  raeburn  2476:         if (exists($settings->{'autofailsafe'})) {
                   2477:             $failsafe = $settings->{'autofailsafe'};
                   2478:         }
1.14      raeburn  2479:     } else {
                   2480:         if ($autorun) {
                   2481:             $runon = ' checked="checked" ';
                   2482:             $runoff = ' ';
                   2483:         } else {
                   2484:             $runoff = ' checked="checked" ';
                   2485:             $runon = ' ';
                   2486:         }
1.3       raeburn  2487:     }
                   2488:     my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39      raeburn  2489:     my $notif_sender;
                   2490:     if (ref($settings) eq 'HASH') {
                   2491:         $notif_sender = $settings->{'sender_uname'};
                   2492:     }
1.3       raeburn  2493:     my $datatable='<tr class="LC_odd_row">'.
                   2494:                   '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8       raeburn  2495:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3       raeburn  2496:                   '<input type="radio" name="autoenroll_run"'.
1.8       raeburn  2497:                   $runon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   2498:                   '<label><input type="radio" name="autoenroll_run"'.
1.14      raeburn  2499:                   $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3       raeburn  2500:                   '</tr><tr>'.
                   2501:                   '<td>'.&mt('Notification messages - sender').
1.8       raeburn  2502:                   '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3       raeburn  2503:                   &mt('username').':&nbsp;'.
                   2504:                   '<input type="text" name="sender_uname" value="'.
1.39      raeburn  2505:                   $notif_sender.'" size="10" />&nbsp;&nbsp;'.&mt('domain').
1.129     raeburn  2506:                   ':&nbsp;'.$domform.'</span></td></tr>'.
                   2507:                   '<tr class="LC_odd_row">'.
                   2508:                   '<td>'.&mt('Automatically assign co-ownership').'</td>'.
                   2509:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   2510:                   '<input type="radio" name="autoassign_coowners"'.
                   2511:                   $coownerson.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   2512:                   '<label><input type="radio" name="autoassign_coowners"'.
                   2513:                   $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.160.6.68  raeburn  2514:                   '</tr><tr>'.
                   2515:                   '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
                   2516:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
                   2517:                   '<input type="text" name="autoenroll_failsafe"'.
1.160.6.87  raeburn  2518:                   ' value="'.$failsafe.'" size="4" /></span></td></tr>';
1.160.6.68  raeburn  2519:     $$rowtotal += 4;
1.3       raeburn  2520:     return $datatable;
                   2521: }
                   2522: 
                   2523: sub print_autoupdate {
1.30      raeburn  2524:     my ($position,$dom,$settings,$rowtotal) = @_;
1.3       raeburn  2525:     my $datatable;
                   2526:     if ($position eq 'top') {
                   2527:         my $updateon = ' ';
                   2528:         my $updateoff = ' checked="checked" ';
                   2529:         my $classlistson = ' ';
                   2530:         my $classlistsoff = ' checked="checked" ';
                   2531:         if (ref($settings) eq 'HASH') {
                   2532:             if ($settings->{'run'} eq '1') {
                   2533:                 $updateon = $updateoff;
                   2534:                 $updateoff = ' ';
                   2535:             }
                   2536:             if ($settings->{'classlists'} eq '1') {
                   2537:                 $classlistson = $classlistsoff;
                   2538:                 $classlistsoff = ' ';
                   2539:             }
                   2540:         }
                   2541:         my %title = (
                   2542:                    run => 'Auto-update active?',
                   2543:                    classlists => 'Update information in classlists?',
                   2544:                     );
                   2545:         $datatable = '<tr class="LC_odd_row">'. 
                   2546:                   '<td>'.&mt($title{'run'}).'</td>'.
1.8       raeburn  2547:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3       raeburn  2548:                   '<input type="radio" name="autoupdate_run"'.
1.8       raeburn  2549:                   $updateon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   2550:                   '<label><input type="radio" name="autoupdate_run"'.
                   2551:                   $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3       raeburn  2552:                   '</tr><tr>'.
                   2553:                   '<td>'.&mt($title{'classlists'}).'</td>'.
1.8       raeburn  2554:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
                   2555:                   '<label><input type="radio" name="classlists"'.
                   2556:                   $classlistson.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   2557:                   '<label><input type="radio" name="classlists"'.
                   2558:                   $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3       raeburn  2559:                   '</tr>';
1.30      raeburn  2560:         $$rowtotal += 2;
1.131     raeburn  2561:     } elsif ($position eq 'middle') {
                   2562:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   2563:         my $numinrow = 3;
                   2564:         my $locknamesettings;
                   2565:         $datatable .= &insttypes_row($settings,$types,$usertypes,
                   2566:                                      $dom,$numinrow,$othertitle,
                   2567:                                     'lockablenames');
                   2568:         $$rowtotal ++;
1.3       raeburn  2569:     } else {
1.44      raeburn  2570:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132     raeburn  2571:         my @fields = ('lastname','firstname','middlename','generation',
1.20      raeburn  2572:                       'permanentemail','id');
1.33      raeburn  2573:         my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3       raeburn  2574:         my $numrows = 0;
1.26      raeburn  2575:         if (ref($types) eq 'ARRAY') {
                   2576:             if (@{$types} > 0) {
                   2577:                 $datatable = 
                   2578:                     &usertype_update_row($settings,$usertypes,\%fieldtitles,
                   2579:                                          \@fields,$types,\$numrows);
1.30      raeburn  2580:                     $$rowtotal += @{$types}; 
1.26      raeburn  2581:             }
1.3       raeburn  2582:         }
                   2583:         $datatable .= 
                   2584:             &usertype_update_row($settings,{'default' => $othertitle},
                   2585:                                  \%fieldtitles,\@fields,['default'],
                   2586:                                  \$numrows);
1.30      raeburn  2587:         $$rowtotal ++;     
1.3       raeburn  2588:     }
                   2589:     return $datatable;
                   2590: }
                   2591: 
1.125     raeburn  2592: sub print_autocreate {
                   2593:     my ($dom,$settings,$rowtotal) = @_;
1.160.6.16  raeburn  2594:     my (%createon,%createoff,%currhash);
1.125     raeburn  2595:     my @types = ('xml','req');
                   2596:     if (ref($settings) eq 'HASH') {
                   2597:         foreach my $item (@types) {
                   2598:             $createoff{$item} = ' checked="checked" ';
                   2599:             $createon{$item} = ' ';
                   2600:             if (exists($settings->{$item})) {
                   2601:                 if ($settings->{$item}) {
                   2602:                     $createon{$item} = ' checked="checked" ';
                   2603:                     $createoff{$item} = ' ';
                   2604:                 }
                   2605:             }
                   2606:         }
1.160.6.16  raeburn  2607:         if ($settings->{'xmldc'} ne '') {
                   2608:             $currhash{$settings->{'xmldc'}} = 1;
                   2609:         }
1.125     raeburn  2610:     } else {
                   2611:         foreach my $item (@types) {
                   2612:             $createoff{$item} = ' checked="checked" ';
                   2613:             $createon{$item} = ' ';
                   2614:         }
                   2615:     }
                   2616:     $$rowtotal += 2;
1.160.6.16  raeburn  2617:     my $numinrow = 2;
1.125     raeburn  2618:     my $datatable='<tr class="LC_odd_row">'.
                   2619:                   '<td>'.&mt('Create pending official courses from XML files').'</td>'.
                   2620:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   2621:                   '<input type="radio" name="autocreate_xml"'.
                   2622:                   $createon{'xml'}.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   2623:                   '<label><input type="radio" name="autocreate_xml"'.
1.143     raeburn  2624:                   $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
                   2625:                   '</td></tr><tr>'.
                   2626:                   '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
                   2627:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   2628:                   '<input type="radio" name="autocreate_req"'.
                   2629:                   $createon{'req'}.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   2630:                   '<label><input type="radio" name="autocreate_req"'.
                   2631:                   $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.160.6.16  raeburn  2632:     my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
                   2633:                                                    'autocreate_xmldc',%currhash);
1.160.6.50  raeburn  2634:     $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125     raeburn  2635:     if ($numdc > 1) {
1.160.6.50  raeburn  2636:         $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
                   2637:                       '</td><td class="LC_left_item">';
1.125     raeburn  2638:     } else {
1.160.6.50  raeburn  2639:         $datatable .= &mt('Course creation processed as:').
                   2640:                       '</td><td class="LC_right_item">';
1.125     raeburn  2641:     }
1.160.6.50  raeburn  2642:     $datatable .= $dctable.'</td></tr>';
1.160.6.16  raeburn  2643:     $$rowtotal += $rows;
1.125     raeburn  2644:     return $datatable;
                   2645: }
                   2646: 
1.23      raeburn  2647: sub print_directorysrch {
1.160.6.72  raeburn  2648:     my ($position,$dom,$settings,$rowtotal) = @_;
                   2649:     my $datatable;
                   2650:     if ($position eq 'top') {
                   2651:         my $instsrchon = ' ';
                   2652:         my $instsrchoff = ' checked="checked" ';
                   2653:         my ($exacton,$containson,$beginson);
                   2654:         my $instlocalon = ' ';
                   2655:         my $instlocaloff = ' checked="checked" ';
                   2656:         if (ref($settings) eq 'HASH') {
                   2657:             if ($settings->{'available'} eq '1') {
                   2658:                 $instsrchon = $instsrchoff;
                   2659:                 $instsrchoff = ' ';
                   2660:             }
                   2661:             if ($settings->{'localonly'} eq '1') {
                   2662:                 $instlocalon = $instlocaloff;
                   2663:                 $instlocaloff = ' ';
                   2664:             }
                   2665:             if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
                   2666:                 foreach my $type (@{$settings->{'searchtypes'}}) {
                   2667:                     if ($type eq 'exact') {
                   2668:                         $exacton = ' checked="checked" ';
                   2669:                     } elsif ($type eq 'contains') {
                   2670:                         $containson = ' checked="checked" ';
                   2671:                     } elsif ($type eq 'begins') {
                   2672:                         $beginson = ' checked="checked" ';
                   2673:                     }
                   2674:                 }
                   2675:             } else {
                   2676:                 if ($settings->{'searchtypes'} eq 'exact') {
                   2677:                     $exacton = ' checked="checked" ';
                   2678:                 } elsif ($settings->{'searchtypes'} eq 'contains') {
                   2679:                     $containson = ' checked="checked" ';
                   2680:                 } elsif ($settings->{'searchtypes'} eq 'specify') {
1.25      raeburn  2681:                     $exacton = ' checked="checked" ';
                   2682:                     $containson = ' checked="checked" ';
                   2683:                 }
                   2684:             }
1.23      raeburn  2685:         }
1.160.6.72  raeburn  2686:         my ($searchtitles,$titleorder) = &sorted_searchtitles();
                   2687:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23      raeburn  2688: 
1.160.6.72  raeburn  2689:         my $numinrow = 4;
                   2690:         my $cansrchrow = 0;
                   2691:         $datatable='<tr class="LC_odd_row">'.
                   2692:                    '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
                   2693:                    '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   2694:                    '<input type="radio" name="dirsrch_available"'.
                   2695:                    $instsrchon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   2696:                    '<label><input type="radio" name="dirsrch_available"'.
                   2697:                    $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
                   2698:                    '</tr><tr>'.
                   2699:                    '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
                   2700:                    '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   2701:                    '<input type="radio" name="dirsrch_instlocalonly"'.
                   2702:                    $instlocaloff.' value="0" />'.&mt('Yes').'</label>&nbsp;'.
                   2703:                    '<label><input type="radio" name="dirsrch_instlocalonly"'.
                   2704:                    $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
                   2705:                    '</tr>';
                   2706:         $$rowtotal += 2;
                   2707:         if (ref($usertypes) eq 'HASH') {
                   2708:             if (keys(%{$usertypes}) > 0) {
                   2709:                 $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
                   2710:                                              $numinrow,$othertitle,'cansearch');
                   2711:                 $cansrchrow = 1;
                   2712:             }
1.26      raeburn  2713:         }
1.160.6.72  raeburn  2714:         if ($cansrchrow) {
                   2715:             $$rowtotal ++;
                   2716:             $datatable .= '<tr>';
                   2717:         } else {
                   2718:             $datatable .= '<tr class="LC_odd_row">';
                   2719:         }
                   2720:         $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
                   2721:                       '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
                   2722:         foreach my $title (@{$titleorder}) {
                   2723:             if (defined($searchtitles->{$title})) {
                   2724:                 my $check = ' ';
                   2725:                 if (ref($settings) eq 'HASH') {
                   2726:                     if (ref($settings->{'searchby'}) eq 'ARRAY') {
                   2727:                         if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
                   2728:                             $check = ' checked="checked" ';
                   2729:                         }
1.39      raeburn  2730:                     }
1.25      raeburn  2731:                 }
1.160.6.72  raeburn  2732:                 $datatable .= '<td class="LC_left_item">'.
                   2733:                               '<span class="LC_nobreak"><label>'.
                   2734:                               '<input type="checkbox" name="searchby" '.
                   2735:                               'value="'.$title.'"'.$check.'/>'.
                   2736:                               $searchtitles->{$title}.'</label></span></td>';
1.25      raeburn  2737:             }
                   2738:         }
1.160.6.72  raeburn  2739:         $datatable .= '</tr></table></td></tr>';
                   2740:         $$rowtotal ++;
                   2741:         if ($cansrchrow) {
                   2742:             $datatable .= '<tr class="LC_odd_row">';
                   2743:         } else {
                   2744:             $datatable .= '<tr>';
                   2745:         }
                   2746:         $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.   
                   2747:                       '<td class="LC_left_item" colspan="2">'.
                   2748:                       '<span class="LC_nobreak"><label>'.
                   2749:                       '<input type="checkbox" name="searchtypes" '.
                   2750:                       $exacton.' value="exact" />'.&mt('Exact match').
                   2751:                       '</label>&nbsp;'.
                   2752:                       '<label><input type="checkbox" name="searchtypes" '.
                   2753:                       $beginson.' value="begins" />'.&mt('Begins with').
                   2754:                       '</label>&nbsp;'.
                   2755:                       '<label><input type="checkbox" name="searchtypes" '.
                   2756:                       $containson.' value="contains" />'.&mt('Contains').
                   2757:                       '</label></span></td></tr>';
                   2758:         $$rowtotal ++;
1.26      raeburn  2759:     } else {
1.160.6.72  raeburn  2760:         my $domsrchon = ' checked="checked" ';
                   2761:         my $domsrchoff = ' ';
                   2762:         my $domlocalon = ' ';
                   2763:         my $domlocaloff = ' checked="checked" ';
                   2764:         if (ref($settings) eq 'HASH') {
                   2765:             if ($settings->{'lclocalonly'} eq '1') {
                   2766:                 $domlocalon = $domlocaloff;
                   2767:                 $domlocaloff = ' ';
                   2768:             }
                   2769:             if ($settings->{'lcavailable'} eq '0') {
                   2770:                 $domsrchoff = $domsrchon;
                   2771:                 $domsrchon = ' ';
                   2772:             }
                   2773:         }
                   2774:         $datatable='<tr class="LC_odd_row">'.
                   2775:                       '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
                   2776:                       '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   2777:                       '<input type="radio" name="dirsrch_domavailable"'.
                   2778:                       $domsrchon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   2779:                       '<label><input type="radio" name="dirsrch_domavailable"'.
                   2780:                       $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
                   2781:                       '</tr><tr>'.
                   2782:                       '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
                   2783:                       '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   2784:                       '<input type="radio" name="dirsrch_domlocalonly"'.
                   2785:                       $domlocaloff.' value="0" />'.&mt('Yes').'</label>&nbsp;'.
                   2786:                       '<label><input type="radio" name="dirsrch_domlocalonly"'.
                   2787:                       $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
                   2788:                       '</tr>';
                   2789:         $$rowtotal += 2;
1.26      raeburn  2790:     }
1.25      raeburn  2791:     return $datatable;
                   2792: }
                   2793: 
1.28      raeburn  2794: sub print_contacts {
1.160.6.78  raeburn  2795:     my ($position,$dom,$settings,$rowtotal) = @_;
1.28      raeburn  2796:     my $datatable;
                   2797:     my @contacts = ('adminemail','supportemail');
1.160.6.78  raeburn  2798:     my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
                   2799:         $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings);
                   2800:     if ($position eq 'top') {
                   2801:         if (ref($settings) eq 'HASH') {
                   2802:             foreach my $item (@contacts) {
                   2803:                 if (exists($settings->{$item})) {
                   2804:                     $to{$item} = $settings->{$item};
                   2805:                 }
1.28      raeburn  2806:             }
                   2807:         }
1.160.6.78  raeburn  2808:     } elsif ($position eq 'middle') {
                   2809:         @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
                   2810:                      'updatesmail','idconflictsmail');
1.28      raeburn  2811:         foreach my $type (@mailings) {
1.160.6.78  raeburn  2812:             $otheremails{$type} = '';
                   2813:         }
                   2814:     } else {
                   2815:         @mailings = ('helpdeskmail','otherdomsmail');
                   2816:         foreach my $type (@mailings) {
                   2817:             $otheremails{$type} = '';
                   2818:         }
                   2819:         $bccemails{'helpdeskmail'} = '';
                   2820:         $bccemails{'otherdomsmail'} = '';
                   2821:         $includestr{'helpdeskmail'} = '';
                   2822:         $includestr{'otherdomsmail'} = '';
                   2823:         ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
                   2824:     }
                   2825:     if (ref($settings) eq 'HASH') {
                   2826:         unless ($position eq 'top') {
                   2827:             foreach my $type (@mailings) {
                   2828:                 if (exists($settings->{$type})) {
                   2829:                     if (ref($settings->{$type}) eq 'HASH') {
                   2830:                         foreach my $item (@contacts) {
                   2831:                             if ($settings->{$type}{$item}) {
                   2832:                                 $checked{$type}{$item} = ' checked="checked" ';
                   2833:                             }
1.28      raeburn  2834:                         }
1.160.6.78  raeburn  2835:                         $otheremails{$type} = $settings->{$type}{'others'};
                   2836:                         if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
                   2837:                             $bccemails{$type} = $settings->{$type}{'bcc'};
                   2838:                             if ($settings->{$type}{'include'} ne '') {
                   2839:                                 ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
                   2840:                                 $includestr{$type} = &unescape($includestr{$type});
                   2841:                             }
                   2842:                         }
                   2843:                     }
                   2844:                 } elsif ($type eq 'lonstatusmail') {
                   2845:                     $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
                   2846:                 }
                   2847:             }
                   2848:         }
                   2849:         if ($position eq 'bottom') {
                   2850:             foreach my $type (@mailings) {
                   2851:                 $bccemails{$type} = $settings->{$type}{'bcc'};
                   2852:                 if ($settings->{$type}{'include'} ne '') {
                   2853:                     ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
                   2854:                     $includestr{$type} = &unescape($includestr{$type});
                   2855:                 }
                   2856:             }
                   2857:             if (ref($settings->{'helpform'}) eq 'HASH') {
                   2858:                 if (ref($fields) eq 'ARRAY') {
                   2859:                     foreach my $field (@{$fields}) {
                   2860:                         $currfield{$field} = $settings->{'helpform'}{$field};
1.28      raeburn  2861:                     }
1.160.6.78  raeburn  2862:                 }
                   2863:                 if (exists($settings->{'helpform'}{'maxsize'})) {
                   2864:                     $maxsize = $settings->{'helpform'}{'maxsize'};
                   2865:                 } else {
                   2866:                     $maxsize = '1.0';
                   2867:                 }
                   2868:             } else {
                   2869:                 if (ref($fields) eq 'ARRAY') {
                   2870:                     foreach my $field (@{$fields}) {
                   2871:                         $currfield{$field} = 'yes';
1.134     raeburn  2872:                     }
1.28      raeburn  2873:                 }
1.160.6.78  raeburn  2874:                 $maxsize = '1.0';
1.28      raeburn  2875:             }
                   2876:         }
                   2877:     } else {
1.160.6.78  raeburn  2878:         if ($position eq 'top') {
                   2879:             $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
                   2880:             $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
                   2881:             $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
                   2882:             $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
                   2883:             $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
                   2884:             $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
                   2885:             $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
                   2886:             $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
                   2887:         } elsif ($position eq 'bottom') {
                   2888:             $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
                   2889:             $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
                   2890:             if (ref($fields) eq 'ARRAY') {
                   2891:                 foreach my $field (@{$fields}) {
                   2892:                     $currfield{$field} = 'yes';
                   2893:                 }
                   2894:             }
                   2895:             $maxsize = '1.0';
                   2896:         }
1.28      raeburn  2897:     }
                   2898:     my ($titles,$short_titles) = &contact_titles();
                   2899:     my $rownum = 0;
                   2900:     my $css_class;
1.160.6.78  raeburn  2901:     if ($position eq 'top') {
                   2902:         foreach my $item (@contacts) {
                   2903:             $css_class = $rownum%2?' class="LC_odd_row"':'';
                   2904:             $datatable .= '<tr'.$css_class.'>'. 
                   2905:                           '<td><span class="LC_nobreak">'.$titles->{$item}.
                   2906:                           '</span></td><td class="LC_right_item">'.
                   2907:                           '<input type="text" name="'.$item.'" value="'.
                   2908:                           $to{$item}.'" /></td></tr>';
                   2909:             $rownum ++;
                   2910:         }
                   2911:     } else {
                   2912:         foreach my $type (@mailings) {
                   2913:             $css_class = $rownum%2?' class="LC_odd_row"':'';
                   2914:             $datatable .= '<tr'.$css_class.'>'.
                   2915:                           '<td><span class="LC_nobreak">'.
                   2916:                           $titles->{$type}.': </span></td>'.
                   2917:                           '<td class="LC_left_item">';
                   2918:             if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
                   2919:                 $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
                   2920:             }
                   2921:             $datatable .= '<span class="LC_nobreak">';
                   2922:             foreach my $item (@contacts) {
                   2923:                 $datatable .= '<label>'.
                   2924:                               '<input type="checkbox" name="'.$type.'"'.
                   2925:                               $checked{$type}{$item}.
                   2926:                               ' value="'.$item.'" />'.$short_titles->{$item}.
                   2927:                               '</label>&nbsp;';
                   2928:             }
                   2929:             $datatable .= '</span><br />'.&mt('Others').':&nbsp;&nbsp;'.
                   2930:                           '<input type="text" name="'.$type.'_others" '.
                   2931:                           'value="'.$otheremails{$type}.'"  />';
                   2932:             my %locchecked;
                   2933:             if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
                   2934:                 foreach my $loc ('s','b') {
                   2935:                     if ($includeloc{$type} eq $loc) {
                   2936:                         $locchecked{$loc} = ' checked="checked"';
                   2937:                         last;
                   2938:                     }
                   2939:                 }
                   2940:                 $datatable .= '<br />'.&mt('Bcc:').('&nbsp;'x6).
                   2941:                               '<input type="text" name="'.$type.'_bcc" '.
                   2942:                               'value="'.$bccemails{$type}.'"  /></fieldset>'.
                   2943:                               '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
                   2944:                               &mt('Text automatically added to e-mail:').' '.
1.160.6.87  raeburn  2945:                               '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br />'.
1.160.6.78  raeburn  2946:                               '<span class="LC_nobreak">'.&mt('Location:').'&nbsp;'.
                   2947:                               '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
                   2948:                               ('&nbsp;'x2).
                   2949:                               '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
                   2950:                               '</span></fieldset>';
                   2951:             }
                   2952:             $datatable .= '</td></tr>'."\n";
                   2953:             $rownum ++;
                   2954:         }
1.28      raeburn  2955:     }
1.160.6.78  raeburn  2956:     if ($position eq 'middle') {
                   2957:         my %choices;
                   2958:         $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',
                   2959:                                        &Apache::loncommon::modal_link('http://loncapa.org/core.html',
                   2960:                                        &mt('LON-CAPA core group - MSU'),600,500));
                   2961:         $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
                   2962:                                         &Apache::loncommon::modal_link('http://loncapa.org/core.html',
                   2963:                                         &mt('LON-CAPA core group - MSU'),600,500));
                   2964:         my @toggles = ('reporterrors','reportupdates');
                   2965:         my %defaultchecked = ('reporterrors'  => 'on',
                   2966:                               'reportupdates' => 'on');
                   2967:         (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
                   2968:                                                    \%choices,$rownum);
                   2969:         $datatable .= $reports;
                   2970:     } elsif ($position eq 'bottom') {
1.69      raeburn  2971:         $css_class = $rownum%2?' class="LC_odd_row"':'';
1.28      raeburn  2972:         $datatable .= '<tr'.$css_class.'>'.
1.160.6.78  raeburn  2973:                       '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
                   2974:                       &mt('(e-mail, subject, and description always shown)').
                   2975:                       '</td><td class="LC_left_item">';
                   2976:         if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
                   2977:             (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
                   2978:             $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
                   2979:             foreach my $field (@{$fields}) {
                   2980:                 $datatable .= '<tr><td>'.$fieldtitles->{$field};
                   2981:                 if (($field eq 'screenshot') || ($field eq 'cc')) {
                   2982:                     $datatable .= ' '.&mt('(logged-in users)');
                   2983:                 }
                   2984:                 $datatable .='</td><td>';
                   2985:                 my $clickaction;
                   2986:                 if ($field eq 'screenshot') {
                   2987:                     $clickaction = ' onclick="screenshotSize(this);"';
                   2988:                 }
                   2989:                 if (ref($possoptions->{$field}) eq 'ARRAY') {
                   2990:                     foreach my $option (@{$possoptions->{$field}}) {
                   2991:                         my $checked;
                   2992:                         if ($currfield{$field} eq $option) {
                   2993:                             $checked = ' checked="checked"';
                   2994:                         }
                   2995:                         $datatable .= '<span class="LC_nobreak"><label>'.
                   2996:                                       '<input type="radio" name="helpform_'.$field.'" '.
                   2997:                                       'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
                   2998:                                       '</label></span>'.('&nbsp;'x2);
                   2999:                     }
                   3000:                 }
                   3001:                 if ($field eq 'screenshot') {
                   3002:                     my $display;
                   3003:                     if ($currfield{$field} eq 'no') {
                   3004:                         $display = ' style="display:none"';
                   3005:                     }
1.160.6.87  raeburn  3006:                     $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.'>'.
1.160.6.78  raeburn  3007:                                   '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
                   3008:                                   '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
                   3009:                 }
                   3010:                 $datatable .= '</td></tr>';
                   3011:             }
                   3012:             $datatable .= '</table>';
1.134     raeburn  3013:         }
                   3014:         $datatable .= '</td></tr>'."\n";
1.160.6.23  raeburn  3015:         $rownum ++;
1.28      raeburn  3016:     }
1.30      raeburn  3017:     $$rowtotal += $rownum;
1.28      raeburn  3018:     return $datatable;
                   3019: }
                   3020: 
1.160.6.78  raeburn  3021: sub contacts_javascript {
                   3022:     return <<"ENDSCRIPT";
                   3023: 
                   3024: <script type="text/javascript">
                   3025: // <![CDATA[
                   3026: 
                   3027: function screenshotSize(field) {
                   3028:     if (document.getElementById('help_screenshotsize')) {
                   3029:         if (field.value == 'no') {
                   3030:             document.getElementById('help_screenshotsize').style.display="none";
                   3031:         } else {
                   3032:             document.getElementById('help_screenshotsize').style.display="";
                   3033:         }
                   3034:     }
                   3035:     return;
                   3036: }
                   3037: 
                   3038: // ]]>
                   3039: </script>
                   3040: 
                   3041: ENDSCRIPT
                   3042: }
                   3043: 
1.118     jms      3044: sub print_helpsettings {
1.160.6.73  raeburn  3045:     my ($position,$dom,$settings,$rowtotal) = @_;
                   3046:     my $confname = $dom.'-domainconfig';
1.160.6.77  raeburn  3047:     my $formname = 'display';
1.160.6.5  raeburn  3048:     my ($datatable,$itemcount);
1.160.6.73  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_');
1.160.6.77  raeburn  3063:         my (%customroles,%ordered,%current);
1.160.6.84  raeburn  3064:         if (ref($settings) eq 'HASH') {
                   3065:             if (ref($settings->{'adhoc'}) eq 'HASH') {
                   3066:                 %current = %{$settings->{'adhoc'}};
                   3067:             }
1.160.6.77  raeburn  3068:         }
                   3069:         my $count = 0;
                   3070:         foreach my $key (sort(keys(%existing))) {
1.160.6.73  raeburn  3071:             if ($key=~/^rolesdef\_(\w+)$/) {
                   3072:                 my $rolename = $1;
1.160.6.77  raeburn  3073:                 my (%privs,$order);
1.160.6.73  raeburn  3074:                 ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
                   3075:                 $customroles{$rolename} = \%privs;
1.160.6.77  raeburn  3076:                 if (ref($current{$rolename}) eq 'HASH') {
                   3077:                     $order = $current{$rolename}{'order'};
                   3078:                 }
                   3079:                 if ($order eq '') {
                   3080:                     $order = $count;
                   3081:                 }
                   3082:                 $ordered{$order} = $rolename;
                   3083:                 $count++;
1.160.6.73  raeburn  3084:             }
                   3085:         }
1.160.6.77  raeburn  3086:         my $maxnum = scalar(keys(%ordered));
                   3087:         my @roles_by_num = ();
                   3088:         foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
                   3089:             push(@roles_by_num,$item);
                   3090:         }
                   3091:         my $context = 'domprefs';
                   3092:         my $crstype = 'Course';
                   3093:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.79  raeburn  3094:         my @accesstypes = ('all','dh','da','none');
1.160.6.77  raeburn  3095:         my ($numstatustypes,@jsarray);
                   3096:         if (ref($types) eq 'ARRAY') {
                   3097:             if (@{$types} > 0) {
                   3098:                 $numstatustypes = scalar(@{$types});
                   3099:                 push(@accesstypes,'status');
                   3100:                 @jsarray = ('bystatus');
                   3101:             }
                   3102:         }
1.160.6.86  raeburn  3103:         my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.160.6.77  raeburn  3104:         if (keys(%domhelpdesk)) {
                   3105:             push(@accesstypes,('inc','exc'));
                   3106:             push(@jsarray,('notinc','notexc'));
                   3107:         }
                   3108:         my $hiddenstr = join("','",@jsarray);
                   3109:         $datatable .= &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname);
1.160.6.73  raeburn  3110:         my $context = 'domprefs';
                   3111:         my $crstype = 'Course';
1.160.6.77  raeburn  3112:         my $prefix = 'helproles_';
                   3113:         my $add_class = 'LC_hidden';
                   3114:         foreach my $num (@roles_by_num) {
                   3115:             my $role = $ordered{$num};
                   3116:             my ($desc,$access,@statuses);
                   3117:             if (ref($current{$role}) eq 'HASH') {
                   3118:                 $desc = $current{$role}{'desc'};
                   3119:                 $access = $current{$role}{'access'};
                   3120:                 if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
                   3121:                     @statuses = @{$current{$role}{'insttypes'}};
                   3122:                 }
                   3123:             }
                   3124:             if ($desc eq '') {
                   3125:                 $desc = $role;
                   3126:             }
                   3127:             my $identifier = 'custhelp'.$num;
1.160.6.73  raeburn  3128:             my %full=();
                   3129:             my %levels= (
                   3130:                          course => {},
                   3131:                          domain => {},
                   3132:                          system => {},
                   3133:                         );
                   3134:             my %levelscurrent=(
                   3135:                                course => {},
                   3136:                                domain => {},
                   3137:                                system => {},
                   3138:                               );
                   3139:             &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
                   3140:             my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
                   3141:             $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.77  raeburn  3142:             my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
                   3143:             $datatable .= '<tr '.$css_class.'><td valign="top"><b>'.$role.'</b><br />'.
                   3144:                           '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
                   3145:             for (my $k=0; $k<=$maxnum; $k++) {
                   3146:                 my $vpos = $k+1;
                   3147:                 my $selstr;
                   3148:                 if ($k == $num) {
                   3149:                     $selstr = ' selected="selected" ';
                   3150:                 }
                   3151:                 $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   3152:             }
                   3153:             $datatable .= '</select>'.('&nbsp;'x2).
                   3154:                           '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
                   3155:                           '</td>'.
                   3156:                           '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
                   3157:                           &mt('Name shown to users:').
                   3158:                           '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
                   3159:                           '</fieldset>'.
                   3160:                           &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
                   3161:                                                 $othertitle,$usertypes,$types,\%domhelpdesk).
                   3162:                           '<fieldset>'.
                   3163:                           '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
1.160.6.73  raeburn  3164:                           &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
1.160.6.77  raeburn  3165:                                                                    \%levelscurrent,$identifier,
                   3166:                                                                    'LC_hidden',$prefix.$num.'_privs').
                   3167:                           '</fieldset></td>';
1.160.6.73  raeburn  3168:             $itemcount ++;
                   3169:         }
                   3170:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   3171:         my $newcust = 'custhelp'.$count;
                   3172:         my (%privs,%levelscurrent);
                   3173:         my %full=();
                   3174:         my %levels= (
                   3175:                      course => {},
                   3176:                      domain => {},
                   3177:                      system => {},
                   3178:                     );
                   3179:         &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
                   3180:         my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.160.6.77  raeburn  3181:         my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
                   3182:         $datatable .= '<tr '.$css_class.'><td valign="top"><span class="LC_nobreak"><label>'.
                   3183:                       '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
                   3184:                       '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
                   3185:         for (my $k=0; $k<$maxnum+1; $k++) {
                   3186:             my $vpos = $k+1;
                   3187:             my $selstr;
                   3188:             if ($k == $maxnum) {
                   3189:                 $selstr = ' selected="selected" ';
                   3190:             }
                   3191:             $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   3192:         }
                   3193:         $datatable .= '</select>&nbsp;'."\n".
1.160.6.73  raeburn  3194:                       '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
                   3195:                       '</label></span></td>'.
1.160.6.77  raeburn  3196:                       '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
                   3197:                       '<span class="LC_nobreak">'.
                   3198:                       &mt('Internal name:').
                   3199:                       '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
                   3200:                       '</span>'.('&nbsp;'x4).
                   3201:                       '<span class="LC_nobreak">'.
                   3202:                       &mt('Name shown to users:').
                   3203:                       '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
                   3204:                       '</span></fieldset>'.
                   3205:                        &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
                   3206:                                              $usertypes,$types,\%domhelpdesk).
                   3207:                       '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
1.160.6.73  raeburn  3208:                       &Apache::lonuserutils::custom_role_header($context,$crstype,
                   3209:                                                                 \@templateroles,$newcust).
                   3210:                       &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
                   3211:                                                                \%levelscurrent,$newcust).
1.160.6.87  raeburn  3212:                       '</fieldset>'.
                   3213:                       &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname).
                   3214:                       '</td></tr>';
1.160.6.73  raeburn  3215:         $count ++;
                   3216:         $$rowtotal += $count;
                   3217:     }
1.160.6.5  raeburn  3218:     return $datatable;
1.121     raeburn  3219: }
                   3220: 
1.160.6.77  raeburn  3221: sub adhocbutton {
                   3222:     my ($prefix,$num,$field,$visibility) = @_;
                   3223:     my %lt = &Apache::lonlocal::texthash(
                   3224:                                           show => 'Show details',
                   3225:                                           hide => 'Hide details',
                   3226:                                         );
                   3227:     return '<span style="text-decoration:line-through; font-weight: normal;">'.('&nbsp;'x10).
                   3228:            '</span>'.('&nbsp;'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
                   3229:            ' value="'.$lt{$visibility}.'" style="height:20px;" '.
                   3230:            'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.('&nbsp;'x2);
                   3231: }
                   3232: 
                   3233: sub helpsettings_javascript {
                   3234:     my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
                   3235:     return unless(ref($roles_by_num) eq 'ARRAY');
                   3236:     my %html_js_lt = &Apache::lonlocal::texthash(
                   3237:                                           show => 'Show details',
                   3238:                                           hide => 'Hide details',
                   3239:                                         );
                   3240:     &html_escape(\%html_js_lt);
                   3241:     my $jstext = '    var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
                   3242:     return <<"ENDSCRIPT";
                   3243: <script type="text/javascript">
                   3244: // <![CDATA[
                   3245: 
                   3246: function reorderHelpRoles(form,item) {
                   3247:     var changedVal;
                   3248: $jstext
                   3249:     var newpos = 'helproles_${total}_pos';
                   3250:     var maxh = 1 + $total;
                   3251:     var current = new Array();
                   3252:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
                   3253:     if (item == newpos) {
                   3254:         changedVal = newitemVal;
                   3255:     } else {
                   3256:         changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
                   3257:         current[newitemVal] = newpos;
                   3258:     }
                   3259:     for (var i=0; i<helproles.length; i++) {
                   3260:         var elementName = 'helproles_'+helproles[i]+'_pos';
                   3261:         if (elementName != item) {
                   3262:             if (form.elements[elementName]) {
                   3263:                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   3264:                 current[currVal] = elementName;
                   3265:             }
                   3266:         }
                   3267:     }
                   3268:     var oldVal;
                   3269:     for (var j=0; j<maxh; j++) {
                   3270:         if (current[j] == undefined) {
                   3271:             oldVal = j;
                   3272:         }
                   3273:     }
                   3274:     if (oldVal < changedVal) {
                   3275:         for (var k=oldVal+1; k<=changedVal ; k++) {
                   3276:            var elementName = current[k];
                   3277:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   3278:         }
                   3279:     } else {
                   3280:         for (var k=changedVal; k<oldVal; k++) {
                   3281:             var elementName = current[k];
                   3282:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   3283:         }
                   3284:     }
                   3285:     return;
                   3286: }
                   3287: 
                   3288: function helpdeskAccess(num) {
                   3289:     var curraccess = null;
                   3290:     if (document.$formname.elements['helproles_'+num+'_access'].length) {
                   3291:         for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
                   3292:             if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
                   3293:                 curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
                   3294:             }
                   3295:         }
                   3296:     }
                   3297:     var shown = Array();
                   3298:     var hidden = Array();
                   3299:     if (curraccess == 'none') {
                   3300:         hidden = Array('$hiddenstr');
                   3301:     } else {
                   3302:         if (curraccess == 'status') {
                   3303:             shown = Array('bystatus');
                   3304:             hidden = Array('notinc','notexc');
                   3305:         } else {
                   3306:             if (curraccess == 'exc') {
                   3307:                 shown = Array('notexc');
                   3308:                 hidden = Array('notinc','bystatus');
                   3309:             }
                   3310:             if (curraccess == 'inc') {
                   3311:                 shown = Array('notinc');
                   3312:                 hidden = Array('notexc','bystatus');
                   3313:             }
1.160.6.79  raeburn  3314:             if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
1.160.6.77  raeburn  3315:                 hidden = Array('notinc','notexc','bystatus');
                   3316:             }
                   3317:         }
                   3318:     }
                   3319:     if (hidden.length > 0) {
                   3320:         for (var i=0; i<hidden.length; i++) {
                   3321:             if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
                   3322:                 document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
                   3323:             }
                   3324:         }
                   3325:     }
                   3326:     if (shown.length > 0) {
                   3327:         for (var i=0; i<shown.length; i++) {
                   3328:             if (document.getElementById('helproles_'+num+'_'+shown[i])) {
                   3329:                 if (shown[i] == 'privs') {
                   3330:                     document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
                   3331:                 } else {
                   3332:                     document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
                   3333:                 }
                   3334:             }
                   3335:         }
                   3336:     }
                   3337:     return;
                   3338: }
                   3339: 
                   3340: function toggleHelpdeskItem(num,field) {
                   3341:     if (document.getElementById('helproles_'+num+'_'+field)) {
                   3342:         if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
                   3343:             document.getElementById('helproles_'+num+'_'+field).className =
                   3344:                 document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
                   3345:             if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
                   3346:                 document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
                   3347:             }
                   3348:         } else {
                   3349:             document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
                   3350:             if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
                   3351:                 document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
                   3352:             }
                   3353:         }
                   3354:     }
                   3355:     return;
                   3356: }
                   3357: 
                   3358: // ]]>
                   3359: </script>
                   3360: 
                   3361: ENDSCRIPT
                   3362: }
                   3363: 
                   3364: sub helpdeskroles_access {
                   3365:     my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
                   3366:         $usertypes,$types,$domhelpdesk) = @_;
                   3367:     return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
                   3368:     my %lt = &Apache::lonlocal::texthash(
                   3369:                     'rou'    => 'Role usage',
                   3370:                     'whi'    => 'Which helpdesk personnel may use this role?',
1.160.6.79  raeburn  3371:                     'all'    => 'All with domain helpdesk or helpdesk assistant role',
                   3372:                     'dh'     => 'All with domain helpdesk role',
                   3373:                     'da'     => 'All with domain helpdesk assistant role',
1.160.6.77  raeburn  3374:                     'none'   => 'None',
                   3375:                     'status' => 'Determined based on institutional status',
                   3376:                     'inc'    => 'Include all, but exclude specific personnel',
                   3377:                     'exc'    => 'Exclude all, but include specific personnel',
                   3378:                   );
                   3379:     my %usecheck = (
                   3380:                      all => ' checked="checked"',
                   3381:                    );
                   3382:     my %displaydiv = (
                   3383:                       status => 'none',
                   3384:                       inc    => 'none',
                   3385:                       exc    => 'none',
                   3386:                       priv   => 'block',
                   3387:                      );
                   3388:     my $output;
                   3389:     if (ref($current) eq 'HASH') {
                   3390:         if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
                   3391:             if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
                   3392:                 $usecheck{$current->{access}} = $usecheck{'all'};
                   3393:                 delete($usecheck{'all'});
                   3394:                 if ($current->{access} =~ /^(status|inc|exc)$/) {
                   3395:                     my $access = $1;
                   3396:                     $displaydiv{$access} = 'inline';
                   3397:                 } elsif ($current->{access} eq 'none') {
                   3398:                     $displaydiv{'priv'} = 'none';
                   3399:                 }
                   3400:             }
                   3401:         }
                   3402:     }
                   3403:     $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
                   3404:               '<p>'.$lt{'whi'}.'</p>';
                   3405:     foreach my $access (@{$accesstypes}) {
                   3406:         $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
                   3407:                    ' onclick="helpdeskAccess('."'$num'".');" />'.
                   3408:                    $lt{$access}.'</label>';
                   3409:         if ($access eq 'status') {
                   3410:             $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
                   3411:                        &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
                   3412:                                                                  $othertitle,$usertypes,$types).
                   3413:                        '</div>';
                   3414:         } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
                   3415:             $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
                   3416:                        &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
                   3417:                        '</div>';
                   3418:         } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
                   3419:             $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
                   3420:                        &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
                   3421:                        '</div>';
                   3422:         }
                   3423:         $output .= '</p>';
                   3424:     }
                   3425:     $output .= '</fieldset>';
                   3426:     return $output;
                   3427: }
                   3428: 
1.121     raeburn  3429: sub radiobutton_prefs {
1.160.6.16  raeburn  3430:     my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.160.6.57  raeburn  3431:         $additional,$align) = @_;
1.121     raeburn  3432:     return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
                   3433:                    (ref($choices) eq 'HASH'));
                   3434: 
                   3435:     my (%checkedon,%checkedoff,$datatable,$css_class);
                   3436: 
                   3437:     foreach my $item (@{$toggles}) {
                   3438:         if ($defaultchecked->{$item} eq 'on') {
1.118     jms      3439:             $checkedon{$item} = ' checked="checked" ';
                   3440:             $checkedoff{$item} = ' ';
1.121     raeburn  3441:         } elsif ($defaultchecked->{$item} eq 'off') {
1.118     jms      3442:             $checkedoff{$item} = ' checked="checked" ';
                   3443:             $checkedon{$item} = ' ';
                   3444:         }
                   3445:     }
                   3446:     if (ref($settings) eq 'HASH') {
1.121     raeburn  3447:         foreach my $item (@{$toggles}) {
1.118     jms      3448:             if ($settings->{$item} eq '1') {
                   3449:                 $checkedon{$item} =  ' checked="checked" ';
                   3450:                 $checkedoff{$item} = ' ';
                   3451:             } elsif ($settings->{$item} eq '0') {
                   3452:                 $checkedoff{$item} =  ' checked="checked" ';
                   3453:                 $checkedon{$item} = ' ';
                   3454:             }
                   3455:         }
1.121     raeburn  3456:     }
1.160.6.16  raeburn  3457:     if ($onclick) {
                   3458:         $onclick = ' onclick="'.$onclick.'"';
                   3459:     }
1.121     raeburn  3460:     foreach my $item (@{$toggles}) {
1.118     jms      3461:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121     raeburn  3462:         $datatable .=
1.160.6.16  raeburn  3463:             '<tr'.$css_class.'><td valign="top">'.
                   3464:             '<span class="LC_nobreak">'.$choices->{$item}.
1.160.6.57  raeburn  3465:             '</span></td>';
                   3466:         if ($align eq 'left') {
                   3467:             $datatable .= '<td class="LC_left_item">';
                   3468:         } else {
                   3469:             $datatable .= '<td class="LC_right_item">';
                   3470:         }
                   3471:         $datatable .=
                   3472:             '<span class="LC_nobreak">'.
1.118     jms      3473:             '<label><input type="radio" name="'.
1.160.6.16  raeburn  3474:             $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118     jms      3475:             '</label>&nbsp;<label><input type="radio" name="'.$item.'" '.
1.160.6.16  raeburn  3476:             $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
                   3477:             '</span>'.$additional.
                   3478:             '</td>'.
1.118     jms      3479:             '</tr>';
                   3480:         $itemcount ++;
1.121     raeburn  3481:     }
                   3482:     return ($datatable,$itemcount);
                   3483: }
                   3484: 
                   3485: sub print_coursedefaults {
1.139     raeburn  3486:     my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.16  raeburn  3487:     my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121     raeburn  3488:     my $itemcount = 1;
1.160.6.16  raeburn  3489:     my %choices =  &Apache::lonlocal::texthash (
1.160.6.21  raeburn  3490:         uploadquota          => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.160.6.16  raeburn  3491:         anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
                   3492:         coursecredits        => 'Credits can be specified for courses',
1.160.6.57  raeburn  3493:         uselcmath            => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
                   3494:         usejsme              => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
1.160.6.90! raeburn  3495:         texengine            => 'Default method to display mathematics',
1.160.6.57  raeburn  3496:         postsubmit           => 'Disable submit button/keypress following student submission',
1.160.6.64  raeburn  3497:         canclone             => "People who may clone a course (besides course's owner and coordinators)",
1.160.6.70  raeburn  3498:         mysqltables          => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.160.6.16  raeburn  3499:     );
1.160.6.21  raeburn  3500:     my %staticdefaults = (
                   3501:                            anonsurvey_threshold => 10,
                   3502:                            uploadquota          => 500,
1.160.6.57  raeburn  3503:                            postsubmit           => 60,
1.160.6.70  raeburn  3504:                            mysqltables          => 172800,
1.160.6.21  raeburn  3505:                          );
1.139     raeburn  3506:     if ($position eq 'top') {
1.160.6.57  raeburn  3507:         %defaultchecked = (
                   3508:                             'uselcmath'       => 'on',
                   3509:                             'usejsme'         => 'on',
1.160.6.64  raeburn  3510:                             'canclone'        => 'none',
1.160.6.57  raeburn  3511:                           );
                   3512:         @toggles = ('uselcmath','usejsme');
1.160.6.90! raeburn  3513:         my $deftex = $Apache::lonnet::deftex;
        !          3514:         if (ref($settings) eq 'HASH') {
        !          3515:             if ($settings->{'texengine'}) {
        !          3516:                 if ($settings->{'texengine'} =~ /^(MathJax|mimetex|tth)$/) {
        !          3517:                     $deftex = $settings->{'texengine'};
        !          3518:                 }
        !          3519:             }
        !          3520:         }
        !          3521:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
        !          3522:         my $mathdisp = '<tr'.$css_class.'><td style="vertical-align: top">'.
        !          3523:                        '<span class="LC_nobreak">'.$choices{'texengine'}.
        !          3524:                        '</span></td><td class="LC_right_item">'.
        !          3525:                        '<select name="texengine">'."\n";
        !          3526:         my %texoptions = (
        !          3527:                             MathJax  => 'MathJax',
        !          3528:                             mimetex  => &mt('Convert to Images'),
        !          3529:                             tth      => &mt('TeX to HTML'),
        !          3530:                          );
        !          3531:         foreach my $renderer ('MathJax','mimetex','tth') {
        !          3532:             my $selected = '';
        !          3533:             if ($renderer eq $deftex) {
        !          3534:                 $selected = ' selected="selected"';
        !          3535:             }
        !          3536:             $mathdisp .= '<option value="'.$renderer.'"'.$selected.'>'.$texoptions{$renderer}.'</option>'."\n";
        !          3537:         }
        !          3538:         $mathdisp .= '</select></td></tr>'."\n";
        !          3539:         $itemcount ++;
1.139     raeburn  3540:         ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.160.6.57  raeburn  3541:                                                      \%choices,$itemcount);
1.160.6.90! raeburn  3542:         $datatable = $mathdisp.$datatable;
1.160.6.64  raeburn  3543:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   3544:         $datatable .=
                   3545:             '<tr'.$css_class.'><td valign="top">'.
                   3546:             '<span class="LC_nobreak">'.$choices{'canclone'}.
                   3547:             '</span></td><td class="LC_left_item">';
                   3548:         my $currcanclone = 'none';
                   3549:         my $onclick;
                   3550:         my @cloneoptions = ('none','domain');
                   3551:         my %clonetitles = (
                   3552:                              none     => 'No additional course requesters',
                   3553:                              domain   => "Any course requester in course's domain",
                   3554:                              instcode => 'Course requests for official courses ...',
                   3555:                           );
                   3556:         my (%codedefaults,@code_order,@posscodes);
                   3557:         if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
                   3558:                                                     \@code_order) eq 'ok') {
                   3559:             if (@code_order > 0) {
                   3560:                 push(@cloneoptions,'instcode');
                   3561:                 $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
                   3562:             }
                   3563:         }
                   3564:         if (ref($settings) eq 'HASH') {
                   3565:             if ($settings->{'canclone'}) {
                   3566:                 if (ref($settings->{'canclone'}) eq 'HASH') {
                   3567:                     if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
                   3568:                         if (@code_order > 0) {
                   3569:                             $currcanclone = 'instcode';
                   3570:                             @posscodes = @{$settings->{'canclone'}{'instcode'}};
                   3571:                         }
                   3572:                     }
                   3573:                 } elsif ($settings->{'canclone'} eq 'domain') {
                   3574:                     $currcanclone = $settings->{'canclone'};
                   3575:                 }
                   3576:             }
                   3577:         }
                   3578:         foreach my $option (@cloneoptions) {
                   3579:             my ($checked,$additional);
                   3580:             if ($currcanclone eq $option) {
                   3581:                 $checked = ' checked="checked"';
                   3582:             }
                   3583:             if ($option eq 'instcode') {
                   3584:                 if (@code_order) {
                   3585:                     my $show = 'none';
                   3586:                     if ($checked) {
                   3587:                         $show = 'block';
                   3588:                     }
                   3589:                     $additional = '<div id="cloneinstcode" style="display:'.$show.'" />'.
                   3590:                                   &mt('Institutional codes for new and cloned course have identical:').
                   3591:                                   '<br />';
                   3592:                     foreach my $item (@code_order) {
                   3593:                         my $codechk;
                   3594:                         if ($checked) {
                   3595:                             if (grep(/^\Q$item\E$/,@posscodes)) {
                   3596:                                 $codechk = ' checked="checked"';
                   3597:                             }
                   3598:                         }
                   3599:                         $additional .= '<label>'.
                   3600:                                        '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
                   3601:                                        $item.'</label>';
                   3602:                     }
                   3603:                     $additional .= ('&nbsp;'x2).'('.&mt('check as many as needed').')</div>';
                   3604:                 }
                   3605:             }
                   3606:             $datatable .=
                   3607:                 '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
                   3608:                 ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
                   3609:                 '</label>&nbsp;'.$additional.'</span><br />';
                   3610:         }
                   3611:         $datatable .= '</td>'.
                   3612:                       '</tr>';
                   3613:         $itemcount ++;
1.139     raeburn  3614:     } else {
                   3615:         $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.160.6.71  raeburn  3616:         my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout,%currmysql);
1.160.6.16  raeburn  3617:         my $currusecredits = 0;
1.160.6.57  raeburn  3618:         my $postsubmitclient = 1;
1.160.6.30  raeburn  3619:         my @types = ('official','unofficial','community','textbook');
1.139     raeburn  3620:         if (ref($settings) eq 'HASH') {
                   3621:             $currdefresponder = $settings->{'anonsurvey_threshold'};
1.160.6.21  raeburn  3622:             if (ref($settings->{'uploadquota'}) eq 'HASH') {
                   3623:                 foreach my $type (keys(%{$settings->{'uploadquota'}})) {
                   3624:                     $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
                   3625:                 }
                   3626:             }
1.160.6.16  raeburn  3627:             if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.160.6.57  raeburn  3628:                 foreach my $type (@types) {
                   3629:                     next if ($type eq 'community');
                   3630:                     $defcredits{$type} = $settings->{'coursecredits'}->{$type};
                   3631:                     if ($defcredits{$type} ne '') {
                   3632:                         $currusecredits = 1;
                   3633:                     }
                   3634:                 }
                   3635:             }
                   3636:             if (ref($settings->{'postsubmit'}) eq 'HASH') {
                   3637:                 if ($settings->{'postsubmit'}->{'client'} eq 'off') {
                   3638:                     $postsubmitclient = 0;
                   3639:                     foreach my $type (@types) {
                   3640:                         $deftimeout{$type} = $staticdefaults{'postsubmit'};
                   3641:                     }
                   3642:                 } else {
                   3643:                     foreach my $type (@types) {
                   3644:                         if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
                   3645:                             if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
                   3646:                                 $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
                   3647:                             } else {
                   3648:                                 $deftimeout{$type} = $staticdefaults{'postsubmit'};
                   3649:                             }
                   3650:                         } else {
                   3651:                             $deftimeout{$type} = $staticdefaults{'postsubmit'};
                   3652:                         }
                   3653:                     }
                   3654:                 }
                   3655:             } else {
                   3656:                 foreach my $type (@types) {
                   3657:                     $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.160.6.16  raeburn  3658:                 }
                   3659:             }
1.160.6.70  raeburn  3660:             if (ref($settings->{'mysqltables'}) eq 'HASH') {
                   3661:                 foreach my $type (keys(%{$settings->{'mysqltables'}})) {
                   3662:                     $currmysql{$type} = $settings->{'mysqltables'}{$type};
                   3663:                 }
                   3664:             } else {
                   3665:                 foreach my $type (@types) {
                   3666:                     $currmysql{$type} = $staticdefaults{'mysqltables'};
                   3667:                 }
                   3668:             }
1.160.6.58  raeburn  3669:         } else {
                   3670:             foreach my $type (@types) {
                   3671:                 $deftimeout{$type} = $staticdefaults{'postsubmit'};
                   3672:             }
1.139     raeburn  3673:         }
                   3674:         if (!$currdefresponder) {
1.160.6.21  raeburn  3675:             $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139     raeburn  3676:         } elsif ($currdefresponder < 1) {
                   3677:             $currdefresponder = 1;
                   3678:         }
1.160.6.21  raeburn  3679:         foreach my $type (@types) {
                   3680:             if ($curruploadquota{$type} eq '') {
                   3681:                 $curruploadquota{$type} = $staticdefaults{'uploadquota'};
                   3682:             }
                   3683:         }
1.139     raeburn  3684:         $datatable .=
1.160.6.16  raeburn  3685:                 '<tr'.$css_class.'><td><span class="LC_nobreak">'.
                   3686:                 $choices{'anonsurvey_threshold'}.
1.139     raeburn  3687:                 '</span></td>'.
                   3688:                 '<td class="LC_right_item"><span class="LC_nobreak">'.
                   3689:                 '<input type="text" name="anonsurvey_threshold"'.
                   3690:                 ' value="'.$currdefresponder.'" size="5" /></span>'.
1.160.6.37  raeburn  3691:                 '</td></tr>'."\n";
                   3692:         $itemcount ++;
                   3693:         $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   3694:         $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
                   3695:                       $choices{'uploadquota'}.
                   3696:                       '</span></td>'.
                   3697:                       '<td align="right" class="LC_right_item">'.
                   3698:                       '<table><tr>';
1.160.6.21  raeburn  3699:         foreach my $type (@types) {
                   3700:             $datatable .= '<td align="center">'.&mt($type).'<br />'.
                   3701:                            '<input type="text" name="uploadquota_'.$type.'"'.
                   3702:                            ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
                   3703:         }
                   3704:         $datatable .= '</tr></table></td></tr>'."\n";
1.160.6.37  raeburn  3705:         $itemcount ++;
1.160.6.40  raeburn  3706:         my $onclick = "toggleDisplay(this.form,'credits');";
1.160.6.16  raeburn  3707:         my $display = 'none';
                   3708:         if ($currusecredits) {
                   3709:             $display = 'block';
                   3710:         }
                   3711:         my $additional = '<div id="credits" style="display: '.$display.'">'.
1.160.6.57  raeburn  3712:                          '<i>'.&mt('Default credits').'</i><br /><table><tr>';
                   3713:         foreach my $type (@types) {
                   3714:             next if ($type eq 'community');
                   3715:             $additional .= '<td align="center">'.&mt($type).'<br />'.
                   3716:                            '<input type="text" name="'.$type.'_credits"'.
                   3717:                            ' value="'.$defcredits{$type}.'" size="3" /></td>';
                   3718:         }
                   3719:         $additional .= '</tr></table></div>'."\n";
1.160.6.16  raeburn  3720:         %defaultchecked = ('coursecredits' => 'off');
                   3721:         @toggles = ('coursecredits');
                   3722:         my $current = {
                   3723:                         'coursecredits' => $currusecredits,
                   3724:                       };
                   3725:         (my $table,$itemcount) =
                   3726:             &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.160.6.57  raeburn  3727:                                \%choices,$itemcount,$onclick,$additional,'left');
                   3728:         $datatable .= $table;
                   3729:         $onclick = "toggleDisplay(this.form,'studentsubmission');";
                   3730:         my $display = 'none';
                   3731:         if ($postsubmitclient) {
                   3732:             $display = 'block';
                   3733:         }
                   3734:         $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.160.6.59  raeburn  3735:                       &mt('Number of seconds submit is disabled').'<br />'.
                   3736:                       '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
                   3737:                       '<table><tr>';
1.160.6.57  raeburn  3738:         foreach my $type (@types) {
                   3739:             $additional .= '<td align="center">'.&mt($type).'<br />'.
                   3740:                            '<input type="text" name="'.$type.'_timeout" value="'.
                   3741:                            $deftimeout{$type}.'" size="5" /></td>';
                   3742:         }
                   3743:         $additional .= '</tr></table></div>'."\n";
                   3744:         %defaultchecked = ('postsubmit' => 'on');
                   3745:         @toggles = ('postsubmit');
1.160.6.70  raeburn  3746:         $current = {
                   3747:                        'postsubmit' => $postsubmitclient,
                   3748:                    };
1.160.6.57  raeburn  3749:         ($table,$itemcount) =
                   3750:             &radiobutton_prefs($current,\@toggles,\%defaultchecked,
                   3751:                                \%choices,$itemcount,$onclick,$additional,'left');
1.160.6.16  raeburn  3752:         $datatable .= $table;
1.160.6.70  raeburn  3753:         $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   3754:         $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
                   3755:                       $choices{'mysqltables'}.
                   3756:                       '</span></td>'.
                   3757:                       '<td align="right" class="LC_right_item">'.
                   3758:                       '<table><tr>';
                   3759:         foreach my $type (@types) {
                   3760:             $datatable .= '<td align="center">'.&mt($type).'<br />'.
                   3761:                            '<input type="text" name="mysqltables_'.$type.'"'.
1.160.6.81  raeburn  3762:                            ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.160.6.70  raeburn  3763:         }
                   3764:         $datatable .= '</tr></table></td></tr>'."\n";
                   3765:         $itemcount ++;
                   3766: 
1.160.6.37  raeburn  3767:     }
                   3768:     $$rowtotal += $itemcount;
                   3769:     return $datatable;
                   3770: }
                   3771: 
                   3772: sub print_selfenrollment {
                   3773:     my ($position,$dom,$settings,$rowtotal) = @_;
                   3774:     my ($css_class,$datatable);
                   3775:     my $itemcount = 1;
                   3776:     my @types = ('official','unofficial','community','textbook');
                   3777:     if (($position eq 'top') || ($position eq 'middle')) {
                   3778:         my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
                   3779:         my %descs = &Apache::lonuserutils::selfenroll_default_descs();
                   3780:         my @rows;
                   3781:         my $key;
                   3782:         if ($position eq 'top') {
                   3783:             $key = 'admin'; 
                   3784:             if (ref($rowsref) eq 'ARRAY') {
                   3785:                 @rows = @{$rowsref};
                   3786:             }
                   3787:         } elsif ($position eq 'middle') {
                   3788:             $key = 'default';
                   3789:             @rows = ('types','registered','approval','limit');
                   3790:         }
                   3791:         foreach my $row (@rows) {
                   3792:             if (defined($titlesref->{$row})) {
                   3793:                 $itemcount ++;
                   3794:                 $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   3795:                 $datatable .= '<tr'.$css_class.'>'.
                   3796:                               '<td>'.$titlesref->{$row}.'</td>'.
                   3797:                               '<td class="LC_left_item">'.
                   3798:                               '<table><tr>';
                   3799:                 my (%current,%currentcap);
                   3800:                 if (ref($settings) eq 'HASH') {
                   3801:                     if (ref($settings->{$key}) eq 'HASH') {
                   3802:                         foreach my $type (@types) {
                   3803:                             if (ref($settings->{$key}->{$type}) eq 'HASH') {
                   3804:                                 $current{$type} = $settings->{$key}->{$type}->{$row};
                   3805:                             }
                   3806:                             if (($row eq 'limit') && ($key eq 'default')) {
                   3807:                                 if (ref($settings->{$key}->{$type}) eq 'HASH') {
                   3808:                                     $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
                   3809:                                 }
                   3810:                             }
                   3811:                         }
                   3812:                     }
                   3813:                 }
                   3814:                 my %roles = (
                   3815:                              '0' => &Apache::lonnet::plaintext('dc'),
                   3816:                             ); 
                   3817:             
                   3818:                 foreach my $type (@types) {
                   3819:                     unless (($row eq 'registered') && ($key eq 'default')) {
                   3820:                         $datatable .= '<th>'.&mt($type).'</th>';
                   3821:                     }
                   3822:                 }
                   3823:                 unless (($row eq 'registered') && ($key eq 'default')) {
                   3824:                     $datatable .= '</tr><tr>';
                   3825:                 }
                   3826:                 foreach my $type (@types) {
                   3827:                     if ($type eq 'community') {
                   3828:                         $roles{'1'} = &mt('Community personnel');
                   3829:                     } else {
                   3830:                         $roles{'1'} = &mt('Course personnel');
                   3831:                     }
                   3832:                     $datatable .= '<td style="vertical-align: top">';
                   3833:                     if ($position eq 'top') {
                   3834:                         my %checked;
                   3835:                         if ($current{$type} eq '0') {
                   3836:                             $checked{'0'} = ' checked="checked"';
                   3837:                         } else {
                   3838:                             $checked{'1'} = ' checked="checked"';
                   3839:                         }
                   3840:                         foreach my $role ('1','0') {
                   3841:                             $datatable .= '<span class="LC_nobreak"><label>'.
                   3842:                                           '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
                   3843:                                           'value="'.$role.'"'.$checked{$role}.' />'.
                   3844:                                           $roles{$role}.'</label></span> ';
                   3845:                         }
                   3846:                     } else {
                   3847:                         if ($row eq 'types') {
                   3848:                             my %checked;
                   3849:                             if ($current{$type} =~ /^(all|dom)$/) {
                   3850:                                 $checked{$1} = ' checked="checked"';
                   3851:                             } else {
                   3852:                                 $checked{''} = ' checked="checked"';
                   3853:                             }
                   3854:                             foreach my $val ('','dom','all') {
                   3855:                                 $datatable .= '<span class="LC_nobreak"><label>'.
                   3856:                                               '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
                   3857:                                               'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
                   3858:                             }
                   3859:                         } elsif ($row eq 'registered') {
                   3860:                             my %checked;
                   3861:                             if ($current{$type} eq '1') {
                   3862:                                 $checked{'1'} = ' checked="checked"';
                   3863:                             } else {
                   3864:                                 $checked{'0'} = ' checked="checked"';
                   3865:                             }
                   3866:                             foreach my $val ('0','1') {
                   3867:                                 $datatable .= '<span class="LC_nobreak"><label>'.
                   3868:                                               '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
                   3869:                                               'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
                   3870:                             }
                   3871:                         } elsif ($row eq 'approval') {
                   3872:                             my %checked;
                   3873:                             if ($current{$type} =~ /^([12])$/) {
                   3874:                                 $checked{$1} = ' checked="checked"';
                   3875:                             } else {
                   3876:                                 $checked{'0'} = ' checked="checked"';
                   3877:                             }
                   3878:                             for my $val (0..2) {
                   3879:                                 $datatable .= '<span class="LC_nobreak"><label>'.
                   3880:                                               '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
                   3881:                                               'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
                   3882:                             }
                   3883:                         } elsif ($row eq 'limit') {
                   3884:                             my %checked;
                   3885:                             if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
                   3886:                                 $checked{$1} = ' checked="checked"';
                   3887:                             } else {
                   3888:                                 $checked{'none'} = ' checked="checked"';
                   3889:                             }
                   3890:                             my $cap;
                   3891:                             if ($currentcap{$type} =~ /^\d+$/) {
                   3892:                                 $cap = $currentcap{$type};
                   3893:                             }
                   3894:                             foreach my $val ('none','allstudents','selfenrolled') {
                   3895:                                 $datatable .= '<span class="LC_nobreak"><label>'.
                   3896:                                               '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
                   3897:                                               'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
                   3898:                             }
                   3899:                             $datatable .= '<br />'.
                   3900:                                           '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
                   3901:                                           '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
                   3902:                                           '</span>'; 
                   3903:                         }
                   3904:                     }
                   3905:                     $datatable .= '</td>';
                   3906:                 }
                   3907:                 $datatable .= '</tr>';
                   3908:             }
                   3909:             $datatable .= '</table></td></tr>';
                   3910:         }
                   3911:     } elsif ($position eq 'bottom') {
1.160.6.39  raeburn  3912:         $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
                   3913:     }
                   3914:     $$rowtotal += $itemcount;
                   3915:     return $datatable;
                   3916: }
                   3917: 
                   3918: sub print_validation_rows {
                   3919:     my ($caller,$dom,$settings,$rowtotal) = @_;
                   3920:     my ($itemsref,$namesref,$fieldsref);
                   3921:     if ($caller eq 'selfenroll') { 
                   3922:         ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
                   3923:     } elsif ($caller eq 'requestcourses') {
                   3924:         ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
                   3925:     }
                   3926:     my %currvalidation;
                   3927:     if (ref($settings) eq 'HASH') {
                   3928:         if (ref($settings->{'validation'}) eq 'HASH') {
                   3929:             %currvalidation = %{$settings->{'validation'}};
1.160.6.37  raeburn  3930:         }
1.160.6.39  raeburn  3931:     }
                   3932:     my $datatable;
                   3933:     my $itemcount = 0;
                   3934:     foreach my $item (@{$itemsref}) {
                   3935:         my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   3936:         $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
                   3937:                       $namesref->{$item}.
                   3938:                       '</span></td>'.
                   3939:                       '<td class="LC_left_item">';
                   3940:         if (($item eq 'url') || ($item eq 'button')) {
                   3941:             $datatable .= '<span class="LC_nobreak">'.
                   3942:                           '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
                   3943:                           ' value="'.$currvalidation{$item}.'" size="50" /></span>';
                   3944:         } elsif ($item eq 'fields') {
                   3945:             my @currfields;
                   3946:             if (ref($currvalidation{$item}) eq 'ARRAY') {
                   3947:                 @currfields = @{$currvalidation{$item}};
                   3948:             }
                   3949:             foreach my $field (@{$fieldsref}) {
                   3950:                 my $check = '';
                   3951:                 if (grep(/^\Q$field\E$/,@currfields)) {
                   3952:                     $check = ' checked="checked"';
                   3953:                 }
                   3954:                 $datatable .= '<span class="LC_nobreak"><label>'.
                   3955:                               '<input type="checkbox" name="'.$caller.'_validation_fields"'.
                   3956:                               ' value="'.$field.'"'.$check.' />'.$field.
                   3957:                               '</label></span> ';
                   3958:             }
                   3959:         } elsif ($item eq 'markup') {
1.160.6.87  raeburn  3960:             $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5">'.
1.160.6.39  raeburn  3961:                            $currvalidation{$item}.
1.160.6.37  raeburn  3962:                               '</textarea>';
1.160.6.39  raeburn  3963:         }
                   3964:         $datatable .= '</td></tr>'."\n";
                   3965:         if (ref($rowtotal)) {
1.160.6.37  raeburn  3966:             $itemcount ++;
                   3967:         }
1.139     raeburn  3968:     }
1.160.6.39  raeburn  3969:     if ($caller eq 'requestcourses') {
                   3970:         my %currhash;
1.160.6.51  raeburn  3971:         if (ref($settings) eq 'HASH') {
                   3972:             if (ref($settings->{'validation'}) eq 'HASH') {
                   3973:                 if ($settings->{'validation'}{'dc'} ne '') {
                   3974:                     $currhash{$settings->{'validation'}{'dc'}} = 1;
                   3975:                 }
1.160.6.39  raeburn  3976:             }
                   3977:         }
                   3978:         my $numinrow = 2;
                   3979:         my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
                   3980:                                                        'validationdc',%currhash);
1.160.6.50  raeburn  3981:         my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.160.6.87  raeburn  3982:         $datatable .= '<tr'.$css_class.'><td>';
1.160.6.39  raeburn  3983:         if ($numdc > 1) {
1.160.6.50  raeburn  3984:             $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.160.6.39  raeburn  3985:         } else {
1.160.6.50  raeburn  3986:             $datatable .=  &mt('Course creation processed as: ');
1.160.6.39  raeburn  3987:         }
1.160.6.50  raeburn  3988:         $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.160.6.39  raeburn  3989:         $itemcount ++;
                   3990:     }
                   3991:     if (ref($rowtotal)) {
                   3992:         $$rowtotal += $itemcount;
                   3993:     }
1.121     raeburn  3994:     return $datatable;
1.118     jms      3995: }
                   3996: 
1.137     raeburn  3997: sub print_usersessions {
                   3998:     my ($position,$dom,$settings,$rowtotal) = @_;
                   3999:     my ($css_class,$datatable,%checked,%choices);
1.140     raeburn  4000:     my (%by_ip,%by_location,@intdoms);
                   4001:     &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145     raeburn  4002: 
                   4003:     my @alldoms = &Apache::lonnet::all_domains();
1.152     raeburn  4004:     my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149     raeburn  4005:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152     raeburn  4006:     my %altids = &id_for_thisdom(%servers);
1.145     raeburn  4007:     my $itemcount = 1;
                   4008:     if ($position eq 'top') {
1.152     raeburn  4009:         if (keys(%serverhomes) > 1) {
1.145     raeburn  4010:             my %spareid = &current_offloads_to($dom,$settings,\%servers);
1.160.6.61  raeburn  4011:             my $curroffloadnow;
                   4012:             if (ref($settings) eq 'HASH') {
                   4013:                 if (ref($settings->{'offloadnow'}) eq 'HASH') {
                   4014:                     $curroffloadnow = $settings->{'offloadnow'};
                   4015:                 }
                   4016:             }
                   4017:             $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$curroffloadnow,$rowtotal);
1.145     raeburn  4018:         } else {
1.140     raeburn  4019:             $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150     raeburn  4020:                           &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140     raeburn  4021:         }
1.137     raeburn  4022:     } else {
1.145     raeburn  4023:         if (keys(%by_location) == 0) {
                   4024:             $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150     raeburn  4025:                           &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145     raeburn  4026:         } else {
                   4027:             my %lt = &usersession_titles();
                   4028:             my $numinrow = 5;
                   4029:             my $prefix;
                   4030:             my @types;
                   4031:             if ($position eq 'bottom') {
                   4032:                 $prefix = 'remote';
                   4033:                 @types = ('version','excludedomain','includedomain');
                   4034:             } else {
                   4035:                 $prefix = 'hosted';
                   4036:                 @types = ('excludedomain','includedomain');
                   4037:             }
                   4038:             my (%current,%checkedon,%checkedoff);
                   4039:             my @lcversions = &Apache::lonnet::all_loncaparevs();
                   4040:             my @locations = sort(keys(%by_location));
                   4041:             foreach my $type (@types) {
                   4042:                 $checkedon{$type} = '';
                   4043:                 $checkedoff{$type} = ' checked="checked"';
                   4044:             }
                   4045:             if (ref($settings) eq 'HASH') {
                   4046:                 if (ref($settings->{$prefix}) eq 'HASH') {
                   4047:                     foreach my $key (keys(%{$settings->{$prefix}})) {
                   4048:                         $current{$key} = $settings->{$prefix}{$key};
                   4049:                         if ($key eq 'version') {
                   4050:                             if ($current{$key} ne '') {
                   4051:                                 $checkedon{$key} = ' checked="checked"';
                   4052:                                 $checkedoff{$key} = '';
                   4053:                             }
                   4054:                         } elsif (ref($current{$key}) eq 'ARRAY') {
                   4055:                             $checkedon{$key} = ' checked="checked"';
                   4056:                             $checkedoff{$key} = '';
                   4057:                         }
1.137     raeburn  4058:                     }
                   4059:                 }
                   4060:             }
1.145     raeburn  4061:             foreach my $type (@types) {
                   4062:                 next if ($type ne 'version' && !@locations);
                   4063:                 $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   4064:                 $datatable .= '<tr'.$css_class.'>
                   4065:                                <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
                   4066:                                <span class="LC_nobreak">&nbsp;
                   4067:                                <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>&nbsp;
                   4068:                                <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
                   4069:                 if ($type eq 'version') {
                   4070:                     my $selector = '<select name="'.$prefix.'_version">';
                   4071:                     foreach my $version (@lcversions) {
                   4072:                         my $selected = '';
                   4073:                         if ($current{'version'} eq $version) {
                   4074:                             $selected = ' selected="selected"';
                   4075:                         }
                   4076:                         $selector .= ' <option value="'.$version.'"'.
                   4077:                                      $selected.'>'.$version.'</option>';
                   4078:                     }
                   4079:                     $selector .= '</select> ';
                   4080:                     $datatable .= &mt('remote server must be version: [_1] or later',$selector);
                   4081:                 } else {
                   4082:                     $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
                   4083:                                  'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
                   4084:                                  ' />'.('&nbsp;'x2).
                   4085:                                  '<input type="button" value="'.&mt('uncheck all').'" '.
                   4086:                                  'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
                   4087:                                  "\n".
                   4088:                                  '</div><div><table>';
                   4089:                     my $rem;
                   4090:                     for (my $i=0; $i<@locations; $i++) {
                   4091:                         my ($showloc,$value,$checkedtype);
                   4092:                         if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
                   4093:                             my $ip = $by_location{$locations[$i]}->[0];
                   4094:                             if (ref($by_ip{$ip}) eq 'ARRAY') {
                   4095:                                  $value = join(':',@{$by_ip{$ip}});
                   4096:                                 $showloc = join(', ',@{$by_ip{$ip}});
                   4097:                                 if (ref($current{$type}) eq 'ARRAY') {
                   4098:                                     foreach my $loc (@{$by_ip{$ip}}) {  
                   4099:                                         if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
                   4100:                                             $checkedtype = ' checked="checked"';
                   4101:                                             last;
                   4102:                                         }
                   4103:                                     }
1.138     raeburn  4104:                                 }
                   4105:                             }
                   4106:                         }
1.145     raeburn  4107:                         $rem = $i%($numinrow);
                   4108:                         if ($rem == 0) {
                   4109:                             if ($i > 0) {
                   4110:                                 $datatable .= '</tr>';
                   4111:                             }
                   4112:                             $datatable .= '<tr>';
                   4113:                         }
                   4114:                         $datatable .= '<td class="LC_left_item">'.
                   4115:                                       '<span class="LC_nobreak"><label>'.
                   4116:                                       '<input type="checkbox" name="'.$prefix.'_'.$type.
                   4117:                                       '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
                   4118:                                       '</label></span></td>';
1.137     raeburn  4119:                     }
1.145     raeburn  4120:                     $rem = @locations%($numinrow);
                   4121:                     my $colsleft = $numinrow - $rem;
                   4122:                     if ($colsleft > 1 ) {
                   4123:                         $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   4124:                                       '&nbsp;</td>';
                   4125:                     } elsif ($colsleft == 1) {
                   4126:                         $datatable .= '<td class="LC_left_item">&nbsp;</td>';
1.137     raeburn  4127:                     }
1.145     raeburn  4128:                     $datatable .= '</tr></table>';
1.137     raeburn  4129:                 }
1.145     raeburn  4130:                 $datatable .= '</td></tr>';
                   4131:                 $itemcount ++;
1.137     raeburn  4132:             }
                   4133:         }
                   4134:     }
                   4135:     $$rowtotal += $itemcount;
                   4136:     return $datatable;
                   4137: }
                   4138: 
1.138     raeburn  4139: sub build_location_hashes {
                   4140:     my ($intdoms,$by_ip,$by_location) = @_;
                   4141:     return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
                   4142:                   (ref($by_location) eq 'HASH')); 
                   4143:     my %iphost = &Apache::lonnet::get_iphost();
                   4144:     my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
                   4145:     my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
                   4146:     if (ref($iphost{$primary_ip}) eq 'ARRAY') {
                   4147:         foreach my $id (@{$iphost{$primary_ip}}) {
                   4148:             my $intdom = &Apache::lonnet::internet_dom($id);
                   4149:             unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
                   4150:                 push(@{$intdoms},$intdom);
                   4151:             }
                   4152:         }
                   4153:     }
                   4154:     foreach my $ip (keys(%iphost)) {
                   4155:         if (ref($iphost{$ip}) eq 'ARRAY') {
                   4156:             foreach my $id (@{$iphost{$ip}}) {
                   4157:                 my $location = &Apache::lonnet::internet_dom($id);
                   4158:                 if ($location) {
                   4159:                     next if (grep(/^\Q$location\E$/,@{$intdoms}));
                   4160:                     if (ref($by_ip->{$ip}) eq 'ARRAY') {
                   4161:                         unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
                   4162:                             push(@{$by_ip->{$ip}},$location);
                   4163:                         }
                   4164:                     } else {
                   4165:                         $by_ip->{$ip} = [$location];
                   4166:                     }
                   4167:                 }
                   4168:             }
                   4169:         }
                   4170:     }
                   4171:     foreach my $ip (sort(keys(%{$by_ip}))) {
                   4172:         if (ref($by_ip->{$ip}) eq 'ARRAY') {
                   4173:             @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
                   4174:             my $first = $by_ip->{$ip}->[0];
                   4175:             if (ref($by_location->{$first}) eq 'ARRAY') {
                   4176:                 unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
                   4177:                     push(@{$by_location->{$first}},$ip);
                   4178:                 }
                   4179:             } else {
                   4180:                 $by_location->{$first} = [$ip];
                   4181:             }
                   4182:         }
                   4183:     }
                   4184:     return;
                   4185: }
                   4186: 
1.145     raeburn  4187: sub current_offloads_to {
                   4188:     my ($dom,$settings,$servers) = @_;
                   4189:     my (%spareid,%otherdomconfigs);
1.152     raeburn  4190:     if (ref($servers) eq 'HASH') {
1.145     raeburn  4191:         foreach my $lonhost (sort(keys(%{$servers}))) {
                   4192:             my $gotspares;
1.152     raeburn  4193:             if (ref($settings) eq 'HASH') {
                   4194:                 if (ref($settings->{'spares'}) eq 'HASH') {
                   4195:                     if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
                   4196:                         $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
                   4197:                         $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
                   4198:                         $gotspares = 1;
                   4199:                     }
1.145     raeburn  4200:                 }
                   4201:             }
                   4202:             unless ($gotspares) {
                   4203:                 my $gotspares;
                   4204:                 my $serverhomeID =
                   4205:                     &Apache::lonnet::get_server_homeID($servers->{$lonhost});
                   4206:                 my $serverhomedom =
                   4207:                     &Apache::lonnet::host_domain($serverhomeID);
                   4208:                 if ($serverhomedom ne $dom) {
                   4209:                     if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
                   4210:                         if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
                   4211:                             if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
                   4212:                                 $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
                   4213:                                 $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
                   4214:                                 $gotspares = 1;
                   4215:                             }
                   4216:                         }
                   4217:                     } else {
                   4218:                         $otherdomconfigs{$serverhomedom} =
                   4219:                             &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
                   4220:                         if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
                   4221:                             if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
                   4222:                                 if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
                   4223:                                     if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
                   4224:                                         $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
                   4225:                                         $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
                   4226:                                         $gotspares = 1;
                   4227:                                     }
                   4228:                                 }
                   4229:                             }
                   4230:                         }
                   4231:                     }
                   4232:                 }
                   4233:             }
                   4234:             unless ($gotspares) {
                   4235:                 if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
                   4236:                     $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
                   4237:                     $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
                   4238:                } else {
                   4239:                     my $server_hostname = &Apache::lonnet::hostname($lonhost);
                   4240:                     my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
                   4241:                     if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
                   4242:                         $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
                   4243:                         $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
                   4244:                     } else {
1.150     raeburn  4245:                         my %what = (
                   4246:                              spareid => 1,
                   4247:                         );
                   4248:                         my ($result,$returnhash) = 
                   4249:                             &Apache::lonnet::get_remote_globals($lonhost,\%what);
                   4250:                         if ($result eq 'ok') { 
                   4251:                             if (ref($returnhash) eq 'HASH') {
                   4252:                                 if (ref($returnhash->{'spareid'}) eq 'HASH') {
                   4253:                                     $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
                   4254:                                     $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
                   4255:                                 }
                   4256:                             }
1.145     raeburn  4257:                         }
                   4258:                     }
                   4259:                 }
                   4260:             }
                   4261:         }
                   4262:     }
                   4263:     return %spareid;
                   4264: }
                   4265: 
                   4266: sub spares_row {
1.160.6.61  raeburn  4267:     my ($dom,$servers,$spareid,$serverhomes,$altids,$curroffloadnow,$rowtotal) = @_;
1.145     raeburn  4268:     my $css_class;
                   4269:     my $numinrow = 4;
                   4270:     my $itemcount = 1;
                   4271:     my $datatable;
1.152     raeburn  4272:     my %typetitles = &sparestype_titles();
                   4273:     if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145     raeburn  4274:         foreach my $server (sort(keys(%{$servers}))) {
1.152     raeburn  4275:             my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
                   4276:             my ($othercontrol,$serverdom);
                   4277:             if ($serverhome ne $server) {
                   4278:                 $serverdom = &Apache::lonnet::host_domain($serverhome);
                   4279:                 $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
                   4280:             } else {
                   4281:                 $serverdom = &Apache::lonnet::host_domain($server);
                   4282:                 if ($serverdom ne $dom) {
                   4283:                     $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
                   4284:                 }
                   4285:             }
                   4286:             next unless (ref($spareid->{$server}) eq 'HASH');
1.160.6.61  raeburn  4287:             my $checkednow;
                   4288:             if (ref($curroffloadnow) eq 'HASH') {
                   4289:                 if ($curroffloadnow->{$server}) {
                   4290:                     $checkednow = ' checked="checked"';
                   4291:                 }
                   4292:             }
1.145     raeburn  4293:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   4294:             $datatable .= '<tr'.$css_class.'>
                   4295:                            <td rowspan="2">
1.160.6.13  raeburn  4296:                             <span class="LC_nobreak">'.
                   4297:                           &mt('[_1] when busy, offloads to:'
1.160.6.61  raeburn  4298:                               ,'<b>'.$server.'</b>').'</span><br />'.
                   4299:                           '<span class="LC_nobreak">'."\n".
                   4300:                           '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
                   4301:                           '&nbsp;'.&mt('Switch active users on next access').'</label></span>'.
1.160.6.13  raeburn  4302:                           "\n";
1.145     raeburn  4303:             my (%current,%canselect);
1.152     raeburn  4304:             my @choices = 
                   4305:                 &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
                   4306:             foreach my $type ('primary','default') {
                   4307:                 if (ref($spareid->{$server}) eq 'HASH') {
1.145     raeburn  4308:                     if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
                   4309:                         my @spares = @{$spareid->{$server}{$type}};
                   4310:                         if (@spares > 0) {
1.152     raeburn  4311:                             if ($othercontrol) {
                   4312:                                 $current{$type} = join(', ',@spares);
                   4313:                             } else {
                   4314:                                 $current{$type} .= '<table>';
                   4315:                                 my $numspares = scalar(@spares);
                   4316:                                 for (my $i=0;  $i<@spares; $i++) {
                   4317:                                     my $rem = $i%($numinrow);
                   4318:                                     if ($rem == 0) {
                   4319:                                         if ($i > 0) {
                   4320:                                             $current{$type} .= '</tr>';
                   4321:                                         }
                   4322:                                         $current{$type} .= '<tr>';
1.145     raeburn  4323:                                     }
1.152     raeburn  4324:                                     $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;'.
                   4325:                                                        $spareid->{$server}{$type}[$i].
                   4326:                                                        '</label></td>'."\n";
                   4327:                                 }
                   4328:                                 my $rem = @spares%($numinrow);
                   4329:                                 my $colsleft = $numinrow - $rem;
                   4330:                                 if ($colsleft > 1 ) {
                   4331:                                     $current{$type} .= '<td colspan="'.$colsleft.
                   4332:                                                        '" class="LC_left_item">'.
                   4333:                                                        '&nbsp;</td>';
                   4334:                                 } elsif ($colsleft == 1) {
                   4335:                                     $current{$type} .= '<td class="LC_left_item">&nbsp;</td>'."\n";
1.145     raeburn  4336:                                 }
1.152     raeburn  4337:                                 $current{$type} .= '</tr></table>';
1.150     raeburn  4338:                             }
1.145     raeburn  4339:                         }
                   4340:                     }
                   4341:                     if ($current{$type} eq '') {
                   4342:                         $current{$type} = &mt('None specified');
                   4343:                     }
1.152     raeburn  4344:                     if ($othercontrol) {
                   4345:                         if ($type eq 'primary') {
                   4346:                             $canselect{$type} = $othercontrol;
                   4347:                         }
                   4348:                     } else {
                   4349:                         $canselect{$type} = 
                   4350:                             &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').'&nbsp;'.
                   4351:                             '<select name="newspare_'.$type.'_'.$server.'" '.
                   4352:                             'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
                   4353:                             '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
                   4354:                         if (@choices > 0) {
                   4355:                             foreach my $lonhost (@choices) {
                   4356:                                 $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
                   4357:                             }
                   4358:                         }
                   4359:                         $canselect{$type} .= '</select>'."\n";
                   4360:                     }
                   4361:                 } else {
                   4362:                     $current{$type} = &mt('Could not be determined');
                   4363:                     if ($type eq 'primary') {
                   4364:                         $canselect{$type} =  $othercontrol;
                   4365:                     }
1.145     raeburn  4366:                 }
1.152     raeburn  4367:                 if ($type eq 'default') {
                   4368:                     $datatable .= '<tr'.$css_class.'>';
                   4369:                 }
                   4370:                 $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
                   4371:                               '<td>'.$current{$type}.'</td>'."\n".
                   4372:                               '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145     raeburn  4373:             }
                   4374:             $itemcount ++;
                   4375:         }
                   4376:     }
                   4377:     $$rowtotal += $itemcount;
                   4378:     return $datatable;
                   4379: }
                   4380: 
1.152     raeburn  4381: sub possible_newspares {
                   4382:     my ($server,$currspares,$serverhomes,$altids) = @_;
                   4383:     my $serverhostname = &Apache::lonnet::hostname($server);
                   4384:     my %excluded;
                   4385:     if ($serverhostname ne '') {
                   4386:         %excluded = (
                   4387:                        $serverhostname => 1,
                   4388:                     );
                   4389:     }
                   4390:     if (ref($currspares) eq 'HASH') {
                   4391:         foreach my $type (keys(%{$currspares})) {
                   4392:             if (ref($currspares->{$type}) eq 'ARRAY') {
                   4393:                 if (@{$currspares->{$type}} > 0) {
                   4394:                     foreach my $curr (@{$currspares->{$type}}) {
                   4395:                         my $hostname = &Apache::lonnet::hostname($curr);
                   4396:                         $excluded{$hostname} = 1;
                   4397:                     }
                   4398:                 }
                   4399:             }
                   4400:         }
                   4401:     }
                   4402:     my @choices;
                   4403:     if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
                   4404:         if (keys(%{$serverhomes}) > 1) {
                   4405:             foreach my $name (sort(keys(%{$serverhomes}))) {
                   4406:                 unless ($excluded{$name}) {
                   4407:                     if (exists($altids->{$serverhomes->{$name}})) {
                   4408:                         push(@choices,$altids->{$serverhomes->{$name}});
                   4409:                     } else {
                   4410:                         push(@choices,$serverhomes->{$name});
1.145     raeburn  4411:                     }
                   4412:                 }
                   4413:             }
                   4414:         }
                   4415:     }
1.152     raeburn  4416:     return sort(@choices);
1.145     raeburn  4417: }
                   4418: 
1.150     raeburn  4419: sub print_loadbalancing {
                   4420:     my ($dom,$settings,$rowtotal) = @_;
                   4421:     my $primary_id = &Apache::lonnet::domain($dom,'primary');
                   4422:     my $intdom = &Apache::lonnet::internet_dom($primary_id);
                   4423:     my $numinrow = 1;
                   4424:     my $datatable;
                   4425:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.7  raeburn  4426:     my (%currbalancer,%currtargets,%currrules,%existing);
                   4427:     if (ref($settings) eq 'HASH') {
                   4428:         %existing = %{$settings};
                   4429:     }
                   4430:     if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
                   4431:         &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
                   4432:                                   \%currtargets,\%currrules);
1.150     raeburn  4433:     } else {
                   4434:         return;
                   4435:     }
                   4436:     my ($othertitle,$usertypes,$types) =
                   4437:         &Apache::loncommon::sorted_inst_types($dom);
1.160.6.26  raeburn  4438:     my $rownum = 8;
1.150     raeburn  4439:     if (ref($types) eq 'ARRAY') {
                   4440:         $rownum += scalar(@{$types});
                   4441:     }
1.160.6.7  raeburn  4442:     my @css_class = ('LC_odd_row','LC_even_row');
                   4443:     my $balnum = 0;
                   4444:     my $islast;
                   4445:     my (@toshow,$disabledtext);
                   4446:     if (keys(%currbalancer) > 0) {
                   4447:         @toshow = sort(keys(%currbalancer));
                   4448:         if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
                   4449:             push(@toshow,'');
                   4450:         }
                   4451:     } else {
                   4452:         @toshow = ('');
                   4453:         $disabledtext = &mt('No existing load balancer');
                   4454:     }
                   4455:     foreach my $lonhost (@toshow) {
                   4456:         if ($balnum == scalar(@toshow)-1) {
                   4457:             $islast = 1;
                   4458:         } else {
                   4459:             $islast = 0;
                   4460:         }
                   4461:         my $cssidx = $balnum%2;
                   4462:         my $targets_div_style = 'display: none';
                   4463:         my $disabled_div_style = 'display: block';
                   4464:         my $homedom_div_style = 'display: none';
                   4465:         $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
                   4466:                       '<td rowspan="'.$rownum.'" valign="top">'.
                   4467:                       '<p>';
                   4468:         if ($lonhost eq '') {
                   4469:             $datatable .= '<span class="LC_nobreak">';
                   4470:             if (keys(%currbalancer) > 0) {
                   4471:                 $datatable .= &mt('Add balancer:');
                   4472:             } else {
                   4473:                 $datatable .= &mt('Enable balancer:');
                   4474:             }
                   4475:             $datatable .= '&nbsp;'.
                   4476:                           '<select name="loadbalancing_lonhost_'.$balnum.'"'.
                   4477:                           ' id="loadbalancing_lonhost_'.$balnum.'"'.
                   4478:                           ' onchange="toggleTargets('."'$balnum'".');">'."\n".
                   4479:                           '<option value="" selected="selected">'.&mt('None').
                   4480:                           '</option>'."\n";
                   4481:             foreach my $server (sort(keys(%servers))) {
                   4482:                 next if ($currbalancer{$server});
                   4483:                 $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
                   4484:             }
                   4485:             $datatable .=
                   4486:                 '</select>'."\n".
                   4487:                 '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" />&nbsp;</span>'."\n";
                   4488:         } else {
                   4489:             $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
                   4490:                           '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" />&nbsp;'.
                   4491:                            &mt('Stop balancing').'</label>'.
                   4492:                            '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
                   4493:             $targets_div_style = 'display: block';
                   4494:             $disabled_div_style = 'display: none';
                   4495:             if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
                   4496:                 $homedom_div_style = 'display: block';
                   4497:             }
                   4498:         }
                   4499:         $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
                   4500:                   '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
                   4501:                   $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
                   4502:                   '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
                   4503:         my ($numspares,@spares) = &count_servers($lonhost,%servers);
                   4504:         my @sparestypes = ('primary','default');
                   4505:         my %typetitles = &sparestype_titles();
1.160.6.76  raeburn  4506:         my %hostherechecked = (
                   4507:                                   no => ' checked="checked"',
                   4508:                               );
1.160.6.7  raeburn  4509:         foreach my $sparetype (@sparestypes) {
                   4510:             my $targettable;
                   4511:             for (my $i=0; $i<$numspares; $i++) {
                   4512:                 my $checked;
                   4513:                 if (ref($currtargets{$lonhost}) eq 'HASH') {
                   4514:                     if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
                   4515:                         if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
                   4516:                             $checked = ' checked="checked"';
                   4517:                         }
                   4518:                     }
                   4519:                 }
                   4520:                 my ($chkboxval,$disabled);
                   4521:                 if (($lonhost ne '') && (exists($servers{$lonhost}))) {
                   4522:                     $chkboxval = $spares[$i];
                   4523:                 }
                   4524:                 if (exists($currbalancer{$spares[$i]})) {
                   4525:                     $disabled = ' disabled="disabled"';
                   4526:                 }
                   4527:                 $targettable .=
1.160.6.55  raeburn  4528:                     '<td><span class="LC_nobreak"><label>'.
                   4529:                     '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.160.6.7  raeburn  4530:                     $checked.$disabled.' value="'.$chkboxval.'" id="loadbalancing_target_'.$balnum.'_'.$sparetype.'_'.$i.'" onclick="checkOffloads('."this,'$balnum','$sparetype'".');" /><span id="loadbalancing_targettxt_'.$balnum.'_'.$sparetype.'_'.$i.'">&nbsp;'.$chkboxval.
1.160.6.55  raeburn  4531:                     '</span></label></span></td>';
1.160.6.7  raeburn  4532:                 my $rem = $i%($numinrow);
                   4533:                 if ($rem == 0) {
                   4534:                     if (($i > 0) && ($i < $numspares-1)) {
                   4535:                         $targettable .= '</tr>';
                   4536:                     }
                   4537:                     if ($i < $numspares-1) {
                   4538:                         $targettable .= '<tr>';
1.150     raeburn  4539:                     }
                   4540:                 }
                   4541:             }
1.160.6.7  raeburn  4542:             if ($targettable ne '') {
                   4543:                 my $rem = $numspares%($numinrow);
                   4544:                 my $colsleft = $numinrow - $rem;
                   4545:                 if ($colsleft > 1 ) {
                   4546:                     $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   4547:                                     '&nbsp;</td>';
                   4548:                 } elsif ($colsleft == 1) {
                   4549:                     $targettable .= '<td class="LC_left_item">&nbsp;</td>';
                   4550:                 }
                   4551:                 $datatable .=  '<i>'.$typetitles{$sparetype}.'</i><br />'.
                   4552:                                '<table><tr>'.$targettable.'</tr></table><br />';
                   4553:             }
1.160.6.76  raeburn  4554:             $hostherechecked{$sparetype} = '';
                   4555:             if (ref($currtargets{$lonhost}) eq 'HASH') {
                   4556:                 if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
                   4557:                     if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
                   4558:                         $hostherechecked{$sparetype} = ' checked="checked"';
                   4559:                         $hostherechecked{'no'} = '';
                   4560:                     }
                   4561:                 }
                   4562:             }
                   4563:         }
                   4564:         $datatable .= &mt('Hosting on balancer itself').'<br />'.
                   4565:                       '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
                   4566:                       $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
                   4567:         foreach my $sparetype (@sparestypes) {
                   4568:             $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
                   4569:                           'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
                   4570:                           '</i></label><br />';
1.160.6.7  raeburn  4571:         }
                   4572:         $datatable .= '</div></td></tr>'.
                   4573:                       &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
                   4574:                                            $othertitle,$usertypes,$types,\%servers,
                   4575:                                            \%currbalancer,$lonhost,
                   4576:                                            $targets_div_style,$homedom_div_style,
                   4577:                                            $css_class[$cssidx],$balnum,$islast);
                   4578:         $$rowtotal += $rownum;
                   4579:         $balnum ++;
                   4580:     }
                   4581:     $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
                   4582:     return $datatable;
                   4583: }
                   4584: 
                   4585: sub get_loadbalancers_config {
                   4586:     my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
                   4587:     return unless ((ref($servers) eq 'HASH') &&
                   4588:                    (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
                   4589:                    (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
                   4590:     if (keys(%{$existing}) > 0) {
                   4591:         my $oldlonhost;
                   4592:         foreach my $key (sort(keys(%{$existing}))) {
                   4593:             if ($key eq 'lonhost') {
                   4594:                 $oldlonhost = $existing->{'lonhost'};
                   4595:                 $currbalancer->{$oldlonhost} = 1;
                   4596:             } elsif ($key eq 'targets') {
                   4597:                 if ($oldlonhost) {
                   4598:                     $currtargets->{$oldlonhost} = $existing->{'targets'};
                   4599:                 }
                   4600:             } elsif ($key eq 'rules') {
                   4601:                 if ($oldlonhost) {
                   4602:                     $currrules->{$oldlonhost} = $existing->{'rules'};
                   4603:                 }
                   4604:             } elsif (ref($existing->{$key}) eq 'HASH') {
                   4605:                 $currbalancer->{$key} = 1;
                   4606:                 $currtargets->{$key} = $existing->{$key}{'targets'};
                   4607:                 $currrules->{$key} = $existing->{$key}{'rules'};
1.150     raeburn  4608:             }
                   4609:         }
1.160.6.7  raeburn  4610:     } else {
                   4611:         my ($balancerref,$targetsref) =
                   4612:                 &Apache::lonnet::get_lonbalancer_config($servers);
                   4613:         if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
                   4614:             foreach my $server (sort(keys(%{$balancerref}))) {
                   4615:                 $currbalancer->{$server} = 1;
                   4616:                 $currtargets->{$server} = $targetsref->{$server};
1.150     raeburn  4617:             }
                   4618:         }
                   4619:     }
1.160.6.7  raeburn  4620:     return;
1.150     raeburn  4621: }
                   4622: 
                   4623: sub loadbalancing_rules {
                   4624:     my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.160.6.7  raeburn  4625:         $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
                   4626:         $css_class,$balnum,$islast) = @_;
1.150     raeburn  4627:     my $output;
1.160.6.7  raeburn  4628:     my $num = 0;
                   4629:     my ($alltypes,$othertypes,$titles) =
1.150     raeburn  4630:         &loadbalancing_titles($dom,$intdom,$usertypes,$types);
                   4631:     if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH'))  {
                   4632:         foreach my $type (@{$alltypes}) {
1.160.6.7  raeburn  4633:             $num ++;
1.150     raeburn  4634:             my $current;
                   4635:             if (ref($currrules) eq 'HASH') {
                   4636:                 $current = $currrules->{$type};
                   4637:             }
1.160.6.55  raeburn  4638:             if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.160.6.7  raeburn  4639:                 if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150     raeburn  4640:                     $current = '';
                   4641:                 }
                   4642:             }
                   4643:             $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.160.6.7  raeburn  4644:                                              $servers,$currbalancer,$lonhost,$dom,
                   4645:                                              $targets_div_style,$homedom_div_style,
                   4646:                                              $css_class,$balnum,$num,$islast);
1.150     raeburn  4647:         }
                   4648:     }
                   4649:     return $output;
                   4650: }
                   4651: 
                   4652: sub loadbalancing_titles {
                   4653:     my ($dom,$intdom,$usertypes,$types) = @_;
                   4654:     my %othertypes = (
                   4655:            '_LC_adv'         => &mt('Advanced users from [_1]',$dom),
                   4656:            '_LC_author'      => &mt('Users from [_1] with author role',$dom),
                   4657:            '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
                   4658:            '_LC_external'    => &mt('Users not from [_1]',$intdom),
1.160.6.26  raeburn  4659:            '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
                   4660:            '_LC_ipchange'    => &mt('Non-SSO users with IP mismatch'),
1.150     raeburn  4661:                      );
1.160.6.26  raeburn  4662:     my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.160.6.89  raeburn  4663:     my @available;
1.150     raeburn  4664:     if (ref($types) eq 'ARRAY') {
1.160.6.89  raeburn  4665:         @available = @{$types};
1.150     raeburn  4666:     }
1.160.6.89  raeburn  4667:     unless (grep(/^default$/,@available)) {
                   4668:         push(@available,'default');
                   4669:     }
                   4670:     unshift(@alltypes,@available);
1.150     raeburn  4671:     my %titles;
                   4672:     foreach my $type (@alltypes) {
                   4673:         if ($type =~ /^_LC_/) {
                   4674:             $titles{$type} = $othertypes{$type};
                   4675:         } elsif ($type eq 'default') {
                   4676:             $titles{$type} = &mt('All users from [_1]',$dom);
                   4677:             if (ref($types) eq 'ARRAY') {
                   4678:                 if (@{$types} > 0) {
                   4679:                     $titles{$type} = &mt('Other users from [_1]',$dom);
                   4680:                 }
                   4681:             }
                   4682:         } elsif (ref($usertypes) eq 'HASH') {
                   4683:             $titles{$type} = $usertypes->{$type};
                   4684:         }
                   4685:     }
                   4686:     return (\@alltypes,\%othertypes,\%titles);
                   4687: }
                   4688: 
                   4689: sub loadbalance_rule_row {
1.160.6.7  raeburn  4690:     my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
                   4691:         $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.160.6.26  raeburn  4692:     my @rulenames;
1.150     raeburn  4693:     my %ruletitles = &offloadtype_text();
1.160.6.26  raeburn  4694:     if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.160.6.55  raeburn  4695:         @rulenames = ('balancer','offloadedto','specific');
1.150     raeburn  4696:     } else {
1.160.6.26  raeburn  4697:         @rulenames = ('default','homeserver');
                   4698:         if ($type eq '_LC_external') {
                   4699:             push(@rulenames,'externalbalancer');
                   4700:         } else {
                   4701:             push(@rulenames,'specific');
                   4702:         }
                   4703:         push(@rulenames,'none');
1.150     raeburn  4704:     }
                   4705:     my $style = $targets_div_style;
1.160.6.55  raeburn  4706:     if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150     raeburn  4707:         $style = $homedom_div_style;
                   4708:     }
1.160.6.7  raeburn  4709:     my $space;
                   4710:     if ($islast && $num == 1) {
                   4711:         $space = '<div display="inline-block">&nbsp;</div>';
                   4712:     }
                   4713:     my $output =
                   4714:         '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
                   4715:         '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
                   4716:         '<td valaign="top">'.$space.
                   4717:         '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150     raeburn  4718:     for (my $i=0; $i<@rulenames; $i++) {
                   4719:         my $rule = $rulenames[$i];
                   4720:         my ($checked,$extra);
                   4721:         if ($rulenames[$i] eq 'default') {
                   4722:             $rule = '';
                   4723:         }
                   4724:         if ($rulenames[$i] eq 'specific') {
                   4725:             if (ref($servers) eq 'HASH') {
                   4726:                 my $default;
                   4727:                 if (($current ne '') && (exists($servers->{$current}))) {
                   4728:                     $checked = ' checked="checked"';
                   4729:                 }
                   4730:                 unless ($checked) {
                   4731:                     $default = ' selected="selected"';
                   4732:                 }
1.160.6.7  raeburn  4733:                 $extra =
                   4734:                     ':&nbsp;<select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
                   4735:                     '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
                   4736:                     '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
                   4737:                     '<option value=""'.$default.'></option>'."\n";
                   4738:                 foreach my $server (sort(keys(%{$servers}))) {
                   4739:                     if (ref($currbalancer) eq 'HASH') {
                   4740:                         next if (exists($currbalancer->{$server}));
                   4741:                     }
1.150     raeburn  4742:                     my $selected;
1.160.6.7  raeburn  4743:                     if ($server eq $current) {
1.150     raeburn  4744:                         $selected = ' selected="selected"';
                   4745:                     }
1.160.6.7  raeburn  4746:                     $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150     raeburn  4747:                 }
                   4748:                 $extra .= '</select>';
                   4749:             }
                   4750:         } elsif ($rule eq $current) {
                   4751:             $checked = ' checked="checked"';
                   4752:         }
                   4753:         $output .= '<span class="LC_nobreak"><label>'.
1.160.6.7  raeburn  4754:                    '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
                   4755:                    '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
                   4756:                    $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.160.6.55  raeburn  4757:                    ')"'.$checked.' />&nbsp;';
1.160.6.56  raeburn  4758:         if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
1.160.6.55  raeburn  4759:             $output .= $ruletitles{'particular'};
                   4760:         } else {
                   4761:             $output .= $ruletitles{$rulenames[$i]};
                   4762:         }
                   4763:         $output .= '</label>'.$extra.'</span><br />'."\n";
1.150     raeburn  4764:     }
                   4765:     $output .= '</div></td></tr>'."\n";
                   4766:     return $output;
                   4767: }
                   4768: 
                   4769: sub offloadtype_text {
                   4770:     my %ruletitles = &Apache::lonlocal::texthash (
                   4771:            'default'          => 'Offloads to default destinations',
                   4772:            'homeserver'       => "Offloads to user's home server",
                   4773:            'externalbalancer' => "Offloads to Load Balancer in user's domain",
                   4774:            'specific'         => 'Offloads to specific server',
1.160.6.3  raeburn  4775:            'none'             => 'No offload',
1.160.6.26  raeburn  4776:            'balancer'         => 'Session hosted on Load Balancer, after re-authentication',
                   4777:            'offloadedto'      => 'Session hosted on offload server, after re-authentication',
1.160.6.55  raeburn  4778:            'particular'       => 'Session hosted (after re-auth) on server:',
1.150     raeburn  4779:     );
                   4780:     return %ruletitles;
                   4781: }
                   4782: 
                   4783: sub sparestype_titles {
                   4784:     my %typestitles = &Apache::lonlocal::texthash (
                   4785:                           'primary' => 'primary',
                   4786:                           'default' => 'default',
                   4787:                       );
                   4788:     return %typestitles;
                   4789: }
                   4790: 
1.28      raeburn  4791: sub contact_titles {
                   4792:     my %titles = &Apache::lonlocal::texthash (
1.160.6.78  raeburn  4793:                    'supportemail'    => 'Support E-mail address',
                   4794:                    'adminemail'      => 'Default Server Admin E-mail address',
                   4795:                    'errormail'       => 'Error reports to be e-mailed to',
                   4796:                    'packagesmail'    => 'Package update alerts to be e-mailed to',
                   4797:                    'helpdeskmail'    => "Helpdesk requests for this domain's users",
                   4798:                    'otherdomsmail'   => 'Helpdesk requests for other (unconfigured) domains',
                   4799:                    'lonstatusmail'   => 'E-mail from nightly status check (warnings/errors)',
                   4800:                    'requestsmail'    => 'E-mail from course requests requiring approval',
                   4801:                    'updatesmail'     => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.160.6.23  raeburn  4802:                    'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.28      raeburn  4803:                  );
                   4804:     my %short_titles = &Apache::lonlocal::texthash (
                   4805:                            adminemail   => 'Admin E-mail address',
                   4806:                            supportemail => 'Support E-mail',
                   4807:                        );   
                   4808:     return (\%titles,\%short_titles);
                   4809: }
                   4810: 
1.160.6.78  raeburn  4811: sub helpform_fields {
                   4812:     my %titles =  &Apache::lonlocal::texthash (
                   4813:                        'username'   => 'Name',
                   4814:                        'user'       => 'Username/domain',
                   4815:                        'phone'      => 'Phone',
                   4816:                        'cc'         => 'Cc e-mail',
                   4817:                        'course'     => 'Course Details',
                   4818:                        'section'    => 'Sections',
                   4819:                        'screenshot' => 'File upload',
                   4820:     );
                   4821:     my @fields = ('username','phone','user','course','section','cc','screenshot');
                   4822:     my %possoptions = (
                   4823:                         username     => ['yes','no','req'],
                   4824:                         phone        => ['yes','no','req'],
                   4825:                         user         => ['yes','no'],
                   4826:                         cc           => ['yes','no'],
                   4827:                         course       => ['yes','no'],
                   4828:                         section      => ['yes','no'],
                   4829:                         screenshot   => ['yes','no'],
                   4830:                       );
                   4831:     my %fieldoptions = &Apache::lonlocal::texthash (
                   4832:                          'yes'  => 'Optional',
                   4833:                          'req'  => 'Required',
                   4834:                          'no'   => "Not shown",
                   4835:     );
                   4836:     return (\@fields,\%titles,\%fieldoptions,\%possoptions);
                   4837: }
                   4838: 
1.72      raeburn  4839: sub tool_titles {
                   4840:     my %titles = &Apache::lonlocal::texthash (
1.160.6.4  raeburn  4841:                      aboutme    => 'Personal web page',
1.86      raeburn  4842:                      blog       => 'Blog',
1.160.6.4  raeburn  4843:                      webdav     => 'WebDAV',
1.86      raeburn  4844:                      portfolio  => 'Portfolio',
1.88      bisitz   4845:                      official   => 'Official courses (with institutional codes)',
                   4846:                      unofficial => 'Unofficial courses',
1.98      raeburn  4847:                      community  => 'Communities',
1.160.6.30  raeburn  4848:                      textbook   => 'Textbook courses',
1.86      raeburn  4849:                  );
1.72      raeburn  4850:     return %titles;
                   4851: }
                   4852: 
1.101     raeburn  4853: sub courserequest_titles {
                   4854:     my %titles = &Apache::lonlocal::texthash (
                   4855:                                    official   => 'Official',
                   4856:                                    unofficial => 'Unofficial',
                   4857:                                    community  => 'Communities',
1.160.6.30  raeburn  4858:                                    textbook   => 'Textbook',
1.101     raeburn  4859:                                    norequest  => 'Not allowed',
1.104     raeburn  4860:                                    approval   => 'Approval by Dom. Coord.',
1.101     raeburn  4861:                                    validate   => 'With validation',
                   4862:                                    autolimit  => 'Numerical limit',
1.103     raeburn  4863:                                    unlimited  => '(blank for unlimited)',
1.101     raeburn  4864:                  );
                   4865:     return %titles;
                   4866: }
                   4867: 
1.160.6.5  raeburn  4868: sub authorrequest_titles {
                   4869:     my %titles = &Apache::lonlocal::texthash (
                   4870:                                    norequest  => 'Not allowed',
                   4871:                                    approval   => 'Approval by Dom. Coord.',
                   4872:                                    automatic  => 'Automatic approval',
                   4873:                  );
                   4874:     return %titles;
                   4875: }
                   4876: 
1.101     raeburn  4877: sub courserequest_conditions {
                   4878:     my %conditions = &Apache::lonlocal::texthash (
1.104     raeburn  4879:        approval    => '(Processing of request subject to approval by Domain Coordinator).',
1.160.6.17  raeburn  4880:        validate   => '(Processing of request subject to institutional validation).',
1.101     raeburn  4881:                  );
                   4882:     return %conditions;
                   4883: }
                   4884: 
                   4885: 
1.27      raeburn  4886: sub print_usercreation {
1.30      raeburn  4887:     my ($position,$dom,$settings,$rowtotal) = @_;
1.27      raeburn  4888:     my $numinrow = 4;
1.28      raeburn  4889:     my $datatable;
                   4890:     if ($position eq 'top') {
1.30      raeburn  4891:         $$rowtotal ++;
1.34      raeburn  4892:         my $rowcount = 0;
1.32      raeburn  4893:         my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28      raeburn  4894:         if (ref($rules) eq 'HASH') {
                   4895:             if (keys(%{$rules}) > 0) {
1.32      raeburn  4896:                 $datatable .= &user_formats_row('username',$settings,$rules,
                   4897:                                                 $ruleorder,$numinrow,$rowcount);
1.30      raeburn  4898:                 $$rowtotal ++;
1.32      raeburn  4899:                 $rowcount ++;
                   4900:             }
                   4901:         }
                   4902:         my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
                   4903:         if (ref($idrules) eq 'HASH') {
                   4904:             if (keys(%{$idrules}) > 0) {
                   4905:                 $datatable .= &user_formats_row('id',$settings,$idrules,
                   4906:                                                 $idruleorder,$numinrow,$rowcount);
                   4907:                 $$rowtotal ++;
                   4908:                 $rowcount ++;
1.28      raeburn  4909:             }
                   4910:         }
1.39      raeburn  4911:         if ($rowcount == 0) {
                   4912:             $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';  
                   4913:             $$rowtotal ++;
                   4914:             $rowcount ++;
                   4915:         }
1.34      raeburn  4916:     } elsif ($position eq 'middle') {
1.160.6.34  raeburn  4917:         my @creators = ('author','course','requestcrs');
1.37      raeburn  4918:         my ($rules,$ruleorder) =
                   4919:             &Apache::lonnet::inst_userrules($dom,'username');
1.34      raeburn  4920:         my %lt = &usercreation_types();
                   4921:         my %checked;
                   4922:         if (ref($settings) eq 'HASH') {
                   4923:             if (ref($settings->{'cancreate'}) eq 'HASH') {
                   4924:                 foreach my $item (@creators) {
                   4925:                     $checked{$item} = $settings->{'cancreate'}{$item};
                   4926:                 }
                   4927:             } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
                   4928:                 foreach my $item (@creators) {
                   4929:                     if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
                   4930:                         $checked{$item} = 'none';
                   4931:                     }
                   4932:                 }
                   4933:             }
                   4934:         }
                   4935:         my $rownum = 0;
                   4936:         foreach my $item (@creators) {
                   4937:             $rownum ++;
1.160.6.34  raeburn  4938:             if ($checked{$item} eq '') {
                   4939:                 $checked{$item} = 'any';
1.34      raeburn  4940:             }
                   4941:             my $css_class;
                   4942:             if ($rownum%2) {
                   4943:                 $css_class = '';
                   4944:             } else {
                   4945:                 $css_class = ' class="LC_odd_row" ';
                   4946:             }
                   4947:             $datatable .= '<tr'.$css_class.'>'.
                   4948:                          '<td><span class="LC_nobreak">'.$lt{$item}.
                   4949:                          '</span></td><td align="right">';
1.160.6.34  raeburn  4950:             my @options = ('any');
                   4951:             if (ref($rules) eq 'HASH') {
                   4952:                 if (keys(%{$rules}) > 0) {
                   4953:                     push(@options,('official','unofficial'));
1.37      raeburn  4954:                 }
                   4955:             }
1.160.6.34  raeburn  4956:             push(@options,'none');
1.37      raeburn  4957:             foreach my $option (@options) {
1.50      raeburn  4958:                 my $type = 'radio';
1.34      raeburn  4959:                 my $check = ' ';
1.160.6.34  raeburn  4960:                 if ($checked{$item} eq $option) {
                   4961:                     $check = ' checked="checked" ';
1.34      raeburn  4962:                 } 
                   4963:                 $datatable .= '<span class="LC_nobreak"><label>'.
1.50      raeburn  4964:                               '<input type="'.$type.'" name="can_createuser_'.
1.34      raeburn  4965:                               $item.'" value="'.$option.'"'.$check.'/>&nbsp;'.
                   4966:                               $lt{$option}.'</label>&nbsp;&nbsp;</span>';
                   4967:             }
                   4968:             $datatable .= '</td></tr>';
                   4969:         }
1.28      raeburn  4970:     } else {
                   4971:         my @contexts = ('author','course','domain');
                   4972:         my @authtypes = ('int','krb4','krb5','loc');
                   4973:         my %checked;
                   4974:         if (ref($settings) eq 'HASH') {
                   4975:             if (ref($settings->{'authtypes'}) eq 'HASH') {
                   4976:                 foreach my $item (@contexts) {
                   4977:                     if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
                   4978:                         foreach my $auth (@authtypes) {
                   4979:                             if ($settings->{'authtypes'}{$item}{$auth}) {
                   4980:                                 $checked{$item}{$auth} = ' checked="checked" ';
                   4981:                             }
                   4982:                         }
                   4983:                     }
                   4984:                 }
1.27      raeburn  4985:             }
1.35      raeburn  4986:         } else {
                   4987:             foreach my $item (@contexts) {
1.36      raeburn  4988:                 foreach my $auth (@authtypes) {
1.35      raeburn  4989:                     $checked{$item}{$auth} = ' checked="checked" ';
                   4990:                 }
                   4991:             }
1.27      raeburn  4992:         }
1.28      raeburn  4993:         my %title = &context_names();
                   4994:         my %authname = &authtype_names();
                   4995:         my $rownum = 0;
                   4996:         my $css_class; 
                   4997:         foreach my $item (@contexts) {
                   4998:             if ($rownum%2) {
                   4999:                 $css_class = '';
                   5000:             } else {
                   5001:                 $css_class = ' class="LC_odd_row" ';
                   5002:             }
1.30      raeburn  5003:             $datatable .=   '<tr'.$css_class.'>'.
1.28      raeburn  5004:                             '<td>'.$title{$item}.
                   5005:                             '</td><td class="LC_left_item">'.
                   5006:                             '<span class="LC_nobreak">';
                   5007:             foreach my $auth (@authtypes) {
                   5008:                 $datatable .= '<label>'. 
                   5009:                               '<input type="checkbox" name="'.$item.'_auth" '.
                   5010:                               $checked{$item}{$auth}.' value="'.$auth.'" />'.
                   5011:                               $authname{$auth}.'</label>&nbsp;';
                   5012:             }
                   5013:             $datatable .= '</span></td></tr>';
                   5014:             $rownum ++;
1.27      raeburn  5015:         }
1.30      raeburn  5016:         $$rowtotal += $rownum;
1.27      raeburn  5017:     }
                   5018:     return $datatable;
                   5019: }
                   5020: 
1.160.6.34  raeburn  5021: sub print_selfcreation {
                   5022:     my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.40  raeburn  5023:     my (@selfcreate,$createsettings,$processing,$datatable);
1.160.6.34  raeburn  5024:     if (ref($settings) eq 'HASH') {
                   5025:         if (ref($settings->{'cancreate'}) eq 'HASH') {
                   5026:             $createsettings = $settings->{'cancreate'};
1.160.6.40  raeburn  5027:             if (ref($createsettings) eq 'HASH') {
                   5028:                 if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
                   5029:                     @selfcreate = @{$createsettings->{'selfcreate'}};
                   5030:                 } elsif ($createsettings->{'selfcreate'} ne '') {
                   5031:                     if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
                   5032:                         @selfcreate = ('email','login','sso');
                   5033:                     } elsif ($createsettings->{'selfcreate'} ne 'none') {
                   5034:                         @selfcreate = ($createsettings->{'selfcreate'});
                   5035:                     }
                   5036:                 }
                   5037:                 if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
                   5038:                     $processing = $createsettings->{'selfcreateprocessing'};
1.160.6.34  raeburn  5039:                 }
                   5040:             }
                   5041:         }
                   5042:     }
                   5043:     my %radiohash;
                   5044:     my $numinrow = 4;
                   5045:     map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
1.160.6.89  raeburn  5046:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.34  raeburn  5047:     if ($position eq 'top') {
                   5048:         my %choices = &Apache::lonlocal::texthash (
                   5049:                                                       cancreate_login      => 'Institutional Login',
                   5050:                                                       cancreate_sso        => 'Institutional Single Sign On',
                   5051:                                                   );
                   5052:         my @toggles = sort(keys(%choices));
                   5053:         my %defaultchecked = (
                   5054:                                'cancreate_login' => 'off',
                   5055:                                'cancreate_sso'   => 'off',
                   5056:                              );
1.160.6.35  raeburn  5057:         my ($onclick,$itemcount);
1.160.6.34  raeburn  5058:         ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
                   5059:                                                      \%choices,$itemcount,$onclick);
1.160.6.35  raeburn  5060:         $$rowtotal += $itemcount;
1.160.6.34  raeburn  5061: 
                   5062:         if (ref($usertypes) eq 'HASH') {
                   5063:             if (keys(%{$usertypes}) > 0) {
                   5064:                 $datatable .= &insttypes_row($createsettings,$types,$usertypes,
                   5065:                                              $dom,$numinrow,$othertitle,
1.160.6.89  raeburn  5066:                                              'statustocreate',$rowtotal);
1.160.6.34  raeburn  5067:                 $$rowtotal ++;
                   5068:             }
                   5069:         }
1.160.6.44  raeburn  5070:         my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
                   5071:         my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
                   5072:         $fieldtitles{'inststatus'} = &mt('Institutional status');
                   5073:         my $rem;
                   5074:         my $numperrow = 2;
                   5075:         my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
                   5076:         $datatable .= '<tr'.$css_class.'>'.
1.160.6.45  raeburn  5077:                      '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.160.6.44  raeburn  5078:                      '<td class="LC_left_item">'."\n".
1.160.6.87  raeburn  5079:                      '<table>'."\n";
1.160.6.44  raeburn  5080:         for (my $i=0; $i<@fields; $i++) {
                   5081:             $rem = $i%($numperrow);
                   5082:             if ($rem == 0) {
                   5083:                 if ($i > 0) {
                   5084:                     $datatable .= '</tr>';
                   5085:                 }
                   5086:                 $datatable .= '<tr>';
                   5087:             }
                   5088:             my $currval;
1.160.6.51  raeburn  5089:             if (ref($createsettings) eq 'HASH') {
                   5090:                 if (ref($createsettings->{'shibenv'}) eq 'HASH') {
                   5091:                     $currval = $createsettings->{'shibenv'}{$fields[$i]};
                   5092:                 }
1.160.6.44  raeburn  5093:             }
                   5094:             $datatable .= '<td class="LC_left_item">'.
                   5095:                           '<span class="LC_nobreak">'.
                   5096:                           '<input type="text" name="shibenv_'.$fields[$i].'" '.
                   5097:                           'value="'.$currval.'" size="10" />&nbsp;'.
                   5098:                           $fieldtitles{$fields[$i]}.'</span></td>';
                   5099:         }
                   5100:         my $colsleft = $numperrow - $rem;
                   5101:         if ($colsleft > 1 ) {
                   5102:             $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   5103:                          '&nbsp;</td>';
                   5104:         } elsif ($colsleft == 1) {
                   5105:             $datatable .= '<td class="LC_left_item">&nbsp;</td>';
                   5106:         }
                   5107:         $datatable .= '</tr></table></td></tr>';
                   5108:         $$rowtotal ++;
1.160.6.34  raeburn  5109:     } elsif ($position eq 'middle') {
                   5110:         my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
1.160.6.89  raeburn  5111:         my @posstypes;
1.160.6.34  raeburn  5112:         if (ref($types) eq 'ARRAY') {
1.160.6.89  raeburn  5113:             @posstypes = @{$types};
                   5114:         }
                   5115:         unless (grep(/^default$/,@posstypes)) {
                   5116:             push(@posstypes,'default');
                   5117:         }
                   5118:         my %usertypeshash;
                   5119:         if (ref($usertypes) eq 'HASH') {
                   5120:             %usertypeshash = %{$usertypes};
                   5121:         }
                   5122:         $usertypeshash{'default'} = $othertitle;
                   5123:         foreach my $status (@posstypes) {
                   5124:             $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
                   5125:                                                    $numinrow,$$rowtotal,\%usertypeshash);
                   5126:             $$rowtotal ++;
1.160.6.34  raeburn  5127:         }
                   5128:     } else {
1.160.6.40  raeburn  5129:         my %choices = &Apache::lonlocal::texthash (
                   5130:                                                       cancreate_email => 'E-mail address as username',
                   5131:                                                   );
                   5132:         my @toggles = sort(keys(%choices));
                   5133:         my %defaultchecked = (
                   5134:                                'cancreate_email' => 'off',
                   5135:                              );
                   5136:         my $itemcount = 0;
                   5137:         my $display = 'none';
                   5138:         if (grep(/^\Qemail\E$/,@selfcreate)) {
                   5139:             $display = 'block';
                   5140:         }
                   5141:         my $onclick = "toggleDisplay(this.form,'emailoptions');";
                   5142:         my $additional = '<div id="emailoptions" style="display: '.$display.'">';
                   5143:         my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.160.6.89  raeburn  5144:         my (@ordered,%usertypeshash);
                   5145:         if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
                   5146:             @ordered = @{$domdefaults{'inststatusguest'}};
                   5147:         }
                   5148:         if (@ordered) {
                   5149:             unless (grep(/^default$/,@ordered)) {
                   5150:                 push(@ordered,'default');
                   5151:             }
                   5152:             if (ref($usertypes) eq 'HASH') {
                   5153:                 %usertypeshash = %{$usertypes};
                   5154:             }
                   5155:             $usertypeshash{'default'} = $othertitle;
                   5156:             $additional .= '<table><tr>';
                   5157:             foreach my $status (@ordered) {
                   5158:                 $additional .= '<th>'.$usertypeshash{$status}.'</th>';
1.160.6.34  raeburn  5159:             }
1.160.6.89  raeburn  5160:             $additional .= '</tr><tr>';
                   5161:             foreach my $status (@ordered) {
                   5162:                 $additional .= '<td>'.&email_as_username($rowtotal,$processing,$status).'</td>';
                   5163:             }
                   5164:             $additional .= '</tr></table>';
                   5165:         } else {
                   5166:             $usertypeshash{'default'} = $othertitle;
                   5167:             $additional .= &email_as_username($rowtotal,$processing);
1.160.6.34  raeburn  5168:         }
1.160.6.40  raeburn  5169:         $additional .= '</div>'."\n";
                   5170: 
                   5171:         ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
1.160.6.44  raeburn  5172:                                                      \%choices,$$rowtotal,$onclick,$additional);
                   5173:         $$rowtotal ++;
1.160.6.40  raeburn  5174:         $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal);
1.160.6.34  raeburn  5175:         $$rowtotal ++;
1.160.6.35  raeburn  5176:         my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
                   5177:         $numinrow = 1;
1.160.6.89  raeburn  5178:         foreach my $status (@ordered) {
                   5179:             $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
                   5180:                                                    $numinrow,$$rowtotal,\%usertypeshash,$infofields,$infotitles);
                   5181:             $$rowtotal ++;
1.160.6.35  raeburn  5182:         }
1.160.6.34  raeburn  5183:         my ($emailrules,$emailruleorder) =
                   5184:             &Apache::lonnet::inst_userrules($dom,'email');
                   5185:         if (ref($emailrules) eq 'HASH') {
                   5186:             if (keys(%{$emailrules}) > 0) {
                   5187:                 $datatable .= &user_formats_row('email',$settings,$emailrules,
1.160.6.35  raeburn  5188:                                                 $emailruleorder,$numinrow,$$rowtotal);
1.160.6.34  raeburn  5189:                 $$rowtotal ++;
                   5190:             }
                   5191:         }
1.160.6.35  raeburn  5192:         $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal);
1.160.6.34  raeburn  5193:     }
                   5194:     return $datatable;
                   5195: }
                   5196: 
1.160.6.40  raeburn  5197: sub email_as_username {
                   5198:     my ($rowtotal,$processing,$type) = @_;
                   5199:     my %choices =
                   5200:         &Apache::lonlocal::texthash (
                   5201:                                       automatic => 'Automatic approval',
                   5202:                                       approval  => 'Queued for approval',
                   5203:                                     );
                   5204:     my $output;
                   5205:     foreach my $option ('automatic','approval') {
                   5206:         my $checked;
                   5207:         if (ref($processing) eq 'HASH') {
                   5208:             if ($type eq '') {   
                   5209:                 if (!exists($processing->{'default'})) {
                   5210:                     if ($option eq 'automatic') {
                   5211:                         $checked = ' checked="checked"';
                   5212:                     }
                   5213:                 } else {
                   5214:                     if ($processing->{'default'} eq $option) {
                   5215:                         $checked = ' checked="checked"';
                   5216:                     }
                   5217:                 }
                   5218:             } else {
                   5219:                 if (!exists($processing->{$type})) {
                   5220:                     if ($option eq 'automatic') {
                   5221:                         $checked = ' checked="checked"';
                   5222:                     }
                   5223:                 } else {
                   5224:                     if ($processing->{$type} eq $option) {
                   5225:                         $checked = ' checked="checked"';
                   5226:                     }
                   5227:                 }
                   5228:             }
                   5229:         } elsif ($option eq 'automatic') {
                   5230:             $checked = ' checked="checked"'; 
                   5231:         }
                   5232:         my $name = 'cancreate_emailprocess';
                   5233:         if (($type ne '') && ($type ne 'default')) {
                   5234:             $name .= '_'.$type;
                   5235:         }
                   5236:         $output .= '<span class="LC_nobreak"><label>'.
                   5237:                    '<input type="radio" name="'.$name.'"'.
                   5238:                    $checked.' value="'.$option.'" />'.
                   5239:                    $choices{$option}.'</label></span>';
                   5240:         if ($type eq '') {
                   5241:             $output .= '&nbsp;';
                   5242:         } else {
                   5243:             $output .= '<br />';
                   5244:         }
                   5245:     }
                   5246:     $$rowtotal ++;
                   5247:     return $output;
                   5248: }
                   5249: 
1.160.6.5  raeburn  5250: sub captcha_choice {
                   5251:     my ($context,$settings,$itemcount) = @_;
1.160.6.69  raeburn  5252:     my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
                   5253:         $vertext,$currver); 
1.160.6.5  raeburn  5254:     my %lt = &captcha_phrases();
                   5255:     $keyentry = 'hidden';
                   5256:     if ($context eq 'cancreate') {
1.160.6.34  raeburn  5257:         $rowname = &mt('CAPTCHA validation');
1.160.6.5  raeburn  5258:     } elsif ($context eq 'login') {
                   5259:         $rowname =  &mt('"Contact helpdesk" CAPTCHA validation');
                   5260:     }
                   5261:     if (ref($settings) eq 'HASH') {
                   5262:         if ($settings->{'captcha'}) {
                   5263:             $checked{$settings->{'captcha'}} = ' checked="checked"';
                   5264:         } else {
                   5265:             $checked{'original'} = ' checked="checked"';
                   5266:         }
                   5267:         if ($settings->{'captcha'} eq 'recaptcha') {
                   5268:             $pubtext = $lt{'pub'};
                   5269:             $privtext = $lt{'priv'};
                   5270:             $keyentry = 'text';
1.160.6.69  raeburn  5271:             $vertext = $lt{'ver'};
                   5272:             $currver = $settings->{'recaptchaversion'};
                   5273:             if ($currver ne '2') {
                   5274:                 $currver = 1;
                   5275:             }
1.160.6.5  raeburn  5276:         }
                   5277:         if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
                   5278:             $currpub = $settings->{'recaptchakeys'}{'public'};
                   5279:             $currpriv = $settings->{'recaptchakeys'}{'private'};
                   5280:         }
                   5281:     } else {
                   5282:         $checked{'original'} = ' checked="checked"';
                   5283:     }
                   5284:     my $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   5285:     my $output = '<tr'.$css_class.'>'.
                   5286:                  '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
                   5287:                  '<table><tr><td>'."\n";
                   5288:     foreach my $option ('original','recaptcha','notused') {
                   5289:         $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
                   5290:                    $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
                   5291:                    $lt{$option}.'</label></span>';
                   5292:         unless ($option eq 'notused') {
                   5293:             $output .= ('&nbsp;'x2)."\n";
                   5294:         }
                   5295:     }
                   5296: #
                   5297: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
                   5298: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
                   5299: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
                   5300: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
                   5301: #
                   5302:     $output .= '</td></tr>'."\n".
                   5303:                '<tr><td>'."\n".
                   5304:                '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span>&nbsp;'."\n".
                   5305:                '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
                   5306:                $currpub.'" size="40" /></span><br />'."\n".
                   5307:                '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span>&nbsp;'."\n".
                   5308:                '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.160.6.69  raeburn  5309:                $currpriv.'" size="40" /></span><br />'.
                   5310:                '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span>&nbsp;'."\n".
                   5311:                '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
                   5312:                $currver.'" size="3" /></span><br />'.
                   5313:                '</td></tr></table>'."\n".
1.160.6.5  raeburn  5314:                '</td></tr>';
                   5315:     return $output;
                   5316: }
                   5317: 
1.32      raeburn  5318: sub user_formats_row {
                   5319:     my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
                   5320:     my $output;
                   5321:     my %text = (
                   5322:                    'username' => 'new usernames',
                   5323:                    'id'       => 'IDs',
1.45      raeburn  5324:                    'email'    => 'self-created accounts (e-mail)',
1.32      raeburn  5325:                );
                   5326:     my $css_class = $rowcount%2?' class="LC_odd_row"':'';
                   5327:     $output = '<tr '.$css_class.'>'.
1.63      raeburn  5328:               '<td><span class="LC_nobreak">';
                   5329:     if ($type eq 'email') {
                   5330:         $output .= &mt("Formats disallowed for $text{$type}: ");
                   5331:     } else {
                   5332:         $output .= &mt("Format rules to check for $text{$type}: ");
                   5333:     }
                   5334:     $output .= '</span></td>'.
                   5335:                '<td class="LC_left_item" colspan="2"><table>';
1.27      raeburn  5336:     my $rem;
                   5337:     if (ref($ruleorder) eq 'ARRAY') {
                   5338:         for (my $i=0; $i<@{$ruleorder}; $i++) {
                   5339:             if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
                   5340:                 my $rem = $i%($numinrow);
                   5341:                 if ($rem == 0) {
                   5342:                     if ($i > 0) {
                   5343:                         $output .= '</tr>';
                   5344:                     }
                   5345:                     $output .= '<tr>';
                   5346:                 }
                   5347:                 my $check = ' ';
1.39      raeburn  5348:                 if (ref($settings) eq 'HASH') {
                   5349:                     if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
                   5350:                         if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
                   5351:                             $check = ' checked="checked" ';
                   5352:                         }
1.27      raeburn  5353:                     }
                   5354:                 }
                   5355:                 $output .= '<td class="LC_left_item">'.
                   5356:                            '<span class="LC_nobreak"><label>'.
1.32      raeburn  5357:                            '<input type="checkbox" name="'.$type.'_rule" '.
1.27      raeburn  5358:                            'value="'.$ruleorder->[$i].'"'.$check.'/>'.
                   5359:                            $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
                   5360:             }
                   5361:         }
                   5362:         $rem = @{$ruleorder}%($numinrow);
                   5363:     }
                   5364:     my $colsleft = $numinrow - $rem;
                   5365:     if ($colsleft > 1 ) {
                   5366:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   5367:                    '&nbsp;</td>';
                   5368:     } elsif ($colsleft == 1) {
                   5369:         $output .= '<td class="LC_left_item">&nbsp;</td>';
                   5370:     }
                   5371:     $output .= '</tr></table></td></tr>';
                   5372:     return $output;
                   5373: }
                   5374: 
1.34      raeburn  5375: sub usercreation_types {
                   5376:     my %lt = &Apache::lonlocal::texthash (
                   5377:                     author     => 'When adding a co-author',
                   5378:                     course     => 'When adding a user to a course',
1.100     raeburn  5379:                     requestcrs => 'When requesting a course',
1.34      raeburn  5380:                     any        => 'Any',
                   5381:                     official   => 'Institutional only ',
                   5382:                     unofficial => 'Non-institutional only',
                   5383:                     none       => 'None',
                   5384:     );
                   5385:     return %lt;
1.48      raeburn  5386: }
1.34      raeburn  5387: 
1.160.6.34  raeburn  5388: sub selfcreation_types {
                   5389:     my %lt = &Apache::lonlocal::texthash (
                   5390:                     selfcreate => 'User creates own account',
                   5391:                     any        => 'Any',
                   5392:                     official   => 'Institutional only ',
                   5393:                     unofficial => 'Non-institutional only',
                   5394:                     email      => 'E-mail address',
                   5395:                     login      => 'Institutional Login',
                   5396:                     sso        => 'SSO',
                   5397:              );
                   5398: }
                   5399: 
1.28      raeburn  5400: sub authtype_names {
                   5401:     my %lt = &Apache::lonlocal::texthash(
                   5402:                       int    => 'Internal',
                   5403:                       krb4   => 'Kerberos 4',
                   5404:                       krb5   => 'Kerberos 5',
                   5405:                       loc    => 'Local',
                   5406:                   );
                   5407:     return %lt;
                   5408: }
                   5409: 
                   5410: sub context_names {
                   5411:     my %context_title = &Apache::lonlocal::texthash(
                   5412:        author => 'Creating users when an Author',
                   5413:        course => 'Creating users when in a course',
                   5414:        domain => 'Creating users when a Domain Coordinator',
                   5415:     );
                   5416:     return %context_title;
                   5417: }
                   5418: 
1.33      raeburn  5419: sub print_usermodification {
                   5420:     my ($position,$dom,$settings,$rowtotal) = @_;
                   5421:     my $numinrow = 4;
                   5422:     my ($context,$datatable,$rowcount);
                   5423:     if ($position eq 'top') {
                   5424:         $rowcount = 0;
                   5425:         $context = 'author'; 
                   5426:         foreach my $role ('ca','aa') {
                   5427:             $datatable .= &modifiable_userdata_row($context,$role,$settings,
                   5428:                                                    $numinrow,$rowcount);
                   5429:             $$rowtotal ++;
                   5430:             $rowcount ++;
                   5431:         }
1.160.6.37  raeburn  5432:     } elsif ($position eq 'bottom') {
1.33      raeburn  5433:         $context = 'course';
                   5434:         $rowcount = 0;
                   5435:         foreach my $role ('st','ep','ta','in','cr') {
                   5436:             $datatable .= &modifiable_userdata_row($context,$role,$settings,
                   5437:                                                    $numinrow,$rowcount);
                   5438:             $$rowtotal ++;
                   5439:             $rowcount ++;
                   5440:         }
                   5441:     }
                   5442:     return $datatable;
                   5443: }
                   5444: 
1.43      raeburn  5445: sub print_defaults {
1.160.6.40  raeburn  5446:     my ($position,$dom,$settings,$rowtotal) = @_;
1.43      raeburn  5447:     my $rownum = 0;
1.160.6.80  raeburn  5448:     my ($datatable,$css_class,$titles);
                   5449:     unless ($position eq 'bottom') {
                   5450:         $titles = &defaults_titles($dom);
                   5451:     }
1.160.6.40  raeburn  5452:     if ($position eq 'top') {
                   5453:         my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
                   5454:                      'datelocale_def','portal_def');
                   5455:         my %defaults;
                   5456:         if (ref($settings) eq 'HASH') {
                   5457:             %defaults = %{$settings};
1.43      raeburn  5458:         } else {
1.160.6.40  raeburn  5459:             my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
                   5460:             foreach my $item (@items) {
                   5461:                 $defaults{$item} = $domdefaults{$item};
                   5462:             }
1.43      raeburn  5463:         }
1.160.6.40  raeburn  5464:         foreach my $item (@items) {
                   5465:             if ($rownum%2) {
                   5466:                 $css_class = '';
                   5467:             } else {
                   5468:                 $css_class = ' class="LC_odd_row" ';
1.43      raeburn  5469:             }
1.160.6.40  raeburn  5470:             $datatable .= '<tr'.$css_class.'>'.
                   5471:                           '<td><span class="LC_nobreak">'.$titles->{$item}.
                   5472:                           '</span></td><td class="LC_right_item" colspan="3">';
                   5473:             if ($item eq 'auth_def') {
                   5474:                 my @authtypes = ('internal','krb4','krb5','localauth');
                   5475:                 my %shortauth = (
                   5476:                                  internal => 'int',
                   5477:                                  krb4 => 'krb4',
                   5478:                                  krb5 => 'krb5',
                   5479:                                  localauth  => 'loc'
                   5480:                                 );
                   5481:                 my %authnames = &authtype_names();
                   5482:                 foreach my $auth (@authtypes) {
                   5483:                     my $checked = ' ';
                   5484:                     if ($defaults{$item} eq $auth) {
                   5485:                         $checked = ' checked="checked" ';
                   5486:                     }
                   5487:                     $datatable .= '<label><input type="radio" name="'.$item.
                   5488:                                   '" value="'.$auth.'"'.$checked.'/>'.
                   5489:                                   $authnames{$shortauth{$auth}}.'</label>&nbsp;&nbsp;';
                   5490:                 }
                   5491:             } elsif ($item eq 'timezone_def') {
                   5492:                 my $includeempty = 1;
                   5493:                 $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
                   5494:             } elsif ($item eq 'datelocale_def') {
                   5495:                 my $includeempty = 1;
                   5496:                 $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
                   5497:             } elsif ($item eq 'lang_def') {
1.160.6.63  raeburn  5498:                 my $includeempty = 1;
                   5499:                 $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.160.6.40  raeburn  5500:             } else {
                   5501:                 my $size;
                   5502:                 if ($item eq 'portal_def') {
                   5503:                     $size = ' size="25"';
                   5504:                 }
                   5505:                 $datatable .= '<input type="text" name="'.$item.'" value="'.
                   5506:                               $defaults{$item}.'"'.$size.' />';
                   5507:             }
                   5508:             $datatable .= '</td></tr>';
                   5509:             $rownum ++;
                   5510:         }
1.160.6.80  raeburn  5511:     } elsif ($position eq 'middle') {
                   5512:         my @items = ('intauth_cost','intauth_check','intauth_switch');
                   5513:         my %defaults;
                   5514:         if (ref($settings) eq 'HASH') {
                   5515:             %defaults = %{$settings};
                   5516:             if ($defaults{'intauth_cost'} !~ /^\d+$/) {
                   5517:                 $defaults{'intauth_cost'} = 10;
                   5518:             }
                   5519:             if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
                   5520:                 $defaults{'intauth_check'} = 0;
                   5521:             }
                   5522:             if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
                   5523:                 $defaults{'intauth_switch'} = 0;
                   5524:             }
                   5525:         } else {
                   5526:             %defaults = (
                   5527:                           'intauth_cost'   => 10,
                   5528:                           'intauth_check'  => 0,
                   5529:                           'intauth_switch' => 0,
                   5530:                         );
                   5531:         }
                   5532:         foreach my $item (@items) {
                   5533:             if ($rownum%2) {
                   5534:                 $css_class = '';
                   5535:             } else {
                   5536:                 $css_class = ' class="LC_odd_row" ';
                   5537:             }
                   5538:             $datatable .= '<tr'.$css_class.'>'.
                   5539:                           '<td><span class="LC_nobreak">'.$titles->{$item}.
                   5540:                           '</span></td><td class="LC_left_item" colspan="3">';
                   5541:             if ($item eq 'intauth_switch') {
                   5542:                 my @options = (0,1,2);
                   5543:                 my %optiondesc = &Apache::lonlocal::texthash (
                   5544:                                    0 => 'No',
                   5545:                                    1 => 'Yes',
                   5546:                                    2 => 'Yes, and copy existing passwd file to passwd.bak file',
                   5547:                                  );
                   5548:                 $datatable .= '<table width="100%">';
                   5549:                 foreach my $option (@options) {
                   5550:                     my $checked = ' ';
                   5551:                     if ($defaults{$item} eq $option) {
                   5552:                         $checked = ' checked="checked"';
                   5553:                     }
                   5554:                     $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
                   5555:                                   '<label><input type="radio" name="'.$item.
                   5556:                                   '" value="'.$option.'"'.$checked.' />'.
                   5557:                                   $optiondesc{$option}.'</label></span></td></tr>';
                   5558:                 }
                   5559:                 $datatable .= '</table>';
                   5560:             } elsif ($item eq 'intauth_check') {
                   5561:                 my @options = (0,1,2);
                   5562:                 my %optiondesc = &Apache::lonlocal::texthash (
                   5563:                                    0 => 'No',
                   5564:                                    1 => 'Yes, allow login then update passwd file using default cost (if higher)',
                   5565:                                    2 => 'Yes, disallow login if stored cost is less than domain default',
                   5566:                                  );
1.160.6.87  raeburn  5567:                 $datatable .= '<table width="100%">';
1.160.6.80  raeburn  5568:                 foreach my $option (@options) {
                   5569:                     my $checked = ' ';
                   5570:                     my $onclick;
                   5571:                     if ($defaults{$item} eq $option) {
                   5572:                         $checked = ' checked="checked"';
                   5573:                     }
                   5574:                     if ($option == 2) {
                   5575:                         $onclick = ' onclick="javascript:warnIntAuth(this);"';
                   5576:                     }
                   5577:                     $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
                   5578:                                   '<label><input type="radio" name="'.$item.
                   5579:                                   '" value="'.$option.'"'.$checked.$onclick.' />'.
                   5580:                                   $optiondesc{$option}.'</label></span></td></tr>';
                   5581:                 }
                   5582:                 $datatable .= '</table>';
                   5583:             } else {
                   5584:                 $datatable .= '<input type="text" name="'.$item.'" value="'.
                   5585:                               $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
                   5586:             }
                   5587:             $datatable .= '</td></tr>';
                   5588:             $rownum ++;
                   5589:         }
1.160.6.40  raeburn  5590:     } else {
1.160.6.80  raeburn  5591:         my %defaults;
1.160.6.40  raeburn  5592:         if (ref($settings) eq 'HASH') {
                   5593:             if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH') &&
                   5594:                 (ref($settings->{'inststatusguest'}) eq 'ARRAY')) {
                   5595:                 my $maxnum = @{$settings->{'inststatusorder'}};
                   5596:                 for (my $i=0; $i<$maxnum; $i++) {
                   5597:                     $css_class = $rownum%2?' class="LC_odd_row"':'';
                   5598:                     my $item = $settings->{'inststatusorder'}->[$i];
                   5599:                     my $title = $settings->{'inststatustypes'}->{$item};
                   5600:                     my $guestok;
                   5601:                     if (grep(/^\Q$item\E$/,@{$settings->{'inststatusguest'}})) {
                   5602:                         $guestok = 1;
                   5603:                     }
                   5604:                     my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
                   5605:                     $datatable .= '<tr'.$css_class.'>'.
                   5606:                                   '<td><span class="LC_nobreak">'.
                   5607:                                   '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
                   5608:                     for (my $k=0; $k<=$maxnum; $k++) {
                   5609:                         my $vpos = $k+1;
                   5610:                         my $selstr;
                   5611:                         if ($k == $i) {
                   5612:                             $selstr = ' selected="selected" ';
                   5613:                         }
                   5614:                         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   5615:                     }
                   5616:                     my ($checkedon,$checkedoff);
                   5617:                     $checkedoff = ' checked="checked"';
                   5618:                     if ($guestok) {
                   5619:                         $checkedon = $checkedoff;
                   5620:                         $checkedoff = ''; 
                   5621:                     }
                   5622:                     $datatable .= '</select>&nbsp;'.&mt('Internal ID:').'&nbsp;<b>'.$item.'</b>&nbsp;'.
                   5623:                                   '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
                   5624:                                   &mt('delete').'</span></td>'.
                   5625:                                   '<td class="LC_left_item"><span class="LC_nobreak">'.&mt('Name displayed:').
                   5626:                                   '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
                   5627:                                   '</span></td>'.
                   5628:                                   '<td class="LC_right_item"><span class="LC_nobreak">'.
                   5629:                                   '<label><input type="radio" value="1" name="inststatus_guest_'.$item.'"'.$checkedon.' />'.
                   5630:                                   &mt('Yes').'</label>'.('&nbsp;'x2).
                   5631:                                   '<label><input type="radio" value="0" name="inststatus_guest_'.$item.'"'.$checkedoff.' />'.
                   5632:                                   &mt('No').'</label></span></td></tr>';
                   5633:                 }
                   5634:                 $css_class = $rownum%2?' class="LC_odd_row"':'';
                   5635:                 my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
                   5636:                 $datatable .= '<tr '.$css_class.'>'.
                   5637:                               '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
                   5638:                 for (my $k=0; $k<=$maxnum; $k++) {
                   5639:                     my $vpos = $k+1;
                   5640:                     my $selstr;
                   5641:                     if ($k == $maxnum) {
                   5642:                         $selstr = ' selected="selected" ';
                   5643:                     }
                   5644:                     $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   5645:                 }
                   5646:                 $datatable .= '</select>&nbsp;'.&mt('Internal ID:').
1.160.6.63  raeburn  5647:                               '<input type="text" size="10" name="addinststatus" value="" />'.
1.160.6.40  raeburn  5648:                               '&nbsp;'.&mt('(new)').
                   5649:                               '</span></td><td class="LC_left_item"><span class="LC_nobreak">'.
                   5650:                               &mt('Name displayed:').
                   5651:                               '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
                   5652:                               '<td class="LC_right_item"><span class="LC_nobreak">'.
                   5653:                               '<label><input type="radio" value="1" name="addinststatus_guest" />'.
                   5654:                               &mt('Yes').'</label>'.('&nbsp;'x2).
                   5655:                               '<label><input type="radio" value="0" name="addinststatus_guest" />'.
                   5656:                               &mt('No').'</label></span></td></tr>';
                   5657:                               '</tr>'."\n";
                   5658:                 $rownum ++;
1.141     raeburn  5659:             }
1.43      raeburn  5660:         }
                   5661:     }
                   5662:     $$rowtotal += $rownum;
                   5663:     return $datatable;
                   5664: }
                   5665: 
1.160.6.5  raeburn  5666: sub get_languages_hash {
                   5667:     my %langchoices;
                   5668:     foreach my $id (&Apache::loncommon::languageids()) {
                   5669:         my $code = &Apache::loncommon::supportedlanguagecode($id);
                   5670:         if ($code ne '') {
                   5671:             $langchoices{$code} =  &Apache::loncommon::plainlanguagedescription($id);
                   5672:         }
                   5673:     }
                   5674:     return %langchoices;
                   5675: }
                   5676: 
1.43      raeburn  5677: sub defaults_titles {
1.141     raeburn  5678:     my ($dom) = @_;
1.43      raeburn  5679:     my %titles = &Apache::lonlocal::texthash (
                   5680:                    'auth_def'      => 'Default authentication type',
                   5681:                    'auth_arg_def'  => 'Default authentication argument',
                   5682:                    'lang_def'      => 'Default language',
1.54      raeburn  5683:                    'timezone_def'  => 'Default timezone',
1.68      raeburn  5684:                    'datelocale_def' => 'Default locale for dates',
1.141     raeburn  5685:                    'portal_def'     => 'Portal/Default URL',
1.160.6.80  raeburn  5686:                    'intauth_cost'   => 'Encryption cost for bcrypt (positive integer)',
                   5687:                    'intauth_check'  => 'Check bcrypt cost if authenticated',
                   5688:                    'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43      raeburn  5689:                  );
1.141     raeburn  5690:     if ($dom) {
                   5691:         my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
                   5692:         my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
                   5693:         my $protocol = $Apache::lonnet::protocol{$uprimary_id};
                   5694:         $protocol = 'http' if ($protocol ne 'https');
                   5695:         if ($uint_dom) {
                   5696:             $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
                   5697:                                          $uint_dom);
                   5698:         }
                   5699:     }
1.43      raeburn  5700:     return (\%titles);
                   5701: }
                   5702: 
1.46      raeburn  5703: sub print_scantronformat {
                   5704:     my ($r,$dom,$confname,$settings,$rowtotal) = @_;
                   5705:     my $itemcount = 1;
1.60      raeburn  5706:     my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
                   5707:         %confhash);
1.46      raeburn  5708:     my $switchserver = &check_switchserver($dom,$confname);
                   5709:     my %lt = &Apache::lonlocal::texthash (
1.95      www      5710:                 default => 'Default bubblesheet format file error',
                   5711:                 custom  => 'Custom bubblesheet format file error',
1.46      raeburn  5712:              );
                   5713:     my %scantronfiles = (
                   5714:         default => 'default.tab',
                   5715:         custom => 'custom.tab',
                   5716:     );
                   5717:     foreach my $key (keys(%scantronfiles)) {
                   5718:         $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
                   5719:                               .$scantronfiles{$key};
                   5720:     }
                   5721:     my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
                   5722:     if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
                   5723:         if (!$switchserver) {
                   5724:             my $servadm = $r->dir_config('lonAdmEMail');
                   5725:             my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
                   5726:             if ($configuserok eq 'ok') {
                   5727:                 if ($author_ok eq 'ok') {
                   5728:                     my %legacyfile = (
                   5729:  default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab', 
                   5730:  custom  => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab', 
                   5731:                     );
                   5732:                     my %md5chk;
                   5733:                     foreach my $type (keys(%legacyfile)) {
1.60      raeburn  5734:                         ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
                   5735:                         chomp($md5chk{$type});
1.46      raeburn  5736:                     }
                   5737:                     if ($md5chk{'default'} ne $md5chk{'custom'}) {
                   5738:                         foreach my $type (keys(%legacyfile)) {
1.60      raeburn  5739:                             ($scantronurls{$type},my $error) = 
1.46      raeburn  5740:                                 &legacy_scantronformat($r,$dom,$confname,
                   5741:                                                  $type,$legacyfile{$type},
                   5742:                                                  $scantronurls{$type},
                   5743:                                                  $scantronfiles{$type});
1.60      raeburn  5744:                             if ($error ne '') {
                   5745:                                 $error{$type} = $error;
                   5746:                             }
                   5747:                         }
                   5748:                         if (keys(%error) == 0) {
                   5749:                             $is_custom = 1;
                   5750:                             $confhash{'scantron'}{'scantronformat'} = 
                   5751:                                 $scantronurls{'custom'};
                   5752:                             my $putresult = 
                   5753:                                 &Apache::lonnet::put_dom('configuration',
                   5754:                                                          \%confhash,$dom);
                   5755:                             if ($putresult ne 'ok') {
                   5756:                                 $error{'custom'} = 
                   5757:                                     '<span class="LC_error">'.
                   5758:                                     &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
                   5759:                             }
1.46      raeburn  5760:                         }
                   5761:                     } else {
1.60      raeburn  5762:                         ($scantronurls{'default'},my $error) =
1.46      raeburn  5763:                             &legacy_scantronformat($r,$dom,$confname,
                   5764:                                           'default',$legacyfile{'default'},
                   5765:                                           $scantronurls{'default'},
                   5766:                                           $scantronfiles{'default'});
1.60      raeburn  5767:                         if ($error eq '') {
                   5768:                             $confhash{'scantron'}{'scantronformat'} = ''; 
                   5769:                             my $putresult =
                   5770:                                 &Apache::lonnet::put_dom('configuration',
                   5771:                                                          \%confhash,$dom);
                   5772:                             if ($putresult ne 'ok') {
                   5773:                                 $error{'default'} =
                   5774:                                     '<span class="LC_error">'.
                   5775:                                     &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
                   5776:                             }
                   5777:                         } else {
                   5778:                             $error{'default'} = $error;
                   5779:                         }
1.46      raeburn  5780:                     }
                   5781:                 }
                   5782:             }
                   5783:         } else {
1.95      www      5784:             $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46      raeburn  5785:         }
                   5786:     }
                   5787:     if (ref($settings) eq 'HASH') {
                   5788:         if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
                   5789:             my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
                   5790:             if ((!@info) || ($info[0] eq 'no_such_dir')) {
                   5791:                 $scantronurl = '';
                   5792:             } else {
                   5793:                 $scantronurl = $settings->{'scantronformat'};
                   5794:             }
                   5795:             $is_custom = 1;
                   5796:         } else {
                   5797:             $scantronurl = $scantronurls{'default'};
                   5798:         }
                   5799:     } else {
1.60      raeburn  5800:         if ($is_custom) {
                   5801:             $scantronurl = $scantronurls{'custom'};
                   5802:         } else {
                   5803:             $scantronurl = $scantronurls{'default'};
                   5804:         }
1.46      raeburn  5805:     }
                   5806:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   5807:     $datatable .= '<tr'.$css_class.'>';
                   5808:     if (!$is_custom) {
1.65      raeburn  5809:         $datatable .= '<td>'.&mt('Default in use:').'<br />'.
                   5810:                       '<span class="LC_nobreak">';
1.46      raeburn  5811:         if ($scantronurl) {
1.160.6.21  raeburn  5812:             $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
                   5813:                                                          undef,undef,undef,undef,'background-color:#ffffff');
1.46      raeburn  5814:         } else {
                   5815:             $datatable = &mt('File unavailable for display');
                   5816:         }
1.65      raeburn  5817:         $datatable .= '</span></td>';
1.60      raeburn  5818:         if (keys(%error) == 0) { 
                   5819:             $datatable .= '<td valign="bottom">';
                   5820:             if (!$switchserver) {
                   5821:                 $datatable .= &mt('Upload:').'<br />';
                   5822:             }
                   5823:         } else {
                   5824:             my $errorstr;
                   5825:             foreach my $key (sort(keys(%error))) {
                   5826:                 $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
                   5827:             }
                   5828:             $datatable .= '<td>'.$errorstr;
                   5829:         }
1.46      raeburn  5830:     } else {
                   5831:         if (keys(%error) > 0) {
                   5832:             my $errorstr;
                   5833:             foreach my $key (sort(keys(%error))) {
                   5834:                 $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
                   5835:             } 
1.60      raeburn  5836:             $datatable .= '<td>'.$errorstr.'</td><td>&nbsp;';
1.46      raeburn  5837:         } elsif ($scantronurl) {
1.160.6.26  raeburn  5838:             my $link =  &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
1.160.6.21  raeburn  5839:                                                        undef,undef,undef,undef,'background-color:#ffffff');
1.65      raeburn  5840:             $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.21  raeburn  5841:                           $link.
                   5842:                           '<label><input type="checkbox" name="scantronformat_del"'.
                   5843:                           ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65      raeburn  5844:                           '<td><span class="LC_nobreak">&nbsp;'.
                   5845:                           &mt('Replace:').'</span><br />';
1.46      raeburn  5846:         }
                   5847:     }
                   5848:     if (keys(%error) == 0) {
                   5849:         if ($switchserver) {
                   5850:             $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   5851:         } else {
1.65      raeburn  5852:             $datatable .='<span class="LC_nobreak">&nbsp;'.
                   5853:                          '<input type="file" name="scantronformat" /></span>';
1.46      raeburn  5854:         }
                   5855:     }
                   5856:     $datatable .= '</td></tr>';
                   5857:     $$rowtotal ++;
                   5858:     return $datatable;
                   5859: }
                   5860: 
                   5861: sub legacy_scantronformat {
                   5862:     my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
                   5863:     my ($url,$error);
                   5864:     my @statinfo = &Apache::lonnet::stat_file($newurl);
                   5865:     if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
                   5866:         (my $result,$url) =
                   5867:             &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
                   5868:                          '','',$newfile);
                   5869:         if ($result ne 'ok') {
1.130     raeburn  5870:             $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46      raeburn  5871:         }
                   5872:     }
                   5873:     return ($url,$error);
                   5874: }
1.43      raeburn  5875: 
1.49      raeburn  5876: sub print_coursecategories {
1.57      raeburn  5877:     my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
                   5878:     my $datatable;
                   5879:     if ($position eq 'top') {
1.160.6.42  raeburn  5880:         my (%checked);
                   5881:         my @catitems = ('unauth','auth');
                   5882:         my @cattypes = ('std','domonly','codesrch','none');
                   5883:         $checked{'unauth'} = 'std';
                   5884:         $checked{'auth'} = 'std';
                   5885:         if (ref($settings) eq 'HASH') {
                   5886:             foreach my $type (@cattypes) {
                   5887:                 if ($type eq $settings->{'unauth'}) {
                   5888:                     $checked{'unauth'} = $type;
                   5889:                 }
                   5890:                 if ($type eq $settings->{'auth'}) {
                   5891:                     $checked{'auth'} = $type;
                   5892:                 }
                   5893:             }
                   5894:         }
                   5895:         my %lt = &Apache::lonlocal::texthash (
                   5896:                                                unauth   => 'Catalog type for unauthenticated users',
                   5897:                                                auth     => 'Catalog type for authenticated users',
                   5898:                                                none     => 'No catalog',
                   5899:                                                std      => 'Standard catalog',
                   5900:                                                domonly  => 'Domain-only catalog',
                   5901:                                                codesrch => "Code search form",
                   5902:                                              );
                   5903:        my $itemcount = 0;
                   5904:        foreach my $item (@catitems) {
                   5905:            my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
                   5906:            $datatable .= '<tr '.$css_class.'>'.
                   5907:                          '<td>'.$lt{$item}.'</td>'.
                   5908:                          '<td class="LC_right_item"><span class="LC_nobreak">';
                   5909:            foreach my $type (@cattypes) {
                   5910:                my $ischecked;
                   5911:                if ($checked{$item} eq $type) {
                   5912:                    $ischecked=' checked="checked"';
                   5913:                }
                   5914:                $datatable .= '<label>'.
                   5915:                              '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
                   5916:                              ' />'.$lt{$type}.'</label>&nbsp;';
                   5917:            }
1.160.6.87  raeburn  5918:            $datatable .= '</span></td></tr>';
1.160.6.42  raeburn  5919:            $itemcount ++;
                   5920:         }
                   5921:         $$rowtotal += $itemcount;
                   5922:     } elsif ($position eq 'middle') {
1.57      raeburn  5923:         my $toggle_cats_crs = ' ';
                   5924:         my $toggle_cats_dom = ' checked="checked" ';
                   5925:         my $can_cat_crs = ' ';
                   5926:         my $can_cat_dom = ' checked="checked" ';
1.120     raeburn  5927:         my $toggle_catscomm_comm = ' ';
                   5928:         my $toggle_catscomm_dom = ' checked="checked" ';
                   5929:         my $can_catcomm_comm = ' ';
                   5930:         my $can_catcomm_dom = ' checked="checked" ';
                   5931: 
1.57      raeburn  5932:         if (ref($settings) eq 'HASH') {
                   5933:             if ($settings->{'togglecats'} eq 'crs') {
                   5934:                 $toggle_cats_crs = $toggle_cats_dom;
                   5935:                 $toggle_cats_dom = ' ';
                   5936:             }
                   5937:             if ($settings->{'categorize'} eq 'crs') {
                   5938:                 $can_cat_crs = $can_cat_dom;
                   5939:                 $can_cat_dom = ' ';
                   5940:             }
1.120     raeburn  5941:             if ($settings->{'togglecatscomm'} eq 'comm') {
                   5942:                 $toggle_catscomm_comm = $toggle_catscomm_dom;
                   5943:                 $toggle_catscomm_dom = ' ';
                   5944:             }
                   5945:             if ($settings->{'categorizecomm'} eq 'comm') {
                   5946:                 $can_catcomm_comm = $can_catcomm_dom;
                   5947:                 $can_catcomm_dom = ' ';
                   5948:             }
1.57      raeburn  5949:         }
                   5950:         my %title = &Apache::lonlocal::texthash (
1.120     raeburn  5951:                      togglecats     => 'Show/Hide a course in catalog',
                   5952:                      togglecatscomm => 'Show/Hide a community in catalog',
                   5953:                      categorize     => 'Assign a category to a course',
                   5954:                      categorizecomm => 'Assign a category to a community',
1.57      raeburn  5955:                     );
                   5956:         my %level = &Apache::lonlocal::texthash (
1.120     raeburn  5957:                      dom  => 'Set in Domain',
                   5958:                      crs  => 'Set in Course',
                   5959:                      comm => 'Set in Community',
1.57      raeburn  5960:                     );
                   5961:         $datatable = '<tr class="LC_odd_row">'.
                   5962:                   '<td>'.$title{'togglecats'}.'</td>'.
                   5963:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   5964:                   '<input type="radio" name="togglecats"'.
                   5965:                   $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   5966:                   '<label><input type="radio" name="togglecats"'.
                   5967:                   $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
                   5968:                   '</tr><tr>'.
                   5969:                   '<td>'.$title{'categorize'}.'</td>'.
                   5970:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
                   5971:                   '<label><input type="radio" name="categorize"'.
                   5972:                   $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   5973:                   '<label><input type="radio" name="categorize"'.
                   5974:                   $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120     raeburn  5975:                   '</tr><tr class="LC_odd_row">'.
                   5976:                   '<td>'.$title{'togglecatscomm'}.'</td>'.
                   5977:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   5978:                   '<input type="radio" name="togglecatscomm"'.
                   5979:                   $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   5980:                   '<label><input type="radio" name="togglecatscomm"'.
                   5981:                   $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
                   5982:                   '</tr><tr>'.
                   5983:                   '<td>'.$title{'categorizecomm'}.'</td>'.
                   5984:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
                   5985:                   '<label><input type="radio" name="categorizecomm"'.
                   5986:                   $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   5987:                   '<label><input type="radio" name="categorizecomm"'.
                   5988:                   $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57      raeburn  5989:                   '</tr>';
1.120     raeburn  5990:         $$rowtotal += 4;
1.57      raeburn  5991:     } else {
                   5992:         my $css_class;
                   5993:         my $itemcount = 1;
                   5994:         my $cathash; 
                   5995:         if (ref($settings) eq 'HASH') {
                   5996:             $cathash = $settings->{'cats'};
                   5997:         }
                   5998:         if (ref($cathash) eq 'HASH') {
                   5999:             my (@cats,@trails,%allitems,%idx,@jsarray);
                   6000:             &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
                   6001:                                                    \%allitems,\%idx,\@jsarray);
                   6002:             my $maxdepth = scalar(@cats);
                   6003:             my $colattrib = '';
                   6004:             if ($maxdepth > 2) {
                   6005:                 $colattrib = ' colspan="2" ';
                   6006:             }
                   6007:             my @path;
                   6008:             if (@cats > 0) {
                   6009:                 if (ref($cats[0]) eq 'ARRAY') {
                   6010:                     my $numtop = @{$cats[0]};
                   6011:                     my $maxnum = $numtop;
1.120     raeburn  6012:                     my %default_names = (
                   6013:                           instcode    => &mt('Official courses'),
                   6014:                           communities => &mt('Communities'),
                   6015:                     );
                   6016: 
                   6017:                     if ((!grep(/^instcode$/,@{$cats[0]})) || 
                   6018:                         ($cathash->{'instcode::0'} eq '') ||
                   6019:                         (!grep(/^communities$/,@{$cats[0]})) || 
                   6020:                         ($cathash->{'communities::0'} eq '')) {
1.57      raeburn  6021:                         $maxnum ++;
                   6022:                     }
                   6023:                     my $lastidx;
                   6024:                     for (my $i=0; $i<$numtop; $i++) {
                   6025:                         my $parent = $cats[0][$i];
                   6026:                         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   6027:                         my $item = &escape($parent).'::0';
                   6028:                         my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
                   6029:                         $lastidx = $idx{$item};
                   6030:                         $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
                   6031:                                       .'<select name="'.$item.'"'.$chgstr.'>';
                   6032:                         for (my $k=0; $k<=$maxnum; $k++) {
                   6033:                             my $vpos = $k+1;
                   6034:                             my $selstr;
                   6035:                             if ($k == $i) {
                   6036:                                 $selstr = ' selected="selected" ';
                   6037:                             }
                   6038:                             $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   6039:                         }
1.160.6.29  raeburn  6040:                         $datatable .= '</select></span></td><td>';
1.120     raeburn  6041:                         if ($parent eq 'instcode' || $parent eq 'communities') {
                   6042:                             $datatable .=  '<span class="LC_nobreak">'
                   6043:                                            .$default_names{$parent}.'</span>';
                   6044:                             if ($parent eq 'instcode') {
                   6045:                                 $datatable .= '<br /><span class="LC_nobreak">('
                   6046:                                               .&mt('with institutional codes')
                   6047:                                               .')</span></td><td'.$colattrib.'>';
                   6048:                             } else {
                   6049:                                 $datatable .= '<table><tr><td>';
                   6050:                             }
                   6051:                             $datatable .= '<span class="LC_nobreak">'
                   6052:                                           .'<label><input type="radio" name="'
                   6053:                                           .$parent.'" value="1" checked="checked" />'
                   6054:                                           .&mt('Display').'</label>';
                   6055:                             if ($parent eq 'instcode') {
                   6056:                                 $datatable .= '&nbsp;';
                   6057:                             } else {
                   6058:                                 $datatable .= '</span></td></tr><tr><td>'
                   6059:                                               .'<span class="LC_nobreak">';
                   6060:                             }
                   6061:                             $datatable .= '<label><input type="radio" name="'
                   6062:                                           .$parent.'" value="0" />'
                   6063:                                           .&mt('Do not display').'</label></span>';
                   6064:                             if ($parent eq 'communities') {
                   6065:                                 $datatable .= '</td></tr></table>';
                   6066:                             }
                   6067:                             $datatable .= '</td>';
1.57      raeburn  6068:                         } else {
                   6069:                             $datatable .= $parent
1.160.6.29  raeburn  6070:                                           .'&nbsp;<span class="LC_nobreak"><label>'
                   6071:                                           .'<input type="checkbox" name="deletecategory" '
1.57      raeburn  6072:                                           .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
                   6073:                         }
                   6074:                         my $depth = 1;
                   6075:                         push(@path,$parent);
                   6076:                         $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
                   6077:                         pop(@path);
                   6078:                         $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
                   6079:                         $itemcount ++;
                   6080:                     }
1.48      raeburn  6081:                     $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57      raeburn  6082:                     my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
                   6083:                     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48      raeburn  6084:                     for (my $k=0; $k<=$maxnum; $k++) {
                   6085:                         my $vpos = $k+1;
                   6086:                         my $selstr;
1.57      raeburn  6087:                         if ($k == $numtop) {
1.48      raeburn  6088:                             $selstr = ' selected="selected" ';
                   6089:                         }
                   6090:                         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   6091:                     }
1.59      bisitz   6092:                     $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').'&nbsp;'
1.57      raeburn  6093:                                   .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
                   6094:                                   .'</tr>'."\n";
1.48      raeburn  6095:                     $itemcount ++;
1.120     raeburn  6096:                     foreach my $default ('instcode','communities') {
                   6097:                         if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
                   6098:                             $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   6099:                             my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
                   6100:                             $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
                   6101:                                           '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
                   6102:                             for (my $k=0; $k<=$maxnum; $k++) {
                   6103:                                 my $vpos = $k+1;
                   6104:                                 my $selstr;
                   6105:                                 if ($k == $maxnum) {
                   6106:                                     $selstr = ' selected="selected" ';
                   6107:                                 }
                   6108:                                 $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57      raeburn  6109:                             }
1.120     raeburn  6110:                             $datatable .= '</select></span></td>'.
                   6111:                                           '<td><span class="LC_nobreak">'.
                   6112:                                           $default_names{$default}.'</span>';
                   6113:                             if ($default eq 'instcode') {
                   6114:                                 $datatable .= '<br /><span class="LC_nobreak">(' 
                   6115:                                               .&mt('with institutional codes').')</span>';
                   6116:                             }
                   6117:                             $datatable .= '</td>'
                   6118:                                           .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
                   6119:                                           .&mt('Display').'</label>&nbsp;'
                   6120:                                           .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
                   6121:                                           .&mt('Do not display').'</label></span></td></tr>';
1.48      raeburn  6122:                         }
                   6123:                     }
                   6124:                 }
1.57      raeburn  6125:             } else {
                   6126:                 $datatable .= &initialize_categories($itemcount);
1.48      raeburn  6127:             }
                   6128:         } else {
1.160.6.87  raeburn  6129:             $datatable .= '<tr><td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td></tr>'
1.57      raeburn  6130:                           .&initialize_categories($itemcount);
1.48      raeburn  6131:         }
1.57      raeburn  6132:         $$rowtotal += $itemcount;
1.48      raeburn  6133:     }
                   6134:     return $datatable;
                   6135: }
                   6136: 
1.69      raeburn  6137: sub print_serverstatuses {
                   6138:     my ($dom,$settings,$rowtotal) = @_;
                   6139:     my $datatable;
                   6140:     my @pages = &serverstatus_pages();
                   6141:     my (%namedaccess,%machineaccess);
                   6142:     foreach my $type (@pages) {
                   6143:         $namedaccess{$type} = '';
                   6144:         $machineaccess{$type}= '';
                   6145:     }
                   6146:     if (ref($settings) eq 'HASH') {
                   6147:         foreach my $type (@pages) {
                   6148:             if (exists($settings->{$type})) {
                   6149:                 if (ref($settings->{$type}) eq 'HASH') {
                   6150:                     foreach my $key (keys(%{$settings->{$type}})) {
                   6151:                         if ($key eq 'namedusers') {
                   6152:                             $namedaccess{$type} = $settings->{$type}->{$key};
                   6153:                         } elsif ($key eq 'machines') {
                   6154:                             $machineaccess{$type} = $settings->{$type}->{$key};
                   6155:                         }
                   6156:                     }
                   6157:                 }
                   6158:             }
                   6159:         }
                   6160:     }
1.81      raeburn  6161:     my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69      raeburn  6162:     my $rownum = 0;
                   6163:     my $css_class;
                   6164:     foreach my $type (@pages) {
                   6165:         $rownum ++;
                   6166:         $css_class = $rownum%2?' class="LC_odd_row"':'';
                   6167:         $datatable .= '<tr'.$css_class.'>'.
                   6168:                       '<td><span class="LC_nobreak">'.
                   6169:                       $titles->{$type}.'</span></td>'.
                   6170:                       '<td class="LC_left_item">'.
                   6171:                       '<input type="text" name="'.$type.'_namedusers" '.
                   6172:                       'value="'.$namedaccess{$type}.'" size="30" /></td>'.
                   6173:                       '<td class="LC_right_item">'.
                   6174:                       '<span class="LC_nobreak">'.
                   6175:                       '<input type="text" name="'.$type.'_machines" '.
                   6176:                       'value="'.$machineaccess{$type}.'" size="10" />'.
1.160.6.87  raeburn  6177:                       '</span></td></tr>'."\n";
1.69      raeburn  6178:     }
                   6179:     $$rowtotal += $rownum;
                   6180:     return $datatable;
                   6181: }
                   6182: 
                   6183: sub serverstatus_pages {
                   6184:     return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.160.6.15  raeburn  6185:             'checksums','clusterstatus','metadata_keywords','metadata_harvest',
1.160.6.31  raeburn  6186:             'takeoffline','takeonline','showenv','toggledebug','ping','domconf',
1.160.6.62  raeburn  6187:             'uniquecodes','diskusage','coursecatalog');
1.69      raeburn  6188: }
                   6189: 
1.160.6.40  raeburn  6190: sub defaults_javascript {
                   6191:     my ($settings) = @_;
1.160.6.80  raeburn  6192:     my $intauthcheck = &mt('Warning: disallowing login for an authenticated user if the stored cost is less than the default will require a password reset by/for the user.');
                   6193:     my $intauthcost = &mt('Warning: bcrypt encryption cost for internal authentication must be an integer.');
                   6194:     &js_escape(\$intauthcheck);
                   6195:     &js_escape(\$intauthcost);
                   6196:     my $intauthjs = <<"ENDSCRIPT";
                   6197: 
                   6198: function warnIntAuth(field) {
                   6199:     if (field.name == 'intauth_check') {
                   6200:         if (field.value == '2') {
                   6201:             alert('$intauthcheck');
                   6202:         }
                   6203:     }
                   6204:     if (field.name == 'intauth_cost') {
                   6205:         field.value.replace(/\s/g,'');
                   6206:         if (field.value != '') {
                   6207:             var regexdigit=/^\\d+\$/;
                   6208:             if (!regexdigit.test(field.value)) {
                   6209:                 alert('$intauthcost');
                   6210:             }
                   6211:         }
                   6212:     }
                   6213:     return;
                   6214: }
                   6215: 
                   6216: ENDSCRIPT
                   6217: 
                   6218:     if (ref($settings) ne 'HASH') {
                   6219:         return &Apache::lonhtmlcommon::scripttag($intauthjs);
                   6220:     }
1.160.6.40  raeburn  6221:     if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
                   6222:         my $maxnum = scalar(@{$settings->{'inststatusorder'}});
                   6223:         if ($maxnum eq '') {
                   6224:             $maxnum = 0;
                   6225:         }
                   6226:         $maxnum ++;
1.160.6.51  raeburn  6227:         my $jstext = '    var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';  
1.160.6.40  raeburn  6228:         return <<"ENDSCRIPT";
                   6229: <script type="text/javascript">
                   6230: // <![CDATA[
                   6231: function reorderTypes(form,caller) {
                   6232:     var changedVal;
                   6233: $jstext 
                   6234:     var newpos = 'addinststatus_pos';
                   6235:     var current = new Array;
                   6236:     var maxh = $maxnum;
                   6237:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
                   6238:     var oldVal;
                   6239:     if (caller == newpos) {
                   6240:         changedVal = newitemVal;
                   6241:     } else {
                   6242:         var curritem = 'inststatus_pos_'+caller;
                   6243:         changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
                   6244:         current[newitemVal] = newpos;
                   6245:     }
                   6246:     for (var i=0; i<inststatuses.length; i++) {
                   6247:         if (inststatuses[i] != caller) {
                   6248:             var elementName = 'inststatus_pos_'+inststatuses[i];
                   6249:             if (form.elements[elementName]) {
                   6250:                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   6251:                 current[currVal] = elementName;
                   6252:             }
                   6253:         }
                   6254:     }
                   6255:     for (var j=0; j<maxh; j++) {
                   6256:         if (current[j] == undefined) {
                   6257:             oldVal = j;
                   6258:         }
                   6259:     }
                   6260:     if (oldVal < changedVal) {
                   6261:         for (var k=oldVal+1; k<=changedVal ; k++) {
                   6262:            var elementName = current[k];
                   6263:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   6264:         }
                   6265:     } else {
                   6266:         for (var k=changedVal; k<oldVal; k++) {
                   6267:             var elementName = current[k];
                   6268:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   6269:         }
                   6270:     }
                   6271:     return;
                   6272: }
                   6273: 
1.160.6.80  raeburn  6274: $intauthjs
                   6275: 
1.160.6.40  raeburn  6276: // ]]>
                   6277: </script>
                   6278: 
                   6279: ENDSCRIPT
1.160.6.80  raeburn  6280:     } else {
                   6281:         return &Apache::lonhtmlcommon::scripttag($intauthjs);
1.160.6.40  raeburn  6282:     }
                   6283: }
                   6284: 
1.49      raeburn  6285: sub coursecategories_javascript {
                   6286:     my ($settings) = @_;
1.57      raeburn  6287:     my ($output,$jstext,$cathash);
1.49      raeburn  6288:     if (ref($settings) eq 'HASH') {
1.57      raeburn  6289:         $cathash = $settings->{'cats'};
                   6290:     }
                   6291:     if (ref($cathash) eq 'HASH') {
1.49      raeburn  6292:         my (@cats,@jsarray,%idx);
1.57      raeburn  6293:         &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49      raeburn  6294:         if (@jsarray > 0) {
                   6295:             $jstext = '    var categories = Array('.scalar(@jsarray).');'."\n";
                   6296:             for (my $i=0; $i<@jsarray; $i++) {
                   6297:                 if (ref($jsarray[$i]) eq 'ARRAY') {
                   6298:                     my $catstr = join('","',@{$jsarray[$i]});
                   6299:                     $jstext .= '    categories['.$i.'] = Array("'.$catstr.'");'."\n";
                   6300:                 }
                   6301:             }
                   6302:         }
                   6303:     } else {
                   6304:         $jstext  = '    var categories = Array(1);'."\n".
                   6305:                    '    categories[0] = Array("instcode_pos");'."\n"; 
                   6306:     }
1.160.6.42  raeburn  6307:     my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
                   6308:     my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.160.6.66  raeburn  6309:     my $choose_again = "\n".&mt('Please use a different name for the new top level category.'); 
                   6310:     &js_escape(\$instcode_reserved);
                   6311:     &js_escape(\$communities_reserved);
                   6312:     &js_escape(\$choose_again);
1.49      raeburn  6313:     $output = <<"ENDSCRIPT";
                   6314: <script type="text/javascript">
1.109     raeburn  6315: // <![CDATA[
1.49      raeburn  6316: function reorderCats(form,parent,item,idx) {
                   6317:     var changedVal;
                   6318: $jstext
                   6319:     var newpos = 'addcategory_pos';
                   6320:     if (parent == '') {
                   6321:         var has_instcode = 0;
                   6322:         var maxtop = categories[idx].length;
                   6323:         for (var j=0; j<maxtop; j++) {
                   6324:             if (categories[idx][j] == 'instcode::0') {
                   6325:                 has_instcode == 1;
                   6326:             }
                   6327:         }
                   6328:         if (has_instcode == 0) {
                   6329:             categories[idx][maxtop] = 'instcode_pos';
                   6330:         }
                   6331:     } else {
                   6332:         newpos += '_'+parent;
                   6333:     }
                   6334:     var maxh = 1 + categories[idx].length;
                   6335:     var current = new Array;
                   6336:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
                   6337:     if (item == newpos) {
                   6338:         changedVal = newitemVal;
                   6339:     } else {
                   6340:         changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
                   6341:         current[newitemVal] = newpos;
                   6342:     }
                   6343:     for (var i=0; i<categories[idx].length; i++) {
                   6344:         var elementName = categories[idx][i];
                   6345:         if (elementName != item) {
                   6346:             if (form.elements[elementName]) {
                   6347:                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   6348:                 current[currVal] = elementName;
                   6349:             }
                   6350:         }
                   6351:     }
                   6352:     var oldVal;
                   6353:     for (var j=0; j<maxh; j++) {
                   6354:         if (current[j] == undefined) {
                   6355:             oldVal = j;
                   6356:         }
                   6357:     }
                   6358:     if (oldVal < changedVal) {
                   6359:         for (var k=oldVal+1; k<=changedVal ; k++) {
                   6360:            var elementName = current[k];
                   6361:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   6362:         }
                   6363:     } else {
                   6364:         for (var k=changedVal; k<oldVal; k++) {
                   6365:             var elementName = current[k];
                   6366:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   6367:         }
                   6368:     }
                   6369:     return;
                   6370: }
1.120     raeburn  6371: 
                   6372: function categoryCheck(form) {
                   6373:     if (form.elements['addcategory_name'].value == 'instcode') {
                   6374:         alert('$instcode_reserved\\n$choose_again');
                   6375:         return false;
                   6376:     }
                   6377:     if (form.elements['addcategory_name'].value == 'communities') {
                   6378:         alert('$communities_reserved\\n$choose_again');
                   6379:         return false;
                   6380:     }
                   6381:     return true;
                   6382: }
                   6383: 
1.109     raeburn  6384: // ]]>
1.49      raeburn  6385: </script>
                   6386: 
                   6387: ENDSCRIPT
                   6388:     return $output;
                   6389: }
                   6390: 
1.48      raeburn  6391: sub initialize_categories {
                   6392:     my ($itemcount) = @_;
1.120     raeburn  6393:     my ($datatable,$css_class,$chgstr);
                   6394:     my %default_names = (
                   6395:                       instcode    => 'Official courses (with institutional codes)',
                   6396:                       communities => 'Communities',
                   6397:                         );
                   6398:     my $select0 = ' selected="selected"';
                   6399:     my $select1 = '';
                   6400:     foreach my $default ('instcode','communities') {
                   6401:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.87  raeburn  6402:         $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','0'".');"';
1.120     raeburn  6403:         if ($default eq 'communities') {
                   6404:             $select1 = $select0;
                   6405:             $select0 = '';
                   6406:         }
                   6407:         $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
                   6408:                      .'<select name="'.$default.'_pos">'
                   6409:                      .'<option value="0"'.$select0.'>1</option>'
                   6410:                      .'<option value="1"'.$select1.'>2</option>'
                   6411:                      .'<option value="2">3</option></select>&nbsp;'
                   6412:                      .$default_names{$default}
                   6413:                      .'</span></td><td><span class="LC_nobreak">'
                   6414:                      .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
                   6415:                      .&mt('Display').'</label>&nbsp;<label>'
                   6416:                      .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48      raeburn  6417:                  .'</label></span></td></tr>';
1.120     raeburn  6418:         $itemcount ++;
                   6419:     }
1.48      raeburn  6420:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49      raeburn  6421:     $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48      raeburn  6422:     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120     raeburn  6423:                   .'<select name="addcategory_pos"'.$chgstr.'>'
                   6424:                   .'<option value="0">1</option>'
                   6425:                   .'<option value="1">2</option>'
                   6426:                   .'<option value="2" selected="selected">3</option></select>&nbsp;'
1.160.6.87  raeburn  6427:                   .&mt('Add category').'</span></td><tda<span class="LC_nobreak">>'.&mt('Name:')
                   6428:                   .'&nbsp;<input type="text" size="20" name="addcategory_name" value="" /></span>'
                   6429:                   .'</td></tr>';
1.48      raeburn  6430:     return $datatable;
                   6431: }
                   6432: 
                   6433: sub build_category_rows {
1.49      raeburn  6434:     my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
                   6435:     my ($text,$name,$item,$chgstr);
1.48      raeburn  6436:     if (ref($cats) eq 'ARRAY') {
                   6437:         my $maxdepth = scalar(@{$cats});
                   6438:         if (ref($cats->[$depth]) eq 'HASH') {
                   6439:             if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
                   6440:                 my $numchildren = @{$cats->[$depth]{$parent}};
                   6441:                 my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.23  raeburn  6442:                 $text .= '<td><table class="LC_data_table">';
1.49      raeburn  6443:                 my ($idxnum,$parent_name,$parent_item);
                   6444:                 my $higher = $depth - 1;
                   6445:                 if ($higher == 0) {
                   6446:                     $parent_name = &escape($parent).'::'.$higher;
                   6447:                 } else {
                   6448:                     if (ref($path) eq 'ARRAY') {
                   6449:                         $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
                   6450:                     }
                   6451:                 }
                   6452:                 $parent_item = 'addcategory_pos_'.$parent_name;
1.48      raeburn  6453:                 for (my $j=0; $j<=$numchildren; $j++) {
1.49      raeburn  6454:                     if ($j < $numchildren) {
1.48      raeburn  6455:                         $name = $cats->[$depth]{$parent}[$j];
                   6456:                         $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49      raeburn  6457:                         $idxnum = $idx->{$item};
                   6458:                     } else {
                   6459:                         $name = $parent_name;
                   6460:                         $item = $parent_item;
1.48      raeburn  6461:                     }
1.49      raeburn  6462:                     $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
                   6463:                     $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48      raeburn  6464:                     for (my $i=0; $i<=$numchildren; $i++) {
                   6465:                         my $vpos = $i+1;
                   6466:                         my $selstr;
                   6467:                         if ($j == $i) {
                   6468:                             $selstr = ' selected="selected" ';
                   6469:                         }
                   6470:                         $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
                   6471:                     }
                   6472:                     $text .= '</select>&nbsp;';
                   6473:                     if ($j < $numchildren) {
                   6474:                         my $deeper = $depth+1;
                   6475:                         $text .= $name.'&nbsp;'
                   6476:                                  .'<label><input type="checkbox" name="deletecategory" value="'
                   6477:                                  .$item.'" />'.&mt('Delete').'</label></span></td><td>';
                   6478:                         if(ref($path) eq 'ARRAY') {
                   6479:                             push(@{$path},$name);
1.49      raeburn  6480:                             $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48      raeburn  6481:                             pop(@{$path});
                   6482:                         }
                   6483:                     } else {
1.160.6.87  raeburn  6484:                         $text .= &mt('Add subcategory:').'&nbsp;</span><input type="text" size="20" name="addcategory_name_';
1.48      raeburn  6485:                         if ($j == $numchildren) {
                   6486:                             $text .= $name;
                   6487:                         } else {
                   6488:                             $text .= $item;
                   6489:                         }
                   6490:                         $text .= '" value="" />';
                   6491:                     }
                   6492:                     $text .= '</td></tr>';
                   6493:                 }
                   6494:                 $text .= '</table></td>';
                   6495:             } else {
                   6496:                 my $higher = $depth-1;
                   6497:                 if ($higher == 0) {
                   6498:                     $name = &escape($parent).'::'.$higher;
                   6499:                 } else {
                   6500:                     if (ref($path) eq 'ARRAY') {
                   6501:                         $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
                   6502:                     }
                   6503:                 }
                   6504:                 my $colspan;
                   6505:                 if ($parent ne 'instcode') {
                   6506:                     $colspan = $maxdepth - $depth - 1;
1.160.6.87  raeburn  6507:                     $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="text" size="20" name="subcat_'.$name.'" value="" /></td>';
1.48      raeburn  6508:                 }
                   6509:             }
                   6510:         }
                   6511:     }
                   6512:     return $text;
                   6513: }
                   6514: 
1.33      raeburn  6515: sub modifiable_userdata_row {
1.160.6.35  raeburn  6516:     my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref) = @_;
                   6517:     my ($role,$rolename,$statustype);
                   6518:     $role = $item;
1.160.6.34  raeburn  6519:     if ($context eq 'cancreate') {
1.160.6.35  raeburn  6520:         if ($item =~ /^emailusername_(.+)$/) {
                   6521:             $statustype = $1;
                   6522:             $role = 'emailusername';
                   6523:             if (ref($usertypes) eq 'HASH') {
                   6524:                 if ($usertypes->{$statustype}) {
                   6525:                     $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
                   6526:                 } else {
                   6527:                     $rolename = &mt('Data provided by user');
                   6528:                 }
                   6529:             }
1.160.6.34  raeburn  6530:         }
                   6531:     } elsif ($context eq 'selfcreate') {
1.63      raeburn  6532:         if (ref($usertypes) eq 'HASH') {
                   6533:             $rolename = $usertypes->{$role};
                   6534:         } else {
                   6535:             $rolename = $role;
                   6536:         }
1.33      raeburn  6537:     } else {
1.63      raeburn  6538:         if ($role eq 'cr') {
                   6539:             $rolename = &mt('Custom role');
                   6540:         } else {
                   6541:             $rolename = &Apache::lonnet::plaintext($role);
                   6542:         }
1.33      raeburn  6543:     }
1.160.6.34  raeburn  6544:     my (@fields,%fieldtitles);
                   6545:     if (ref($fieldsref) eq 'ARRAY') {
                   6546:         @fields = @{$fieldsref};
                   6547:     } else {
                   6548:         @fields = ('lastname','firstname','middlename','generation',
                   6549:                    'permanentemail','id');
                   6550:     }
                   6551:     if ((ref($titlesref) eq 'HASH')) {
                   6552:         %fieldtitles = %{$titlesref};
                   6553:     } else {
                   6554:         %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
                   6555:     }
1.33      raeburn  6556:     my $output;
                   6557:     my $css_class = $rowcount%2?' class="LC_odd_row"':'';
                   6558:     $output = '<tr '.$css_class.'>'.
                   6559:               '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
                   6560:               '<td class="LC_left_item" colspan="2"><table>';
                   6561:     my $rem;
                   6562:     my %checks;
                   6563:     if (ref($settings) eq 'HASH') {
                   6564:         if (ref($settings->{$context}) eq 'HASH') {
                   6565:             if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.160.6.35  raeburn  6566:                 my $hashref = $settings->{$context}->{$role};
                   6567:                 if ($role eq 'emailusername') {
                   6568:                     if ($statustype) {
                   6569:                         if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
                   6570:                             $hashref = $settings->{$context}->{$role}->{$statustype};
1.160.6.39  raeburn  6571:                             if (ref($hashref) eq 'HASH') { 
1.160.6.35  raeburn  6572:                                 foreach my $field (@fields) {
                   6573:                                     if ($hashref->{$field}) {
                   6574:                                         $checks{$field} = $hashref->{$field};
                   6575:                                     }
                   6576:                                 }
                   6577:                             }
                   6578:                         }
                   6579:                     }
                   6580:                 } else {
                   6581:                     if (ref($hashref) eq 'HASH') {
                   6582:                         foreach my $field (@fields) {
                   6583:                             if ($hashref->{$field}) {
                   6584:                                 $checks{$field} = ' checked="checked" ';
                   6585:                             }
                   6586:                         }
1.33      raeburn  6587:                     }
                   6588:                 }
                   6589:             }
                   6590:         }
                   6591:     }
1.160.6.39  raeburn  6592:      
1.33      raeburn  6593:     for (my $i=0; $i<@fields; $i++) {
                   6594:         my $rem = $i%($numinrow);
                   6595:         if ($rem == 0) {
                   6596:             if ($i > 0) {
                   6597:                 $output .= '</tr>';
                   6598:             }
                   6599:             $output .= '<tr>';
                   6600:         }
                   6601:         my $check = ' ';
1.160.6.35  raeburn  6602:         unless ($role eq 'emailusername') {
                   6603:             if (exists($checks{$fields[$i]})) {
                   6604:                 $check = $checks{$fields[$i]}
                   6605:             } else {
                   6606:                 if ($role eq 'st') {
                   6607:                     if (ref($settings) ne 'HASH') {
1.160.6.39  raeburn  6608:                         $check = ' checked="checked" '; 
1.160.6.35  raeburn  6609:                     }
1.33      raeburn  6610:                 }
                   6611:             }
                   6612:         }
                   6613:         $output .= '<td class="LC_left_item">'.
1.160.6.35  raeburn  6614:                    '<span class="LC_nobreak">';
                   6615:         if ($role eq 'emailusername') {
                   6616:             unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
                   6617:                 $checks{$fields[$i]} = 'omit';
                   6618:             }
                   6619:             foreach my $option ('required','optional','omit') {
                   6620:                 my $checked='';
                   6621:                 if ($checks{$fields[$i]} eq $option) {
                   6622:                     $checked='checked="checked" ';
                   6623:                 }
                   6624:                 $output .= '<label>'.
                   6625:                            '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
                   6626:                            &mt($option).'</label>'.('&nbsp;' x2);
                   6627:             }
                   6628:             $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
                   6629:         } else {
                   6630:             $output .= '<label>'.
                   6631:                        '<input type="checkbox" name="canmodify_'.$role.'" '.
                   6632:                        'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
                   6633:                        '</label>';
                   6634:         }
                   6635:         $output .= '</span></td>';
1.33      raeburn  6636:         $rem = @fields%($numinrow);
                   6637:     }
                   6638:     my $colsleft = $numinrow - $rem;
                   6639:     if ($colsleft > 1 ) {
                   6640:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   6641:                    '&nbsp;</td>';
                   6642:     } elsif ($colsleft == 1) {
                   6643:         $output .= '<td class="LC_left_item">&nbsp;</td>';
                   6644:     }
                   6645:     $output .= '</tr></table></td></tr>';
                   6646:     return $output;
                   6647: }
1.28      raeburn  6648: 
1.93      raeburn  6649: sub insttypes_row {
1.160.6.34  raeburn  6650:     my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rownum) = @_;
1.93      raeburn  6651:     my %lt = &Apache::lonlocal::texthash (
                   6652:                       cansearch => 'Users allowed to search',
                   6653:                       statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131     raeburn  6654:                       lockablenames => 'User preference to lock name',
1.93      raeburn  6655:              );
                   6656:     my $showdom;
                   6657:     if ($context eq 'cansearch') {
                   6658:         $showdom = ' ('.$dom.')';
                   6659:     }
1.160.6.5  raeburn  6660:     my $class = 'LC_left_item';
                   6661:     if ($context eq 'statustocreate') {
                   6662:         $class = 'LC_right_item';
                   6663:     }
1.160.6.34  raeburn  6664:     my $css_class = ' class="LC_odd_row"';
                   6665:     if ($rownum ne '') { 
                   6666:         $css_class = ($rownum%2? ' class="LC_odd_row"':'');
                   6667:     }
                   6668:     my $output = '<tr'.$css_class.'>'.
                   6669:                  '<td>'.$lt{$context}.$showdom.
                   6670:                  '</td><td class="'.$class.'" colspan="2"><table>';
1.26      raeburn  6671:     my $rem;
                   6672:     if (ref($types) eq 'ARRAY') {
                   6673:         for (my $i=0; $i<@{$types}; $i++) {
                   6674:             if (defined($usertypes->{$types->[$i]})) {
                   6675:                 my $rem = $i%($numinrow);
                   6676:                 if ($rem == 0) {
                   6677:                     if ($i > 0) {
                   6678:                         $output .= '</tr>';
                   6679:                     }
                   6680:                     $output .= '<tr>';
1.23      raeburn  6681:                 }
1.26      raeburn  6682:                 my $check = ' ';
1.99      raeburn  6683:                 if (ref($settings) eq 'HASH') {
                   6684:                     if (ref($settings->{$context}) eq 'ARRAY') {
                   6685:                         if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
                   6686:                             $check = ' checked="checked" ';
                   6687:                         }
                   6688:                     } elsif ($context eq 'statustocreate') {
1.26      raeburn  6689:                         $check = ' checked="checked" ';
                   6690:                     }
1.23      raeburn  6691:                 }
1.26      raeburn  6692:                 $output .= '<td class="LC_left_item">'.
                   6693:                            '<span class="LC_nobreak"><label>'.
1.93      raeburn  6694:                            '<input type="checkbox" name="'.$context.'" '.
1.26      raeburn  6695:                            'value="'.$types->[$i].'"'.$check.'/>'.
                   6696:                            $usertypes->{$types->[$i]}.'</label></span></td>';
1.23      raeburn  6697:             }
                   6698:         }
1.26      raeburn  6699:         $rem = @{$types}%($numinrow);
1.23      raeburn  6700:     }
                   6701:     my $colsleft = $numinrow - $rem;
1.160.6.87  raeburn  6702:     if ($rem == 0) {
1.131     raeburn  6703:         $output .= '<tr>';
                   6704:     }
1.23      raeburn  6705:     if ($colsleft > 1) {
1.25      raeburn  6706:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23      raeburn  6707:     } else {
1.25      raeburn  6708:         $output .= '<td class="LC_left_item">';
1.23      raeburn  6709:     }
                   6710:     my $defcheck = ' ';
1.99      raeburn  6711:     if (ref($settings) eq 'HASH') {  
                   6712:         if (ref($settings->{$context}) eq 'ARRAY') {
                   6713:             if (grep(/^default$/,@{$settings->{$context}})) {
                   6714:                 $defcheck = ' checked="checked" ';
                   6715:             }
                   6716:         } elsif ($context eq 'statustocreate') {
1.26      raeburn  6717:             $defcheck = ' checked="checked" ';
                   6718:         }
1.23      raeburn  6719:     }
1.25      raeburn  6720:     $output .= '<span class="LC_nobreak"><label>'.
1.93      raeburn  6721:                '<input type="checkbox" name="'.$context.'" '.
1.25      raeburn  6722:                'value="default"'.$defcheck.'/>'.
                   6723:                $othertitle.'</label></span></td>'.
                   6724:                '</tr></table></td></tr>';
                   6725:     return $output;
1.23      raeburn  6726: }
                   6727: 
                   6728: sub sorted_searchtitles {
                   6729:     my %searchtitles = &Apache::lonlocal::texthash(
                   6730:                          'uname' => 'username',
                   6731:                          'lastname' => 'last name',
                   6732:                          'lastfirst' => 'last name, first name',
                   6733:                      );
                   6734:     my @titleorder = ('uname','lastname','lastfirst');
                   6735:     return (\%searchtitles,\@titleorder);
                   6736: }
                   6737: 
1.25      raeburn  6738: sub sorted_searchtypes {
                   6739:     my %srchtypes_desc = (
                   6740:                            exact    => 'is exact match',
                   6741:                            contains => 'contains ..',
                   6742:                            begins   => 'begins with ..',
                   6743:                          );
                   6744:     my @srchtypeorder = ('exact','begins','contains');
                   6745:     return (\%srchtypes_desc,\@srchtypeorder);
                   6746: }
                   6747: 
1.3       raeburn  6748: sub usertype_update_row {
                   6749:     my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
                   6750:     my $datatable;
                   6751:     my $numinrow = 4;
                   6752:     foreach my $type (@{$types}) {
                   6753:         if (defined($usertypes->{$type})) {
                   6754:             $$rownums ++;
                   6755:             my $css_class = $$rownums%2?' class="LC_odd_row"':'';
                   6756:             $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
                   6757:                           '</td><td class="LC_left_item"><table>';
                   6758:             for (my $i=0; $i<@{$fields}; $i++) {
                   6759:                 my $rem = $i%($numinrow);
                   6760:                 if ($rem == 0) {
                   6761:                     if ($i > 0) {
                   6762:                         $datatable .= '</tr>';
                   6763:                     }
                   6764:                     $datatable .= '<tr>';
                   6765:                 }
                   6766:                 my $check = ' ';
1.39      raeburn  6767:                 if (ref($settings) eq 'HASH') {
                   6768:                     if (ref($settings->{'fields'}) eq 'HASH') {
                   6769:                         if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
                   6770:                             if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
                   6771:                                 $check = ' checked="checked" ';
                   6772:                             }
1.3       raeburn  6773:                         }
                   6774:                     }
                   6775:                 }
                   6776: 
                   6777:                 if ($i == @{$fields}-1) {
                   6778:                     my $colsleft = $numinrow - $rem;
                   6779:                     if ($colsleft > 1) {
                   6780:                         $datatable .= '<td colspan="'.$colsleft.'">';
                   6781:                     } else {
                   6782:                         $datatable .= '<td>';
                   6783:                     }
                   6784:                 } else {
                   6785:                     $datatable .= '<td>';
                   6786:                 }
1.8       raeburn  6787:                 $datatable .= '<span class="LC_nobreak"><label>'.
                   6788:                               '<input type="checkbox" name="updateable_'.$type.
                   6789:                               '_'.$fields->[$i].'" value="1"'.$check.'/>'.
                   6790:                               $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3       raeburn  6791:             }
                   6792:             $datatable .= '</tr></table></td></tr>';
                   6793:         }
                   6794:     }
                   6795:     return $datatable;
1.1       raeburn  6796: }
                   6797: 
                   6798: sub modify_login {
1.160.6.24  raeburn  6799:     my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5  raeburn  6800:     my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
                   6801:         %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
                   6802:     %title = ( coursecatalog => 'Display course catalog',
                   6803:                adminmail => 'Display administrator E-mail address',
1.160.6.14  raeburn  6804:                helpdesk  => 'Display "Contact Helpdesk" link',
1.160.6.5  raeburn  6805:                newuser => 'Link for visitors to create a user account',
                   6806:                loginheader => 'Log-in box header');
                   6807:     @offon = ('off','on');
1.112     raeburn  6808:     if (ref($domconfig{login}) eq 'HASH') {
                   6809:         if (ref($domconfig{login}{loginvia}) eq 'HASH') {
                   6810:             foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
                   6811:                 $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
                   6812:             }
                   6813:         }
                   6814:     }
1.9       raeburn  6815:     ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
                   6816:                                            \%domconfig,\%loginhash);
1.160.6.14  raeburn  6817:     my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42      raeburn  6818:     foreach my $item (@toggles) {
                   6819:         $loginhash{login}{$item} = $env{'form.'.$item};
                   6820:     }
1.41      raeburn  6821:     $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6       raeburn  6822:     if (ref($colchanges{'login'}) eq 'HASH') {  
                   6823:         $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
                   6824:                                          \%loginhash);
                   6825:     }
1.110     raeburn  6826: 
1.149     raeburn  6827:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.56  raeburn  6828:     my %domservers = &Apache::lonnet::get_servers($dom);
1.128     raeburn  6829:     my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110     raeburn  6830:     if (keys(%servers) > 1) {
                   6831:         foreach my $lonhost (keys(%servers)) {
1.128     raeburn  6832:             next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
                   6833:             if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
                   6834:                 if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
                   6835:                     $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
                   6836:                 } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
                   6837:                     if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
                   6838:                         $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
                   6839:                         $changes{'loginvia'}{$lonhost} = 1;
                   6840:                     } else {
                   6841:                         $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
                   6842:                         $changes{'loginvia'}{$lonhost} = 1;
                   6843:                     }
                   6844:                 } else {
                   6845:                     if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
                   6846:                         $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
                   6847:                         $changes{'loginvia'}{$lonhost} = 1;
                   6848:                     }
                   6849:                 }
                   6850:                 if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
                   6851:                     foreach my $item (@loginvia_attribs) {
                   6852:                         $loginhash{login}{loginvia}{$lonhost}{$item} = '';
                   6853:                     }
                   6854:                 } else {
                   6855:                     foreach my $item (@loginvia_attribs) {
                   6856:                         my $new = $env{'form.'.$lonhost.'_'.$item};
                   6857:                         if (($item eq 'serverpath') && ($new eq 'custom')) {
                   6858:                             $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
                   6859:                             if ($env{'form.'.$lonhost.'_custompath'} eq '') {
                   6860:                                 $new = '/';
                   6861:                             }
                   6862:                         }
                   6863:                         if (($item eq 'custompath') && 
                   6864:                             ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
                   6865:                             $new = '';
                   6866:                         }
                   6867:                         if ($new ne $curr_loginvia{$lonhost}{$item}) {
                   6868:                             $changes{'loginvia'}{$lonhost} = 1;
                   6869:                         }
                   6870:                         if ($item eq 'exempt') {
1.160.6.56  raeburn  6871:                             $new = &check_exempt_addresses($new);
1.128     raeburn  6872:                         }
                   6873:                         $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
                   6874:                     }
                   6875:                 }
1.112     raeburn  6876:             } else {
1.128     raeburn  6877:                 if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
                   6878:                     $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112     raeburn  6879:                     $changes{'loginvia'}{$lonhost} = 1;
1.128     raeburn  6880:                     foreach my $item (@loginvia_attribs) {
                   6881:                         my $new = $env{'form.'.$lonhost.'_'.$item};
                   6882:                         if (($item eq 'serverpath') && ($new eq 'custom')) {
                   6883:                             if ($env{'form.'.$lonhost.'_custompath'} eq '') {
                   6884:                                 $new = '/';
                   6885:                             }
                   6886:                         }
                   6887:                         if (($item eq 'custompath') && 
                   6888:                             ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
                   6889:                             $new = '';
                   6890:                         }
                   6891:                         $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
                   6892:                     }
1.110     raeburn  6893:                 }
                   6894:             }
                   6895:         }
                   6896:     }
1.119     raeburn  6897: 
1.160.6.5  raeburn  6898:     my $servadm = $r->dir_config('lonAdmEMail');
                   6899:     my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
                   6900:     if (ref($domconfig{'login'}) eq 'HASH') {
                   6901:         if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
                   6902:             foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
                   6903:                 if ($lang eq 'nolang') {
                   6904:                     push(@currlangs,$lang);
                   6905:                 } elsif (defined($langchoices{$lang})) {
                   6906:                     push(@currlangs,$lang);
                   6907:                 } else {
                   6908:                     next;
                   6909:                 }
                   6910:             }
                   6911:         }
                   6912:     }
                   6913:     my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
                   6914:     if (@currlangs > 0) {
                   6915:         foreach my $lang (@currlangs) {
                   6916:             if (grep(/^\Q$lang\E$/,@delurls)) {
                   6917:                 $changes{'helpurl'}{$lang} = 1;
                   6918:             } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
                   6919:                 $changes{'helpurl'}{$lang} = 1;
                   6920:                 $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
                   6921:                 push(@newlangs,$lang);
                   6922:             } else {
                   6923:                 $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
                   6924:             }
                   6925:         }
                   6926:     }
                   6927:     unless (grep(/^nolang$/,@currlangs)) {
                   6928:         if ($env{'form.loginhelpurl_nolang.filename'}) {
                   6929:             $changes{'helpurl'}{'nolang'} = 1;
                   6930:             $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
                   6931:             push(@newlangs,'nolang');
                   6932:         }
                   6933:     }
                   6934:     if ($env{'form.loginhelpurl_add_lang'}) {
                   6935:         if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
                   6936:             ($env{'form.loginhelpurl_add_file.filename'})) {
                   6937:             $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
                   6938:             $addedfile = $env{'form.loginhelpurl_add_lang'};
                   6939:         }
                   6940:     }
                   6941:     if ((@newlangs > 0) || ($addedfile)) {
                   6942:         my $error;
                   6943:         my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
                   6944:         if ($configuserok eq 'ok') {
                   6945:             if ($switchserver) {
                   6946:                 $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
                   6947:             } elsif ($author_ok eq 'ok') {
                   6948:                 my @allnew = @newlangs;
                   6949:                 if ($addedfile ne '') {
                   6950:                     push(@allnew,$addedfile);
                   6951:                 }
                   6952:                 foreach my $lang (@allnew) {
                   6953:                     my $formelem = 'loginhelpurl_'.$lang;
                   6954:                     if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
                   6955:                         $formelem = 'loginhelpurl_add_file';
                   6956:                     }
                   6957:                     (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
                   6958:                                                                "help/$lang",'','',$newfile{$lang});
                   6959:                     if ($result eq 'ok') {
                   6960:                         $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
                   6961:                         $changes{'helpurl'}{$lang} = 1;
                   6962:                     } else {
                   6963:                         my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
                   6964:                         $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
                   6965:                         if ((grep(/^\Q$lang\E$/,@currlangs)) &&
                   6966:                             (!grep(/^\Q$lang\E$/,@delurls))) {
                   6967:                             $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
                   6968:                         }
                   6969:                     }
                   6970:                 }
                   6971:             } else {
                   6972:                 $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);
                   6973:             }
                   6974:         } else {
                   6975:             $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);
                   6976:         }
                   6977:         if ($error) {
                   6978:             &Apache::lonnet::logthis($error);
                   6979:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   6980:         }
                   6981:     }
1.160.6.56  raeburn  6982: 
                   6983:     my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
                   6984:     if (ref($domconfig{'login'}) eq 'HASH') {
                   6985:         if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
                   6986:             foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
                   6987:                 if ($domservers{$lonhost}) {
                   6988:                     if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
                   6989:                         $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.160.6.73  raeburn  6990:                         $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.160.6.56  raeburn  6991:                     }
                   6992:                 }
                   6993:             }
                   6994:         }
                   6995:     }
                   6996:     my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
                   6997:     foreach my $lonhost (sort(keys(%domservers))) {
                   6998:         if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
                   6999:             $changes{'headtag'}{$lonhost} = 1;
                   7000:         } else {
                   7001:             if ($env{'form.loginheadtagexempt_'.$lonhost}) {
                   7002:                 $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
                   7003:             }
                   7004:             if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
                   7005:                 push(@newhosts,$lonhost);
                   7006:             } elsif ($currheadtagurls{$lonhost}) {
                   7007:                 $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
                   7008:                 if ($currexempt{$lonhost}) {
                   7009:                     if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
                   7010:                         $changes{'headtag'}{$lonhost} = 1;
                   7011:                     }
                   7012:                 } elsif ($possexempt{$lonhost}) {
                   7013:                     $changes{'headtag'}{$lonhost} = 1;
                   7014:                 }
                   7015:                 if ($possexempt{$lonhost}) {
                   7016:                     $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
                   7017:                 }
                   7018:             }
                   7019:         }
                   7020:     }
                   7021:     if (@newhosts) {
                   7022:         my $error;
                   7023:         my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
                   7024:         if ($configuserok eq 'ok') {
                   7025:             if ($switchserver) {
                   7026:                 $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
                   7027:             } elsif ($author_ok eq 'ok') {
                   7028:                 foreach my $lonhost (@newhosts) {
                   7029:                     my $formelem = 'loginheadtag_'.$lonhost;
                   7030:                     (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
                   7031:                                                                           "login/headtag/$lonhost",'','',
                   7032:                                                                           $env{'form.loginheadtag_'.$lonhost.'.filename'});
                   7033:                     if ($result eq 'ok') {
                   7034:                         $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
                   7035:                         $changes{'headtag'}{$lonhost} = 1;
                   7036:                         if ($possexempt{$lonhost}) {
                   7037:                             $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
                   7038:                         }
                   7039:                     } else {
                   7040:                         my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
                   7041:                                            $newheadtagurls{$lonhost},$result);
                   7042:                         $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
                   7043:                         if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
                   7044:                             (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
                   7045:                             $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
                   7046:                         }
                   7047:                     }
                   7048:                 }
                   7049:             } else {
                   7050:                 $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);
                   7051:             }
                   7052:         } else {
                   7053:             $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);
                   7054:         }
                   7055:         if ($error) {
                   7056:             &Apache::lonnet::logthis($error);
                   7057:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   7058:         }
                   7059:     }
1.160.6.5  raeburn  7060:     &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
                   7061: 
                   7062:     my $defaulthelpfile = '/adm/loginproblems.html';
                   7063:     my $defaulttext = &mt('Default in use');
                   7064: 
1.1       raeburn  7065:     my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
                   7066:                                              $dom);
                   7067:     if ($putresult eq 'ok') {
1.160.6.14  raeburn  7068:         my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42      raeburn  7069:         my %defaultchecked = (
                   7070:                     'coursecatalog' => 'on',
1.160.6.14  raeburn  7071:                     'helpdesk'      => 'on',
1.42      raeburn  7072:                     'adminmail'     => 'off',
1.43      raeburn  7073:                     'newuser'       => 'off',
1.42      raeburn  7074:         );
1.55      raeburn  7075:         if (ref($domconfig{'login'}) eq 'HASH') {
                   7076:             foreach my $item (@toggles) {
                   7077:                 if ($defaultchecked{$item} eq 'on') { 
                   7078:                     if (($domconfig{'login'}{$item} eq '0') &&
                   7079:                         ($env{'form.'.$item} eq '1')) {
                   7080:                         $changes{$item} = 1;
                   7081:                     } elsif (($domconfig{'login'}{$item} eq '' ||
                   7082:                               $domconfig{'login'}{$item} eq '1') &&
                   7083:                              ($env{'form.'.$item} eq '0')) {
                   7084:                         $changes{$item} = 1;
                   7085:                     }
                   7086:                 } elsif ($defaultchecked{$item} eq 'off') {
                   7087:                     if (($domconfig{'login'}{$item} eq '1') &&
                   7088:                         ($env{'form.'.$item} eq '0')) {
                   7089:                         $changes{$item} = 1;
                   7090:                     } elsif (($domconfig{'login'}{$item} eq '' ||
                   7091:                               $domconfig{'login'}{$item} eq '0') &&
                   7092:                              ($env{'form.'.$item} eq '1')) {
                   7093:                         $changes{$item} = 1;
                   7094:                     }
1.42      raeburn  7095:                 }
                   7096:             }
1.41      raeburn  7097:         }
1.6       raeburn  7098:         if (keys(%changes) > 0 || $colchgtext) {
1.41      raeburn  7099:             &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27  raeburn  7100:             if (ref($lastactref) eq 'HASH') {
                   7101:                 $lastactref->{'domainconfig'} = 1;
                   7102:             }
1.1       raeburn  7103:             $resulttext = &mt('Changes made:').'<ul>';
                   7104:             foreach my $item (sort(keys(%changes))) {
1.135     bisitz   7105:                 if ($item eq 'loginvia') {
1.112     raeburn  7106:                     if (ref($changes{$item}) eq 'HASH') {
                   7107:                         $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
                   7108:                         foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128     raeburn  7109:                             if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
                   7110:                                 if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
                   7111:                                     my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
                   7112:                                     $protocol = 'http' if ($protocol ne 'https');
                   7113:                                     my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
                   7114: 
                   7115:                                     if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
                   7116:                                         $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
                   7117:                                     } else {
                   7118:                                         $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'}; 
                   7119:                                     }
                   7120:                                     $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
                   7121:                                     if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
                   7122:                                         $resulttext .= '&nbsp;'.&mt('No redirection for clients from following IPs:').'&nbsp;'.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
                   7123:                                     }
                   7124:                                     $resulttext .= '</li>';
                   7125:                                 } else {
                   7126:                                     $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
                   7127:                                 }
1.112     raeburn  7128:                             } else {
1.128     raeburn  7129:                                 $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112     raeburn  7130:                             }
                   7131:                         }
1.128     raeburn  7132:                         $resulttext .= '</ul></li>';
1.112     raeburn  7133:                     }
1.160.6.5  raeburn  7134:                 } elsif ($item eq 'helpurl') {
                   7135:                     if (ref($changes{$item}) eq 'HASH') {
                   7136:                         foreach my $lang (sort(keys(%{$changes{$item}}))) {
                   7137:                             if (grep(/^\Q$lang\E$/,@delurls)) {
                   7138:                                 my ($chg,$link);
                   7139:                                 $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
                   7140:                                 if ($lang eq 'nolang') {
                   7141:                                     $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
                   7142:                                 } else {
                   7143:                                     $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
                   7144:                                 }
                   7145:                                 $resulttext .= '<li>'.$chg.'</li>';
                   7146:                             } else {
                   7147:                                 my $chg;
                   7148:                                 if ($lang eq 'nolang') {
                   7149:                                     $chg = &mt('custom log-in help file for no preferred language');
                   7150:                                 } else {
                   7151:                                     $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
                   7152:                                 }
                   7153:                                 $resulttext .= '<li>'.&Apache::loncommon::modal_link(
                   7154:                                                       $loginhash{'login'}{'helpurl'}{$lang}.
                   7155:                                                       '?inhibitmenu=yes',$chg,600,500).
                   7156:                                                '</li>';
                   7157:                             }
                   7158:                         }
                   7159:                     }
1.160.6.56  raeburn  7160:                 } elsif ($item eq 'headtag') {
                   7161:                     if (ref($changes{$item}) eq 'HASH') {
                   7162:                         foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
                   7163:                             if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
                   7164:                                 $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
                   7165:                             } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
                   7166:                                 $resulttext .= '<li><a href="'.
                   7167:                                                "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
                   7168:                                                'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
                   7169:                                                '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
                   7170:                                 if ($possexempt{$lonhost}) {
                   7171:                                     $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
                   7172:                                 } else {
                   7173:                                     $resulttext .= &mt('included for any client IP');
                   7174:                                 }
                   7175:                                 $resulttext .= '</li>';
                   7176:                             }
                   7177:                         }
                   7178:                     }
1.160.6.5  raeburn  7179:                 } elsif ($item eq 'captcha') {
                   7180:                     if (ref($loginhash{'login'}) eq 'HASH') {
                   7181:                         my $chgtxt;
                   7182:                         if ($loginhash{'login'}{$item} eq 'notused') {
                   7183:                             $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
                   7184:                         } else {
                   7185:                             my %captchas = &captcha_phrases();
                   7186:                             if ($captchas{$loginhash{'login'}{$item}}) {
                   7187:                                 $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
                   7188:                             } else {
                   7189:                                 $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
                   7190:                             }
                   7191:                         }
                   7192:                         $resulttext .= '<li>'.$chgtxt.'</li>';
                   7193:                     }
                   7194:                 } elsif ($item eq 'recaptchakeys') {
                   7195:                     if (ref($loginhash{'login'}) eq 'HASH') {
                   7196:                         my ($privkey,$pubkey);
                   7197:                         if (ref($loginhash{'login'}{$item}) eq 'HASH') {
                   7198:                             $pubkey = $loginhash{'login'}{$item}{'public'};
                   7199:                             $privkey = $loginhash{'login'}{$item}{'private'};
                   7200:                         }
                   7201:                         my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
                   7202:                         if (!$pubkey) {
                   7203:                             $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
                   7204:                         } else {
                   7205:                             $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
                   7206:                         }
                   7207:                         if (!$privkey) {
                   7208:                             $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
                   7209:                         } else {
1.160.6.53  raeburn  7210:                             $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.160.6.5  raeburn  7211:                         }
                   7212:                         $chgtxt .= '</ul>';
                   7213:                         $resulttext .= '<li>'.$chgtxt.'</li>';
                   7214:                     }
1.160.6.69  raeburn  7215:                 } elsif ($item eq 'recaptchaversion') {
                   7216:                     if (ref($loginhash{'login'}) eq 'HASH') {
                   7217:                         if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
                   7218:                             $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
                   7219:                                            '</li>';
                   7220:                         }
                   7221:                     }
1.41      raeburn  7222:                 } else {
                   7223:                     $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
                   7224:                 }
1.1       raeburn  7225:             }
1.6       raeburn  7226:             $resulttext .= $colchgtext.'</ul>';
1.1       raeburn  7227:         } else {
                   7228:             $resulttext = &mt('No changes made to log-in page settings');
                   7229:         }
                   7230:     } else {
1.11      albertel 7231:         $resulttext = '<span class="LC_error">'.
                   7232: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  7233:     }
1.6       raeburn  7234:     if ($errors) {
1.9       raeburn  7235:         $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6       raeburn  7236:                        $errors.'</ul>';
                   7237:     }
                   7238:     return $resulttext;
                   7239: }
                   7240: 
1.160.6.56  raeburn  7241: sub check_exempt_addresses {
                   7242:     my ($iplist) = @_;
                   7243:     $iplist =~ s/^\s+//;
                   7244:     $iplist =~ s/\s+$//;
                   7245:     my @poss_ips = split(/\s*[,:]\s*/,$iplist);
                   7246:     my (@okips,$new);
                   7247:     foreach my $ip (@poss_ips) {
                   7248:         if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
                   7249:             if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
                   7250:                 push(@okips,$ip);
                   7251:             }
                   7252:         }
                   7253:     }
                   7254:     if (@okips > 0) {
                   7255:         $new = join(',',@okips);
                   7256:     } else {
                   7257:         $new = '';
                   7258:     }
                   7259:     return $new;
                   7260: }
                   7261: 
1.6       raeburn  7262: sub color_font_choices {
                   7263:     my %choices =
                   7264:         &Apache::lonlocal::texthash (
                   7265:             img => "Header",
                   7266:             bgs => "Background colors",
                   7267:             links => "Link colors",
1.55      raeburn  7268:             images => "Images",
1.6       raeburn  7269:             font => "Font color",
1.160.6.22  raeburn  7270:             fontmenu => "Font menu",
1.76      raeburn  7271:             pgbg => "Page",
1.6       raeburn  7272:             tabbg => "Header",
                   7273:             sidebg => "Border",
                   7274:             link => "Link",
                   7275:             alink => "Active link",
                   7276:             vlink => "Visited link",
                   7277:         );
                   7278:     return %choices;
                   7279: }
                   7280: 
                   7281: sub modify_rolecolors {
1.160.6.24  raeburn  7282:     my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6       raeburn  7283:     my ($resulttext,%rolehash);
                   7284:     $rolehash{'rolecolors'} = {};
1.55      raeburn  7285:     if (ref($domconfig{'rolecolors'}) ne 'HASH') {
                   7286:         if ($domconfig{'rolecolors'} eq '') {
                   7287:             $domconfig{'rolecolors'} = {};
                   7288:         }
                   7289:     }
1.9       raeburn  7290:     my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6       raeburn  7291:                          $domconfig{'rolecolors'},$rolehash{'rolecolors'});
                   7292:     my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
                   7293:                                              $dom);
                   7294:     if ($putresult eq 'ok') {
                   7295:         if (keys(%changes) > 0) {
1.41      raeburn  7296:             &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27  raeburn  7297:             if (ref($lastactref) eq 'HASH') {
                   7298:                 $lastactref->{'domainconfig'} = 1;
                   7299:             }
1.6       raeburn  7300:             $resulttext = &display_colorchgs($dom,\%changes,$roles,
                   7301:                                              $rolehash{'rolecolors'});
                   7302:         } else {
                   7303:             $resulttext = &mt('No changes made to default color schemes');
                   7304:         }
                   7305:     } else {
1.11      albertel 7306:         $resulttext = '<span class="LC_error">'.
                   7307: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.6       raeburn  7308:     }
                   7309:     if ($errors) {
                   7310:         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
                   7311:                        $errors.'</ul>';
                   7312:     }
                   7313:     return $resulttext;
                   7314: }
                   7315: 
                   7316: sub modify_colors {
1.9       raeburn  7317:     my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12      raeburn  7318:     my (%changes,%choices);
1.51      raeburn  7319:     my @bgs;
1.6       raeburn  7320:     my @links = ('link','alink','vlink');
1.41      raeburn  7321:     my @logintext;
1.6       raeburn  7322:     my @images;
                   7323:     my $servadm = $r->dir_config('lonAdmEMail');
                   7324:     my $errors;
1.160.6.22  raeburn  7325:     my %defaults;
1.6       raeburn  7326:     foreach my $role (@{$roles}) {
                   7327:         if ($role eq 'login') {
1.12      raeburn  7328:             %choices = &login_choices();
1.41      raeburn  7329:             @logintext = ('textcol','bgcol');
1.12      raeburn  7330:         } else {
                   7331:             %choices = &color_font_choices();
                   7332:         }
                   7333:         if ($role eq 'login') {
1.41      raeburn  7334:             @images = ('img','logo','domlogo','login');
1.51      raeburn  7335:             @bgs = ('pgbg','mainbg','sidebg');
1.6       raeburn  7336:         } else {
                   7337:             @images = ('img');
1.160.6.22  raeburn  7338:             @bgs = ('pgbg','tabbg','sidebg');
                   7339:         }
                   7340:         my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
                   7341:         unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
                   7342:             $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
                   7343:         }
                   7344:         if ($role eq 'login') {
                   7345:             foreach my $item (@logintext) {
1.160.6.39  raeburn  7346:                 $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
                   7347:                 if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
                   7348:                     $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
                   7349:                 }
                   7350:                 unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.160.6.22  raeburn  7351:                     $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
                   7352:                 }
                   7353:             }
                   7354:         } else {
1.160.6.39  raeburn  7355:             $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
                   7356:             if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
                   7357:                 $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
                   7358:             }
                   7359:             unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.160.6.22  raeburn  7360:                 $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
                   7361:             }
1.6       raeburn  7362:         }
1.160.6.22  raeburn  7363:         foreach my $item (@bgs) {
1.160.6.39  raeburn  7364:             $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
                   7365:             if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
                   7366:                 $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
                   7367:             }
                   7368:             unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.160.6.22  raeburn  7369:                 $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
                   7370:             }
                   7371:         }
                   7372:         foreach my $item (@links) {
1.160.6.39  raeburn  7373:             $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
                   7374:             if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
                   7375:                 $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
                   7376:             }
                   7377:             unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.160.6.22  raeburn  7378:                 $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
                   7379:             }
1.6       raeburn  7380:         }
1.46      raeburn  7381:         my ($configuserok,$author_ok,$switchserver) = 
                   7382:             &config_check($dom,$confname,$servadm);
1.9       raeburn  7383:         my ($width,$height) = &thumb_dimensions();
1.40      raeburn  7384:         if (ref($domconfig->{$role}) ne 'HASH') {
                   7385:             $domconfig->{$role} = {};
                   7386:         }
1.8       raeburn  7387:         foreach my $img (@images) {
1.70      raeburn  7388:             if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {  
                   7389:                 if (defined($env{'form.login_showlogo_'.$img})) {
                   7390:                     $confhash->{$role}{'showlogo'}{$img} = 1;
                   7391:                 } else { 
                   7392:                     $confhash->{$role}{'showlogo'}{$img} = 0;
                   7393:                 }
                   7394:             } 
1.18      albertel 7395: 	    if ( ! $env{'form.'.$role.'_'.$img.'.filename'} 
                   7396: 		 && !defined($domconfig->{$role}{$img})
                   7397: 		 && !$env{'form.'.$role.'_del_'.$img}
                   7398: 		 && $env{'form.'.$role.'_import_'.$img}) {
                   7399: 		# import the old configured image from the .tab setting
                   7400: 		# if they haven't provided a new one 
                   7401: 		$domconfig->{$role}{$img} = 
                   7402: 		    $env{'form.'.$role.'_import_'.$img};
                   7403: 	    }
1.6       raeburn  7404:             if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9       raeburn  7405:                 my $error;
1.6       raeburn  7406:                 if ($configuserok eq 'ok') {
1.9       raeburn  7407:                     if ($switchserver) {
1.12      raeburn  7408:                         $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9       raeburn  7409:                     } else {
                   7410:                         if ($author_ok eq 'ok') {
                   7411:                             my ($result,$logourl) = 
                   7412:                                 &publishlogo($r,'upload',$role.'_'.$img,
                   7413:                                            $dom,$confname,$img,$width,$height);
                   7414:                             if ($result eq 'ok') {
                   7415:                                 $confhash->{$role}{$img} = $logourl;
1.12      raeburn  7416:                                 $changes{$role}{'images'}{$img} = 1;
1.9       raeburn  7417:                             } else {
1.12      raeburn  7418:                                 $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  7419:                             }
                   7420:                         } else {
1.46      raeburn  7421:                             $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  7422:                         }
                   7423:                     }
                   7424:                 } else {
1.46      raeburn  7425:                     $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  7426:                 }
                   7427:                 if ($error) {
1.8       raeburn  7428:                     &Apache::lonnet::logthis($error);
1.11      albertel 7429:                     $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8       raeburn  7430:                 }
                   7431:             } elsif ($domconfig->{$role}{$img} ne '') {
1.9       raeburn  7432:                 if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
                   7433:                     my $error;
                   7434:                     if ($configuserok eq 'ok') {
                   7435: # is confname an author?
                   7436:                         if ($switchserver eq '') {
                   7437:                             if ($author_ok eq 'ok') {
                   7438:                                 my ($result,$logourl) = 
                   7439:                                &publishlogo($r,'copy',$domconfig->{$role}{$img},
                   7440:                                             $dom,$confname,$img,$width,$height);
                   7441:                                 if ($result eq 'ok') {
                   7442:                                     $confhash->{$role}{$img} = $logourl;
1.18      albertel 7443: 				    $changes{$role}{'images'}{$img} = 1;
1.9       raeburn  7444:                                 }
                   7445:                             }
                   7446:                         }
                   7447:                     }
1.6       raeburn  7448:                 }
                   7449:             }
                   7450:         }
                   7451:         if (ref($domconfig) eq 'HASH') {
                   7452:             if (ref($domconfig->{$role}) eq 'HASH') {
                   7453:                 foreach my $img (@images) {
                   7454:                     if ($domconfig->{$role}{$img} ne '') {
                   7455:                         if ($env{'form.'.$role.'_del_'.$img}) {
                   7456:                             $confhash->{$role}{$img} = '';
1.12      raeburn  7457:                             $changes{$role}{'images'}{$img} = 1;
1.6       raeburn  7458:                         } else {
1.9       raeburn  7459:                             if ($confhash->{$role}{$img} eq '') {
                   7460:                                 $confhash->{$role}{$img} = $domconfig->{$role}{$img};
                   7461:                             }
1.6       raeburn  7462:                         }
                   7463:                     } else {
                   7464:                         if ($env{'form.'.$role.'_del_'.$img}) {
                   7465:                             $confhash->{$role}{$img} = '';
1.12      raeburn  7466:                             $changes{$role}{'images'}{$img} = 1;
1.6       raeburn  7467:                         } 
                   7468:                     }
1.70      raeburn  7469:                     if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
                   7470:                         if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
                   7471:                             if ($confhash->{$role}{'showlogo'}{$img} ne 
                   7472:                                 $domconfig->{$role}{'showlogo'}{$img}) {
                   7473:                                 $changes{$role}{'showlogo'}{$img} = 1; 
                   7474:                             }
                   7475:                         } else {
                   7476:                             if ($confhash->{$role}{'showlogo'}{$img} == 0) {
                   7477:                                 $changes{$role}{'showlogo'}{$img} = 1;
                   7478:                             }
                   7479:                         }
                   7480:                     }
                   7481:                 }
1.6       raeburn  7482:                 if ($domconfig->{$role}{'font'} ne '') {
                   7483:                     if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
                   7484:                         $changes{$role}{'font'} = 1;
                   7485:                     }
                   7486:                 } else {
                   7487:                     if ($confhash->{$role}{'font'}) {
                   7488:                         $changes{$role}{'font'} = 1;
                   7489:                     }
                   7490:                 }
1.107     raeburn  7491:                 if ($role ne 'login') {
                   7492:                     if ($domconfig->{$role}{'fontmenu'} ne '') {
                   7493:                         if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
                   7494:                             $changes{$role}{'fontmenu'} = 1;
                   7495:                         }
                   7496:                     } else {
                   7497:                         if ($confhash->{$role}{'fontmenu'}) {
                   7498:                             $changes{$role}{'fontmenu'} = 1;
                   7499:                         }
1.97      tempelho 7500:                     }
                   7501:                 }
1.6       raeburn  7502:                 foreach my $item (@bgs) {
                   7503:                     if ($domconfig->{$role}{$item} ne '') {
                   7504:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
                   7505:                             $changes{$role}{'bgs'}{$item} = 1;
                   7506:                         } 
                   7507:                     } else {
                   7508:                         if ($confhash->{$role}{$item}) {
                   7509:                             $changes{$role}{'bgs'}{$item} = 1;
                   7510:                         }
                   7511:                     }
                   7512:                 }
                   7513:                 foreach my $item (@links) {
                   7514:                     if ($domconfig->{$role}{$item} ne '') {
                   7515:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
                   7516:                             $changes{$role}{'links'}{$item} = 1;
                   7517:                         }
                   7518:                     } else {
                   7519:                         if ($confhash->{$role}{$item}) {
                   7520:                             $changes{$role}{'links'}{$item} = 1;
                   7521:                         }
                   7522:                     }
                   7523:                 }
1.41      raeburn  7524:                 foreach my $item (@logintext) {
                   7525:                     if ($domconfig->{$role}{$item} ne '') {
                   7526:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
                   7527:                             $changes{$role}{'logintext'}{$item} = 1;
                   7528:                         }
                   7529:                     } else {
                   7530:                         if ($confhash->{$role}{$item}) {
                   7531:                             $changes{$role}{'logintext'}{$item} = 1;
                   7532:                         }
                   7533:                     }
                   7534:                 }
1.6       raeburn  7535:             } else {
                   7536:                 &default_change_checker($role,\@images,\@links,\@bgs,
1.41      raeburn  7537:                                         \@logintext,$confhash,\%changes); 
1.6       raeburn  7538:             }
                   7539:         } else {
                   7540:             &default_change_checker($role,\@images,\@links,\@bgs,
1.41      raeburn  7541:                                     \@logintext,$confhash,\%changes); 
1.6       raeburn  7542:         }
                   7543:     }
                   7544:     return ($errors,%changes);
                   7545: }
                   7546: 
1.46      raeburn  7547: sub config_check {
                   7548:     my ($dom,$confname,$servadm) = @_;
                   7549:     my ($configuserok,$author_ok,$switchserver,%currroles);
                   7550:     my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
                   7551:     ($configuserok,%currroles) = &check_configuser($uhome,$dom,
                   7552:                                                    $confname,$servadm);
                   7553:     if ($configuserok eq 'ok') {
                   7554:         $switchserver = &check_switchserver($dom,$confname);
                   7555:         if ($switchserver eq '') {
                   7556:             $author_ok = &check_authorstatus($dom,$confname,%currroles);
                   7557:         }
                   7558:     }
                   7559:     return ($configuserok,$author_ok,$switchserver);
                   7560: }
                   7561: 
1.6       raeburn  7562: sub default_change_checker {
1.41      raeburn  7563:     my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6       raeburn  7564:     foreach my $item (@{$links}) {
                   7565:         if ($confhash->{$role}{$item}) {
                   7566:             $changes->{$role}{'links'}{$item} = 1;
                   7567:         }
                   7568:     }
                   7569:     foreach my $item (@{$bgs}) {
                   7570:         if ($confhash->{$role}{$item}) {
                   7571:             $changes->{$role}{'bgs'}{$item} = 1;
                   7572:         }
                   7573:     }
1.41      raeburn  7574:     foreach my $item (@{$logintext}) {
                   7575:         if ($confhash->{$role}{$item}) {
                   7576:             $changes->{$role}{'logintext'}{$item} = 1;
                   7577:         }
                   7578:     }
1.6       raeburn  7579:     foreach my $img (@{$images}) {
                   7580:         if ($env{'form.'.$role.'_del_'.$img}) {
                   7581:             $confhash->{$role}{$img} = '';
1.12      raeburn  7582:             $changes->{$role}{'images'}{$img} = 1;
1.6       raeburn  7583:         }
1.70      raeburn  7584:         if ($role eq 'login') {
                   7585:             if ($confhash->{$role}{'showlogo'}{$img} == 0) {
                   7586:                 $changes->{$role}{'showlogo'}{$img} = 1;
                   7587:             }
                   7588:         }
1.6       raeburn  7589:     }
                   7590:     if ($confhash->{$role}{'font'}) {
                   7591:         $changes->{$role}{'font'} = 1;
                   7592:     }
1.48      raeburn  7593: }
1.6       raeburn  7594: 
                   7595: sub display_colorchgs {
                   7596:     my ($dom,$changes,$roles,$confhash) = @_;
                   7597:     my (%choices,$resulttext);
                   7598:     if (!grep(/^login$/,@{$roles})) {
                   7599:         $resulttext = &mt('Changes made:').'<br />';
                   7600:     }
                   7601:     foreach my $role (@{$roles}) {
                   7602:         if ($role eq 'login') {
                   7603:             %choices = &login_choices();
                   7604:         } else {
                   7605:             %choices = &color_font_choices();
                   7606:         }
                   7607:         if (ref($changes->{$role}) eq 'HASH') {
                   7608:             if ($role ne 'login') {
                   7609:                 $resulttext .= '<h4>'.&mt($role).'</h4>';
                   7610:             }
                   7611:             foreach my $key (sort(keys(%{$changes->{$role}}))) {
                   7612:                 if ($role ne 'login') {
                   7613:                     $resulttext .= '<ul>';
                   7614:                 }
                   7615:                 if (ref($changes->{$role}{$key}) eq 'HASH') {
                   7616:                     if ($role ne 'login') {
                   7617:                         $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
                   7618:                     }
                   7619:                     foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70      raeburn  7620:                         if (($role eq 'login') && ($key eq 'showlogo')) {
                   7621:                             if ($confhash->{$role}{$key}{$item}) {
                   7622:                                 $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
                   7623:                             } else {
                   7624:                                 $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
                   7625:                             }
                   7626:                         } elsif ($confhash->{$role}{$item} eq '') {
1.6       raeburn  7627:                             $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
                   7628:                         } else {
1.12      raeburn  7629:                             my $newitem = $confhash->{$role}{$item};
                   7630:                             if ($key eq 'images') {
                   7631:                                 $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
                   7632:                             }
                   7633:                             $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6       raeburn  7634:                         }
                   7635:                     }
                   7636:                     if ($role ne 'login') {
                   7637:                         $resulttext .= '</ul></li>';
                   7638:                     }
                   7639:                 } else {
                   7640:                     if ($confhash->{$role}{$key} eq '') {
                   7641:                         $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
                   7642:                     } else {
                   7643:                         $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
                   7644:                     }
                   7645:                 }
                   7646:                 if ($role ne 'login') {
                   7647:                     $resulttext .= '</ul>';
                   7648:                 }
                   7649:             }
                   7650:         }
                   7651:     }
1.3       raeburn  7652:     return $resulttext;
1.1       raeburn  7653: }
                   7654: 
1.9       raeburn  7655: sub thumb_dimensions {
                   7656:     return ('200','50');
                   7657: }
                   7658: 
1.16      raeburn  7659: sub check_dimensions {
                   7660:     my ($inputfile) = @_;
                   7661:     my ($fullwidth,$fullheight);
                   7662:     if ($inputfile =~ m|^[/\w.\-]+$|) {
                   7663:         if (open(PIPE,"identify $inputfile 2>&1 |")) {
                   7664:             my $imageinfo = <PIPE>;
                   7665:             if (!close(PIPE)) {
                   7666:                 &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
                   7667:             }
                   7668:             chomp($imageinfo);
                   7669:             my ($fullsize) = 
1.21      raeburn  7670:                 ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16      raeburn  7671:             if ($fullsize) {
                   7672:                 ($fullwidth,$fullheight) = split(/x/,$fullsize);
                   7673:             }
                   7674:         }
                   7675:     }
                   7676:     return ($fullwidth,$fullheight);
                   7677: }
                   7678: 
1.9       raeburn  7679: sub check_configuser {
                   7680:     my ($uhome,$dom,$confname,$servadm) = @_;
                   7681:     my ($configuserok,%currroles);
                   7682:     if ($uhome eq 'no_host') {
                   7683:         srand( time() ^ ($$ + ($$ << 15))  ); # Seed rand.
                   7684:         my $configpass = &LONCAPA::Enrollment::create_password();
                   7685:         $configuserok = 
                   7686:             &Apache::lonnet::modifyuser($dom,$confname,'','internal',
                   7687:                              $configpass,'','','','','',undef,$servadm);
                   7688:     } else {
                   7689:         $configuserok = 'ok';
                   7690:         %currroles = 
                   7691:             &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
                   7692:     }
                   7693:     return ($configuserok,%currroles);
                   7694: }
                   7695: 
                   7696: sub check_authorstatus {
                   7697:     my ($dom,$confname,%currroles) = @_;
                   7698:     my $author_ok;
1.40      raeburn  7699:     if (!$currroles{':'.$dom.':au'}) {
1.9       raeburn  7700:         my $start = time;
                   7701:         my $end = 0;
                   7702:         $author_ok = 
                   7703:             &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47      raeburn  7704:                                         'au',$end,$start,'','','domconfig');
1.9       raeburn  7705:     } else {
                   7706:         $author_ok = 'ok';
                   7707:     }
                   7708:     return $author_ok;
                   7709: }
                   7710: 
                   7711: sub publishlogo {
1.46      raeburn  7712:     my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9       raeburn  7713:     my ($output,$fname,$logourl);
                   7714:     if ($action eq 'upload') {
                   7715:         $fname=$env{'form.'.$formname.'.filename'};
                   7716:         chop($env{'form.'.$formname});
                   7717:     } else {
                   7718:         ($fname) = ($formname =~ /([^\/]+)$/);
                   7719:     }
1.46      raeburn  7720:     if ($savefileas ne '') {
                   7721:         $fname = $savefileas;
                   7722:     }
1.9       raeburn  7723:     $fname=&Apache::lonnet::clean_filename($fname);
                   7724: # See if there is anything left
                   7725:     unless ($fname) { return ('error: no uploaded file'); }
                   7726:     $fname="$subdir/$fname";
1.160.6.5  raeburn  7727:     my $docroot=$r->dir_config('lonDocRoot');
                   7728:     my $filepath="$docroot/priv";
                   7729:     my $relpath = "$dom/$confname";
1.9       raeburn  7730:     my ($fnamepath,$file,$fetchthumb);
                   7731:     $file=$fname;
                   7732:     if ($fname=~m|/|) {
                   7733:         ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
                   7734:     }
1.160.6.26  raeburn  7735:     my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9       raeburn  7736:     my $count;
1.160.6.5  raeburn  7737:     for ($count=5;$count<=$#parts;$count++) {
1.9       raeburn  7738:         $filepath.="/$parts[$count]";
                   7739:         if ((-e $filepath)!=1) {
                   7740:             mkdir($filepath,02770);
                   7741:         }
                   7742:     }
                   7743:     # Check for bad extension and disallow upload
                   7744:     if ($file=~/\.(\w+)$/ &&
                   7745:         (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
                   7746:         $output = 
1.160.6.25  raeburn  7747:             &mt('Invalid file extension ([_1]) - reserved for internal use.',$1); 
1.9       raeburn  7748:     } elsif ($file=~/\.(\w+)$/ &&
                   7749:         !defined(&Apache::loncommon::fileembstyle($1))) {
                   7750:         $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
                   7751:     } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.160.6.18  raeburn  7752:         $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  7753:     } elsif (-d "$filepath/$file") {
1.160.6.18  raeburn  7754:         $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9       raeburn  7755:     } else {
                   7756:         my $source = $filepath.'/'.$file;
                   7757:         my $logfile;
1.160.6.88  raeburn  7758:         if (!open($logfile,">>",$source.'.log')) {
1.160.6.19  raeburn  7759:             return (&mt('No write permission to Authoring Space'));
1.9       raeburn  7760:         }
                   7761:         print $logfile
                   7762: "\n================= Publish ".localtime()." ================\n".
                   7763: $env{'user.name'}.':'.$env{'user.domain'}."\n";
                   7764: # Save the file
1.160.6.88  raeburn  7765:         if (!open(FH,">",$source)) {
1.9       raeburn  7766:             &Apache::lonnet::logthis('Failed to create '.$source);
                   7767:             return (&mt('Failed to create file'));
                   7768:         }
                   7769:         if ($action eq 'upload') {
                   7770:             if (!print FH ($env{'form.'.$formname})) {
                   7771:                 &Apache::lonnet::logthis('Failed to write to '.$source);
                   7772:                 return (&mt('Failed to write file'));
                   7773:             }
                   7774:         } else {
                   7775:             my $original = &Apache::lonnet::filelocation('',$formname);
                   7776:             if(!copy($original,$source)) {
                   7777:                 &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
                   7778:                 return (&mt('Failed to write file'));
                   7779:             }
                   7780:         }
                   7781:         close(FH);
                   7782:         chmod(0660, $source); # Permissions to rw-rw---.
                   7783: 
                   7784:         my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
                   7785:         my $copyfile=$targetdir.'/'.$file;
                   7786: 
                   7787:         my @parts=split(/\//,$targetdir);
                   7788:         my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
                   7789:         for (my $count=5;$count<=$#parts;$count++) {
                   7790:             $path.="/$parts[$count]";
                   7791:             if (!-e $path) {
                   7792:                 print $logfile "\nCreating directory ".$path;
                   7793:                 mkdir($path,02770);
                   7794:             }
                   7795:         }
                   7796:         my $versionresult;
                   7797:         if (-e $copyfile) {
                   7798:             $versionresult = &logo_versioning($targetdir,$file,$logfile);
                   7799:         } else {
                   7800:             $versionresult = 'ok';
                   7801:         }
                   7802:         if ($versionresult eq 'ok') {
                   7803:             if (copy($source,$copyfile)) {
                   7804:                 print $logfile "\nCopied original source to ".$copyfile."\n";
                   7805:                 $output = 'ok';
                   7806:                 $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155     raeburn  7807:                 push(@{$modified_urls},[$copyfile,$source]);
                   7808:                 my $metaoutput = 
                   7809:                     &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
                   7810:                 unless ($registered_cleanup) {
                   7811:                     my $handlers = $r->get_handlers('PerlCleanupHandler');
                   7812:                     $r->set_handlers('PerlCleanupHandler' => [\&notifysubscribed,@{$handlers}]);
                   7813:                     $registered_cleanup=1;
                   7814:                 }
1.9       raeburn  7815:             } else {
                   7816:                 print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
                   7817:                 $output = &mt('Failed to copy file to RES space').", $!";
                   7818:             }
                   7819:             if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
                   7820:                 my $inputfile = $filepath.'/'.$file;
                   7821:                 my $outfile = $filepath.'/'.'tn-'.$file;
1.16      raeburn  7822:                 my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
                   7823:                 if ($fullwidth ne '' && $fullheight ne '') { 
                   7824:                     if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
                   7825:                         my $thumbsize = $thumbwidth.'x'.$thumbheight;
1.160.6.88  raeburn  7826:                         my @args = ('convert','-sample',$thumbsize,$inputfile,$outfile);
                   7827:                         system({$args[0]} @args);
1.16      raeburn  7828:                         chmod(0660, $filepath.'/tn-'.$file);
                   7829:                         if (-e $outfile) {
                   7830:                             my $copyfile=$targetdir.'/tn-'.$file;
                   7831:                             if (copy($outfile,$copyfile)) {
                   7832:                                 print $logfile "\nCopied source to ".$copyfile."\n";
1.155     raeburn  7833:                                 my $thumb_metaoutput = 
                   7834:                                     &write_metadata($dom,$confname,$formname,
                   7835:                                                     $targetdir,'tn-'.$file,$logfile);
                   7836:                                 push(@{$modified_urls},[$copyfile,$outfile]);
                   7837:                                 unless ($registered_cleanup) {
                   7838:                                     my $handlers = $r->get_handlers('PerlCleanupHandler');
                   7839:                                     $r->set_handlers('PerlCleanupHandler' => [\&notifysubscribed,@{$handlers}]);
                   7840:                                     $registered_cleanup=1;
                   7841:                                 }
1.16      raeburn  7842:                             } else {
                   7843:                                 print $logfile "\nUnable to write ".$copyfile.
                   7844:                                                ':'.$!."\n";
                   7845:                             }
                   7846:                         }
1.9       raeburn  7847:                     }
                   7848:                 }
                   7849:             }
                   7850:         } else {
                   7851:             $output = $versionresult;
                   7852:         }
                   7853:     }
                   7854:     return ($output,$logourl);
                   7855: }
                   7856: 
                   7857: sub logo_versioning {
                   7858:     my ($targetdir,$file,$logfile) = @_;
                   7859:     my $target = $targetdir.'/'.$file;
                   7860:     my ($maxversion,$fn,$extn,$output);
                   7861:     $maxversion = 0;
                   7862:     if ($file =~ /^(.+)\.(\w+)$/) {
                   7863:         $fn=$1;
                   7864:         $extn=$2;
                   7865:     }
                   7866:     opendir(DIR,$targetdir);
                   7867:     while (my $filename=readdir(DIR)) {
                   7868:         if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
                   7869:             $maxversion=($1>$maxversion)?$1:$maxversion;
                   7870:         }
                   7871:     }
                   7872:     $maxversion++;
                   7873:     print $logfile "\nCreating old version ".$maxversion."\n";
                   7874:     my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
                   7875:     if (copy($target,$copyfile)) {
                   7876:         print $logfile "Copied old target to ".$copyfile."\n";
                   7877:         $copyfile=$copyfile.'.meta';
                   7878:         if (copy($target.'.meta',$copyfile)) {
                   7879:             print $logfile "Copied old target metadata to ".$copyfile."\n";
                   7880:             $output = 'ok';
                   7881:         } else {
                   7882:             print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
                   7883:             $output = &mt('Failed to copy old meta').", $!, ";
                   7884:         }
                   7885:     } else {
                   7886:         print $logfile "Unable to write ".$copyfile.':'.$!."\n";
                   7887:         $output = &mt('Failed to copy old target').", $!, ";
                   7888:     }
                   7889:     return $output;
                   7890: }
                   7891: 
                   7892: sub write_metadata {
                   7893:     my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
                   7894:     my (%metadatafields,%metadatakeys,$output);
                   7895:     $metadatafields{'title'}=$formname;
                   7896:     $metadatafields{'creationdate'}=time;
                   7897:     $metadatafields{'lastrevisiondate'}=time;
                   7898:     $metadatafields{'copyright'}='public';
                   7899:     $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
                   7900:                                          $env{'user.domain'};
                   7901:     $metadatafields{'authorspace'}=$confname.':'.$dom;
                   7902:     $metadatafields{'domain'}=$dom;
                   7903:     {
                   7904:         print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
                   7905:         my $mfh;
1.160.6.88  raeburn  7906:         if (open($mfh,">",$targetdir.'/'.$file.'.meta')) {
1.160.6.13  raeburn  7907:             foreach (sort(keys(%metadatafields))) {
1.155     raeburn  7908:                 unless ($_=~/\./) {
                   7909:                     my $unikey=$_;
                   7910:                     $unikey=~/^([A-Za-z]+)/;
                   7911:                     my $tag=$1;
                   7912:                     $tag=~tr/A-Z/a-z/;
                   7913:                     print $mfh "\n\<$tag";
                   7914:                     foreach (split(/\,/,$metadatakeys{$unikey})) {
                   7915:                         my $value=$metadatafields{$unikey.'.'.$_};
                   7916:                         $value=~s/\"/\'\'/g;
                   7917:                         print $mfh ' '.$_.'="'.$value.'"';
                   7918:                     }
                   7919:                     print $mfh '>'.
                   7920:                         &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
                   7921:                             .'</'.$tag.'>';
                   7922:                 }
                   7923:             }
                   7924:             $output = 'ok';
                   7925:             print $logfile "\nWrote metadata";
                   7926:             close($mfh);
                   7927:         } else {
                   7928:             print $logfile "\nFailed to open metadata file";
1.9       raeburn  7929:             $output = &mt('Could not write metadata');
                   7930:         }
                   7931:     }
1.155     raeburn  7932:     return $output;
                   7933: }
                   7934: 
                   7935: sub notifysubscribed {
                   7936:     foreach my $targetsource (@{$modified_urls}){
                   7937:         next unless (ref($targetsource) eq 'ARRAY');
                   7938:         my ($target,$source)=@{$targetsource};
                   7939:         if ($source ne '') {
1.160.6.88  raeburn  7940:             if (open(my $logfh,">>",$source.'.log')) {
1.155     raeburn  7941:                 print $logfh "\nCleanup phase: Notifications\n";
                   7942:                 my @subscribed=&subscribed_hosts($target);
                   7943:                 foreach my $subhost (@subscribed) {
                   7944:                     print $logfh "\nNotifying host ".$subhost.':';
                   7945:                     my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
                   7946:                     print $logfh $reply;
                   7947:                 }
                   7948:                 my @subscribedmeta=&subscribed_hosts("$target.meta");
                   7949:                 foreach my $subhost (@subscribedmeta) {
                   7950:                     print $logfh "\nNotifying host for metadata only ".$subhost.':';
                   7951:                     my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
                   7952:                                                         $subhost);
                   7953:                     print $logfh $reply;
                   7954:                 }
                   7955:                 print $logfh "\n============ Done ============\n";
1.160     raeburn  7956:                 close($logfh);
1.155     raeburn  7957:             }
                   7958:         }
                   7959:     }
                   7960:     return OK;
                   7961: }
                   7962: 
                   7963: sub subscribed_hosts {
                   7964:     my ($target) = @_;
                   7965:     my @subscribed;
1.160.6.88  raeburn  7966:     if (open(my $fh,"<","$target.subscription")) {
1.155     raeburn  7967:         while (my $subline=<$fh>) {
                   7968:             if ($subline =~ /^($match_lonid):/) {
                   7969:                 my $host = $1;
                   7970:                 if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
                   7971:                     unless (grep(/^\Q$host\E$/,@subscribed)) {
                   7972:                         push(@subscribed,$host);
                   7973:                     }
                   7974:                 }
                   7975:             }
                   7976:         }
                   7977:     }
                   7978:     return @subscribed;
1.9       raeburn  7979: }
                   7980: 
                   7981: sub check_switchserver {
                   7982:     my ($dom,$confname) = @_;
                   7983:     my ($allowed,$switchserver);
                   7984:     my $home = &Apache::lonnet::homeserver($confname,$dom);
                   7985:     if ($home eq 'no_host') {
                   7986:         $home = &Apache::lonnet::domain($dom,'primary');
                   7987:     }
                   7988:     my @ids=&Apache::lonnet::current_machine_ids();
1.10      albertel 7989:     foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
                   7990:     if (!$allowed) {
1.160.6.11  raeburn  7991: 	$switchserver='<a href="/adm/switchserver?otherserver='.$home.'&amp;role=dc./'.$dom.'/&amp;destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9       raeburn  7992:     }
                   7993:     return $switchserver;
                   7994: }
                   7995: 
1.1       raeburn  7996: sub modify_quotas {
1.160.6.30  raeburn  7997:     my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101     raeburn  7998:     my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.160.6.30  raeburn  7999:         %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.160.6.39  raeburn  8000:         $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
                   8001:         $validationfieldsref);
1.86      raeburn  8002:     if ($action eq 'quotas') {
                   8003:         $context = 'tools'; 
1.160.6.26  raeburn  8004:     } else {
1.86      raeburn  8005:         $context = $action;
                   8006:     }
                   8007:     if ($context eq 'requestcourses') {
1.160.6.30  raeburn  8008:         @usertools = ('official','unofficial','community','textbook');
1.106     raeburn  8009:         @options =('norequest','approval','validate','autolimit');
1.101     raeburn  8010:         %validations = &Apache::lonnet::auto_courserequest_checks($dom);
                   8011:         %titles = &courserequest_titles();
                   8012:         $toolregexp = join('|',@usertools);
                   8013:         %conditions = &courserequest_conditions();
1.160.6.30  raeburn  8014:         $confname = $dom.'-domainconfig';
                   8015:         my $servadm = $r->dir_config('lonAdmEMail');
                   8016:         ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.160.6.39  raeburn  8017:         ($validationitemsref,$validationnamesref,$validationfieldsref) = 
                   8018:             &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.160.6.5  raeburn  8019:     } elsif ($context eq 'requestauthor') {
                   8020:         @usertools = ('author');
                   8021:         %titles = &authorrequest_titles();
1.86      raeburn  8022:     } else {
1.160.6.4  raeburn  8023:         @usertools = ('aboutme','blog','webdav','portfolio');
1.101     raeburn  8024:         %titles = &tool_titles();
1.86      raeburn  8025:     }
1.160.6.27  raeburn  8026:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44      raeburn  8027:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1       raeburn  8028:     foreach my $key (keys(%env)) {
1.101     raeburn  8029:         if ($context eq 'requestcourses') {
                   8030:             if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
                   8031:                 my $item = $1;
                   8032:                 my $type = $2;
                   8033:                 if ($type =~ /^limit_(.+)/) {
                   8034:                     $limithash{$item}{$1} = $env{$key};
                   8035:                 } else {
                   8036:                     $confhash{$item}{$type} = $env{$key};
                   8037:                 }
                   8038:             }
1.160.6.5  raeburn  8039:         } elsif ($context eq 'requestauthor') {
                   8040:             if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
                   8041:                 $confhash{$1} = $env{$key};
                   8042:             }
1.101     raeburn  8043:         } else {
1.86      raeburn  8044:             if ($key =~ /^form\.quota_(.+)$/) {
                   8045:                 $confhash{'defaultquota'}{$1} = $env{$key};
1.160.6.20  raeburn  8046:             } elsif ($key =~ /^form\.authorquota_(.+)$/) {
                   8047:                 $confhash{'authorquota'}{$1} = $env{$key};
                   8048:             } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101     raeburn  8049:                 @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
                   8050:             }
1.72      raeburn  8051:         }
                   8052:     }
1.160.6.5  raeburn  8053:     if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.34  raeburn  8054:         my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102     raeburn  8055:         @approvalnotify = sort(@approvalnotify);
                   8056:         $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.160.6.30  raeburn  8057:         my @crstypes = ('official','unofficial','community','textbook');
                   8058:         my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
                   8059:         foreach my $type (@hasuniquecode) {
                   8060:             if (grep(/^\Q$type\E$/,@crstypes)) {
                   8061:                 $confhash{'uniquecode'}{$type} = 1;
                   8062:             }
                   8063:         }
1.160.6.46  raeburn  8064:         my (%newbook,%allpos);
1.160.6.30  raeburn  8065:         if ($context eq 'requestcourses') {
1.160.6.46  raeburn  8066:             foreach my $type ('textbooks','templates') {
                   8067:                 @{$allpos{$type}} = (); 
                   8068:                 my $invalid;
                   8069:                 if ($type eq 'textbooks') {
                   8070:                     $invalid = &mt('Invalid LON-CAPA course for textbook');
                   8071:                 } else {
                   8072:                     $invalid = &mt('Invalid LON-CAPA course for template');
                   8073:                 }
                   8074:                 if ($env{'form.'.$type.'_addbook'}) {
                   8075:                     if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
                   8076:                         ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
                   8077:                         if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
                   8078:                                                         $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
                   8079:                             $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
                   8080:                         } else {
                   8081:                             $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
                   8082:                             my $position = $env{'form.'.$type.'_addbook_pos'};
                   8083:                             $position =~ s/\D+//g;
                   8084:                             if ($position ne '') {
                   8085:                                 $allpos{$type}[$position] = $newbook{$type};
                   8086:                             }
1.160.6.30  raeburn  8087:                         }
1.160.6.46  raeburn  8088:                     } else {
                   8089:                         $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.160.6.30  raeburn  8090:                     }
                   8091:                 }
1.160.6.46  raeburn  8092:             } 
1.160.6.30  raeburn  8093:         }
1.102     raeburn  8094:         if (ref($domconfig{$action}) eq 'HASH') {
                   8095:             if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
                   8096:                 if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
                   8097:                     $changes{'notify'}{'approval'} = 1;
                   8098:                 }
                   8099:             } else {
1.144     raeburn  8100:                 if ($confhash{'notify'}{'approval'}) {
1.102     raeburn  8101:                     $changes{'notify'}{'approval'} = 1;
                   8102:                 }
                   8103:             }
1.160.6.30  raeburn  8104:             if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
                   8105:                 if (ref($confhash{'uniquecode'}) eq 'HASH') {
                   8106:                     foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
                   8107:                         unless ($confhash{'uniquecode'}{$crstype}) {
                   8108:                             $changes{'uniquecode'} = 1;
                   8109:                         }
                   8110:                     }
                   8111:                     unless ($changes{'uniquecode'}) {
                   8112:                         foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
                   8113:                             unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
                   8114:                                 $changes{'uniquecode'} = 1;
                   8115:                             }
                   8116:                         }
                   8117:                     }
                   8118:                } else {
                   8119:                    $changes{'uniquecode'} = 1;
                   8120:                }
                   8121:             } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
                   8122:                 $changes{'uniquecode'} = 1;
                   8123:             }
                   8124:             if ($context eq 'requestcourses') {
1.160.6.46  raeburn  8125:                 foreach my $type ('textbooks','templates') {
                   8126:                     if (ref($domconfig{$action}{$type}) eq 'HASH') {
                   8127:                         my %deletions;
                   8128:                         my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
                   8129:                         if (@todelete) {
                   8130:                             map { $deletions{$_} = 1; } @todelete;
                   8131:                         }
                   8132:                         my %imgdeletions;
                   8133:                         my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
                   8134:                         if (@todeleteimages) {
                   8135:                             map { $imgdeletions{$_} = 1; } @todeleteimages;
                   8136:                         }
                   8137:                         my $maxnum = $env{'form.'.$type.'_maxnum'};
                   8138:                         for (my $i=0; $i<=$maxnum; $i++) {
                   8139:                             my $itemid = $env{'form.'.$type.'_id_'.$i};
                   8140:                             my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/); 
                   8141:                             if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
                   8142:                                 if ($deletions{$key}) {
                   8143:                                     if ($domconfig{$action}{$type}{$key}{'image'}) {
                   8144:                                         #FIXME need to obsolete item in RES space
                   8145:                                     }
                   8146:                                     next;
                   8147:                                 } else {
                   8148:                                     my $newpos = $env{'form.'.$itemid};
                   8149:                                     $newpos =~ s/\D+//g;
1.160.6.47  raeburn  8150:                                     foreach my $item ('subject','title','publisher','author') {
                   8151:                                         next if ((($item eq 'author') || ($item eq 'publisher')) &&
                   8152:                                                  ($type eq 'templates'));
1.160.6.46  raeburn  8153:                                         $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
                   8154:                                         if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
                   8155:                                             $changes{$type}{$key} = 1;
                   8156:                                         }
                   8157:                                     }
                   8158:                                     $allpos{$type}[$newpos] = $key;
1.160.6.30  raeburn  8159:                                 }
1.160.6.46  raeburn  8160:                                 if ($imgdeletions{$key}) {
                   8161:                                     $changes{$type}{$key} = 1;
                   8162:                                     #FIXME need to obsolete item in RES space
                   8163:                                 } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
                   8164:                                     my ($cdom,$cnum) = split(/_/,$key);
1.160.6.88  raeburn  8165:                                     if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
                   8166:                                         $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
                   8167:                                     } else {
                   8168:                                         my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
                   8169:                                                                                       $cdom,$cnum,$type,$configuserok,
                   8170:                                                                                       $switchserver,$author_ok);
                   8171:                                         if ($imgurl) {
                   8172:                                             $confhash{$type}{$key}{'image'} = $imgurl;
                   8173:                                             $changes{$type}{$key} = 1; 
                   8174:                                         }
                   8175:                                         if ($error) {
                   8176:                                             &Apache::lonnet::logthis($error);
                   8177:                                             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   8178:                                         }
1.160.6.46  raeburn  8179:                                     } 
                   8180:                                 } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
                   8181:                                     $confhash{$type}{$key}{'image'} = 
                   8182:                                         $domconfig{$action}{$type}{$key}{'image'};
1.160.6.30  raeburn  8183:                                 }
                   8184:                             }
                   8185:                         }
                   8186:                     }
                   8187:                 }
                   8188:             }
1.102     raeburn  8189:         } else {
1.144     raeburn  8190:             if ($confhash{'notify'}{'approval'}) {
1.102     raeburn  8191:                 $changes{'notify'}{'approval'} = 1;
                   8192:             }
1.160.6.30  raeburn  8193:             if (ref($confhash{'uniquecode'} eq 'HASH')) {
                   8194:                 $changes{'uniquecode'} = 1;
                   8195:             }
                   8196:         }
                   8197:         if ($context eq 'requestcourses') {
1.160.6.46  raeburn  8198:             foreach my $type ('textbooks','templates') {
                   8199:                 if ($newbook{$type}) {
                   8200:                     $changes{$type}{$newbook{$type}} = 1;
1.160.6.47  raeburn  8201:                     foreach my $item ('subject','title','publisher','author') {
                   8202:                         next if ((($item eq 'author') || ($item eq 'publisher')) &&
                   8203:                                  ($type eq 'template'));
1.160.6.46  raeburn  8204:                         $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
                   8205:                         if ($env{'form.'.$type.'_addbook_'.$item}) {
                   8206:                             $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
                   8207:                         }
                   8208:                     }
                   8209:                     if ($type eq 'textbooks') {
                   8210:                         if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
                   8211:                             my ($cdom,$cnum) = split(/_/,$newbook{$type});
1.160.6.88  raeburn  8212:                             if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
                   8213:                                 $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
                   8214:                             } else {
                   8215:                                 my ($imageurl,$error) =
                   8216:                                     &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
                   8217:                                                             $configuserok,$switchserver,$author_ok);
                   8218:                                 if ($imageurl) {
                   8219:                                     $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
                   8220:                                 }
                   8221:                                 if ($error) {
                   8222:                                     &Apache::lonnet::logthis($error);
                   8223:                                     $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   8224:                                 }
1.160.6.46  raeburn  8225:                             }
                   8226:                         }
1.160.6.30  raeburn  8227:                     }
                   8228:                 }
1.160.6.46  raeburn  8229:                 if (@{$allpos{$type}} > 0) {
                   8230:                     my $idx = 0;
                   8231:                     foreach my $item (@{$allpos{$type}}) {
                   8232:                         if ($item ne '') {
                   8233:                             $confhash{$type}{$item}{'order'} = $idx;
                   8234:                             if (ref($domconfig{$action}) eq 'HASH') {
                   8235:                                 if (ref($domconfig{$action}{$type}) eq 'HASH') {
                   8236:                                     if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
                   8237:                                         if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
                   8238:                                             $changes{$type}{$item} = 1;
                   8239:                                         }
1.160.6.30  raeburn  8240:                                     }
                   8241:                                 }
                   8242:                             }
1.160.6.46  raeburn  8243:                             $idx ++;
1.160.6.30  raeburn  8244:                         }
                   8245:                     }
                   8246:                 }
                   8247:             }
1.160.6.39  raeburn  8248:             if (ref($validationitemsref) eq 'ARRAY') {
                   8249:                 foreach my $item (@{$validationitemsref}) {
                   8250:                     if ($item eq 'fields') {
                   8251:                         my @changed;
                   8252:                         @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
                   8253:                         if (@{$confhash{'validation'}{$item}} > 0) {
                   8254:                             @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
                   8255:                         }
1.160.6.65  raeburn  8256:                         if (ref($domconfig{'requestcourses'}) eq 'HASH') {
                   8257:                             if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
                   8258:                                 if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
                   8259:                                     @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
                   8260:                                                                                   $domconfig{'requestcourses'}{'validation'}{$item});
                   8261:                                 } else {
                   8262:                                     @changed = @{$confhash{'validation'}{$item}};
                   8263:                                 }
1.160.6.39  raeburn  8264:                             } else {
                   8265:                                 @changed = @{$confhash{'validation'}{$item}};
                   8266:                             }
                   8267:                         } else {
                   8268:                             @changed = @{$confhash{'validation'}{$item}};
                   8269:                         }
                   8270:                         if (@changed) {
                   8271:                             if ($confhash{'validation'}{$item}) {
                   8272:                                 $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
                   8273:                             } else {
                   8274:                                 $changes{'validation'}{$item} = &mt('None');
                   8275:                             }
                   8276:                         }
                   8277:                     } else {
                   8278:                         $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
                   8279:                         if ($item eq 'markup') {
                   8280:                             if ($env{'form.requestcourses_validation_'.$item}) {
                   8281:                                 $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
                   8282:                             }
                   8283:                         }
1.160.6.65  raeburn  8284:                         if (ref($domconfig{'requestcourses'}) eq 'HASH') {
                   8285:                             if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
                   8286:                                 if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
                   8287:                                     $changes{'validation'}{$item} = $confhash{'validation'}{$item};
                   8288:                                 }
                   8289:                             } else {
                   8290:                                 if ($confhash{'validation'}{$item} ne '') {
                   8291:                                     $changes{'validation'}{$item} = $confhash{'validation'}{$item};
                   8292:                                 }
1.160.6.39  raeburn  8293:                             }
                   8294:                         } else {
                   8295:                             if ($confhash{'validation'}{$item} ne '') {
                   8296:                                 $changes{'validation'}{$item} = $confhash{'validation'}{$item};
                   8297:                             }
                   8298:                         }
                   8299:                     }
                   8300:                 }
                   8301:             }
                   8302:             if ($env{'form.validationdc'}) {
                   8303:                 my $newval = $env{'form.validationdc'};
1.160.6.77  raeburn  8304:                 my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.160.6.39  raeburn  8305:                 if (exists($domcoords{$newval})) {
                   8306:                     $confhash{'validation'}{'dc'} = $newval;
                   8307:                 }
                   8308:             }
                   8309:             if (ref($confhash{'validation'}) eq 'HASH') {
1.160.6.65  raeburn  8310:                 if (ref($domconfig{'requestcourses'}) eq 'HASH') {
                   8311:                     if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
                   8312:                         if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
                   8313:                             unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
                   8314:                                 if ($confhash{'validation'}{'dc'} eq '') {
                   8315:                                     $changes{'validation'}{'dc'} = &mt('None');
                   8316:                                 } else {
                   8317:                                     $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
                   8318:                                 }
1.160.6.39  raeburn  8319:                             }
1.160.6.65  raeburn  8320:                         } elsif ($confhash{'validation'}{'dc'} ne '') {
                   8321:                             $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.160.6.39  raeburn  8322:                         }
                   8323:                     } elsif ($confhash{'validation'}{'dc'} ne '') {
                   8324:                         $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
                   8325:                     }
                   8326:                 } elsif ($confhash{'validation'}{'dc'} ne '') {
                   8327:                     $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
                   8328:                 }
1.160.6.65  raeburn  8329:             } else {
                   8330:                 if (ref($domconfig{'requestcourses'}) eq 'HASH') {
                   8331:                     if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
                   8332:                         if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
                   8333:                             $changes{'validation'}{'dc'} = &mt('None');
                   8334:                         }
                   8335:                     }
1.160.6.39  raeburn  8336:                 }
                   8337:             }
1.102     raeburn  8338:         }
                   8339:     } else {
1.86      raeburn  8340:         $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.160.6.20  raeburn  8341:         $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86      raeburn  8342:     }
1.72      raeburn  8343:     foreach my $item (@usertools) {
                   8344:         foreach my $type (@{$types},'default','_LC_adv') {
1.104     raeburn  8345:             my $unset; 
1.101     raeburn  8346:             if ($context eq 'requestcourses') {
1.104     raeburn  8347:                 $unset = '0';
                   8348:                 if ($type eq '_LC_adv') {
                   8349:                     $unset = '';
                   8350:                 }
1.101     raeburn  8351:                 if ($confhash{$item}{$type} eq 'autolimit') {
                   8352:                     $confhash{$item}{$type} .= '=';
                   8353:                     unless ($limithash{$item}{$type} =~ /\D/) {
                   8354:                         $confhash{$item}{$type} .= $limithash{$item}{$type};
                   8355:                     }
                   8356:                 }
1.160.6.5  raeburn  8357:             } elsif ($context eq 'requestauthor') {
                   8358:                 $unset = '0';
                   8359:                 if ($type eq '_LC_adv') {
                   8360:                     $unset = '';
                   8361:                 }
1.72      raeburn  8362:             } else {
1.101     raeburn  8363:                 if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
                   8364:                     $confhash{$item}{$type} = 1;
                   8365:                 } else {
                   8366:                     $confhash{$item}{$type} = 0;
                   8367:                 }
1.72      raeburn  8368:             }
1.86      raeburn  8369:             if (ref($domconfig{$action}) eq 'HASH') {
1.160.6.5  raeburn  8370:                 if ($action eq 'requestauthor') {
                   8371:                     if ($domconfig{$action}{$type} ne $confhash{$type}) {
                   8372:                         $changes{$type} = 1;
                   8373:                     }
                   8374:                 } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86      raeburn  8375:                     if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
                   8376:                         $changes{$item}{$type} = 1;
                   8377:                     }
                   8378:                 } else {
                   8379:                     if ($context eq 'requestcourses') {
1.104     raeburn  8380:                         if ($confhash{$item}{$type} ne $unset) {
1.86      raeburn  8381:                             $changes{$item}{$type} = 1;
                   8382:                         }
                   8383:                     } else {
                   8384:                         if (!$confhash{$item}{$type}) {
                   8385:                             $changes{$item}{$type} = 1;
                   8386:                         }
                   8387:                     }
                   8388:                 }
                   8389:             } else {
                   8390:                 if ($context eq 'requestcourses') {
1.104     raeburn  8391:                     if ($confhash{$item}{$type} ne $unset) {
1.72      raeburn  8392:                         $changes{$item}{$type} = 1;
                   8393:                     }
1.160.6.5  raeburn  8394:                 } elsif ($context eq 'requestauthor') {
                   8395:                     if ($confhash{$type} ne $unset) {
                   8396:                         $changes{$type} = 1;
                   8397:                     }
1.72      raeburn  8398:                 } else {
                   8399:                     if (!$confhash{$item}{$type}) {
                   8400:                         $changes{$item}{$type} = 1;
                   8401:                     }
                   8402:                 }
                   8403:             }
1.1       raeburn  8404:         }
                   8405:     }
1.160.6.5  raeburn  8406:     unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86      raeburn  8407:         if (ref($domconfig{'quotas'}) eq 'HASH') {
                   8408:             if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
                   8409:                 foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
                   8410:                     if (exists($confhash{'defaultquota'}{$key})) {
                   8411:                         if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
                   8412:                             $changes{'defaultquota'}{$key} = 1;
                   8413:                         }
                   8414:                     } else {
                   8415:                         $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72      raeburn  8416:                     }
                   8417:                 }
1.86      raeburn  8418:             } else {
                   8419:                 foreach my $key (keys(%{$domconfig{'quotas'}})) {
                   8420:                     if (exists($confhash{'defaultquota'}{$key})) {
                   8421:                         if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
                   8422:                             $changes{'defaultquota'}{$key} = 1;
                   8423:                         }
                   8424:                     } else {
                   8425:                         $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72      raeburn  8426:                     }
1.1       raeburn  8427:                 }
                   8428:             }
1.160.6.20  raeburn  8429:             if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
                   8430:                 foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
                   8431:                     if (exists($confhash{'authorquota'}{$key})) {
                   8432:                         if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
                   8433:                             $changes{'authorquota'}{$key} = 1;
                   8434:                         }
                   8435:                     } else {
                   8436:                         $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
                   8437:                     }
                   8438:                 }
                   8439:             }
1.1       raeburn  8440:         }
1.86      raeburn  8441:         if (ref($confhash{'defaultquota'}) eq 'HASH') {
                   8442:             foreach my $key (keys(%{$confhash{'defaultquota'}})) {
                   8443:                 if (ref($domconfig{'quotas'}) eq 'HASH') {
                   8444:                     if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
                   8445:                         if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
                   8446:                             $changes{'defaultquota'}{$key} = 1;
                   8447:                         }
                   8448:                     } else {
                   8449:                         if (!exists($domconfig{'quotas'}{$key})) {
                   8450:                             $changes{'defaultquota'}{$key} = 1;
                   8451:                         }
1.72      raeburn  8452:                     }
                   8453:                 } else {
1.86      raeburn  8454:                     $changes{'defaultquota'}{$key} = 1;
1.55      raeburn  8455:                 }
1.1       raeburn  8456:             }
                   8457:         }
1.160.6.20  raeburn  8458:         if (ref($confhash{'authorquota'}) eq 'HASH') {
                   8459:             foreach my $key (keys(%{$confhash{'authorquota'}})) {
                   8460:                 if (ref($domconfig{'quotas'}) eq 'HASH') {
                   8461:                     if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
                   8462:                         if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
                   8463:                             $changes{'authorquota'}{$key} = 1;
                   8464:                         }
                   8465:                     } else {
                   8466:                         $changes{'authorquota'}{$key} = 1;
                   8467:                     }
                   8468:                 } else {
                   8469:                     $changes{'authorquota'}{$key} = 1;
                   8470:                 }
                   8471:             }
                   8472:         }
1.1       raeburn  8473:     }
1.72      raeburn  8474: 
1.160.6.5  raeburn  8475:     if ($context eq 'requestauthor') {
                   8476:         $domdefaults{'requestauthor'} = \%confhash;
                   8477:     } else {
                   8478:         foreach my $key (keys(%confhash)) {
1.160.6.46  raeburn  8479:             unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.160.6.30  raeburn  8480:                 $domdefaults{$key} = $confhash{$key};
                   8481:             }
1.160.6.5  raeburn  8482:         }
1.72      raeburn  8483:     }
1.160.6.5  raeburn  8484: 
1.1       raeburn  8485:     my %quotahash = (
1.86      raeburn  8486:                       $action => { %confhash }
1.1       raeburn  8487:                     );
                   8488:     my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
                   8489:                                              $dom);
                   8490:     if ($putresult eq 'ok') {
                   8491:         if (keys(%changes) > 0) {
1.72      raeburn  8492:             my $cachetime = 24*60*60;
                   8493:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27  raeburn  8494:             if (ref($lastactref) eq 'HASH') {
                   8495:                 $lastactref->{'domdefaults'} = 1;
                   8496:             }
1.1       raeburn  8497:             $resulttext = &mt('Changes made:').'<ul>';
1.160.6.5  raeburn  8498:             unless (($context eq 'requestcourses') ||
                   8499:                     ($context eq 'requestauthor')) {
1.86      raeburn  8500:                 if (ref($changes{'defaultquota'}) eq 'HASH') {
                   8501:                     $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
                   8502:                     foreach my $type (@{$types},'default') {
                   8503:                         if (defined($changes{'defaultquota'}{$type})) {
                   8504:                             my $typetitle = $usertypes->{$type};
                   8505:                             if ($type eq 'default') {
                   8506:                                 $typetitle = $othertitle;
                   8507:                             }
1.160.6.28  raeburn  8508:                             $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72      raeburn  8509:                         }
                   8510:                     }
1.86      raeburn  8511:                     $resulttext .= '</ul></li>';
1.72      raeburn  8512:                 }
1.160.6.20  raeburn  8513:                 if (ref($changes{'authorquota'}) eq 'HASH') {
1.160.6.34  raeburn  8514:                     $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.160.6.20  raeburn  8515:                     foreach my $type (@{$types},'default') {
                   8516:                         if (defined($changes{'authorquota'}{$type})) {
                   8517:                             my $typetitle = $usertypes->{$type};
                   8518:                             if ($type eq 'default') {
                   8519:                                 $typetitle = $othertitle;
                   8520:                             }
1.160.6.28  raeburn  8521:                             $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.160.6.20  raeburn  8522:                         }
                   8523:                     }
                   8524:                     $resulttext .= '</ul></li>';
                   8525:                 }
1.72      raeburn  8526:             }
1.80      raeburn  8527:             my %newenv;
1.72      raeburn  8528:             foreach my $item (@usertools) {
1.160.6.5  raeburn  8529:                 my (%haschgs,%inconf);
                   8530:                 if ($context eq 'requestauthor') {
                   8531:                     %haschgs = %changes;
                   8532:                     %inconf = %confhash;
                   8533:                 } else {
                   8534:                     if (ref($changes{$item}) eq 'HASH') {
                   8535:                         %haschgs = %{$changes{$item}};
                   8536:                     }
                   8537:                     if (ref($confhash{$item}) eq 'HASH') {
                   8538:                         %inconf = %{$confhash{$item}};
                   8539:                     }
                   8540:                 }
                   8541:                 if (keys(%haschgs) > 0) {
1.80      raeburn  8542:                     my $newacc = 
                   8543:                         &Apache::lonnet::usertools_access($env{'user.name'},
                   8544:                                                           $env{'user.domain'},
1.86      raeburn  8545:                                                           $item,'reload',$context);
1.160.6.5  raeburn  8546:                     if (($context eq 'requestcourses') ||
                   8547:                         ($context eq 'requestauthor')) {
1.108     raeburn  8548:                         if ($env{'environment.canrequest.'.$item} ne $newacc) {
                   8549:                             $newenv{'environment.canrequest.'.$item} = $newacc;
1.86      raeburn  8550:                         }
                   8551:                     } else {
                   8552:                         if ($env{'environment.availabletools.'.$item} ne $newacc) { 
                   8553:                             $newenv{'environment.availabletools.'.$item} = $newacc;
                   8554:                         }
1.80      raeburn  8555:                     }
1.160.6.5  raeburn  8556:                     unless ($context eq 'requestauthor') {
                   8557:                         $resulttext .= '<li>'.$titles{$item}.'<ul>';
                   8558:                     }
1.72      raeburn  8559:                     foreach my $type (@{$types},'default','_LC_adv') {
1.160.6.5  raeburn  8560:                         if ($haschgs{$type}) {
1.72      raeburn  8561:                             my $typetitle = $usertypes->{$type};
                   8562:                             if ($type eq 'default') {
                   8563:                                 $typetitle = $othertitle;
                   8564:                             } elsif ($type eq '_LC_adv') {
                   8565:                                 $typetitle = 'LON-CAPA Advanced Users'; 
                   8566:                             }
1.160.6.5  raeburn  8567:                             if ($inconf{$type}) {
1.101     raeburn  8568:                                 if ($context eq 'requestcourses') {
                   8569:                                     my $cond;
1.160.6.5  raeburn  8570:                                     if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101     raeburn  8571:                                         if ($1 eq '') {
                   8572:                                             $cond = &mt('(Automatic processing of any request).');
                   8573:                                         } else {
                   8574:                                             $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
                   8575:                                         }
                   8576:                                     } else { 
1.160.6.5  raeburn  8577:                                         $cond = $conditions{$inconf{$type}};
1.101     raeburn  8578:                                     }
                   8579:                                     $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.160.6.8  raeburn  8580:                                 } elsif ($context eq 'requestauthor') {
                   8581:                                     $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
                   8582:                                                              $titles{$inconf{$type}},$typetitle);
                   8583: 
1.101     raeburn  8584:                                 } else {
                   8585:                                     $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
                   8586:                                 }
1.72      raeburn  8587:                             } else {
1.104     raeburn  8588:                                 if ($type eq '_LC_adv') {
1.160.6.5  raeburn  8589:                                     if ($inconf{$type} eq '0') {
1.104     raeburn  8590:                                         $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
                   8591:                                     } else { 
                   8592:                                         $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
                   8593:                                     }
                   8594:                                 } else {
                   8595:                                     $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
                   8596:                                 }
1.72      raeburn  8597:                             }
                   8598:                         }
1.26      raeburn  8599:                     }
1.160.6.5  raeburn  8600:                     unless ($context eq 'requestauthor') {
                   8601:                         $resulttext .= '</ul></li>';
                   8602:                     }
1.26      raeburn  8603:                 }
1.1       raeburn  8604:             }
1.160.6.5  raeburn  8605:             if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102     raeburn  8606:                 if (ref($changes{'notify'}) eq 'HASH') {
                   8607:                     if ($changes{'notify'}{'approval'}) {
                   8608:                         if (ref($confhash{'notify'}) eq 'HASH') {
                   8609:                             if ($confhash{'notify'}{'approval'}) {
                   8610:                                 $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
                   8611:                             } else {
1.160.6.5  raeburn  8612:                                 $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102     raeburn  8613:                             }
                   8614:                         }
                   8615:                     }
                   8616:                 }
                   8617:             }
1.160.6.30  raeburn  8618:             if ($action eq 'requestcourses') {
                   8619:                 my @offon = ('off','on');
                   8620:                 if ($changes{'uniquecode'}) {
                   8621:                     if (ref($confhash{'uniquecode'}) eq 'HASH') {
                   8622:                         my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
                   8623:                         $resulttext .= '<li>'.
                   8624:                                        &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
                   8625:                                        '</li>';
                   8626:                     } else {
                   8627:                         $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
                   8628:                                        '</li>';
                   8629:                     }
                   8630:                 }
1.160.6.46  raeburn  8631:                 foreach my $type ('textbooks','templates') {
                   8632:                     if (ref($changes{$type}) eq 'HASH') {
                   8633:                         $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
                   8634:                         foreach my $key (sort(keys(%{$changes{$type}}))) {
                   8635:                             my %coursehash = &Apache::lonnet::coursedescription($key);
                   8636:                             my $coursetitle = $coursehash{'description'};
                   8637:                             my $position = $confhash{$type}{$key}{'order'} + 1;
                   8638:                             $resulttext .= '<li>';
1.160.6.47  raeburn  8639:                             foreach my $item ('subject','title','publisher','author') {
                   8640:                                 next if ((($item eq 'author') || ($item eq 'publisher')) &&
                   8641:                                          ($type eq 'templates'));
1.160.6.46  raeburn  8642:                                 my $name = $item.':';
                   8643:                                 $name =~ s/^(\w)/\U$1/;
                   8644:                                 $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
                   8645:                             }
                   8646:                             $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
                   8647:                             if ($type eq 'textbooks') {
                   8648:                                 if ($confhash{$type}{$key}{'image'}) {
                   8649:                                     $resulttext .= ' '.&mt('Image: [_1]',
                   8650:                                                    '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
                   8651:                                                    ' alt="Textbook cover" />').'<br />';
                   8652:                                 }
                   8653:                             }
                   8654:                             $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.160.6.30  raeburn  8655:                         }
1.160.6.46  raeburn  8656:                         $resulttext .= '</ul></li>';
1.160.6.30  raeburn  8657:                     }
                   8658:                 }
1.160.6.39  raeburn  8659:                 if (ref($changes{'validation'}) eq 'HASH') {
                   8660:                     if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
                   8661:                         $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
                   8662:                         foreach my $item (@{$validationitemsref}) {
                   8663:                             if (exists($changes{'validation'}{$item})) {
                   8664:                                 if ($item eq 'markup') {
                   8665:                                     $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
                   8666:                                                               '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
                   8667:                                 } else {
                   8668:                                     $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
                   8669:                                                               '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
                   8670:                                 }
                   8671:                             }
                   8672:                         }
                   8673:                         if (exists($changes{'validation'}{'dc'})) {
                   8674:                             $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
                   8675:                                                      '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
                   8676:                         }
                   8677:                     }
                   8678:                 }
1.160.6.30  raeburn  8679:             }
1.1       raeburn  8680:             $resulttext .= '</ul>';
1.80      raeburn  8681:             if (keys(%newenv)) {
                   8682:                 &Apache::lonnet::appenv(\%newenv);
                   8683:             }
1.1       raeburn  8684:         } else {
1.86      raeburn  8685:             if ($context eq 'requestcourses') {
                   8686:                 $resulttext = &mt('No changes made to rights to request creation of courses.');
1.160.6.5  raeburn  8687:             } elsif ($context eq 'requestauthor') {
                   8688:                 $resulttext = &mt('No changes made to rights to request author space.');
1.86      raeburn  8689:             } else {
1.90      weissno  8690:                 $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86      raeburn  8691:             }
1.1       raeburn  8692:         }
                   8693:     } else {
1.11      albertel 8694:         $resulttext = '<span class="LC_error">'.
                   8695: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  8696:     }
1.160.6.30  raeburn  8697:     if ($errors) {
                   8698:         $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
                   8699:                        '<ul>'.$errors.'</ul></p>';
                   8700:     }
1.3       raeburn  8701:     return $resulttext;
1.1       raeburn  8702: }
                   8703: 
1.160.6.30  raeburn  8704: sub process_textbook_image {
1.160.6.46  raeburn  8705:     my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.160.6.30  raeburn  8706:     my $filename = $env{'form.'.$caller.'.filename'};
                   8707:     my ($error,$url);
                   8708:     my ($width,$height) = (50,50);
                   8709:     if ($configuserok eq 'ok') {
                   8710:         if ($switchserver) {
                   8711:             $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
                   8712:                          $switchserver);
                   8713:         } elsif ($author_ok eq 'ok') {
                   8714:             my ($result,$imageurl) =
                   8715:                 &publishlogo($r,'upload',$caller,$dom,$confname,
1.160.6.88  raeburn  8716:                              "$type/$cdom/$cnum/cover",$width,$height);
1.160.6.30  raeburn  8717:             if ($result eq 'ok') {
                   8718:                 $url = $imageurl;
                   8719:             } else {
                   8720:                 $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
                   8721:             }
                   8722:         } else {
                   8723:             $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);
                   8724:         }
                   8725:     } else {
                   8726:         $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);
                   8727:     }
                   8728:     return ($url,$error);
                   8729: }
                   8730: 
1.3       raeburn  8731: sub modify_autoenroll {
1.160.6.24  raeburn  8732:     my ($dom,$lastactref,%domconfig) = @_;
1.1       raeburn  8733:     my ($resulttext,%changes);
                   8734:     my %currautoenroll;
                   8735:     if (ref($domconfig{'autoenroll'}) eq 'HASH') {
                   8736:         foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
                   8737:             $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
                   8738:         }
                   8739:     }
                   8740:     my $autorun = &Apache::lonnet::auto_run(undef,$dom),
                   8741:     my %title = ( run => 'Auto-enrollment active',
1.129     raeburn  8742:                   sender => 'Sender for notification messages',
1.160.6.68  raeburn  8743:                   coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
                   8744:                   failsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1       raeburn  8745:     my @offon = ('off','on');
1.17      raeburn  8746:     my $sender_uname = $env{'form.sender_uname'};
                   8747:     my $sender_domain = $env{'form.sender_domain'};
                   8748:     if ($sender_domain eq '') {
                   8749:         $sender_uname = '';
                   8750:     } elsif ($sender_uname eq '') {
                   8751:         $sender_domain = '';
                   8752:     }
1.129     raeburn  8753:     my $coowners = $env{'form.autoassign_coowners'};
1.160.6.68  raeburn  8754:     my $failsafe = $env{'form.autoenroll_failsafe'};
                   8755:     $failsafe =~ s{^\s+|\s+$}{}g;
                   8756:     if ($failsafe =~ /\D/) {
                   8757:         undef($failsafe);
                   8758:     }
1.1       raeburn  8759:     my %autoenrollhash =  (
1.129     raeburn  8760:                        autoenroll => { 'run' => $env{'form.autoenroll_run'},
                   8761:                                        'sender_uname' => $sender_uname,
                   8762:                                        'sender_domain' => $sender_domain,
                   8763:                                        'co-owners' => $coowners,
1.160.6.68  raeburn  8764:                                        'autofailsafe' => $failsafe,
1.1       raeburn  8765:                                 }
                   8766:                      );
1.4       raeburn  8767:     my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
                   8768:                                              $dom);
1.1       raeburn  8769:     if ($putresult eq 'ok') {
                   8770:         if (exists($currautoenroll{'run'})) {
                   8771:              if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
                   8772:                  $changes{'run'} = 1;
                   8773:              }
                   8774:         } elsif ($autorun) {
                   8775:             if ($env{'form.autoenroll_run'} ne '1') {
1.23      raeburn  8776:                  $changes{'run'} = 1;
1.1       raeburn  8777:             }
                   8778:         }
1.17      raeburn  8779:         if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1       raeburn  8780:             $changes{'sender'} = 1;
                   8781:         }
1.17      raeburn  8782:         if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1       raeburn  8783:             $changes{'sender'} = 1;
                   8784:         }
1.129     raeburn  8785:         if ($currautoenroll{'co-owners'} ne '') {
                   8786:             if ($currautoenroll{'co-owners'} ne $coowners) {
                   8787:                 $changes{'coowners'} = 1;
                   8788:             }
                   8789:         } elsif ($coowners) {
                   8790:             $changes{'coowners'} = 1;
1.160.6.68  raeburn  8791:         }
                   8792:         if ($currautoenroll{'autofailsafe'} ne $failsafe) {
                   8793:             $changes{'autofailsafe'} = 1;
                   8794:         }
1.1       raeburn  8795:         if (keys(%changes) > 0) {
                   8796:             $resulttext = &mt('Changes made:').'<ul>';
1.3       raeburn  8797:             if ($changes{'run'}) {
1.1       raeburn  8798:                 $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
                   8799:             }
                   8800:             if ($changes{'sender'}) {
1.17      raeburn  8801:                 if ($sender_uname eq '' || $sender_domain eq '') {
                   8802:                     $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
                   8803:                 } else {
                   8804:                     $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
                   8805:                 }
1.1       raeburn  8806:             }
1.129     raeburn  8807:             if ($changes{'coowners'}) {
                   8808:                 $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
                   8809:                 &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27  raeburn  8810:                 if (ref($lastactref) eq 'HASH') {
                   8811:                     $lastactref->{'domainconfig'} = 1;
                   8812:                 }
1.129     raeburn  8813:             }
1.160.6.68  raeburn  8814:             if ($changes{'autofailsafe'}) {
                   8815:                 if ($failsafe ne '') {
1.160.6.82  raeburn  8816:                     $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$failsafe).'</li>';
1.160.6.68  raeburn  8817:                 } else {
1.160.6.82  raeburn  8818:                     $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section: deleted');
1.160.6.68  raeburn  8819:                 }
                   8820:                 &Apache::lonnet::get_domain_defaults($dom,1);
                   8821:                 if (ref($lastactref) eq 'HASH') {
                   8822:                     $lastactref->{'domdefaults'} = 1;
                   8823:                 }
                   8824:             }
1.1       raeburn  8825:             $resulttext .= '</ul>';
                   8826:         } else {
                   8827:             $resulttext = &mt('No changes made to auto-enrollment settings');
                   8828:         }
                   8829:     } else {
1.11      albertel 8830:         $resulttext = '<span class="LC_error">'.
                   8831: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  8832:     }
1.3       raeburn  8833:     return $resulttext;
1.1       raeburn  8834: }
                   8835: 
                   8836: sub modify_autoupdate {
1.3       raeburn  8837:     my ($dom,%domconfig) = @_;
1.1       raeburn  8838:     my ($resulttext,%currautoupdate,%fields,%changes);
                   8839:     if (ref($domconfig{'autoupdate'}) eq 'HASH') {
                   8840:         foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
                   8841:             $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
                   8842:         }
                   8843:     }
                   8844:     my @offon = ('off','on');
                   8845:     my %title = &Apache::lonlocal::texthash (
                   8846:                    run => 'Auto-update:',
                   8847:                    classlists => 'Updates to user information in classlists?'
                   8848:                 );
1.44      raeburn  8849:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1       raeburn  8850:     my %fieldtitles = &Apache::lonlocal::texthash (
                   8851:                         id => 'Student/Employee ID',
1.20      raeburn  8852:                         permanentemail => 'E-mail address',
1.1       raeburn  8853:                         lastname => 'Last Name',
                   8854:                         firstname => 'First Name',
                   8855:                         middlename => 'Middle Name',
1.132     raeburn  8856:                         generation => 'Generation',
1.1       raeburn  8857:                       );
1.142     raeburn  8858:     $othertitle = &mt('All users');
1.1       raeburn  8859:     if (keys(%{$usertypes}) >  0) {
1.26      raeburn  8860:         $othertitle = &mt('Other users');
1.1       raeburn  8861:     }
                   8862:     foreach my $key (keys(%env)) {
                   8863:         if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132     raeburn  8864:             my ($usertype,$item) = ($1,$2);
                   8865:             if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
                   8866:                 if ($usertype eq 'default') {   
                   8867:                     push(@{$fields{$1}},$2);
                   8868:                 } elsif (ref($types) eq 'ARRAY') {
                   8869:                     if (grep(/^\Q$usertype\E$/,@{$types})) {
                   8870:                         push(@{$fields{$1}},$2);
                   8871:                     }
                   8872:                 }
                   8873:             }
1.1       raeburn  8874:         }
                   8875:     }
1.131     raeburn  8876:     my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
                   8877:     @lockablenames = sort(@lockablenames);
                   8878:     if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
                   8879:         my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
                   8880:         if (@changed) {
                   8881:             $changes{'lockablenames'} = 1;
                   8882:         }
                   8883:     } else {
                   8884:         if (@lockablenames) {
                   8885:             $changes{'lockablenames'} = 1;
                   8886:         }
                   8887:     }
1.1       raeburn  8888:     my %updatehash = (
                   8889:                       autoupdate => { run => $env{'form.autoupdate_run'},
                   8890:                                       classlists => $env{'form.classlists'},
                   8891:                                       fields => {%fields},
1.131     raeburn  8892:                                       lockablenames => \@lockablenames,
1.1       raeburn  8893:                                     }
                   8894:                      );
                   8895:     foreach my $key (keys(%currautoupdate)) {
                   8896:         if (($key eq 'run') || ($key eq 'classlists')) {
                   8897:             if (exists($updatehash{autoupdate}{$key})) {
                   8898:                 if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
                   8899:                     $changes{$key} = 1;
                   8900:                 }
                   8901:             }
                   8902:         } elsif ($key eq 'fields') {
                   8903:             if (ref($currautoupdate{$key}) eq 'HASH') {
1.26      raeburn  8904:                 foreach my $item (@{$types},'default') {
1.1       raeburn  8905:                     if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
                   8906:                         my $change = 0;
                   8907:                         foreach my $type (@{$currautoupdate{$key}{$item}}) {
                   8908:                             if (!exists($fields{$item})) {
                   8909:                                 $change = 1;
1.132     raeburn  8910:                                 last;
1.1       raeburn  8911:                             } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26      raeburn  8912:                                 if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1       raeburn  8913:                                     $change = 1;
1.132     raeburn  8914:                                     last;
1.1       raeburn  8915:                                 }
                   8916:                             }
                   8917:                         }
                   8918:                         if ($change) {
                   8919:                             push(@{$changes{$key}},$item);
                   8920:                         }
1.26      raeburn  8921:                     } 
1.1       raeburn  8922:                 }
                   8923:             }
1.131     raeburn  8924:         } elsif ($key eq 'lockablenames') {
                   8925:             if (ref($currautoupdate{$key}) eq 'ARRAY') {
                   8926:                 my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
                   8927:                 if (@changed) {
                   8928:                     $changes{'lockablenames'} = 1;
                   8929:                 }
                   8930:             } else {
                   8931:                 if (@lockablenames) {
                   8932:                     $changes{'lockablenames'} = 1;
                   8933:                 }
                   8934:             }
                   8935:         }
                   8936:     }
                   8937:     unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
                   8938:         if (@lockablenames) {
                   8939:             $changes{'lockablenames'} = 1;
1.1       raeburn  8940:         }
                   8941:     }
1.26      raeburn  8942:     foreach my $item (@{$types},'default') {
                   8943:         if (defined($fields{$item})) {
                   8944:             if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132     raeburn  8945:                 if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
                   8946:                     my $change = 0;
                   8947:                     if (ref($fields{$item}) eq 'ARRAY') {
                   8948:                         foreach my $type (@{$fields{$item}}) {
                   8949:                             if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
                   8950:                                 $change = 1;
                   8951:                                 last;
                   8952:                             }
                   8953:                         }
                   8954:                     }
                   8955:                     if ($change) {
                   8956:                         push(@{$changes{'fields'}},$item);
                   8957:                     }
                   8958:                 } else {
1.26      raeburn  8959:                     push(@{$changes{'fields'}},$item);
                   8960:                 }
                   8961:             } else {
                   8962:                 push(@{$changes{'fields'}},$item);
1.1       raeburn  8963:             }
                   8964:         }
                   8965:     }
                   8966:     my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
                   8967:                                              $dom);
                   8968:     if ($putresult eq 'ok') {
                   8969:         if (keys(%changes) > 0) {
                   8970:             $resulttext = &mt('Changes made:').'<ul>';
                   8971:             foreach my $key (sort(keys(%changes))) {
1.131     raeburn  8972:                 if ($key eq 'lockablenames') {
                   8973:                     $resulttext .= '<li>';
                   8974:                     if (@lockablenames) {
                   8975:                         $usertypes->{'default'} = $othertitle;
                   8976:                         $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
                   8977:                                    join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
                   8978:                     } else {
                   8979:                         $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
                   8980:                     }
                   8981:                     $resulttext .= '</li>';
                   8982:                 } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1       raeburn  8983:                     foreach my $item (@{$changes{$key}}) {
                   8984:                         my @newvalues;
                   8985:                         foreach my $type (@{$fields{$item}}) {
                   8986:                             push(@newvalues,$fieldtitles{$type});
                   8987:                         }
1.3       raeburn  8988:                         my $newvaluestr;
                   8989:                         if (@newvalues > 0) {
                   8990:                             $newvaluestr = join(', ',@newvalues);
                   8991:                         } else {
                   8992:                             $newvaluestr = &mt('none');
1.6       raeburn  8993:                         }
1.1       raeburn  8994:                         if ($item eq 'default') {
1.26      raeburn  8995:                             $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1       raeburn  8996:                         } else {
1.26      raeburn  8997:                             $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1       raeburn  8998:                         }
                   8999:                     }
                   9000:                 } else {
                   9001:                     my $newvalue;
                   9002:                     if ($key eq 'run') {
                   9003:                         $newvalue = $offon[$env{'form.autoupdate_run'}];
                   9004:                     } else {
                   9005:                         $newvalue = $offon[$env{'form.'.$key}];
1.3       raeburn  9006:                     }
1.1       raeburn  9007:                     $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
                   9008:                 }
                   9009:             }
                   9010:             $resulttext .= '</ul>';
                   9011:         } else {
1.3       raeburn  9012:             $resulttext = &mt('No changes made to autoupdates');
1.1       raeburn  9013:         }
                   9014:     } else {
1.11      albertel 9015:         $resulttext = '<span class="LC_error">'.
                   9016: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  9017:     }
1.3       raeburn  9018:     return $resulttext;
1.1       raeburn  9019: }
                   9020: 
1.125     raeburn  9021: sub modify_autocreate {
                   9022:     my ($dom,%domconfig) = @_;
                   9023:     my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
                   9024:     if (ref($domconfig{'autocreate'}) eq 'HASH') {
                   9025:         foreach my $key (keys(%{$domconfig{'autocreate'}})) {
                   9026:             $currautocreate{$key} = $domconfig{'autocreate'}{$key};
                   9027:         }
                   9028:     }
                   9029:     my %title= ( xml => 'Auto-creation of courses in XML course description files',
                   9030:                  req => 'Auto-creation of validated requests for official courses',
                   9031:                  xmldc => 'Identity of course creator of courses from XML files',
                   9032:                );
                   9033:     my @types = ('xml','req');
                   9034:     foreach my $item (@types) {
                   9035:         $newvals{$item} = $env{'form.autocreate_'.$item};
                   9036:         $newvals{$item} =~ s/\D//g;
                   9037:         $newvals{$item} = 0 if ($newvals{$item} eq '');
                   9038:     }
                   9039:     $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.160.6.77  raeburn  9040:     my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125     raeburn  9041:     unless (exists($domcoords{$newvals{'xmldc'}})) {
                   9042:         $newvals{'xmldc'} = '';
                   9043:     } 
                   9044:     %autocreatehash =  (
                   9045:                         autocreate => { xml => $newvals{'xml'},
                   9046:                                         req => $newvals{'req'},
                   9047:                                       }
                   9048:                        );
                   9049:     if ($newvals{'xmldc'} ne '') {
                   9050:         $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
                   9051:     }
                   9052:     my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
                   9053:                                              $dom);
                   9054:     if ($putresult eq 'ok') {
                   9055:         my @items = @types;
                   9056:         if ($newvals{'xml'}) {
                   9057:             push(@items,'xmldc');
                   9058:         }
                   9059:         foreach my $item (@items) {
                   9060:             if (exists($currautocreate{$item})) {
                   9061:                 if ($currautocreate{$item} ne $newvals{$item}) {
                   9062:                     $changes{$item} = 1;
                   9063:                 }
                   9064:             } elsif ($newvals{$item}) {
                   9065:                 $changes{$item} = 1;
                   9066:             }
                   9067:         }
                   9068:         if (keys(%changes) > 0) {
                   9069:             my @offon = ('off','on'); 
                   9070:             $resulttext = &mt('Changes made:').'<ul>';
                   9071:             foreach my $item (@types) {
                   9072:                 if ($changes{$item}) {
                   9073:                     my $newtxt = $offon[$newvals{$item}];
1.160.6.13  raeburn  9074:                     $resulttext .= '<li>'.
                   9075:                                    &mt("$title{$item} set to [_1]$newtxt [_2]",
                   9076:                                        '<b>','</b>').
                   9077:                                    '</li>';
1.125     raeburn  9078:                 }
                   9079:             }
                   9080:             if ($changes{'xmldc'}) {
                   9081:                 my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
                   9082:                 my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.13  raeburn  9083:                 $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>'; 
1.125     raeburn  9084:             }
                   9085:             $resulttext .= '</ul>';
                   9086:         } else {
                   9087:             $resulttext = &mt('No changes made to auto-creation settings');
                   9088:         }
                   9089:     } else {
                   9090:         $resulttext = '<span class="LC_error">'.
                   9091:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   9092:     }
                   9093:     return $resulttext;
                   9094: }
                   9095: 
1.23      raeburn  9096: sub modify_directorysrch {
1.160.6.81  raeburn  9097:     my ($dom,$lastactref,%domconfig) = @_;
1.23      raeburn  9098:     my ($resulttext,%changes);
                   9099:     my %currdirsrch;
                   9100:     if (ref($domconfig{'directorysrch'}) eq 'HASH') {
                   9101:         foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
                   9102:             $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
                   9103:         }
                   9104:     }
1.160.6.72  raeburn  9105:     my %title = ( available => 'Institutional directory search available',
                   9106:                   localonly => 'Other domains can search institution',
                   9107:                   lcavailable => 'LON-CAPA directory search available',
                   9108:                   lclocalonly => 'Other domains can search LON-CAPA domain',
1.23      raeburn  9109:                   searchby => 'Search types',
                   9110:                   searchtypes => 'Search latitude');
                   9111:     my @offon = ('off','on');
1.24      raeburn  9112:     my @otherdoms = ('Yes','No');
1.23      raeburn  9113: 
1.25      raeburn  9114:     my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');  
1.23      raeburn  9115:     my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
                   9116:     my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
                   9117: 
1.44      raeburn  9118:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26      raeburn  9119:     if (keys(%{$usertypes}) == 0) {
                   9120:         @cansearch = ('default');
                   9121:     } else {
                   9122:         if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
                   9123:             foreach my $type (@{$currdirsrch{'cansearch'}}) {
                   9124:                 if (!grep(/^\Q$type\E$/,@cansearch)) {
                   9125:                     push(@{$changes{'cansearch'}},$type);
                   9126:                 }
1.23      raeburn  9127:             }
1.26      raeburn  9128:             foreach my $type (@cansearch) {
                   9129:                 if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
                   9130:                     push(@{$changes{'cansearch'}},$type);
                   9131:                 }
1.23      raeburn  9132:             }
1.26      raeburn  9133:         } else {
                   9134:             push(@{$changes{'cansearch'}},@cansearch);
1.23      raeburn  9135:         }
                   9136:     }
                   9137: 
                   9138:     if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
                   9139:         foreach my $by (@{$currdirsrch{'searchby'}}) {
                   9140:             if (!grep(/^\Q$by\E$/,@searchby)) {
                   9141:                 push(@{$changes{'searchby'}},$by);
                   9142:             }
                   9143:         }
                   9144:         foreach my $by (@searchby) {
                   9145:             if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
                   9146:                 push(@{$changes{'searchby'}},$by);
                   9147:             }
                   9148:         }
                   9149:     } else {
                   9150:         push(@{$changes{'searchby'}},@searchby);
                   9151:     }
1.25      raeburn  9152: 
                   9153:     if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
                   9154:         foreach my $type (@{$currdirsrch{'searchtypes'}}) {
                   9155:             if (!grep(/^\Q$type\E$/,@searchtypes)) {
                   9156:                 push(@{$changes{'searchtypes'}},$type);
                   9157:             }
                   9158:         }
                   9159:         foreach my $type (@searchtypes) {
                   9160:             if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
                   9161:                 push(@{$changes{'searchtypes'}},$type);
                   9162:             }
                   9163:         }
                   9164:     } else {
                   9165:         if (exists($currdirsrch{'searchtypes'})) {
                   9166:             foreach my $type (@searchtypes) {  
                   9167:                 if ($type ne $currdirsrch{'searchtypes'}) { 
                   9168:                     push(@{$changes{'searchtypes'}},$type);
                   9169:                 }
                   9170:             }
                   9171:             if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
                   9172:                 push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
                   9173:             }   
                   9174:         } else {
                   9175:             push(@{$changes{'searchtypes'}},@searchtypes); 
                   9176:         }
                   9177:     }
                   9178: 
1.23      raeburn  9179:     my %dirsrch_hash =  (
                   9180:             directorysrch => { available => $env{'form.dirsrch_available'},
                   9181:                                cansearch => \@cansearch,
1.160.6.72  raeburn  9182:                                localonly => $env{'form.dirsrch_instlocalonly'},
                   9183:                                lclocalonly => $env{'form.dirsrch_domlocalonly'},
                   9184:                                lcavailable => $env{'form.dirsrch_domavailable'},
1.23      raeburn  9185:                                searchby => \@searchby,
1.25      raeburn  9186:                                searchtypes => \@searchtypes,
1.23      raeburn  9187:                              }
                   9188:             );
                   9189:     my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
                   9190:                                              $dom);
                   9191:     if ($putresult eq 'ok') {
                   9192:         if (exists($currdirsrch{'available'})) {
                   9193:              if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
                   9194:                  $changes{'available'} = 1;
                   9195:              }
                   9196:         } else {
                   9197:             if ($env{'form.dirsrch_available'} eq '1') {
                   9198:                 $changes{'available'} = 1;
                   9199:             }
                   9200:         }
1.160.6.72  raeburn  9201:         if (exists($currdirsrch{'lcavailable'})) {
1.160.6.78  raeburn  9202:             if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
                   9203:                 $changes{'lcavailable'} = 1;
                   9204:             }
1.24      raeburn  9205:         } else {
1.160.6.72  raeburn  9206:             if ($env{'form.dirsrch_lcavailable'} eq '1') {
                   9207:                 $changes{'lcavailable'} = 1;
                   9208:             }
                   9209:         }
                   9210:         if (exists($currdirsrch{'localonly'})) {
                   9211:             if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
1.24      raeburn  9212:                 $changes{'localonly'} = 1;
                   9213:             }
1.160.6.72  raeburn  9214:         } else {
                   9215:             if ($env{'form.dirsrch_instlocalonly'} eq '1') {
                   9216:                 $changes{'localonly'} = 1;
                   9217:             }
                   9218:         }
                   9219:         if (exists($currdirsrch{'lclocalonly'})) {
                   9220:             if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
                   9221:                 $changes{'lclocalonly'} = 1;
                   9222:             }
                   9223:         } else {
                   9224:             if ($env{'form.dirsrch_domlocalonly'} eq '1') {
                   9225:                 $changes{'lclocalonly'} = 1;
                   9226:             }
1.24      raeburn  9227:         }
1.23      raeburn  9228:         if (keys(%changes) > 0) {
                   9229:             $resulttext = &mt('Changes made:').'<ul>';
                   9230:             if ($changes{'available'}) {
                   9231:                 $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
                   9232:             }
1.160.6.72  raeburn  9233:             if ($changes{'lcavailable'}) {
                   9234:                 $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
                   9235:             }
1.24      raeburn  9236:             if ($changes{'localonly'}) {
1.160.6.72  raeburn  9237:                 $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
                   9238:             }
                   9239:             if ($changes{'lclocalonly'}) {
                   9240:                 $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.24      raeburn  9241:             }
1.23      raeburn  9242:             if (ref($changes{'cansearch'}) eq 'ARRAY') {
                   9243:                 my $chgtext;
1.26      raeburn  9244:                 if (ref($usertypes) eq 'HASH') {
                   9245:                     if (keys(%{$usertypes}) > 0) {
                   9246:                         foreach my $type (@{$types}) {
                   9247:                             if (grep(/^\Q$type\E$/,@cansearch)) {
                   9248:                                 $chgtext .= $usertypes->{$type}.'; ';
                   9249:                             }
                   9250:                         }
                   9251:                         if (grep(/^default$/,@cansearch)) {
                   9252:                             $chgtext .= $othertitle;
                   9253:                         } else {
                   9254:                             $chgtext =~ s/\; $//;
                   9255:                         }
1.160.6.13  raeburn  9256:                         $resulttext .=
                   9257:                             '<li>'.
                   9258:                             &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
                   9259:                                 '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
                   9260:                             '</li>';
1.23      raeburn  9261:                     }
                   9262:                 }
                   9263:             }
                   9264:             if (ref($changes{'searchby'}) eq 'ARRAY') {
                   9265:                 my ($searchtitles,$titleorder) = &sorted_searchtitles();
                   9266:                 my $chgtext;
                   9267:                 foreach my $type (@{$titleorder}) {
                   9268:                     if (grep(/^\Q$type\E$/,@searchby)) {
                   9269:                         if (defined($searchtitles->{$type})) {
                   9270:                             $chgtext .= $searchtitles->{$type}.'; ';
                   9271:                         }
                   9272:                     }
                   9273:                 }
                   9274:                 $chgtext =~ s/\; $//;
                   9275:                 $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
                   9276:             }
1.25      raeburn  9277:             if (ref($changes{'searchtypes'}) eq 'ARRAY') {
                   9278:                 my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes(); 
                   9279:                 my $chgtext;
                   9280:                 foreach my $type (@{$srchtypeorder}) {
                   9281:                     if (grep(/^\Q$type\E$/,@searchtypes)) {
                   9282:                         if (defined($srchtypes_desc->{$type})) {
                   9283:                             $chgtext .= $srchtypes_desc->{$type}.'; ';
                   9284:                         }
                   9285:                     }
                   9286:                 }
                   9287:                 $chgtext =~ s/\; $//;
1.160.6.13  raeburn  9288:                 $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23      raeburn  9289:             }
                   9290:             $resulttext .= '</ul>';
1.160.6.81  raeburn  9291:             &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
                   9292:             if (ref($lastactref) eq 'HASH') {
                   9293:                 $lastactref->{'directorysrch'} = 1;
                   9294:             }
1.23      raeburn  9295:         } else {
1.160.6.72  raeburn  9296:             $resulttext = &mt('No changes made to directory search settings');
1.23      raeburn  9297:         }
                   9298:     } else {
                   9299:         $resulttext = '<span class="LC_error">'.
1.27      raeburn  9300:                       &mt('An error occurred: [_1]',$putresult).'</span>';
                   9301:     }
                   9302:     return $resulttext;
                   9303: }
                   9304: 
1.28      raeburn  9305: sub modify_contacts {
1.160.6.24  raeburn  9306:     my ($dom,$lastactref,%domconfig) = @_;
1.28      raeburn  9307:     my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
                   9308:     if (ref($domconfig{'contacts'}) eq 'HASH') {
                   9309:         foreach my $key (keys(%{$domconfig{'contacts'}})) {
                   9310:             $currsetting{$key} = $domconfig{'contacts'}{$key};
                   9311:         }
                   9312:     }
1.160.6.78  raeburn  9313:     my (%others,%to,%bcc,%includestr,%includeloc);
1.28      raeburn  9314:     my @contacts = ('supportemail','adminemail');
1.160.6.78  raeburn  9315:     my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
                   9316:                     'lonstatusmail','requestsmail','updatesmail','idconflictsmail');
1.160.6.23  raeburn  9317:     my @toggles = ('reporterrors','reportupdates');
1.160.6.78  raeburn  9318:     my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28      raeburn  9319:     foreach my $type (@mailings) {
                   9320:         @{$newsetting{$type}} = 
                   9321:             &Apache::loncommon::get_env_multiple('form.'.$type);
                   9322:         foreach my $item (@contacts) {
                   9323:             if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
                   9324:                 $contacts_hash{contacts}{$type}{$item} = 1;
                   9325:             } else {
                   9326:                 $contacts_hash{contacts}{$type}{$item} = 0;
                   9327:             }
1.160.6.78  raeburn  9328:         }
1.28      raeburn  9329:         $others{$type} = $env{'form.'.$type.'_others'};
                   9330:         $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.160.6.78  raeburn  9331:         if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134     raeburn  9332:             $bcc{$type} = $env{'form.'.$type.'_bcc'};
                   9333:             $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.160.6.78  raeburn  9334:             if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
                   9335:                 $includestr{$type} = $env{'form.'.$type.'_includestr'};
                   9336:                 $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
                   9337:                 $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
                   9338:             }
1.134     raeburn  9339:         }
1.28      raeburn  9340:     }
                   9341:     foreach my $item (@contacts) {
                   9342:         $to{$item} = $env{'form.'.$item};
                   9343:         $contacts_hash{'contacts'}{$item} = $to{$item};
                   9344:     }
1.160.6.23  raeburn  9345:     foreach my $item (@toggles) {
                   9346:         if ($env{'form.'.$item} =~ /^(0|1)$/) {
                   9347:             $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
                   9348:         }
                   9349:     }
1.160.6.78  raeburn  9350:     if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
                   9351:         foreach my $field (@{$fields}) {
                   9352:             if (ref($possoptions->{$field}) eq 'ARRAY') {
                   9353:                 my $value = $env{'form.helpform_'.$field};
                   9354:                 $value =~ s/^\s+|\s+$//g;
                   9355:                 if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
                   9356:                     $contacts_hash{contacts}{'helpform'}{$field} = $value;
                   9357:                     if ($field eq 'screenshot') {
                   9358:                         $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
                   9359:                         if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
                   9360:                             $contacts_hash{contacts}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
                   9361:                         }
                   9362:                     }
                   9363:                 }
                   9364:             }
                   9365:         }
                   9366:     }
1.28      raeburn  9367:     if (keys(%currsetting) > 0) {
                   9368:         foreach my $item (@contacts) {
                   9369:             if ($to{$item} ne $currsetting{$item}) {
                   9370:                 $changes{$item} = 1;
                   9371:             }
                   9372:         }
                   9373:         foreach my $type (@mailings) {
                   9374:             foreach my $item (@contacts) {
                   9375:                 if (ref($currsetting{$type}) eq 'HASH') {
                   9376:                     if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
                   9377:                         push(@{$changes{$type}},$item);
                   9378:                     }
                   9379:                 } else {
                   9380:                     push(@{$changes{$type}},@{$newsetting{$type}});
                   9381:                 }
                   9382:             }
                   9383:             if ($others{$type} ne $currsetting{$type}{'others'}) {
                   9384:                 push(@{$changes{$type}},'others');
                   9385:             }
1.160.6.78  raeburn  9386:             if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134     raeburn  9387:                 if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
                   9388:                     push(@{$changes{$type}},'bcc'); 
                   9389:                 }
1.160.6.78  raeburn  9390:                 my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
                   9391:                 if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
                   9392:                     push(@{$changes{$type}},'include');
                   9393:                 }
                   9394:             }
                   9395:         }
                   9396:         if (ref($fields) eq 'ARRAY') {
                   9397:             if (ref($currsetting{'helpform'}) eq 'HASH') {
                   9398:                 foreach my $field (@{$fields}) {
                   9399:                     if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
                   9400:                         push(@{$changes{'helpform'}},$field);
                   9401:                     }
                   9402:                     if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
                   9403:                         if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
                   9404:                             push(@{$changes{'helpform'}},'maxsize');
                   9405:                         }
                   9406:                     }
                   9407:                 }
                   9408:             } else {
                   9409:                 foreach my $field (@{$fields}) {
                   9410:                     if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
                   9411:                         push(@{$changes{'helpform'}},$field);
                   9412:                     }
                   9413:                     if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
                   9414:                         if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
                   9415:                             push(@{$changes{'helpform'}},'maxsize');
                   9416:                         }
                   9417:                     }
                   9418:                 }
1.134     raeburn  9419:             }
1.28      raeburn  9420:         }
                   9421:     } else {
                   9422:         my %default;
                   9423:         $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
                   9424:         $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
                   9425:         $default{'errormail'} = 'adminemail';
                   9426:         $default{'packagesmail'} = 'adminemail';
                   9427:         $default{'helpdeskmail'} = 'supportemail';
1.160.6.78  raeburn  9428:         $default{'otherdomsmail'} = 'supportemail';
1.89      raeburn  9429:         $default{'lonstatusmail'} = 'adminemail';
1.102     raeburn  9430:         $default{'requestsmail'} = 'adminemail';
1.160.6.15  raeburn  9431:         $default{'updatesmail'} = 'adminemail';
1.28      raeburn  9432:         foreach my $item (@contacts) {
                   9433:            if ($to{$item} ne $default{$item}) {
1.160.6.78  raeburn  9434:                $changes{$item} = 1;
1.160.6.23  raeburn  9435:            }
1.28      raeburn  9436:         }
                   9437:         foreach my $type (@mailings) {
                   9438:             if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
                   9439:                 push(@{$changes{$type}},@{$newsetting{$type}});
                   9440:             }
                   9441:             if ($others{$type} ne '') {
                   9442:                 push(@{$changes{$type}},'others');
1.134     raeburn  9443:             }
1.160.6.78  raeburn  9444:             if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134     raeburn  9445:                 if ($bcc{$type} ne '') {
                   9446:                     push(@{$changes{$type}},'bcc');
                   9447:                 }
1.160.6.78  raeburn  9448:                 if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
                   9449:                     push(@{$changes{$type}},'include');
                   9450:                 }
                   9451:             }
                   9452:         }
                   9453:         if (ref($fields) eq 'ARRAY') {
                   9454:             foreach my $field (@{$fields}) {
                   9455:                 if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
                   9456:                     push(@{$changes{'helpform'}},$field);
                   9457:                 }
                   9458:                 if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
                   9459:                     if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
                   9460:                         push(@{$changes{'helpform'}},'maxsize');
                   9461:                     }
                   9462:                 }
1.134     raeburn  9463:             }
1.28      raeburn  9464:         }
                   9465:     }
1.160.6.23  raeburn  9466:     foreach my $item (@toggles) {
                   9467:         if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
                   9468:             $changes{$item} = 1;
                   9469:         } elsif ((!$env{'form.'.$item}) &&
                   9470:                  (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
                   9471:             $changes{$item} = 1;
                   9472:         }
                   9473:     }
1.28      raeburn  9474:     my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
                   9475:                                              $dom);
                   9476:     if ($putresult eq 'ok') {
                   9477:         if (keys(%changes) > 0) {
1.160.6.24  raeburn  9478:             &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27  raeburn  9479:             if (ref($lastactref) eq 'HASH') {
                   9480:                 $lastactref->{'domainconfig'} = 1;
                   9481:             }
1.28      raeburn  9482:             my ($titles,$short_titles)  = &contact_titles();
                   9483:             $resulttext = &mt('Changes made:').'<ul>';
                   9484:             foreach my $item (@contacts) {
                   9485:                 if ($changes{$item}) {
                   9486:                     $resulttext .= '<li>'.$titles->{$item}.
                   9487:                                     &mt(' set to: ').
                   9488:                                     '<span class="LC_cusr_emph">'.
                   9489:                                     $to{$item}.'</span></li>';
                   9490:                 }
                   9491:             }
                   9492:             foreach my $type (@mailings) {
                   9493:                 if (ref($changes{$type}) eq 'ARRAY') {
1.160.6.78  raeburn  9494:                     if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
                   9495:                         $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
                   9496:                     } else {
                   9497:                         $resulttext .= '<li>'.$titles->{$type}.': ';
                   9498:                     }
1.28      raeburn  9499:                     my @text;
                   9500:                     foreach my $item (@{$newsetting{$type}}) {
                   9501:                         push(@text,$short_titles->{$item});
                   9502:                     }
                   9503:                     if ($others{$type} ne '') {
                   9504:                         push(@text,$others{$type});
                   9505:                     }
1.160.6.78  raeburn  9506:                     if (@text) {
                   9507:                         $resulttext .= '<span class="LC_cusr_emph">'.
                   9508:                                        join(', ',@text).'</span>';
                   9509:                     }
                   9510:                     if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134     raeburn  9511:                         if ($bcc{$type} ne '') {
1.160.6.78  raeburn  9512:                             my $bcctext;
                   9513:                             if (@text) {
                   9514:                                 $bcctext = '&nbsp;'.&mt('with Bcc to');
                   9515:                             } else {
                   9516:                                 $bcctext = '(Bcc)';
                   9517:                             }
                   9518:                             $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
                   9519:                         } elsif (!@text) {
                   9520:                             $resulttext .= &mt('No one');
1.134     raeburn  9521:                         }
1.160.6.78  raeburn  9522:                         if ($includestr{$type} ne '') {
                   9523:                             if ($includeloc{$type} eq 'b') {
                   9524:                                 $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
                   9525:                             } elsif ($includeloc{$type} eq 's') {
                   9526:                                 $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
                   9527:                             }
                   9528:                         }
                   9529:                     } elsif (!@text) {
                   9530:                         $resulttext .= &mt('No recipients');
1.134     raeburn  9531:                     }
                   9532:                     $resulttext .= '</li>';
1.28      raeburn  9533:                 }
                   9534:             }
1.160.6.23  raeburn  9535:             my @offon = ('off','on');
                   9536:             if ($changes{'reporterrors'}) {
                   9537:                 $resulttext .= '<li>'.
                   9538:                                &mt('E-mail error reports to [_1] set to "'.
                   9539:                                    $offon[$env{'form.reporterrors'}].'".',
                   9540:                                    &Apache::loncommon::modal_link('http://loncapa.org/core.html',
                   9541:                                        &mt('LON-CAPA core group - MSU'),600,500)).
                   9542:                                '</li>';
                   9543:             }
                   9544:             if ($changes{'reportupdates'}) {
                   9545:                 $resulttext .= '<li>'.
                   9546:                                 &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
                   9547:                                     $offon[$env{'form.reportupdates'}].'".',
                   9548:                                     &Apache::loncommon::modal_link('http://loncapa.org/core.html',
                   9549:                                         &mt('LON-CAPA core group - MSU'),600,500)).
                   9550:                                 '</li>';
                   9551:             }
1.160.6.78  raeburn  9552:             if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
                   9553:                 my (@optional,@required,@unused,$maxsizechg);
                   9554:                 foreach my $field (@{$changes{'helpform'}}) {
                   9555:                     if ($field eq 'maxsize') {
                   9556:                         $maxsizechg = 1;
                   9557:                         next;
                   9558:                     }
                   9559:                     if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
                   9560:                         push(@optional,$field);
                   9561:                     } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
                   9562:                         push(@unused,$field);
                   9563:                     } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
                   9564:                         push(@required,$field);
                   9565:                     }
                   9566:                 }
                   9567:                 if (@optional) {
                   9568:                     $resulttext .= '<li>'.
                   9569:                                    &mt('Help form fields changed to "Optional": [_1].',
                   9570:                                        '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
                   9571:                                    '</li>';
                   9572:                 }
                   9573:                 if (@required) {
                   9574:                     $resulttext .= '<li>'.
                   9575:                                    &mt('Help form fields changed to "Required": [_1].',
                   9576:                                        '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
                   9577:                                    '</li>';
                   9578:                 }
                   9579:                 if (@unused) {
                   9580:                     $resulttext .= '<li>'.
                   9581:                                    &mt('Help form fields changed to "Not shown": [_1].',
                   9582:                                        '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
                   9583:                                    '</li>';
                   9584:                 }
                   9585:                 if ($maxsizechg) {
                   9586:                     $resulttext .= '<li>'.
                   9587:                                    &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
                   9588:                                        $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
                   9589:                                    '</li>';
                   9590: 
                   9591:                 }
                   9592:             }
1.28      raeburn  9593:             $resulttext .= '</ul>';
                   9594:         } else {
1.160.6.78  raeburn  9595:             $resulttext = &mt('No changes made to contacts and form settings');
1.28      raeburn  9596:         }
                   9597:     } else {
                   9598:         $resulttext = '<span class="LC_error">'.
                   9599:             &mt('An error occurred: [_1].',$putresult).'</span>';
                   9600:     }
                   9601:     return $resulttext;
                   9602: }
                   9603: 
                   9604: sub modify_usercreation {
1.27      raeburn  9605:     my ($dom,%domconfig) = @_;
1.160.6.34  raeburn  9606:     my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43      raeburn  9607:     my $warningmsg;
1.27      raeburn  9608:     if (ref($domconfig{'usercreation'}) eq 'HASH') {
                   9609:         foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.160.6.34  raeburn  9610:             if ($key eq 'cancreate') {
                   9611:                 if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
                   9612:                     foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
                   9613:                         if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.160.6.69  raeburn  9614:                             ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
                   9615:                             ($item eq 'recaptchaversion')) {
1.160.6.34  raeburn  9616:                             $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
                   9617:                         } else {
                   9618:                             $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
                   9619:                         }
1.50      raeburn  9620:                     }
1.43      raeburn  9621:                 }
1.160.6.34  raeburn  9622:             } elsif ($key eq 'email_rule') {
                   9623:                 $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
                   9624:             } else {
                   9625:                 $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
1.43      raeburn  9626:             }
                   9627:         }
1.34      raeburn  9628:     }
1.160.6.34  raeburn  9629:     my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
                   9630:     my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
                   9631:     my @contexts = ('author','course','requestcrs');
                   9632:     foreach my $item(@contexts) {
                   9633:         $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93      raeburn  9634:     }
1.34      raeburn  9635:     if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
                   9636:         foreach my $item (@contexts) {
1.160.6.34  raeburn  9637:             if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
                   9638:                 push(@{$changes{'cancreate'}},$item);
1.50      raeburn  9639:             }
1.27      raeburn  9640:         }
1.34      raeburn  9641:     } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
                   9642:         foreach my $item (@contexts) {
1.43      raeburn  9643:             if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34      raeburn  9644:                 if ($cancreate{$item} ne 'any') {
                   9645:                     push(@{$changes{'cancreate'}},$item);
                   9646:                 }
                   9647:             } else {
                   9648:                 if ($cancreate{$item} ne 'none') {
                   9649:                     push(@{$changes{'cancreate'}},$item);
                   9650:                 }
1.27      raeburn  9651:             }
                   9652:         }
                   9653:     } else {
1.43      raeburn  9654:         foreach my $item (@contexts)  {
1.34      raeburn  9655:             push(@{$changes{'cancreate'}},$item);
                   9656:         }
1.27      raeburn  9657:     }
1.34      raeburn  9658: 
1.27      raeburn  9659:     if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
                   9660:         foreach my $type (@{$curr_usercreation{'username_rule'}}) {
                   9661:             if (!grep(/^\Q$type\E$/,@username_rule)) {
                   9662:                 push(@{$changes{'username_rule'}},$type);
                   9663:             }
                   9664:         }
                   9665:         foreach my $type (@username_rule) {
                   9666:             if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
                   9667:                 push(@{$changes{'username_rule'}},$type);
                   9668:             }
                   9669:         }
                   9670:     } else {
                   9671:         push(@{$changes{'username_rule'}},@username_rule);
                   9672:     }
                   9673: 
1.32      raeburn  9674:     if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
                   9675:         foreach my $type (@{$curr_usercreation{'id_rule'}}) {
                   9676:             if (!grep(/^\Q$type\E$/,@id_rule)) {
                   9677:                 push(@{$changes{'id_rule'}},$type);
                   9678:             }
                   9679:         }
                   9680:         foreach my $type (@id_rule) {
                   9681:             if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
                   9682:                 push(@{$changes{'id_rule'}},$type);
                   9683:             }
                   9684:         }
                   9685:     } else {
                   9686:         push(@{$changes{'id_rule'}},@id_rule);
                   9687:     }
                   9688: 
1.43      raeburn  9689:     my @authen_contexts = ('author','course','domain');
1.28      raeburn  9690:     my @authtypes = ('int','krb4','krb5','loc');
                   9691:     my %authhash;
1.43      raeburn  9692:     foreach my $item (@authen_contexts) {
1.28      raeburn  9693:         my @authallowed =  &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
                   9694:         foreach my $auth (@authtypes) {
                   9695:             if (grep(/^\Q$auth\E$/,@authallowed)) {
                   9696:                 $authhash{$item}{$auth} = 1;
                   9697:             } else {
                   9698:                 $authhash{$item}{$auth} = 0;
                   9699:             }
                   9700:         }
                   9701:     }
                   9702:     if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43      raeburn  9703:         foreach my $item (@authen_contexts) {
1.28      raeburn  9704:             if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
                   9705:                 foreach my $auth (@authtypes) {
                   9706:                     if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
                   9707:                         push(@{$changes{'authtypes'}},$item);
                   9708:                         last;
                   9709:                     }
                   9710:                 }
                   9711:             }
                   9712:         }
                   9713:     } else {
1.43      raeburn  9714:         foreach my $item (@authen_contexts) {
1.28      raeburn  9715:             push(@{$changes{'authtypes'}},$item);
                   9716:         }
                   9717:     }
                   9718: 
1.160.6.34  raeburn  9719:     $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'}; 
                   9720:     $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
                   9721:     $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
                   9722:     $save_usercreate{'id_rule'} = \@id_rule;
                   9723:     $save_usercreate{'username_rule'} = \@username_rule,
                   9724:     $save_usercreate{'authtypes'} = \%authhash;
                   9725: 
1.27      raeburn  9726:     my %usercreation_hash =  (
1.160.6.34  raeburn  9727:         usercreation     => \%save_usercreate,
                   9728:     );
1.27      raeburn  9729: 
                   9730:     my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
                   9731:                                              $dom);
1.50      raeburn  9732: 
1.160.6.34  raeburn  9733:     if ($putresult eq 'ok') {
                   9734:         if (keys(%changes) > 0) {
                   9735:             $resulttext = &mt('Changes made:').'<ul>';
                   9736:             if (ref($changes{'cancreate'}) eq 'ARRAY') {
                   9737:                 my %lt = &usercreation_types();
                   9738:                 foreach my $type (@{$changes{'cancreate'}}) {
                   9739:                     my $chgtext = $lt{$type}.', ';
                   9740:                     if ($cancreate{$type} eq 'none') {
                   9741:                         $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
                   9742:                     } elsif ($cancreate{$type} eq 'any') {
                   9743:                         $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
                   9744:                     } elsif ($cancreate{$type} eq 'official') {
                   9745:                         $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
                   9746:                     } elsif ($cancreate{$type} eq 'unofficial') {
                   9747:                         $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
                   9748:                     }
                   9749:                     $resulttext .= '<li>'.$chgtext.'</li>';
                   9750:                 }
                   9751:             }
                   9752:             if (ref($changes{'username_rule'}) eq 'ARRAY') {
                   9753:                 my ($rules,$ruleorder) = 
                   9754:                     &Apache::lonnet::inst_userrules($dom,'username');
                   9755:                 my $chgtext = '<ul>';
                   9756:                 foreach my $type (@username_rule) {
                   9757:                     if (ref($rules->{$type}) eq 'HASH') {
                   9758:                         $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
                   9759:                     }
                   9760:                 }
                   9761:                 $chgtext .= '</ul>';
                   9762:                 if (@username_rule > 0) {
                   9763:                     $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';     
                   9764:                 } else {
                   9765:                     $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>'; 
                   9766:                 }
                   9767:             }
                   9768:             if (ref($changes{'id_rule'}) eq 'ARRAY') {
                   9769:                 my ($idrules,$idruleorder) = 
                   9770:                     &Apache::lonnet::inst_userrules($dom,'id');
                   9771:                 my $chgtext = '<ul>';
                   9772:                 foreach my $type (@id_rule) {
                   9773:                     if (ref($idrules->{$type}) eq 'HASH') {
                   9774:                         $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
                   9775:                     }
                   9776:                 }
                   9777:                 $chgtext .= '</ul>';
                   9778:                 if (@id_rule > 0) {
                   9779:                     $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
                   9780:                 } else {
                   9781:                     $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
                   9782:                 }
                   9783:             }
                   9784:             my %authname = &authtype_names();
                   9785:             my %context_title = &context_names();
                   9786:             if (ref($changes{'authtypes'}) eq 'ARRAY') {
                   9787:                 my $chgtext = '<ul>';
                   9788:                 foreach my $type (@{$changes{'authtypes'}}) {
                   9789:                     my @allowed;
                   9790:                     $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
                   9791:                     foreach my $auth (@authtypes) {
                   9792:                         if ($authhash{$type}{$auth}) {
                   9793:                             push(@allowed,$authname{$auth});
                   9794:                         }
                   9795:                     }
                   9796:                     if (@allowed > 0) {
                   9797:                         $chgtext .= join(', ',@allowed).'</li>';
                   9798:                     } else {
                   9799:                         $chgtext .= &mt('none').'</li>';
                   9800:                     }
                   9801:                 }
                   9802:                 $chgtext .= '</ul>';
                   9803:                 $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
                   9804:                 $resulttext .= '</li>';
                   9805:             }
                   9806:             $resulttext .= '</ul>';
                   9807:         } else {
                   9808:             $resulttext = &mt('No changes made to user creation settings');
                   9809:         }
                   9810:     } else {
                   9811:         $resulttext = '<span class="LC_error">'.
                   9812:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   9813:     }
                   9814:     if ($warningmsg ne '') {
                   9815:         $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
                   9816:     }
                   9817:     return $resulttext;
                   9818: }
                   9819: 
                   9820: sub modify_selfcreation {
                   9821:     my ($dom,%domconfig) = @_;
                   9822:     my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%changes,%cancreate);
                   9823:     my (%save_usercreate,%save_usermodify);
1.160.6.35  raeburn  9824:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   9825:     if (ref($types) eq 'ARRAY') {
                   9826:         $usertypes->{'default'} = $othertitle;
                   9827:         push(@{$types},'default');
                   9828:     }
1.160.6.34  raeburn  9829: #
                   9830: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
                   9831: #
                   9832:     if (ref($domconfig{'usercreation'}) eq 'HASH') {
                   9833:         foreach my $key (keys(%{$domconfig{'usercreation'}})) {
                   9834:             if ($key eq 'cancreate') {
                   9835:                 if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
                   9836:                     foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
                   9837:                         if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
                   9838:                             ($item eq 'captcha') || ($item eq 'recaptchakeys') || 
1.160.6.69  raeburn  9839:                             ($item eq 'recaptchaversion') ||
1.160.6.40  raeburn  9840:                             ($item eq 'emailusername') || ($item eq 'notify') ||
1.160.6.44  raeburn  9841:                             ($item eq 'selfcreateprocessing') || ($item eq 'shibenv')) {
1.160.6.34  raeburn  9842:                             $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
                   9843:                         } else {
                   9844:                             $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
                   9845:                         }
                   9846:                     }
                   9847:                 }
                   9848:             } elsif ($key eq 'email_rule') {
                   9849:                 $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
                   9850:             } else {
                   9851:                 $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
                   9852:             }
                   9853:         }
                   9854:     }
                   9855: #
                   9856: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
                   9857: #
                   9858:     if (ref($domconfig{'usermodification'}) eq 'HASH') {
                   9859:         foreach my $key (keys(%{$domconfig{'usermodification'}})) {
                   9860:             if ($key eq 'selfcreate') {
                   9861:                 $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
                   9862:             } else {
                   9863:                 $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
                   9864:             }
                   9865:         }
                   9866:     }
                   9867: 
                   9868:     my @contexts = ('selfcreate');
                   9869:     @{$cancreate{'selfcreate'}} = ();
                   9870:     %{$cancreate{'emailusername'}} = ();
                   9871:     @{$cancreate{'statustocreate'}} = ();
1.160.6.40  raeburn  9872:     %{$cancreate{'selfcreateprocessing'}} = ();
1.160.6.44  raeburn  9873:     %{$cancreate{'shibenv'}} = ();
1.50      raeburn  9874:     my %selfcreatetypes = (
                   9875:                              sso   => 'users authenticated by institutional single sign on',
                   9876:                              login => 'users authenticated by institutional log-in',
1.160.6.40  raeburn  9877:                              email => 'users who provide a valid e-mail address for use as username',
1.50      raeburn  9878:                           );
1.160.6.34  raeburn  9879: #
                   9880: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
                   9881: # is permitted.
                   9882: #
1.160.6.40  raeburn  9883: 
                   9884:     my @statuses;
                   9885:     if (ref($domconfig{'inststatus'}) eq 'HASH') {
                   9886:         if (ref($domconfig{'inststatus'}{'inststatusguest'}) eq 'ARRAY') {
                   9887:             @statuses = @{$domconfig{'inststatus'}{'inststatusguest'}};
                   9888:         }
                   9889:     }
                   9890:     push(@statuses,'default');
                   9891: 
1.160.6.35  raeburn  9892:     foreach my $item ('login','sso','email') {
1.160.6.34  raeburn  9893:         if ($item eq 'email') {
1.160.6.40  raeburn  9894:             if ($env{'form.cancreate_email'}) {
1.160.6.34  raeburn  9895:                 push(@{$cancreate{'selfcreate'}},'email');
1.160.6.40  raeburn  9896:                 push(@contexts,'selfcreateprocessing');
                   9897:                 foreach my $type (@statuses) {
                   9898:                     if ($type eq 'default') {
                   9899:                         $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess'};
                   9900:                     } else { 
                   9901:                         $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
                   9902:                     }
                   9903:                 }
1.160.6.34  raeburn  9904:             }
                   9905:         } else {
                   9906:             if ($env{'form.cancreate_'.$item}) {
                   9907:                 push(@{$cancreate{'selfcreate'}},$item);
                   9908:             }
                   9909:         }
                   9910:     }
                   9911:     my (@email_rule,%userinfo,%savecaptcha);
                   9912:     my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
                   9913: #
1.160.6.35  raeburn  9914: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
                   9915: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.160.6.34  raeburn  9916: #
1.160.6.40  raeburn  9917: 
1.160.6.48  raeburn  9918:     if ($env{'form.cancreate_email'}) {
1.160.6.37  raeburn  9919:         push(@contexts,'emailusername');
1.160.6.35  raeburn  9920:         if (ref($types) eq 'ARRAY') {
                   9921:             foreach my $type (@{$types}) {
                   9922:                 if (ref($infofields) eq 'ARRAY') {
                   9923:                     foreach my $field (@{$infofields}) {
                   9924:                         if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
                   9925:                             $cancreate{'emailusername'}{$type}{$field} = $1;
                   9926:                         }
                   9927:                     }
1.160.6.34  raeburn  9928:                 }
                   9929:             }
                   9930:         }
                   9931: #
                   9932: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
                   9933: # queued requests for self-creation of account using e-mail address as username
                   9934: #
                   9935: 
                   9936:         my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
                   9937:         @approvalnotify = sort(@approvalnotify);
                   9938:         $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
                   9939:         if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
                   9940:             if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
                   9941:                 if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
                   9942:                     push(@{$changes{'cancreate'}},'notify');
                   9943:                 }
                   9944:             } else {
                   9945:                 if ($cancreate{'notify'}{'approval'}) {
                   9946:                     push(@{$changes{'cancreate'}},'notify');
                   9947:                 }
                   9948:             }
                   9949:         } elsif ($cancreate{'notify'}{'approval'}) {
                   9950:             push(@{$changes{'cancreate'}},'notify');
                   9951:         }
                   9952: 
                   9953: #
                   9954: # Retrieve rules (if any) governing types of e-mail address which may be used as a username
                   9955: #
                   9956:         @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
                   9957:         &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
                   9958:         if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
                   9959:             if (@{$curr_usercreation{'email_rule'}} > 0) {
                   9960:                 foreach my $type (@{$curr_usercreation{'email_rule'}}) {
                   9961:                     if (!grep(/^\Q$type\E$/,@email_rule)) {
                   9962:                         push(@{$changes{'email_rule'}},$type);
                   9963:                     }
                   9964:                 }
                   9965:             }
                   9966:             if (@email_rule > 0) {
                   9967:                 foreach my $type (@email_rule) {
                   9968:                     if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
                   9969:                         push(@{$changes{'email_rule'}},$type);
                   9970:                     }
                   9971:                 }
                   9972:             }
                   9973:         } elsif (@email_rule > 0) {
                   9974:             push(@{$changes{'email_rule'}},@email_rule);
                   9975:         }
                   9976:     }
                   9977: #  
1.160.6.40  raeburn  9978: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.160.6.34  raeburn  9979: # institutional log-in.
                   9980: #
                   9981:     if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
                   9982:         my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
                   9983:         if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) || 
                   9984:                ($domdefaults{'auth_def'} eq 'localauth'))) {
                   9985:             $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.').' '.
                   9986:                           &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.');
                   9987:         }
                   9988:     }
                   9989:     my @fields = ('lastname','firstname','middlename','generation',
                   9990:                   'permanentemail','id');
1.160.6.44  raeburn  9991:     my @shibfields = (@fields,'inststatus');
1.160.6.34  raeburn  9992:     my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
                   9993: #
                   9994: # Where usernames may created for institutional log-in and/or institutional single sign on:
                   9995: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
                   9996: # may self-create accounts 
                   9997: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
                   9998: # which the user may supply, if institutional data is unavailable.
                   9999: #
                   10000:     if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
                   10001:         if (ref($types) eq 'ARRAY') {
1.160.6.35  raeburn  10002:             if (@{$types} > 1) {
1.160.6.34  raeburn  10003:                 @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
                   10004:                 push(@contexts,'statustocreate');
                   10005:             } else {
                   10006:                 undef($cancreate{'statustocreate'});
                   10007:             } 
                   10008:             foreach my $type (@{$types}) {
                   10009:                 my @modifiable =  &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
                   10010:                 foreach my $field (@fields) {
                   10011:                     if (grep(/^\Q$field\E$/,@modifiable)) {
                   10012:                         $save_usermodify{'selfcreate'}{$type}{$field} = 1;
                   10013:                     } else {
                   10014:                         $save_usermodify{'selfcreate'}{$type}{$field} = 0;
                   10015:                     }
                   10016:                 }
                   10017:             }
                   10018:             if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
                   10019:                 foreach my $type (@{$types}) {
                   10020:                     if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
                   10021:                         foreach my $field (@fields) {
                   10022:                             if ($save_usermodify{'selfcreate'}{$type}{$field} ne
                   10023:                                 $curr_usermodify{'selfcreate'}{$type}{$field}) {
                   10024:                                 push(@{$changes{'selfcreate'}},$type);
                   10025:                                 last;
                   10026:                             }
                   10027:                         }
                   10028:                     }
                   10029:                 }
                   10030:             } else {
                   10031:                 foreach my $type (@{$types}) {
                   10032:                     push(@{$changes{'selfcreate'}},$type);
                   10033:                 }
                   10034:             }
                   10035:         }
1.160.6.44  raeburn  10036:         foreach my $field (@shibfields) {
                   10037:             if ($env{'form.shibenv_'.$field} ne '') {
                   10038:                 $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
                   10039:             }
                   10040:         }
                   10041:         if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
                   10042:             if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
                   10043:                 foreach my $field (@shibfields) {
                   10044:                     if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
                   10045:                         push(@{$changes{'cancreate'}},'shibenv');
                   10046:                     }
                   10047:                 }
                   10048:             } else {
                   10049:                 foreach my $field (@shibfields) {
                   10050:                     if ($env{'form.shibenv_'.$field}) {
                   10051:                         push(@{$changes{'cancreate'}},'shibenv');
                   10052:                         last;
                   10053:                     }
                   10054:                 }
                   10055:             }
                   10056:         }
1.160.6.34  raeburn  10057:     }
                   10058:     foreach my $item (@contexts) {
                   10059:         if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
                   10060:             foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
                   10061:                 if (ref($cancreate{$item}) eq 'ARRAY') {
                   10062:                     if (!grep(/^$curr$/,@{$cancreate{$item}})) {
                   10063:                         if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   10064:                             push(@{$changes{'cancreate'}},$item);
                   10065:                         }
                   10066:                     }
                   10067:                 }
                   10068:             }
                   10069:             if (ref($cancreate{$item}) eq 'ARRAY') {
                   10070:                 foreach my $type (@{$cancreate{$item}}) {
                   10071:                     if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
                   10072:                         if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   10073:                             push(@{$changes{'cancreate'}},$item);
                   10074:                         }
                   10075:                     }
                   10076:                 }
                   10077:             }
                   10078:         } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
                   10079:             if (ref($cancreate{$item}) eq 'HASH') {
                   10080:                 foreach my $curr (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
1.160.6.35  raeburn  10081:                     if (ref($curr_usercreation{'cancreate'}{$item}{$curr}) eq 'HASH') {
                   10082:                         foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$curr}})) {
                   10083:                             unless ($curr_usercreation{'cancreate'}{$item}{$curr}{$field} eq $cancreate{$item}{$curr}{$field}) {
                   10084:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   10085:                                     push(@{$changes{'cancreate'}},$item);
                   10086:                                 }
                   10087:                             }
                   10088:                         }
1.160.6.40  raeburn  10089:                     } elsif ($item eq 'selfcreateprocessing') {
                   10090:                         if ($cancreate{$item}{$curr} ne $curr_usercreation{'cancreate'}{$item}{$curr}) {
                   10091:                             if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   10092:                                 push(@{$changes{'cancreate'}},$item);
                   10093:                             }
                   10094:                         }
1.160.6.35  raeburn  10095:                     } else {
                   10096:                         if (!$cancreate{$item}{$curr}) {
                   10097:                             if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   10098:                                 push(@{$changes{'cancreate'}},$item);
                   10099:                             }
1.160.6.34  raeburn  10100:                         }
                   10101:                     }
                   10102:                 }
                   10103:                 foreach my $field (keys(%{$cancreate{$item}})) {
1.160.6.35  raeburn  10104:                     if (ref($cancreate{$item}{$field}) eq 'HASH') {
                   10105:                         foreach my $inner (keys(%{$cancreate{$item}{$field}})) {
                   10106:                             if (ref($curr_usercreation{'cancreate'}{$item}{$field}) eq 'HASH') {
                   10107:                                 unless ($curr_usercreation{'cancreate'}{$item}{$field}{$inner} eq $cancreate{$item}{$field}{$inner}) {
                   10108:                                     if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   10109:                                         push(@{$changes{'cancreate'}},$item);
                   10110:                                     }
                   10111:                                 }
                   10112:                             } else {
                   10113:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   10114:                                     push(@{$changes{'cancreate'}},$item);
                   10115:                                 }
                   10116:                             }
                   10117:                         }
1.160.6.40  raeburn  10118:                     } elsif ($item eq 'selfcreateprocessing') {
                   10119:                         if ($cancreate{$item}{$field} ne $curr_usercreation{'cancreate'}{$item}{$field}) {
                   10120:                             if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   10121:                                 push(@{$changes{'cancreate'}},$item);
                   10122:                             }
                   10123:                         }
1.160.6.35  raeburn  10124:                     } else {
                   10125:                         if (!$curr_usercreation{'cancreate'}{$item}{$field}) {
                   10126:                             if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   10127:                                 push(@{$changes{'cancreate'}},$item);
                   10128:                             }
1.160.6.34  raeburn  10129:                         }
                   10130:                     }
                   10131:                 }
                   10132:             }
                   10133:         } elsif ($curr_usercreation{'cancreate'}{$item}) {
                   10134:             if (ref($cancreate{$item}) eq 'ARRAY') {
                   10135:                 if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
                   10136:                     if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   10137:                         push(@{$changes{'cancreate'}},$item);
                   10138:                     }
                   10139:                 }
                   10140:             } elsif (ref($cancreate{$item}) eq 'HASH') {
                   10141:                 if (!$cancreate{$item}{$curr_usercreation{'cancreate'}{$item}}) {
                   10142:                     if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   10143:                         push(@{$changes{'cancreate'}},$item);
                   10144:                     }
                   10145:                 }
                   10146:             }
                   10147:         } elsif ($item eq 'emailusername') {
1.160.6.35  raeburn  10148:             if (ref($cancreate{$item}) eq 'HASH') {
                   10149:                 foreach my $type (keys(%{$cancreate{$item}})) {
                   10150:                     if (ref($cancreate{$item}{$type}) eq 'HASH') {
                   10151:                         foreach my $field (keys(%{$cancreate{$item}{$type}})) {
                   10152:                             if ($cancreate{$item}{$type}{$field}) {
                   10153:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   10154:                                     push(@{$changes{'cancreate'}},$item);
                   10155:                                 }
                   10156:                                 last;
                   10157:                             }
                   10158:                         }
                   10159:                     }
                   10160:                 }
1.160.6.34  raeburn  10161:             }
                   10162:         }
                   10163:     }
                   10164: #
                   10165: # Populate %save_usercreate hash with updates to self-creation configuration.
                   10166: #
                   10167:     $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
                   10168:     $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.160.6.69  raeburn  10169:     $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.160.6.34  raeburn  10170:     $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
                   10171:     if (ref($cancreate{'notify'}) eq 'HASH') {
                   10172:         $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
                   10173:     }
1.160.6.40  raeburn  10174:     if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
                   10175:         $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
                   10176:     }
1.160.6.34  raeburn  10177:     if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
                   10178:         $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
                   10179:     }
1.160.6.44  raeburn  10180:     if (ref($cancreate{'shibenv'}) eq 'HASH') {
                   10181:         $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
                   10182:     }
1.160.6.34  raeburn  10183:     $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.160.6.85  raeburn  10184:     $save_usercreate{'email_rule'} = \@email_rule;
1.160.6.34  raeburn  10185: 
                   10186:     my %userconfig_hash = (
                   10187:             usercreation     => \%save_usercreate,
                   10188:             usermodification => \%save_usermodify,
                   10189:     );
                   10190:     my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
                   10191:                                              $dom);
                   10192: #
                   10193: # Accumulate details of changes to domain cofiguration for self-creation of usernames in $resulttext
                   10194: #
1.27      raeburn  10195:     if ($putresult eq 'ok') {
                   10196:         if (keys(%changes) > 0) {
                   10197:             $resulttext = &mt('Changes made:').'<ul>';
                   10198:             if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.160.6.34  raeburn  10199:                 my %lt = &selfcreation_types();
1.34      raeburn  10200:                 foreach my $type (@{$changes{'cancreate'}}) {
1.100     raeburn  10201:                     my $chgtext;
1.45      raeburn  10202:                     if ($type eq 'selfcreate') {
1.50      raeburn  10203:                         if (@{$cancreate{$type}} == 0) {
1.160.6.34  raeburn  10204:                             $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50      raeburn  10205:                         } else {
1.160.6.34  raeburn  10206:                             $chgtext .= &mt('Self-creation of a new account is permitted for:').
                   10207:                                         '<ul>';
1.50      raeburn  10208:                             foreach my $case (@{$cancreate{$type}}) {
                   10209:                                 $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
                   10210:                             }
                   10211:                             $chgtext .= '</ul>';
1.100     raeburn  10212:                             if (ref($cancreate{$type}) eq 'ARRAY') {
                   10213:                                 if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
                   10214:                                     if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
                   10215:                                         if (@{$cancreate{'statustocreate'}} == 0) {
1.160.6.34  raeburn  10216:                                             $chgtext .= '<br />'.
                   10217:                                                         '<span class="LC_warning">'.
                   10218:                                                         &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
                   10219:                                                         '</span>';
1.100     raeburn  10220:                                         }
                   10221:                                     }
                   10222:                                 }
                   10223:                             }
1.43      raeburn  10224:                         }
1.160.6.44  raeburn  10225:                     } elsif ($type eq 'shibenv') {
                   10226:                         if (keys(%{$cancreate{$type}}) == 0) {
                   10227:                             $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information'); 
                   10228:                         } else {
                   10229:                             $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
                   10230:                                         '<ul>';
                   10231:                             foreach my $field (@shibfields) {
                   10232:                                 next if ($cancreate{$type}{$field} eq '');
                   10233:                                 if ($field eq 'inststatus') {
                   10234:                                     $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
                   10235:                                 } else {
                   10236:                                     $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
                   10237:                                 }
                   10238:                             }
                   10239:                             $chgtext .= '</ul>';
                   10240:                         }  
1.93      raeburn  10241:                     } elsif ($type eq 'statustocreate') {
1.96      raeburn  10242:                         if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
                   10243:                             (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
                   10244:                             if (@{$cancreate{'selfcreate'}} > 0) {
                   10245:                                 if (@{$cancreate{'statustocreate'}} == 0) {
1.100     raeburn  10246:                                     $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96      raeburn  10247:                                     if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.160.6.34  raeburn  10248:                                         $chgtext .= '<br />'.
                   10249:                                                     '<span class="LC_warning">'.
                   10250:                                                     &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
                   10251:                                                     '</span>';
                   10252:                                     }
1.96      raeburn  10253:                                 } elsif (ref($usertypes) eq 'HASH') {
                   10254:                                     if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100     raeburn  10255:                                         $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
                   10256:                                     } else {
                   10257:                                         $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
                   10258:                                     }
                   10259:                                     $chgtext .= '<ul>';
                   10260:                                     foreach my $case (@{$cancreate{$type}}) {
                   10261:                                         if ($case eq 'default') {
                   10262:                                             $chgtext .= '<li>'.$othertitle.'</li>';
                   10263:                                         } else {
                   10264:                                             $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93      raeburn  10265:                                         }
                   10266:                                     }
1.100     raeburn  10267:                                     $chgtext .= '</ul>';
                   10268:                                     if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.160.6.34  raeburn  10269:                                         $chgtext .= '<br /><span class="LC_warning">'.
                   10270:                                                     &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
                   10271:                                                     '</span>';
1.100     raeburn  10272:                                     }
                   10273:                                 }
                   10274:                             } else {
                   10275:                                 if (@{$cancreate{$type}} == 0) {
                   10276:                                     $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
                   10277:                                 } else {
                   10278:                                     $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  10279:                                 }
                   10280:                             }
                   10281:                         }
1.160.6.40  raeburn  10282:                     } elsif ($type eq 'selfcreateprocessing') {
                   10283:                         my %choices = &Apache::lonlocal::texthash (
                   10284:                                                                     automatic => 'Automatic approval',
                   10285:                                                                     approval  => 'Queued for approval',
                   10286:                                                                   );
                   10287:                         if (@statuses > 1) {
                   10288:                             $chgtext .= &mt('Processing of requests to create account with e-mail address as username set as follows:'). 
                   10289:                                         '<ul>';
                   10290:                            foreach my $type (@statuses) {
                   10291:                                if ($type eq 'default') {
                   10292:                                    $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
                   10293:                                } else {
                   10294:                                    $chgtext .= '<li>'.$usertypes->{$type}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
                   10295:                                }
                   10296:                            }
                   10297:                            $chgtext .= '</ul>';
                   10298:                         } else {
                   10299:                            $chgtext .= &mt('Processing of requests to create account with e-mail address as username set to: "[_1]"',
                   10300:                                          $choices{$cancreate{'selfcreateprocessing'}{'default'}});
                   10301:                         }
1.160.6.5  raeburn  10302:                     } elsif ($type eq 'captcha') {
1.160.6.34  raeburn  10303:                         if ($savecaptcha{$type} eq 'notused') {
1.160.6.5  raeburn  10304:                             $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
                   10305:                         } else {
                   10306:                             my %captchas = &captcha_phrases();
1.160.6.34  raeburn  10307:                             if ($captchas{$savecaptcha{$type}}) {
                   10308:                                 $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.160.6.5  raeburn  10309:                             } else {
                   10310:                                 $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
                   10311:                             }
                   10312:                         }
                   10313:                     } elsif ($type eq 'recaptchakeys') {
                   10314:                         my ($privkey,$pubkey);
1.160.6.34  raeburn  10315:                         if (ref($savecaptcha{$type}) eq 'HASH') {
                   10316:                             $pubkey = $savecaptcha{$type}{'public'};
                   10317:                             $privkey = $savecaptcha{$type}{'private'};
1.160.6.5  raeburn  10318:                         }
                   10319:                         $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
                   10320:                         if (!$pubkey) {
                   10321:                             $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
                   10322:                         } else {
                   10323:                             $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
                   10324:                         }
                   10325:                         if (!$privkey) {
                   10326:                             $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
                   10327:                         } else {
                   10328:                             $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
                   10329:                         }
                   10330:                         $chgtext .= '</ul>';
1.160.6.69  raeburn  10331:                     } elsif ($type eq 'recaptchaversion') {
                   10332:                         if ($savecaptcha{'captcha'} eq 'recaptcha') {
                   10333:                             $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
                   10334:                         }
1.160.6.34  raeburn  10335:                     } elsif ($type eq 'emailusername') {
                   10336:                         if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.160.6.35  raeburn  10337:                             if (ref($types) eq 'ARRAY') {
                   10338:                                 foreach my $type (@{$types}) {
                   10339:                                     if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
                   10340:                                         if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.160.6.50  raeburn  10341:                                             $chgtext .= &mt('When self-creating account with e-mail as username, the following information will be provided by [_1]:',"'$usertypes->{$type}'").
1.160.6.35  raeburn  10342:                                                     '<ul>';
                   10343:                                             foreach my $field (@{$infofields}) {
                   10344:                                                 if ($cancreate{'emailusername'}{$type}{$field}) {
                   10345:                                                     $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
                   10346:                                                 }
                   10347:                                             }
1.160.6.50  raeburn  10348:                                             $chgtext .= '</ul>';
                   10349:                                         } else {
                   10350:                                             $chgtext .= &mt('When self creating account with e-mail as username, no information besides e-mail address will be provided by [_1].',"'$usertypes->{$type}'").'<br />';
1.160.6.35  raeburn  10351:                                         }
                   10352:                                     } else {
1.160.6.50  raeburn  10353:                                         $chgtext .= &mt('When self creating account with e-mail as username, no information besides e-mail address will be provided by [_1].',"'$usertypes->{$type}'").'<br />';
1.160.6.34  raeburn  10354:                                     }
                   10355:                                 }
                   10356:                             }
                   10357:                         }
                   10358:                     } elsif ($type eq 'notify') {
                   10359:                         $chgtext = &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
                   10360:                         if (ref($changes{'cancreate'}) eq 'ARRAY') {
                   10361:                             if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
                   10362:                                 if ($cancreate{'notify'}{'approval'}) {
                   10363:                                     $chgtext = &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
                   10364:                                 }
                   10365:                             }
1.43      raeburn  10366:                         }
1.34      raeburn  10367:                     }
1.160.6.34  raeburn  10368:                     if ($chgtext) {
                   10369:                         $resulttext .= '<li>'.$chgtext.'</li>';
1.32      raeburn  10370:                     }
                   10371:                 }
                   10372:             }
1.43      raeburn  10373:             if (ref($changes{'email_rule'}) eq 'ARRAY') {
                   10374:                 my ($emailrules,$emailruleorder) =
                   10375:                     &Apache::lonnet::inst_userrules($dom,'email');
                   10376:                 my $chgtext = '<ul>';
                   10377:                 foreach my $type (@email_rule) {
                   10378:                     if (ref($emailrules->{$type}) eq 'HASH') {
                   10379:                         $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
                   10380:                     }
                   10381:                 }
                   10382:                 $chgtext .= '</ul>';
                   10383:                 if (@email_rule > 0) {
1.160.6.34  raeburn  10384:                     $resulttext .= '<li>'.
                   10385:                                    &mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').
                   10386:                                        $chgtext.
                   10387:                                    '</li>';
1.43      raeburn  10388:                 } else {
1.160.6.34  raeburn  10389:                     $resulttext .= '<li>'.
                   10390:                                    &mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').
                   10391:                                    '</li>';
1.43      raeburn  10392:                 }
                   10393:             }
1.160.6.34  raeburn  10394:             if (ref($changes{'selfcreate'}) eq 'ARRAY') {
                   10395:                 $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
                   10396:                 my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
                   10397:                 foreach my $type (@{$changes{'selfcreate'}}) {
                   10398:                     my $typename = $type;
                   10399:                     if (ref($usertypes) eq 'HASH') {
                   10400:                         if ($usertypes->{$type} ne '') {
                   10401:                             $typename = $usertypes->{$type};
1.28      raeburn  10402:                         }
                   10403:                     }
1.160.6.34  raeburn  10404:                     my @modifiable;
                   10405:                     $resulttext .= '<li>'.
                   10406:                                     &mt('Self-creation of account by users with status: [_1]',
                   10407:                                         '<span class="LC_cusr_emph">'.$typename.'</span>').
                   10408:                                     ' - '.&mt('modifiable fields (if institutional data blank): ');
                   10409:                     foreach my $field (@fields) {
                   10410:                         if ($save_usermodify{'selfcreate'}{$type}{$field}) {
                   10411:                             push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
                   10412:                         }
                   10413:                     }
                   10414:                     if (@modifiable > 0) {
                   10415:                         $resulttext .= join(', ',@modifiable);
1.43      raeburn  10416:                     } else {
1.160.6.34  raeburn  10417:                         $resulttext .= &mt('none');
1.43      raeburn  10418:                     }
1.160.6.34  raeburn  10419:                     $resulttext .= '</li>';
1.28      raeburn  10420:                 }
1.160.6.34  raeburn  10421:                 $resulttext .= '</ul></li>';
1.28      raeburn  10422:             }
1.27      raeburn  10423:             $resulttext .= '</ul>';
                   10424:         } else {
1.160.6.34  raeburn  10425:             $resulttext = &mt('No changes made to self-creation settings');
1.27      raeburn  10426:         }
                   10427:     } else {
                   10428:         $resulttext = '<span class="LC_error">'.
1.23      raeburn  10429:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   10430:     }
1.43      raeburn  10431:     if ($warningmsg ne '') {
                   10432:         $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
                   10433:     }
1.23      raeburn  10434:     return $resulttext;
                   10435: }
                   10436: 
1.160.6.5  raeburn  10437: sub process_captcha {
                   10438:     my ($container,$changes,$newsettings,$current) = @_;
                   10439:     return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
                   10440:     $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
                   10441:     unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
                   10442:         $newsettings->{'captcha'} = 'original';
                   10443:     }
                   10444:     if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
                   10445:         if ($container eq 'cancreate') {
                   10446:             if (ref($changes->{'cancreate'}) eq 'ARRAY') {
                   10447:                 push(@{$changes->{'cancreate'}},'captcha');
                   10448:             } elsif (!defined($changes->{'cancreate'})) {
                   10449:                 $changes->{'cancreate'} = ['captcha'];
                   10450:             }
                   10451:         } else {
                   10452:             $changes->{'captcha'} = 1;
                   10453:         }
                   10454:     }
1.160.6.69  raeburn  10455:     my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.160.6.5  raeburn  10456:     if ($newsettings->{'captcha'} eq 'recaptcha') {
                   10457:         $newpub = $env{'form.'.$container.'_recaptchapub'};
                   10458:         $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.160.6.52  raeburn  10459:         $newpub =~ s/[^\w\-]//g;
                   10460:         $newpriv =~ s/[^\w\-]//g;
1.160.6.5  raeburn  10461:         $newsettings->{'recaptchakeys'} = {
                   10462:                                              public  => $newpub,
                   10463:                                              private => $newpriv,
                   10464:                                           };
1.160.6.69  raeburn  10465:         $newversion = $env{'form.'.$container.'_recaptchaversion'};
                   10466:         $newversion =~ s/\D//g;
                   10467:         if ($newversion ne '2') {
                   10468:             $newversion = 1;
                   10469:         }
                   10470:         $newsettings->{'recaptchaversion'} = $newversion;
1.160.6.5  raeburn  10471:     }
                   10472:     if (ref($current->{'recaptchakeys'}) eq 'HASH') {
                   10473:         $currpub = $current->{'recaptchakeys'}{'public'};
                   10474:         $currpriv = $current->{'recaptchakeys'}{'private'};
1.160.6.10  raeburn  10475:         unless ($newsettings->{'captcha'} eq 'recaptcha') {
                   10476:             $newsettings->{'recaptchakeys'} = {
                   10477:                                                  public  => '',
                   10478:                                                  private => '',
                   10479:                                               }
                   10480:         }
1.160.6.5  raeburn  10481:     }
1.160.6.69  raeburn  10482:     if ($current->{'captcha'} eq 'recaptcha') {
                   10483:         $currversion = $current->{'recaptchaversion'};
                   10484:         if ($currversion ne '2') {
                   10485:             $currversion = 1;
                   10486:         }
                   10487:     }
                   10488:     if ($currversion ne $newversion) {
                   10489:         if ($container eq 'cancreate') {
                   10490:             if (ref($changes->{'cancreate'}) eq 'ARRAY') {
                   10491:                 push(@{$changes->{'cancreate'}},'recaptchaversion');
                   10492:             } elsif (!defined($changes->{'cancreate'})) {
                   10493:                 $changes->{'cancreate'} = ['recaptchaversion'];
                   10494:             }
                   10495:         } else {
                   10496:             $changes->{'recaptchaversion'} = 1;
                   10497:         }
                   10498:     }
1.160.6.5  raeburn  10499:     if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
                   10500:         if ($container eq 'cancreate') {
                   10501:             if (ref($changes->{'cancreate'}) eq 'ARRAY') {
                   10502:                 push(@{$changes->{'cancreate'}},'recaptchakeys');
                   10503:             } elsif (!defined($changes->{'cancreate'})) {
                   10504:                 $changes->{'cancreate'} = ['recaptchakeys'];
                   10505:             }
                   10506:         } else {
                   10507:             $changes->{'recaptchakeys'} = 1;
                   10508:         }
                   10509:     }
                   10510:     return;
                   10511: }
                   10512: 
1.33      raeburn  10513: sub modify_usermodification {
                   10514:     my ($dom,%domconfig) = @_;
1.160.6.34  raeburn  10515:     my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33      raeburn  10516:     if (ref($domconfig{'usermodification'}) eq 'HASH') {
                   10517:         foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.160.6.34  raeburn  10518:             if ($key eq 'selfcreate') {
                   10519:                 $modifyhash{$key} = $domconfig{'usermodification'}{$key};
                   10520:             } else {  
                   10521:                 $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
                   10522:             }
1.33      raeburn  10523:         }
                   10524:     }
1.160.6.34  raeburn  10525:     my @contexts = ('author','course');
1.33      raeburn  10526:     my %context_title = (
                   10527:                            author => 'In author context',
                   10528:                            course => 'In course context',
                   10529:                         );
                   10530:     my @fields = ('lastname','firstname','middlename','generation',
                   10531:                   'permanentemail','id');
                   10532:     my %roles = (
                   10533:                   author => ['ca','aa'],
                   10534:                   course => ['st','ep','ta','in','cr'],
                   10535:                 );
                   10536:     my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
                   10537:     foreach my $context (@contexts) {
                   10538:         foreach my $role (@{$roles{$context}}) {
                   10539:             my @modifiable =  &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
                   10540:             foreach my $item (@fields) {
                   10541:                 if (grep(/^\Q$item\E$/,@modifiable)) {
                   10542:                     $modifyhash{$context}{$role}{$item} = 1;
                   10543:                 } else {
                   10544:                     $modifyhash{$context}{$role}{$item} = 0;
                   10545:                 }
                   10546:             }
                   10547:         }
                   10548:         if (ref($curr_usermodification{$context}) eq 'HASH') {
                   10549:             foreach my $role (@{$roles{$context}}) {
                   10550:                 if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
                   10551:                     foreach my $field (@fields) {
                   10552:                         if ($modifyhash{$context}{$role}{$field} ne 
                   10553:                                 $curr_usermodification{$context}{$role}{$field}) {
                   10554:                             push(@{$changes{$context}},$role);
                   10555:                             last;
                   10556:                         }
                   10557:                     }
                   10558:                 }
                   10559:             }
                   10560:         } else {
                   10561:             foreach my $context (@contexts) {
                   10562:                 foreach my $role (@{$roles{$context}}) {
                   10563:                     push(@{$changes{$context}},$role);
                   10564:                 }
                   10565:             }
                   10566:         }
                   10567:     }
                   10568:     my %usermodification_hash =  (
                   10569:                                    usermodification => \%modifyhash,
                   10570:                                  );
                   10571:     my $putresult = &Apache::lonnet::put_dom('configuration',
                   10572:                                              \%usermodification_hash,$dom);
                   10573:     if ($putresult eq 'ok') {
                   10574:         if (keys(%changes) > 0) {
                   10575:             $resulttext = &mt('Changes made: ').'<ul>';
                   10576:             foreach my $context (@contexts) {
                   10577:                 if (ref($changes{$context}) eq 'ARRAY') {
                   10578:                     $resulttext .= '<li>'.$context_title{$context}.':<ul>';
                   10579:                     if (ref($changes{$context}) eq 'ARRAY') {
                   10580:                         foreach my $role (@{$changes{$context}}) {
                   10581:                             my $rolename;
1.160.6.34  raeburn  10582:                             if ($role eq 'cr') {
                   10583:                                 $rolename = &mt('Custom');
1.33      raeburn  10584:                             } else {
1.160.6.34  raeburn  10585:                                 $rolename = &Apache::lonnet::plaintext($role);
1.33      raeburn  10586:                             }
                   10587:                             my @modifiable;
1.160.6.34  raeburn  10588:                             $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33      raeburn  10589:                             foreach my $field (@fields) {
                   10590:                                 if ($modifyhash{$context}{$role}{$field}) {
                   10591:                                     push(@modifiable,$fieldtitles{$field});
                   10592:                                 }
                   10593:                             }
                   10594:                             if (@modifiable > 0) {
                   10595:                                 $resulttext .= join(', ',@modifiable);
                   10596:                             } else {
                   10597:                                 $resulttext .= &mt('none'); 
                   10598:                             }
                   10599:                             $resulttext .= '</li>';
                   10600:                         }
                   10601:                         $resulttext .= '</ul></li>';
                   10602:                     }
                   10603:                 }
                   10604:             }
                   10605:             $resulttext .= '</ul>';
                   10606:         } else {
                   10607:             $resulttext = &mt('No changes made to user modification settings');
                   10608:         }
                   10609:     } else {
                   10610:         $resulttext = '<span class="LC_error">'.
                   10611:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   10612:     }
                   10613:     return $resulttext;
                   10614: }
                   10615: 
1.43      raeburn  10616: sub modify_defaults {
1.160.6.27  raeburn  10617:     my ($dom,$lastactref,%domconfig) = @_;
1.43      raeburn  10618:     my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.160.6.27  raeburn  10619:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.80  raeburn  10620:     my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
                   10621:                  'portal_def','intauth_cost','intauth_check','intauth_switch');
1.43      raeburn  10622:     my @authtypes = ('internal','krb4','krb5','localauth');
                   10623:     foreach my $item (@items) {
                   10624:         $newvalues{$item} = $env{'form.'.$item};
                   10625:         if ($item eq 'auth_def') {
                   10626:             if ($newvalues{$item} ne '') {
                   10627:                 if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
                   10628:                     push(@errors,$item);
                   10629:                 }
                   10630:             }
                   10631:         } elsif ($item eq 'lang_def') {
                   10632:             if ($newvalues{$item} ne '') {
                   10633:                 if ($newvalues{$item} =~ /^(\w+)/) {
                   10634:                     my $langcode = $1;
1.103     raeburn  10635:                     if ($langcode ne 'x_chef') {
                   10636:                         if (code2language($langcode) eq '') {
                   10637:                             push(@errors,$item);
                   10638:                         }
1.43      raeburn  10639:                     }
                   10640:                 } else {
                   10641:                     push(@errors,$item);
                   10642:                 }
                   10643:             }
1.54      raeburn  10644:         } elsif ($item eq 'timezone_def') {
                   10645:             if ($newvalues{$item} ne '') {
1.62      raeburn  10646:                 if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54      raeburn  10647:                     push(@errors,$item);   
                   10648:                 }
                   10649:             }
1.68      raeburn  10650:         } elsif ($item eq 'datelocale_def') {
                   10651:             if ($newvalues{$item} ne '') {
                   10652:                 my @datelocale_ids = DateTime::Locale->ids();
                   10653:                 if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
                   10654:                     push(@errors,$item);
                   10655:                 }
                   10656:             }
1.141     raeburn  10657:         } elsif ($item eq 'portal_def') {
                   10658:             if ($newvalues{$item} ne '') {
                   10659:                 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])\/?$/) {
                   10660:                     push(@errors,$item);
                   10661:                 }
                   10662:             }
1.160.6.80  raeburn  10663:         } elsif ($item eq 'intauth_cost') {
                   10664:             if ($newvalues{$item} ne '') {
                   10665:                 if ($newvalues{$item} =~ /\D/) {
                   10666:                     push(@errors,$item);
                   10667:                 }
                   10668:             }
                   10669:         } elsif ($item eq 'intauth_check') {
                   10670:             if ($newvalues{$item} ne '') {
                   10671:                 unless ($newvalues{$item} =~ /^(0|1|2)$/) {
                   10672:                     push(@errors,$item);
                   10673:                 }
                   10674:             }
                   10675:         } elsif ($item eq 'intauth_switch') {
                   10676:             if ($newvalues{$item} ne '') {
                   10677:                 unless ($newvalues{$item} =~ /^(0|1|2)$/) {
                   10678:                     push(@errors,$item);
                   10679:                 }
                   10680:             }
1.43      raeburn  10681:         }
                   10682:         if (grep(/^\Q$item\E$/,@errors)) {
                   10683:             $newvalues{$item} = $domdefaults{$item};
                   10684:         } elsif ($domdefaults{$item} ne $newvalues{$item}) {
                   10685:             $changes{$item} = 1;
                   10686:         }
1.72      raeburn  10687:         $domdefaults{$item} = $newvalues{$item};
1.43      raeburn  10688:     }
                   10689:     my %defaults_hash = (
1.72      raeburn  10690:                          defaults => \%newvalues,
                   10691:                         );
1.43      raeburn  10692:     my $title = &defaults_titles();
1.160.6.40  raeburn  10693: 
                   10694:     my $currinststatus;
                   10695:     if (ref($domconfig{'inststatus'}) eq 'HASH') {
                   10696:         $currinststatus = $domconfig{'inststatus'};
                   10697:     } else {
                   10698:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   10699:         $currinststatus = {
                   10700:                              inststatustypes => $usertypes,
                   10701:                              inststatusorder => $types,
                   10702:                              inststatusguest => [],
                   10703:                           };
                   10704:     }
                   10705:     my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
                   10706:     my @allpos;
                   10707:     my %guests;
                   10708:     my %alltypes;
                   10709:     my ($currtitles,$currguests,$currorder);
                   10710:     if (ref($currinststatus) eq 'HASH') {
                   10711:         if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
                   10712:             foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
                   10713:                 if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
                   10714:                     if ($currinststatus->{inststatustypes}->{$type} ne '') {
                   10715:                         $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
                   10716:                     }
                   10717:                 }
                   10718:                 unless (grep(/^\Q$type\E$/,@todelete)) { 
                   10719:                     my $position = $env{'form.inststatus_pos_'.$type};
                   10720:                     $position =~ s/\D+//g;
                   10721:                     $allpos[$position] = $type;
                   10722:                     $alltypes{$type} = $env{'form.inststatus_title_'.$type};
                   10723:                     $alltypes{$type} =~ s/`//g;
                   10724:                     if ($env{'form.inststatus_guest_'.$type}) {
                   10725:                         $guests{$type} = 1;
                   10726:                     }
                   10727:                 }
                   10728:             }
                   10729:             if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
                   10730:                 $currguests = join(',',@{$currinststatus->{'inststatusguest'}});
                   10731:             }
                   10732:             $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
                   10733:             $currtitles =~ s/,$//;
                   10734:         }
                   10735:     }
                   10736:     if ($env{'form.addinststatus'}) {
                   10737:         my $newtype = $env{'form.addinststatus'};
                   10738:         $newtype =~ s/\W//g;
                   10739:         unless (exists($alltypes{$newtype})) {
                   10740:             if ($env{'form.addinststatus_guest'}) {
                   10741:                 $guests{$newtype} = 1;
                   10742:             }
                   10743:             $alltypes{$newtype} = $env{'form.addinststatus_title'};
                   10744:             $alltypes{$newtype} =~ s/`//g; 
                   10745:             my $position = $env{'form.addinststatus_pos'};
                   10746:             $position =~ s/\D+//g;
                   10747:             if ($position ne '') {
                   10748:                 $allpos[$position] = $newtype;
                   10749:             }
                   10750:         }
                   10751:     }
                   10752:     my (@orderedstatus,@orderedguests);
                   10753:     foreach my $type (@allpos) {
                   10754:         unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
                   10755:             push(@orderedstatus,$type);
                   10756:             if ($guests{$type}) {
                   10757:                 push(@orderedguests,$type);
                   10758:             }
                   10759:         }
                   10760:     }
                   10761:     foreach my $type (keys(%alltypes)) {
                   10762:         unless (grep(/^\Q$type\E$/,@orderedstatus)) {
                   10763:             delete($alltypes{$type});
                   10764:         }
                   10765:     }
                   10766:     $defaults_hash{'inststatus'} = {
                   10767:                                      inststatustypes => \%alltypes,
                   10768:                                      inststatusorder => \@orderedstatus,
                   10769:                                      inststatusguest => \@orderedguests,
                   10770:                                    };
                   10771:     if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
                   10772:         foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
                   10773:             $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
                   10774:         }
                   10775:     }
                   10776:     if ($currorder ne join(',',@orderedstatus)) {
                   10777:         $changes{'inststatus'}{'inststatusorder'} = 1;
                   10778:     }
                   10779:     if ($currguests ne join(',',@orderedguests)) {
                   10780:         $changes{'inststatus'}{'inststatusguest'} = 1;
                   10781:     }
                   10782:     my $newtitles;
                   10783:     foreach my $item (@orderedstatus) {
                   10784:         $newtitles .= $alltypes{$item}.',';
                   10785:     }
                   10786:     $newtitles =~ s/,$//;
                   10787:     if ($currtitles ne $newtitles) {
                   10788:         $changes{'inststatus'}{'inststatustypes'} = 1;
                   10789:     }
1.43      raeburn  10790:     my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
                   10791:                                              $dom);
                   10792:     if ($putresult eq 'ok') {
                   10793:         if (keys(%changes) > 0) {
                   10794:             $resulttext = &mt('Changes made:').'<ul>';
1.160.6.27  raeburn  10795:             my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43      raeburn  10796:             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";
                   10797:             foreach my $item (sort(keys(%changes))) {
1.160.6.40  raeburn  10798:                 if ($item eq 'inststatus') {
                   10799:                     if (ref($changes{'inststatus'}) eq 'HASH') {
                   10800:                         if (($changes{'inststatus'}{'inststatustypes'}) || $changes{'inststatus'}{'inststatusorder'}) {
                   10801:                             $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
                   10802:                             foreach my $type (@orderedstatus) { 
                   10803:                                 $resulttext .= $alltypes{$type}.', ';
                   10804:                             }
                   10805:                             $resulttext =~ s/, $//;
                   10806:                             $resulttext .= '</li>';
                   10807:                         }
                   10808:                         if ($changes{'inststatus'}{'inststatusguest'}) {
                   10809:                             $resulttext .= '<li>'; 
                   10810:                             if (@orderedguests) {
                   10811:                                 $resulttext .= &mt('Types assignable to "non-institutional" usernames set to:').' ';
                   10812:                                 foreach my $type (@orderedguests) {
                   10813:                                     $resulttext .= $alltypes{$type}.', ';
                   10814:                                 }
                   10815:                                 $resulttext =~ s/, $//;
                   10816:                             } else {
                   10817:                                 $resulttext .= &mt('Types assignable to "non-institutional" usernames set to none.');
                   10818:                             }
                   10819:                             $resulttext .= '</li>';
                   10820:                         }
                   10821:                     }
                   10822:                 } else {
                   10823:                     my $value = $env{'form.'.$item};
                   10824:                     if ($value eq '') {
                   10825:                         $value = &mt('none');
                   10826:                     } elsif ($item eq 'auth_def') {
                   10827:                         my %authnames = &authtype_names();
                   10828:                         my %shortauth = (
                   10829:                                           internal   => 'int',
                   10830:                                           krb4       => 'krb4',
                   10831:                                           krb5       => 'krb5',
                   10832:                                           localauth  => 'loc',
                   10833:                         );
                   10834:                         $value = $authnames{$shortauth{$value}};
1.160.6.80  raeburn  10835:                     } elsif ($item eq 'intauth_switch') {
                   10836:                         my %optiondesc = &Apache::lonlocal::texthash (
                   10837:                                             0 => 'No',
                   10838:                                             1 => 'Yes',
                   10839:                                             2 => 'Yes, and copy existing passwd file to passwd.bak file',
                   10840:                                          );
                   10841:                         if ($value =~ /^(0|1|2)$/) {
                   10842:                             $value = $optiondesc{$value};
                   10843:                         } else {
                   10844:                             $value = &mt('none -- defaults to No');
                   10845:                         }
                   10846:                     } elsif ($item eq 'intauth_check') {
                   10847:                         my %optiondesc = &Apache::lonlocal::texthash (
                   10848:                                              0 => 'No',
                   10849:                                              1 => 'Yes, allow login then update passwd file using default cost (if higher)',
                   10850:                                              2 => 'Yes, disallow login if stored cost is less than domain default',
                   10851:                                          );
                   10852:                         if ($value =~ /^(0|1|2)$/) {
                   10853:                             $value = $optiondesc{$value};
                   10854:                         } else {
                   10855:                             $value = &mt('none -- defaults to No');
                   10856:                         }
1.160.6.40  raeburn  10857:                     }
                   10858:                     $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
                   10859:                     $mailmsgtext .= "$title->{$item} set to $value\n";  
1.43      raeburn  10860:                 }
                   10861:             }
                   10862:             $resulttext .= '</ul>';
                   10863:             $mailmsgtext .= "\n";
                   10864:             my $cachetime = 24*60*60;
1.72      raeburn  10865:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27  raeburn  10866:             if (ref($lastactref) eq 'HASH') {
                   10867:                 $lastactref->{'domdefaults'} = 1;
                   10868:             }
1.68      raeburn  10869:             if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.160.6.23  raeburn  10870:                 my $notify = 1;
                   10871:                 if (ref($domconfig{'contacts'}) eq 'HASH') {
                   10872:                     if ($domconfig{'contacts'}{'reportupdates'} == 0) {
                   10873:                         $notify = 0;
                   10874:                     }
                   10875:                 }
                   10876:                 if ($notify) {
                   10877:                     &Apache::lonmsg::sendemail('installrecord@loncapa.org',
                   10878:                                                "LON-CAPA Domain Settings Change - $dom",
                   10879:                                                $mailmsgtext);
                   10880:                 }
1.54      raeburn  10881:             }
1.43      raeburn  10882:         } else {
1.54      raeburn  10883:             $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43      raeburn  10884:         }
                   10885:     } else {
                   10886:         $resulttext = '<span class="LC_error">'.
                   10887:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   10888:     }
                   10889:     if (@errors > 0) {
                   10890:         $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
                   10891:         foreach my $item (@errors) {
                   10892:             $resulttext .= ' "'.$title->{$item}.'",';
                   10893:         }
                   10894:         $resulttext =~ s/,$//;
                   10895:     }
                   10896:     return $resulttext;
                   10897: }
                   10898: 
1.46      raeburn  10899: sub modify_scantron {
1.160.6.24  raeburn  10900:     my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46      raeburn  10901:     my ($resulttext,%confhash,%changes,$errors);
                   10902:     my $custom = 'custom.tab';
                   10903:     my $default = 'default.tab';
                   10904:     my $servadm = $r->dir_config('lonAdmEMail');
                   10905:     my ($configuserok,$author_ok,$switchserver) = 
                   10906:         &config_check($dom,$confname,$servadm);
                   10907:     if ($env{'form.scantronformat.filename'} ne '') {
                   10908:         my $error;
                   10909:         if ($configuserok eq 'ok') {
                   10910:             if ($switchserver) {
1.130     raeburn  10911:                 $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46      raeburn  10912:             } else {
                   10913:                 if ($author_ok eq 'ok') {
                   10914:                     my ($result,$scantronurl) =
                   10915:                         &publishlogo($r,'upload','scantronformat',$dom,
                   10916:                                      $confname,'scantron','','',$custom);
                   10917:                     if ($result eq 'ok') {
                   10918:                         $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48      raeburn  10919:                         $changes{'scantronformat'} = 1;
1.46      raeburn  10920:                     } else {
                   10921:                         $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
                   10922:                     }
                   10923:                 } else {
                   10924:                     $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);
                   10925:                 }
                   10926:             }
                   10927:         } else {
                   10928:             $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);
                   10929:         }
                   10930:         if ($error) {
                   10931:             &Apache::lonnet::logthis($error);
                   10932:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   10933:         }
                   10934:     }
1.48      raeburn  10935:     if (ref($domconfig{'scantron'}) eq 'HASH') {
                   10936:         if ($domconfig{'scantron'}{'scantronformat'} ne '') {
                   10937:             if ($env{'form.scantronformat_del'}) {
                   10938:                 $confhash{'scantron'}{'scantronformat'} = '';
                   10939:                 $changes{'scantronformat'} = 1;
1.46      raeburn  10940:             }
                   10941:         }
                   10942:     }
                   10943:     if (keys(%confhash) > 0) {
                   10944:         my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
                   10945:                                                  $dom);
                   10946:         if ($putresult eq 'ok') {
                   10947:             if (keys(%changes) > 0) {
1.48      raeburn  10948:                 if (ref($confhash{'scantron'}) eq 'HASH') {
                   10949:                     $resulttext = &mt('Changes made:').'<ul>';
                   10950:                     if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130     raeburn  10951:                         $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48      raeburn  10952:                     } else {
1.130     raeburn  10953:                         $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46      raeburn  10954:                     }
1.48      raeburn  10955:                     $resulttext .= '</ul>';
                   10956:                 } else {
1.130     raeburn  10957:                     $resulttext = &mt('Changes made to bubblesheet format file.');
1.46      raeburn  10958:                 }
                   10959:                 $resulttext .= '</ul>';
                   10960:                 &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27  raeburn  10961:                 if (ref($lastactref) eq 'HASH') {
                   10962:                     $lastactref->{'domainconfig'} = 1;
                   10963:                 }
1.46      raeburn  10964:             } else {
1.130     raeburn  10965:                 $resulttext = &mt('No changes made to bubblesheet format file');
1.46      raeburn  10966:             }
                   10967:         } else {
                   10968:             $resulttext = '<span class="LC_error">'.
                   10969:                 &mt('An error occurred: [_1]',$putresult).'</span>';
                   10970:         }
                   10971:     } else {
1.130     raeburn  10972:         $resulttext = &mt('No changes made to bubblesheet format file'); 
1.46      raeburn  10973:     }
                   10974:     if ($errors) {
                   10975:         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
                   10976:                        $errors.'</ul>';
                   10977:     }
                   10978:     return $resulttext;
                   10979: }
                   10980: 
1.48      raeburn  10981: sub modify_coursecategories {
1.160.6.43  raeburn  10982:     my ($dom,$lastactref,%domconfig) = @_;
1.57      raeburn  10983:     my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
                   10984:         $cathash);
1.48      raeburn  10985:     my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.160.6.42  raeburn  10986:     my @catitems = ('unauth','auth');
                   10987:     my @cattypes = ('std','domonly','codesrch','none');
1.55      raeburn  10988:     if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57      raeburn  10989:         $cathash = $domconfig{'coursecategories'}{'cats'};
                   10990:         if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
                   10991:             $changes{'togglecats'} = 1;
                   10992:             $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
                   10993:         }
                   10994:         if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
                   10995:             $changes{'categorize'} = 1;
                   10996:             $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
                   10997:         }
1.120     raeburn  10998:         if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
                   10999:             $changes{'togglecatscomm'} = 1;
                   11000:             $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
                   11001:         }
                   11002:         if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
                   11003:             $changes{'categorizecomm'} = 1;
                   11004:             $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
                   11005:         }
1.160.6.42  raeburn  11006:         foreach my $item (@catitems) {
                   11007:             if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
                   11008:                 if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
                   11009:                     $changes{$item} = 1;
                   11010:                     $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
                   11011:                 }
                   11012:             }
                   11013:         }
1.57      raeburn  11014:     } else {
                   11015:         $changes{'togglecats'} = 1;
                   11016:         $changes{'categorize'} = 1;
1.124     raeburn  11017:         $changes{'togglecatscomm'} = 1;
                   11018:         $changes{'categorizecomm'} = 1;
1.87      raeburn  11019:         $domconfig{'coursecategories'} = {
                   11020:                                              togglecats => $env{'form.togglecats'},
                   11021:                                              categorize => $env{'form.categorize'},
1.124     raeburn  11022:                                              togglecatscomm => $env{'form.togglecatscomm'},
                   11023:                                              categorizecomm => $env{'form.categorizecomm'},
1.120     raeburn  11024:                                          };
1.160.6.42  raeburn  11025:         foreach my $item (@catitems) {
                   11026:             if ($env{'form.coursecat_'.$item} ne 'std') {
                   11027:                 $changes{$item} = 1;
                   11028:             }
                   11029:             if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
                   11030:                 $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
                   11031:             }
                   11032:         }
1.57      raeburn  11033:     }
                   11034:     if (ref($cathash) eq 'HASH') {
                   11035:         if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '')  && ($env{'form.instcode'} == 0)) {
1.55      raeburn  11036:             push (@deletecategory,'instcode::0');
                   11037:         }
1.120     raeburn  11038:         if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '')  && ($env{'form.communities'} == 0)) {
                   11039:             push(@deletecategory,'communities::0');
                   11040:         }
1.48      raeburn  11041:     }
1.57      raeburn  11042:     my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
                   11043:     if (ref($cathash) eq 'HASH') {
1.48      raeburn  11044:         if (@deletecategory > 0) {
                   11045:             #FIXME Need to remove category from all courses using a deleted category 
1.57      raeburn  11046:             &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48      raeburn  11047:             foreach my $item (@deletecategory) {
1.57      raeburn  11048:                 if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
                   11049:                     delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48      raeburn  11050:                     $deletions{$item} = 1;
1.57      raeburn  11051:                     &recurse_cat_deletes($item,$cathash,\%deletions);
1.48      raeburn  11052:                 }
                   11053:             }
                   11054:         }
1.57      raeburn  11055:         foreach my $item (keys(%{$cathash})) {
1.48      raeburn  11056:             my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57      raeburn  11057:             if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48      raeburn  11058:                 $reorderings{$item} = 1;
1.57      raeburn  11059:                 $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48      raeburn  11060:             }
                   11061:             if ($env{'form.addcategory_name_'.$item} ne '') {
                   11062:                 my $newcat = $env{'form.addcategory_name_'.$item};
                   11063:                 my $newdepth = $depth+1;
                   11064:                 my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57      raeburn  11065:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48      raeburn  11066:                 $adds{$newitem} = 1; 
                   11067:             }
                   11068:             if ($env{'form.subcat_'.$item} ne '') {
                   11069:                 my $newcat = $env{'form.subcat_'.$item};
                   11070:                 my $newdepth = $depth+1;
                   11071:                 my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57      raeburn  11072:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48      raeburn  11073:                 $adds{$newitem} = 1;
                   11074:             }
                   11075:         }
                   11076:     }
                   11077:     if ($env{'form.instcode'} eq '1') {
1.57      raeburn  11078:         if (ref($cathash) eq 'HASH') {
1.48      raeburn  11079:             my $newitem = 'instcode::0';
1.57      raeburn  11080:             if ($cathash->{$newitem} eq '') {  
                   11081:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48      raeburn  11082:                 $adds{$newitem} = 1;
                   11083:             }
                   11084:         } else {
                   11085:             my $newitem = 'instcode::0';
1.57      raeburn  11086:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48      raeburn  11087:             $adds{$newitem} = 1;
                   11088:         }
                   11089:     }
1.120     raeburn  11090:     if ($env{'form.communities'} eq '1') {
                   11091:         if (ref($cathash) eq 'HASH') {
                   11092:             my $newitem = 'communities::0';
                   11093:             if ($cathash->{$newitem} eq '') {
                   11094:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
                   11095:                 $adds{$newitem} = 1;
                   11096:             }
                   11097:         } else {
                   11098:             my $newitem = 'communities::0';
                   11099:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
                   11100:             $adds{$newitem} = 1;
                   11101:         }
                   11102:     }
1.48      raeburn  11103:     if ($env{'form.addcategory_name'} ne '') {
1.120     raeburn  11104:         if (($env{'form.addcategory_name'} ne 'instcode') &&
                   11105:             ($env{'form.addcategory_name'} ne 'communities')) {
                   11106:             my $newitem = &escape($env{'form.addcategory_name'}).'::0';
                   11107:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
                   11108:             $adds{$newitem} = 1;
                   11109:         }
1.48      raeburn  11110:     }
1.57      raeburn  11111:     my $putresult;
1.48      raeburn  11112:     if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
                   11113:         if (keys(%deletions) > 0) {
                   11114:             foreach my $key (keys(%deletions)) {
                   11115:                 if ($predelallitems{$key} ne '') {
                   11116:                     $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
                   11117:                 }
                   11118:             }
                   11119:         }
                   11120:         my (@chkcats,@chktrails,%chkallitems);
1.57      raeburn  11121:         &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48      raeburn  11122:         if (ref($chkcats[0]) eq 'ARRAY') {
                   11123:             my $depth = 0;
                   11124:             my $chg = 0;
                   11125:             for (my $i=0; $i<@{$chkcats[0]}; $i++) {
                   11126:                 my $name = $chkcats[0][$i];
                   11127:                 my $item;
                   11128:                 if ($name eq '') {
                   11129:                     $chg ++;
                   11130:                 } else {
                   11131:                     $item = &escape($name).'::0';
                   11132:                     if ($chg) {
1.57      raeburn  11133:                         $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48      raeburn  11134:                     }
                   11135:                     $depth ++; 
1.57      raeburn  11136:                     &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48      raeburn  11137:                     $depth --;
                   11138:                 }
                   11139:             }
                   11140:         }
1.57      raeburn  11141:     }
                   11142:     if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
                   11143:         $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48      raeburn  11144:         if ($putresult eq 'ok') {
1.57      raeburn  11145:             my %title = (
1.120     raeburn  11146:                          togglecats     => 'Show/Hide a course in catalog',
                   11147:                          categorize     => 'Assign a category to a course',
                   11148:                          togglecatscomm => 'Show/Hide a community in catalog',
                   11149:                          categorizecomm => 'Assign a category to a community',
1.57      raeburn  11150:                         );
                   11151:             my %level = (
1.120     raeburn  11152:                          dom  => 'set in Domain ("Modify Course/Community")',
                   11153:                          crs  => 'set in Course ("Course Configuration")',
                   11154:                          comm => 'set in Community ("Community Configuration")',
1.160.6.42  raeburn  11155:                          none     => 'No catalog',
                   11156:                          std      => 'Standard catalog',
                   11157:                          domonly  => 'Domain-only catalog',
                   11158:                          codesrch => 'Code search form',
1.57      raeburn  11159:                         );
1.48      raeburn  11160:             $resulttext = &mt('Changes made:').'<ul>';
1.57      raeburn  11161:             if ($changes{'togglecats'}) {
                   11162:                 $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>'; 
                   11163:             }
                   11164:             if ($changes{'categorize'}) {
                   11165:                 $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48      raeburn  11166:             }
1.120     raeburn  11167:             if ($changes{'togglecatscomm'}) {
                   11168:                 $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
                   11169:             }
                   11170:             if ($changes{'categorizecomm'}) {
                   11171:                 $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
                   11172:             }
1.160.6.42  raeburn  11173:             if ($changes{'unauth'}) {
                   11174:                 $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
                   11175:             }
                   11176:             if ($changes{'auth'}) {
                   11177:                 $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
                   11178:             }
1.57      raeburn  11179:             if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
                   11180:                 my $cathash;
                   11181:                 if (ref($domconfig{'coursecategories'}) eq 'HASH') {
                   11182:                     $cathash = $domconfig{'coursecategories'}{'cats'};
                   11183:                 } else {
                   11184:                     $cathash = {};
                   11185:                 } 
                   11186:                 my (@cats,@trails,%allitems);
                   11187:                     &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
                   11188:                 if (keys(%deletions) > 0) {
                   11189:                     $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
                   11190:                     foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) { 
                   11191:                         $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
                   11192:                     }
                   11193:                     $resulttext .= '</ul></li>';
                   11194:                 }
                   11195:                 if (keys(%reorderings) > 0) {
                   11196:                     my %sort_by_trail;
                   11197:                     $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
                   11198:                     foreach my $key (keys(%reorderings)) {
                   11199:                         if ($allitems{$key} ne '') {
                   11200:                             $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
                   11201:                         }
1.48      raeburn  11202:                     }
1.57      raeburn  11203:                     foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
                   11204:                         $resulttext .= '<li>'.$trails[$trail].'</li>';
                   11205:                     }
                   11206:                     $resulttext .= '</ul></li>';
1.48      raeburn  11207:                 }
1.57      raeburn  11208:                 if (keys(%adds) > 0) {
                   11209:                     my %sort_by_trail;
                   11210:                     $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
                   11211:                     foreach my $key (keys(%adds)) {
                   11212:                         if ($allitems{$key} ne '') {
                   11213:                             $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
                   11214:                         }
                   11215:                     }
                   11216:                     foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
                   11217:                         $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48      raeburn  11218:                     }
1.57      raeburn  11219:                     $resulttext .= '</ul></li>';
1.48      raeburn  11220:                 }
                   11221:             }
                   11222:             $resulttext .= '</ul>';
1.160.6.43  raeburn  11223:             if ($changes{'unauth'} || $changes{'auth'}) {
1.160.6.50  raeburn  11224:                 my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
                   11225:                 if ($changes{'auth'}) {
                   11226:                     $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
                   11227:                 }
                   11228:                 if ($changes{'unauth'}) {
                   11229:                     $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
                   11230:                 }
                   11231:                 my $cachetime = 24*60*60;
                   11232:                 &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.43  raeburn  11233:                 if (ref($lastactref) eq 'HASH') {
1.160.6.50  raeburn  11234:                     $lastactref->{'domdefaults'} = 1;
1.160.6.43  raeburn  11235:                 }
                   11236:             }
1.48      raeburn  11237:         } else {
                   11238:             $resulttext = '<span class="LC_error">'.
1.57      raeburn  11239:                           &mt('An error occurred: [_1]',$putresult).'</span>';
1.48      raeburn  11240:         }
                   11241:     } else {
1.120     raeburn  11242:         $resulttext = &mt('No changes made to course and community categories');
1.48      raeburn  11243:     }
                   11244:     return $resulttext;
                   11245: }
                   11246: 
1.69      raeburn  11247: sub modify_serverstatuses {
                   11248:     my ($dom,%domconfig) = @_;
                   11249:     my ($resulttext,%changes,%currserverstatus,%newserverstatus);
                   11250:     if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
                   11251:         %currserverstatus = %{$domconfig{'serverstatuses'}};
                   11252:     }
                   11253:     my @pages = &serverstatus_pages();
                   11254:     foreach my $type (@pages) {
                   11255:         $newserverstatus{$type}{'namedusers'} = '';
                   11256:         $newserverstatus{$type}{'machines'} = '';
                   11257:         if (defined($env{'form.'.$type.'_namedusers'})) {
                   11258:             my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
                   11259:             my @okusers;
                   11260:             foreach my $user (@users) {
                   11261:                 my ($uname,$udom) = split(/:/,$user);
                   11262:                 if (($udom =~ /^$match_domain$/) &&   
                   11263:                     (&Apache::lonnet::domain($udom)) &&
                   11264:                     ($uname =~ /^$match_username$/)) {
                   11265:                     if (!grep(/^\Q$user\E/,@okusers)) {
                   11266:                         push(@okusers,$user);
                   11267:                     }
                   11268:                 }
                   11269:             }
                   11270:             if (@okusers > 0) {
                   11271:                  @okusers = sort(@okusers);
                   11272:                  $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
                   11273:             }
                   11274:         }
                   11275:         if (defined($env{'form.'.$type.'_machines'})) {
                   11276:             my @machines = split(/,/,$env{'form.'.$type.'_machines'});
                   11277:             my @okmachines;
                   11278:             foreach my $ip (@machines) {
                   11279:                 my @parts = split(/\./,$ip);
                   11280:                 next if (@parts < 4);
                   11281:                 my $badip = 0;
                   11282:                 for (my $i=0; $i<4; $i++) {
                   11283:                     if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
                   11284:                         $badip = 1;
                   11285:                         last;
                   11286:                     }
                   11287:                 }
                   11288:                 if (!$badip) {
                   11289:                     push(@okmachines,$ip);     
                   11290:                 }
                   11291:             }
                   11292:             @okmachines = sort(@okmachines);
                   11293:             $newserverstatus{$type}{'machines'} = join(',',@okmachines);
                   11294:         }
                   11295:     }
                   11296:     my %serverstatushash =  (
                   11297:                                 serverstatuses => \%newserverstatus,
                   11298:                             );
                   11299:     foreach my $type (@pages) {
1.83      raeburn  11300:         foreach my $setting ('namedusers','machines') {
1.84      raeburn  11301:             my (@current,@new);
1.83      raeburn  11302:             if (ref($currserverstatus{$type}) eq 'HASH') {
1.84      raeburn  11303:                 if ($currserverstatus{$type}{$setting} ne '') { 
                   11304:                     @current = split(/,/,$currserverstatus{$type}{$setting});
                   11305:                 }
                   11306:             }
                   11307:             if ($newserverstatus{$type}{$setting} ne '') {
                   11308:                 @new = split(/,/,$newserverstatus{$type}{$setting});
1.83      raeburn  11309:             }
                   11310:             if (@current > 0) {
                   11311:                 if (@new > 0) {
                   11312:                     foreach my $item (@current) {
                   11313:                         if (!grep(/^\Q$item\E$/,@new)) {
                   11314:                             $changes{$type}{$setting} = 1;
1.82      raeburn  11315:                             last;
                   11316:                         }
                   11317:                     }
1.84      raeburn  11318:                     foreach my $item (@new) {
                   11319:                         if (!grep(/^\Q$item\E$/,@current)) {
                   11320:                             $changes{$type}{$setting} = 1;
                   11321:                             last;
1.82      raeburn  11322:                         }
                   11323:                     }
                   11324:                 } else {
1.83      raeburn  11325:                     $changes{$type}{$setting} = 1;
1.69      raeburn  11326:                 }
1.83      raeburn  11327:             } elsif (@new > 0) {
                   11328:                 $changes{$type}{$setting} = 1;
1.69      raeburn  11329:             }
                   11330:         }
                   11331:     }
                   11332:     if (keys(%changes) > 0) {
1.81      raeburn  11333:         my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69      raeburn  11334:         my $putresult = &Apache::lonnet::put_dom('configuration',
                   11335:                                                  \%serverstatushash,$dom);
                   11336:         if ($putresult eq 'ok') {
                   11337:             $resulttext .= &mt('Changes made:').'<ul>';
                   11338:             foreach my $type (@pages) {
1.84      raeburn  11339:                 if (ref($changes{$type}) eq 'HASH') {
1.69      raeburn  11340:                     $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84      raeburn  11341:                     if ($changes{$type}{'namedusers'}) {
1.69      raeburn  11342:                         if ($newserverstatus{$type}{'namedusers'} eq '') {
                   11343:                             $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
                   11344:                         } else {
                   11345:                             $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
                   11346:                         }
1.84      raeburn  11347:                     }
                   11348:                     if ($changes{$type}{'machines'}) {
1.69      raeburn  11349:                         if ($newserverstatus{$type}{'machines'} eq '') {
                   11350:                             $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
                   11351:                         } else {
                   11352:                             $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
                   11353:                         }
                   11354: 
                   11355:                     }
                   11356:                     $resulttext .= '</ul></li>';
                   11357:                 }
                   11358:             }
                   11359:             $resulttext .= '</ul>';
                   11360:         } else {
                   11361:             $resulttext = '<span class="LC_error">'.
                   11362:                           &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
                   11363: 
                   11364:         }
                   11365:     } else {
                   11366:         $resulttext = &mt('No changes made to access to server status pages');
                   11367:     }
                   11368:     return $resulttext;
                   11369: }
                   11370: 
1.118     jms      11371: sub modify_helpsettings {
1.160.6.77  raeburn  11372:     my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5  raeburn  11373:     my ($resulttext,$errors,%changes,%helphash);
                   11374:     my %defaultchecked = ('submitbugs' => 'on');
                   11375:     my @offon = ('off','on');
1.118     jms      11376:     my @toggles = ('submitbugs');
1.160.6.77  raeburn  11377:     my %current = ('submitbugs' => '',
                   11378:                    'adhoc'      => {},
                   11379:                   );
1.118     jms      11380:     if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.160.6.73  raeburn  11381:         %current = %{$domconfig{'helpsettings'}};
                   11382:     }
1.160.6.77  raeburn  11383:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.73  raeburn  11384:     foreach my $item (@toggles) {
                   11385:         if ($defaultchecked{$item} eq 'on') { 
                   11386:             if ($current{$item} eq '') {
                   11387:                 if ($env{'form.'.$item} eq '0') {
1.160.6.5  raeburn  11388:                     $changes{$item} = 1;
                   11389:                 }
1.160.6.73  raeburn  11390:             } elsif ($current{$item} ne $env{'form.'.$item}) {
                   11391:                 $changes{$item} = 1;
                   11392:             }
                   11393:         } elsif ($defaultchecked{$item} eq 'off') {
                   11394:             if ($current{$item} eq '') {
                   11395:                 if ($env{'form.'.$item} eq '1') {
1.160.6.5  raeburn  11396:                     $changes{$item} = 1;
                   11397:                 }
1.160.6.73  raeburn  11398:             } elsif ($current{$item} ne $env{'form.'.$item}) {
                   11399:                 $changes{$item} = 1;
                   11400:             }
                   11401:         }
                   11402:         if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
                   11403:             $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
                   11404:         }
                   11405:     }
1.160.6.77  raeburn  11406:     my $maxnum = $env{'form.helproles_maxnum'};
1.160.6.73  raeburn  11407:     my $confname = $dom.'-domainconfig';
                   11408:     my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.160.6.77  raeburn  11409:     my (@allpos,%newsettings,%changedprivs,$newrole);
                   11410:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.79  raeburn  11411:     my @accesstypes = ('all','dh','da','none','status','inc','exc');
                   11412:     my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.160.6.77  raeburn  11413:     my %lt = &Apache::lonlocal::texthash(
                   11414:                     s      => 'system',
                   11415:                     d      => 'domain',
                   11416:                     order  => 'Display order',
                   11417:                     access => 'Role usage',
1.160.6.79  raeburn  11418:                     all    => 'All with domain helpdesk or helpdesk assistant role',
                   11419:                     dh     => 'All with domain helpdesk role',
                   11420:                     da     => 'All with domain helpdesk assistant role',
1.160.6.77  raeburn  11421:                     none   => 'None',
                   11422:                     status => 'Determined based on institutional status',
                   11423:                     inc    => 'Include all, but exclude specific personnel',
                   11424:                     exc    => 'Exclude all, but include specific personnel',
                   11425:     );
                   11426:     for (my $num=0; $num<=$maxnum; $num++) {
                   11427:         my ($prefix,$identifier,$rolename,%curr);
                   11428:         if ($num == $maxnum) {
                   11429:             next unless ($env{'form.newcusthelp'} == $maxnum);
                   11430:             $identifier = 'custhelp'.$num;
                   11431:             $prefix = 'helproles_'.$num;
                   11432:             $rolename = $env{'form.custhelpname'.$num};
                   11433:             $rolename=~s/[^A-Za-z0-9]//gs;
                   11434:             next if ($rolename eq '');
                   11435:             next if (exists($existing{'rolesdef_'.$rolename}));
                   11436:             my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
                   11437:             my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
                   11438:                                                      $newprivs{'c'},$confname,$dom);
                   11439:             if ($result ne 'ok') {
                   11440:                 $errors .= '<li><span class="LC_error">'.
                   11441:                            &mt('An error occurred storing the new custom role: [_1]',
                   11442:                            $result).'</span></li>';
                   11443:                 next;
                   11444:             } else {
                   11445:                 $changedprivs{$rolename} = \%newprivs;
                   11446:                 $newrole = $rolename;
                   11447:             }
                   11448:         } else {
                   11449:             $prefix = 'helproles_'.$num;
                   11450:             $rolename = $env{'form.'.$prefix};
                   11451:             next if ($rolename eq '');
                   11452:             next unless (exists($existing{'rolesdef_'.$rolename}));
                   11453:             $identifier = 'custhelp'.$num;
                   11454:             my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
                   11455:             my %currprivs;
                   11456:             ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
                   11457:                 split(/\_/,$existing{'rolesdef_'.$rolename});
                   11458:             foreach my $level ('c','d','s') {
                   11459:                 if ($newprivs{$level} ne $currprivs{$level}) {
                   11460:                     my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
                   11461:                                                              $newprivs{'c'},$confname,$dom);
                   11462:                     if ($result ne 'ok') {
                   11463:                         $errors .= '<li><span class="LC_error">'.
                   11464:                                    &mt('An error occurred storing privileges for existing role [_1]: [_2]',
                   11465:                                        $rolename,$result).'</span></li>';
                   11466:                     } else {
                   11467:                         $changedprivs{$rolename} = \%newprivs;
                   11468:                     }
                   11469:                     last;
                   11470:                 }
                   11471:             }
                   11472:             if (ref($current{'adhoc'}) eq 'HASH') {
                   11473:                 if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
                   11474:                     %curr = %{$current{'adhoc'}{$rolename}};
                   11475:                 }
                   11476:             }
                   11477:         }
                   11478:         my $newpos = $env{'form.'.$prefix.'_pos'};
                   11479:         $newpos =~ s/\D+//g;
                   11480:         $allpos[$newpos] = $rolename;
                   11481:         my $newdesc = $env{'form.'.$prefix.'_desc'};
                   11482:         $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
                   11483:         if ($curr{'desc'}) {
                   11484:             if ($curr{'desc'} ne $newdesc) {
                   11485:                 $changes{'customrole'}{$rolename}{'desc'} = 1;
                   11486:                 $newsettings{$rolename}{'desc'} = $newdesc;
                   11487:             }
                   11488:         } elsif ($newdesc ne '') {
                   11489:             $changes{'customrole'}{$rolename}{'desc'} = 1;
                   11490:             $newsettings{$rolename}{'desc'} = $newdesc;
                   11491:         }
                   11492:         my $access = $env{'form.'.$prefix.'_access'};
                   11493:         if (grep(/^\Q$access\E$/,@accesstypes)) {
                   11494:             $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
                   11495:             if ($access eq 'status') {
                   11496:                 my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
                   11497:                 if (scalar(@statuses) == 0) {
                   11498:                     $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
                   11499:                 } else {
                   11500:                     my (@shownstatus,$numtypes);
                   11501:                     $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
                   11502:                     if (ref($types) eq 'ARRAY') {
                   11503:                         $numtypes = scalar(@{$types});
                   11504:                         foreach my $type (sort(@statuses)) {
                   11505:                             if ($type eq 'default') {
                   11506:                                 push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
                   11507:                             } elsif (grep(/^\Q$type\E$/,@{$types})) {
                   11508:                                 push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
                   11509:                                 push(@shownstatus,$usertypes->{$type});
                   11510:                             }
1.160.6.73  raeburn  11511:                         }
                   11512:                     }
1.160.6.77  raeburn  11513:                     if (grep(/^default$/,@statuses)) {
                   11514:                         push(@shownstatus,$othertitle);
                   11515:                     }
                   11516:                     if (scalar(@shownstatus) == 1+$numtypes) {
                   11517:                         $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
                   11518:                         delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
                   11519:                     } else {
                   11520:                         $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
                   11521:                         if (ref($curr{'status'}) eq 'ARRAY') {
                   11522:                             my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
                   11523:                             if (@diffs) {
                   11524:                                 $changes{'customrole'}{$rolename}{$access} = 1;
                   11525:                             }
                   11526:                         } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
                   11527:                             $changes{'customrole'}{$rolename}{$access} = 1;
                   11528:                         }
                   11529:                     }
                   11530:                 }
                   11531:             } elsif (($access eq 'inc') || ($access eq 'exc')) {
                   11532:                 my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
                   11533:                 my @newspecstaff;
                   11534:                 $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
                   11535:                 foreach my $person (sort(@personnel)) {
                   11536:                     if ($domhelpdesk{$person}) {
                   11537:                         push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
                   11538:                     }
                   11539:                 }
                   11540:                 if (ref($curr{$access}) eq 'ARRAY') {
                   11541:                     my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
                   11542:                     if (@diffs) {
                   11543:                         $changes{'customrole'}{$rolename}{$access} = 1;
                   11544:                     }
                   11545:                 } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
                   11546:                     $changes{'customrole'}{$rolename}{$access} = 1;
1.160.6.73  raeburn  11547:                 }
1.160.6.77  raeburn  11548:                 foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
                   11549:                     my ($uname,$udom) = split(/:/,$person);
                   11550:                         push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
                   11551:                 }
                   11552:                 $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.160.6.26  raeburn  11553:             }
1.160.6.77  raeburn  11554:         } else {
                   11555:             $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
                   11556:         }
                   11557:         unless ($curr{'access'} eq $access) {
                   11558:             $changes{'customrole'}{$rolename}{'access'} = 1;
                   11559:             $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.160.6.73  raeburn  11560:         }
                   11561:     }
1.160.6.77  raeburn  11562:     if (@allpos > 0) {
                   11563:         my $idx = 0;
                   11564:         foreach my $rolename (@allpos) {
                   11565:             if ($rolename ne '') {
                   11566:                 $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
                   11567:                 if (ref($current{'adhoc'}) eq 'HASH') {
                   11568:                     if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
                   11569:                         if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
                   11570:                             $changes{'customrole'}{$rolename}{'order'} = 1;
                   11571:                             $newsettings{$rolename}{'order'} = $idx+1;
                   11572:                         }
                   11573:                     }
1.160.6.73  raeburn  11574:                 }
1.160.6.77  raeburn  11575:                 $idx ++;
1.122     jms      11576:             }
                   11577:         }
1.118     jms      11578:     }
1.123     jms      11579:     my $putresult;
                   11580:     if (keys(%changes) > 0) {
1.160.6.5  raeburn  11581:         $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
                   11582:         if ($putresult eq 'ok') {
1.160.6.77  raeburn  11583:             if (ref($helphash{'helpsettings'}) eq 'HASH') {
                   11584:                 $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
                   11585:                 if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
                   11586:                     $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
                   11587:                 }
                   11588:             }
                   11589:             my $cachetime = 24*60*60;
                   11590:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
                   11591:             if (ref($lastactref) eq 'HASH') {
                   11592:                 $lastactref->{'domdefaults'} = 1;
                   11593:             }
                   11594:         } else {
                   11595:             $errors .= '<li><span class="LC_error">'.
                   11596:                        &mt('An error occurred storing the settings: [_1]',
                   11597:                            $putresult).'</span></li>';
                   11598:         }
                   11599:     }
                   11600:     if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
                   11601:         $resulttext = &mt('Changes made:').'<ul>';
                   11602:         my (%shownprivs,@levelorder);
                   11603:         @levelorder = ('c','d','s');
                   11604:         if ((keys(%changes)) && ($putresult eq 'ok')) {
1.160.6.5  raeburn  11605:             foreach my $item (sort(keys(%changes))) {
                   11606:                 if ($item eq 'submitbugs') {
                   11607:                     $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
                   11608:                                               &Apache::loncommon::modal_link('http://bugs.loncapa.org',
                   11609:                                               &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.160.6.73  raeburn  11610:                 } elsif ($item eq 'customrole') {
                   11611:                     if (ref($changes{'customrole'}) eq 'HASH') {
1.160.6.77  raeburn  11612:                         my @keyorder = ('order','desc','access','status','exc','inc');
                   11613:                         my %keytext = &Apache::lonlocal::texthash(
                   11614:                                                                    order  => 'Order',
                   11615:                                                                    desc   => 'Role description',
                   11616:                                                                    access => 'Role usage',
1.160.6.83  raeburn  11617:                                                                    status => 'Allowed institutional types',
1.160.6.77  raeburn  11618:                                                                    exc    => 'Allowed personnel',
                   11619:                                                                    inc    => 'Disallowed personnel',
                   11620:                         );
1.160.6.73  raeburn  11621:                         foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.160.6.77  raeburn  11622:                             if (ref($changes{'customrole'}{$role}) eq 'HASH') {
                   11623:                                 if ($role eq $newrole) {
                   11624:                                     $resulttext .= '<li>'.&mt('New custom role added: [_1]',
                   11625:                                                               $role).'<ul>';
                   11626:                                 } else {
                   11627:                                     $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
                   11628:                                                               $role).'<ul>';
                   11629:                                 }
                   11630:                                 foreach my $key (@keyorder) {
                   11631:                                     if ($changes{'customrole'}{$role}{$key}) {
                   11632:                                         $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
                   11633:                                                                   $keytext{$key},$newsettings{$role}{$key}).
                   11634:                                                        '</li>';
                   11635:                                     }
                   11636:                                 }
                   11637:                                 if (ref($changedprivs{$role}) eq 'HASH') {
                   11638:                                     $shownprivs{$role} = 1;
                   11639:                                     $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
                   11640:                                     foreach my $level (@levelorder) {
                   11641:                                         foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
                   11642:                                             next if ($item eq '');
                   11643:                                             my ($priv) = split(/\&/,$item,2);
                   11644:                                             if (&Apache::lonnet::plaintext($priv)) {
                   11645:                                                 $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
                   11646:                                                 unless ($level eq 'c') {
                   11647:                                                     $resulttext .= ' ('.$lt{$level}.')';
                   11648:                                                 }
                   11649:                                                 $resulttext .= '</li>';
                   11650:                                             }
                   11651:                                         }
                   11652:                                     }
                   11653:                                     $resulttext .= '</ul>';
                   11654:                                 }
                   11655:                                 $resulttext .= '</ul></li>';
                   11656:                             }
1.160.6.73  raeburn  11657:                         }
                   11658:                     }
1.160.6.5  raeburn  11659:                 }
                   11660:             }
                   11661:         }
1.160.6.77  raeburn  11662:         if (keys(%changedprivs)) {
                   11663:             foreach my $role (sort(keys(%changedprivs))) {
                   11664:                 unless ($shownprivs{$role}) {
                   11665:                     $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
                   11666:                                               $role).'<ul>'.
                   11667:                                    '<li>'.&mt('Privileges set to :').'<ul>';
                   11668:                     foreach my $level (@levelorder) {
                   11669:                         foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
                   11670:                             next if ($item eq '');
                   11671:                             my ($priv) = split(/\&/,$item,2);
                   11672:                             if (&Apache::lonnet::plaintext($priv)) {
                   11673:                                 $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
                   11674:                                 unless ($level eq 'c') {
                   11675:                                     $resulttext .= ' ('.$lt{$level}.')';
                   11676:                                 }
                   11677:                                 $resulttext .= '</li>';
                   11678:                             }
                   11679:                         }
                   11680:                     }
                   11681:                     $resulttext .= '</ul></li></ul></li>';
                   11682:                 }
                   11683:             }
                   11684:         }
                   11685:         $resulttext .= '</ul>';
                   11686:     } else {
                   11687:         $resulttext = &mt('No changes made to help settings');
1.118     jms      11688:     }
                   11689:     if ($errors) {
1.160.6.5  raeburn  11690:         $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.160.6.77  raeburn  11691:                                     $errors.'</ul>';
1.118     jms      11692:     }
                   11693:     return $resulttext;
                   11694: }
                   11695: 
1.121     raeburn  11696: sub modify_coursedefaults {
1.160.6.27  raeburn  11697:     my ($dom,$lastactref,%domconfig) = @_;
1.121     raeburn  11698:     my ($resulttext,$errors,%changes,%defaultshash);
1.160.6.57  raeburn  11699:     my %defaultchecked = (
                   11700:                            'uselcmath'       => 'on',
                   11701:                            'usejsme'         => 'on'
                   11702:                          );
                   11703:     my @toggles = ('uselcmath','usejsme');
1.160.6.21  raeburn  11704:     my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.160.6.70  raeburn  11705:                    'uploadquota_community','uploadquota_textbook','mysqltables_official',
                   11706:                    'mysqltables_unofficial','mysqltables_community','mysqltables_textbook');
1.160.6.30  raeburn  11707:     my @types = ('official','unofficial','community','textbook');
1.160.6.21  raeburn  11708:     my %staticdefaults = (
                   11709:                            anonsurvey_threshold => 10,
                   11710:                            uploadquota          => 500,
1.160.6.57  raeburn  11711:                            postsubmit           => 60,
1.160.6.70  raeburn  11712:                            mysqltables          => 172800,
1.160.6.21  raeburn  11713:                          );
1.160.6.90! raeburn  11714:     my %texoptions = (
        !          11715:                         MathJax  => 'MathJax',
        !          11716:                         mimetex  => &mt('Convert to Images'),
        !          11717:                         tth      => &mt('TeX to HTML'),
        !          11718:                      );
1.121     raeburn  11719:     $defaultshash{'coursedefaults'} = {};
                   11720: 
                   11721:     if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
                   11722:         if ($domconfig{'coursedefaults'} eq '') {
                   11723:             $domconfig{'coursedefaults'} = {};
                   11724:         }
                   11725:     }
                   11726: 
                   11727:     if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
                   11728:         foreach my $item (@toggles) {
                   11729:             if ($defaultchecked{$item} eq 'on') {
                   11730:                 if (($domconfig{'coursedefaults'}{$item} eq '') &&
                   11731:                     ($env{'form.'.$item} eq '0')) {
                   11732:                     $changes{$item} = 1;
1.160.6.16  raeburn  11733:                 } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121     raeburn  11734:                     $changes{$item} = 1;
                   11735:                 }
                   11736:             } elsif ($defaultchecked{$item} eq 'off') {
                   11737:                 if (($domconfig{'coursedefaults'}{$item} eq '') &&
                   11738:                     ($env{'form.'.$item} eq '1')) {
                   11739:                     $changes{$item} = 1;
                   11740:                 } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
                   11741:                     $changes{$item} = 1;
                   11742:                 }
                   11743:             }
                   11744:             $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
                   11745:         }
1.160.6.21  raeburn  11746:         foreach my $item (@numbers) {
                   11747:             my ($currdef,$newdef);
1.160.6.26  raeburn  11748:             $newdef = $env{'form.'.$item};
1.160.6.21  raeburn  11749:             if ($item eq 'anonsurvey_threshold') {
                   11750:                 $currdef = $domconfig{'coursedefaults'}{$item};
                   11751:                 $newdef =~ s/\D//g;
                   11752:                 if ($newdef eq '' || $newdef < 1) {
                   11753:                     $newdef = 1;
                   11754:                 }
                   11755:                 $defaultshash{'coursedefaults'}{$item} = $newdef;
                   11756:             } else {
1.160.6.70  raeburn  11757:                 my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
                   11758:                 if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
                   11759:                     $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.160.6.21  raeburn  11760:                 }
                   11761:                 $newdef =~ s/[^\w.\-]//g;
1.160.6.70  raeburn  11762:                 $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.160.6.21  raeburn  11763:             }
                   11764:             if ($currdef ne $newdef) {
                   11765:                 if ($item eq 'anonsurvey_threshold') {
                   11766:                     unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
                   11767:                         $changes{$item} = 1;
                   11768:                     }
1.160.6.70  raeburn  11769:                 } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
                   11770:                     my $setting = $1;
                   11771:                     unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
                   11772:                         $changes{$setting} = 1;
1.160.6.21  raeburn  11773:                     }
                   11774:                 }
1.139     raeburn  11775:             }
                   11776:         }
1.160.6.90! raeburn  11777:         my $texengine;
        !          11778:         if ($env{'form.texengine'} =~ /^(MathJax|mimetex|tth)$/) {
        !          11779:             $texengine = $env{'form.texengine'};
        !          11780:             my $currdef = $domconfig{'coursedefaults'}{'texengine'};
        !          11781:             if ($currdef eq '') {
        !          11782:                 unless ($texengine eq $Apache::lonnet::deftex) {
        !          11783:                     $changes{'texengine'} = 1;
        !          11784:                 }
        !          11785:             } elsif ($currdef ne $texengine) {
        !          11786:                 $changes{'texengine'} = 1;
        !          11787:             }
        !          11788:         }
        !          11789:         if ($texengine ne '') {
        !          11790:             $defaultshash{'coursedefaults'}{'texengine'} = $texengine;
        !          11791:         }
1.160.6.64  raeburn  11792:         my $currclone = $domconfig{'coursedefaults'}{'canclone'};
                   11793:         my @currclonecode;
                   11794:         if (ref($currclone) eq 'HASH') {
                   11795:             if (ref($currclone->{'instcode'}) eq 'ARRAY') {
                   11796:                 @currclonecode = @{$currclone->{'instcode'}};
                   11797:             }
                   11798:         }
                   11799:         my $newclone;
                   11800:         if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
                   11801:             $newclone = $env{'form.canclone'};
                   11802:         }
                   11803:         if ($newclone eq 'instcode') {
                   11804:             my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
                   11805:             my (%codedefaults,@code_order,@clonecode);
                   11806:             &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
                   11807:                                                     \@code_order);
                   11808:             foreach my $item (@code_order) {
                   11809:                 if (grep(/^\Q$item\E$/,@newcodes)) {
                   11810:                     push(@clonecode,$item);
                   11811:                 }
                   11812:             }
                   11813:             if (@clonecode) {
                   11814:                 $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
                   11815:                 my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
                   11816:                 if (@diffs) {
                   11817:                     $changes{'canclone'} = 1;
                   11818:                 }
                   11819:             } else {
                   11820:                 $newclone eq '';
                   11821:             }
                   11822:         } elsif ($newclone ne '') {
                   11823:             $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
                   11824:         }
                   11825:         if ($newclone ne $currclone) {
                   11826:             $changes{'canclone'} = 1;
                   11827:         }
1.160.6.57  raeburn  11828:         my %credits;
                   11829:         foreach my $type (@types) {
                   11830:             unless ($type eq 'community') {
                   11831:                 $credits{$type} = $env{'form.'.$type.'_credits'};
                   11832:                 $credits{$type} =~ s/[^\d.]+//g;
                   11833:             }
                   11834:         }
                   11835:         if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
                   11836:             ($env{'form.coursecredits'} eq '1')) {
                   11837:             $changes{'coursecredits'} = 1;
                   11838:             foreach my $type (keys(%credits)) {
                   11839:                 $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
                   11840:             }
                   11841:         } else {
                   11842:             if ($env{'form.coursecredits'} eq '1') {
                   11843:                 foreach my $type (@types) {
                   11844:                     unless ($type eq 'community') {
                   11845:                         if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
                   11846:                             $changes{'coursecredits'} = 1;
                   11847:                         }
                   11848:                         $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
                   11849:                     }
                   11850:                 }
                   11851:             } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
                   11852:                 foreach my $type (@types) {
                   11853:                     unless ($type eq 'community') {
                   11854:                         if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
                   11855:                             $changes{'coursecredits'} = 1;
                   11856:                             last;
                   11857:                         }
                   11858:                     }
                   11859:                 }
                   11860:             }
                   11861:         }
                   11862:         if ($env{'form.postsubmit'} eq '1') {
                   11863:             $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
                   11864:             my %currtimeout;
                   11865:             if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
                   11866:                 if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
                   11867:                     $changes{'postsubmit'} = 1;
                   11868:                 }
                   11869:                 if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
                   11870:                     %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
                   11871:                 }
                   11872:             } else {
                   11873:                 $changes{'postsubmit'} = 1;
                   11874:             }
                   11875:             foreach my $type (@types) {
                   11876:                 my $timeout = $env{'form.'.$type.'_timeout'};
                   11877:                 $timeout =~ s/\D//g;
                   11878:                 if ($timeout == $staticdefaults{'postsubmit'}) {
                   11879:                     $timeout = '';
                   11880:                 } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
                   11881:                     $timeout = '0';
                   11882:                 }
                   11883:                 unless ($timeout eq '') {
                   11884:                     $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
                   11885:                 }
                   11886:                 if (exists($currtimeout{$type})) {
                   11887:                     if ($timeout ne $currtimeout{$type}) {
                   11888:                         $changes{'postsubmit'} = 1;
                   11889:                     }
                   11890:                 } elsif ($timeout ne '') {
                   11891:                     $changes{'postsubmit'} = 1;
                   11892:                 }
                   11893:             }
                   11894:         } else {
                   11895:             $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
                   11896:             if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
                   11897:                 if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
                   11898:                     $changes{'postsubmit'} = 1;
                   11899:                 }
                   11900:             } else {
                   11901:                 $changes{'postsubmit'} = 1;
                   11902:             }
1.160.6.16  raeburn  11903:         }
1.121     raeburn  11904:     }
                   11905:     my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
                   11906:                                              $dom);
                   11907:     if ($putresult eq 'ok') {
                   11908:         if (keys(%changes) > 0) {
1.160.6.27  raeburn  11909:             my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.57  raeburn  11910:             if (($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.160.6.64  raeburn  11911:                 ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.160.6.90! raeburn  11912:                 ($changes{'canclone'}) || ($changes{'mysqltables'}) || ($changes{'texengine'})) {
        !          11913:                 foreach my $item ('uselcmath','usejsme','texengine') {
1.160.6.57  raeburn  11914:                     if ($changes{$item}) {
                   11915:                         $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
                   11916:                     }
1.160.6.16  raeburn  11917:                 }
                   11918:                 if ($changes{'coursecredits'}) {
                   11919:                     if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.160.6.57  raeburn  11920:                         foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
                   11921:                             $domdefaults{$type.'credits'} =
                   11922:                                 $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
                   11923:                         }
                   11924:                     }
                   11925:                 }
                   11926:                 if ($changes{'postsubmit'}) {
                   11927:                     if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
                   11928:                         $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
                   11929:                         if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
                   11930:                             foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
                   11931:                                 $domdefaults{$type.'postsubtimeout'} =
                   11932:                                     $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
                   11933:                             }
                   11934:                         }
1.160.6.16  raeburn  11935:                     }
                   11936:                 }
1.160.6.21  raeburn  11937:                 if ($changes{'uploadquota'}) {
                   11938:                     if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
                   11939:                         foreach my $type (@types) {
                   11940:                             $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
                   11941:                         }
                   11942:                     }
                   11943:                 }
1.160.6.64  raeburn  11944:                 if ($changes{'canclone'}) {
                   11945:                     if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
                   11946:                         if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
                   11947:                             my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
                   11948:                             if (@clonecodes) {
                   11949:                                 $domdefaults{'canclone'} = join('+',@clonecodes);
                   11950:                             }
                   11951:                         }
                   11952:                     } else {
                   11953:                         $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
                   11954:                     }
                   11955:                 }
1.121     raeburn  11956:                 my $cachetime = 24*60*60;
                   11957:                 &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27  raeburn  11958:                 if (ref($lastactref) eq 'HASH') {
                   11959:                     $lastactref->{'domdefaults'} = 1;
                   11960:                 }
1.121     raeburn  11961:             }
                   11962:             $resulttext = &mt('Changes made:').'<ul>';
                   11963:             foreach my $item (sort(keys(%changes))) {
1.160.6.57  raeburn  11964:                 if ($item eq 'uselcmath') {
1.121     raeburn  11965:                     if ($env{'form.'.$item} eq '1') {
1.160.6.57  raeburn  11966:                         $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
1.121     raeburn  11967:                     } else {
1.160.6.57  raeburn  11968:                         $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
                   11969:                     }
                   11970:                 } elsif ($item eq 'usejsme') {
                   11971:                     if ($env{'form.'.$item} eq '1') {
                   11972:                         $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
                   11973:                     } else {
                   11974:                         $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.121     raeburn  11975:                     }
1.160.6.90! raeburn  11976:                 } elsif ($item eq 'texengine') {
        !          11977:                     if ($defaultshash{'coursedefaults'}{'texengine'} ne '') {
        !          11978:                         $resulttext .= '<li>'.&mt('Default method to display mathematics set to: "[_1]"',
        !          11979:                                                   $texoptions{$defaultshash{'coursedefaults'}{'texengine'}}).'</li>';
        !          11980:                     }
1.139     raeburn  11981:                 } elsif ($item eq 'anonsurvey_threshold') {
1.160.6.26  raeburn  11982:                     $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.160.6.21  raeburn  11983:                 } elsif ($item eq 'uploadquota') {
                   11984:                     if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
                   11985:                         $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
                   11986:                                        '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
                   11987:                                        '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.160.6.30  raeburn  11988:                                        '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
                   11989: 
1.160.6.21  raeburn  11990:                                        '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
                   11991:                                        '</ul>'.
                   11992:                                        '</li>';
                   11993:                     } else {
                   11994:                         $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
                   11995:                     }
1.160.6.70  raeburn  11996:                 } elsif ($item eq 'mysqltables') {
                   11997:                     if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
                   11998:                         $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
                   11999:                                        '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
                   12000:                                        '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
                   12001:                                        '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
                   12002:                                        '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
                   12003:                                        '</ul>'.
                   12004:                                        '</li>';
                   12005:                     } else {
                   12006:                         $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
                   12007:                     }
1.160.6.57  raeburn  12008:                 } elsif ($item eq 'postsubmit') {
                   12009:                     if ($domdefaults{'postsubmit'} eq 'off') {
                   12010:                         $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
                   12011:                     } else {
                   12012:                         $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
                   12013:                         if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
                   12014:                             $resulttext .= &mt('durations:').'<ul>';
                   12015:                             foreach my $type (@types) {
                   12016:                                 $resulttext .= '<li>';
                   12017:                                 my $timeout;
                   12018:                                 if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
                   12019:                                     $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
                   12020:                                 }
                   12021:                                 my $display;
                   12022:                                 if ($timeout eq '0') {
                   12023:                                     $display = &mt('unlimited');
                   12024:                                 } elsif ($timeout eq '') {
                   12025:                                     $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
                   12026:                                 } else {
                   12027:                                     $display = &mt('[quant,_1,second]',$timeout);
                   12028:                                 }
                   12029:                                 if ($type eq 'community') {
                   12030:                                     $resulttext .= &mt('Communities');
                   12031:                                 } elsif ($type eq 'official') {
                   12032:                                     $resulttext .= &mt('Official courses');
                   12033:                                 } elsif ($type eq 'unofficial') {
                   12034:                                     $resulttext .= &mt('Unofficial courses');
                   12035:                                 } elsif ($type eq 'textbook') {
                   12036:                                     $resulttext .= &mt('Textbook courses');
                   12037:                                 }
                   12038:                                 $resulttext .= ' -- '.$display.'</li>';
                   12039:                             }
                   12040:                             $resulttext .= '</ul>';
                   12041:                         }
                   12042:                         $resulttext .= '</li>';
                   12043:                     }
1.160.6.16  raeburn  12044:                 } elsif ($item eq 'coursecredits') {
                   12045:                     if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
                   12046:                         if (($domdefaults{'officialcredits'} eq '') &&
1.160.6.30  raeburn  12047:                             ($domdefaults{'unofficialcredits'} eq '') &&
                   12048:                             ($domdefaults{'textbookcredits'} eq '')) {
1.160.6.16  raeburn  12049:                             $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
                   12050:                         } else {
                   12051:                             $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
                   12052:                                            '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
                   12053:                                            '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.160.6.30  raeburn  12054:                                            '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.160.6.16  raeburn  12055:                                            '</ul>'.
                   12056:                                            '</li>';
                   12057:                         }
                   12058:                     } else {
                   12059:                         $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
                   12060:                     }
1.160.6.64  raeburn  12061:                 } elsif ($item eq 'canclone') {
                   12062:                     if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
                   12063:                         if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
                   12064:                             my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
                   12065:                             $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
                   12066:                         }
                   12067:                     } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
                   12068:                         $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
                   12069:                     } else {
                   12070:                         $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
                   12071:                     }
1.140     raeburn  12072:                 }
1.121     raeburn  12073:             }
                   12074:             $resulttext .= '</ul>';
                   12075:         } else {
                   12076:             $resulttext = &mt('No changes made to course defaults');
                   12077:         }
                   12078:     } else {
                   12079:         $resulttext = '<span class="LC_error">'.
                   12080:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   12081:     }
                   12082:     return $resulttext;
                   12083: }
                   12084: 
1.160.6.37  raeburn  12085: sub modify_selfenrollment {
                   12086:     my ($dom,$lastactref,%domconfig) = @_;
                   12087:     my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
                   12088:     my @types = ('official','unofficial','community','textbook');
                   12089:     my %titles = &tool_titles();
                   12090:     my %descs = &Apache::lonuserutils::selfenroll_default_descs();
                   12091:     ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
                   12092:     $ordered{'default'} = ['types','registered','approval','limit'];
                   12093: 
                   12094:     my (%roles,%shown,%toplevel);
                   12095:     $roles{'0'} = &Apache::lonnet::plaintext('dc');
                   12096: 
                   12097:     if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
                   12098:         if ($domconfig{'selfenrollment'} eq '') {
                   12099:             $domconfig{'selfenrollment'} = {};
                   12100:         }
                   12101:     }
                   12102:     %toplevel = (
                   12103:                   admin      => 'Configuration Rights',
                   12104:                   default    => 'Default settings',
                   12105:                   validation => 'Validation of self-enrollment requests',
                   12106:                 );
                   12107:     my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
                   12108: 
                   12109:     if (ref($ordered{'admin'}) eq 'ARRAY') {
                   12110:         foreach my $item (@{$ordered{'admin'}}) {
                   12111:             foreach my $type (@types) {
                   12112:                 if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
                   12113:                     $selfenrollhash{'admin'}{$type}{$item} = 1;
                   12114:                 } else {
                   12115:                     $selfenrollhash{'admin'}{$type}{$item} = 0;
                   12116:                 }
                   12117:                 if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
                   12118:                     if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
                   12119:                         if ($selfenrollhash{'admin'}{$type}{$item} ne
                   12120:                             $domconfig{'selfenrollment'}{'admin'}{$type}{$item})  {
                   12121:                             push(@{$changes{'admin'}{$type}},$item);
                   12122:                         }
                   12123:                     } else {
                   12124:                         if (!$selfenrollhash{'admin'}{$type}{$item}) {
                   12125:                             push(@{$changes{'admin'}{$type}},$item);
                   12126:                         }
                   12127:                     }
                   12128:                 } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
                   12129:                     push(@{$changes{'admin'}{$type}},$item);
                   12130:                 }
                   12131:             }
                   12132:         }
                   12133:     }
                   12134: 
                   12135:     foreach my $item (@{$ordered{'default'}}) {
                   12136:         foreach my $type (@types) {
                   12137:             my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
                   12138:             if ($item eq 'types') {
                   12139:                 unless (($value eq 'all') || ($value eq 'dom')) {
                   12140:                     $value = '';
                   12141:                 }
                   12142:             } elsif ($item eq 'registered') {
                   12143:                 unless ($value eq '1') {
                   12144:                     $value = 0;
                   12145:                 }
                   12146:             } elsif ($item eq 'approval') {
                   12147:                 unless ($value =~ /^[012]$/) {
                   12148:                     $value = 0;
                   12149:                 }
                   12150:             } else {
                   12151:                 unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
                   12152:                     $value = 'none';
                   12153:                 }
                   12154:             }
                   12155:             $selfenrollhash{'default'}{$type}{$item} = $value;
                   12156:             if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
                   12157:                 if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
                   12158:                     if ($selfenrollhash{'default'}{$type}{$item} ne
                   12159:                          $domconfig{'selfenrollment'}{'default'}{$type}{$item})  {
                   12160:                          push(@{$changes{'default'}{$type}},$item);
                   12161:                     }
                   12162:                 } else {
                   12163:                     push(@{$changes{'default'}{$type}},$item);
                   12164:                 }
                   12165:             } else {
                   12166:                 push(@{$changes{'default'}{$type}},$item);
                   12167:             }
                   12168:             if ($item eq 'limit') {
                   12169:                 if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
                   12170:                     $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
                   12171:                     if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
                   12172:                         $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
                   12173:                     }
                   12174:                 } else {
                   12175:                     $selfenrollhash{'default'}{$type}{'cap'} = '';
                   12176:                 }
                   12177:                 if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
                   12178:                     if ($selfenrollhash{'default'}{$type}{'cap'} ne
                   12179:                          $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'})  {
                   12180:                          push(@{$changes{'default'}{$type}},'cap');
                   12181:                     }
                   12182:                 } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
                   12183:                     push(@{$changes{'default'}{$type}},'cap');
                   12184:                 }
                   12185:             }
                   12186:         }
                   12187:     }
                   12188: 
                   12189:     foreach my $item (@{$itemsref}) {
                   12190:         if ($item eq 'fields') {
                   12191:             my @changed;
                   12192:             @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
                   12193:             if (@{$selfenrollhash{'validation'}{$item}} > 0) {
                   12194:                 @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
                   12195:             }
                   12196:             if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
                   12197:                 if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
                   12198:                     @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
                   12199:                                                                   $domconfig{'selfenrollment'}{'validation'}{$item});
                   12200:                 } else {
                   12201:                     @changed = @{$selfenrollhash{'validation'}{$item}};
                   12202:                 }
                   12203:             } else {
                   12204:                 @changed = @{$selfenrollhash{'validation'}{$item}};
                   12205:             }
                   12206:             if (@changed) {
                   12207:                 if ($selfenrollhash{'validation'}{$item}) { 
                   12208:                     $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
                   12209:                 } else {
                   12210:                     $changes{'validation'}{$item} = &mt('None');
                   12211:                 }
                   12212:             }
                   12213:         } else {
                   12214:             $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
                   12215:             if ($item eq 'markup') {
                   12216:                if ($env{'form.selfenroll_validation_'.$item}) {
                   12217:                    $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
                   12218:                }
                   12219:             }
                   12220:             if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
                   12221:                 if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
                   12222:                     $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
                   12223:                 }
                   12224:             }
                   12225:         }
                   12226:     }
                   12227: 
                   12228:     my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
                   12229:                                              $dom);
                   12230:     if ($putresult eq 'ok') {
                   12231:         if (keys(%changes) > 0) {
                   12232:             my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
                   12233:             $resulttext = &mt('Changes made:').'<ul>';
                   12234:             foreach my $key ('admin','default','validation') {
                   12235:                 if (ref($changes{$key}) eq 'HASH') {
                   12236:                     $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
                   12237:                     if ($key eq 'validation') {
                   12238:                         foreach my $item (@{$itemsref}) {
                   12239:                             if (exists($changes{$key}{$item})) {
                   12240:                                 if ($item eq 'markup') {
                   12241:                                     $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
                   12242:                                                               '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
                   12243:                                 } else {  
                   12244:                                     $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
                   12245:                                                               '<b>'.$changes{$key}{$item}.'</b>').'</li>';
                   12246:                                 }
                   12247:                             }
                   12248:                         }
                   12249:                     } else {
                   12250:                         foreach my $type (@types) {
                   12251:                             if ($type eq 'community') {
                   12252:                                 $roles{'1'} = &mt('Community personnel');
                   12253:                             } else {
                   12254:                                 $roles{'1'} = &mt('Course personnel');
                   12255:                             }
                   12256:                             if (ref($changes{$key}{$type}) eq 'ARRAY') {
                   12257:                                 if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
                   12258:                                     if ($key eq 'admin') {
                   12259:                                         my @mgrdc = ();
                   12260:                                         if (ref($ordered{$key}) eq 'ARRAY') {
                   12261:                                             foreach my $item (@{$ordered{'admin'}}) {
                   12262:                                                 if (ref($selfenrollhash{$key}{$type}) eq 'HASH') { 
                   12263:                                                     if ($selfenrollhash{$key}{$type}{$item} eq '0') {
                   12264:                                                         push(@mgrdc,$item);
                   12265:                                                     }
                   12266:                                                 }
                   12267:                                             }
                   12268:                                             if (@mgrdc) {
                   12269:                                                 $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
                   12270:                                             } else {
                   12271:                                                 delete($domdefaults{$type.'selfenrolladmdc'});
                   12272:                                             }
                   12273:                                         }
                   12274:                                     } else {
                   12275:                                         if (ref($ordered{$key}) eq 'ARRAY') {
                   12276:                                             foreach my $item (@{$ordered{$key}}) {
                   12277:                                                 if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
                   12278:                                                     $domdefaults{$type.'selfenroll'.$item} =
                   12279:                                                         $selfenrollhash{$key}{$type}{$item};
                   12280:                                                 }
                   12281:                                             }
                   12282:                                         }
                   12283:                                     }
                   12284:                                 }
                   12285:                                 $resulttext .= '<li>'.$titles{$type}.'<ul>';
                   12286:                                 foreach my $item (@{$ordered{$key}}) {
                   12287:                                     if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
                   12288:                                         $resulttext .= '<li>';
                   12289:                                         if ($key eq 'admin') {
                   12290:                                             $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
                   12291:                                                                '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
                   12292:                                         } else {
                   12293:                                             $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
                   12294:                                                                '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
                   12295:                                         }
                   12296:                                         $resulttext .= '</li>';
                   12297:                                     }
                   12298:                                 }
                   12299:                                 $resulttext .= '</ul></li>';
                   12300:                             }
                   12301:                         }
                   12302:                         $resulttext .= '</ul></li>'; 
                   12303:                     }
                   12304:                 }
                   12305:                 if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
                   12306:                     my $cachetime = 24*60*60;
                   12307:                     &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
                   12308:                     if (ref($lastactref) eq 'HASH') {
                   12309:                         $lastactref->{'domdefaults'} = 1;
                   12310:                     }
                   12311:                 }
                   12312:             }
                   12313:             $resulttext .= '</ul>';
                   12314:         } else {
                   12315:             $resulttext = &mt('No changes made to self-enrollment settings');
                   12316:         }
                   12317:     } else {
                   12318:         $resulttext = '<span class="LC_error">'.
                   12319:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   12320:     }
                   12321:     return $resulttext;
                   12322: }
                   12323: 
1.137     raeburn  12324: sub modify_usersessions {
1.160.6.27  raeburn  12325:     my ($dom,$lastactref,%domconfig) = @_;
1.145     raeburn  12326:     my @hostingtypes = ('version','excludedomain','includedomain');
                   12327:     my @offloadtypes = ('primary','default');
                   12328:     my %types = (
                   12329:                   remote => \@hostingtypes,
                   12330:                   hosted => \@hostingtypes,
                   12331:                   spares => \@offloadtypes,
                   12332:                 );
                   12333:     my @prefixes = ('remote','hosted','spares');
1.137     raeburn  12334:     my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138     raeburn  12335:     my (%by_ip,%by_location,@intdoms);
                   12336:     &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
                   12337:     my @locations = sort(keys(%by_location));
1.137     raeburn  12338:     my (%defaultshash,%changes);
                   12339:     foreach my $prefix (@prefixes) {
                   12340:         $defaultshash{'usersessions'}{$prefix} = {};
                   12341:     }
1.160.6.27  raeburn  12342:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137     raeburn  12343:     my $resulttext;
1.138     raeburn  12344:     my %iphost = &Apache::lonnet::get_iphost();
1.137     raeburn  12345:     foreach my $prefix (@prefixes) {
1.145     raeburn  12346:         next if ($prefix eq 'spares');
                   12347:         foreach my $type (@{$types{$prefix}}) {
1.137     raeburn  12348:             my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
                   12349:             if ($type eq 'version') {
                   12350:                 my $value = $env{'form.'.$prefix.'_'.$type};
                   12351:                 my $okvalue;
                   12352:                 if ($value ne '') {
                   12353:                     if (grep(/^\Q$value\E$/,@lcversions)) {
                   12354:                         $okvalue = $value;
                   12355:                     }
                   12356:                 }
                   12357:                 if (ref($domconfig{'usersessions'}) eq 'HASH') {
                   12358:                     if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
                   12359:                         if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
                   12360:                             if ($inuse == 0) {
                   12361:                                 $changes{$prefix}{$type} = 1;
                   12362:                             } else {
                   12363:                                 if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
                   12364:                                     $changes{$prefix}{$type} = 1;
                   12365:                                 }
                   12366:                                 if ($okvalue ne '') {
                   12367:                                     $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
                   12368:                                 } 
                   12369:                             }
                   12370:                         } else {
                   12371:                             if (($inuse == 1) && ($okvalue ne '')) {
                   12372:                                 $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
                   12373:                                 $changes{$prefix}{$type} = 1;
                   12374:                             }
                   12375:                         }
                   12376:                     } else {
                   12377:                         if (($inuse == 1) && ($okvalue ne '')) {
                   12378:                             $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
                   12379:                             $changes{$prefix}{$type} = 1;
                   12380:                         }
                   12381:                     }
                   12382:                 } else {
                   12383:                     if (($inuse == 1) && ($okvalue ne '')) {
                   12384:                         $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
                   12385:                         $changes{$prefix}{$type} = 1;
                   12386:                     }
                   12387:                 }
                   12388:             } else {
                   12389:                 my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
                   12390:                 my @okvals;
                   12391:                 foreach my $val (@vals) {
1.138     raeburn  12392:                     if ($val =~ /:/) {
                   12393:                         my @items = split(/:/,$val);
                   12394:                         foreach my $item (@items) {
                   12395:                             if (ref($by_location{$item}) eq 'ARRAY') {
                   12396:                                 push(@okvals,$item);
                   12397:                             }
                   12398:                         }
                   12399:                     } else {
                   12400:                         if (ref($by_location{$val}) eq 'ARRAY') {
                   12401:                             push(@okvals,$val);
                   12402:                         }
1.137     raeburn  12403:                     }
                   12404:                 }
                   12405:                 @okvals = sort(@okvals);
                   12406:                 if (ref($domconfig{'usersessions'}) eq 'HASH') {
                   12407:                     if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
                   12408:                         if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
                   12409:                             if ($inuse == 0) {
                   12410:                                 $changes{$prefix}{$type} = 1; 
                   12411:                             } else {
                   12412:                                 $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
                   12413:                                 my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
                   12414:                                 if (@changed > 0) {
                   12415:                                     $changes{$prefix}{$type} = 1;
                   12416:                                 }
                   12417:                             }
                   12418:                         } else {
                   12419:                             if ($inuse == 1) {
                   12420:                                 $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
                   12421:                                 $changes{$prefix}{$type} = 1;
                   12422:                             }
                   12423:                         } 
                   12424:                     } else {
                   12425:                         if ($inuse == 1) {
                   12426:                             $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
                   12427:                             $changes{$prefix}{$type} = 1;
                   12428:                         }
                   12429:                     }
                   12430:                 } else {
                   12431:                     if ($inuse == 1) {
                   12432:                         $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
                   12433:                         $changes{$prefix}{$type} = 1;
                   12434:                     }
                   12435:                 }
                   12436:             }
                   12437:         }
                   12438:     }
1.145     raeburn  12439: 
                   12440:     my @alldoms = &Apache::lonnet::all_domains();
1.149     raeburn  12441:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145     raeburn  12442:     my %spareid = &current_offloads_to($dom,$domconfig{'usersessions'},\%servers);
                   12443:     my $savespares;
                   12444: 
                   12445:     foreach my $lonhost (sort(keys(%servers))) {
                   12446:         my $serverhomeID =
                   12447:             &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152     raeburn  12448:         my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145     raeburn  12449:         $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
                   12450:         my %spareschg;
                   12451:         foreach my $type (@{$types{'spares'}}) {
                   12452:             my @okspares;
                   12453:             my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
                   12454:             foreach my $server (@checked) {
1.152     raeburn  12455:                 if (&Apache::lonnet::hostname($server) ne '') {
                   12456:                     unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
                   12457:                         unless (grep(/^\Q$server\E$/,@okspares)) {
                   12458:                             push(@okspares,$server);
                   12459:                         }
1.145     raeburn  12460:                     }
                   12461:                 }
                   12462:             }
                   12463:             my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
                   12464:             my $newspare;
1.152     raeburn  12465:             if (($new ne '') && (&Apache::lonnet::hostname($new))) {
                   12466:                 unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145     raeburn  12467:                     $newspare = $new;
                   12468:                 }
                   12469:             }
1.152     raeburn  12470:             my @spares;
                   12471:             if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
                   12472:                 @spares = sort(@okspares,$newspare);
                   12473:             } else {
                   12474:                 @spares = sort(@okspares);
                   12475:             }
                   12476:             $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145     raeburn  12477:             if (ref($spareid{$lonhost}) eq 'HASH') {
                   12478:                 if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152     raeburn  12479:                     my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145     raeburn  12480:                     if (@diffs > 0) {
                   12481:                         $spareschg{$type} = 1;
                   12482:                     }
                   12483:                 }
                   12484:             }
                   12485:         }
                   12486:         if (keys(%spareschg) > 0) {
                   12487:             $changes{'spares'}{$lonhost} = \%spareschg;
                   12488:         }
                   12489:     }
1.160.6.61  raeburn  12490:     $defaultshash{'usersessions'}{'offloadnow'} = {};
                   12491:     my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
                   12492:     my @okoffload;
                   12493:     if (@offloadnow) {
                   12494:         foreach my $server (@offloadnow) {
                   12495:             if (&Apache::lonnet::hostname($server) ne '') {
                   12496:                 unless (grep(/^\Q$server\E$/,@okoffload)) {
                   12497:                     push(@okoffload,$server);
                   12498:                 }
                   12499:             }
                   12500:         }
                   12501:         if (@okoffload) {
                   12502:             foreach my $lonhost (@okoffload) {
                   12503:                 $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
                   12504:             }
                   12505:         }
                   12506:     }
1.145     raeburn  12507:     if (ref($domconfig{'usersessions'}) eq 'HASH') {
                   12508:         if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
                   12509:             if (ref($changes{'spares'}) eq 'HASH') {
                   12510:                 if (keys(%{$changes{'spares'}}) > 0) {
                   12511:                     $savespares = 1;
                   12512:                 }
                   12513:             }
                   12514:         } else {
                   12515:             $savespares = 1;
                   12516:         }
1.160.6.61  raeburn  12517:         if (ref($domconfig{'usersessions'}{'offloadnow'}) eq 'HASH') {
                   12518:             foreach my $lonhost (keys(%{$domconfig{'usersessions'}{'offloadnow'}})) {
                   12519:                 unless ($defaultshash{'usersessions'}{'offloadnow'}{$lonhost}) {
                   12520:                     $changes{'offloadnow'} = 1;
                   12521:                     last;
                   12522:                 }
                   12523:             }
                   12524:             unless ($changes{'offloadnow'}) {
                   12525:                 foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{'offloadnow'}})) {
                   12526:                     unless ($domconfig{'usersessions'}{'offloadnow'}{$lonhost}) {
                   12527:                         $changes{'offloadnow'} = 1;
                   12528:                         last;
                   12529:                     }
                   12530:                 }
                   12531:             }
                   12532:         } elsif (@okoffload) {
                   12533:             $changes{'offloadnow'} = 1;
                   12534:         }
                   12535:     } elsif (@okoffload) {
                   12536:         $changes{'offloadnow'} = 1;
1.145     raeburn  12537:     }
1.147     raeburn  12538:     my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
                   12539:     if ((keys(%changes) > 0) || ($savespares)) {
1.137     raeburn  12540:         my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
                   12541:                                                  $dom);
                   12542:         if ($putresult eq 'ok') {
                   12543:             if (ref($defaultshash{'usersessions'}) eq 'HASH') {
                   12544:                 if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
                   12545:                     $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
                   12546:                 }
                   12547:                 if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
                   12548:                     $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
                   12549:                 }
1.160.6.61  raeburn  12550:                 if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
                   12551:                     $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
                   12552:                 }
1.137     raeburn  12553:             }
                   12554:             my $cachetime = 24*60*60;
                   12555:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.81  raeburn  12556:             &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.160.6.27  raeburn  12557:             if (ref($lastactref) eq 'HASH') {
                   12558:                 $lastactref->{'domdefaults'} = 1;
1.160.6.81  raeburn  12559:                 $lastactref->{'usersessions'} = 1;
1.160.6.27  raeburn  12560:             }
1.147     raeburn  12561:             if (keys(%changes) > 0) {
                   12562:                 my %lt = &usersession_titles();
                   12563:                 $resulttext = &mt('Changes made:').'<ul>';
                   12564:                 foreach my $prefix (@prefixes) {
                   12565:                     if (ref($changes{$prefix}) eq 'HASH') {
                   12566:                         $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
                   12567:                         if ($prefix eq 'spares') {
                   12568:                             if (ref($changes{$prefix}) eq 'HASH') {
                   12569:                                 foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
                   12570:                                     $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148     raeburn  12571:                                     my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.160.6.27  raeburn  12572:                                     my $cachekey = &escape('spares').':'.&escape($lonhostdom);
                   12573:                                     &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147     raeburn  12574:                                     if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
                   12575:                                         foreach my $type (@{$types{$prefix}}) {
                   12576:                                             if ($changes{$prefix}{$lonhost}{$type}) {
                   12577:                                                 my $offloadto = &mt('None');
                   12578:                                                 if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
                   12579:                                                     if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {   
                   12580:                                                         $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
                   12581:                                                     }
1.145     raeburn  12582:                                                 }
1.147     raeburn  12583:                                                 $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).('&nbsp;'x3);
1.145     raeburn  12584:                                             }
1.137     raeburn  12585:                                         }
                   12586:                                     }
1.147     raeburn  12587:                                     $resulttext .= '</li>';
1.137     raeburn  12588:                                 }
                   12589:                             }
1.147     raeburn  12590:                         } else {
                   12591:                             foreach my $type (@{$types{$prefix}}) {
                   12592:                                 if (defined($changes{$prefix}{$type})) {
                   12593:                                     my $newvalue;
                   12594:                                     if (ref($defaultshash{'usersessions'}) eq 'HASH') {
                   12595:                                         if (ref($defaultshash{'usersessions'}{$prefix})) {
                   12596:                                             if ($type eq 'version') {
                   12597:                                                 $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
                   12598:                                             } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
                   12599:                                                 if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
                   12600:                                                     $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
                   12601:                                                 }
1.145     raeburn  12602:                                             }
                   12603:                                         }
                   12604:                                     }
1.147     raeburn  12605:                                     if ($newvalue eq '') {
                   12606:                                         if ($type eq 'version') {
                   12607:                                             $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
                   12608:                                         } else {
                   12609:                                             $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
                   12610:                                         }
1.145     raeburn  12611:                                     } else {
1.147     raeburn  12612:                                         if ($type eq 'version') {
                   12613:                                             $newvalue .= ' '.&mt('(or later)'); 
                   12614:                                         }
                   12615:                                         $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145     raeburn  12616:                                     }
1.137     raeburn  12617:                                 }
                   12618:                             }
                   12619:                         }
1.147     raeburn  12620:                         $resulttext .= '</ul>';
1.137     raeburn  12621:                     }
                   12622:                 }
1.160.6.61  raeburn  12623:                 if ($changes{'offloadnow'}) {
                   12624:                     if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
                   12625:                         if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
                   12626:                             $resulttext .= '<li>'.&mt('Switch active users on next access, for server(s):').'<ul>';
                   12627:                             foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
                   12628:                                 $resulttext .= '<li>'.$lonhost.'</li>';
                   12629:                             }
                   12630:                             $resulttext .= '</ul>';
                   12631:                         } else {
                   12632:                             $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.');
                   12633:                         }
                   12634:                     } else {
                   12635:                         $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.').'</li>';
                   12636:                     }
                   12637:                 }
1.147     raeburn  12638:                 $resulttext .= '</ul>';
                   12639:             } else {
                   12640:                 $resulttext = $nochgmsg;
1.137     raeburn  12641:             }
                   12642:         } else {
                   12643:             $resulttext = '<span class="LC_error">'.
                   12644:                           &mt('An error occurred: [_1]',$putresult).'</span>';
                   12645:         }
                   12646:     } else {
1.147     raeburn  12647:         $resulttext = $nochgmsg;
1.137     raeburn  12648:     }
                   12649:     return $resulttext;
                   12650: }
                   12651: 
1.150     raeburn  12652: sub modify_loadbalancing {
                   12653:     my ($dom,%domconfig) = @_;
                   12654:     my $primary_id = &Apache::lonnet::domain($dom,'primary');
                   12655:     my $intdom = &Apache::lonnet::internet_dom($primary_id);
                   12656:     my ($othertitle,$usertypes,$types) =
                   12657:         &Apache::loncommon::sorted_inst_types($dom);
                   12658:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.55  raeburn  12659:     my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150     raeburn  12660:     my @sparestypes = ('primary','default');
                   12661:     my %typetitles = &sparestype_titles();
                   12662:     my $resulttext;
1.160.6.7  raeburn  12663:     my (%currbalancer,%currtargets,%currrules,%existing);
                   12664:     if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
                   12665:         %existing = %{$domconfig{'loadbalancing'}};
                   12666:     }
                   12667:     &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
                   12668:                               \%currtargets,\%currrules);
                   12669:     my ($saveloadbalancing,%defaultshash,%changes);
                   12670:     my ($alltypes,$othertypes,$titles) =
                   12671:         &loadbalancing_titles($dom,$intdom,$usertypes,$types);
                   12672:     my %ruletitles = &offloadtype_text();
                   12673:     my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
                   12674:     for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
                   12675:         my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
                   12676:         if ($balancer eq '') {
                   12677:             next;
                   12678:         }
                   12679:         if (!exists($servers{$balancer})) {
                   12680:             if (exists($currbalancer{$balancer})) {
                   12681:                 push(@{$changes{'delete'}},$balancer);
1.150     raeburn  12682:             }
1.160.6.7  raeburn  12683:             next;
                   12684:         }
                   12685:         if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
                   12686:             push(@{$changes{'delete'}},$balancer);
                   12687:             next;
                   12688:         }
                   12689:         if (!exists($currbalancer{$balancer})) {
                   12690:             push(@{$changes{'add'}},$balancer);
                   12691:         }
                   12692:         $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
                   12693:         $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
                   12694:         $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
                   12695:         unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
                   12696:             $saveloadbalancing = 1;
                   12697:         }
                   12698:         foreach my $sparetype (@sparestypes) {
                   12699:             my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
                   12700:             my @offloadto;
                   12701:             foreach my $target (@targets) {
                   12702:                 if (($servers{$target}) && ($target ne $balancer)) {
                   12703:                     if ($sparetype eq 'default') {
                   12704:                         if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
                   12705:                             next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150     raeburn  12706:                         }
                   12707:                     }
1.160.6.7  raeburn  12708:                     unless(grep(/^\Q$target\E$/,@offloadto)) {
                   12709:                         push(@offloadto,$target);
                   12710:                     }
1.150     raeburn  12711:                 }
                   12712:             }
1.160.6.76  raeburn  12713:             if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
                   12714:                 unless(grep(/^\Q$balancer\E$/,@offloadto)) {
                   12715:                     push(@offloadto,$balancer);
                   12716:                 }
                   12717:             }
                   12718:             $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150     raeburn  12719:         }
1.160.6.7  raeburn  12720:         if (ref($currtargets{$balancer}) eq 'HASH') {
1.150     raeburn  12721:             foreach my $sparetype (@sparestypes) {
1.160.6.7  raeburn  12722:                 if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
                   12723:                     my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150     raeburn  12724:                     if (@targetdiffs > 0) {
1.160.6.7  raeburn  12725:                         $changes{'curr'}{$balancer}{'targets'} = 1;
1.150     raeburn  12726:                     }
1.160.6.7  raeburn  12727:                 } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
                   12728:                     if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
                   12729:                         $changes{'curr'}{$balancer}{'targets'} = 1;
1.150     raeburn  12730:                     }
                   12731:                 }
                   12732:             }
                   12733:         } else {
1.160.6.7  raeburn  12734:             if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
                   12735:                 foreach my $sparetype (@sparestypes) {
                   12736:                     if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
                   12737:                         if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
                   12738:                             $changes{'curr'}{$balancer}{'targets'} = 1;
                   12739:                         }
1.150     raeburn  12740:                     }
                   12741:                 }
1.160.6.7  raeburn  12742:             }
1.150     raeburn  12743:         }
                   12744:         my $ishomedom;
1.160.6.7  raeburn  12745:         if (&Apache::lonnet::host_domain($balancer) eq $dom) {
                   12746:             $ishomedom = 1;
1.150     raeburn  12747:         }
                   12748:         if (ref($alltypes) eq 'ARRAY') {
                   12749:             foreach my $type (@{$alltypes}) {
                   12750:                 my $rule;
1.160.6.7  raeburn  12751:                 unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150     raeburn  12752:                          (!$ishomedom)) {
1.160.6.7  raeburn  12753:                     $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
                   12754:                 }
                   12755:                 if ($rule eq 'specific') {
1.160.6.55  raeburn  12756:                     my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
                   12757:                     if (exists($servers{$specifiedhost})) {
                   12758:                         $rule = $specifiedhost;
                   12759:                     }
1.150     raeburn  12760:                 }
1.160.6.7  raeburn  12761:                 $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
                   12762:                 if (ref($currrules{$balancer}) eq 'HASH') {
                   12763:                     if ($rule ne $currrules{$balancer}{$type}) {
                   12764:                         $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150     raeburn  12765:                     }
                   12766:                 } elsif ($rule ne '') {
1.160.6.7  raeburn  12767:                     $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150     raeburn  12768:                 }
                   12769:             }
                   12770:         }
1.160.6.7  raeburn  12771:     }
                   12772:     my $nochgmsg = &mt('No changes made to Load Balancer settings.');
                   12773:     if ((keys(%changes) > 0) || ($saveloadbalancing)) {
                   12774:         unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
                   12775:             $defaultshash{'loadbalancing'} = {};
                   12776:         }
                   12777:         my $putresult = &Apache::lonnet::put_dom('configuration',
                   12778:                                                  \%defaultshash,$dom);
                   12779:         if ($putresult eq 'ok') {
                   12780:             if (keys(%changes) > 0) {
1.160.6.54  raeburn  12781:                 my %toupdate;
1.160.6.7  raeburn  12782:                 if (ref($changes{'delete'}) eq 'ARRAY') {
                   12783:                     foreach my $balancer (sort(@{$changes{'delete'}})) {
                   12784:                         $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.160.6.54  raeburn  12785:                         $toupdate{$balancer} = 1;
1.150     raeburn  12786:                     }
1.160.6.7  raeburn  12787:                 }
                   12788:                 if (ref($changes{'add'}) eq 'ARRAY') {
                   12789:                     foreach my $balancer (sort(@{$changes{'add'}})) {
                   12790:                         $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.160.6.54  raeburn  12791:                         $toupdate{$balancer} = 1;
1.160.6.7  raeburn  12792:                     }
                   12793:                 }
                   12794:                 if (ref($changes{'curr'}) eq 'HASH') {
                   12795:                     foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.160.6.55  raeburn  12796:                         $toupdate{$balancer} = 1;
1.160.6.7  raeburn  12797:                         if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
                   12798:                             if ($changes{'curr'}{$balancer}{'targets'}) {
                   12799:                                 my %offloadstr;
                   12800:                                 foreach my $sparetype (@sparestypes) {
                   12801:                                     if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
                   12802:                                         if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
                   12803:                                             $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
                   12804:                                         }
                   12805:                                     }
1.150     raeburn  12806:                                 }
1.160.6.7  raeburn  12807:                                 if (keys(%offloadstr) == 0) {
                   12808:                                     $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150     raeburn  12809:                                 } else {
1.160.6.7  raeburn  12810:                                     my $showoffload;
                   12811:                                     foreach my $sparetype (@sparestypes) {
                   12812:                                         $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>:&nbsp;';
                   12813:                                         if (defined($offloadstr{$sparetype})) {
                   12814:                                             $showoffload .= $offloadstr{$sparetype};
                   12815:                                         } else {
                   12816:                                             $showoffload .= &mt('None');
                   12817:                                         }
                   12818:                                         $showoffload .= ('&nbsp;'x3);
                   12819:                                     }
                   12820:                                     $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150     raeburn  12821:                                 }
                   12822:                             }
                   12823:                         }
1.160.6.7  raeburn  12824:                         if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
                   12825:                             if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
                   12826:                                 foreach my $type (@{$alltypes}) {
                   12827:                                     if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
                   12828:                                         my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
                   12829:                                         my $balancetext;
                   12830:                                         if ($rule eq '') {
                   12831:                                             $balancetext =  $ruletitles{'default'};
1.160.6.26  raeburn  12832:                                         } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.160.6.55  raeburn  12833:                                                  ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
                   12834:                                             if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.160.6.54  raeburn  12835:                                                 foreach my $sparetype (@sparestypes) {
                   12836:                                                     if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
                   12837:                                                         map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
                   12838:                                                     }
                   12839:                                                 }
1.160.6.55  raeburn  12840:                                                 foreach my $item (@{$alltypes}) {
                   12841:                                                     next if ($item =~  /^_LC_ipchange/);
                   12842:                                                     my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
                   12843:                                                     if ($hasrule eq 'homeserver') {
                   12844:                                                         map { $toupdate{$_} = 1; } (keys(%libraryservers));
                   12845:                                                     } else {
                   12846:                                                         unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
                   12847:                                                             if ($servers{$hasrule}) {
                   12848:                                                                 $toupdate{$hasrule} = 1;
                   12849:                                                             }
                   12850:                                                         }
                   12851:                                                     }
                   12852:                                                 }
                   12853:                                                 if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
                   12854:                                                     $balancetext =  $ruletitles{$rule};
                   12855:                                                 } else {
                   12856:                                                     my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
                   12857:                                                     $balancetext = $ruletitles{'particular'}.' '.$receiver;
                   12858:                                                     if ($receiver) {
                   12859:                                                         $toupdate{$receiver};
                   12860:                                                     }
                   12861:                                                 }
                   12862:                                             } else {
                   12863:                                                 $balancetext =  $ruletitles{$rule};
1.160.6.54  raeburn  12864:                                             }
1.160.6.7  raeburn  12865:                                         } else {
                   12866:                                             $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
                   12867:                                         }
1.160.6.26  raeburn  12868:                                         $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150     raeburn  12869:                                     }
                   12870:                                 }
                   12871:                             }
                   12872:                         }
1.160.6.54  raeburn  12873:                         if (keys(%toupdate)) {
                   12874:                             my %thismachine;
                   12875:                             my $updatedhere;
                   12876:                             my $cachetime = 60*60*24;
                   12877:                             map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
                   12878:                             foreach my $lonhost (keys(%toupdate)) {
                   12879:                                 if ($thismachine{$lonhost}) {
                   12880:                                     unless ($updatedhere) {
                   12881:                                         &Apache::lonnet::do_cache_new('loadbalancing',$dom,
                   12882:                                                                       $defaultshash{'loadbalancing'},
                   12883:                                                                       $cachetime);
                   12884:                                         $updatedhere = 1;
                   12885:                                     }
                   12886:                                 } else {
                   12887:                                     my $cachekey = &escape('loadbalancing').':'.&escape($dom);
                   12888:                                     &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
                   12889:                                 }
                   12890:                             }
                   12891:                         }
1.150     raeburn  12892:                     }
1.160.6.7  raeburn  12893:                 }
                   12894:                 if ($resulttext ne '') {
                   12895:                     $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150     raeburn  12896:                 } else {
                   12897:                     $resulttext = $nochgmsg;
                   12898:                 }
                   12899:             } else {
1.160.6.7  raeburn  12900:                 $resulttext = $nochgmsg;
1.150     raeburn  12901:             }
                   12902:         } else {
1.160.6.7  raeburn  12903:             $resulttext = '<span class="LC_error">'.
                   12904:                           &mt('An error occurred: [_1]',$putresult).'</span>';
1.150     raeburn  12905:         }
                   12906:     } else {
1.160.6.7  raeburn  12907:         $resulttext = $nochgmsg;
1.150     raeburn  12908:     }
                   12909:     return $resulttext;
                   12910: }
                   12911: 
1.48      raeburn  12912: sub recurse_check {
                   12913:     my ($chkcats,$categories,$depth,$name) = @_;
                   12914:     if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
                   12915:         my $chg = 0;
                   12916:         for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
                   12917:             my $category = $chkcats->[$depth]{$name}[$j];
                   12918:             my $item;
                   12919:             if ($category eq '') {
                   12920:                 $chg ++;
                   12921:             } else {
                   12922:                 my $deeper = $depth + 1;
                   12923:                 $item = &escape($category).':'.&escape($name).':'.$depth;
                   12924:                 if ($chg) {
                   12925:                     $categories->{$item} -= $chg;
                   12926:                 }
                   12927:                 &recurse_check($chkcats,$categories,$deeper,$category);
                   12928:                 $deeper --;
                   12929:             }
                   12930:         }
                   12931:     }
                   12932:     return;
                   12933: }
                   12934: 
                   12935: sub recurse_cat_deletes {
                   12936:     my ($item,$coursecategories,$deletions) = @_;
                   12937:     my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
                   12938:     my $subdepth = $depth + 1;
                   12939:     if (ref($coursecategories) eq 'HASH') {
                   12940:         foreach my $subitem (keys(%{$coursecategories})) {
                   12941:             my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
                   12942:             if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
                   12943:                 delete($coursecategories->{$subitem});
                   12944:                 $deletions->{$subitem} = 1;
                   12945:                 &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.160.6.26  raeburn  12946:             }
1.48      raeburn  12947:         }
                   12948:     }
                   12949:     return;
                   12950: }
                   12951: 
1.125     raeburn  12952: sub active_dc_picker {
1.160.6.16  raeburn  12953:     my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.160.6.77  raeburn  12954:     my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.160.6.16  raeburn  12955:     my @domcoord = keys(%domcoords);
                   12956:     if (keys(%currhash)) {
                   12957:         foreach my $dc (keys(%currhash)) {
                   12958:             unless (exists($domcoords{$dc})) {
                   12959:                 push(@domcoord,$dc);
                   12960:             }
                   12961:         }
                   12962:     }
                   12963:     @domcoord = sort(@domcoord);
                   12964:     my $numdcs = scalar(@domcoord);
                   12965:     my $rows = 0;
                   12966:     my $table;
1.125     raeburn  12967:     if ($numdcs > 1) {
1.160.6.16  raeburn  12968:         $table = '<table>';
                   12969:         for (my $i=0; $i<@domcoord; $i++) {
1.125     raeburn  12970:             my $rem = $i%($numinrow);
                   12971:             if ($rem == 0) {
                   12972:                 if ($i > 0) {
1.160.6.16  raeburn  12973:                     $table .= '</tr>';
1.125     raeburn  12974:                 }
1.160.6.16  raeburn  12975:                 $table .= '<tr>';
                   12976:                 $rows ++;
1.125     raeburn  12977:             }
1.160.6.16  raeburn  12978:             my $check = '';
                   12979:             if ($inputtype eq 'radio') {
                   12980:                 if (keys(%currhash) == 0) {
                   12981:                     if (!$i) {
                   12982:                         $check = ' checked="checked"';
                   12983:                     }
                   12984:                 } elsif (exists($currhash{$domcoord[$i]})) {
                   12985:                     $check = ' checked="checked"';
                   12986:                 }
                   12987:             } else {
                   12988:                 if (exists($currhash{$domcoord[$i]})) {
                   12989:                     $check = ' checked="checked"';
1.125     raeburn  12990:                 }
                   12991:             }
1.160.6.16  raeburn  12992:             if ($i == @domcoord - 1) {
1.125     raeburn  12993:                 my $colsleft = $numinrow - $rem;
                   12994:                 if ($colsleft > 1) {
1.160.6.16  raeburn  12995:                     $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125     raeburn  12996:                 } else {
1.160.6.16  raeburn  12997:                     $table .= '<td class="LC_left_item">';
1.125     raeburn  12998:                 }
                   12999:             } else {
1.160.6.16  raeburn  13000:                 $table .= '<td class="LC_left_item">';
                   13001:             }
                   13002:             my ($dcname,$dcdom) = split(':',$domcoord[$i]);
                   13003:             my $user = &Apache::loncommon::plainname($dcname,$dcdom);
                   13004:             $table .= '<span class="LC_nobreak"><label>'.
                   13005:                       '<input type="'.$inputtype.'" name="'.$name.'"'.
                   13006:                       ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
                   13007:             if ($user ne $dcname.':'.$dcdom) {
1.160.6.32  raeburn  13008:                 $table .=  ' ('.$dcname.':'.$dcdom.')';
1.125     raeburn  13009:             }
1.160.6.33  raeburn  13010:             $table .= '</label></span></td>';
1.125     raeburn  13011:         }
1.160.6.16  raeburn  13012:         $table .= '</tr></table>';
                   13013:     } elsif ($numdcs == 1) {
1.160.6.32  raeburn  13014:         my ($dcname,$dcdom) = split(':',$domcoord[0]);
                   13015:         my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.16  raeburn  13016:         if ($inputtype eq 'radio') {
1.160.6.50  raeburn  13017:             $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.160.6.31  raeburn  13018:             if ($user ne $dcname.':'.$dcdom) {
                   13019:                 $table .=  ' ('.$dcname.':'.$dcdom.')';
                   13020:             }
1.160.6.16  raeburn  13021:         } else {
                   13022:             my $check;
                   13023:             if (exists($currhash{$domcoord[0]})) {
                   13024:                 $check = ' checked="checked"';
                   13025:             }
1.160.6.50  raeburn  13026:             $table = '<span class="LC_nobreak"><label>'.
                   13027:                      '<input type="checkbox" name="'.$name.'" '.
                   13028:                      'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.160.6.31  raeburn  13029:             if ($user ne $dcname.':'.$dcdom) {
                   13030:                 $table .=  ' ('.$dcname.':'.$dcdom.')';
                   13031:             }
                   13032:             $table .= '</label></span>';
1.160.6.16  raeburn  13033:             $rows ++;
                   13034:         }
1.125     raeburn  13035:     }
1.160.6.16  raeburn  13036:     return ($numdcs,$table,$rows);
1.125     raeburn  13037: }
                   13038: 
1.137     raeburn  13039: sub usersession_titles {
                   13040:     return &Apache::lonlocal::texthash(
                   13041:                hosted => 'Hosting of sessions for users from other domains on servers in this domain',
                   13042:                remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145     raeburn  13043:                spares => 'Servers offloaded to, when busy',
1.137     raeburn  13044:                version => 'LON-CAPA version requirement',
1.138     raeburn  13045:                excludedomain => 'Allow all, but exclude specific domains',
                   13046:                includedomain => 'Deny all, but include specific domains',
1.145     raeburn  13047:                primary => 'Primary (checked first)',
1.154     raeburn  13048:                default => 'Default',
1.137     raeburn  13049:            );
                   13050: }
                   13051: 
1.152     raeburn  13052: sub id_for_thisdom {
                   13053:     my (%servers) = @_;
                   13054:     my %altids;
                   13055:     foreach my $server (keys(%servers)) {
                   13056:         my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
                   13057:         if ($serverhome ne $server) {
                   13058:             $altids{$serverhome} = $server;
                   13059:         }
                   13060:     }
                   13061:     return %altids;
                   13062: }
                   13063: 
1.150     raeburn  13064: sub count_servers {
                   13065:     my ($currbalancer,%servers) = @_;
                   13066:     my (@spares,$numspares);
                   13067:     foreach my $lonhost (sort(keys(%servers))) {
                   13068:         next if ($currbalancer eq $lonhost);
                   13069:         push(@spares,$lonhost);
                   13070:     }
                   13071:     if ($currbalancer) {
                   13072:         $numspares = scalar(@spares);
                   13073:     } else {
                   13074:         $numspares = scalar(@spares) - 1;
                   13075:     }
                   13076:     return ($numspares,@spares);
                   13077: }
                   13078: 
                   13079: sub lonbalance_targets_js {
1.160.6.7  raeburn  13080:     my ($dom,$types,$servers,$settings) = @_;
1.150     raeburn  13081:     my $select = &mt('Select');
                   13082:     my ($alltargets,$allishome,$allinsttypes,@alltypes);
                   13083:     if (ref($servers) eq 'HASH') {
                   13084:         $alltargets = join("','",sort(keys(%{$servers})));
                   13085:         my @homedoms;
                   13086:         foreach my $server (sort(keys(%{$servers}))) {
                   13087:             if (&Apache::lonnet::host_domain($server) eq $dom) {
                   13088:                 push(@homedoms,'1');
                   13089:             } else {
                   13090:                 push(@homedoms,'0');
                   13091:             }
                   13092:         }
                   13093:         $allishome = join("','",@homedoms);
                   13094:     }
                   13095:     if (ref($types) eq 'ARRAY') {
                   13096:         if (@{$types} > 0) {
                   13097:             @alltypes = @{$types};
                   13098:         }
                   13099:     }
                   13100:     push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
                   13101:     $allinsttypes = join("','",@alltypes);
1.160.6.7  raeburn  13102:     my (%currbalancer,%currtargets,%currrules,%existing);
                   13103:     if (ref($settings) eq 'HASH') {
                   13104:         %existing = %{$settings};
                   13105:     }
                   13106:     &get_loadbalancers_config($servers,\%existing,\%currbalancer,
                   13107:                               \%currtargets,\%currrules);
                   13108:     my $balancers = join("','",sort(keys(%currbalancer)));
1.150     raeburn  13109:     return <<"END";
                   13110: 
                   13111: <script type="text/javascript">
                   13112: // <![CDATA[
                   13113: 
1.160.6.7  raeburn  13114: currBalancers = new Array('$balancers');
                   13115: 
                   13116: function toggleTargets(balnum) {
                   13117:     var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
                   13118:     var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
                   13119:     var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
                   13120:     var prevbalancer = prevhostitem.value;
                   13121:     var baltotal = document.getElementById('loadbalancing_total').value;
                   13122:     prevhostitem.value = balancer;
                   13123:     if (prevbalancer != '') {
                   13124:         var prevIdx = currBalancers.indexOf(prevbalancer);
                   13125:         if (prevIdx != -1) {
                   13126:             currBalancers.splice(prevIdx,1);
                   13127:         }
                   13128:     }
1.150     raeburn  13129:     if (balancer == '') {
1.160.6.7  raeburn  13130:         hideSpares(balnum);
1.150     raeburn  13131:     } else {
1.160.6.7  raeburn  13132:         var currIdx = currBalancers.indexOf(balancer);
                   13133:         if (currIdx == -1) {
                   13134:             currBalancers.push(balancer);
                   13135:         }
1.150     raeburn  13136:         var homedoms = new Array('$allishome');
1.160.6.7  raeburn  13137:         var ishomedom = homedoms[lonhostitem.selectedIndex];
                   13138:         showSpares(balancer,ishomedom,balnum);
1.150     raeburn  13139:     }
1.160.6.7  raeburn  13140:     balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150     raeburn  13141:     return;
                   13142: }
                   13143: 
1.160.6.7  raeburn  13144: function showSpares(balancer,ishomedom,balnum) {
1.150     raeburn  13145:     var alltargets = new Array('$alltargets');
                   13146:     var insttypes = new Array('$allinsttypes');
1.151     raeburn  13147:     var offloadtypes = new Array('primary','default');
                   13148: 
1.160.6.7  raeburn  13149:     document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
                   13150:     document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152     raeburn  13151:  
1.151     raeburn  13152:     for (var i=0; i<offloadtypes.length; i++) {
                   13153:         var count = 0;
                   13154:         for (var j=0; j<alltargets.length; j++) {
                   13155:             if (alltargets[j] != balancer) {
1.160.6.7  raeburn  13156:                 var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
                   13157:                 item.value = alltargets[j];
                   13158:                 item.style.textAlign='left';
                   13159:                 item.style.textFace='normal';
                   13160:                 document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
                   13161:                 if (currBalancers.indexOf(alltargets[j]) == -1) {
                   13162:                     item.disabled = '';
                   13163:                 } else {
                   13164:                     item.disabled = 'disabled';
                   13165:                     item.checked = false;
                   13166:                 }
1.151     raeburn  13167:                 count ++;
                   13168:             }
1.150     raeburn  13169:         }
                   13170:     }
1.151     raeburn  13171:     for (var k=0; k<insttypes.length; k++) {
                   13172:         if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150     raeburn  13173:             if (ishomedom == 1) {
1.160.6.7  raeburn  13174:                 document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
                   13175:                 document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150     raeburn  13176:             } else {
1.160.6.7  raeburn  13177:                 document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
                   13178:                 document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150     raeburn  13179:             }
                   13180:         } else {
1.160.6.7  raeburn  13181:             document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
                   13182:             document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150     raeburn  13183:         }
1.151     raeburn  13184:         if ((insttypes[k] != '_LC_external') && 
                   13185:             ((insttypes[k] != '_LC_internetdom') ||
                   13186:              ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.160.6.7  raeburn  13187:             var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
                   13188:             item.options.length = 0;
                   13189:             item.options[0] = new Option("","",true,true);
                   13190:             var idx = 0;
1.151     raeburn  13191:             for (var m=0; m<alltargets.length; m++) {
1.160.6.7  raeburn  13192:                 if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
                   13193:                     idx ++;
                   13194:                     item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150     raeburn  13195:                 }
                   13196:             }
                   13197:         }
                   13198:     }
                   13199:     return;
                   13200: }
                   13201: 
1.160.6.7  raeburn  13202: function hideSpares(balnum) {
1.150     raeburn  13203:     var alltargets = new Array('$alltargets');
                   13204:     var insttypes = new Array('$allinsttypes');
                   13205:     var offloadtypes = new Array('primary','default');
                   13206: 
1.160.6.7  raeburn  13207:     document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
                   13208:     document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150     raeburn  13209: 
                   13210:     var total = alltargets.length - 1;
                   13211:     for (var i=0; i<offloadtypes; i++) {
                   13212:         for (var j=0; j<total; j++) {
1.160.6.7  raeburn  13213:            document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
                   13214:            document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
                   13215:            document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151     raeburn  13216:         }
1.150     raeburn  13217:     }
                   13218:     for (var k=0; k<insttypes.length; k++) {
1.160.6.7  raeburn  13219:         document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
                   13220:         document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151     raeburn  13221:         if (insttypes[k] != '_LC_external') {
1.160.6.7  raeburn  13222:             document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
                   13223:             document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150     raeburn  13224:         }
                   13225:     }
                   13226:     return;
                   13227: }
                   13228: 
1.160.6.7  raeburn  13229: function checkOffloads(item,balnum,type) {
1.150     raeburn  13230:     var alltargets = new Array('$alltargets');
                   13231:     var offloadtypes = new Array('primary','default');
                   13232:     if (item.checked) {
                   13233:         var total = alltargets.length - 1;
                   13234:         var other;
                   13235:         if (type == offloadtypes[0]) {
1.151     raeburn  13236:             other = offloadtypes[1];
1.150     raeburn  13237:         } else {
1.151     raeburn  13238:             other = offloadtypes[0];
1.150     raeburn  13239:         }
                   13240:         for (var i=0; i<total; i++) {
1.160.6.7  raeburn  13241:             var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150     raeburn  13242:             if (server == item.value) {
1.160.6.7  raeburn  13243:                 if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
                   13244:                     document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150     raeburn  13245:                 }
                   13246:             }
                   13247:         }
                   13248:     }
                   13249:     return;
                   13250: }
                   13251: 
1.160.6.7  raeburn  13252: function singleServerToggle(balnum,type) {
                   13253:     var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150     raeburn  13254:     if (offloadtoSelIdx == 0) {
1.160.6.7  raeburn  13255:         document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
                   13256:         document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150     raeburn  13257: 
                   13258:     } else {
1.160.6.7  raeburn  13259:         document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
                   13260:         document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150     raeburn  13261:     }
                   13262:     return;
                   13263: }
                   13264: 
1.160.6.7  raeburn  13265: function balanceruleChange(formname,balnum,type) {
1.150     raeburn  13266:     if (type == '_LC_external') {
1.160.6.26  raeburn  13267:         return;
1.150     raeburn  13268:     }
1.160.6.7  raeburn  13269:     var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150     raeburn  13270:     for (var i=0; i<typesRules.length; i++) {
                   13271:         if (formname.elements[typesRules[i]].checked) {
                   13272:             if (formname.elements[typesRules[i]].value != 'specific') {
1.160.6.7  raeburn  13273:                 document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
                   13274:                 document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150     raeburn  13275:             } else {
1.160.6.7  raeburn  13276:                 document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
                   13277:             }
                   13278:         }
                   13279:     }
                   13280:     return;
                   13281: }
                   13282: 
                   13283: function balancerDeleteChange(balnum) {
                   13284:     var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
                   13285:     var baltotal = document.getElementById('loadbalancing_total').value;
                   13286:     var addtarget;
                   13287:     var removetarget;
                   13288:     var action = 'delete';
                   13289:     if (document.getElementById('loadbalancing_delete_'+balnum)) {
                   13290:         var lonhost = hostitem.value;
                   13291:         var currIdx = currBalancers.indexOf(lonhost);
                   13292:         if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
                   13293:             if (currIdx != -1) {
                   13294:                 currBalancers.splice(currIdx,1);
                   13295:             }
                   13296:             addtarget = lonhost;
                   13297:         } else {
                   13298:             if (currIdx == -1) {
                   13299:                 currBalancers.push(lonhost);
                   13300:             }
                   13301:             removetarget = lonhost;
                   13302:             action = 'undelete';
                   13303:         }
                   13304:         balancerChange(balnum,baltotal,action,addtarget,removetarget);
                   13305:     }
                   13306:     return;
                   13307: }
                   13308: 
                   13309: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
                   13310:     if (baltotal > 1) {
                   13311:         var offloadtypes = new Array('primary','default');
                   13312:         var alltargets = new Array('$alltargets');
                   13313:         var insttypes = new Array('$allinsttypes');
                   13314:         for (var i=0; i<baltotal; i++) {
                   13315:             if (i != balnum) {
                   13316:                 for (var j=0; j<offloadtypes.length; j++) {
                   13317:                     var total = alltargets.length - 1;
                   13318:                     for (var k=0; k<total; k++) {
                   13319:                         var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
                   13320:                         var server = serveritem.value;
                   13321:                         if ((action == 'delete') || (action == 'change' && addtarget != ''))  {
                   13322:                             if (server == addtarget) {
                   13323:                                 serveritem.disabled = '';
                   13324:                             }
                   13325:                         }
                   13326:                         if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
                   13327:                             if (server == removetarget) {
                   13328:                                 serveritem.disabled = 'disabled';
                   13329:                                 serveritem.checked = false;
                   13330:                             }
                   13331:                         }
                   13332:                     }
                   13333:                 }
                   13334:                 for (var j=0; j<insttypes.length; j++) {
                   13335:                     if (insttypes[j] != '_LC_external') {
                   13336:                         if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
                   13337:                             var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
                   13338:                             var currSel = singleserver.selectedIndex;
                   13339:                             var currVal = singleserver.options[currSel].value;
                   13340:                             if ((action == 'delete') || (action == 'change' && addtarget != '')) {
                   13341:                                 var numoptions = singleserver.options.length;
                   13342:                                 var needsnew = 1;
                   13343:                                 for (var k=0; k<numoptions; k++) {
                   13344:                                     if (singleserver.options[k] == addtarget) {
                   13345:                                         needsnew = 0;
                   13346:                                         break;
                   13347:                                     }
                   13348:                                 }
                   13349:                                 if (needsnew == 1) {
                   13350:                                     singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
                   13351:                                 }
                   13352:                             }
                   13353:                             if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
                   13354:                                 singleserver.options.length = 0;
                   13355:                                 if ((currVal) && (currVal != removetarget)) {
                   13356:                                     singleserver.options[0] = new Option("","",false,false);
                   13357:                                 } else {
                   13358:                                     singleserver.options[0] = new Option("","",true,true);
                   13359:                                 }
                   13360:                                 var idx = 0;
                   13361:                                 for (var m=0; m<alltargets.length; m++) {
                   13362:                                     if (currBalancers.indexOf(alltargets[m]) == -1) {
                   13363:                                         idx ++;
                   13364:                                         if (currVal == alltargets[m]) {
                   13365:                                             singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
                   13366:                                         } else {
                   13367:                                             singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
                   13368:                                         }
                   13369:                                     }
                   13370:                                 }
                   13371:                             }
                   13372:                         }
                   13373:                     }
                   13374:                 }
1.150     raeburn  13375:             }
                   13376:         }
                   13377:     }
                   13378:     return;
                   13379: }
                   13380: 
1.152     raeburn  13381: // ]]>
                   13382: </script>
                   13383: 
                   13384: END
                   13385: }
                   13386: 
                   13387: sub new_spares_js {
                   13388:     my @sparestypes = ('primary','default');
                   13389:     my $types = join("','",@sparestypes);
                   13390:     my $select = &mt('Select');
                   13391:     return <<"END";
                   13392: 
                   13393: <script type="text/javascript">
                   13394: // <![CDATA[
                   13395: 
                   13396: function updateNewSpares(formname,lonhost) {
                   13397:     var types = new Array('$types');
                   13398:     var include = new Array();
                   13399:     var exclude = new Array();
                   13400:     for (var i=0; i<types.length; i++) {
                   13401:         var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
                   13402:         for (var j=0; j<spareboxes.length; j++) {
                   13403:             if (formname.elements[spareboxes[j]].checked) {
                   13404:                 exclude.push(formname.elements[spareboxes[j]].value);
                   13405:             } else {
                   13406:                 include.push(formname.elements[spareboxes[j]].value);
                   13407:             }
                   13408:         }
                   13409:     }
                   13410:     for (var i=0; i<types.length; i++) {
                   13411:         var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
                   13412:         var selIdx = newSpare.selectedIndex;
                   13413:         var currnew = newSpare.options[selIdx].value;
                   13414:         var okSpares = new Array();
                   13415:         for (var j=0; j<newSpare.options.length; j++) {
                   13416:             var possible = newSpare.options[j].value;
                   13417:             if (possible != '') {
                   13418:                 if (exclude.indexOf(possible) == -1) {
                   13419:                     okSpares.push(possible);
                   13420:                 } else {
                   13421:                     if (currnew == possible) {
                   13422:                         selIdx = 0;
                   13423:                     }
                   13424:                 }
                   13425:             }
                   13426:         }
                   13427:         for (var k=0; k<include.length; k++) {
                   13428:             if (okSpares.indexOf(include[k]) == -1) {
                   13429:                 okSpares.push(include[k]);
                   13430:             }
                   13431:         }
                   13432:         okSpares.sort();
                   13433:         newSpare.options.length = 0;
                   13434:         if (selIdx == 0) {
                   13435:             newSpare.options[0] = new Option("$select","",true,true);
                   13436:         } else {
                   13437:             newSpare.options[0] = new Option("$select","",false,false);
                   13438:         }
                   13439:         for (var m=0; m<okSpares.length; m++) {
                   13440:             var idx = m+1;
                   13441:             var selThis = 0;
                   13442:             if (selIdx != 0) {
                   13443:                 if (okSpares[m] == currnew) {
                   13444:                     selThis = 1;
                   13445:                 }
                   13446:             }
                   13447:             if (selThis == 1) {
                   13448:                 newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
                   13449:             } else {
                   13450:                 newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
                   13451:             }
                   13452:         }
                   13453:     }
                   13454:     return;
                   13455: }
                   13456: 
                   13457: function checkNewSpares(lonhost,type) {
                   13458:     var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
                   13459:     var chosen =  newSpare.options[newSpare.selectedIndex].value;
                   13460:     if (chosen != '') { 
                   13461:         var othertype;
                   13462:         var othernewSpare;
                   13463:         if (type == 'primary') {
                   13464:             othernewSpare = document.getElementById('newspare_default_'+lonhost);
                   13465:         }
                   13466:         if (type == 'default') {
                   13467:             othernewSpare = document.getElementById('newspare_primary_'+lonhost);
                   13468:         }
                   13469:         if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
                   13470:             othernewSpare.selectedIndex = 0;
                   13471:         }
                   13472:     }
                   13473:     return;
                   13474: }
                   13475: 
                   13476: // ]]>
                   13477: </script>
                   13478: 
                   13479: END
                   13480: 
                   13481: }
                   13482: 
                   13483: sub common_domprefs_js {
                   13484:     return <<"END";
                   13485: 
                   13486: <script type="text/javascript">
                   13487: // <![CDATA[
                   13488: 
1.150     raeburn  13489: function getIndicesByName(formname,item) {
1.152     raeburn  13490:     var group = new Array();
1.150     raeburn  13491:     for (var i=0;i<formname.elements.length;i++) {
                   13492:         if (formname.elements[i].name == item) {
1.152     raeburn  13493:             group.push(formname.elements[i].id);
1.150     raeburn  13494:         }
                   13495:     }
1.152     raeburn  13496:     return group;
1.150     raeburn  13497: }
                   13498: 
                   13499: // ]]>
                   13500: </script>
                   13501: 
                   13502: END
1.152     raeburn  13503: 
1.150     raeburn  13504: }
                   13505: 
1.160.6.5  raeburn  13506: sub recaptcha_js {
                   13507:     my %lt = &captcha_phrases();
                   13508:     return <<"END";
                   13509: 
                   13510: <script type="text/javascript">
                   13511: // <![CDATA[
                   13512: 
                   13513: function updateCaptcha(caller,context) {
                   13514:     var privitem;
                   13515:     var pubitem;
                   13516:     var privtext;
                   13517:     var pubtext;
1.160.6.69  raeburn  13518:     var versionitem;
                   13519:     var versiontext;
1.160.6.5  raeburn  13520:     if (document.getElementById(context+'_recaptchapub')) {
                   13521:         pubitem = document.getElementById(context+'_recaptchapub');
                   13522:     } else {
                   13523:         return;
                   13524:     }
                   13525:     if (document.getElementById(context+'_recaptchapriv')) {
                   13526:         privitem = document.getElementById(context+'_recaptchapriv');
                   13527:     } else {
                   13528:         return;
                   13529:     }
                   13530:     if (document.getElementById(context+'_recaptchapubtxt')) {
                   13531:         pubtext = document.getElementById(context+'_recaptchapubtxt');
                   13532:     } else {
                   13533:         return;
                   13534:     }
                   13535:     if (document.getElementById(context+'_recaptchaprivtxt')) {
                   13536:         privtext = document.getElementById(context+'_recaptchaprivtxt');
                   13537:     } else {
                   13538:         return;
                   13539:     }
1.160.6.69  raeburn  13540:     if (document.getElementById(context+'_recaptchaversion')) {
                   13541:         versionitem = document.getElementById(context+'_recaptchaversion');
                   13542:     } else {
                   13543:         return;
                   13544:     }
                   13545:     if (document.getElementById(context+'_recaptchavertxt')) {
                   13546:         versiontext = document.getElementById(context+'_recaptchavertxt');
                   13547:     } else {
                   13548:         return;
                   13549:     }
1.160.6.5  raeburn  13550:     if (caller.checked) {
                   13551:         if (caller.value == 'recaptcha') {
                   13552:             pubitem.type = 'text';
                   13553:             privitem.type = 'text';
                   13554:             pubitem.size = '40';
                   13555:             privitem.size = '40';
                   13556:             pubtext.innerHTML = "$lt{'pub'}";
                   13557:             privtext.innerHTML = "$lt{'priv'}";
1.160.6.69  raeburn  13558:             versionitem.type = 'text';
                   13559:             versionitem.size = '3';
                   13560:             versiontext.innerHTML = "$lt{'ver'}";
1.160.6.5  raeburn  13561:         } else {
                   13562:             pubitem.type = 'hidden';
                   13563:             privitem.type = 'hidden';
1.160.6.69  raeburn  13564:             versionitem.type = 'hidden';
1.160.6.5  raeburn  13565:             pubtext.innerHTML = '';
                   13566:             privtext.innerHTML = '';
1.160.6.69  raeburn  13567:             versiontext.innerHTML = '';
1.160.6.5  raeburn  13568:         }
                   13569:     }
                   13570:     return;
                   13571: }
                   13572: 
                   13573: // ]]>
                   13574: </script>
                   13575: 
                   13576: END
                   13577: 
                   13578: }
                   13579: 
1.160.6.40  raeburn  13580: sub toggle_display_js {
1.160.6.16  raeburn  13581:     return <<"END";
                   13582: 
                   13583: <script type="text/javascript">
                   13584: // <![CDATA[
                   13585: 
1.160.6.40  raeburn  13586: function toggleDisplay(domForm,caller) {
                   13587:     if (document.getElementById(caller)) {
                   13588:         var divitem = document.getElementById(caller);
                   13589:         var optionsElement = domForm.coursecredits;
1.160.6.64  raeburn  13590:         var checkval = 1;
                   13591:         var dispval = 'block';
1.160.6.40  raeburn  13592:         if (caller == 'emailoptions') {
                   13593:             optionsElement = domForm.cancreate_email; 
                   13594:         }
1.160.6.57  raeburn  13595:         if (caller == 'studentsubmission') {
                   13596:             optionsElement = domForm.postsubmit;
                   13597:         }
1.160.6.64  raeburn  13598:         if (caller == 'cloneinstcode') {
                   13599:             optionsElement = domForm.canclone;
                   13600:             checkval = 'instcode';
                   13601:         }
1.160.6.40  raeburn  13602:         if (optionsElement.length) {
1.160.6.16  raeburn  13603:             var currval;
1.160.6.40  raeburn  13604:             for (var i=0; i<optionsElement.length; i++) {
                   13605:                 if (optionsElement[i].checked) {
                   13606:                    currval = optionsElement[i].value;
1.160.6.16  raeburn  13607:                 }
                   13608:             }
1.160.6.64  raeburn  13609:             if (currval == checkval) {
                   13610:                 divitem.style.display = dispval;
1.160.6.16  raeburn  13611:             } else {
1.160.6.40  raeburn  13612:                 divitem.style.display = 'none';
1.160.6.16  raeburn  13613:             }
                   13614:         }
                   13615:     }
                   13616:     return;
                   13617: }
                   13618: 
                   13619: // ]]>
                   13620: </script>
                   13621: 
                   13622: END
                   13623: 
                   13624: }
                   13625: 
1.160.6.5  raeburn  13626: sub captcha_phrases {
                   13627:     return &Apache::lonlocal::texthash (
                   13628:                  priv => 'Private key',
                   13629:                  pub  => 'Public key',
                   13630:                  original  => 'original (CAPTCHA)',
                   13631:                  recaptcha => 'successor (ReCAPTCHA)',
                   13632:                  notused   => 'unused',
1.160.6.69  raeburn  13633:                  ver => 'ReCAPTCHA version (1 or 2)',
1.160.6.5  raeburn  13634:     );
                   13635: }
                   13636: 
1.160.6.24  raeburn  13637: sub devalidate_remote_domconfs {
1.160.6.27  raeburn  13638:     my ($dom,$cachekeys) = @_;
                   13639:     return unless (ref($cachekeys) eq 'HASH');
1.160.6.24  raeburn  13640:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
                   13641:     my %thismachine;
                   13642:     map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.160.6.81  raeburn  13643:     my @posscached = ('domainconfig','domdefaults','usersessions','directorysrch');
1.160.6.61  raeburn  13644:     if (keys(%servers)) {
1.160.6.24  raeburn  13645:         foreach my $server (keys(%servers)) {
                   13646:             next if ($thismachine{$server});
1.160.6.27  raeburn  13647:             my @cached;
                   13648:             foreach my $name (@posscached) {
                   13649:                 if ($cachekeys->{$name}) {
                   13650:                     push(@cached,&escape($name).':'.&escape($dom));
                   13651:                 }
                   13652:             }
                   13653:             if (@cached) {
                   13654:                 &Apache::lonnet::remote_devalidate_cache($server,\@cached);
                   13655:             }
1.160.6.24  raeburn  13656:         }
                   13657:     }
                   13658:     return;
                   13659: }
                   13660: 
1.3       raeburn  13661: 1;

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