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

1.1       raeburn     1: # The LearningOnline Network with CAPA
                      2: # Handler to set domain-wide configuration settings
                      3: #
1.234   ! raeburn     4: # $Id: domainprefs.pm,v 1.233 2014/04/02 16:27:18 raeburn Exp $
1.2       albertel    5: #
1.1       raeburn     6: # Copyright Michigan State University Board of Trustees
                      7: #
                      8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                      9: #
                     10: # LON-CAPA is free software; you can redistribute it and/or modify
                     11: # it under the terms of the GNU General Public License as published by
                     12: # the Free Software Foundation; either version 2 of the License, or
                     13: # (at your option) any later version.
                     14: #
                     15: # LON-CAPA is distributed in the hope that it will be useful,
                     16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     18: # GNU General Public License for more details.
                     19: #
                     20: # You should have received a copy of the GNU General Public License
                     21: # along with LON-CAPA; if not, write to the Free Software
                     22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA#
                     23: # /home/httpd/html/adm/gpl.txt
                     24: #
                     25: # http://www.lon-capa.org/
                     26: #
                     27: #
                     28: ###############################################################
                     29: ##############################################################
                     30: 
1.101     raeburn    31: =pod
                     32: 
                     33: =head1 NAME
                     34: 
                     35: Apache::domainprefs.pm
                     36: 
                     37: =head1 SYNOPSIS
                     38: 
                     39: Handles configuration of a LON-CAPA domain.  
                     40: 
                     41: This is part of the LearningOnline Network with CAPA project
                     42: described at http://www.lon-capa.org.
                     43: 
                     44: 
                     45: =head1 OVERVIEW
                     46: 
                     47: Each institution using LON-CAPA will typically have a single domain designated 
1.183     bisitz     48: for use by individuals affiliated with the institution.  Accordingly, each domain
1.101     raeburn    49: may define a default set of logos and a color scheme which can be used to "brand"
                     50: the LON-CAPA instance. In addition, an institution will typically have a language
                     51: and timezone which are used for the majority of courses.
                     52: 
                     53: LON-CAPA provides a mechanism to display and modify these defaults, as well as a 
                     54: host of other domain-wide settings which determine the types of functionality
                     55: available to users and courses in the domain.
                     56: 
                     57: There is also a mechanism to configure cataloging of courses in the domain, and
                     58: controls on the operation of automated processes which govern such things as
                     59: roster updates, user directory updates and processing of course requests.
                     60: 
                     61: The domain coordination manual which is built dynamically on install/update of 
                     62: LON-CAPA from the relevant help items provides more information about domain 
                     63: configuration.
                     64: 
                     65: Most of the domain settings are stored in the configuration.db GDBM file which is
                     66: housed on the primary library server for the domain in /home/httpd/lonUsers/$dom,
                     67: where $dom is the domain.  The configuration.db stores settings in a number of 
                     68: frozen hashes of hashes.  In a few cases, domain information must be uploaded to
                     69: the domain as files (e.g., image files for logos etc., or plain text files for
                     70: bubblesheet formats).  In this case the domainprefs.pm must be running in a user
                     71: session hosted on the primary library server in the domain, as these files are 
                     72: stored in author space belonging to a special $dom-domainconfig user.   
                     73: 
                     74: domainprefs.pm in combination with lonconfigsettings.pm will retrieve and display
                     75: the current settings, and provides an interface to make modifications.
                     76: 
                     77: =head1 SUBROUTINES
                     78: 
                     79: =over
                     80: 
                     81: =item print_quotas()
                     82: 
                     83: Inputs: 4 
                     84: 
                     85: $dom,$settings,$rowtotal,$action.
                     86: 
                     87: $dom is the domain, $settings is a reference to a hash of current settings for
                     88: the current context, $rowtotal is a reference to the scalar used to record the 
1.210     raeburn    89: number of rows displayed on the page, and $action is the context (quotas, 
1.163     raeburn    90: requestcourses or requestauthor).
1.101     raeburn    91: 
                     92: The print_quotas routine was orginally created to display/store information
                     93: about default quota sizes for portfolio spaces for the different types of 
                     94: institutional affiliation in the domain (e.g., Faculty, Staff, Student etc.), 
                     95: but is now also used to manage availability of user tools: 
                     96: i.e., blogs, aboutme page, and portfolios, and the course request tool,
1.197     raeburn    97: used by course owners to request creation of a course, and to display/store
1.223     bisitz     98: default quota sizes for Authoring Spaces.
1.101     raeburn    99: 
                    100: Outputs: 1
                    101: 
                    102: $datatable  - HTML containing form elements which allow settings to be changed. 
                    103: 
                    104: In the case of course requests, radio buttons are displayed for each institutional
                    105: affiliate type (and also default, and _LC_adv) for each of the course types 
1.216     raeburn   106: (official, unofficial, community, and textbook).  In each case the radio buttons 
                    107: allow the selection of one of four values:
1.101     raeburn   108: 
1.104     raeburn   109: 0, approval, validate, autolimit=N (where N is blank, or a positive integer).
1.101     raeburn   110: which have the following effects:
                    111: 
                    112: 0
                    113: 
                    114: =over
                    115: 
                    116: - course requests are not allowed for this course types/affiliation
                    117: 
                    118: =back
                    119: 
1.104     raeburn   120: approval 
1.101     raeburn   121: 
                    122: =over 
                    123: 
                    124: - course requests must be approved by a Doman Coordinator in the 
                    125: course's domain
                    126: 
                    127: =back
                    128: 
                    129: validate 
                    130: 
                    131: =over
                    132: 
                    133: - an institutional validation (e.g., check requestor is instructor
                    134: of record) needs to be passed before the course will be created.  The required
                    135: validation is in localenroll.pm on the primary library server for the course 
                    136: domain.
                    137: 
                    138: =back
                    139: 
                    140: autolimit 
                    141: 
                    142: =over
                    143:  
1.143     raeburn   144: - course requests will be processed automatically up to a limit of
1.101     raeburn   145: N requests for the course type for the particular requestor.
                    146: If N is undefined, there is no limit to the number of course requests
                    147: which a course owner may submit and have processed automatically. 
                    148: 
                    149: =back
                    150: 
                    151: =item modify_quotas() 
                    152: 
                    153: =back
                    154: 
                    155: =cut
                    156: 
1.1       raeburn   157: package Apache::domainprefs;
                    158: 
                    159: use strict;
                    160: use Apache::Constants qw(:common :http);
                    161: use Apache::lonnet;
                    162: use Apache::loncommon();
                    163: use Apache::lonhtmlcommon();
                    164: use Apache::lonlocal;
1.43      raeburn   165: use Apache::lonmsg();
1.91      raeburn   166: use Apache::lonconfigsettings;
1.232     raeburn   167: use Apache::lonuserutils();
1.69      raeburn   168: use LONCAPA qw(:DEFAULT :match);
1.6       raeburn   169: use LONCAPA::Enrollment;
1.81      raeburn   170: use LONCAPA::lonauthcgi();
1.9       raeburn   171: use File::Copy;
1.43      raeburn   172: use Locale::Language;
1.62      raeburn   173: use DateTime::TimeZone;
1.68      raeburn   174: use DateTime::Locale;
1.1       raeburn   175: 
1.155     raeburn   176: my $registered_cleanup;
                    177: my $modified_urls;
                    178: 
1.1       raeburn   179: sub handler {
                    180:     my $r=shift;
                    181:     if ($r->header_only) {
                    182:         &Apache::loncommon::content_type($r,'text/html');
                    183:         $r->send_http_header;
                    184:         return OK;
                    185:     }
                    186: 
1.91      raeburn   187:     my $context = 'domain';
1.1       raeburn   188:     my $dom = $env{'request.role.domain'};
1.5       albertel  189:     my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1       raeburn   190:     if (&Apache::lonnet::allowed('mau',$dom)) {
                    191:         &Apache::loncommon::content_type($r,'text/html');
                    192:         $r->send_http_header;
                    193:     } else {
                    194:         $env{'user.error.msg'}=
                    195:         "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
                    196:         return HTTP_NOT_ACCEPTABLE;
                    197:     }
1.155     raeburn   198: 
                    199:     $registered_cleanup=0;
                    200:     @{$modified_urls}=();
                    201: 
1.1       raeburn   202:     &Apache::lonhtmlcommon::clear_breadcrumbs();
                    203:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.58      raeburn   204:                                             ['phase','actions']);
1.30      raeburn   205:     my $phase = 'pickactions';
1.3       raeburn   206:     if ( exists($env{'form.phase'}) ) {
                    207:         $phase = $env{'form.phase'};
                    208:     }
1.150     raeburn   209:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.3       raeburn   210:     my %domconfig =
1.6       raeburn   211:       &Apache::lonnet::get_dom('configuration',['login','rolecolors',
1.125     raeburn   212:                 'quotas','autoenroll','autoupdate','autocreate',
                    213:                 'directorysrch','usercreation','usermodification',
                    214:                 'contacts','defaults','scantron','coursecategories',
                    215:                 'serverstatuses','requestcourses','helpsettings',
1.163     raeburn   216:                 'coursedefaults','usersessions','loadbalancing',
1.231     raeburn   217:                 'requestauthor','selfenrollment'],$dom);
1.43      raeburn   218:     my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll',
1.125     raeburn   219:                        'autoupdate','autocreate','directorysrch','contacts',
1.224     raeburn   220:                        'usercreation','selfcreation','usermodification','scantron',
1.163     raeburn   221:                        'requestcourses','requestauthor','coursecategories',
                    222:                        'serverstatuses','helpsettings',
1.231     raeburn   223:                        'coursedefaults','selfenrollment','usersessions');
1.171     raeburn   224:     my %existing;
                    225:     if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
                    226:         %existing = %{$domconfig{'loadbalancing'}};
                    227:     }
                    228:     if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.150     raeburn   229:         push(@prefs_order,'loadbalancing');
                    230:     }
1.30      raeburn   231:     my %prefs = (
                    232:         'rolecolors' =>
                    233:                    { text => 'Default color schemes',
1.67      raeburn   234:                      help => 'Domain_Configuration_Color_Schemes',
1.30      raeburn   235:                      header => [{col1 => 'Student Settings',
                    236:                                  col2 => '',},
                    237:                                 {col1 => 'Coordinator Settings',
                    238:                                  col2 => '',},
                    239:                                 {col1 => 'Author Settings',
                    240:                                  col2 => '',},
                    241:                                 {col1 => 'Administrator Settings',
                    242:                                  col2 => '',}],
1.230     raeburn   243:                       print => \&print_rolecolors,
                    244:                       modify => \&modify_rolecolors,
1.30      raeburn   245:                     },
1.110     raeburn   246:         'login' =>
1.30      raeburn   247:                     { text => 'Log-in page options',
1.67      raeburn   248:                       help => 'Domain_Configuration_Login_Page',
1.168     raeburn   249:                       header => [{col1 => 'Log-in Page Items',
                    250:                                   col2 => '',},
                    251:                                  {col1 => 'Log-in Help',
                    252:                                   col2 => 'Value'}],
1.230     raeburn   253:                       print => \&print_login,
                    254:                       modify => \&modify_login,
1.30      raeburn   255:                     },
1.43      raeburn   256:         'defaults' => 
1.141     raeburn   257:                     { text => 'Default authentication/language/timezone/portal',
1.67      raeburn   258:                       help => 'Domain_Configuration_LangTZAuth',
1.43      raeburn   259:                       header => [{col1 => 'Setting',
                    260:                                   col2 => 'Value'}],
1.230     raeburn   261:                       print => \&print_defaults,
                    262:                       modify => \&modify_defaults,
1.43      raeburn   263:                     },
1.30      raeburn   264:         'quotas' => 
1.197     raeburn   265:                     { text => 'Blogs, personal web pages, webDAV/quotas, portfolios',
1.67      raeburn   266:                       help => 'Domain_Configuration_Quotas',
1.77      raeburn   267:                       header => [{col1 => 'User affiliation',
1.72      raeburn   268:                                   col2 => 'Available tools',
1.213     raeburn   269:                                   col3 => 'Quotas, MB; (Authoring requires role)',}],
1.230     raeburn   270:                       print => \&print_quotas,
                    271:                       modify => \&modify_quotas,
1.30      raeburn   272:                     },
                    273:         'autoenroll' =>
                    274:                    { text => 'Auto-enrollment settings',
1.67      raeburn   275:                      help => 'Domain_Configuration_Auto_Enrollment',
1.30      raeburn   276:                      header => [{col1 => 'Configuration setting',
                    277:                                  col2 => 'Value(s)'}],
1.230     raeburn   278:                      print => \&print_autoenroll,
                    279:                      modify => \&modify_autoenroll,
1.30      raeburn   280:                    },
                    281:         'autoupdate' => 
                    282:                    { text => 'Auto-update settings',
1.67      raeburn   283:                      help => 'Domain_Configuration_Auto_Updates',
1.30      raeburn   284:                      header => [{col1 => 'Setting',
                    285:                                  col2 => 'Value',},
1.131     raeburn   286:                                 {col1 => 'Setting',
                    287:                                  col2 => 'Affiliation'},
1.43      raeburn   288:                                 {col1 => 'User population',
1.227     bisitz    289:                                  col2 => 'Updatable user data'}],
1.230     raeburn   290:                      print => \&print_autoupdate,
                    291:                      modify => \&modify_autoupdate,
1.30      raeburn   292:                   },
1.125     raeburn   293:         'autocreate' => 
                    294:                   { text => 'Auto-course creation settings',
                    295:                      help => 'Domain_Configuration_Auto_Creation',
                    296:                      header => [{col1 => 'Configuration Setting',
                    297:                                  col2 => 'Value',}],
1.230     raeburn   298:                      print => \&print_autocreate,
                    299:                      modify => \&modify_autocreate,
1.125     raeburn   300:                   },
1.30      raeburn   301:         'directorysrch' => 
                    302:                   { text => 'Institutional directory searches',
1.67      raeburn   303:                     help => 'Domain_Configuration_InstDirectory_Search',
1.30      raeburn   304:                     header => [{col1 => 'Setting',
                    305:                                 col2 => 'Value',}],
1.230     raeburn   306:                     print => \&print_directorysrch,
                    307:                     modify => \&modify_directorysrch,
1.30      raeburn   308:                   },
                    309:         'contacts' =>
                    310:                   { text => 'Contact Information',
1.67      raeburn   311:                     help => 'Domain_Configuration_Contact_Info',
1.30      raeburn   312:                     header => [{col1 => 'Setting',
                    313:                                 col2 => 'Value',}],
1.230     raeburn   314:                     print => \&print_contacts,
                    315:                     modify => \&modify_contacts,
1.30      raeburn   316:                   },
                    317:         'usercreation' => 
                    318:                   { text => 'User creation',
1.67      raeburn   319:                     help => 'Domain_Configuration_User_Creation',
1.43      raeburn   320:                     header => [{col1 => 'Format rule type',
                    321:                                 col2 => 'Format rules in force'},
1.34      raeburn   322:                                {col1 => 'User account creation',
                    323:                                 col2 => 'Usernames which may be created',},
1.30      raeburn   324:                                {col1 => 'Context',
1.43      raeburn   325:                                 col2 => 'Assignable authentication types'}],
1.230     raeburn   326:                     print => \&print_usercreation,
                    327:                     modify => \&modify_usercreation,
1.30      raeburn   328:                   },
1.224     raeburn   329:         'selfcreation' => 
                    330:                   { text => 'Users self-creating accounts',
                    331:                     help => 'Domain_Configuration_Self_Creation', 
                    332:                     header => [{col1 => 'Self-creation with institutional username',
                    333:                                 col2 => 'Enabled?'},
                    334:                                {col1 => 'Institutional user type (login/SSO self-creation)',
                    335:                                 col2 => 'Information user can enter'},
                    336:                                {col1 => 'Self-creation with e-mail as username',
                    337:                                 col2 => 'Settings'}],
1.230     raeburn   338:                     print => \&print_selfcreation,
                    339:                     modify => \&modify_selfcreation,
1.224     raeburn   340:                   },
1.69      raeburn   341:         'usermodification' =>
1.33      raeburn   342:                   { text => 'User modification',
1.67      raeburn   343:                     help => 'Domain_Configuration_User_Modification',
1.33      raeburn   344:                     header => [{col1 => 'Target user has role',
1.227     bisitz    345:                                 col2 => 'User information updatable in author context'},
1.33      raeburn   346:                                {col1 => 'Target user has role',
1.227     bisitz    347:                                 col2 => 'User information updatable in course context'}],
1.230     raeburn   348:                     print => \&print_usermodification,
                    349:                     modify => \&modify_usermodification,
1.33      raeburn   350:                   },
1.69      raeburn   351:         'scantron' =>
1.95      www       352:                   { text => 'Bubblesheet format file',
1.67      raeburn   353:                     help => 'Domain_Configuration_Scantron_Format',
1.46      raeburn   354:                     header => [ {col1 => 'Item',
                    355:                                  col2 => '',
                    356:                               }],
1.230     raeburn   357:                     print => \&print_scantron,
                    358:                     modify => \&modify_scantron,
1.46      raeburn   359:                   },
1.86      raeburn   360:         'requestcourses' => 
                    361:                  {text => 'Request creation of courses',
                    362:                   help => 'Domain_Configuration_Request_Courses',
                    363:                   header => [{col1 => 'User affiliation',
1.102     raeburn   364:                               col2 => 'Availability/Processing of requests',},
                    365:                              {col1 => 'Setting',
1.216     raeburn   366:                               col2 => 'Value'},
                    367:                              {col1 => 'Available textbooks',
                    368:                               col2 => ''}],
1.230     raeburn   369:                   print => \&print_quotas,
                    370:                   modify => \&modify_quotas,
1.86      raeburn   371:                  },
1.163     raeburn   372:         'requestauthor' =>
1.223     bisitz    373:                  {text => 'Request Authoring Space',
1.163     raeburn   374:                   help => 'Domain_Configuration_Request_Author',
                    375:                   header => [{col1 => 'User affiliation',
                    376:                               col2 => 'Availability/Processing of requests',},
                    377:                              {col1 => 'Setting',
                    378:                               col2 => 'Value'}],
1.230     raeburn   379:                   print => \&print_quotas,
                    380:                   modify => \&modify_quotas,
1.163     raeburn   381:                  },
1.69      raeburn   382:         'coursecategories' =>
1.120     raeburn   383:                   { text => 'Cataloging of courses/communities',
1.67      raeburn   384:                     help => 'Domain_Configuration_Cataloging_Courses',
1.69      raeburn   385:                     header => [{col1 => 'Category settings',
1.57      raeburn   386:                                 col2 => '',},
                    387:                                {col1 => 'Categories',
                    388:                                 col2 => '',
                    389:                                }],
1.230     raeburn   390:                     print => \&print_coursecategories,
                    391:                     modify => \&modify_coursecategories,
1.69      raeburn   392:                   },
                    393:         'serverstatuses' =>
1.77      raeburn   394:                  {text   => 'Access to server status pages',
1.69      raeburn   395:                   help   => 'Domain_Configuration_Server_Status',
                    396:                   header => [{col1 => 'Status Page',
                    397:                               col2 => 'Other named users',
                    398:                               col3 => 'Specific IPs',
                    399:                             }],
1.230     raeburn   400:                   print => \&print_serverstatuses,
                    401:                   modify => \&modify_serverstatuses,
1.69      raeburn   402:                  },
1.118     jms       403:         'helpsettings' =>
                    404:                  {text   => 'Help page settings',
                    405:                   help   => 'Domain_Configuration_Help_Settings',
1.166     raeburn   406:                   header => [{col1 => 'Help Settings (logged-in users)',
                    407:                               col2 => 'Value'}],
1.230     raeburn   408:                   print  => \&print_helpsettings,
                    409:                   modify => \&modify_helpsettings,
1.118     jms       410:                  },
1.121     raeburn   411:         'coursedefaults' => 
                    412:                  {text => 'Course/Community defaults',
                    413:                   help => 'Domain_Configuration_Course_Defaults',
1.139     raeburn   414:                   header => [{col1 => 'Defaults which can be overridden in each course by a CC',
                    415:                               col2 => 'Value',},
                    416:                              {col1 => 'Defaults which can be overridden for each course by a DC',
                    417:                               col2 => 'Value',},],
1.230     raeburn   418:                   print => \&print_coursedefaults,
                    419:                   modify => \&modify_coursedefaults,
1.121     raeburn   420:                  },
1.231     raeburn   421:         'selfenrollment' => 
                    422:                  {text   => 'Self-enrollment in Course/Community',
                    423:                   help   => 'Domain_Configuration_Selfenrollment',
                    424:                   header => [{col1 => 'Configuration Rights',
                    425:                               col2 => 'Configured by Course Personnel or Domain Coordinator?'},
                    426:                              {col1 => 'Defaults',
                    427:                               col2 => 'Value'},
                    428:                              {col1 => 'Self-enrollment validation (optional)',
                    429:                               col2 => 'Value'},],
                    430:                   print => \&print_selfenrollment,
                    431:                   modify => \&modify_selfenrollment,
                    432:                  },
1.120     raeburn   433:         'privacy' => 
                    434:                  {text   => 'User Privacy',
                    435:                   help   => 'Domain_Configuration_User_Privacy',
                    436:                   header => [{col1 => 'Setting',
                    437:                               col2 => 'Value',}],
1.230     raeburn   438:                   print => \&print_privacy,
                    439:                   modify => \&modify_privacy,
1.120     raeburn   440:                  },
1.141     raeburn   441:         'usersessions' =>
1.145     raeburn   442:                  {text  => 'User session hosting/offloading',
1.137     raeburn   443:                   help  => 'Domain_Configuration_User_Sessions',
1.145     raeburn   444:                   header => [{col1 => 'Domain server',
                    445:                               col2 => 'Servers to offload sessions to when busy'},
                    446:                              {col1 => 'Hosting of users from other domains',
1.137     raeburn   447:                               col2 => 'Rules'},
                    448:                              {col1 => "Hosting domain's own users elsewhere",
                    449:                               col2 => 'Rules'}],
1.230     raeburn   450:                   print => \&print_usersessions,
                    451:                   modify => \&modify_usersessions,
1.137     raeburn   452:                  },
1.150     raeburn   453:          'loadbalancing' =>
1.185     raeburn   454:                  {text  => 'Dedicated Load Balancer(s)',
1.150     raeburn   455:                   help  => 'Domain_Configuration_Load_Balancing',
1.171     raeburn   456:                   header => [{col1 => 'Balancers',
1.150     raeburn   457:                               col2 => 'Default destinations',
1.183     bisitz    458:                               col3 => 'User affiliation',
1.150     raeburn   459:                               col4 => 'Overrides'},
                    460:                             ],
1.230     raeburn   461:                   print => \&print_loadbalancing,
                    462:                   modify => \&modify_loadbalancing,
1.150     raeburn   463:                  },
1.3       raeburn   464:     );
1.110     raeburn   465:     if (keys(%servers) > 1) {
                    466:         $prefs{'login'}  = { text   => 'Log-in page options',
                    467:                              help   => 'Domain_Configuration_Login_Page',
                    468:                             header => [{col1 => 'Log-in Service',
                    469:                                         col2 => 'Server Setting',},
                    470:                                        {col1 => 'Log-in Page Items',
1.168     raeburn   471:                                         col2 => ''},
                    472:                                        {col1 => 'Log-in Help',
                    473:                                         col2 => 'Value'}],
1.230     raeburn   474:                             print => \&print_login,
                    475:                             modify => \&modify_login,
1.110     raeburn   476:                            };
                    477:     }
1.174     foxr      478: 
1.6       raeburn   479:     my @roles = ('student','coordinator','author','admin');
1.30      raeburn   480:     my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3       raeburn   481:     &Apache::lonhtmlcommon::add_breadcrumb
1.30      raeburn   482:     ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133     raeburn   483:       text=>"Settings to display/modify"});
1.9       raeburn   484:     my $confname = $dom.'-domainconfig';
1.174     foxr      485: 
1.3       raeburn   486:     if ($phase eq 'process') {
1.212     raeburn   487:         my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
                    488:                                                               \%prefs,\%domconfig,$confname,\@roles);
1.224     raeburn   489:         if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.205     raeburn   490:             $r->rflush();
1.212     raeburn   491:             &devalidate_remote_domconfs($dom,$result);
1.205     raeburn   492:         }
1.30      raeburn   493:     } elsif ($phase eq 'display') {
1.192     raeburn   494:         my $js = &recaptcha_js().
                    495:                  &credits_js();
1.171     raeburn   496:         if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152     raeburn   497:             my ($othertitle,$usertypes,$types) =
                    498:                 &Apache::loncommon::sorted_inst_types($dom);
1.171     raeburn   499:             $js .= &lonbalance_targets_js($dom,$types,\%servers,
                    500:                                           $domconfig{'loadbalancing'}).
1.170     raeburn   501:                    &new_spares_js().
                    502:                    &common_domprefs_js().
                    503:                    &Apache::loncommon::javascript_array_indexof();
1.152     raeburn   504:         }
1.216     raeburn   505:         if (grep(/^requestcourses$/,@actions)) {
                    506:             my $javascript_validations;
                    507:             my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'}); 
                    508:             $js .= <<END;
                    509: <script type="text/javascript">
                    510: $javascript_validations
                    511: </script>
                    512: $coursebrowserjs
                    513: END
                    514:         }
1.150     raeburn   515:         &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1       raeburn   516:     } else {
1.180     raeburn   517: # check if domconfig user exists for the domain.
                    518:         my $servadm = $r->dir_config('lonAdmEMail');
                    519:         my ($configuserok,$author_ok,$switchserver) =
                    520:             &config_check($dom,$confname,$servadm);
                    521:         unless ($configuserok eq 'ok') {
1.181     raeburn   522:             &Apache::lonconfigsettings::print_header($r,$phase,$context);
                    523:             $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
1.210     raeburn   524:                           $confname).
1.181     raeburn   525:                       '<br />'
                    526:             );
1.180     raeburn   527:             if ($switchserver) {
1.181     raeburn   528:                 $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
                    529:                           '<br />'.
                    530:                           &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
                    531:                           '<br />'.
                    532:                           &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).
                    533:                           '<br />'.
                    534:                           &mt('To do that now, use the following link: [_1]',$switchserver)
                    535:                 );
                    536:             } else {
                    537:                 $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.').
                    538:                           '<br />'.
                    539:                           &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
                    540:                 );
1.180     raeburn   541:             }
                    542:             $r->print(&Apache::loncommon::end_page());
                    543:             return OK;
                    544:         }
1.21      raeburn   545:         if (keys(%domconfig) == 0) {
                    546:             my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29      raeburn   547:             my @ids=&Apache::lonnet::current_machine_ids();
                    548:             if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21      raeburn   549:                 my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41      raeburn   550:                 my @loginimages = ('img','logo','domlogo','login');
1.21      raeburn   551:                 my $custom_img_count = 0;
                    552:                 foreach my $img (@loginimages) {
                    553:                     if ($designhash{$dom.'.login.'.$img} ne '') {
                    554:                         $custom_img_count ++;
                    555:                     }
                    556:                 }
                    557:                 foreach my $role (@roles) {
                    558:                     if ($designhash{$dom.'.'.$role.'.img'} ne '') {
                    559:                         $custom_img_count ++;
                    560:                     }
                    561:                 }
                    562:                 if ($custom_img_count > 0) {
1.94      raeburn   563:                     &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21      raeburn   564:                     my $switch_server = &check_switchserver($dom,$confname);
1.29      raeburn   565:                     $r->print(
                    566:     &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
                    567:     &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
                    568:     &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 />'.
                    569:     &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
                    570:                     if ($switch_server) {
1.30      raeburn   571:                         $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29      raeburn   572:                     }
1.91      raeburn   573:                     $r->print(&Apache::loncommon::end_page());
1.21      raeburn   574:                     return OK;
                    575:                 }
                    576:             }
                    577:         }
1.91      raeburn   578:         &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3       raeburn   579:     }
                    580:     return OK;
                    581: }
                    582: 
                    583: sub process_changes {
1.205     raeburn   584:     my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92      raeburn   585:     my %domconfig;
                    586:     if (ref($values) eq 'HASH') {
                    587:         %domconfig = %{$values};
                    588:     }
1.3       raeburn   589:     my $output;
                    590:     if ($action eq 'login') {
1.205     raeburn   591:         $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6       raeburn   592:     } elsif ($action eq 'rolecolors') {
1.9       raeburn   593:         $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.205     raeburn   594:                                      $lastactref,%domconfig);
1.3       raeburn   595:     } elsif ($action eq 'quotas') {
1.216     raeburn   596:         $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3       raeburn   597:     } elsif ($action eq 'autoenroll') {
1.205     raeburn   598:         $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3       raeburn   599:     } elsif ($action eq 'autoupdate') {
                    600:         $output = &modify_autoupdate($dom,%domconfig);
1.125     raeburn   601:     } elsif ($action eq 'autocreate') {
                    602:         $output = &modify_autocreate($dom,%domconfig);
1.23      raeburn   603:     } elsif ($action eq 'directorysrch') {
                    604:         $output = &modify_directorysrch($dom,%domconfig);
1.27      raeburn   605:     } elsif ($action eq 'usercreation') {
1.28      raeburn   606:         $output = &modify_usercreation($dom,%domconfig);
1.224     raeburn   607:     } elsif ($action eq 'selfcreation') {
                    608:         $output = &modify_selfcreation($dom,%domconfig);
1.33      raeburn   609:     } elsif ($action eq 'usermodification') {
                    610:         $output = &modify_usermodification($dom,%domconfig);
1.28      raeburn   611:     } elsif ($action eq 'contacts') {
1.205     raeburn   612:         $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43      raeburn   613:     } elsif ($action eq 'defaults') {
1.212     raeburn   614:         $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46      raeburn   615:     } elsif ($action eq 'scantron') {
1.205     raeburn   616:         $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48      raeburn   617:     } elsif ($action eq 'coursecategories') {
                    618:         $output = &modify_coursecategories($dom,%domconfig);
1.69      raeburn   619:     } elsif ($action eq 'serverstatuses') {
                    620:         $output = &modify_serverstatuses($dom,%domconfig);
1.86      raeburn   621:     } elsif ($action eq 'requestcourses') {
1.216     raeburn   622:         $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.163     raeburn   623:     } elsif ($action eq 'requestauthor') {
1.216     raeburn   624:         $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.118     jms       625:     } elsif ($action eq 'helpsettings') {
1.122     jms       626:         $output = &modify_helpsettings($r,$dom,$confname,%domconfig);
1.121     raeburn   627:     } elsif ($action eq 'coursedefaults') {
1.212     raeburn   628:         $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.231     raeburn   629:     } elsif ($action eq 'selfenrollment') {
                    630:         $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
1.137     raeburn   631:     } elsif ($action eq 'usersessions') {
1.212     raeburn   632:         $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150     raeburn   633:     } elsif ($action eq 'loadbalancing') {
                    634:         $output = &modify_loadbalancing($dom,%domconfig);
1.3       raeburn   635:     }
                    636:     return $output;
                    637: }
                    638: 
                    639: sub print_config_box {
1.9       raeburn   640:     my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30      raeburn   641:     my $rowtotal = 0;
1.49      raeburn   642:     my $output;
                    643:     if ($action eq 'coursecategories') {
                    644:         $output = &coursecategories_javascript($settings);
1.91      raeburn   645:     }
1.49      raeburn   646:     $output .= 
1.30      raeburn   647:          '<table class="LC_nested_outer">
1.3       raeburn   648:           <tr>
1.66      raeburn   649:            <th align="left" valign="middle"><span class="LC_nobreak">'.
                    650:            &mt($item->{text}).'&nbsp;'.
                    651:            &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
                    652:           '</tr>';
1.30      raeburn   653:     $rowtotal ++;
1.110     raeburn   654:     my $numheaders = 1;
                    655:     if (ref($item->{'header'}) eq 'ARRAY') {
                    656:         $numheaders = scalar(@{$item->{'header'}});
                    657:     }
                    658:     if ($numheaders > 1) {
1.64      raeburn   659:         my $colspan = '';
1.145     raeburn   660:         my $rightcolspan = '';
1.210     raeburn   661:         if (($action eq 'rolecolors') || ($action eq 'coursecategories') ||
1.168     raeburn   662:             (($action eq 'login') && ($numheaders < 3))) {
1.64      raeburn   663:             $colspan = ' colspan="2"';
                    664:         }
1.145     raeburn   665:         if ($action eq 'usersessions') {
                    666:             $rightcolspan = ' colspan="3"'; 
                    667:         }
1.30      raeburn   668:         $output .= '
1.3       raeburn   669:           <tr>
                    670:            <td>
                    671:             <table class="LC_nested">
                    672:              <tr class="LC_info_row">
1.59      bisitz    673:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145     raeburn   674:               <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30      raeburn   675:              </tr>';
1.69      raeburn   676:         $rowtotal ++;
1.230     raeburn   677:         if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
                    678:             ($action eq 'usermodification') || ($action eq 'coursedefaults') ||
                    679:             ($action eq 'selfenrollment') || ($action eq 'usersessions')) {
                    680:             $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.57      raeburn   681:         } elsif ($action eq 'coursecategories') {
1.230     raeburn   682:             $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.110     raeburn   683:         } elsif ($action eq 'login') {
1.168     raeburn   684:             if ($numheaders == 3) {
                    685:                 $colspan = ' colspan="2"';
                    686:                 $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
                    687:             } else {
                    688:                 $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
                    689:             }
1.230     raeburn   690:         } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.163     raeburn   691:             $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122     jms       692:         } elsif ($action eq 'rolecolors') {
1.30      raeburn   693:             $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.6       raeburn   694:         }
1.30      raeburn   695:         $output .= '
1.6       raeburn   696:            </table>
                    697:           </td>
                    698:          </tr>
                    699:          <tr>
                    700:            <td>
                    701:             <table class="LC_nested">
                    702:              <tr class="LC_info_row">
1.230     raeburn   703:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59      bisitz    704:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30      raeburn   705:              </tr>';
                    706:             $rowtotal ++;
1.230     raeburn   707:         if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
                    708:             ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
                    709:             ($action eq 'usersessions')) {
                    710:             $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal).'
1.63      raeburn   711:            </table>
                    712:           </td>
                    713:          </tr>
                    714:          <tr>
                    715:            <td>
                    716:             <table class="LC_nested">
                    717:              <tr class="LC_info_row">
                    718:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.224     raeburn   719:               <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.230     raeburn   720:              </tr>'."\n".
                    721:             $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.63      raeburn   722:             $rowtotal ++;
1.230     raeburn   723:         } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults')) {
                    724:             $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.57      raeburn   725:         } elsif ($action eq 'coursecategories') {
                    726:             $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.110     raeburn   727:         } elsif ($action eq 'login') {
1.168     raeburn   728:             if ($numheaders == 3) {
                    729:                 $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
                    730:            </table>
                    731:           </td>
                    732:          </tr>
                    733:          <tr>
                    734:            <td>
                    735:             <table class="LC_nested">
                    736:              <tr class="LC_info_row">
                    737:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.216     raeburn   738:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.168     raeburn   739:                        &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
                    740:                 $rowtotal ++;
                    741:             } else {
                    742:                 $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
                    743:             }
1.102     raeburn   744:         } elsif ($action eq 'requestcourses') {
1.216     raeburn   745:             $output .= &print_requestmail($dom,$action,$settings,\$rowtotal).
                    746:                        &print_studentcode($settings,\$rowtotal).'
                    747:            </table>
                    748:           </td>
                    749:          </tr>
                    750:          <tr>
                    751:            <td>
                    752:             <table class="LC_nested">
                    753:              <tr class="LC_info_row">
                    754:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
                    755:               <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
                    756:                        &print_textbookcourses($dom,$settings,\$rowtotal);
1.163     raeburn   757:         } elsif ($action eq 'requestauthor') {
                    758:             $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.122     jms       759:         } elsif ($action eq 'rolecolors') {
1.30      raeburn   760:             $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6       raeburn   761:            </table>
                    762:           </td>
                    763:          </tr>
                    764:          <tr>
                    765:            <td>
                    766:             <table class="LC_nested">
                    767:              <tr class="LC_info_row">
1.69      raeburn   768:               <td class="LC_left_item"'.$colspan.' valign="top">'.
                    769:                &mt($item->{'header'}->[2]->{'col1'}).'</td>
                    770:               <td class="LC_right_item" valign="top">'.
                    771:                &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3       raeburn   772:              </tr>'.
1.30      raeburn   773:             &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3       raeburn   774:            </table>
                    775:           </td>
                    776:          </tr>
                    777:          <tr>
                    778:            <td>
                    779:             <table class="LC_nested">
                    780:              <tr class="LC_info_row">
1.59      bisitz    781:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
                    782:               <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3       raeburn   783:              </tr>'.
1.30      raeburn   784:             &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
                    785:             $rowtotal += 2;
1.6       raeburn   786:         }
1.3       raeburn   787:     } else {
1.30      raeburn   788:         $output .= '
1.3       raeburn   789:           <tr>
                    790:            <td>
                    791:             <table class="LC_nested">
1.30      raeburn   792:              <tr class="LC_info_row">';
1.24      raeburn   793:         if (($action eq 'login') || ($action eq 'directorysrch')) {
1.30      raeburn   794:             $output .= '  
1.59      bisitz    795:               <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69      raeburn   796:         } elsif ($action eq 'serverstatuses') {
                    797:             $output .= '
                    798:               <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
                    799:               '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
                    800: 
1.6       raeburn   801:         } else {
1.30      raeburn   802:             $output .= '
1.69      raeburn   803:               <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
                    804:         }
1.72      raeburn   805:         if (defined($item->{'header'}->[0]->{'col3'})) {
                    806:             $output .= '<td class="LC_left_item" valign="top">'.
                    807:                        &mt($item->{'header'}->[0]->{'col2'});
                    808:             if ($action eq 'serverstatuses') {
                    809:                 $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
                    810:             } 
1.69      raeburn   811:         } else {
                    812:             $output .= '<td class="LC_right_item" valign="top">'.
                    813:                        &mt($item->{'header'}->[0]->{'col2'});
                    814:         }
                    815:         $output .= '</td>';
                    816:         if ($item->{'header'}->[0]->{'col3'}) {
1.150     raeburn   817:             if (defined($item->{'header'}->[0]->{'col4'})) {
                    818:                 $output .= '<td class="LC_left_item" valign="top">'.
                    819:                             &mt($item->{'header'}->[0]->{'col3'});
                    820:             } else {
                    821:                 $output .= '<td class="LC_right_item" valign="top">'.
                    822:                            &mt($item->{'header'}->[0]->{'col3'});
                    823:             }
1.69      raeburn   824:             if ($action eq 'serverstatuses') {
                    825:                 $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
                    826:             }
                    827:             $output .= '</td>';
1.6       raeburn   828:         }
1.150     raeburn   829:         if ($item->{'header'}->[0]->{'col4'}) {
                    830:             $output .= '<td class="LC_right_item" valign="top">'.
                    831:                        &mt($item->{'header'}->[0]->{'col4'});
                    832:         }
1.69      raeburn   833:         $output .= '</tr>';
1.48      raeburn   834:         $rowtotal ++;
1.168     raeburn   835:         if ($action eq 'quotas') {
1.86      raeburn   836:             $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.230     raeburn   837:         } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') || ($action eq 'directorysrch') ||
                    838:                  ($action eq 'contacts') || ($action eq 'defaults') || ($action eq 'serverstatuses') ||
                    839:                  ($action eq 'loadbalancing')) {
                    840:             $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.46      raeburn   841:         } elsif ($action eq 'scantron') {
                    842:             $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
1.118     jms       843:         } elsif ($action eq 'helpsettings') {
1.168     raeburn   844:             $output .= &print_helpsettings($dom,$confname,$settings,\$rowtotal);
1.121     raeburn   845:         }
1.3       raeburn   846:     }
1.30      raeburn   847:     $output .= '
1.3       raeburn   848:    </table>
                    849:   </td>
                    850:  </tr>
1.30      raeburn   851: </table><br />';
                    852:     return ($output,$rowtotal);
1.1       raeburn   853: }
                    854: 
1.3       raeburn   855: sub print_login {
1.168     raeburn   856:     my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110     raeburn   857:     my ($css_class,$datatable);
1.6       raeburn   858:     my %choices = &login_choices();
1.110     raeburn   859: 
1.168     raeburn   860:     if ($caller eq 'service') {
1.149     raeburn   861:         my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110     raeburn   862:         my $choice = $choices{'disallowlogin'};
                    863:         $css_class = ' class="LC_odd_row"';
1.128     raeburn   864:         $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110     raeburn   865:                       '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128     raeburn   866:                       '<th>'.$choices{'server'}.'</th>'.
                    867:                       '<th>'.$choices{'serverpath'}.'</th>'.
                    868:                       '<th>'.$choices{'custompath'}.'</th>'.
                    869:                       '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110     raeburn   870:         my %disallowed;
                    871:         if (ref($settings) eq 'HASH') {
                    872:             if (ref($settings->{'loginvia'}) eq 'HASH') {
                    873:                %disallowed = %{$settings->{'loginvia'}};
                    874:             }
                    875:         }
                    876:         foreach my $lonhost (sort(keys(%servers))) {
                    877:             my $direct = 'selected="selected"';
1.128     raeburn   878:             if (ref($disallowed{$lonhost}) eq 'HASH') {
                    879:                 if ($disallowed{$lonhost}{'server'} ne '') {
                    880:                     $direct = '';
                    881:                 }
1.110     raeburn   882:             }
1.115     raeburn   883:             $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128     raeburn   884:                           '<td><select name="'.$lonhost.'_server">'.
1.110     raeburn   885:                           '<option value=""'.$direct.'>'.$choices{'directlogin'}.
                    886:                           '</option>';
1.184     raeburn   887:             foreach my $hostid (sort(keys(%servers))) {
1.115     raeburn   888:                 next if ($servers{$hostid} eq $servers{$lonhost});
1.110     raeburn   889:                 my $selected = '';
1.128     raeburn   890:                 if (ref($disallowed{$lonhost}) eq 'HASH') {
                    891:                     if ($hostid eq $disallowed{$lonhost}{'server'}) {
                    892:                         $selected = 'selected="selected"';
                    893:                     }
1.110     raeburn   894:                 }
                    895:                 $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
                    896:                               $servers{$hostid}.'</option>';
                    897:             }
1.128     raeburn   898:             $datatable .= '</select></td>'.
                    899:                           '<td><select name="'.$lonhost.'_serverpath">';
                    900:             foreach my $path ('','/','/adm/login','/adm/roles','custom') {
                    901:                 my $pathname = $path;
                    902:                 if ($path eq 'custom') {
                    903:                     $pathname = &mt('Custom Path').' ->';
                    904:                 }
                    905:                 my $selected = '';
                    906:                 if (ref($disallowed{$lonhost}) eq 'HASH') {
                    907:                     if ($path eq $disallowed{$lonhost}{'serverpath'}) {
                    908:                         $selected = 'selected="selected"';
                    909:                     }
                    910:                 } elsif ($path eq '') {
                    911:                     $selected = 'selected="selected"';
                    912:                 }
                    913:                 $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
                    914:             }
                    915:             $datatable .= '</select></td>';
                    916:             my ($custom,$exempt);
                    917:             if (ref($disallowed{$lonhost}) eq 'HASH') {
                    918:                 $custom = $disallowed{$lonhost}{'custompath'};
                    919:                 $exempt = $disallowed{$lonhost}{'exempt'};
                    920:             }
                    921:             $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
                    922:                           '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
                    923:                           '</tr>';
1.110     raeburn   924:         }
                    925:         $datatable .= '</table></td></tr>';
                    926:         return $datatable;
1.168     raeburn   927:     } elsif ($caller eq 'page') {
                    928:         my %defaultchecked = ( 
                    929:                                'coursecatalog' => 'on',
1.188     raeburn   930:                                'helpdesk'      => 'on',
1.168     raeburn   931:                                'adminmail'     => 'off',
                    932:                                'newuser'       => 'off',
                    933:                              );
1.188     raeburn   934:         my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.168     raeburn   935:         my (%checkedon,%checkedoff);
1.42      raeburn   936:         foreach my $item (@toggles) {
1.168     raeburn   937:             if ($defaultchecked{$item} eq 'on') { 
                    938:                 $checkedon{$item} = ' checked="checked" ';
1.42      raeburn   939:                 $checkedoff{$item} = ' ';
1.168     raeburn   940:             } elsif ($defaultchecked{$item} eq 'off') {
                    941:                 $checkedoff{$item} = ' checked="checked" ';
1.42      raeburn   942:                 $checkedon{$item} = ' ';
                    943:             }
1.1       raeburn   944:         }
1.168     raeburn   945:         my @images = ('img','logo','domlogo','login');
                    946:         my @logintext = ('textcol','bgcol');
                    947:         my @bgs = ('pgbg','mainbg','sidebg');
                    948:         my @links = ('link','alink','vlink');
                    949:         my %designhash = &Apache::loncommon::get_domainconf($dom);
                    950:         my %defaultdesign = %Apache::loncommon::defaultdesign;
                    951:         my (%is_custom,%designs);
                    952:         my %defaults = (
                    953:                        font => $defaultdesign{'login.font'},
                    954:                        );
1.6       raeburn   955:         foreach my $item (@images) {
1.168     raeburn   956:             $defaults{$item} = $defaultdesign{'login.'.$item};
                    957:             $defaults{'showlogo'}{$item} = 1;
                    958:         }
                    959:         foreach my $item (@bgs) {
                    960:             $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6       raeburn   961:         }
1.41      raeburn   962:         foreach my $item (@logintext) {
1.168     raeburn   963:             $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41      raeburn   964:         }
1.168     raeburn   965:         foreach my $item (@links) {
                    966:             $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6       raeburn   967:         }
1.168     raeburn   968:         if (ref($settings) eq 'HASH') {
                    969:             foreach my $item (@toggles) {
                    970:                 if ($settings->{$item} eq '1') {
                    971:                     $checkedon{$item} =  ' checked="checked" ';
                    972:                     $checkedoff{$item} = ' ';
                    973:                 } elsif ($settings->{$item} eq '0') {
                    974:                     $checkedoff{$item} =  ' checked="checked" ';
                    975:                     $checkedon{$item} = ' ';
                    976:                 }
                    977:             }
                    978:             foreach my $item (@images) {
                    979:                 if (defined($settings->{$item})) {
                    980:                     $designs{$item} = $settings->{$item};
                    981:                     $is_custom{$item} = 1;
                    982:                 }
                    983:                 if (defined($settings->{'showlogo'}{$item})) {
                    984:                     $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
                    985:                 }
                    986:             }
                    987:             foreach my $item (@logintext) {
                    988:                 if ($settings->{$item} ne '') {
                    989:                     $designs{'logintext'}{$item} = $settings->{$item};
                    990:                     $is_custom{$item} = 1;
                    991:                 }
                    992:             }
                    993:             if ($settings->{'font'} ne '') {
                    994:                 $designs{'font'} = $settings->{'font'};
                    995:                 $is_custom{'font'} = 1;
                    996:             }
                    997:             foreach my $item (@bgs) {
                    998:                 if ($settings->{$item} ne '') {
                    999:                     $designs{'bgs'}{$item} = $settings->{$item};
                   1000:                     $is_custom{$item} = 1;
                   1001:                 }
                   1002:             }
                   1003:             foreach my $item (@links) {
                   1004:                 if ($settings->{$item} ne '') {
                   1005:                     $designs{'links'}{$item} = $settings->{$item};
                   1006:                     $is_custom{$item} = 1;
                   1007:                 }
                   1008:             }
                   1009:         } else {
                   1010:             if ($designhash{$dom.'.login.font'} ne '') {
                   1011:                 $designs{'font'} = $designhash{$dom.'.login.font'};
                   1012:                 $is_custom{'font'} = 1;
                   1013:             }
                   1014:             foreach my $item (@images) {
                   1015:                 if ($designhash{$dom.'.login.'.$item} ne '') {
                   1016:                     $designs{$item} = $designhash{$dom.'.login.'.$item};
                   1017:                     $is_custom{$item} = 1;
                   1018:                 }
                   1019:             }
                   1020:             foreach my $item (@bgs) {
                   1021:                 if ($designhash{$dom.'.login.'.$item} ne '') {
                   1022:                     $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
                   1023:                     $is_custom{$item} = 1;
                   1024:                 }
1.6       raeburn  1025:             }
1.168     raeburn  1026:             foreach my $item (@links) {
                   1027:                 if ($designhash{$dom.'.login.'.$item} ne '') {
                   1028:                     $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
                   1029:                     $is_custom{$item} = 1;
                   1030:                 }
1.6       raeburn  1031:             }
                   1032:         }
1.168     raeburn  1033:         my %alt_text = &Apache::lonlocal::texthash  ( img => 'Log-in banner',
                   1034:                                                       logo => 'Institution Logo',
                   1035:                                                       domlogo => 'Domain Logo',
                   1036:                                                       login => 'Login box');
                   1037:         my $itemcount = 1;
                   1038:         foreach my $item (@toggles) {
                   1039:             $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   1040:             $datatable .=  
                   1041:                 '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
                   1042:                 '</td><td>'.
                   1043:                 '<span class="LC_nobreak"><label><input type="radio" name="'.
                   1044:                 $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
                   1045:                 '</label>&nbsp;<label><input type="radio" name="'.$item.'"'.
                   1046:                 $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
                   1047:                 '</tr>';
                   1048:             $itemcount ++;
1.6       raeburn  1049:         }
1.168     raeburn  1050:         $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
                   1051:         $datatable .= '</tr></table></td></tr>';
                   1052:     } elsif ($caller eq 'help') {
                   1053:         my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
                   1054:         my $switchserver = &check_switchserver($dom,$confname);
                   1055:         my $itemcount = 1;
                   1056:         $defaulturl = '/adm/loginproblems.html';
                   1057:         $defaulttype = 'default';
                   1058:         %lt = &Apache::lonlocal::texthash (
                   1059:                      del     => 'Delete?',
                   1060:                      rep     => 'Replace:',
                   1061:                      upl     => 'Upload:',
                   1062:                      default => 'Default',
                   1063:                      custom  => 'Custom',
                   1064:                                              );
                   1065:         %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
                   1066:         my @currlangs;
                   1067:         if (ref($settings) eq 'HASH') {
                   1068:             if (ref($settings->{'helpurl'}) eq 'HASH') {
                   1069:                 foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
                   1070:                     next if ($settings->{'helpurl'}{$key} eq '');
                   1071:                     $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
                   1072:                     $type{$key} = 'custom';
                   1073:                     unless ($key eq 'nolang') {
                   1074:                         push(@currlangs,$key);
                   1075:                     }
                   1076:                 }
                   1077:             } elsif ($settings->{'helpurl'} ne '') {
                   1078:                 $type{'nolang'} = 'custom';
                   1079:                 $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8       raeburn  1080:             }
                   1081:         }
1.168     raeburn  1082:         foreach my $lang ('nolang',sort(@currlangs)) {
                   1083:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   1084:             $datatable .= '<tr'.$css_class.'>';
                   1085:             if ($url{$lang} eq '') {
                   1086:                 $url{$lang} = $defaulturl;
                   1087:             }
                   1088:             if ($type{$lang} eq '') {
                   1089:                 $type{$lang} = $defaulttype;
                   1090:             }
                   1091:             $datatable .= '<td colspan="2"><span class="LC_nobreak">';
                   1092:             if ($lang eq 'nolang') {
                   1093:                 $datatable .= &mt('Log-in help page if no specific language file: [_1]',
                   1094:                                   &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
                   1095:             } else {
                   1096:                 $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
                   1097:                                   $langchoices{$lang},
                   1098:                                   &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
                   1099:             }
                   1100:             $datatable .= '</span></td>'."\n".
                   1101:                           '<td class="LC_left_item">';
                   1102:             if ($type{$lang} eq 'custom') {
                   1103:                 $datatable .= '<span class="LC_nobreak"><label>'.
                   1104:                               '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
                   1105:                               $lt{'del'}.'</label>&nbsp;'.$lt{'rep'}.'</span>';
                   1106:             } else {
                   1107:                 $datatable .= $lt{'upl'};
                   1108:             }
                   1109:             $datatable .='<br />';
                   1110:             if ($switchserver) {
                   1111:                 $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   1112:             } else {
                   1113:                 $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6       raeburn  1114:             }
1.168     raeburn  1115:             $datatable .= '</td></tr>';
                   1116:             $itemcount ++;
1.6       raeburn  1117:         }
1.168     raeburn  1118:         my @addlangs;
                   1119:         foreach my $lang (sort(keys(%langchoices))) {
                   1120:             next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
                   1121:             push(@addlangs,$lang);
                   1122:         }
                   1123:         if (@addlangs > 0) {
                   1124:             my %toadd;
                   1125:             map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
                   1126:             $toadd{''} = &mt('Select');
                   1127:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   1128:             $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
                   1129:                           &mt('Add log-in help page for a specific language:').'&nbsp;'.
                   1130:                           &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
                   1131:                           '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
                   1132:             if ($switchserver) {
                   1133:                 $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   1134:             } else {
                   1135:                 $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6       raeburn  1136:             }
1.168     raeburn  1137:             $datatable .= '</td></tr>';
1.169     raeburn  1138:             $itemcount ++;
1.6       raeburn  1139:         }
1.169     raeburn  1140:         $datatable .= &captcha_choice('login',$settings,$itemcount);
1.1       raeburn  1141:     }
1.6       raeburn  1142:     return $datatable;
                   1143: }
                   1144: 
                   1145: sub login_choices {
                   1146:     my %choices =
                   1147:         &Apache::lonlocal::texthash (
1.116     bisitz   1148:             coursecatalog => 'Display Course/Community Catalog link?',
1.110     raeburn  1149:             adminmail     => "Display Administrator's E-mail Address?",
1.188     raeburn  1150:             helpdesk      => 'Display "Contact Helpdesk" link',
1.110     raeburn  1151:             disallowlogin => "Login page requests redirected",
                   1152:             hostid        => "Server",
1.128     raeburn  1153:             server        => "Redirect to:",
                   1154:             serverpath    => "Path",
                   1155:             custompath    => "Custom", 
                   1156:             exempt        => "Exempt IP(s)",
1.110     raeburn  1157:             directlogin   => "No redirect",
                   1158:             newuser       => "Link to create a user account",
                   1159:             img           => "Header",
                   1160:             logo          => "Main Logo",
                   1161:             domlogo       => "Domain Logo",
                   1162:             login         => "Log-in Header", 
                   1163:             textcol       => "Text color",
                   1164:             bgcol         => "Box color",
                   1165:             bgs           => "Background colors",
                   1166:             links         => "Link colors",
                   1167:             font          => "Font color",
                   1168:             pgbg          => "Header",
                   1169:             mainbg        => "Page",
                   1170:             sidebg        => "Login box",
                   1171:             link          => "Link",
                   1172:             alink         => "Active link",
                   1173:             vlink         => "Visited link",
1.6       raeburn  1174:         );
                   1175:     return %choices;
                   1176: }
                   1177: 
                   1178: sub print_rolecolors {
1.30      raeburn  1179:     my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6       raeburn  1180:     my %choices = &color_font_choices();
                   1181:     my @bgs = ('pgbg','tabbg','sidebg');
                   1182:     my @links = ('link','alink','vlink');
                   1183:     my @images = ('img');
                   1184:     my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7       albertel 1185:     my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6       raeburn  1186:     my %defaultdesign = %Apache::loncommon::defaultdesign;
                   1187:     my (%is_custom,%designs);
1.200     raeburn  1188:     my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6       raeburn  1189:     if (ref($settings) eq 'HASH') {
                   1190:         if (ref($settings->{$role}) eq 'HASH') {
                   1191:             if ($settings->{$role}->{'img'} ne '') {
                   1192:                 $designs{'img'} = $settings->{$role}->{'img'};
                   1193:                 $is_custom{'img'} = 1;
                   1194:             }
                   1195:             if ($settings->{$role}->{'font'} ne '') {
                   1196:                 $designs{'font'} = $settings->{$role}->{'font'};
                   1197:                 $is_custom{'font'} = 1;
                   1198:             }
1.97      tempelho 1199:             if ($settings->{$role}->{'fontmenu'} ne '') {
                   1200:                 $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
                   1201:                 $is_custom{'fontmenu'} = 1;
                   1202:             }
1.6       raeburn  1203:             foreach my $item (@bgs) {
                   1204:                 if ($settings->{$role}->{$item} ne '') {
                   1205:                     $designs{'bgs'}{$item} = $settings->{$role}->{$item};
                   1206:                     $is_custom{$item} = 1;
                   1207:                 }
                   1208:             }
                   1209:             foreach my $item (@links) {
                   1210:                 if ($settings->{$role}->{$item} ne '') {
                   1211:                     $designs{'links'}{$item} = $settings->{$role}->{$item};
                   1212:                     $is_custom{$item} = 1;
                   1213:                 }
                   1214:             }
                   1215:         }
                   1216:     } else {
                   1217:         if ($designhash{$dom.'.'.$role.'.img'} ne '') {
                   1218:             $designs{img} = $designhash{$dom.'.'.$role.'.img'};
                   1219:             $is_custom{'img'} = 1;
                   1220:         }
1.97      tempelho 1221:         if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
                   1222:             $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
                   1223:             $is_custom{'fontmenu'} = 1; 
                   1224:         }
1.6       raeburn  1225:         if ($designhash{$dom.'.'.$role.'.font'} ne '') {
                   1226:             $designs{font} = $designhash{$dom.'.'.$role.'.font'};
                   1227:             $is_custom{'font'} = 1;
                   1228:         }
                   1229:         foreach my $item (@bgs) {
                   1230:             if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
                   1231:                 $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
                   1232:                 $is_custom{$item} = 1;
                   1233:             
                   1234:             }
                   1235:         }
                   1236:         foreach my $item (@links) {
                   1237:             if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
                   1238:                 $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
                   1239:                 $is_custom{$item} = 1;
                   1240:             }
                   1241:         }
                   1242:     }
                   1243:     my $itemcount = 1;
1.30      raeburn  1244:     my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6       raeburn  1245:     $datatable .= '</tr></table></td></tr>';
                   1246:     return $datatable;
                   1247: }
                   1248: 
1.200     raeburn  1249: sub role_defaults {
                   1250:     my ($role,$bgs,$links,$images,$logintext) = @_;
1.202     raeburn  1251:     my %defaults;
                   1252:     unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1.200     raeburn  1253:         return %defaults;
                   1254:     }
                   1255:     my %defaultdesign = %Apache::loncommon::defaultdesign;
                   1256:     if ($role eq 'login') {
                   1257:         %defaults = (
                   1258:                        font => $defaultdesign{$role.'.font'},
                   1259:                     );
                   1260:         if (ref($logintext) eq 'ARRAY') {
                   1261:             foreach my $item (@{$logintext}) {
                   1262:                 $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
                   1263:             }
                   1264:         }
                   1265:         foreach my $item (@{$images}) {
                   1266:             $defaults{'showlogo'}{$item} = 1;
                   1267:         }
                   1268:     } else {
                   1269:         %defaults = (
                   1270:                        img => $defaultdesign{$role.'.img'},
                   1271:                        font => $defaultdesign{$role.'.font'},
                   1272:                        fontmenu => $defaultdesign{$role.'.fontmenu'},
                   1273:                     );
                   1274:     }
                   1275:     foreach my $item (@{$bgs}) {
                   1276:         $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
                   1277:     }
                   1278:     foreach my $item (@{$links}) {
                   1279:         $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
                   1280:     }
                   1281:     foreach my $item (@{$images}) {
                   1282:         $defaults{$item} = $defaultdesign{$role.'.'.$item};
                   1283:     }
                   1284:     return %defaults;
                   1285: }
                   1286: 
1.6       raeburn  1287: sub display_color_options {
1.9       raeburn  1288:     my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135     bisitz   1289:         $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159     raeburn  1290:     my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6       raeburn  1291:     my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.176     raeburn  1292:     my $datatable = '<tr'.$css_class.'>'.
1.6       raeburn  1293:         '<td>'.$choices->{'font'}.'</td>';
                   1294:     if (!$is_custom->{'font'}) {
1.30      raeburn  1295:         $datatable .=  '<td>'.&mt('Default in use:').'&nbsp;<span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6       raeburn  1296:     } else {
                   1297:         $datatable .= '<td>&nbsp;</td>';
                   1298:     }
1.174     foxr     1299:     my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
                   1300: 
1.8       raeburn  1301:     $datatable .= '<td><span class="LC_nobreak">'.
1.174     foxr     1302:                   '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1.202     raeburn  1303:                   ' value="'.$current_color.'" />&nbsp;'.
1.174     foxr     1304:                   '&nbsp;</td></tr>';
1.107     raeburn  1305:     unless ($role eq 'login') { 
                   1306:         $datatable .= '<tr'.$css_class.'>'.
                   1307:                       '<td>'.$choices->{'fontmenu'}.'</td>';
                   1308:         if (!$is_custom->{'fontmenu'}) {
                   1309:             $datatable .=  '<td>'.&mt('Default in use:').'&nbsp;<span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
                   1310:         } else {
                   1311:             $datatable .= '<td>&nbsp;</td>';
                   1312:         }
1.202     raeburn  1313: 	$current_color = $designs->{'fontmenu'} ?
1.174     foxr     1314: 	    $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107     raeburn  1315:         $datatable .= '<td><span class="LC_nobreak">'.
1.174     foxr     1316:                       '<input class="colorchooser" type="text" size="10" name="'
                   1317: 		      .$role.'_fontmenu"'.
                   1318:                       ' value="'.$current_color.'" />&nbsp;'.
                   1319:                       '&nbsp;</td></tr>';
1.97      tempelho 1320:     }
1.9       raeburn  1321:     my $switchserver = &check_switchserver($dom,$confname);
1.6       raeburn  1322:     foreach my $img (@{$images}) {
1.18      albertel 1323: 	$itemcount ++;
1.6       raeburn  1324:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8       raeburn  1325:         $datatable .= '<tr'.$css_class.'>'.
1.70      raeburn  1326:                       '<td>'.$choices->{$img};
1.41      raeburn  1327:         my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70      raeburn  1328:         if ($role eq 'login') {
                   1329:             if ($img eq 'login') {
                   1330:                 $login_hdr_pick =
1.135     bisitz   1331:                     &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70      raeburn  1332:                 $logincolors =
                   1333:                     &login_text_colors($img,$role,$logintext,$phase,$choices,
1.201     raeburn  1334:                                        $designs,$defaults);
1.70      raeburn  1335:             } elsif ($img ne 'domlogo') {
                   1336:                 $datatable.= &logo_display_options($img,$defaults,$designs);
                   1337:             }
                   1338:         }
                   1339:         $datatable .= '</td>';
1.6       raeburn  1340:         if ($designs->{$img} ne '') {
                   1341:             $imgfile = $designs->{$img};
1.18      albertel 1342: 	    $img_import = ($imgfile =~ m{^/adm/});
1.6       raeburn  1343:         } else {
                   1344:             $imgfile = $defaults->{$img};
                   1345:         }
                   1346:         if ($imgfile) {
1.9       raeburn  1347:             my ($showfile,$fullsize);
                   1348:             if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6       raeburn  1349:                 my $urldir = $1;
                   1350:                 my $filename = $2;
                   1351:                 my @info = &Apache::lonnet::stat_file($designs->{$img});
                   1352:                 if (@info) {
                   1353:                     my $thumbfile = 'tn-'.$filename;
                   1354:                     my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
                   1355:                     if (@thumb) {
                   1356:                         $showfile = $urldir.'/'.$thumbfile;
                   1357:                     } else {
                   1358:                         $showfile = $imgfile;
                   1359:                     }
                   1360:                 } else {
                   1361:                     $showfile = '';
                   1362:                 }
                   1363:             } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16      raeburn  1364:                 $showfile = $imgfile;
1.6       raeburn  1365:                 my $imgdir = $1;
                   1366:                 my $filename = $2;
1.159     raeburn  1367:                 if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6       raeburn  1368:                     $showfile = "/$imgdir/tn-".$filename;
                   1369:                 } else {
1.159     raeburn  1370:                     my $input = $londocroot.$imgfile;
                   1371:                     my $output = "$londocroot/$imgdir/tn-".$filename;
1.6       raeburn  1372:                     if (!-e $output) {
1.9       raeburn  1373:                         my ($width,$height) = &thumb_dimensions();
1.16      raeburn  1374:                         my ($fullwidth,$fullheight) = &check_dimensions($input);
                   1375:                         if ($fullwidth ne '' && $fullheight ne '') {
                   1376:                             if ($fullwidth > $width && $fullheight > $height) { 
                   1377:                                 my $size = $width.'x'.$height;
                   1378:                                 system("convert -sample $size $input $output");
1.159     raeburn  1379:                                 $showfile = "/$imgdir/tn-".$filename;
1.16      raeburn  1380:                             }
                   1381:                         }
1.6       raeburn  1382:                     }
                   1383:                 }
1.16      raeburn  1384:             }
1.6       raeburn  1385:             if ($showfile) {
1.40      raeburn  1386:                 if ($showfile =~ m{^/(adm|res)/}) {
                   1387:                     if ($showfile =~ m{^/res/}) {
                   1388:                         my $local_showfile =
                   1389:                             &Apache::lonnet::filelocation('',$showfile);
                   1390:                         &Apache::lonnet::repcopy($local_showfile);
                   1391:                     }
                   1392:                     $showfile = &Apache::loncommon::lonhttpdurl($showfile);
                   1393:                 }
                   1394:                 if ($imgfile) {
                   1395:                     if ($imgfile  =~ m{^/(adm|res)/}) {
                   1396:                         if ($imgfile =~ m{^/res/}) {
                   1397:                             my $local_imgfile =
                   1398:                                 &Apache::lonnet::filelocation('',$imgfile);
                   1399:                             &Apache::lonnet::repcopy($local_imgfile);
                   1400:                         }
                   1401:                         $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
                   1402:                     } else {
                   1403:                         $fullsize = $imgfile;
                   1404:                     }
                   1405:                 }
1.41      raeburn  1406:                 $datatable .= '<td>';
                   1407:                 if ($img eq 'login') {
1.135     bisitz   1408:                     $datatable .= $login_hdr_pick;
                   1409:                 } 
1.41      raeburn  1410:                 $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
                   1411:                                              $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6       raeburn  1412:             } else {
1.201     raeburn  1413:                 $datatable .= '<td>&nbsp;</td><td class="LC_left_item">'.
                   1414:                               &mt('Upload:').'<br />';
1.6       raeburn  1415:             }
                   1416:         } else {
1.201     raeburn  1417:             $datatable .= '<td>&nbsp;</td><td class="LC_left_item">'.
                   1418:                           &mt('Upload:').'<br />';
1.6       raeburn  1419:         }
1.9       raeburn  1420:         if ($switchserver) {
                   1421:             $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   1422:         } else {
1.135     bisitz   1423:             if ($img ne 'login') { # suppress file selection for Log-in header
                   1424:                 $datatable .='&nbsp;<input type="file" name="'.$role.'_'.$img.'" />';
                   1425:             }
1.9       raeburn  1426:         }
                   1427:         $datatable .= '</td></tr>';
1.6       raeburn  1428:     }
                   1429:     $itemcount ++;
                   1430:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   1431:     $datatable .= '<tr'.$css_class.'>'.
                   1432:                   '<td>'.$choices->{'bgs'}.'</td>';
                   1433:     my $bgs_def;
                   1434:     foreach my $item (@{$bgs}) {
                   1435:         if (!$is_custom->{$item}) {
1.70      raeburn  1436:             $bgs_def .= '<td><span class="LC_nobreak">'.$choices->{$item}.'</span>&nbsp;<span id="css_default_'.$role.'_'.$item.'" style="background-color: '.$defaults->{'bgs'}{$item}.';">&nbsp;&nbsp;&nbsp;</span><br />'.$defaults->{'bgs'}{$item}.'</td>';
1.6       raeburn  1437:         }
                   1438:     }
                   1439:     if ($bgs_def) {
1.8       raeburn  1440:         $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6       raeburn  1441:     } else {
                   1442:         $datatable .= '<td>&nbsp;</td>';
                   1443:     }
                   1444:     $datatable .= '<td class="LC_right_item">'.
                   1445:                   '<table border="0"><tr>';
1.174     foxr     1446: 
1.6       raeburn  1447:     foreach my $item (@{$bgs}) {
1.201     raeburn  1448:         $datatable .= '<td align="center">'.$choices->{$item};
1.174     foxr     1449: 	my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6       raeburn  1450:         if ($designs->{'bgs'}{$item}) {
1.174     foxr     1451:             $datatable .= '&nbsp;';
1.6       raeburn  1452:         }
1.174     foxr     1453:         $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41      raeburn  1454:                       '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6       raeburn  1455:     }
                   1456:     $datatable .= '</tr></table></td></tr>';
                   1457:     $itemcount ++;
                   1458:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   1459:     $datatable .= '<tr'.$css_class.'>'.
                   1460:                   '<td>'.$choices->{'links'}.'</td>';
                   1461:     my $links_def;
                   1462:     foreach my $item (@{$links}) {
                   1463:         if (!$is_custom->{$item}) {
1.30      raeburn  1464:             $links_def .= '<td>'.$choices->{$item}.'<br /><span id="css_default_'.$role.'_'.$item.'" style="color: '.$defaults->{'links'}{$item}.';">'.$defaults->{'links'}{$item}.'</span></td>';
1.6       raeburn  1465:         }
                   1466:     }
                   1467:     if ($links_def) {
1.8       raeburn  1468:         $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6       raeburn  1469:     } else {
                   1470:         $datatable .= '<td>&nbsp;</td>';
                   1471:     }
                   1472:     $datatable .= '<td class="LC_right_item">'.
                   1473:                   '<table border="0"><tr>';
                   1474:     foreach my $item (@{$links}) {
1.234   ! raeburn  1475: 	my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.201     raeburn  1476:         $datatable .= '<td align="center">'.$choices->{$item}."\n";
1.6       raeburn  1477:         if ($designs->{'links'}{$item}) {
1.174     foxr     1478:             $datatable.='&nbsp;';
1.6       raeburn  1479:         }
1.174     foxr     1480:         $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6       raeburn  1481:                       '" /></td>';
                   1482:     }
1.30      raeburn  1483:     $$rowtotal += $itemcount;
1.3       raeburn  1484:     return $datatable;
                   1485: }
                   1486: 
1.70      raeburn  1487: sub logo_display_options {
                   1488:     my ($img,$defaults,$designs) = @_;
                   1489:     my $checkedon;
                   1490:     if (ref($defaults) eq 'HASH') {
                   1491:         if (ref($defaults->{'showlogo'}) eq 'HASH') {
                   1492:             if ($defaults->{'showlogo'}{$img}) {
                   1493:                 $checkedon = 'checked="checked" ';     
                   1494:             }
                   1495:         } 
                   1496:     }
                   1497:     if (ref($designs) eq 'HASH') {
                   1498:         if (ref($designs->{'showlogo'}) eq 'HASH') {
                   1499:             if (defined($designs->{'showlogo'}{$img})) {
                   1500:                 if ($designs->{'showlogo'}{$img} == 0) {
                   1501:                     $checkedon = '';
                   1502:                 } elsif ($designs->{'showlogo'}{$img} == 1) {
                   1503:                     $checkedon = 'checked="checked" ';
                   1504:                 }
                   1505:             }
                   1506:         }
                   1507:     }
                   1508:     return '<br /><label>&nbsp;&nbsp;<input type="checkbox" name="'.
                   1509:            'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
                   1510:            &mt('show').'</label>'."\n";
                   1511: }
                   1512: 
1.41      raeburn  1513: sub login_header_options  {
1.135     bisitz   1514:     my ($img,$role,$defaults,$is_custom,$choices) = @_;
                   1515:     my $output = '';
1.41      raeburn  1516:     if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135     bisitz   1517:         $output .= &mt('Text default(s):').'<br />';
1.41      raeburn  1518:         if (!$is_custom->{'textcol'}) {
                   1519:             $output .= $choices->{'textcol'}.':&nbsp;'.$defaults->{'logintext'}{'textcol'}.
                   1520:                        '&nbsp;&nbsp;&nbsp;';
                   1521:         }
                   1522:         if (!$is_custom->{'bgcol'}) {
                   1523:             $output .= $choices->{'bgcol'}.':&nbsp;'.
                   1524:                        '<span id="css_'.$role.'_font" style="background-color: '.
                   1525:                        $defaults->{'logintext'}{'bgcol'}.';">&nbsp;&nbsp;&nbsp;</span>';
                   1526:         }
                   1527:         $output .= '<br />';
                   1528:     }
                   1529:     $output .='<br />';
                   1530:     return $output;
                   1531: }
                   1532: 
                   1533: sub login_text_colors {
1.201     raeburn  1534:     my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41      raeburn  1535:     my $color_menu = '<table border="0"><tr>';
                   1536:     foreach my $item (@{$logintext}) {
1.201     raeburn  1537:         $color_menu .= '<td align="center">'.$choices->{$item};
                   1538:         my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
                   1539:         $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
                   1540:                       '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41      raeburn  1541:     }
                   1542:     $color_menu .= '</tr></table><br />';
                   1543:     return $color_menu;
                   1544: }
                   1545: 
                   1546: sub image_changes {
                   1547:     my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
                   1548:     my $output;
1.135     bisitz   1549:     if ($img eq 'login') {
                   1550:             # suppress image for Log-in header
                   1551:     } elsif (!$is_custom) {
1.70      raeburn  1552:         if ($img ne 'domlogo') {
1.41      raeburn  1553:             $output .= &mt('Default image:').'<br />';
                   1554:         } else {
                   1555:             $output .= &mt('Default in use:').'<br />';
                   1556:         }
                   1557:     }
1.135     bisitz   1558:     if ($img eq 'login') { # suppress image for Log-in header
                   1559:         $output .= '<td>'.$logincolors;
1.41      raeburn  1560:     } else {
1.135     bisitz   1561:         if ($img_import) {
                   1562:             $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
                   1563:         }
                   1564:         $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
                   1565:                    $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
                   1566:         if ($is_custom) {
                   1567:             $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
                   1568:                        '<input type="checkbox" name="'.
                   1569:                        $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
                   1570:                        '</label>&nbsp;'.&mt('Replace:').'</span><br />';
                   1571:         } else {
1.201     raeburn  1572:             $output .= '<td valign="middle">'.$logincolors.&mt('Upload:').'<br />';
1.135     bisitz   1573:         }
1.41      raeburn  1574:     }
                   1575:     return $output;
                   1576: }
                   1577: 
1.3       raeburn  1578: sub print_quotas {
1.86      raeburn  1579:     my ($dom,$settings,$rowtotal,$action) = @_;
                   1580:     my $context;
                   1581:     if ($action eq 'quotas') {
                   1582:         $context = 'tools';
                   1583:     } else {
                   1584:         $context = $action;
                   1585:     }
1.197     raeburn  1586:     my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44      raeburn  1587:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3       raeburn  1588:     my $typecount = 0;
1.101     raeburn  1589:     my ($css_class,%titles);
1.86      raeburn  1590:     if ($context eq 'requestcourses') {
1.216     raeburn  1591:         @usertools = ('official','unofficial','community','textbook');
1.106     raeburn  1592:         @options =('norequest','approval','validate','autolimit');
1.101     raeburn  1593:         %validations = &Apache::lonnet::auto_courserequest_checks($dom);
                   1594:         %titles = &courserequest_titles();
1.163     raeburn  1595:     } elsif ($context eq 'requestauthor') {
                   1596:         @usertools = ('author');
                   1597:         @options = ('norequest','approval','automatic');
1.210     raeburn  1598:         %titles = &authorrequest_titles();
1.86      raeburn  1599:     } else {
1.162     raeburn  1600:         @usertools = ('aboutme','blog','webdav','portfolio');
1.101     raeburn  1601:         %titles = &tool_titles();
1.86      raeburn  1602:     }
1.26      raeburn  1603:     if (ref($types) eq 'ARRAY') {
1.23      raeburn  1604:         foreach my $type (@{$types}) {
1.197     raeburn  1605:             my ($currdefquota,$currauthorquota);
1.163     raeburn  1606:             unless (($context eq 'requestcourses') ||
                   1607:                     ($context eq 'requestauthor')) {
1.86      raeburn  1608:                 if (ref($settings) eq 'HASH') {
                   1609:                     if (ref($settings->{defaultquota}) eq 'HASH') {
1.197     raeburn  1610:                         $currdefquota = $settings->{defaultquota}->{$type};
1.86      raeburn  1611:                     } else {
                   1612:                         $currdefquota = $settings->{$type};
                   1613:                     }
1.197     raeburn  1614:                     if (ref($settings->{authorquota}) eq 'HASH') {
                   1615:                         $currauthorquota = $settings->{authorquota}->{$type};
                   1616:                     }
1.78      raeburn  1617:                 }
1.72      raeburn  1618:             }
1.3       raeburn  1619:             if (defined($usertypes->{$type})) {
                   1620:                 $typecount ++;
                   1621:                 $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72      raeburn  1622:                 $datatable .= '<tr'.$css_class.'>'.
1.3       raeburn  1623:                               '<td>'.$usertypes->{$type}.'</td>'.
1.72      raeburn  1624:                               '<td class="LC_left_item">';
1.101     raeburn  1625:                 if ($context eq 'requestcourses') {
                   1626:                     $datatable .= '<table><tr>';
                   1627:                 }
                   1628:                 my %cell;  
1.72      raeburn  1629:                 foreach my $item (@usertools) {
1.101     raeburn  1630:                     if ($context eq 'requestcourses') {
                   1631:                         my ($curroption,$currlimit);
                   1632:                         if (ref($settings) eq 'HASH') {
                   1633:                             if (ref($settings->{$item}) eq 'HASH') {
                   1634:                                 $curroption = $settings->{$item}->{$type};
                   1635:                                 if ($curroption =~ /^autolimit=(\d*)$/) {
                   1636:                                     $currlimit = $1; 
                   1637:                                 }
                   1638:                             }
                   1639:                         }
                   1640:                         if (!$curroption) {
                   1641:                             $curroption = 'norequest';
                   1642:                         }
                   1643:                         $datatable .= '<th>'.$titles{$item}.'</th>';
                   1644:                         foreach my $option (@options) {
                   1645:                             my $val = $option;
                   1646:                             if ($option eq 'norequest') {
                   1647:                                 $val = 0;  
                   1648:                             }
                   1649:                             if ($option eq 'validate') {
                   1650:                                 my $canvalidate = 0;
                   1651:                                 if (ref($validations{$item}) eq 'HASH') { 
                   1652:                                     if ($validations{$item}{$type}) {
                   1653:                                         $canvalidate = 1;
                   1654:                                     }
                   1655:                                 }
                   1656:                                 next if (!$canvalidate);
                   1657:                             }
                   1658:                             my $checked = '';
                   1659:                             if ($option eq $curroption) {
                   1660:                                 $checked = ' checked="checked"';
                   1661:                             } elsif ($option eq 'autolimit') {
                   1662:                                 if ($curroption =~ /^autolimit/) {
                   1663:                                     $checked = ' checked="checked"';
                   1664:                                 }                       
                   1665:                             } 
                   1666:                             $cell{$item} .= '<span class="LC_nobreak"><label>'.
                   1667:                                   '<input type="radio" name="crsreq_'.$item.
                   1668:                                   '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127     raeburn  1669:                                   $titles{$option}.'</label>';
1.101     raeburn  1670:                             if ($option eq 'autolimit') {
1.127     raeburn  1671:                                 $cell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
1.101     raeburn  1672:                                                 $item.'_limit_'.$type.'" size="1" '.
1.103     raeburn  1673:                                                 'value="'.$currlimit.'" />';
1.101     raeburn  1674:                             }
1.127     raeburn  1675:                             $cell{$item} .= '</span> ';
1.103     raeburn  1676:                             if ($option eq 'autolimit') {
1.127     raeburn  1677:                                 $cell{$item} .= $titles{'unlimited'};
1.103     raeburn  1678:                             }
1.101     raeburn  1679:                         }
1.163     raeburn  1680:                     } elsif ($context eq 'requestauthor') {
                   1681:                         my $curroption;
                   1682:                         if (ref($settings) eq 'HASH') {
                   1683:                             $curroption = $settings->{$type};
                   1684:                         }
                   1685:                         if (!$curroption) {
                   1686:                             $curroption = 'norequest';
                   1687:                         }
                   1688:                         foreach my $option (@options) {
                   1689:                             my $val = $option;
                   1690:                             if ($option eq 'norequest') {
                   1691:                                 $val = 0;
                   1692:                             }
                   1693:                             my $checked = '';
                   1694:                             if ($option eq $curroption) {
                   1695:                                 $checked = ' checked="checked"';
                   1696:                             }
                   1697:                             $datatable .= '<span class="LC_nobreak"><label>'.
                   1698:                                   '<input type="radio" name="authorreq_'.$type.
                   1699:                                   '" value="'.$val.'"'.$checked.' />'.
                   1700:                                   $titles{$option}.'</label></span>&nbsp; ';
                   1701:                         }
1.101     raeburn  1702:                     } else {
                   1703:                         my $checked = 'checked="checked" ';
                   1704:                         if (ref($settings) eq 'HASH') {
                   1705:                             if (ref($settings->{$item}) eq 'HASH') {
                   1706:                                 if ($settings->{$item}->{$type} == 0) {
                   1707:                                     $checked = '';
                   1708:                                 } elsif ($settings->{$item}->{$type} == 1) {
                   1709:                                     $checked =  'checked="checked" ';
                   1710:                                 }
1.78      raeburn  1711:                             }
1.72      raeburn  1712:                         }
1.101     raeburn  1713:                         $datatable .= '<span class="LC_nobreak"><label>'.
                   1714:                                       '<input type="checkbox" name="'.$context.'_'.$item.
                   1715:                                       '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
                   1716:                                       '</label></span>&nbsp; ';
1.72      raeburn  1717:                     }
1.101     raeburn  1718:                 }
                   1719:                 if ($context eq 'requestcourses') {
                   1720:                     $datatable .= '</tr><tr>';
                   1721:                     foreach my $item (@usertools) {
1.106     raeburn  1722:                         $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';  
1.101     raeburn  1723:                     }
                   1724:                     $datatable .= '</tr></table>';
1.72      raeburn  1725:                 }
1.86      raeburn  1726:                 $datatable .= '</td>';
1.163     raeburn  1727:                 unless (($context eq 'requestcourses') ||
                   1728:                         ($context eq 'requestauthor')) {
1.86      raeburn  1729:                     $datatable .= 
1.197     raeburn  1730:                               '<td class="LC_right_item">'.
                   1731:                               '<span class="LC_nobreak">'.&mt('Portfolio').':&nbsp;'.
1.3       raeburn  1732:                               '<input type="text" name="quota_'.$type.
1.72      raeburn  1733:                               '" value="'.$currdefquota.
1.197     raeburn  1734:                               '" size="5" /></span>'.('&nbsp;' x 2).
                   1735:                               '<span class="LC_nobreak">'.&mt('Authoring').':&nbsp;'.
                   1736:                               '<input type="text" name="authorquota_'.$type.
                   1737:                               '" value="'.$currauthorquota.
                   1738:                               '" size="5" /></span></td>';
1.86      raeburn  1739:                 }
                   1740:                 $datatable .= '</tr>';
1.3       raeburn  1741:             }
                   1742:         }
                   1743:     }
1.163     raeburn  1744:     unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86      raeburn  1745:         $defaultquota = '20';
1.197     raeburn  1746:         $authorquota = '500';
1.86      raeburn  1747:         if (ref($settings) eq 'HASH') {
                   1748:             if (ref($settings->{'defaultquota'}) eq 'HASH') {
                   1749:                 $defaultquota = $settings->{'defaultquota'}->{'default'};
                   1750:             } elsif (defined($settings->{'default'})) {
                   1751:                 $defaultquota = $settings->{'default'};
                   1752:             }
1.197     raeburn  1753:             if (ref($settings->{'authorquota'}) eq 'HASH') {
                   1754:                 $authorquota = $settings->{'authorquota'}->{'default'};
                   1755:             }
1.3       raeburn  1756:         }
                   1757:     }
                   1758:     $typecount ++;
                   1759:     $css_class = $typecount%2?' class="LC_odd_row"':'';
                   1760:     $datatable .= '<tr'.$css_class.'>'.
1.26      raeburn  1761:                   '<td>'.$othertitle.'</td>'.
1.72      raeburn  1762:                   '<td class="LC_left_item">';
1.101     raeburn  1763:     if ($context eq 'requestcourses') {
                   1764:         $datatable .= '<table><tr>';
                   1765:     }
                   1766:     my %defcell;
1.72      raeburn  1767:     foreach my $item (@usertools) {
1.101     raeburn  1768:         if ($context eq 'requestcourses') {
                   1769:             my ($curroption,$currlimit);
                   1770:             if (ref($settings) eq 'HASH') {
                   1771:                 if (ref($settings->{$item}) eq 'HASH') {
                   1772:                     $curroption = $settings->{$item}->{'default'};
                   1773:                     if ($curroption =~ /^autolimit=(\d*)$/) {
                   1774:                         $currlimit = $1;
                   1775:                     }
                   1776:                 }
                   1777:             }
                   1778:             if (!$curroption) {
                   1779:                 $curroption = 'norequest';
                   1780:             }
                   1781:             $datatable .= '<th>'.$titles{$item}.'</th>';
                   1782:             foreach my $option (@options) {
                   1783:                 my $val = $option;
                   1784:                 if ($option eq 'norequest') {
                   1785:                     $val = 0;
                   1786:                 }
                   1787:                 if ($option eq 'validate') {
                   1788:                     my $canvalidate = 0;
                   1789:                     if (ref($validations{$item}) eq 'HASH') {
                   1790:                         if ($validations{$item}{'default'}) {
                   1791:                             $canvalidate = 1;
                   1792:                         }
                   1793:                     }
                   1794:                     next if (!$canvalidate);
                   1795:                 }
                   1796:                 my $checked = '';
                   1797:                 if ($option eq $curroption) {
                   1798:                     $checked = ' checked="checked"';
                   1799:                 } elsif ($option eq 'autolimit') {
                   1800:                     if ($curroption =~ /^autolimit/) {
                   1801:                         $checked = ' checked="checked"';
                   1802:                     }
                   1803:                 }
                   1804:                 $defcell{$item} .= '<span class="LC_nobreak"><label>'.
                   1805:                                   '<input type="radio" name="crsreq_'.$item.
                   1806:                                   '_default" value="'.$val.'"'.$checked.' />'.
                   1807:                                   $titles{$option}.'</label>';
                   1808:                 if ($option eq 'autolimit') {
1.127     raeburn  1809:                     $defcell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
1.101     raeburn  1810:                                        $item.'_limit_default" size="1" '.
                   1811:                                        'value="'.$currlimit.'" />';
                   1812:                 }
1.127     raeburn  1813:                 $defcell{$item} .= '</span> ';
1.104     raeburn  1814:                 if ($option eq 'autolimit') {
1.127     raeburn  1815:                     $defcell{$item} .= $titles{'unlimited'};
1.104     raeburn  1816:                 }
1.101     raeburn  1817:             }
1.163     raeburn  1818:         } elsif ($context eq 'requestauthor') {
                   1819:             my $curroption;
                   1820:             if (ref($settings) eq 'HASH') {
1.172     raeburn  1821:                 $curroption = $settings->{'default'};
1.163     raeburn  1822:             }
                   1823:             if (!$curroption) {
                   1824:                 $curroption = 'norequest';
                   1825:             }
                   1826:             foreach my $option (@options) {
                   1827:                 my $val = $option;
                   1828:                 if ($option eq 'norequest') {
                   1829:                     $val = 0;
                   1830:                 }
                   1831:                 my $checked = '';
                   1832:                 if ($option eq $curroption) {
                   1833:                     $checked = ' checked="checked"';
                   1834:                 }
                   1835:                 $datatable .= '<span class="LC_nobreak"><label>'.
                   1836:                               '<input type="radio" name="authorreq_default"'.
                   1837:                               ' value="'.$val.'"'.$checked.' />'.
                   1838:                               $titles{$option}.'</label></span>&nbsp; ';
                   1839:             }
1.101     raeburn  1840:         } else {
                   1841:             my $checked = 'checked="checked" ';
                   1842:             if (ref($settings) eq 'HASH') {
                   1843:                 if (ref($settings->{$item}) eq 'HASH') {
                   1844:                     if ($settings->{$item}->{'default'} == 0) {
                   1845:                         $checked = '';
                   1846:                     } elsif ($settings->{$item}->{'default'} == 1) {
                   1847:                         $checked = 'checked="checked" ';
                   1848:                     }
1.78      raeburn  1849:                 }
1.72      raeburn  1850:             }
1.101     raeburn  1851:             $datatable .= '<span class="LC_nobreak"><label>'.
                   1852:                           '<input type="checkbox" name="'.$context.'_'.$item.
                   1853:                           '" value="default" '.$checked.'/>'.$titles{$item}.
                   1854:                           '</label></span>&nbsp; ';
                   1855:         }
                   1856:     }
                   1857:     if ($context eq 'requestcourses') {
                   1858:         $datatable .= '</tr><tr>';
                   1859:         foreach my $item (@usertools) {
1.106     raeburn  1860:             $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72      raeburn  1861:         }
1.101     raeburn  1862:         $datatable .= '</tr></table>';
1.72      raeburn  1863:     }
1.86      raeburn  1864:     $datatable .= '</td>';
1.163     raeburn  1865:     unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.197     raeburn  1866:         $datatable .= '<td class="LC_right_item">'.
                   1867:                       '<span class="LC_nobreak">'.&mt('Portfolio').':&nbsp;'.
1.86      raeburn  1868:                       '<input type="text" name="defaultquota" value="'.
1.197     raeburn  1869:                       $defaultquota.'" size="5" /></span>'.('&nbsp;' x2).
                   1870:                       '<span class="LC_nobreak">'.&mt('Authoring').':&nbsp;'.
                   1871:                       '<input type="text" name="authorquota" value="'.
                   1872:                       $authorquota.'" size="5" /></span></td>';
1.86      raeburn  1873:     }
                   1874:     $datatable .= '</tr>';
1.72      raeburn  1875:     $typecount ++;
                   1876:     $css_class = $typecount%2?' class="LC_odd_row"':'';
                   1877:     $datatable .= '<tr'.$css_class.'>'.
1.197     raeburn  1878:                   '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104     raeburn  1879:     if ($context eq 'requestcourses') {
1.109     raeburn  1880:         $datatable .= &mt('(overrides affiliation, if set)').
                   1881:                       '</td>'.
                   1882:                       '<td class="LC_left_item">'.
                   1883:                       '<table><tr>';
1.101     raeburn  1884:     } else {
1.109     raeburn  1885:         $datatable .= &mt('(overrides affiliation, if checked)').
                   1886:                       '</td>'.
                   1887:                       '<td class="LC_left_item" colspan="2">'.
                   1888:                       '<br />';
1.101     raeburn  1889:     }
                   1890:     my %advcell;
1.72      raeburn  1891:     foreach my $item (@usertools) {
1.101     raeburn  1892:         if ($context eq 'requestcourses') {
                   1893:             my ($curroption,$currlimit);
                   1894:             if (ref($settings) eq 'HASH') {
                   1895:                 if (ref($settings->{$item}) eq 'HASH') {
                   1896:                     $curroption = $settings->{$item}->{'_LC_adv'};
                   1897:                     if ($curroption =~ /^autolimit=(\d*)$/) {
                   1898:                         $currlimit = $1;
                   1899:                     }
                   1900:                 }
                   1901:             }
                   1902:             $datatable .= '<th>'.$titles{$item}.'</th>';
1.104     raeburn  1903:             my $checked = '';
                   1904:             if ($curroption eq '') {
                   1905:                 $checked = ' checked="checked"';
                   1906:             }
                   1907:             $advcell{$item} .= '<span class="LC_nobreak"><label>'.
                   1908:                                '<input type="radio" name="crsreq_'.$item.
                   1909:                                '__LC_adv" value=""'.$checked.' />'.
                   1910:                                &mt('No override set').'</label></span>&nbsp; ';
1.101     raeburn  1911:             foreach my $option (@options) {
                   1912:                 my $val = $option;
                   1913:                 if ($option eq 'norequest') {
                   1914:                     $val = 0;
                   1915:                 }
                   1916:                 if ($option eq 'validate') {
                   1917:                     my $canvalidate = 0;
                   1918:                     if (ref($validations{$item}) eq 'HASH') {
                   1919:                         if ($validations{$item}{'_LC_adv'}) {
                   1920:                             $canvalidate = 1;
                   1921:                         }
                   1922:                     }
                   1923:                     next if (!$canvalidate);
                   1924:                 }
                   1925:                 my $checked = '';
1.104     raeburn  1926:                 if ($val eq $curroption) {
1.101     raeburn  1927:                     $checked = ' checked="checked"';
                   1928:                 } elsif ($option eq 'autolimit') {
                   1929:                     if ($curroption =~ /^autolimit/) {
                   1930:                         $checked = ' checked="checked"';
                   1931:                     }
                   1932:                 }
                   1933:                 $advcell{$item} .= '<span class="LC_nobreak"><label>'.
                   1934:                                   '<input type="radio" name="crsreq_'.$item.
                   1935:                                   '__LC_adv" value="'.$val.'"'.$checked.' />'.
                   1936:                                   $titles{$option}.'</label>';
                   1937:                 if ($option eq 'autolimit') {
1.127     raeburn  1938:                     $advcell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
1.101     raeburn  1939:                                        $item.'_limit__LC_adv" size="1" '.
                   1940:                                        'value="'.$currlimit.'" />';
                   1941:                 }
1.127     raeburn  1942:                 $advcell{$item} .= '</span> ';
1.104     raeburn  1943:                 if ($option eq 'autolimit') {
1.127     raeburn  1944:                     $advcell{$item} .= $titles{'unlimited'};
1.104     raeburn  1945:                 }
1.101     raeburn  1946:             }
1.163     raeburn  1947:         } elsif ($context eq 'requestauthor') {
                   1948:             my $curroption;
                   1949:             if (ref($settings) eq 'HASH') {
                   1950:                 $curroption = $settings->{'_LC_adv'};
                   1951:             }
                   1952:             my $checked = '';
                   1953:             if ($curroption eq '') {
                   1954:                 $checked = ' checked="checked"';
                   1955:             }
                   1956:             $datatable .= '<span class="LC_nobreak"><label>'.
                   1957:                           '<input type="radio" name="authorreq__LC_adv"'.
                   1958:                           ' value=""'.$checked.' />'.
                   1959:                           &mt('No override set').'</label></span>&nbsp; ';
                   1960:             foreach my $option (@options) {
                   1961:                 my $val = $option;
                   1962:                 if ($option eq 'norequest') {
                   1963:                     $val = 0;
                   1964:                 }
                   1965:                 my $checked = '';
                   1966:                 if ($val eq $curroption) {
                   1967:                     $checked = ' checked="checked"';
                   1968:                 }
                   1969:                 $datatable .= '<span class="LC_nobreak"><label>'.
1.173     raeburn  1970:                               '<input type="radio" name="authorreq__LC_adv"'.
                   1971:                               ' value="'.$val.'"'.$checked.' />'.
1.163     raeburn  1972:                               $titles{$option}.'</label></span>&nbsp; ';
                   1973:             }
1.101     raeburn  1974:         } else {
                   1975:             my $checked = 'checked="checked" ';
                   1976:             if (ref($settings) eq 'HASH') {
                   1977:                 if (ref($settings->{$item}) eq 'HASH') {
                   1978:                     if ($settings->{$item}->{'_LC_adv'} == 0) {
                   1979:                         $checked = '';
                   1980:                     } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
                   1981:                         $checked = 'checked="checked" ';
                   1982:                     }
1.79      raeburn  1983:                 }
1.72      raeburn  1984:             }
1.101     raeburn  1985:             $datatable .= '<span class="LC_nobreak"><label>'.
                   1986:                           '<input type="checkbox" name="'.$context.'_'.$item.
                   1987:                           '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
                   1988:                           '</label></span>&nbsp; ';
                   1989:         }
                   1990:     }
                   1991:     if ($context eq 'requestcourses') {
                   1992:         $datatable .= '</tr><tr>';
                   1993:         foreach my $item (@usertools) {
1.106     raeburn  1994:             $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72      raeburn  1995:         }
1.101     raeburn  1996:         $datatable .= '</tr></table>';
1.72      raeburn  1997:     }
1.98      raeburn  1998:     $datatable .= '</td></tr>';
1.30      raeburn  1999:     $$rowtotal += $typecount;
1.3       raeburn  2000:     return $datatable;
                   2001: }
                   2002: 
1.163     raeburn  2003: sub print_requestmail {
                   2004:     my ($dom,$action,$settings,$rowtotal) = @_;
1.208     raeburn  2005:     my ($now,$datatable,%currapp);
1.102     raeburn  2006:     $now = time;
                   2007:     if (ref($settings) eq 'HASH') {
                   2008:         if (ref($settings->{'notify'}) eq 'HASH') {
                   2009:             if ($settings->{'notify'}{'approval'} ne '') {
1.224     raeburn  2010:                 map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102     raeburn  2011:             }
                   2012:         }
                   2013:     }
1.191     raeburn  2014:     my $numinrow = 2;
1.224     raeburn  2015:     my $css_class;
                   2016:     $css_class = ($$rowtotal%2? ' class="LC_odd_row"':'');
1.163     raeburn  2017:     my $text;
                   2018:     if ($action eq 'requestcourses') {
                   2019:         $text = &mt('Receive notification of course requests requiring approval');
1.224     raeburn  2020:     } elsif ($action eq 'requestauthor') {
                   2021:         $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.163     raeburn  2022:     } else {
1.224     raeburn  2023:        $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.163     raeburn  2024:     }
1.224     raeburn  2025:     $datatable = '<tr'.$css_class.'>'.
1.163     raeburn  2026:                  ' <td>'.$text.'</td>'.
1.102     raeburn  2027:                  ' <td class="LC_left_item">';
1.191     raeburn  2028:     my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.224     raeburn  2029:                                                  $action.'notifyapproval',%currapp);
1.191     raeburn  2030:     if ($numdc > 0) {
                   2031:         $datatable .= $table;
1.102     raeburn  2032:     } else {
                   2033:         $datatable .= &mt('There are no active Domain Coordinators');
                   2034:     }
                   2035:     $datatable .='</td></tr>';
                   2036:     $$rowtotal += $rows;
                   2037:     return $datatable;
                   2038: }
                   2039: 
1.216     raeburn  2040: sub print_studentcode {
                   2041:     my ($settings,$rowtotal) = @_;
                   2042:     my $rownum = 0; 
1.218     raeburn  2043:     my ($output,%current);
                   2044:     my @crstypes = ('official','unofficial','community','textbook');
                   2045:     if (ref($settings->{'uniquecode'}) eq 'HASH') {
                   2046:         foreach my $type (@crstypes) {
                   2047:             $current{$type} = $settings->{'uniquecode'}{$type};
                   2048:         }
                   2049:     }
                   2050:     $output .= '<tr>'.
                   2051:                '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
                   2052:                '<td class="LC_left_item">';
                   2053:     foreach my $type (@crstypes) {
                   2054:         my $check = ' ';
                   2055:         if ($current{$type}) {
                   2056:             $check = ' checked="checked" ';
                   2057:         }
                   2058:         $output .= '<span class="LC_nobreak"><label>'.
                   2059:                    '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
                   2060:                    &mt($type).'</label></span>'.('&nbsp;'x2).' ';
                   2061:     }
                   2062:     $output .= '</td></tr>';
                   2063:     $$rowtotal ++;
                   2064:     return $output;
1.216     raeburn  2065: }
                   2066: 
                   2067: sub print_textbookcourses {
                   2068:     my ($dom,$settings,$rowtotal) = @_;
                   2069:     my $rownum = 0;
                   2070:     my $css_class;
                   2071:     my $itemcount = 1;
                   2072:     my $maxnum = 0;
                   2073:     my $bookshash;
                   2074:     if (ref($settings) eq 'HASH') {
                   2075:         $bookshash = $settings->{'textbooks'};
                   2076:     }
                   2077:     my %ordered;
                   2078:     if (ref($bookshash) eq 'HASH') {
                   2079:         foreach my $item (keys(%{$bookshash})) {
                   2080:             if (ref($bookshash->{$item}) eq 'HASH') {
                   2081:                 my $num = $bookshash->{$item}{'order'};
                   2082:                 $ordered{$num} = $item;
                   2083:             }
                   2084:         }
                   2085:     }
                   2086:     my $confname = $dom.'-domainconfig';
                   2087:     my $switchserver = &check_switchserver($dom,$confname);
                   2088:     my $maxnum = scalar(keys(%ordered));
1.217     raeburn  2089:     my $datatable = &textbookcourses_javascript(\%ordered);
1.216     raeburn  2090:     if (keys(%ordered)) {
                   2091:         my @items = sort { $a <=> $b } keys(%ordered);
                   2092:         for (my $i=0; $i<@items; $i++) {
                   2093:             $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   2094:             my $key = $ordered{$items[$i]};
                   2095:             my %coursehash=&Apache::lonnet::coursedescription($key);
                   2096:             my $coursetitle = $coursehash{'description'};
                   2097:             my ($subject,$title,$author,$image,$imgsrc,$cdom,$cnum);
                   2098:             if (ref($bookshash->{$key}) eq 'HASH') {
                   2099:                 $subject = $bookshash->{$key}->{'subject'};
                   2100:                 $title = $bookshash->{$key}->{'title'};
                   2101:                 $author = $bookshash->{$key}->{'author'};
                   2102:                 $image = $bookshash->{$key}->{'image'};
                   2103:                 if ($image ne '') {
                   2104:                     my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
                   2105:                     my $imagethumb = "$path/tn-".$imagefile;
                   2106:                     $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
                   2107:                 }
                   2108:             }
1.217     raeburn  2109:             my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$key'".');"';
1.216     raeburn  2110:             $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
                   2111:                          .'<select name="'.$key.'"'.$chgstr.'>';
                   2112:             for (my $k=0; $k<=$maxnum; $k++) {
                   2113:                 my $vpos = $k+1;
                   2114:                 my $selstr;
                   2115:                 if ($k == $i) {
                   2116:                     $selstr = ' selected="selected" ';
                   2117:                 }
                   2118:                 $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   2119:             }
                   2120:             $datatable .= '</select>'.('&nbsp;'x2).
                   2121:                 '<label><input type="checkbox" name="book_del" value="'.$key.'" />'.
                   2122:                 &mt('Delete?').'</label></span></td>'.
                   2123:                 '<td colspan="2">'.
                   2124:                 '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="book_subject_'.$i.'" value="'.$subject.'" /></span> '.
                   2125:                 ('&nbsp;'x2).
                   2126:                 '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="book_title_'.$i.'" value="'.$title.'" /></span> '.
                   2127:                 ('&nbsp;'x2).
                   2128:                 '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="book_author_'.$i.'" value="'.$author.'" /></span> '.
                   2129:                 ('&nbsp;'x2).
                   2130:                 '<span class="LC_nobreak">'.&mt('Thumbnail:');
                   2131:             if ($image) {
                   2132:                 $datatable .= '<span class="LC_nobreak">'.
                   2133:                               $imgsrc.
                   2134:                               '<label><input type="checkbox" name="book_image_del"'.
                   2135:                               ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
                   2136:                               '<span class="LC_nobreak">&nbsp;'.&mt('Replace:').'&nbsp;';
                   2137:             }
                   2138:             if ($switchserver) {
                   2139:                 $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   2140:             } else {
                   2141:                 $datatable .= '<input type="file" name="book_image_'.$i.'" value="" />';
                   2142:             }
                   2143:             $datatable .= '<input type="hidden" name="book_id_'.$i.'" value="'.$key.'" /></span> '.
                   2144:                           '<span class="LC_nobreak">'.&mt('LON-CAPA course:').'&nbsp;'.
                   2145:                           $coursetitle.'</span></td></tr>'."\n";
                   2146:             $itemcount ++;
                   2147:         }
                   2148:     }
                   2149:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.217     raeburn  2150:     my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'addbook_pos'".');"';
1.216     raeburn  2151:     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
                   2152:                   '<input type="hidden" name="book_maxnum" value="'.$maxnum.'" />'."\n".
                   2153:                   '<select name="addbook_pos"'.$chgstr.'>';
                   2154:     for (my $k=0; $k<$maxnum+1; $k++) {
                   2155:         my $vpos = $k+1;
                   2156:         my $selstr;
                   2157:         if ($k == $maxnum) {
                   2158:             $selstr = ' selected="selected" ';
                   2159:         }
                   2160:         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   2161:     }
                   2162:     $datatable .= '</select>&nbsp;'."\n".
                   2163:                   '<input type="checkbox" name="addbook" value="1" />'.&mt('Add').'</td>'."\n".
                   2164:                   '<td colspan="2">'.
                   2165:                   '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="addbook_subject" value="" /></span> '."\n".
                   2166:                   ('&nbsp;'x2).
                   2167:                   '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="addbook_title" value="" /></span> '."\n".
                   2168:                   ('&nbsp;'x2).
                   2169:                   '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="addbook_author" value="" /></span> '."\n".
                   2170:                   ('&nbsp;'x2).
                   2171:                   '<span class="LC_nobreak">'.&mt('Image:').'&nbsp;';
                   2172:     if ($switchserver) {
                   2173:         $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   2174:     } else {
                   2175:         $datatable .= '<input type="file" name="addbook_image" value="" />';
                   2176:     }
                   2177:     $datatable .= '</span>'."\n".
                   2178:                   '<span class="LC_nobreak">'.&mt('LON-CAPA course:').'&nbsp;'.
                   2179:                   &Apache::loncommon::select_dom_form($env{'request.role.domain'},'addbook_cdom').
                   2180:                   '<input type="text" size="25" name="addbook_cnum" value="" />'.
                   2181:                   &Apache::loncommon::selectcourse_link
                   2182:                       ('display','addbook_cnum','addbook_cdom',undef,undef,undef,'Course');
                   2183:                   '</span></td>'."\n".
                   2184:                   '</tr>'."\n";
                   2185:     $itemcount ++;
                   2186:     return $datatable;
                   2187: }
                   2188: 
1.217     raeburn  2189: sub textbookcourses_javascript {
                   2190:     my ($textbooks) = @_;
                   2191:     return unless(ref($textbooks) eq 'HASH');
                   2192:     my $num = scalar(keys(%{$textbooks}));
                   2193:     my @jsarray;
                   2194:     foreach my $item (sort {$a <=> $b } (keys(%{$textbooks}))) {
                   2195:         push(@jsarray,$textbooks->{$item});
                   2196:     }
                   2197:     my $jstext = '    var textbooks = Array('."'".join("','",@jsarray)."'".');'."\n";
                   2198:     return <<"ENDSCRIPT";
                   2199: <script type="text/javascript">
                   2200: // <![CDATA[
                   2201: function reorderBooks(form,item) {
                   2202:     var changedVal;
                   2203: $jstext 
                   2204:     var newpos = 'addbook_pos';
                   2205:     var current = new Array;
                   2206:     var maxh = 1 + $num;
                   2207:     var current = new Array;
                   2208:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
                   2209:     if (item == newpos) {
                   2210:         changedVal = newitemVal;
                   2211:     } else {
                   2212:         changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
                   2213:         current[newitemVal] = newpos;
                   2214:     }
                   2215:     for (var i=0; i<textbooks.length; i++) {
                   2216:         var elementName = textbooks[i];
                   2217:         if (elementName != item) {
                   2218:             if (form.elements[elementName]) {
                   2219:                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   2220:                 current[currVal] = elementName;
                   2221:             }
                   2222:         }
                   2223:     }
                   2224:     var oldVal;
                   2225:     for (var j=0; j<maxh; j++) {
                   2226:         if (current[j] == undefined) {
                   2227:             oldVal = j;
                   2228:         }
                   2229:     }
                   2230:     if (oldVal < changedVal) {
                   2231:         for (var k=oldVal+1; k<=changedVal ; k++) {
                   2232:            var elementName = current[k];
                   2233:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   2234:         }
                   2235:     } else {
                   2236:         for (var k=changedVal; k<oldVal; k++) {
                   2237:             var elementName = current[k];
                   2238:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   2239:         }
                   2240:     }
                   2241:     return;
                   2242: }
                   2243: 
                   2244: // ]]>
                   2245: </script>
                   2246: 
                   2247: ENDSCRIPT
                   2248: }
                   2249: 
1.3       raeburn  2250: sub print_autoenroll {
1.30      raeburn  2251:     my ($dom,$settings,$rowtotal) = @_;
1.3       raeburn  2252:     my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.129     raeburn  2253:     my ($defdom,$runon,$runoff,$coownerson,$coownersoff);
1.3       raeburn  2254:     if (ref($settings) eq 'HASH') {
                   2255:         if (exists($settings->{'run'})) {
                   2256:             if ($settings->{'run'} eq '0') {
                   2257:                 $runoff = ' checked="checked" ';
                   2258:                 $runon = ' ';
                   2259:             } else {
                   2260:                 $runon = ' checked="checked" ';
                   2261:                 $runoff = ' ';
                   2262:             }
                   2263:         } else {
                   2264:             if ($autorun) {
                   2265:                 $runon = ' checked="checked" ';
                   2266:                 $runoff = ' ';
                   2267:             } else {
                   2268:                 $runoff = ' checked="checked" ';
                   2269:                 $runon = ' ';
                   2270:             }
                   2271:         }
1.129     raeburn  2272:         if (exists($settings->{'co-owners'})) {
                   2273:             if ($settings->{'co-owners'} eq '0') {
                   2274:                 $coownersoff = ' checked="checked" ';
                   2275:                 $coownerson = ' ';
                   2276:             } else {
                   2277:                 $coownerson = ' checked="checked" ';
                   2278:                 $coownersoff = ' ';
                   2279:             }
                   2280:         } else {
                   2281:             $coownersoff = ' checked="checked" ';
                   2282:             $coownerson = ' ';
                   2283:         }
1.3       raeburn  2284:         if (exists($settings->{'sender_domain'})) {
                   2285:             $defdom = $settings->{'sender_domain'};
                   2286:         }
1.14      raeburn  2287:     } else {
                   2288:         if ($autorun) {
                   2289:             $runon = ' checked="checked" ';
                   2290:             $runoff = ' ';
                   2291:         } else {
                   2292:             $runoff = ' checked="checked" ';
                   2293:             $runon = ' ';
                   2294:         }
1.3       raeburn  2295:     }
                   2296:     my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39      raeburn  2297:     my $notif_sender;
                   2298:     if (ref($settings) eq 'HASH') {
                   2299:         $notif_sender = $settings->{'sender_uname'};
                   2300:     }
1.3       raeburn  2301:     my $datatable='<tr class="LC_odd_row">'.
                   2302:                   '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8       raeburn  2303:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3       raeburn  2304:                   '<input type="radio" name="autoenroll_run"'.
1.8       raeburn  2305:                   $runon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   2306:                   '<label><input type="radio" name="autoenroll_run"'.
1.14      raeburn  2307:                   $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3       raeburn  2308:                   '</tr><tr>'.
                   2309:                   '<td>'.&mt('Notification messages - sender').
1.8       raeburn  2310:                   '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3       raeburn  2311:                   &mt('username').':&nbsp;'.
                   2312:                   '<input type="text" name="sender_uname" value="'.
1.39      raeburn  2313:                   $notif_sender.'" size="10" />&nbsp;&nbsp;'.&mt('domain').
1.129     raeburn  2314:                   ':&nbsp;'.$domform.'</span></td></tr>'.
                   2315:                   '<tr class="LC_odd_row">'.
                   2316:                   '<td>'.&mt('Automatically assign co-ownership').'</td>'.
                   2317:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   2318:                   '<input type="radio" name="autoassign_coowners"'.
                   2319:                   $coownerson.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   2320:                   '<label><input type="radio" name="autoassign_coowners"'.
                   2321:                   $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
                   2322:                   '</tr>';
                   2323:     $$rowtotal += 3;
1.3       raeburn  2324:     return $datatable;
                   2325: }
                   2326: 
                   2327: sub print_autoupdate {
1.30      raeburn  2328:     my ($position,$dom,$settings,$rowtotal) = @_;
1.3       raeburn  2329:     my $datatable;
                   2330:     if ($position eq 'top') {
                   2331:         my $updateon = ' ';
                   2332:         my $updateoff = ' checked="checked" ';
                   2333:         my $classlistson = ' ';
                   2334:         my $classlistsoff = ' checked="checked" ';
                   2335:         if (ref($settings) eq 'HASH') {
                   2336:             if ($settings->{'run'} eq '1') {
                   2337:                 $updateon = $updateoff;
                   2338:                 $updateoff = ' ';
                   2339:             }
                   2340:             if ($settings->{'classlists'} eq '1') {
                   2341:                 $classlistson = $classlistsoff;
                   2342:                 $classlistsoff = ' ';
                   2343:             }
                   2344:         }
                   2345:         my %title = (
                   2346:                    run => 'Auto-update active?',
                   2347:                    classlists => 'Update information in classlists?',
                   2348:                     );
                   2349:         $datatable = '<tr class="LC_odd_row">'. 
                   2350:                   '<td>'.&mt($title{'run'}).'</td>'.
1.8       raeburn  2351:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3       raeburn  2352:                   '<input type="radio" name="autoupdate_run"'.
1.8       raeburn  2353:                   $updateon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   2354:                   '<label><input type="radio" name="autoupdate_run"'.
                   2355:                   $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3       raeburn  2356:                   '</tr><tr>'.
                   2357:                   '<td>'.&mt($title{'classlists'}).'</td>'.
1.8       raeburn  2358:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
                   2359:                   '<label><input type="radio" name="classlists"'.
                   2360:                   $classlistson.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   2361:                   '<label><input type="radio" name="classlists"'.
                   2362:                   $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3       raeburn  2363:                   '</tr>';
1.30      raeburn  2364:         $$rowtotal += 2;
1.131     raeburn  2365:     } elsif ($position eq 'middle') {
                   2366:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   2367:         my $numinrow = 3;
                   2368:         my $locknamesettings;
                   2369:         $datatable .= &insttypes_row($settings,$types,$usertypes,
                   2370:                                      $dom,$numinrow,$othertitle,
                   2371:                                     'lockablenames');
                   2372:         $$rowtotal ++;
1.3       raeburn  2373:     } else {
1.44      raeburn  2374:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132     raeburn  2375:         my @fields = ('lastname','firstname','middlename','generation',
1.20      raeburn  2376:                       'permanentemail','id');
1.33      raeburn  2377:         my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3       raeburn  2378:         my $numrows = 0;
1.26      raeburn  2379:         if (ref($types) eq 'ARRAY') {
                   2380:             if (@{$types} > 0) {
                   2381:                 $datatable = 
                   2382:                     &usertype_update_row($settings,$usertypes,\%fieldtitles,
                   2383:                                          \@fields,$types,\$numrows);
1.30      raeburn  2384:                     $$rowtotal += @{$types}; 
1.26      raeburn  2385:             }
1.3       raeburn  2386:         }
                   2387:         $datatable .= 
                   2388:             &usertype_update_row($settings,{'default' => $othertitle},
                   2389:                                  \%fieldtitles,\@fields,['default'],
                   2390:                                  \$numrows);
1.30      raeburn  2391:         $$rowtotal ++;     
1.3       raeburn  2392:     }
                   2393:     return $datatable;
                   2394: }
                   2395: 
1.125     raeburn  2396: sub print_autocreate {
                   2397:     my ($dom,$settings,$rowtotal) = @_;
1.191     raeburn  2398:     my (%createon,%createoff,%currhash);
1.125     raeburn  2399:     my @types = ('xml','req');
                   2400:     if (ref($settings) eq 'HASH') {
                   2401:         foreach my $item (@types) {
                   2402:             $createoff{$item} = ' checked="checked" ';
                   2403:             $createon{$item} = ' ';
                   2404:             if (exists($settings->{$item})) {
                   2405:                 if ($settings->{$item}) {
                   2406:                     $createon{$item} = ' checked="checked" ';
                   2407:                     $createoff{$item} = ' ';
                   2408:                 }
                   2409:             }
                   2410:         }
1.210     raeburn  2411:         if ($settings->{'xmldc'} ne '') {
1.191     raeburn  2412:             $currhash{$settings->{'xmldc'}} = 1;
                   2413:         }
1.125     raeburn  2414:     } else {
                   2415:         foreach my $item (@types) {
                   2416:             $createoff{$item} = ' checked="checked" ';
                   2417:             $createon{$item} = ' ';
                   2418:         }
                   2419:     }
                   2420:     $$rowtotal += 2;
1.191     raeburn  2421:     my $numinrow = 2;
1.125     raeburn  2422:     my $datatable='<tr class="LC_odd_row">'.
                   2423:                   '<td>'.&mt('Create pending official courses from XML files').'</td>'.
                   2424:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   2425:                   '<input type="radio" name="autocreate_xml"'.
                   2426:                   $createon{'xml'}.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   2427:                   '<label><input type="radio" name="autocreate_xml"'.
1.143     raeburn  2428:                   $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
                   2429:                   '</td></tr><tr>'.
                   2430:                   '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
                   2431:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   2432:                   '<input type="radio" name="autocreate_req"'.
                   2433:                   $createon{'req'}.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   2434:                   '<label><input type="radio" name="autocreate_req"'.
                   2435:                   $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.191     raeburn  2436:     my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
                   2437:                                                    'autocreate_xmldc',%currhash);
1.125     raeburn  2438:     if ($numdc > 1) {
1.143     raeburn  2439:         $datatable .= '</td></tr><tr class="LC_odd_row"><td>'.
                   2440:                       &mt('Course creation processed as: (choose Dom. Coord.)').
                   2441:                       '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.125     raeburn  2442:     } else {
1.143     raeburn  2443:         $datatable .= $dctable.'</td></tr>';
1.125     raeburn  2444:     }
1.191     raeburn  2445:     $$rowtotal += $rows;
1.125     raeburn  2446:     return $datatable;
                   2447: }
                   2448: 
1.23      raeburn  2449: sub print_directorysrch {
1.30      raeburn  2450:     my ($dom,$settings,$rowtotal) = @_;
1.23      raeburn  2451:     my $srchon = ' ';
                   2452:     my $srchoff = ' checked="checked" ';
1.25      raeburn  2453:     my ($exacton,$containson,$beginson);
1.24      raeburn  2454:     my $localon = ' ';
                   2455:     my $localoff = ' checked="checked" ';
1.23      raeburn  2456:     if (ref($settings) eq 'HASH') {
                   2457:         if ($settings->{'available'} eq '1') {
                   2458:             $srchon = $srchoff;
                   2459:             $srchoff = ' ';
                   2460:         }
1.24      raeburn  2461:         if ($settings->{'localonly'} eq '1') {
                   2462:             $localon = $localoff;
                   2463:             $localoff = ' ';
                   2464:         }
1.25      raeburn  2465:         if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
                   2466:             foreach my $type (@{$settings->{'searchtypes'}}) {
                   2467:                 if ($type eq 'exact') {
                   2468:                     $exacton = ' checked="checked" ';
                   2469:                 } elsif ($type eq 'contains') {
                   2470:                     $containson = ' checked="checked" ';
                   2471:                 } elsif ($type eq 'begins') {
                   2472:                     $beginson = ' checked="checked" ';
                   2473:                 }
                   2474:             }
                   2475:         } else {
                   2476:             if ($settings->{'searchtypes'} eq 'exact') {
                   2477:                 $exacton = ' checked="checked" ';
                   2478:             } elsif ($settings->{'searchtypes'} eq 'contains') {
                   2479:                 $containson = ' checked="checked" ';
                   2480:             } elsif ($settings->{'searchtypes'} eq 'specify') {
                   2481:                 $exacton = ' checked="checked" ';
                   2482:                 $containson = ' checked="checked" ';
                   2483:             }
1.23      raeburn  2484:         }
                   2485:     }
                   2486:     my ($searchtitles,$titleorder) = &sorted_searchtitles();
1.45      raeburn  2487:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23      raeburn  2488: 
                   2489:     my $numinrow = 4;
1.26      raeburn  2490:     my $cansrchrow = 0;
1.23      raeburn  2491:     my $datatable='<tr class="LC_odd_row">'.
1.30      raeburn  2492:                   '<td colspan="2"><span class ="LC_nobreak">'.&mt('Directory search available?').'</span></td>'.
1.23      raeburn  2493:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   2494:                   '<input type="radio" name="dirsrch_available"'.
                   2495:                   $srchon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   2496:                   '<label><input type="radio" name="dirsrch_available"'.
                   2497:                   $srchoff.' value="0" />'.&mt('No').'</label></span></td>'.
                   2498:                   '</tr><tr>'.
1.30      raeburn  2499:                   '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search?').'</span></td>'.
1.24      raeburn  2500:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   2501:                   '<input type="radio" name="dirsrch_localonly"'.
                   2502:                   $localoff.' value="0" />'.&mt('Yes').'</label>&nbsp;'.
                   2503:                   '<label><input type="radio" name="dirsrch_localonly"'.
                   2504:                   $localon.' value="1" />'.&mt('No').'</label></span></td>'.
1.25      raeburn  2505:                   '</tr>';
1.30      raeburn  2506:     $$rowtotal += 2;
1.26      raeburn  2507:     if (ref($usertypes) eq 'HASH') {
                   2508:         if (keys(%{$usertypes}) > 0) {
1.93      raeburn  2509:             $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
                   2510:                                          $numinrow,$othertitle,'cansearch');
1.26      raeburn  2511:             $cansrchrow = 1;
                   2512:         }
                   2513:     }
                   2514:     if ($cansrchrow) {
1.30      raeburn  2515:         $$rowtotal ++;
1.26      raeburn  2516:         $datatable .= '<tr>';
                   2517:     } else {
                   2518:         $datatable .= '<tr class="LC_odd_row">';
                   2519:     }
1.30      raeburn  2520:     $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
                   2521:                   '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
1.25      raeburn  2522:     foreach my $title (@{$titleorder}) {
                   2523:         if (defined($searchtitles->{$title})) {
                   2524:             my $check = ' ';
1.93      raeburn  2525:             if (ref($settings) eq 'HASH') {
1.39      raeburn  2526:                 if (ref($settings->{'searchby'}) eq 'ARRAY') {
                   2527:                     if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
                   2528:                         $check = ' checked="checked" ';
                   2529:                     }
1.25      raeburn  2530:                 }
                   2531:             }
                   2532:             $datatable .= '<td class="LC_left_item">'.
                   2533:                           '<span class="LC_nobreak"><label>'.
                   2534:                           '<input type="checkbox" name="searchby" '.
                   2535:                           'value="'.$title.'"'.$check.'/>'.
                   2536:                           $searchtitles->{$title}.'</label></span></td>';
                   2537:         }
                   2538:     }
1.26      raeburn  2539:     $datatable .= '</tr></table></td></tr>';
1.30      raeburn  2540:     $$rowtotal ++;
1.26      raeburn  2541:     if ($cansrchrow) {
                   2542:         $datatable .= '<tr class="LC_odd_row">';
                   2543:     } else {
                   2544:         $datatable .= '<tr>';
                   2545:     }
1.30      raeburn  2546:     $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.   
1.26      raeburn  2547:                   '<td class="LC_left_item" colspan="2">'.
1.25      raeburn  2548:                   '<span class="LC_nobreak"><label>'.
                   2549:                   '<input type="checkbox" name="searchtypes" '.
                   2550:                   $exacton.' value="exact" />'.&mt('Exact match').
                   2551:                   '</label>&nbsp;'.
                   2552:                   '<label><input type="checkbox" name="searchtypes" '.
                   2553:                   $beginson.' value="begins" />'.&mt('Begins with').
                   2554:                   '</label>&nbsp;'.
                   2555:                   '<label><input type="checkbox" name="searchtypes" '.
                   2556:                   $containson.' value="contains" />'.&mt('Contains').
                   2557:                   '</label></span></td></tr>';
1.30      raeburn  2558:     $$rowtotal ++;
1.25      raeburn  2559:     return $datatable;
                   2560: }
                   2561: 
1.28      raeburn  2562: sub print_contacts {
1.30      raeburn  2563:     my ($dom,$settings,$rowtotal) = @_;
1.28      raeburn  2564:     my $datatable;
                   2565:     my @contacts = ('adminemail','supportemail');
1.134     raeburn  2566:     my (%checked,%to,%otheremails,%bccemails);
1.102     raeburn  2567:     my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail',
1.203     raeburn  2568:                     'requestsmail','updatesmail','idconflictsmail');
1.28      raeburn  2569:     foreach my $type (@mailings) {
                   2570:         $otheremails{$type} = '';
                   2571:     }
1.134     raeburn  2572:     $bccemails{'helpdeskmail'} = '';
1.28      raeburn  2573:     if (ref($settings) eq 'HASH') {
                   2574:         foreach my $item (@contacts) {
                   2575:             if (exists($settings->{$item})) {
                   2576:                 $to{$item} = $settings->{$item};
                   2577:             }
                   2578:         }
                   2579:         foreach my $type (@mailings) {
                   2580:             if (exists($settings->{$type})) {
                   2581:                 if (ref($settings->{$type}) eq 'HASH') {
                   2582:                     foreach my $item (@contacts) {
                   2583:                         if ($settings->{$type}{$item}) {
                   2584:                             $checked{$type}{$item} = ' checked="checked" ';
                   2585:                         }
                   2586:                     }
                   2587:                     $otheremails{$type} = $settings->{$type}{'others'};
1.134     raeburn  2588:                     if ($type eq 'helpdeskmail') {
                   2589:                         $bccemails{$type} = $settings->{$type}{'bcc'};
                   2590:                     }
1.28      raeburn  2591:                 }
1.89      raeburn  2592:             } elsif ($type eq 'lonstatusmail') {
                   2593:                 $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.28      raeburn  2594:             }
                   2595:         }
                   2596:     } else {
                   2597:         $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
                   2598:         $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
                   2599:         $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
                   2600:         $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.89      raeburn  2601:         $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
                   2602:         $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" '; 
1.102     raeburn  2603:         $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
1.190     raeburn  2604:         $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
1.203     raeburn  2605:         $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.28      raeburn  2606:     }
                   2607:     my ($titles,$short_titles) = &contact_titles();
                   2608:     my $rownum = 0;
                   2609:     my $css_class;
                   2610:     foreach my $item (@contacts) {
1.69      raeburn  2611:         $css_class = $rownum%2?' class="LC_odd_row"':'';
1.30      raeburn  2612:         $datatable .= '<tr'.$css_class.'>'. 
                   2613:                   '<td><span class="LC_nobreak">'.$titles->{$item}.
                   2614:                   '</span></td><td class="LC_right_item">'.
1.28      raeburn  2615:                   '<input type="text" name="'.$item.'" value="'.
                   2616:                   $to{$item}.'" /></td></tr>';
1.203     raeburn  2617:         $rownum ++;
1.28      raeburn  2618:     }
                   2619:     foreach my $type (@mailings) {
1.69      raeburn  2620:         $css_class = $rownum%2?' class="LC_odd_row"':'';
1.28      raeburn  2621:         $datatable .= '<tr'.$css_class.'>'.
1.30      raeburn  2622:                       '<td><span class="LC_nobreak">'.
                   2623:                       $titles->{$type}.': </span></td>'.
1.28      raeburn  2624:                       '<td class="LC_left_item">'.
                   2625:                       '<span class="LC_nobreak">';
                   2626:         foreach my $item (@contacts) {
                   2627:             $datatable .= '<label>'.
                   2628:                           '<input type="checkbox" name="'.$type.'"'.
                   2629:                           $checked{$type}{$item}.
                   2630:                           ' value="'.$item.'" />'.$short_titles->{$item}.
                   2631:                           '</label>&nbsp;';
                   2632:         }
                   2633:         $datatable .= '</span><br />'.&mt('Others').':&nbsp;&nbsp;'.
                   2634:                       '<input type="text" name="'.$type.'_others" '.
1.134     raeburn  2635:                       'value="'.$otheremails{$type}.'"  />';
                   2636:         if ($type eq 'helpdeskmail') {
1.136     raeburn  2637:             $datatable .= '<br />'.&mt('Bcc:').('&nbsp;'x6).
1.134     raeburn  2638:                           '<input type="text" name="'.$type.'_bcc" '.
                   2639:                           'value="'.$bccemails{$type}.'"  />';
                   2640:         }
                   2641:         $datatable .= '</td></tr>'."\n";
1.203     raeburn  2642:         $rownum ++;
1.28      raeburn  2643:     }
1.203     raeburn  2644:     my %choices;
                   2645:     $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',
                   2646:                                    &Apache::loncommon::modal_link('http://loncapa.org/core.html',
                   2647:                                    &mt('LON-CAPA core group - MSU'),600,500));
                   2648:     $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
                   2649:                                     &Apache::loncommon::modal_link('http://loncapa.org/core.html',
                   2650:                                     &mt('LON-CAPA core group - MSU'),600,500));
                   2651:     my @toggles = ('reporterrors','reportupdates');
                   2652:     my %defaultchecked = ('reporterrors'  => 'on',
                   2653:                           'reportupdates' => 'on');
                   2654:     (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
                   2655:                                                \%choices,$rownum);
                   2656:     $datatable .= $reports;
1.30      raeburn  2657:     $$rowtotal += $rownum;
1.28      raeburn  2658:     return $datatable;
                   2659: }
                   2660: 
1.118     jms      2661: sub print_helpsettings {
1.168     raeburn  2662:     my ($dom,$confname,$settings,$rowtotal) = @_;
                   2663:     my ($datatable,$itemcount);
1.166     raeburn  2664:     $itemcount = 1;
1.168     raeburn  2665:     my (%choices,%defaultchecked,@toggles);
                   2666:     $choices{'submitbugs'} = &mt('Display link to: [_1]?',
                   2667:                                  &Apache::loncommon::modal_link('http://bugs.loncapa.org',
                   2668:                                  &mt('LON-CAPA bug tracker'),600,500));
                   2669:     %defaultchecked = ('submitbugs' => 'on');
                   2670:     @toggles = ('submitbugs',);
1.166     raeburn  2671: 
1.168     raeburn  2672:     ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
                   2673:                                                  \%choices,$itemcount);
1.166     raeburn  2674:     return $datatable;
1.121     raeburn  2675: }
                   2676: 
                   2677: sub radiobutton_prefs {
1.192     raeburn  2678:     my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
                   2679:         $additional) = @_;
1.121     raeburn  2680:     return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
                   2681:                    (ref($choices) eq 'HASH'));
                   2682: 
1.170     raeburn  2683:     my (%checkedon,%checkedoff,$datatable,$css_class);
1.121     raeburn  2684: 
                   2685:     foreach my $item (@{$toggles}) {
                   2686:         if ($defaultchecked->{$item} eq 'on') {
1.118     jms      2687:             $checkedon{$item} = ' checked="checked" ';
                   2688:             $checkedoff{$item} = ' ';
1.121     raeburn  2689:         } elsif ($defaultchecked->{$item} eq 'off') {
1.118     jms      2690:             $checkedoff{$item} = ' checked="checked" ';
                   2691:             $checkedon{$item} = ' ';
                   2692:         }
                   2693:     }
                   2694:     if (ref($settings) eq 'HASH') {
1.121     raeburn  2695:         foreach my $item (@{$toggles}) {
1.118     jms      2696:             if ($settings->{$item} eq '1') {
                   2697:                 $checkedon{$item} =  ' checked="checked" ';
                   2698:                 $checkedoff{$item} = ' ';
                   2699:             } elsif ($settings->{$item} eq '0') {
                   2700:                 $checkedoff{$item} =  ' checked="checked" ';
                   2701:                 $checkedon{$item} = ' ';
                   2702:             }
                   2703:         }
1.121     raeburn  2704:     }
1.192     raeburn  2705:     if ($onclick) {
                   2706:         $onclick = ' onclick="'.$onclick.'"';
                   2707:     }
1.121     raeburn  2708:     foreach my $item (@{$toggles}) {
1.118     jms      2709:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121     raeburn  2710:         $datatable .=
1.192     raeburn  2711:             '<tr'.$css_class.'><td valign="top">'.
                   2712:             '<span class="LC_nobreak">'.$choices->{$item}.
1.118     jms      2713:             '</span></td>'.
                   2714:             '<td class="LC_right_item"><span class="LC_nobreak">'.
                   2715:             '<label><input type="radio" name="'.
1.192     raeburn  2716:             $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118     jms      2717:             '</label>&nbsp;<label><input type="radio" name="'.$item.'" '.
1.192     raeburn  2718:             $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
                   2719:             '</span>'.$additional.
                   2720:             '</td>'.
1.118     jms      2721:             '</tr>';
                   2722:         $itemcount ++;
1.121     raeburn  2723:     }
                   2724:     return ($datatable,$itemcount);
                   2725: }
                   2726: 
                   2727: sub print_coursedefaults {
1.139     raeburn  2728:     my ($position,$dom,$settings,$rowtotal) = @_;
1.192     raeburn  2729:     my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121     raeburn  2730:     my $itemcount = 1;
1.192     raeburn  2731:     my %choices =  &Apache::lonlocal::texthash (
                   2732:         canuse_pdfforms      => 'Course/Community users can create/upload PDF forms',
1.198     raeburn  2733:         uploadquota          => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.192     raeburn  2734:         anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
                   2735:         coursecredits        => 'Credits can be specified for courses',
                   2736:     );
1.198     raeburn  2737:     my %staticdefaults = (
                   2738:                            anonsurvey_threshold => 10,
                   2739:                            uploadquota          => 500,
                   2740:                          );
1.139     raeburn  2741:     if ($position eq 'top') {
                   2742:         %defaultchecked = ('canuse_pdfforms' => 'off');
1.192     raeburn  2743:         @toggles = ('canuse_pdfforms');
1.139     raeburn  2744:         ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.121     raeburn  2745:                                                  \%choices,$itemcount);
1.139     raeburn  2746:     } else {
                   2747:         $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.216     raeburn  2748:         my ($currdefresponder,$def_official_credits,$def_unofficial_credits,$def_textbook_credits,
                   2749:             %curruploadquota);
1.192     raeburn  2750:         my $currusecredits = 0;
1.216     raeburn  2751:         my @types = ('official','unofficial','community','textbook');
1.139     raeburn  2752:         if (ref($settings) eq 'HASH') {
                   2753:             $currdefresponder = $settings->{'anonsurvey_threshold'};
1.198     raeburn  2754:             if (ref($settings->{'uploadquota'}) eq 'HASH') {
                   2755:                 foreach my $type (keys(%{$settings->{'uploadquota'}})) {
                   2756:                     $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
                   2757:                 }
                   2758:             }
1.192     raeburn  2759:             if (ref($settings->{'coursecredits'}) eq 'HASH') {
                   2760:                 $def_official_credits = $settings->{'coursecredits'}->{'official'};
                   2761:                 $def_unofficial_credits = $settings->{'coursecredits'}->{'unofficial'};
1.216     raeburn  2762:                 $def_textbook_credits = $settings->{'coursecredits'}->{'textbook'};
                   2763:                 if (($def_official_credits ne '') || ($def_unofficial_credits ne '') ||
                   2764:                     ($def_textbook_credits ne '')) {
1.192     raeburn  2765:                     $currusecredits = 1;
                   2766:                 }
                   2767:             }
1.139     raeburn  2768:         }
                   2769:         if (!$currdefresponder) {
1.198     raeburn  2770:             $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139     raeburn  2771:         } elsif ($currdefresponder < 1) {
                   2772:             $currdefresponder = 1;
                   2773:         }
1.198     raeburn  2774:         foreach my $type (@types) {
                   2775:             if ($curruploadquota{$type} eq '') {
                   2776:                 $curruploadquota{$type} = $staticdefaults{'uploadquota'};
                   2777:             }
                   2778:         }
1.139     raeburn  2779:         $datatable .=
1.192     raeburn  2780:                 '<tr'.$css_class.'><td><span class="LC_nobreak">'.
                   2781:                 $choices{'anonsurvey_threshold'}.
1.139     raeburn  2782:                 '</span></td>'.
                   2783:                 '<td class="LC_right_item"><span class="LC_nobreak">'.
                   2784:                 '<input type="text" name="anonsurvey_threshold"'.
                   2785:                 ' value="'.$currdefresponder.'" size="5" /></span>'.
1.230     raeburn  2786:                 '</td></tr>'."\n";
                   2787:         $itemcount ++;
                   2788:         $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   2789:         $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
                   2790:                       $choices{'uploadquota'}.
                   2791:                       '</span></td>'.
                   2792:                       '<td align="right" class="LC_right_item">'.
                   2793:                       '<table><tr>';
1.198     raeburn  2794:         foreach my $type (@types) {
                   2795:             $datatable .= '<td align="center">'.&mt($type).'<br />'.
                   2796:                            '<input type="text" name="uploadquota_'.$type.'"'.
                   2797:                            ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
                   2798:         }
                   2799:         $datatable .= '</tr></table></td></tr>'."\n";
1.230     raeburn  2800:         $itemcount ++;
1.192     raeburn  2801:         my $onclick = 'toggleCredits(this.form);';
1.210     raeburn  2802:         my $display = 'none';
1.192     raeburn  2803:         if ($currusecredits) {
                   2804:             $display = 'block';
                   2805:         }
                   2806:         my $additional = '<div id="credits" style="display: '.$display.'">'.
                   2807:                          '<span class="LC_nobreak">'.
                   2808:                          &mt('Default credits for official courses [_1]',
                   2809:                          '<input type="text" name="official_credits" value="'.
                   2810:                          $def_official_credits.'" size="3" />').
                   2811:                          '</span><br />'.
                   2812:                          '<span class="LC_nobreak">'.
                   2813:                          &mt('Default credits for unofficial courses [_1]',
                   2814:                          '<input type="text" name="unofficial_credits" value="'.
                   2815:                          $def_unofficial_credits.'" size="3" />').
1.216     raeburn  2816:                          '</span><br />'.
                   2817:                          '<span class="LC_nobreak">'.
                   2818:                          &mt('Default credits for textbook courses [_1]',
                   2819:                          '<input type="text" name="textbook_credits" value="'.
                   2820:                          $def_textbook_credits.'" size="3" />').
1.192     raeburn  2821:                          '</span></div>'."\n";
                   2822:         %defaultchecked = ('coursecredits' => 'off');
                   2823:         @toggles = ('coursecredits');
                   2824:         my $current = {
                   2825:                         'coursecredits' => $currusecredits,
                   2826:                       };
                   2827:         (my $table,$itemcount) =
                   2828:             &radiobutton_prefs($current,\@toggles,\%defaultchecked,
                   2829:                                \%choices,$itemcount,$onclick,$additional);
                   2830:         $datatable .= $table;
1.230     raeburn  2831:         $itemcount ++;
1.139     raeburn  2832:     }
1.192     raeburn  2833:     $$rowtotal += $itemcount;
1.121     raeburn  2834:     return $datatable;
1.118     jms      2835: }
                   2836: 
1.231     raeburn  2837: sub print_selfenrollment {
                   2838:     my ($position,$dom,$settings,$rowtotal) = @_;
                   2839:     my ($css_class,$datatable);
                   2840:     my $itemcount = 1;
                   2841:     my @types = ('official','unofficial','community','textbook');
                   2842:     if (($position eq 'top') || ($position eq 'middle')) {
1.232     raeburn  2843:         my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
                   2844:         my %descs = &Apache::lonuserutils::selfenroll_default_descs();
1.231     raeburn  2845:         my @rows;
                   2846:         my $key;
                   2847:         if ($position eq 'top') {
                   2848:             $key = 'admin'; 
                   2849:             if (ref($rowsref) eq 'ARRAY') {
                   2850:                 @rows = @{$rowsref};
                   2851:             }
                   2852:         } elsif ($position eq 'middle') {
                   2853:             $key = 'default';
                   2854:             @rows = ('types','registered','approval','limit');
                   2855:         }
                   2856:         foreach my $row (@rows) {
                   2857:             if (defined($titlesref->{$row})) {
                   2858:                 $itemcount ++;
                   2859:                 $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   2860:                 $datatable .= '<tr'.$css_class.'>'.
                   2861:                               '<td>'.$titlesref->{$row}.'</td>'.
                   2862:                               '<td class="LC_left_item">'.
                   2863:                               '<table><tr>';
                   2864:                 my (%current,%currentcap);
                   2865:                 if (ref($settings) eq 'HASH') {
                   2866:                     if (ref($settings->{$key}) eq 'HASH') {
                   2867:                         foreach my $type (@types) {
                   2868:                             if (ref($settings->{$key}->{$type}) eq 'HASH') {
                   2869:                                 $current{$type} = $settings->{$key}->{$type}->{$row};
                   2870:                             }
                   2871:                             if (($row eq 'limit') && ($key eq 'default')) {
                   2872:                                 if (ref($settings->{$key}->{$type}) eq 'HASH') {
                   2873:                                     $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
                   2874:                                 }
                   2875:                             }
                   2876:                         }
                   2877:                     }
                   2878:                 }
                   2879:                 my %roles = (
                   2880:                              '0' => &Apache::lonnet::plaintext('dc'),
                   2881:                             ); 
                   2882:             
                   2883:                 foreach my $type (@types) {
                   2884:                     unless (($row eq 'registered') && ($key eq 'default')) {
                   2885:                         $datatable .= '<th>'.&mt($type).'</th>';
                   2886:                     }
                   2887:                 }
                   2888:                 unless (($row eq 'registered') && ($key eq 'default')) {
                   2889:                     $datatable .= '</tr><tr>';
                   2890:                 }
                   2891:                 foreach my $type (@types) {
                   2892:                     if ($type eq 'community') {
                   2893:                         $roles{'1'} = &mt('Community personnel');
                   2894:                     } else {
                   2895:                         $roles{'1'} = &mt('Course personnel');
                   2896:                     }
                   2897:                     $datatable .= '<td style="vertical-align: top">';
                   2898:                     if ($position eq 'top') {
                   2899:                         my %checked;
                   2900:                         if ($current{$type} eq '0') {
                   2901:                             $checked{'0'} = ' checked="checked"';
                   2902:                         } else {
                   2903:                             $checked{'1'} = ' checked="checked"';
                   2904:                         }
                   2905:                         foreach my $role ('1','0') {
                   2906:                             $datatable .= '<span class="LC_nobreak"><label>'.
                   2907:                                           '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
                   2908:                                           'value="'.$role.'"'.$checked{$role}.' />'.
                   2909:                                           $roles{$role}.'</label></span> ';
                   2910:                         }
                   2911:                     } else {
                   2912:                         if ($row eq 'types') {
                   2913:                             my %checked;
                   2914:                             if ($current{$type} =~ /^(all|dom)$/) {
                   2915:                                 $checked{$1} = ' checked="checked"';
                   2916:                             } else {
                   2917:                                 $checked{''} = ' checked="checked"';
                   2918:                             }
                   2919:                             foreach my $val ('','dom','all') {
                   2920:                                 $datatable .= '<span class="LC_nobreak"><label>'.
                   2921:                                               '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
                   2922:                                               'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
                   2923:                             }
                   2924:                         } elsif ($row eq 'registered') {
                   2925:                             my %checked;
                   2926:                             if ($current{$type} eq '1') {
                   2927:                                 $checked{'1'} = ' checked="checked"';
                   2928:                             } else {
                   2929:                                 $checked{'0'} = ' checked="checked"';
                   2930:                             }
                   2931:                             foreach my $val ('0','1') {
                   2932:                                 $datatable .= '<span class="LC_nobreak"><label>'.
                   2933:                                               '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
                   2934:                                               'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
                   2935:                             }
                   2936:                         } elsif ($row eq 'approval') {
                   2937:                             my %checked;
                   2938:                             if ($current{$type} =~ /^([12])$/) {
                   2939:                                 $checked{$1} = ' checked="checked"';
                   2940:                             } else {
                   2941:                                 $checked{'0'} = ' checked="checked"';
                   2942:                             }
                   2943:                             for my $val (0..2) {
                   2944:                                 $datatable .= '<span class="LC_nobreak"><label>'.
                   2945:                                               '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
                   2946:                                               'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
                   2947:                             }
                   2948:                         } elsif ($row eq 'limit') {
                   2949:                             my %checked;
                   2950:                             if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
                   2951:                                 $checked{$1} = ' checked="checked"';
                   2952:                             } else {
                   2953:                                 $checked{'none'} = ' checked="checked"';
                   2954:                             }
                   2955:                             my $cap;
                   2956:                             if ($currentcap{$type} =~ /^\d+$/) {
                   2957:                                 $cap = $currentcap{$type};
                   2958:                             }
                   2959:                             foreach my $val ('none','allstudents','selfenrolled') {
                   2960:                                 $datatable .= '<span class="LC_nobreak"><label>'.
                   2961:                                               '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
                   2962:                                               'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
                   2963:                             }
                   2964:                             $datatable .= '<br />'.
                   2965:                                           '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
                   2966:                                           '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
                   2967:                                           '</span>'; 
                   2968:                         }
                   2969:                     }
                   2970:                     $datatable .= '</td>';
                   2971:                 }
                   2972:                 $datatable .= '</tr>';
                   2973:             }
                   2974:             $datatable .= '</table></td></tr>';
                   2975:         }
                   2976:     } elsif ($position eq 'bottom') {
1.233     raeburn  2977:         my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
1.231     raeburn  2978:         my %currvalidation;
                   2979:         if (ref($settings) eq 'HASH') {
                   2980:             if (ref($settings->{'validation'}) eq 'HASH') {
                   2981:                 %currvalidation = %{$settings->{'validation'}}; 
                   2982:             }
                   2983:         }
                   2984:         foreach my $item (@{$itemsref}) {
                   2985:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   2986:             $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
                   2987:                           $namesref->{$item}.
                   2988:                           '</span></td>'.
                   2989:                           '<td class="LC_left_item">';
                   2990:             if (($item eq 'url') || ($item eq 'button')) {
                   2991:                 $datatable .= '<span class="LC_nobreak">'.
                   2992:                               '<input type="text" name="selfenroll_validation_'.$item.'"'.
                   2993:                               ' value="'.$currvalidation{$item}.'" size="50" /></span>';
                   2994:             } elsif ($item eq 'fields') {
                   2995:                 my @currfields;
                   2996:                 if (ref($currvalidation{$item}) eq 'ARRAY') {
                   2997:                     @currfields = @{$currvalidation{$item}};
                   2998:                 }
                   2999:                 foreach my $field (@{$fieldsref}) {
                   3000:                     my $check = '';
                   3001:                     if (grep(/^\Q$field\E$/,@currfields)) {
                   3002:                         $check = ' checked="checked"';
                   3003:                     }
                   3004:                     $datatable .= '<span class="LC_nobreak"><label>'.
                   3005:                                   '<input type="checkbox" name="selfenroll_validation_fields"'.
                   3006:                                   ' value="'.$field.'"'.$check.' />'.$field.
                   3007:                                   '</label></span> ';
                   3008:                 }
                   3009:             } elsif ($item eq 'markup') {
                   3010:                 $datatable .= '<textarea name="selfenroll_validation_markup" cols="50" rows="5" wrap="soft">'.
                   3011:                               $currvalidation{$item}. 
                   3012:                               '</textarea>';
                   3013:             }
                   3014:             $datatable .= '</td></tr>'."\n";
                   3015:             $itemcount ++;
                   3016:         }
                   3017:     }
                   3018:     $$rowtotal += $itemcount;
                   3019:     return $datatable;
                   3020: }
                   3021: 
1.137     raeburn  3022: sub print_usersessions {
                   3023:     my ($position,$dom,$settings,$rowtotal) = @_;
                   3024:     my ($css_class,$datatable,%checked,%choices);
1.140     raeburn  3025:     my (%by_ip,%by_location,@intdoms);
                   3026:     &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145     raeburn  3027: 
                   3028:     my @alldoms = &Apache::lonnet::all_domains();
1.152     raeburn  3029:     my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149     raeburn  3030:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152     raeburn  3031:     my %altids = &id_for_thisdom(%servers);
1.145     raeburn  3032:     my $itemcount = 1;
                   3033:     if ($position eq 'top') {
1.152     raeburn  3034:         if (keys(%serverhomes) > 1) {
1.145     raeburn  3035:             my %spareid = &current_offloads_to($dom,$settings,\%servers);
1.152     raeburn  3036:             $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$rowtotal);
1.145     raeburn  3037:         } else {
1.140     raeburn  3038:             $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150     raeburn  3039:                           &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140     raeburn  3040:         }
1.137     raeburn  3041:     } else {
1.145     raeburn  3042:         if (keys(%by_location) == 0) {
                   3043:             $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150     raeburn  3044:                           &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145     raeburn  3045:         } else {
                   3046:             my %lt = &usersession_titles();
                   3047:             my $numinrow = 5;
                   3048:             my $prefix;
                   3049:             my @types;
                   3050:             if ($position eq 'bottom') {
                   3051:                 $prefix = 'remote';
                   3052:                 @types = ('version','excludedomain','includedomain');
                   3053:             } else {
                   3054:                 $prefix = 'hosted';
                   3055:                 @types = ('excludedomain','includedomain');
                   3056:             }
                   3057:             my (%current,%checkedon,%checkedoff);
                   3058:             my @lcversions = &Apache::lonnet::all_loncaparevs();
                   3059:             my @locations = sort(keys(%by_location));
                   3060:             foreach my $type (@types) {
                   3061:                 $checkedon{$type} = '';
                   3062:                 $checkedoff{$type} = ' checked="checked"';
                   3063:             }
                   3064:             if (ref($settings) eq 'HASH') {
                   3065:                 if (ref($settings->{$prefix}) eq 'HASH') {
                   3066:                     foreach my $key (keys(%{$settings->{$prefix}})) {
                   3067:                         $current{$key} = $settings->{$prefix}{$key};
                   3068:                         if ($key eq 'version') {
                   3069:                             if ($current{$key} ne '') {
                   3070:                                 $checkedon{$key} = ' checked="checked"';
                   3071:                                 $checkedoff{$key} = '';
                   3072:                             }
                   3073:                         } elsif (ref($current{$key}) eq 'ARRAY') {
                   3074:                             $checkedon{$key} = ' checked="checked"';
                   3075:                             $checkedoff{$key} = '';
                   3076:                         }
1.137     raeburn  3077:                     }
                   3078:                 }
                   3079:             }
1.145     raeburn  3080:             foreach my $type (@types) {
                   3081:                 next if ($type ne 'version' && !@locations);
                   3082:                 $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   3083:                 $datatable .= '<tr'.$css_class.'>
                   3084:                                <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
                   3085:                                <span class="LC_nobreak">&nbsp;
                   3086:                                <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>&nbsp;
                   3087:                                <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
                   3088:                 if ($type eq 'version') {
                   3089:                     my $selector = '<select name="'.$prefix.'_version">';
                   3090:                     foreach my $version (@lcversions) {
                   3091:                         my $selected = '';
                   3092:                         if ($current{'version'} eq $version) {
                   3093:                             $selected = ' selected="selected"';
                   3094:                         }
                   3095:                         $selector .= ' <option value="'.$version.'"'.
                   3096:                                      $selected.'>'.$version.'</option>';
                   3097:                     }
                   3098:                     $selector .= '</select> ';
                   3099:                     $datatable .= &mt('remote server must be version: [_1] or later',$selector);
                   3100:                 } else {
                   3101:                     $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
                   3102:                                  'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
                   3103:                                  ' />'.('&nbsp;'x2).
                   3104:                                  '<input type="button" value="'.&mt('uncheck all').'" '.
                   3105:                                  'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
                   3106:                                  "\n".
                   3107:                                  '</div><div><table>';
                   3108:                     my $rem;
                   3109:                     for (my $i=0; $i<@locations; $i++) {
                   3110:                         my ($showloc,$value,$checkedtype);
                   3111:                         if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
                   3112:                             my $ip = $by_location{$locations[$i]}->[0];
                   3113:                             if (ref($by_ip{$ip}) eq 'ARRAY') {
                   3114:                                  $value = join(':',@{$by_ip{$ip}});
                   3115:                                 $showloc = join(', ',@{$by_ip{$ip}});
                   3116:                                 if (ref($current{$type}) eq 'ARRAY') {
                   3117:                                     foreach my $loc (@{$by_ip{$ip}}) {  
                   3118:                                         if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
                   3119:                                             $checkedtype = ' checked="checked"';
                   3120:                                             last;
                   3121:                                         }
                   3122:                                     }
1.138     raeburn  3123:                                 }
                   3124:                             }
                   3125:                         }
1.145     raeburn  3126:                         $rem = $i%($numinrow);
                   3127:                         if ($rem == 0) {
                   3128:                             if ($i > 0) {
                   3129:                                 $datatable .= '</tr>';
                   3130:                             }
                   3131:                             $datatable .= '<tr>';
                   3132:                         }
                   3133:                         $datatable .= '<td class="LC_left_item">'.
                   3134:                                       '<span class="LC_nobreak"><label>'.
                   3135:                                       '<input type="checkbox" name="'.$prefix.'_'.$type.
                   3136:                                       '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
                   3137:                                       '</label></span></td>';
1.137     raeburn  3138:                     }
1.145     raeburn  3139:                     $rem = @locations%($numinrow);
                   3140:                     my $colsleft = $numinrow - $rem;
                   3141:                     if ($colsleft > 1 ) {
                   3142:                         $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   3143:                                       '&nbsp;</td>';
                   3144:                     } elsif ($colsleft == 1) {
                   3145:                         $datatable .= '<td class="LC_left_item">&nbsp;</td>';
1.137     raeburn  3146:                     }
1.145     raeburn  3147:                     $datatable .= '</tr></table>';
1.137     raeburn  3148:                 }
1.145     raeburn  3149:                 $datatable .= '</td></tr>';
                   3150:                 $itemcount ++;
1.137     raeburn  3151:             }
                   3152:         }
                   3153:     }
                   3154:     $$rowtotal += $itemcount;
                   3155:     return $datatable;
                   3156: }
                   3157: 
1.138     raeburn  3158: sub build_location_hashes {
                   3159:     my ($intdoms,$by_ip,$by_location) = @_;
                   3160:     return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
                   3161:                   (ref($by_location) eq 'HASH')); 
                   3162:     my %iphost = &Apache::lonnet::get_iphost();
                   3163:     my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
                   3164:     my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
                   3165:     if (ref($iphost{$primary_ip}) eq 'ARRAY') {
                   3166:         foreach my $id (@{$iphost{$primary_ip}}) {
                   3167:             my $intdom = &Apache::lonnet::internet_dom($id);
                   3168:             unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
                   3169:                 push(@{$intdoms},$intdom);
                   3170:             }
                   3171:         }
                   3172:     }
                   3173:     foreach my $ip (keys(%iphost)) {
                   3174:         if (ref($iphost{$ip}) eq 'ARRAY') {
                   3175:             foreach my $id (@{$iphost{$ip}}) {
                   3176:                 my $location = &Apache::lonnet::internet_dom($id);
                   3177:                 if ($location) {
                   3178:                     next if (grep(/^\Q$location\E$/,@{$intdoms}));
                   3179:                     if (ref($by_ip->{$ip}) eq 'ARRAY') {
                   3180:                         unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
                   3181:                             push(@{$by_ip->{$ip}},$location);
                   3182:                         }
                   3183:                     } else {
                   3184:                         $by_ip->{$ip} = [$location];
                   3185:                     }
                   3186:                 }
                   3187:             }
                   3188:         }
                   3189:     }
                   3190:     foreach my $ip (sort(keys(%{$by_ip}))) {
                   3191:         if (ref($by_ip->{$ip}) eq 'ARRAY') {
                   3192:             @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
                   3193:             my $first = $by_ip->{$ip}->[0];
                   3194:             if (ref($by_location->{$first}) eq 'ARRAY') {
                   3195:                 unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
                   3196:                     push(@{$by_location->{$first}},$ip);
                   3197:                 }
                   3198:             } else {
                   3199:                 $by_location->{$first} = [$ip];
                   3200:             }
                   3201:         }
                   3202:     }
                   3203:     return;
                   3204: }
                   3205: 
1.145     raeburn  3206: sub current_offloads_to {
                   3207:     my ($dom,$settings,$servers) = @_;
                   3208:     my (%spareid,%otherdomconfigs);
1.152     raeburn  3209:     if (ref($servers) eq 'HASH') {
1.145     raeburn  3210:         foreach my $lonhost (sort(keys(%{$servers}))) {
                   3211:             my $gotspares;
1.152     raeburn  3212:             if (ref($settings) eq 'HASH') {
                   3213:                 if (ref($settings->{'spares'}) eq 'HASH') {
                   3214:                     if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
                   3215:                         $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
                   3216:                         $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
                   3217:                         $gotspares = 1;
                   3218:                     }
1.145     raeburn  3219:                 }
                   3220:             }
                   3221:             unless ($gotspares) {
                   3222:                 my $gotspares;
                   3223:                 my $serverhomeID =
                   3224:                     &Apache::lonnet::get_server_homeID($servers->{$lonhost});
                   3225:                 my $serverhomedom =
                   3226:                     &Apache::lonnet::host_domain($serverhomeID);
                   3227:                 if ($serverhomedom ne $dom) {
                   3228:                     if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
                   3229:                         if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
                   3230:                             if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
                   3231:                                 $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
                   3232:                                 $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
                   3233:                                 $gotspares = 1;
                   3234:                             }
                   3235:                         }
                   3236:                     } else {
                   3237:                         $otherdomconfigs{$serverhomedom} =
                   3238:                             &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
                   3239:                         if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
                   3240:                             if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
                   3241:                                 if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
                   3242:                                     if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
                   3243:                                         $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
                   3244:                                         $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
                   3245:                                         $gotspares = 1;
                   3246:                                     }
                   3247:                                 }
                   3248:                             }
                   3249:                         }
                   3250:                     }
                   3251:                 }
                   3252:             }
                   3253:             unless ($gotspares) {
                   3254:                 if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
                   3255:                     $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
                   3256:                     $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
                   3257:                } else {
                   3258:                     my $server_hostname = &Apache::lonnet::hostname($lonhost);
                   3259:                     my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
                   3260:                     if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
                   3261:                         $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
                   3262:                         $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
                   3263:                     } else {
1.150     raeburn  3264:                         my %what = (
                   3265:                              spareid => 1,
                   3266:                         );
                   3267:                         my ($result,$returnhash) = 
                   3268:                             &Apache::lonnet::get_remote_globals($lonhost,\%what);
                   3269:                         if ($result eq 'ok') { 
                   3270:                             if (ref($returnhash) eq 'HASH') {
                   3271:                                 if (ref($returnhash->{'spareid'}) eq 'HASH') {
                   3272:                                     $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
                   3273:                                     $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
                   3274:                                 }
                   3275:                             }
1.145     raeburn  3276:                         }
                   3277:                     }
                   3278:                 }
                   3279:             }
                   3280:         }
                   3281:     }
                   3282:     return %spareid;
                   3283: }
                   3284: 
                   3285: sub spares_row {
1.152     raeburn  3286:     my ($dom,$servers,$spareid,$serverhomes,$altids,$rowtotal) = @_;
1.145     raeburn  3287:     my $css_class;
                   3288:     my $numinrow = 4;
                   3289:     my $itemcount = 1;
                   3290:     my $datatable;
1.152     raeburn  3291:     my %typetitles = &sparestype_titles();
                   3292:     if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145     raeburn  3293:         foreach my $server (sort(keys(%{$servers}))) {
1.152     raeburn  3294:             my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
                   3295:             my ($othercontrol,$serverdom);
                   3296:             if ($serverhome ne $server) {
                   3297:                 $serverdom = &Apache::lonnet::host_domain($serverhome);
                   3298:                 $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
                   3299:             } else {
                   3300:                 $serverdom = &Apache::lonnet::host_domain($server);
                   3301:                 if ($serverdom ne $dom) {
                   3302:                     $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
                   3303:                 }
                   3304:             }
                   3305:             next unless (ref($spareid->{$server}) eq 'HASH');
1.145     raeburn  3306:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   3307:             $datatable .= '<tr'.$css_class.'>
                   3308:                            <td rowspan="2">
1.183     bisitz   3309:                             <span class="LC_nobreak">'.
                   3310:                           &mt('[_1] when busy, offloads to:'
                   3311:                               ,'<b>'.$server.'</b>').
                   3312:                           "\n";
1.145     raeburn  3313:             my (%current,%canselect);
1.152     raeburn  3314:             my @choices = 
                   3315:                 &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
                   3316:             foreach my $type ('primary','default') {
                   3317:                 if (ref($spareid->{$server}) eq 'HASH') {
1.145     raeburn  3318:                     if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
                   3319:                         my @spares = @{$spareid->{$server}{$type}};
                   3320:                         if (@spares > 0) {
1.152     raeburn  3321:                             if ($othercontrol) {
                   3322:                                 $current{$type} = join(', ',@spares);
                   3323:                             } else {
                   3324:                                 $current{$type} .= '<table>';
                   3325:                                 my $numspares = scalar(@spares);
                   3326:                                 for (my $i=0;  $i<@spares; $i++) {
                   3327:                                     my $rem = $i%($numinrow);
                   3328:                                     if ($rem == 0) {
                   3329:                                         if ($i > 0) {
                   3330:                                             $current{$type} .= '</tr>';
                   3331:                                         }
                   3332:                                         $current{$type} .= '<tr>';
1.145     raeburn  3333:                                     }
1.152     raeburn  3334:                                     $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;'.
                   3335:                                                        $spareid->{$server}{$type}[$i].
                   3336:                                                        '</label></td>'."\n";
                   3337:                                 }
                   3338:                                 my $rem = @spares%($numinrow);
                   3339:                                 my $colsleft = $numinrow - $rem;
                   3340:                                 if ($colsleft > 1 ) {
                   3341:                                     $current{$type} .= '<td colspan="'.$colsleft.
                   3342:                                                        '" class="LC_left_item">'.
                   3343:                                                        '&nbsp;</td>';
                   3344:                                 } elsif ($colsleft == 1) {
                   3345:                                     $current{$type} .= '<td class="LC_left_item">&nbsp;</td>'."\n";
1.145     raeburn  3346:                                 }
1.152     raeburn  3347:                                 $current{$type} .= '</tr></table>';
1.150     raeburn  3348:                             }
1.145     raeburn  3349:                         }
                   3350:                     }
                   3351:                     if ($current{$type} eq '') {
                   3352:                         $current{$type} = &mt('None specified');
                   3353:                     }
1.152     raeburn  3354:                     if ($othercontrol) {
                   3355:                         if ($type eq 'primary') {
                   3356:                             $canselect{$type} = $othercontrol;
                   3357:                         }
                   3358:                     } else {
                   3359:                         $canselect{$type} = 
                   3360:                             &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').'&nbsp;'.
                   3361:                             '<select name="newspare_'.$type.'_'.$server.'" '.
                   3362:                             'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
                   3363:                             '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
                   3364:                         if (@choices > 0) {
                   3365:                             foreach my $lonhost (@choices) {
                   3366:                                 $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
                   3367:                             }
                   3368:                         }
                   3369:                         $canselect{$type} .= '</select>'."\n";
                   3370:                     }
                   3371:                 } else {
                   3372:                     $current{$type} = &mt('Could not be determined');
                   3373:                     if ($type eq 'primary') {
                   3374:                         $canselect{$type} =  $othercontrol;
                   3375:                     }
1.145     raeburn  3376:                 }
1.152     raeburn  3377:                 if ($type eq 'default') {
                   3378:                     $datatable .= '<tr'.$css_class.'>';
                   3379:                 }
                   3380:                 $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
                   3381:                               '<td>'.$current{$type}.'</td>'."\n".
                   3382:                               '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145     raeburn  3383:             }
                   3384:             $itemcount ++;
                   3385:         }
                   3386:     }
                   3387:     $$rowtotal += $itemcount;
                   3388:     return $datatable;
                   3389: }
                   3390: 
1.152     raeburn  3391: sub possible_newspares {
                   3392:     my ($server,$currspares,$serverhomes,$altids) = @_;
                   3393:     my $serverhostname = &Apache::lonnet::hostname($server);
                   3394:     my %excluded;
                   3395:     if ($serverhostname ne '') {
                   3396:         %excluded = (
                   3397:                        $serverhostname => 1,
                   3398:                     );
                   3399:     }
                   3400:     if (ref($currspares) eq 'HASH') {
                   3401:         foreach my $type (keys(%{$currspares})) {
                   3402:             if (ref($currspares->{$type}) eq 'ARRAY') {
                   3403:                 if (@{$currspares->{$type}} > 0) {
                   3404:                     foreach my $curr (@{$currspares->{$type}}) {
                   3405:                         my $hostname = &Apache::lonnet::hostname($curr);
                   3406:                         $excluded{$hostname} = 1;
                   3407:                     }
                   3408:                 }
                   3409:             }
                   3410:         }
                   3411:     }
                   3412:     my @choices;
                   3413:     if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
                   3414:         if (keys(%{$serverhomes}) > 1) {
                   3415:             foreach my $name (sort(keys(%{$serverhomes}))) {
                   3416:                 unless ($excluded{$name}) {
                   3417:                     if (exists($altids->{$serverhomes->{$name}})) {
                   3418:                         push(@choices,$altids->{$serverhomes->{$name}});
                   3419:                     } else {
                   3420:                         push(@choices,$serverhomes->{$name});
1.145     raeburn  3421:                     }
                   3422:                 }
                   3423:             }
                   3424:         }
                   3425:     }
1.152     raeburn  3426:     return sort(@choices);
1.145     raeburn  3427: }
                   3428: 
1.150     raeburn  3429: sub print_loadbalancing {
                   3430:     my ($dom,$settings,$rowtotal) = @_;
                   3431:     my $primary_id = &Apache::lonnet::domain($dom,'primary');
                   3432:     my $intdom = &Apache::lonnet::internet_dom($primary_id);
                   3433:     my $numinrow = 1;
                   3434:     my $datatable;
                   3435:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.171     raeburn  3436:     my (%currbalancer,%currtargets,%currrules,%existing);
                   3437:     if (ref($settings) eq 'HASH') {
                   3438:         %existing = %{$settings};
                   3439:     }
                   3440:     if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
                   3441:         &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
                   3442:                                   \%currtargets,\%currrules);
1.150     raeburn  3443:     } else {
                   3444:         return;
                   3445:     }
                   3446:     my ($othertitle,$usertypes,$types) =
                   3447:         &Apache::loncommon::sorted_inst_types($dom);
1.209     raeburn  3448:     my $rownum = 8;
1.150     raeburn  3449:     if (ref($types) eq 'ARRAY') {
                   3450:         $rownum += scalar(@{$types});
                   3451:     }
1.171     raeburn  3452:     my @css_class = ('LC_odd_row','LC_even_row');
                   3453:     my $balnum = 0;
                   3454:     my $islast;
                   3455:     my (@toshow,$disabledtext);
                   3456:     if (keys(%currbalancer) > 0) {
                   3457:         @toshow = sort(keys(%currbalancer));
                   3458:         if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
                   3459:             push(@toshow,'');
                   3460:         }
                   3461:     } else {
                   3462:         @toshow = ('');
                   3463:         $disabledtext = &mt('No existing load balancer');
                   3464:     }
                   3465:     foreach my $lonhost (@toshow) {
                   3466:         if ($balnum == scalar(@toshow)-1) {
                   3467:             $islast = 1;
                   3468:         } else {
                   3469:             $islast = 0;
                   3470:         }
                   3471:         my $cssidx = $balnum%2;
                   3472:         my $targets_div_style = 'display: none';
                   3473:         my $disabled_div_style = 'display: block';
                   3474:         my $homedom_div_style = 'display: none';
                   3475:         $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
                   3476:                       '<td rowspan="'.$rownum.'" valign="top">'.
                   3477:                       '<p>';
                   3478:         if ($lonhost eq '') {
1.210     raeburn  3479:             $datatable .= '<span class="LC_nobreak">';
1.171     raeburn  3480:             if (keys(%currbalancer) > 0) {
                   3481:                 $datatable .= &mt('Add balancer:');
                   3482:             } else {
                   3483:                 $datatable .= &mt('Enable balancer:');
                   3484:             }
                   3485:             $datatable .= '&nbsp;'.
                   3486:                           '<select name="loadbalancing_lonhost_'.$balnum.'"'.
                   3487:                           ' id="loadbalancing_lonhost_'.$balnum.'"'.
                   3488:                           ' onchange="toggleTargets('."'$balnum'".');">'."\n".
                   3489:                           '<option value="" selected="selected">'.&mt('None').
                   3490:                           '</option>'."\n";
                   3491:             foreach my $server (sort(keys(%servers))) {
                   3492:                 next if ($currbalancer{$server});
                   3493:                 $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
                   3494:             }
1.210     raeburn  3495:             $datatable .=
1.171     raeburn  3496:                 '</select>'."\n".
                   3497:                 '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" />&nbsp;</span>'."\n";
                   3498:         } else {
                   3499:             $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
                   3500:                           '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" />&nbsp;'.
                   3501:                            &mt('Stop balancing').'</label>'.
                   3502:                            '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
                   3503:             $targets_div_style = 'display: block';
                   3504:             $disabled_div_style = 'display: none';
                   3505:             if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
                   3506:                 $homedom_div_style = 'display: block';
                   3507:             }
                   3508:         }
                   3509:         $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
                   3510:                   '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
                   3511:                   $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
                   3512:                   '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
                   3513:         my ($numspares,@spares) = &count_servers($lonhost,%servers);
                   3514:         my @sparestypes = ('primary','default');
                   3515:         my %typetitles = &sparestype_titles();
                   3516:         foreach my $sparetype (@sparestypes) {
                   3517:             my $targettable;
                   3518:             for (my $i=0; $i<$numspares; $i++) {
                   3519:                 my $checked;
                   3520:                 if (ref($currtargets{$lonhost}) eq 'HASH') {
                   3521:                     if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
                   3522:                         if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
                   3523:                             $checked = ' checked="checked"';
                   3524:                         }
                   3525:                     }
                   3526:                 }
                   3527:                 my ($chkboxval,$disabled);
                   3528:                 if (($lonhost ne '') && (exists($servers{$lonhost}))) {
                   3529:                     $chkboxval = $spares[$i];
                   3530:                 }
                   3531:                 if (exists($currbalancer{$spares[$i]})) {
                   3532:                     $disabled = ' disabled="disabled"';
                   3533:                 }
1.210     raeburn  3534:                 $targettable .=
1.171     raeburn  3535:                     '<td><label><input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
                   3536:                     $checked.$disabled.' value="'.$chkboxval.'" id="loadbalancing_target_'.$balnum.'_'.$sparetype.'_'.$i.'" onclick="checkOffloads('."this,'$balnum','$sparetype'".');" /><span id="loadbalancing_targettxt_'.$balnum.'_'.$sparetype.'_'.$i.'">&nbsp;'.$chkboxval.
                   3537:                     '</span></label></td>';
                   3538:                 my $rem = $i%($numinrow);
                   3539:                 if ($rem == 0) {
                   3540:                     if (($i > 0) && ($i < $numspares-1)) {
                   3541:                         $targettable .= '</tr>';
                   3542:                     }
                   3543:                     if ($i < $numspares-1) {
                   3544:                         $targettable .= '<tr>';
1.150     raeburn  3545:                     }
                   3546:                 }
                   3547:             }
1.171     raeburn  3548:             if ($targettable ne '') {
                   3549:                 my $rem = $numspares%($numinrow);
                   3550:                 my $colsleft = $numinrow - $rem;
                   3551:                 if ($colsleft > 1 ) {
                   3552:                     $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   3553:                                     '&nbsp;</td>';
                   3554:                 } elsif ($colsleft == 1) {
                   3555:                     $targettable .= '<td class="LC_left_item">&nbsp;</td>';
                   3556:                 }
                   3557:                 $datatable .=  '<i>'.$typetitles{$sparetype}.'</i><br />'.
                   3558:                                '<table><tr>'.$targettable.'</tr></table><br />';
                   3559:             }
                   3560:         }
                   3561:         $datatable .= '</div></td></tr>'.
                   3562:                       &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
                   3563:                                            $othertitle,$usertypes,$types,\%servers,
                   3564:                                            \%currbalancer,$lonhost,
                   3565:                                            $targets_div_style,$homedom_div_style,
                   3566:                                            $css_class[$cssidx],$balnum,$islast);
                   3567:         $$rowtotal += $rownum;
                   3568:         $balnum ++;
                   3569:     }
                   3570:     $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
                   3571:     return $datatable;
                   3572: }
                   3573: 
                   3574: sub get_loadbalancers_config {
                   3575:     my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
                   3576:     return unless ((ref($servers) eq 'HASH') &&
                   3577:                    (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
                   3578:                    (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
                   3579:     if (keys(%{$existing}) > 0) {
                   3580:         my $oldlonhost;
                   3581:         foreach my $key (sort(keys(%{$existing}))) {
                   3582:             if ($key eq 'lonhost') {
                   3583:                 $oldlonhost = $existing->{'lonhost'};
                   3584:                 $currbalancer->{$oldlonhost} = 1;
                   3585:             } elsif ($key eq 'targets') {
                   3586:                 if ($oldlonhost) {
                   3587:                     $currtargets->{$oldlonhost} = $existing->{'targets'};
                   3588:                 }
                   3589:             } elsif ($key eq 'rules') {
                   3590:                 if ($oldlonhost) {
                   3591:                     $currrules->{$oldlonhost} = $existing->{'rules'};
                   3592:                 }
                   3593:             } elsif (ref($existing->{$key}) eq 'HASH') {
                   3594:                 $currbalancer->{$key} = 1;
                   3595:                 $currtargets->{$key} = $existing->{$key}{'targets'};
                   3596:                 $currrules->{$key} = $existing->{$key}{'rules'};
1.150     raeburn  3597:             }
                   3598:         }
1.171     raeburn  3599:     } else {
                   3600:         my ($balancerref,$targetsref) =
                   3601:                 &Apache::lonnet::get_lonbalancer_config($servers);
                   3602:         if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
                   3603:             foreach my $server (sort(keys(%{$balancerref}))) {
                   3604:                 $currbalancer->{$server} = 1;
                   3605:                 $currtargets->{$server} = $targetsref->{$server};
1.150     raeburn  3606:             }
                   3607:         }
                   3608:     }
1.171     raeburn  3609:     return;
1.150     raeburn  3610: }
                   3611: 
                   3612: sub loadbalancing_rules {
                   3613:     my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171     raeburn  3614:         $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
                   3615:         $css_class,$balnum,$islast) = @_;
1.150     raeburn  3616:     my $output;
1.171     raeburn  3617:     my $num = 0;
1.210     raeburn  3618:     my ($alltypes,$othertypes,$titles) =
1.150     raeburn  3619:         &loadbalancing_titles($dom,$intdom,$usertypes,$types);
                   3620:     if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH'))  {
                   3621:         foreach my $type (@{$alltypes}) {
1.171     raeburn  3622:             $num ++;
1.150     raeburn  3623:             my $current;
                   3624:             if (ref($currrules) eq 'HASH') {
                   3625:                 $current = $currrules->{$type};
                   3626:             }
1.209     raeburn  3627:             if (($type eq '_LC_external') || ($type eq '_LC_internetdom') || ($type eq '_LC_ipchange')) {
1.171     raeburn  3628:                 if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150     raeburn  3629:                     $current = '';
                   3630:                 }
                   3631:             }
                   3632:             $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171     raeburn  3633:                                              $servers,$currbalancer,$lonhost,$dom,
                   3634:                                              $targets_div_style,$homedom_div_style,
                   3635:                                              $css_class,$balnum,$num,$islast);
1.150     raeburn  3636:         }
                   3637:     }
                   3638:     return $output;
                   3639: }
                   3640: 
                   3641: sub loadbalancing_titles {
                   3642:     my ($dom,$intdom,$usertypes,$types) = @_;
                   3643:     my %othertypes = (
                   3644:            '_LC_adv'         => &mt('Advanced users from [_1]',$dom),
                   3645:            '_LC_author'      => &mt('Users from [_1] with author role',$dom),
                   3646:            '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
                   3647:            '_LC_external'    => &mt('Users not from [_1]',$intdom),
1.209     raeburn  3648:            '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
                   3649:            '_LC_ipchange'    => &mt('Non-SSO users with IP mismatch'),
1.150     raeburn  3650:                      );
1.209     raeburn  3651:     my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.150     raeburn  3652:     if (ref($types) eq 'ARRAY') {
                   3653:         unshift(@alltypes,@{$types},'default');
                   3654:     }
                   3655:     my %titles;
                   3656:     foreach my $type (@alltypes) {
                   3657:         if ($type =~ /^_LC_/) {
                   3658:             $titles{$type} = $othertypes{$type};
                   3659:         } elsif ($type eq 'default') {
                   3660:             $titles{$type} = &mt('All users from [_1]',$dom);
                   3661:             if (ref($types) eq 'ARRAY') {
                   3662:                 if (@{$types} > 0) {
                   3663:                     $titles{$type} = &mt('Other users from [_1]',$dom);
                   3664:                 }
                   3665:             }
                   3666:         } elsif (ref($usertypes) eq 'HASH') {
                   3667:             $titles{$type} = $usertypes->{$type};
                   3668:         }
                   3669:     }
                   3670:     return (\@alltypes,\%othertypes,\%titles);
                   3671: }
                   3672: 
                   3673: sub loadbalance_rule_row {
1.171     raeburn  3674:     my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
                   3675:         $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.209     raeburn  3676:     my @rulenames;
1.150     raeburn  3677:     my %ruletitles = &offloadtype_text();
1.209     raeburn  3678:     if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
                   3679:         @rulenames = ('balancer','offloadedto');
1.150     raeburn  3680:     } else {
1.209     raeburn  3681:         @rulenames = ('default','homeserver');
                   3682:         if ($type eq '_LC_external') {
                   3683:             push(@rulenames,'externalbalancer');
                   3684:         } else {
                   3685:             push(@rulenames,'specific');
                   3686:         }
                   3687:         push(@rulenames,'none');
1.150     raeburn  3688:     }
                   3689:     my $style = $targets_div_style;
1.209     raeburn  3690:     if (($type eq '_LC_external') || ($type eq '_LC_internetdom') || ($type eq '_LC_ipchange')) {
1.150     raeburn  3691:         $style = $homedom_div_style;
                   3692:     }
1.171     raeburn  3693:     my $space;
                   3694:     if ($islast && $num == 1) {
                   3695:         $space = '<div display="inline-block">&nbsp;</div>';
                   3696:     }
1.210     raeburn  3697:     my $output =
1.171     raeburn  3698:         '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
                   3699:         '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
                   3700:         '<td valaign="top">'.$space.
                   3701:         '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150     raeburn  3702:     for (my $i=0; $i<@rulenames; $i++) {
                   3703:         my $rule = $rulenames[$i];
                   3704:         my ($checked,$extra);
                   3705:         if ($rulenames[$i] eq 'default') {
                   3706:             $rule = '';
                   3707:         }
                   3708:         if ($rulenames[$i] eq 'specific') {
                   3709:             if (ref($servers) eq 'HASH') {
                   3710:                 my $default;
                   3711:                 if (($current ne '') && (exists($servers->{$current}))) {
                   3712:                     $checked = ' checked="checked"';
                   3713:                 }
                   3714:                 unless ($checked) {
                   3715:                     $default = ' selected="selected"';
                   3716:                 }
1.210     raeburn  3717:                 $extra =
1.171     raeburn  3718:                     ':&nbsp;<select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
                   3719:                     '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
                   3720:                     '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
                   3721:                     '<option value=""'.$default.'></option>'."\n";
                   3722:                 foreach my $server (sort(keys(%{$servers}))) {
                   3723:                     if (ref($currbalancer) eq 'HASH') {
                   3724:                         next if (exists($currbalancer->{$server}));
                   3725:                     }
1.150     raeburn  3726:                     my $selected;
1.171     raeburn  3727:                     if ($server eq $current) {
1.150     raeburn  3728:                         $selected = ' selected="selected"';
                   3729:                     }
1.171     raeburn  3730:                     $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150     raeburn  3731:                 }
                   3732:                 $extra .= '</select>';
                   3733:             }
                   3734:         } elsif ($rule eq $current) {
                   3735:             $checked = ' checked="checked"';
                   3736:         }
                   3737:         $output .= '<span class="LC_nobreak"><label>'.
1.171     raeburn  3738:                    '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
                   3739:                    '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
                   3740:                    $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.150     raeburn  3741:                    ')"'.$checked.' />&nbsp;'.$ruletitles{$rulenames[$i]}.
                   3742:                    '</label>'.$extra.'</span><br />'."\n";
                   3743:     }
                   3744:     $output .= '</div></td></tr>'."\n";
                   3745:     return $output;
                   3746: }
                   3747: 
                   3748: sub offloadtype_text {
                   3749:     my %ruletitles = &Apache::lonlocal::texthash (
                   3750:            'default'          => 'Offloads to default destinations',
                   3751:            'homeserver'       => "Offloads to user's home server",
                   3752:            'externalbalancer' => "Offloads to Load Balancer in user's domain",
                   3753:            'specific'         => 'Offloads to specific server',
1.161     raeburn  3754:            'none'             => 'No offload',
1.209     raeburn  3755:            'balancer'         => 'Session hosted on Load Balancer, after re-authentication',
                   3756:            'offloadedto'      => 'Session hosted on offload server, after re-authentication',
1.150     raeburn  3757:     );
                   3758:     return %ruletitles;
                   3759: }
                   3760: 
                   3761: sub sparestype_titles {
                   3762:     my %typestitles = &Apache::lonlocal::texthash (
                   3763:                           'primary' => 'primary',
                   3764:                           'default' => 'default',
                   3765:                       );
                   3766:     return %typestitles;
                   3767: }
                   3768: 
1.28      raeburn  3769: sub contact_titles {
                   3770:     my %titles = &Apache::lonlocal::texthash (
                   3771:                    'supportemail' => 'Support E-mail address',
1.69      raeburn  3772:                    'adminemail'   => 'Default Server Admin E-mail address',
1.28      raeburn  3773:                    'errormail'    => 'Error reports to be e-mailed to',
                   3774:                    'packagesmail' => 'Package update alerts to be e-mailed to',
1.89      raeburn  3775:                    'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
                   3776:                    'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
1.102     raeburn  3777:                    'requestsmail' => 'E-mail from course requests requiring approval',
1.190     raeburn  3778:                    'updatesmail'  => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.203     raeburn  3779:                    'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.28      raeburn  3780:                  );
                   3781:     my %short_titles = &Apache::lonlocal::texthash (
                   3782:                            adminemail   => 'Admin E-mail address',
                   3783:                            supportemail => 'Support E-mail',
                   3784:                        );   
                   3785:     return (\%titles,\%short_titles);
                   3786: }
                   3787: 
1.72      raeburn  3788: sub tool_titles {
                   3789:     my %titles = &Apache::lonlocal::texthash (
1.162     raeburn  3790:                      aboutme    => 'Personal web page',
1.86      raeburn  3791:                      blog       => 'Blog',
1.162     raeburn  3792:                      webdav     => 'WebDAV',
1.86      raeburn  3793:                      portfolio  => 'Portfolio',
1.88      bisitz   3794:                      official   => 'Official courses (with institutional codes)',
                   3795:                      unofficial => 'Unofficial courses',
1.98      raeburn  3796:                      community  => 'Communities',
1.216     raeburn  3797:                      textbook   => 'Textbook courses',
1.86      raeburn  3798:                  );
1.72      raeburn  3799:     return %titles;
                   3800: }
                   3801: 
1.101     raeburn  3802: sub courserequest_titles {
                   3803:     my %titles = &Apache::lonlocal::texthash (
                   3804:                                    official   => 'Official',
                   3805:                                    unofficial => 'Unofficial',
                   3806:                                    community  => 'Communities',
1.216     raeburn  3807:                                    textbook   => 'Textbook',
1.101     raeburn  3808:                                    norequest  => 'Not allowed',
1.104     raeburn  3809:                                    approval   => 'Approval by Dom. Coord.',
1.101     raeburn  3810:                                    validate   => 'With validation',
                   3811:                                    autolimit  => 'Numerical limit',
1.103     raeburn  3812:                                    unlimited  => '(blank for unlimited)',
1.101     raeburn  3813:                  );
                   3814:     return %titles;
                   3815: }
                   3816: 
1.163     raeburn  3817: sub authorrequest_titles {
                   3818:     my %titles = &Apache::lonlocal::texthash (
                   3819:                                    norequest  => 'Not allowed',
                   3820:                                    approval   => 'Approval by Dom. Coord.',
                   3821:                                    automatic  => 'Automatic approval',
                   3822:                  );
                   3823:     return %titles;
1.210     raeburn  3824: }
1.163     raeburn  3825: 
1.101     raeburn  3826: sub courserequest_conditions {
                   3827:     my %conditions = &Apache::lonlocal::texthash (
1.104     raeburn  3828:        approval    => '(Processing of request subject to approval by Domain Coordinator).',
1.193     bisitz   3829:        validate   => '(Processing of request subject to institutional validation).',
1.101     raeburn  3830:                  );
                   3831:     return %conditions;
                   3832: }
                   3833: 
                   3834: 
1.27      raeburn  3835: sub print_usercreation {
1.30      raeburn  3836:     my ($position,$dom,$settings,$rowtotal) = @_;
1.27      raeburn  3837:     my $numinrow = 4;
1.28      raeburn  3838:     my $datatable;
                   3839:     if ($position eq 'top') {
1.30      raeburn  3840:         $$rowtotal ++;
1.34      raeburn  3841:         my $rowcount = 0;
1.32      raeburn  3842:         my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28      raeburn  3843:         if (ref($rules) eq 'HASH') {
                   3844:             if (keys(%{$rules}) > 0) {
1.32      raeburn  3845:                 $datatable .= &user_formats_row('username',$settings,$rules,
                   3846:                                                 $ruleorder,$numinrow,$rowcount);
1.30      raeburn  3847:                 $$rowtotal ++;
1.32      raeburn  3848:                 $rowcount ++;
                   3849:             }
                   3850:         }
                   3851:         my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
                   3852:         if (ref($idrules) eq 'HASH') {
                   3853:             if (keys(%{$idrules}) > 0) {
                   3854:                 $datatable .= &user_formats_row('id',$settings,$idrules,
                   3855:                                                 $idruleorder,$numinrow,$rowcount);
                   3856:                 $$rowtotal ++;
                   3857:                 $rowcount ++;
1.28      raeburn  3858:             }
                   3859:         }
1.39      raeburn  3860:         if ($rowcount == 0) {
                   3861:             $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';  
                   3862:             $$rowtotal ++;
                   3863:             $rowcount ++;
                   3864:         }
1.34      raeburn  3865:     } elsif ($position eq 'middle') {
1.224     raeburn  3866:         my @creators = ('author','course','requestcrs');
1.37      raeburn  3867:         my ($rules,$ruleorder) =
                   3868:             &Apache::lonnet::inst_userrules($dom,'username');
1.34      raeburn  3869:         my %lt = &usercreation_types();
                   3870:         my %checked;
                   3871:         if (ref($settings) eq 'HASH') {
                   3872:             if (ref($settings->{'cancreate'}) eq 'HASH') {
                   3873:                 foreach my $item (@creators) {
                   3874:                     $checked{$item} = $settings->{'cancreate'}{$item};
                   3875:                 }
                   3876:             } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
                   3877:                 foreach my $item (@creators) {
                   3878:                     if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
                   3879:                         $checked{$item} = 'none';
                   3880:                     }
                   3881:                 }
                   3882:             }
                   3883:         }
                   3884:         my $rownum = 0;
                   3885:         foreach my $item (@creators) {
                   3886:             $rownum ++;
1.224     raeburn  3887:             if ($checked{$item} eq '') {
                   3888:                 $checked{$item} = 'any';
1.34      raeburn  3889:             }
                   3890:             my $css_class;
                   3891:             if ($rownum%2) {
                   3892:                 $css_class = '';
                   3893:             } else {
                   3894:                 $css_class = ' class="LC_odd_row" ';
                   3895:             }
                   3896:             $datatable .= '<tr'.$css_class.'>'.
                   3897:                          '<td><span class="LC_nobreak">'.$lt{$item}.
                   3898:                          '</span></td><td align="right">';
1.224     raeburn  3899:             my @options = ('any');
                   3900:             if (ref($rules) eq 'HASH') {
                   3901:                 if (keys(%{$rules}) > 0) {
                   3902:                     push(@options,('official','unofficial'));
1.37      raeburn  3903:                 }
                   3904:             }
1.224     raeburn  3905:             push(@options,'none');
1.37      raeburn  3906:             foreach my $option (@options) {
1.50      raeburn  3907:                 my $type = 'radio';
1.34      raeburn  3908:                 my $check = ' ';
1.224     raeburn  3909:                 if ($checked{$item} eq $option) {
                   3910:                     $check = ' checked="checked" ';
1.34      raeburn  3911:                 } 
                   3912:                 $datatable .= '<span class="LC_nobreak"><label>'.
1.50      raeburn  3913:                               '<input type="'.$type.'" name="can_createuser_'.
1.34      raeburn  3914:                               $item.'" value="'.$option.'"'.$check.'/>&nbsp;'.
                   3915:                               $lt{$option}.'</label>&nbsp;&nbsp;</span>';
                   3916:             }
                   3917:             $datatable .= '</td></tr>';
                   3918:         }
1.28      raeburn  3919:     } else {
                   3920:         my @contexts = ('author','course','domain');
                   3921:         my @authtypes = ('int','krb4','krb5','loc');
                   3922:         my %checked;
                   3923:         if (ref($settings) eq 'HASH') {
                   3924:             if (ref($settings->{'authtypes'}) eq 'HASH') {
                   3925:                 foreach my $item (@contexts) {
                   3926:                     if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
                   3927:                         foreach my $auth (@authtypes) {
                   3928:                             if ($settings->{'authtypes'}{$item}{$auth}) {
                   3929:                                 $checked{$item}{$auth} = ' checked="checked" ';
                   3930:                             }
                   3931:                         }
                   3932:                     }
                   3933:                 }
1.27      raeburn  3934:             }
1.35      raeburn  3935:         } else {
                   3936:             foreach my $item (@contexts) {
1.36      raeburn  3937:                 foreach my $auth (@authtypes) {
1.35      raeburn  3938:                     $checked{$item}{$auth} = ' checked="checked" ';
                   3939:                 }
                   3940:             }
1.27      raeburn  3941:         }
1.28      raeburn  3942:         my %title = &context_names();
                   3943:         my %authname = &authtype_names();
                   3944:         my $rownum = 0;
                   3945:         my $css_class; 
                   3946:         foreach my $item (@contexts) {
                   3947:             if ($rownum%2) {
                   3948:                 $css_class = '';
                   3949:             } else {
                   3950:                 $css_class = ' class="LC_odd_row" ';
                   3951:             }
1.30      raeburn  3952:             $datatable .=   '<tr'.$css_class.'>'.
1.28      raeburn  3953:                             '<td>'.$title{$item}.
                   3954:                             '</td><td class="LC_left_item">'.
                   3955:                             '<span class="LC_nobreak">';
                   3956:             foreach my $auth (@authtypes) {
                   3957:                 $datatable .= '<label>'. 
                   3958:                               '<input type="checkbox" name="'.$item.'_auth" '.
                   3959:                               $checked{$item}{$auth}.' value="'.$auth.'" />'.
                   3960:                               $authname{$auth}.'</label>&nbsp;';
                   3961:             }
                   3962:             $datatable .= '</span></td></tr>';
                   3963:             $rownum ++;
1.27      raeburn  3964:         }
1.30      raeburn  3965:         $$rowtotal += $rownum;
1.27      raeburn  3966:     }
                   3967:     return $datatable;
                   3968: }
                   3969: 
1.224     raeburn  3970: sub print_selfcreation {
                   3971:     my ($position,$dom,$settings,$rowtotal) = @_;
                   3972:     my (@selfcreate,$createsettings,$datatable);
                   3973:     if (ref($settings) eq 'HASH') {
                   3974:         if (ref($settings->{'cancreate'}) eq 'HASH') {
                   3975:             $createsettings = $settings->{'cancreate'};
                   3976:             if (ref($settings->{'cancreate'}{'selfcreate'}) eq 'ARRAY') {
                   3977:                 @selfcreate = @{$settings->{'cancreate'}{'selfcreate'}};
                   3978:             } elsif ($settings->{'cancreate'}{'selfcreate'} ne '') {
                   3979:                 if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
                   3980:                     @selfcreate = ('email','login','sso');
                   3981:                 } elsif ($settings->{'cancreate'}{'selfcreate'} ne 'none') {
                   3982:                     @selfcreate = ($settings->{'cancreate'}{'selfcreate'});
                   3983:                 }
                   3984:             }
                   3985:         }
                   3986:     }
                   3987:     my %radiohash;
                   3988:     my $numinrow = 4;
                   3989:     map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
                   3990:     if ($position eq 'top') {
                   3991:         my %choices = &Apache::lonlocal::texthash (
                   3992:                                                       cancreate_login      => 'Institutional Login',
                   3993:                                                       cancreate_sso        => 'Institutional Single Sign On',
                   3994:                                                   );
                   3995:         my @toggles = sort(keys(%choices));
                   3996:         my %defaultchecked = (
                   3997:                                'cancreate_login' => 'off',
                   3998:                                'cancreate_sso'   => 'off',
                   3999:                              );
1.228     raeburn  4000:         my ($onclick,$itemcount);
1.224     raeburn  4001:         ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
                   4002:                                                      \%choices,$itemcount,$onclick);
1.228     raeburn  4003:         $$rowtotal += $itemcount;
                   4004:         
1.224     raeburn  4005:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   4006: 
                   4007:         if (ref($usertypes) eq 'HASH') {
                   4008:             if (keys(%{$usertypes}) > 0) {
                   4009:                 $datatable .= &insttypes_row($createsettings,$types,$usertypes,
                   4010:                                              $dom,$numinrow,$othertitle,
1.228     raeburn  4011:                                              'statustocreate',$$rowtotal);
1.224     raeburn  4012:                 $$rowtotal ++;
                   4013:             }
                   4014:         }
                   4015:     } elsif ($position eq 'middle') {
                   4016:         my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
                   4017:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   4018:         $usertypes->{'default'} = $othertitle;
                   4019:         if (ref($types) eq 'ARRAY') {
                   4020:             push(@{$types},'default');
                   4021:             $usertypes->{'default'} = $othertitle;
                   4022:             foreach my $status (@{$types}) {
                   4023:                 $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
1.228     raeburn  4024:                                                        $numinrow,$$rowtotal,$usertypes);
1.224     raeburn  4025:                 $$rowtotal ++;
                   4026:             }
                   4027:         }
                   4028:     } else {
1.228     raeburn  4029:         my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
1.224     raeburn  4030:         my %choices =
                   4031:             &Apache::lonlocal::texthash(
                   4032:                                           email         => 'Approved automatically',
                   4033:                                           emailapproval => 'Queued for approval by DC',
                   4034:                                           off           => 'Not enabled',
                   4035:                                        );
                   4036:         $datatable .= '<tr'.$css_class.'>'.
                   4037:                       '<td>'.&mt('E-mail address as username').
                   4038:                       '</td><td class="LC_left_item">'.
                   4039:                       '<span class="LC_nobreak">';
                   4040:         foreach my $option ('email','emailapproval','off') {
                   4041:             my $checked;
                   4042:             if ($option eq 'email') {
                   4043:                 if ($radiohash{'cancreate_email'}) {
                   4044:                     $checked = 'checked="checked"';
                   4045:                 }
                   4046:             } elsif ($option eq 'emailapproval') {
                   4047:                 if ($radiohash{'cancreate_emailapproval'}) {
                   4048:                     $checked = 'checked="checked"';
                   4049:                 }
                   4050:             } else {
                   4051:                 if ((!$radiohash{'cancreate_email'}) && (!$radiohash{'cancreate_emailapproval'})) {
                   4052:                     $checked = 'checked="checked"';  
                   4053:                 }
                   4054:             }
                   4055:             $datatable .= '<label>'.
                   4056:                           '<input type="radio" name="cancreate_email" '.
                   4057:                           $checked.' value="'.$option.'" />'.
                   4058:                           $choices{$option}.'</label>&nbsp;';
                   4059:         }
                   4060:         $$rowtotal ++;
                   4061:         $datatable .= '</span></td></tr>'.
                   4062:                       &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal);
1.228     raeburn  4063:         $$rowtotal ++;
1.224     raeburn  4064:         my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.228     raeburn  4065:         $numinrow = 1;
                   4066:         my ($othertitle,$usertypes,$types) =  &Apache::loncommon::sorted_inst_types($dom);
                   4067:         $usertypes->{'default'} = $othertitle;
                   4068:         if (ref($types) eq 'ARRAY') {
                   4069:             push(@{$types},'default');
                   4070:             $usertypes->{'default'} = $othertitle;
                   4071:             foreach my $status (@{$types}) {
                   4072:                 $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
                   4073:                                                        $numinrow,$$rowtotal,$usertypes,$infofields,$infotitles);
                   4074:                 $$rowtotal ++;
                   4075:             }
                   4076:         }
1.224     raeburn  4077:         my ($emailrules,$emailruleorder) =
                   4078:             &Apache::lonnet::inst_userrules($dom,'email');
                   4079:         if (ref($emailrules) eq 'HASH') {
                   4080:             if (keys(%{$emailrules}) > 0) {
                   4081:                 $datatable .= &user_formats_row('email',$settings,$emailrules,
1.228     raeburn  4082:                                                 $emailruleorder,$numinrow,$$rowtotal);
1.224     raeburn  4083:                 $$rowtotal ++;
                   4084:             }
                   4085:         }
1.228     raeburn  4086:         $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal);
1.224     raeburn  4087:     }
                   4088:     return $datatable;
                   4089: }
                   4090: 
1.165     raeburn  4091: sub captcha_choice {
1.169     raeburn  4092:     my ($context,$settings,$itemcount) = @_;
1.165     raeburn  4093:     my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext);
                   4094:     my %lt = &captcha_phrases();
                   4095:     $keyentry = 'hidden';
                   4096:     if ($context eq 'cancreate') {
1.224     raeburn  4097:         $rowname = &mt('CAPTCHA validation');
1.169     raeburn  4098:     } elsif ($context eq 'login') {
                   4099:         $rowname =  &mt('"Contact helpdesk" CAPTCHA validation');
1.165     raeburn  4100:     }
                   4101:     if (ref($settings) eq 'HASH') {
                   4102:         if ($settings->{'captcha'}) {
                   4103:             $checked{$settings->{'captcha'}} = ' checked="checked"';
                   4104:         } else {
                   4105:             $checked{'original'} = ' checked="checked"';
                   4106:         }
                   4107:         if ($settings->{'captcha'} eq 'recaptcha') {
                   4108:             $pubtext = $lt{'pub'};
                   4109:             $privtext = $lt{'priv'};
                   4110:             $keyentry = 'text';
                   4111:         }
                   4112:         if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
                   4113:             $currpub = $settings->{'recaptchakeys'}{'public'};
                   4114:             $currpriv = $settings->{'recaptchakeys'}{'private'};
                   4115:         }
                   4116:     } else {
                   4117:         $checked{'original'} = ' checked="checked"';
                   4118:     }
1.169     raeburn  4119:     my $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   4120:     my $output = '<tr'.$css_class.'>'.
                   4121:                  '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
1.165     raeburn  4122:                  '<table><tr><td>'."\n";
                   4123:     foreach my $option ('original','recaptcha','notused') {
                   4124:         $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
                   4125:                    $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
                   4126:                    $lt{$option}.'</label></span>';
                   4127:         unless ($option eq 'notused') {
                   4128:             $output .= ('&nbsp;'x2)."\n";
                   4129:         }
                   4130:     }
                   4131: #
                   4132: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
                   4133: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
1.210     raeburn  4134: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
1.165     raeburn  4135: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
1.210     raeburn  4136: #
1.165     raeburn  4137:     $output .= '</td></tr>'."\n".
                   4138:                '<tr><td>'."\n".
                   4139:                '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span>&nbsp;'."\n".
                   4140:                '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
                   4141:                $currpub.'" size="40" /></span><br />'."\n".
                   4142:                '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span>&nbsp;'."\n".
                   4143:                '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
                   4144:                $currpriv.'" size="40" /></span></td></tr></table>'."\n".
                   4145:                '</td></tr>';
                   4146:     return $output;
                   4147: }
                   4148: 
1.32      raeburn  4149: sub user_formats_row {
                   4150:     my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
                   4151:     my $output;
                   4152:     my %text = (
                   4153:                    'username' => 'new usernames',
                   4154:                    'id'       => 'IDs',
1.45      raeburn  4155:                    'email'    => 'self-created accounts (e-mail)',
1.32      raeburn  4156:                );
                   4157:     my $css_class = $rowcount%2?' class="LC_odd_row"':'';
                   4158:     $output = '<tr '.$css_class.'>'.
1.63      raeburn  4159:               '<td><span class="LC_nobreak">';
                   4160:     if ($type eq 'email') {
                   4161:         $output .= &mt("Formats disallowed for $text{$type}: ");
                   4162:     } else {
                   4163:         $output .= &mt("Format rules to check for $text{$type}: ");
                   4164:     }
                   4165:     $output .= '</span></td>'.
                   4166:                '<td class="LC_left_item" colspan="2"><table>';
1.27      raeburn  4167:     my $rem;
                   4168:     if (ref($ruleorder) eq 'ARRAY') {
                   4169:         for (my $i=0; $i<@{$ruleorder}; $i++) {
                   4170:             if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
                   4171:                 my $rem = $i%($numinrow);
                   4172:                 if ($rem == 0) {
                   4173:                     if ($i > 0) {
                   4174:                         $output .= '</tr>';
                   4175:                     }
                   4176:                     $output .= '<tr>';
                   4177:                 }
                   4178:                 my $check = ' ';
1.39      raeburn  4179:                 if (ref($settings) eq 'HASH') {
                   4180:                     if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
                   4181:                         if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
                   4182:                             $check = ' checked="checked" ';
                   4183:                         }
1.27      raeburn  4184:                     }
                   4185:                 }
                   4186:                 $output .= '<td class="LC_left_item">'.
                   4187:                            '<span class="LC_nobreak"><label>'.
1.32      raeburn  4188:                            '<input type="checkbox" name="'.$type.'_rule" '.
1.27      raeburn  4189:                            'value="'.$ruleorder->[$i].'"'.$check.'/>'.
                   4190:                            $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
                   4191:             }
                   4192:         }
                   4193:         $rem = @{$ruleorder}%($numinrow);
                   4194:     }
                   4195:     my $colsleft = $numinrow - $rem;
                   4196:     if ($colsleft > 1 ) {
                   4197:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   4198:                    '&nbsp;</td>';
                   4199:     } elsif ($colsleft == 1) {
                   4200:         $output .= '<td class="LC_left_item">&nbsp;</td>';
                   4201:     }
                   4202:     $output .= '</tr></table></td></tr>';
                   4203:     return $output;
                   4204: }
                   4205: 
1.34      raeburn  4206: sub usercreation_types {
                   4207:     my %lt = &Apache::lonlocal::texthash (
                   4208:                     author     => 'When adding a co-author',
                   4209:                     course     => 'When adding a user to a course',
1.100     raeburn  4210:                     requestcrs => 'When requesting a course',
1.34      raeburn  4211:                     any        => 'Any',
                   4212:                     official   => 'Institutional only ',
                   4213:                     unofficial => 'Non-institutional only',
                   4214:                     none       => 'None',
                   4215:     );
                   4216:     return %lt;
1.48      raeburn  4217: }
1.34      raeburn  4218: 
1.224     raeburn  4219: sub selfcreation_types {
                   4220:     my %lt = &Apache::lonlocal::texthash (
                   4221:                     selfcreate => 'User creates own account',
                   4222:                     any        => 'Any',
                   4223:                     official   => 'Institutional only ',
                   4224:                     unofficial => 'Non-institutional only',
                   4225:                     email      => 'E-mail address',
                   4226:                     login      => 'Institutional Login',
                   4227:                     sso        => 'SSO',
                   4228:              );
                   4229: }
                   4230: 
1.28      raeburn  4231: sub authtype_names {
                   4232:     my %lt = &Apache::lonlocal::texthash(
                   4233:                       int    => 'Internal',
                   4234:                       krb4   => 'Kerberos 4',
                   4235:                       krb5   => 'Kerberos 5',
                   4236:                       loc    => 'Local',
                   4237:                   );
                   4238:     return %lt;
                   4239: }
                   4240: 
                   4241: sub context_names {
                   4242:     my %context_title = &Apache::lonlocal::texthash(
                   4243:        author => 'Creating users when an Author',
                   4244:        course => 'Creating users when in a course',
                   4245:        domain => 'Creating users when a Domain Coordinator',
                   4246:     );
                   4247:     return %context_title;
                   4248: }
                   4249: 
1.33      raeburn  4250: sub print_usermodification {
                   4251:     my ($position,$dom,$settings,$rowtotal) = @_;
                   4252:     my $numinrow = 4;
                   4253:     my ($context,$datatable,$rowcount);
                   4254:     if ($position eq 'top') {
                   4255:         $rowcount = 0;
                   4256:         $context = 'author'; 
                   4257:         foreach my $role ('ca','aa') {
                   4258:             $datatable .= &modifiable_userdata_row($context,$role,$settings,
                   4259:                                                    $numinrow,$rowcount);
                   4260:             $$rowtotal ++;
                   4261:             $rowcount ++;
                   4262:         }
1.230     raeburn  4263:     } elsif ($position eq 'bottom') {
1.33      raeburn  4264:         $context = 'course';
                   4265:         $rowcount = 0;
                   4266:         foreach my $role ('st','ep','ta','in','cr') {
                   4267:             $datatable .= &modifiable_userdata_row($context,$role,$settings,
                   4268:                                                    $numinrow,$rowcount);
                   4269:             $$rowtotal ++;
                   4270:             $rowcount ++;
                   4271:         }
                   4272:     }
                   4273:     return $datatable;
                   4274: }
                   4275: 
1.43      raeburn  4276: sub print_defaults {
1.212     raeburn  4277:     my ($dom,$settings,$rowtotal) = @_;
1.68      raeburn  4278:     my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
1.141     raeburn  4279:                  'datelocale_def','portal_def');
1.212     raeburn  4280:     my %defaults;
                   4281:     if (ref($settings) eq 'HASH') {
1.213     raeburn  4282:         %defaults = %{$settings};
1.212     raeburn  4283:     } else {
                   4284:         my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
                   4285:         foreach my $item (@items) {
                   4286:             $defaults{$item} = $domdefaults{$item};
                   4287:         }
                   4288:     }
1.141     raeburn  4289:     my $titles = &defaults_titles($dom);
1.43      raeburn  4290:     my $rownum = 0;
                   4291:     my ($datatable,$css_class);
                   4292:     foreach my $item (@items) {
                   4293:         if ($rownum%2) {
                   4294:             $css_class = '';
                   4295:         } else {
                   4296:             $css_class = ' class="LC_odd_row" ';
                   4297:         }
                   4298:         $datatable .= '<tr'.$css_class.'>'.
                   4299:                   '<td><span class="LC_nobreak">'.$titles->{$item}.
                   4300:                   '</span></td><td class="LC_right_item">';
                   4301:         if ($item eq 'auth_def') {
                   4302:             my @authtypes = ('internal','krb4','krb5','localauth');
                   4303:             my %shortauth = (
                   4304:                              internal => 'int',
                   4305:                              krb4 => 'krb4',
                   4306:                              krb5 => 'krb5',
                   4307:                              localauth  => 'loc'
                   4308:                            );
                   4309:             my %authnames = &authtype_names();
                   4310:             foreach my $auth (@authtypes) {
                   4311:                 my $checked = ' ';
1.212     raeburn  4312:                 if ($defaults{$item} eq $auth) {
1.43      raeburn  4313:                     $checked = ' checked="checked" ';
                   4314:                 }
                   4315:                 $datatable .= '<label><input type="radio" name="'.$item.
                   4316:                               '" value="'.$auth.'"'.$checked.'/>'.
                   4317:                               $authnames{$shortauth{$auth}}.'</label>&nbsp;&nbsp;';
                   4318:             }
1.54      raeburn  4319:         } elsif ($item eq 'timezone_def') {
                   4320:             my $includeempty = 1;
1.212     raeburn  4321:             $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
1.68      raeburn  4322:         } elsif ($item eq 'datelocale_def') {
                   4323:             my $includeempty = 1;
1.212     raeburn  4324:             $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
1.167     raeburn  4325:         } elsif ($item eq 'lang_def') {
1.168     raeburn  4326:             my %langchoices = &get_languages_hash();
                   4327:             $langchoices{''} = 'No language preference';
1.167     raeburn  4328:             %langchoices = &Apache::lonlocal::texthash(%langchoices);
1.212     raeburn  4329:             $datatable .= &Apache::loncommon::select_form($defaults{$item},$item,
1.167     raeburn  4330:                                                           \%langchoices);
1.43      raeburn  4331:         } else {
1.141     raeburn  4332:             my $size;
                   4333:             if ($item eq 'portal_def') {
                   4334:                 $size = ' size="25"';
                   4335:             }
1.43      raeburn  4336:             $datatable .= '<input type="text" name="'.$item.'" value="'.
1.212     raeburn  4337:                           $defaults{$item}.'"'.$size.' />';
1.43      raeburn  4338:         }
                   4339:         $datatable .= '</td></tr>';
                   4340:         $rownum ++;
                   4341:     }
                   4342:     $$rowtotal += $rownum;
                   4343:     return $datatable;
                   4344: }
                   4345: 
1.168     raeburn  4346: sub get_languages_hash {
                   4347:     my %langchoices;
                   4348:     foreach my $id (&Apache::loncommon::languageids()) {
                   4349:         my $code = &Apache::loncommon::supportedlanguagecode($id);
                   4350:         if ($code ne '') {
                   4351:             $langchoices{$code} =  &Apache::loncommon::plainlanguagedescription($id);
                   4352:         }
                   4353:     }
                   4354:     return %langchoices;
                   4355: }
                   4356: 
1.43      raeburn  4357: sub defaults_titles {
1.141     raeburn  4358:     my ($dom) = @_;
1.43      raeburn  4359:     my %titles = &Apache::lonlocal::texthash (
                   4360:                    'auth_def'      => 'Default authentication type',
                   4361:                    'auth_arg_def'  => 'Default authentication argument',
                   4362:                    'lang_def'      => 'Default language',
1.54      raeburn  4363:                    'timezone_def'  => 'Default timezone',
1.68      raeburn  4364:                    'datelocale_def' => 'Default locale for dates',
1.141     raeburn  4365:                    'portal_def'     => 'Portal/Default URL',
1.43      raeburn  4366:                  );
1.141     raeburn  4367:     if ($dom) {
                   4368:         my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
                   4369:         my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
                   4370:         my $protocol = $Apache::lonnet::protocol{$uprimary_id};
                   4371:         $protocol = 'http' if ($protocol ne 'https');
                   4372:         if ($uint_dom) {
                   4373:             $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
                   4374:                                          $uint_dom);
                   4375:         }
                   4376:     }
1.43      raeburn  4377:     return (\%titles);
                   4378: }
                   4379: 
1.46      raeburn  4380: sub print_scantronformat {
                   4381:     my ($r,$dom,$confname,$settings,$rowtotal) = @_;
                   4382:     my $itemcount = 1;
1.60      raeburn  4383:     my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
                   4384:         %confhash);
1.46      raeburn  4385:     my $switchserver = &check_switchserver($dom,$confname);
                   4386:     my %lt = &Apache::lonlocal::texthash (
1.95      www      4387:                 default => 'Default bubblesheet format file error',
                   4388:                 custom  => 'Custom bubblesheet format file error',
1.46      raeburn  4389:              );
                   4390:     my %scantronfiles = (
                   4391:         default => 'default.tab',
                   4392:         custom => 'custom.tab',
                   4393:     );
                   4394:     foreach my $key (keys(%scantronfiles)) {
                   4395:         $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
                   4396:                               .$scantronfiles{$key};
                   4397:     }
                   4398:     my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
                   4399:     if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
                   4400:         if (!$switchserver) {
                   4401:             my $servadm = $r->dir_config('lonAdmEMail');
                   4402:             my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
                   4403:             if ($configuserok eq 'ok') {
                   4404:                 if ($author_ok eq 'ok') {
                   4405:                     my %legacyfile = (
                   4406:  default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab', 
                   4407:  custom  => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab', 
                   4408:                     );
                   4409:                     my %md5chk;
                   4410:                     foreach my $type (keys(%legacyfile)) {
1.60      raeburn  4411:                         ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
                   4412:                         chomp($md5chk{$type});
1.46      raeburn  4413:                     }
                   4414:                     if ($md5chk{'default'} ne $md5chk{'custom'}) {
                   4415:                         foreach my $type (keys(%legacyfile)) {
1.60      raeburn  4416:                             ($scantronurls{$type},my $error) = 
1.46      raeburn  4417:                                 &legacy_scantronformat($r,$dom,$confname,
                   4418:                                                  $type,$legacyfile{$type},
                   4419:                                                  $scantronurls{$type},
                   4420:                                                  $scantronfiles{$type});
1.60      raeburn  4421:                             if ($error ne '') {
                   4422:                                 $error{$type} = $error;
                   4423:                             }
                   4424:                         }
                   4425:                         if (keys(%error) == 0) {
                   4426:                             $is_custom = 1;
                   4427:                             $confhash{'scantron'}{'scantronformat'} = 
                   4428:                                 $scantronurls{'custom'};
                   4429:                             my $putresult = 
                   4430:                                 &Apache::lonnet::put_dom('configuration',
                   4431:                                                          \%confhash,$dom);
                   4432:                             if ($putresult ne 'ok') {
                   4433:                                 $error{'custom'} = 
                   4434:                                     '<span class="LC_error">'.
                   4435:                                     &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
                   4436:                             }
1.46      raeburn  4437:                         }
                   4438:                     } else {
1.60      raeburn  4439:                         ($scantronurls{'default'},my $error) =
1.46      raeburn  4440:                             &legacy_scantronformat($r,$dom,$confname,
                   4441:                                           'default',$legacyfile{'default'},
                   4442:                                           $scantronurls{'default'},
                   4443:                                           $scantronfiles{'default'});
1.60      raeburn  4444:                         if ($error eq '') {
                   4445:                             $confhash{'scantron'}{'scantronformat'} = ''; 
                   4446:                             my $putresult =
                   4447:                                 &Apache::lonnet::put_dom('configuration',
                   4448:                                                          \%confhash,$dom);
                   4449:                             if ($putresult ne 'ok') {
                   4450:                                 $error{'default'} =
                   4451:                                     '<span class="LC_error">'.
                   4452:                                     &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
                   4453:                             }
                   4454:                         } else {
                   4455:                             $error{'default'} = $error;
                   4456:                         }
1.46      raeburn  4457:                     }
                   4458:                 }
                   4459:             }
                   4460:         } else {
1.95      www      4461:             $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46      raeburn  4462:         }
                   4463:     }
                   4464:     if (ref($settings) eq 'HASH') {
                   4465:         if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
                   4466:             my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
                   4467:             if ((!@info) || ($info[0] eq 'no_such_dir')) {
                   4468:                 $scantronurl = '';
                   4469:             } else {
                   4470:                 $scantronurl = $settings->{'scantronformat'};
                   4471:             }
                   4472:             $is_custom = 1;
                   4473:         } else {
                   4474:             $scantronurl = $scantronurls{'default'};
                   4475:         }
                   4476:     } else {
1.60      raeburn  4477:         if ($is_custom) {
                   4478:             $scantronurl = $scantronurls{'custom'};
                   4479:         } else {
                   4480:             $scantronurl = $scantronurls{'default'};
                   4481:         }
1.46      raeburn  4482:     }
                   4483:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   4484:     $datatable .= '<tr'.$css_class.'>';
                   4485:     if (!$is_custom) {
1.65      raeburn  4486:         $datatable .= '<td>'.&mt('Default in use:').'<br />'.
                   4487:                       '<span class="LC_nobreak">';
1.46      raeburn  4488:         if ($scantronurl) {
1.199     raeburn  4489:             $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
                   4490:                                                          undef,undef,undef,undef,'background-color:#ffffff');
1.46      raeburn  4491:         } else {
                   4492:             $datatable = &mt('File unavailable for display');
                   4493:         }
1.65      raeburn  4494:         $datatable .= '</span></td>';
1.60      raeburn  4495:         if (keys(%error) == 0) { 
                   4496:             $datatable .= '<td valign="bottom">';
                   4497:             if (!$switchserver) {
                   4498:                 $datatable .= &mt('Upload:').'<br />';
                   4499:             }
                   4500:         } else {
                   4501:             my $errorstr;
                   4502:             foreach my $key (sort(keys(%error))) {
                   4503:                 $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
                   4504:             }
                   4505:             $datatable .= '<td>'.$errorstr;
                   4506:         }
1.46      raeburn  4507:     } else {
                   4508:         if (keys(%error) > 0) {
                   4509:             my $errorstr;
                   4510:             foreach my $key (sort(keys(%error))) {
                   4511:                 $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
                   4512:             } 
1.60      raeburn  4513:             $datatable .= '<td>'.$errorstr.'</td><td>&nbsp;';
1.46      raeburn  4514:         } elsif ($scantronurl) {
1.199     raeburn  4515:             my $link =  &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
                   4516:                                                        undef,undef,undef,undef,'background-color:#ffffff');
1.65      raeburn  4517:             $datatable .= '<td><span class="LC_nobreak">'.
1.199     raeburn  4518:                           $link.
                   4519:                           '<label><input type="checkbox" name="scantronformat_del"'.
                   4520:                           ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65      raeburn  4521:                           '<td><span class="LC_nobreak">&nbsp;'.
                   4522:                           &mt('Replace:').'</span><br />';
1.46      raeburn  4523:         }
                   4524:     }
                   4525:     if (keys(%error) == 0) {
                   4526:         if ($switchserver) {
                   4527:             $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   4528:         } else {
1.65      raeburn  4529:             $datatable .='<span class="LC_nobreak">&nbsp;'.
                   4530:                          '<input type="file" name="scantronformat" /></span>';
1.46      raeburn  4531:         }
                   4532:     }
                   4533:     $datatable .= '</td></tr>';
                   4534:     $$rowtotal ++;
                   4535:     return $datatable;
                   4536: }
                   4537: 
                   4538: sub legacy_scantronformat {
                   4539:     my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
                   4540:     my ($url,$error);
                   4541:     my @statinfo = &Apache::lonnet::stat_file($newurl);
                   4542:     if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
                   4543:         (my $result,$url) =
                   4544:             &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
                   4545:                          '','',$newfile);
                   4546:         if ($result ne 'ok') {
1.130     raeburn  4547:             $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46      raeburn  4548:         }
                   4549:     }
                   4550:     return ($url,$error);
                   4551: }
1.43      raeburn  4552: 
1.49      raeburn  4553: sub print_coursecategories {
1.57      raeburn  4554:     my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
                   4555:     my $datatable;
                   4556:     if ($position eq 'top') {
                   4557:         my $toggle_cats_crs = ' ';
                   4558:         my $toggle_cats_dom = ' checked="checked" ';
                   4559:         my $can_cat_crs = ' ';
                   4560:         my $can_cat_dom = ' checked="checked" ';
1.120     raeburn  4561:         my $toggle_catscomm_comm = ' ';
                   4562:         my $toggle_catscomm_dom = ' checked="checked" ';
                   4563:         my $can_catcomm_comm = ' ';
                   4564:         my $can_catcomm_dom = ' checked="checked" ';
                   4565: 
1.57      raeburn  4566:         if (ref($settings) eq 'HASH') {
                   4567:             if ($settings->{'togglecats'} eq 'crs') {
                   4568:                 $toggle_cats_crs = $toggle_cats_dom;
                   4569:                 $toggle_cats_dom = ' ';
                   4570:             }
                   4571:             if ($settings->{'categorize'} eq 'crs') {
                   4572:                 $can_cat_crs = $can_cat_dom;
                   4573:                 $can_cat_dom = ' ';
                   4574:             }
1.120     raeburn  4575:             if ($settings->{'togglecatscomm'} eq 'comm') {
                   4576:                 $toggle_catscomm_comm = $toggle_catscomm_dom;
                   4577:                 $toggle_catscomm_dom = ' ';
                   4578:             }
                   4579:             if ($settings->{'categorizecomm'} eq 'comm') {
                   4580:                 $can_catcomm_comm = $can_catcomm_dom;
                   4581:                 $can_catcomm_dom = ' ';
                   4582:             }
1.57      raeburn  4583:         }
                   4584:         my %title = &Apache::lonlocal::texthash (
1.120     raeburn  4585:                      togglecats     => 'Show/Hide a course in catalog',
                   4586:                      togglecatscomm => 'Show/Hide a community in catalog',
                   4587:                      categorize     => 'Assign a category to a course',
                   4588:                      categorizecomm => 'Assign a category to a community',
1.57      raeburn  4589:                     );
                   4590:         my %level = &Apache::lonlocal::texthash (
1.120     raeburn  4591:                      dom  => 'Set in Domain',
                   4592:                      crs  => 'Set in Course',
                   4593:                      comm => 'Set in Community',
1.57      raeburn  4594:                     );
                   4595:         $datatable = '<tr class="LC_odd_row">'.
                   4596:                   '<td>'.$title{'togglecats'}.'</td>'.
                   4597:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   4598:                   '<input type="radio" name="togglecats"'.
                   4599:                   $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   4600:                   '<label><input type="radio" name="togglecats"'.
                   4601:                   $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
                   4602:                   '</tr><tr>'.
                   4603:                   '<td>'.$title{'categorize'}.'</td>'.
                   4604:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
                   4605:                   '<label><input type="radio" name="categorize"'.
                   4606:                   $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   4607:                   '<label><input type="radio" name="categorize"'.
                   4608:                   $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120     raeburn  4609:                   '</tr><tr class="LC_odd_row">'.
                   4610:                   '<td>'.$title{'togglecatscomm'}.'</td>'.
                   4611:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   4612:                   '<input type="radio" name="togglecatscomm"'.
                   4613:                   $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   4614:                   '<label><input type="radio" name="togglecatscomm"'.
                   4615:                   $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
                   4616:                   '</tr><tr>'.
                   4617:                   '<td>'.$title{'categorizecomm'}.'</td>'.
                   4618:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
                   4619:                   '<label><input type="radio" name="categorizecomm"'.
                   4620:                   $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   4621:                   '<label><input type="radio" name="categorizecomm"'.
                   4622:                   $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57      raeburn  4623:                   '</tr>';
1.120     raeburn  4624:         $$rowtotal += 4;
1.57      raeburn  4625:     } else {
                   4626:         my $css_class;
                   4627:         my $itemcount = 1;
                   4628:         my $cathash; 
                   4629:         if (ref($settings) eq 'HASH') {
                   4630:             $cathash = $settings->{'cats'};
                   4631:         }
                   4632:         if (ref($cathash) eq 'HASH') {
                   4633:             my (@cats,@trails,%allitems,%idx,@jsarray);
                   4634:             &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
                   4635:                                                    \%allitems,\%idx,\@jsarray);
                   4636:             my $maxdepth = scalar(@cats);
                   4637:             my $colattrib = '';
                   4638:             if ($maxdepth > 2) {
                   4639:                 $colattrib = ' colspan="2" ';
                   4640:             }
                   4641:             my @path;
                   4642:             if (@cats > 0) {
                   4643:                 if (ref($cats[0]) eq 'ARRAY') {
                   4644:                     my $numtop = @{$cats[0]};
                   4645:                     my $maxnum = $numtop;
1.120     raeburn  4646:                     my %default_names = (
                   4647:                           instcode    => &mt('Official courses'),
                   4648:                           communities => &mt('Communities'),
                   4649:                     );
                   4650: 
                   4651:                     if ((!grep(/^instcode$/,@{$cats[0]})) || 
                   4652:                         ($cathash->{'instcode::0'} eq '') ||
                   4653:                         (!grep(/^communities$/,@{$cats[0]})) || 
                   4654:                         ($cathash->{'communities::0'} eq '')) {
1.57      raeburn  4655:                         $maxnum ++;
                   4656:                     }
                   4657:                     my $lastidx;
                   4658:                     for (my $i=0; $i<$numtop; $i++) {
                   4659:                         my $parent = $cats[0][$i];
                   4660:                         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   4661:                         my $item = &escape($parent).'::0';
                   4662:                         my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
                   4663:                         $lastidx = $idx{$item};
                   4664:                         $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
                   4665:                                       .'<select name="'.$item.'"'.$chgstr.'>';
                   4666:                         for (my $k=0; $k<=$maxnum; $k++) {
                   4667:                             my $vpos = $k+1;
                   4668:                             my $selstr;
                   4669:                             if ($k == $i) {
                   4670:                                 $selstr = ' selected="selected" ';
                   4671:                             }
                   4672:                             $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   4673:                         }
1.214     raeburn  4674:                         $datatable .= '</select></span></td><td>';
1.120     raeburn  4675:                         if ($parent eq 'instcode' || $parent eq 'communities') {
                   4676:                             $datatable .=  '<span class="LC_nobreak">'
                   4677:                                            .$default_names{$parent}.'</span>';
                   4678:                             if ($parent eq 'instcode') {
                   4679:                                 $datatable .= '<br /><span class="LC_nobreak">('
                   4680:                                               .&mt('with institutional codes')
                   4681:                                               .')</span></td><td'.$colattrib.'>';
                   4682:                             } else {
                   4683:                                 $datatable .= '<table><tr><td>';
                   4684:                             }
                   4685:                             $datatable .= '<span class="LC_nobreak">'
                   4686:                                           .'<label><input type="radio" name="'
                   4687:                                           .$parent.'" value="1" checked="checked" />'
                   4688:                                           .&mt('Display').'</label>';
                   4689:                             if ($parent eq 'instcode') {
                   4690:                                 $datatable .= '&nbsp;';
                   4691:                             } else {
                   4692:                                 $datatable .= '</span></td></tr><tr><td>'
                   4693:                                               .'<span class="LC_nobreak">';
                   4694:                             }
                   4695:                             $datatable .= '<label><input type="radio" name="'
                   4696:                                           .$parent.'" value="0" />'
                   4697:                                           .&mt('Do not display').'</label></span>';
                   4698:                             if ($parent eq 'communities') {
                   4699:                                 $datatable .= '</td></tr></table>';
                   4700:                             }
                   4701:                             $datatable .= '</td>';
1.57      raeburn  4702:                         } else {
                   4703:                             $datatable .= $parent
1.214     raeburn  4704:                                           .'&nbsp;<span class="LC_nobreak"><label>'
                   4705:                                           .'<input type="checkbox" name="deletecategory" '
1.57      raeburn  4706:                                           .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
                   4707:                         }
                   4708:                         my $depth = 1;
                   4709:                         push(@path,$parent);
                   4710:                         $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
                   4711:                         pop(@path);
                   4712:                         $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
                   4713:                         $itemcount ++;
                   4714:                     }
1.48      raeburn  4715:                     $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57      raeburn  4716:                     my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
                   4717:                     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48      raeburn  4718:                     for (my $k=0; $k<=$maxnum; $k++) {
                   4719:                         my $vpos = $k+1;
                   4720:                         my $selstr;
1.57      raeburn  4721:                         if ($k == $numtop) {
1.48      raeburn  4722:                             $selstr = ' selected="selected" ';
                   4723:                         }
                   4724:                         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   4725:                     }
1.59      bisitz   4726:                     $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').'&nbsp;'
1.57      raeburn  4727:                                   .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
                   4728:                                   .'</tr>'."\n";
1.48      raeburn  4729:                     $itemcount ++;
1.120     raeburn  4730:                     foreach my $default ('instcode','communities') {
                   4731:                         if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
                   4732:                             $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   4733:                             my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
                   4734:                             $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
                   4735:                                           '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
                   4736:                             for (my $k=0; $k<=$maxnum; $k++) {
                   4737:                                 my $vpos = $k+1;
                   4738:                                 my $selstr;
                   4739:                                 if ($k == $maxnum) {
                   4740:                                     $selstr = ' selected="selected" ';
                   4741:                                 }
                   4742:                                 $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57      raeburn  4743:                             }
1.120     raeburn  4744:                             $datatable .= '</select></span></td>'.
                   4745:                                           '<td><span class="LC_nobreak">'.
                   4746:                                           $default_names{$default}.'</span>';
                   4747:                             if ($default eq 'instcode') {
                   4748:                                 $datatable .= '<br /><span class="LC_nobreak">(' 
                   4749:                                               .&mt('with institutional codes').')</span>';
                   4750:                             }
                   4751:                             $datatable .= '</td>'
                   4752:                                           .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
                   4753:                                           .&mt('Display').'</label>&nbsp;'
                   4754:                                           .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
                   4755:                                           .&mt('Do not display').'</label></span></td></tr>';
1.48      raeburn  4756:                         }
                   4757:                     }
                   4758:                 }
1.57      raeburn  4759:             } else {
                   4760:                 $datatable .= &initialize_categories($itemcount);
1.48      raeburn  4761:             }
                   4762:         } else {
1.57      raeburn  4763:             $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[0]->{'col2'}.'</td>'
                   4764:                           .&initialize_categories($itemcount);
1.48      raeburn  4765:         }
1.57      raeburn  4766:         $$rowtotal += $itemcount;
1.48      raeburn  4767:     }
                   4768:     return $datatable;
                   4769: }
                   4770: 
1.69      raeburn  4771: sub print_serverstatuses {
                   4772:     my ($dom,$settings,$rowtotal) = @_;
                   4773:     my $datatable;
                   4774:     my @pages = &serverstatus_pages();
                   4775:     my (%namedaccess,%machineaccess);
                   4776:     foreach my $type (@pages) {
                   4777:         $namedaccess{$type} = '';
                   4778:         $machineaccess{$type}= '';
                   4779:     }
                   4780:     if (ref($settings) eq 'HASH') {
                   4781:         foreach my $type (@pages) {
                   4782:             if (exists($settings->{$type})) {
                   4783:                 if (ref($settings->{$type}) eq 'HASH') {
                   4784:                     foreach my $key (keys(%{$settings->{$type}})) {
                   4785:                         if ($key eq 'namedusers') {
                   4786:                             $namedaccess{$type} = $settings->{$type}->{$key};
                   4787:                         } elsif ($key eq 'machines') {
                   4788:                             $machineaccess{$type} = $settings->{$type}->{$key};
                   4789:                         }
                   4790:                     }
                   4791:                 }
                   4792:             }
                   4793:         }
                   4794:     }
1.81      raeburn  4795:     my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69      raeburn  4796:     my $rownum = 0;
                   4797:     my $css_class;
                   4798:     foreach my $type (@pages) {
                   4799:         $rownum ++;
                   4800:         $css_class = $rownum%2?' class="LC_odd_row"':'';
                   4801:         $datatable .= '<tr'.$css_class.'>'.
                   4802:                       '<td><span class="LC_nobreak">'.
                   4803:                       $titles->{$type}.'</span></td>'.
                   4804:                       '<td class="LC_left_item">'.
                   4805:                       '<input type="text" name="'.$type.'_namedusers" '.
                   4806:                       'value="'.$namedaccess{$type}.'" size="30" /></td>'.
                   4807:                       '<td class="LC_right_item">'.
                   4808:                       '<span class="LC_nobreak">'.
                   4809:                       '<input type="text" name="'.$type.'_machines" '.
                   4810:                       'value="'.$machineaccess{$type}.'" size="10" />'.
                   4811:                       '</td></tr>'."\n";
                   4812:     }
                   4813:     $$rowtotal += $rownum;
                   4814:     return $datatable;
                   4815: }
                   4816: 
                   4817: sub serverstatus_pages {
                   4818:     return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.189     raeburn  4819:             'checksums','clusterstatus','metadata_keywords','metadata_harvest',
1.221     raeburn  4820:             'takeoffline','takeonline','showenv','toggledebug','ping','domconf',
1.229     raeburn  4821:             'uniquecodes','diskusage');
1.69      raeburn  4822: }
                   4823: 
1.49      raeburn  4824: sub coursecategories_javascript {
                   4825:     my ($settings) = @_;
1.57      raeburn  4826:     my ($output,$jstext,$cathash);
1.49      raeburn  4827:     if (ref($settings) eq 'HASH') {
1.57      raeburn  4828:         $cathash = $settings->{'cats'};
                   4829:     }
                   4830:     if (ref($cathash) eq 'HASH') {
1.49      raeburn  4831:         my (@cats,@jsarray,%idx);
1.57      raeburn  4832:         &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49      raeburn  4833:         if (@jsarray > 0) {
                   4834:             $jstext = '    var categories = Array('.scalar(@jsarray).');'."\n";
                   4835:             for (my $i=0; $i<@jsarray; $i++) {
                   4836:                 if (ref($jsarray[$i]) eq 'ARRAY') {
                   4837:                     my $catstr = join('","',@{$jsarray[$i]});
                   4838:                     $jstext .= '    categories['.$i.'] = Array("'.$catstr.'");'."\n";
                   4839:                 }
                   4840:             }
                   4841:         }
                   4842:     } else {
                   4843:         $jstext  = '    var categories = Array(1);'."\n".
                   4844:                    '    categories[0] = Array("instcode_pos");'."\n"; 
                   4845:     }
1.120     raeburn  4846:     my $instcode_reserved = &mt('The name: "instcode" is a reserved category');
                   4847:     my $communities_reserved = &mt('The name: "communities" is a reserved category');
                   4848:     my $choose_again = '\\n'.&mt('Please use a different name for the new top level category'); 
1.49      raeburn  4849:     $output = <<"ENDSCRIPT";
                   4850: <script type="text/javascript">
1.109     raeburn  4851: // <![CDATA[
1.49      raeburn  4852: function reorderCats(form,parent,item,idx) {
                   4853:     var changedVal;
                   4854: $jstext
                   4855:     var newpos = 'addcategory_pos';
                   4856:     var current = new Array;
                   4857:     if (parent == '') {
                   4858:         var has_instcode = 0;
                   4859:         var maxtop = categories[idx].length;
                   4860:         for (var j=0; j<maxtop; j++) {
                   4861:             if (categories[idx][j] == 'instcode::0') {
                   4862:                 has_instcode == 1;
                   4863:             }
                   4864:         }
                   4865:         if (has_instcode == 0) {
                   4866:             categories[idx][maxtop] = 'instcode_pos';
                   4867:         }
                   4868:     } else {
                   4869:         newpos += '_'+parent;
                   4870:     }
                   4871:     var maxh = 1 + categories[idx].length;
                   4872:     var current = new Array;
                   4873:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
                   4874:     if (item == newpos) {
                   4875:         changedVal = newitemVal;
                   4876:     } else {
                   4877:         changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
                   4878:         current[newitemVal] = newpos;
                   4879:     }
                   4880:     for (var i=0; i<categories[idx].length; i++) {
                   4881:         var elementName = categories[idx][i];
                   4882:         if (elementName != item) {
                   4883:             if (form.elements[elementName]) {
                   4884:                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   4885:                 current[currVal] = elementName;
                   4886:             }
                   4887:         }
                   4888:     }
                   4889:     var oldVal;
                   4890:     for (var j=0; j<maxh; j++) {
                   4891:         if (current[j] == undefined) {
                   4892:             oldVal = j;
                   4893:         }
                   4894:     }
                   4895:     if (oldVal < changedVal) {
                   4896:         for (var k=oldVal+1; k<=changedVal ; k++) {
                   4897:            var elementName = current[k];
                   4898:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   4899:         }
                   4900:     } else {
                   4901:         for (var k=changedVal; k<oldVal; k++) {
                   4902:             var elementName = current[k];
                   4903:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   4904:         }
                   4905:     }
                   4906:     return;
                   4907: }
1.120     raeburn  4908: 
                   4909: function categoryCheck(form) {
                   4910:     if (form.elements['addcategory_name'].value == 'instcode') {
                   4911:         alert('$instcode_reserved\\n$choose_again');
                   4912:         return false;
                   4913:     }
                   4914:     if (form.elements['addcategory_name'].value == 'communities') {
                   4915:         alert('$communities_reserved\\n$choose_again');
                   4916:         return false;
                   4917:     }
                   4918:     return true;
                   4919: }
                   4920: 
1.109     raeburn  4921: // ]]>
1.49      raeburn  4922: </script>
                   4923: 
                   4924: ENDSCRIPT
                   4925:     return $output;
                   4926: }
                   4927: 
1.48      raeburn  4928: sub initialize_categories {
                   4929:     my ($itemcount) = @_;
1.120     raeburn  4930:     my ($datatable,$css_class,$chgstr);
                   4931:     my %default_names = (
                   4932:                       instcode    => 'Official courses (with institutional codes)',
                   4933:                       communities => 'Communities',
                   4934:                         );
                   4935:     my $select0 = ' selected="selected"';
                   4936:     my $select1 = '';
                   4937:     foreach my $default ('instcode','communities') {
                   4938:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   4939:         $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
                   4940:         if ($default eq 'communities') {
                   4941:             $select1 = $select0;
                   4942:             $select0 = '';
                   4943:         }
                   4944:         $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
                   4945:                      .'<select name="'.$default.'_pos">'
                   4946:                      .'<option value="0"'.$select0.'>1</option>'
                   4947:                      .'<option value="1"'.$select1.'>2</option>'
                   4948:                      .'<option value="2">3</option></select>&nbsp;'
                   4949:                      .$default_names{$default}
                   4950:                      .'</span></td><td><span class="LC_nobreak">'
                   4951:                      .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
                   4952:                      .&mt('Display').'</label>&nbsp;<label>'
                   4953:                      .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48      raeburn  4954:                  .'</label></span></td></tr>';
1.120     raeburn  4955:         $itemcount ++;
                   4956:     }
1.48      raeburn  4957:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49      raeburn  4958:     $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48      raeburn  4959:     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120     raeburn  4960:                   .'<select name="addcategory_pos"'.$chgstr.'>'
                   4961:                   .'<option value="0">1</option>'
                   4962:                   .'<option value="1">2</option>'
                   4963:                   .'<option value="2" selected="selected">3</option></select>&nbsp;'
1.48      raeburn  4964:                   .&mt('Add category').'</td><td>'.&mt('Name:')
                   4965:                   .'&nbsp;<input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
                   4966:     return $datatable;
                   4967: }
                   4968: 
                   4969: sub build_category_rows {
1.49      raeburn  4970:     my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
                   4971:     my ($text,$name,$item,$chgstr);
1.48      raeburn  4972:     if (ref($cats) eq 'ARRAY') {
                   4973:         my $maxdepth = scalar(@{$cats});
                   4974:         if (ref($cats->[$depth]) eq 'HASH') {
                   4975:             if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
                   4976:                 my $numchildren = @{$cats->[$depth]{$parent}};
                   4977:                 my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204     raeburn  4978:                 $text .= '<td><table class="LC_data_table">';
1.49      raeburn  4979:                 my ($idxnum,$parent_name,$parent_item);
                   4980:                 my $higher = $depth - 1;
                   4981:                 if ($higher == 0) {
                   4982:                     $parent_name = &escape($parent).'::'.$higher;
                   4983:                 } else {
                   4984:                     if (ref($path) eq 'ARRAY') {
                   4985:                         $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
                   4986:                     }
                   4987:                 }
                   4988:                 $parent_item = 'addcategory_pos_'.$parent_name;
1.48      raeburn  4989:                 for (my $j=0; $j<=$numchildren; $j++) {
1.49      raeburn  4990:                     if ($j < $numchildren) {
1.48      raeburn  4991:                         $name = $cats->[$depth]{$parent}[$j];
                   4992:                         $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49      raeburn  4993:                         $idxnum = $idx->{$item};
                   4994:                     } else {
                   4995:                         $name = $parent_name;
                   4996:                         $item = $parent_item;
1.48      raeburn  4997:                     }
1.49      raeburn  4998:                     $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
                   4999:                     $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48      raeburn  5000:                     for (my $i=0; $i<=$numchildren; $i++) {
                   5001:                         my $vpos = $i+1;
                   5002:                         my $selstr;
                   5003:                         if ($j == $i) {
                   5004:                             $selstr = ' selected="selected" ';
                   5005:                         }
                   5006:                         $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
                   5007:                     }
                   5008:                     $text .= '</select>&nbsp;';
                   5009:                     if ($j < $numchildren) {
                   5010:                         my $deeper = $depth+1;
                   5011:                         $text .= $name.'&nbsp;'
                   5012:                                  .'<label><input type="checkbox" name="deletecategory" value="'
                   5013:                                  .$item.'" />'.&mt('Delete').'</label></span></td><td>';
                   5014:                         if(ref($path) eq 'ARRAY') {
                   5015:                             push(@{$path},$name);
1.49      raeburn  5016:                             $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48      raeburn  5017:                             pop(@{$path});
                   5018:                         }
                   5019:                     } else {
1.59      bisitz   5020:                         $text .= &mt('Add subcategory:').'&nbsp;</span><input type="textbox" size="20" name="addcategory_name_';
1.48      raeburn  5021:                         if ($j == $numchildren) {
                   5022:                             $text .= $name;
                   5023:                         } else {
                   5024:                             $text .= $item;
                   5025:                         }
                   5026:                         $text .= '" value="" />';
                   5027:                     }
                   5028:                     $text .= '</td></tr>';
                   5029:                 }
                   5030:                 $text .= '</table></td>';
                   5031:             } else {
                   5032:                 my $higher = $depth-1;
                   5033:                 if ($higher == 0) {
                   5034:                     $name = &escape($parent).'::'.$higher;
                   5035:                 } else {
                   5036:                     if (ref($path) eq 'ARRAY') {
                   5037:                         $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
                   5038:                     }
                   5039:                 }
                   5040:                 my $colspan;
                   5041:                 if ($parent ne 'instcode') {
                   5042:                     $colspan = $maxdepth - $depth - 1;
                   5043:                     $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
                   5044:                 }
                   5045:             }
                   5046:         }
                   5047:     }
                   5048:     return $text;
                   5049: }
                   5050: 
1.33      raeburn  5051: sub modifiable_userdata_row {
1.228     raeburn  5052:     my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref) = @_;
                   5053:     my ($role,$rolename,$statustype);
                   5054:     $role = $item;
1.224     raeburn  5055:     if ($context eq 'cancreate') {
1.228     raeburn  5056:         if ($item =~ /^emailusername_(.+)$/) {
                   5057:             $statustype = $1;
                   5058:             $role = 'emailusername';
                   5059:             if (ref($usertypes) eq 'HASH') {
                   5060:                 if ($usertypes->{$statustype}) {
                   5061:                     $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
                   5062:                 } else {
                   5063:                     $rolename = &mt('Data provided by user');
                   5064:                 }
                   5065:             }
1.224     raeburn  5066:         }
                   5067:     } elsif ($context eq 'selfcreate') {
1.63      raeburn  5068:         if (ref($usertypes) eq 'HASH') {
                   5069:             $rolename = $usertypes->{$role};
                   5070:         } else {
                   5071:             $rolename = $role;
                   5072:         }
1.33      raeburn  5073:     } else {
1.63      raeburn  5074:         if ($role eq 'cr') {
                   5075:             $rolename = &mt('Custom role');
                   5076:         } else {
                   5077:             $rolename = &Apache::lonnet::plaintext($role);
                   5078:         }
1.33      raeburn  5079:     }
1.224     raeburn  5080:     my (@fields,%fieldtitles);
                   5081:     if (ref($fieldsref) eq 'ARRAY') {
                   5082:         @fields = @{$fieldsref};
                   5083:     } else {
                   5084:         @fields = ('lastname','firstname','middlename','generation',
                   5085:                    'permanentemail','id');
                   5086:     }
                   5087:     if ((ref($titlesref) eq 'HASH')) {
                   5088:         %fieldtitles = %{$titlesref};
                   5089:     } else {
                   5090:         %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
                   5091:     }
1.33      raeburn  5092:     my $output;
                   5093:     my $css_class = $rowcount%2?' class="LC_odd_row"':'';
                   5094:     $output = '<tr '.$css_class.'>'.
                   5095:               '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
                   5096:               '<td class="LC_left_item" colspan="2"><table>';
                   5097:     my $rem;
                   5098:     my %checks;
                   5099:     if (ref($settings) eq 'HASH') {
                   5100:         if (ref($settings->{$context}) eq 'HASH') {
                   5101:             if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.228     raeburn  5102:                 my $hashref = $settings->{$context}->{$role};
                   5103:                 if ($role eq 'emailusername') {
                   5104:                     if ($statustype) {
                   5105:                         if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
                   5106:                             $hashref = $settings->{$context}->{$role}->{$statustype};
                   5107:                             if (ref($hashref) eq 'HASH') { 
                   5108:                                 foreach my $field (@fields) {
                   5109:                                     if ($hashref->{$field}) {
                   5110:                                         $checks{$field} = $hashref->{$field};
                   5111:                                     }
                   5112:                                 }
                   5113:                             }
                   5114:                         }
                   5115:                     }
                   5116:                 } else {
                   5117:                     if (ref($hashref) eq 'HASH') {
                   5118:                         foreach my $field (@fields) {
                   5119:                             if ($hashref->{$field}) {
                   5120:                                 $checks{$field} = ' checked="checked" ';
                   5121:                             }
                   5122:                         }
1.33      raeburn  5123:                     }
                   5124:                 }
                   5125:             }
                   5126:         }
                   5127:     }
1.228     raeburn  5128:      
1.33      raeburn  5129:     for (my $i=0; $i<@fields; $i++) {
                   5130:         my $rem = $i%($numinrow);
                   5131:         if ($rem == 0) {
                   5132:             if ($i > 0) {
                   5133:                 $output .= '</tr>';
                   5134:             }
                   5135:             $output .= '<tr>';
                   5136:         }
                   5137:         my $check = ' ';
1.228     raeburn  5138:         unless ($role eq 'emailusername') {
                   5139:             if (exists($checks{$fields[$i]})) {
                   5140:                 $check = $checks{$fields[$i]}
                   5141:             } else {
                   5142:                 if ($role eq 'st') {
                   5143:                     if (ref($settings) ne 'HASH') {
                   5144:                         $check = ' checked="checked" '; 
                   5145:                     }
1.33      raeburn  5146:                 }
                   5147:             }
                   5148:         }
                   5149:         $output .= '<td class="LC_left_item">'.
1.228     raeburn  5150:                    '<span class="LC_nobreak">';
                   5151:         if ($role eq 'emailusername') {
                   5152:             unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
                   5153:                 $checks{$fields[$i]} = 'omit';
                   5154:             }
                   5155:             foreach my $option ('required','optional','omit') {
                   5156:                 my $checked='';
                   5157:                 if ($checks{$fields[$i]} eq $option) {
                   5158:                     $checked='checked="checked" ';
                   5159:                 }
                   5160:                 $output .= '<label>'.
                   5161:                            '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
                   5162:                            &mt($option).'</label>'.('&nbsp;' x2);
                   5163:             }
                   5164:             $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
                   5165:         } else {
                   5166:             $output .= '<label>'.
                   5167:                        '<input type="checkbox" name="canmodify_'.$role.'" '.
                   5168:                        'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
                   5169:                        '</label>';
                   5170:         }
                   5171:         $output .= '</span></td>';
1.33      raeburn  5172:         $rem = @fields%($numinrow);
                   5173:     }
                   5174:     my $colsleft = $numinrow - $rem;
                   5175:     if ($colsleft > 1 ) {
                   5176:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   5177:                    '&nbsp;</td>';
                   5178:     } elsif ($colsleft == 1) {
                   5179:         $output .= '<td class="LC_left_item">&nbsp;</td>';
                   5180:     }
                   5181:     $output .= '</tr></table></td></tr>';
                   5182:     return $output;
                   5183: }
1.28      raeburn  5184: 
1.93      raeburn  5185: sub insttypes_row {
1.224     raeburn  5186:     my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rownum) = @_;
1.93      raeburn  5187:     my %lt = &Apache::lonlocal::texthash (
                   5188:                       cansearch => 'Users allowed to search',
                   5189:                       statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131     raeburn  5190:                       lockablenames => 'User preference to lock name',
1.93      raeburn  5191:              );
                   5192:     my $showdom;
                   5193:     if ($context eq 'cansearch') {
                   5194:         $showdom = ' ('.$dom.')';
                   5195:     }
1.165     raeburn  5196:     my $class = 'LC_left_item';
                   5197:     if ($context eq 'statustocreate') {
                   5198:         $class = 'LC_right_item';
                   5199:     }
1.224     raeburn  5200:     my $css_class = ' class="LC_odd_row"';
                   5201:     if ($rownum ne '') { 
                   5202:         $css_class = ($rownum%2? ' class="LC_odd_row"':'');
                   5203:     }
                   5204:     my $output = '<tr'.$css_class.'>'.
                   5205:                  '<td>'.$lt{$context}.$showdom.
                   5206:                  '</td><td class="'.$class.'" colspan="2"><table>';
1.26      raeburn  5207:     my $rem;
                   5208:     if (ref($types) eq 'ARRAY') {
                   5209:         for (my $i=0; $i<@{$types}; $i++) {
                   5210:             if (defined($usertypes->{$types->[$i]})) {
                   5211:                 my $rem = $i%($numinrow);
                   5212:                 if ($rem == 0) {
                   5213:                     if ($i > 0) {
                   5214:                         $output .= '</tr>';
                   5215:                     }
                   5216:                     $output .= '<tr>';
1.23      raeburn  5217:                 }
1.26      raeburn  5218:                 my $check = ' ';
1.99      raeburn  5219:                 if (ref($settings) eq 'HASH') {
                   5220:                     if (ref($settings->{$context}) eq 'ARRAY') {
                   5221:                         if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
                   5222:                             $check = ' checked="checked" ';
                   5223:                         }
                   5224:                     } elsif ($context eq 'statustocreate') {
1.26      raeburn  5225:                         $check = ' checked="checked" ';
                   5226:                     }
1.23      raeburn  5227:                 }
1.26      raeburn  5228:                 $output .= '<td class="LC_left_item">'.
                   5229:                            '<span class="LC_nobreak"><label>'.
1.93      raeburn  5230:                            '<input type="checkbox" name="'.$context.'" '.
1.26      raeburn  5231:                            'value="'.$types->[$i].'"'.$check.'/>'.
                   5232:                            $usertypes->{$types->[$i]}.'</label></span></td>';
1.23      raeburn  5233:             }
                   5234:         }
1.26      raeburn  5235:         $rem = @{$types}%($numinrow);
1.23      raeburn  5236:     }
                   5237:     my $colsleft = $numinrow - $rem;
1.131     raeburn  5238:     if (($rem == 0) && (@{$types} > 0)) {
                   5239:         $output .= '<tr>';
                   5240:     }
1.23      raeburn  5241:     if ($colsleft > 1) {
1.25      raeburn  5242:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23      raeburn  5243:     } else {
1.25      raeburn  5244:         $output .= '<td class="LC_left_item">';
1.23      raeburn  5245:     }
                   5246:     my $defcheck = ' ';
1.99      raeburn  5247:     if (ref($settings) eq 'HASH') {  
                   5248:         if (ref($settings->{$context}) eq 'ARRAY') {
                   5249:             if (grep(/^default$/,@{$settings->{$context}})) {
                   5250:                 $defcheck = ' checked="checked" ';
                   5251:             }
                   5252:         } elsif ($context eq 'statustocreate') {
1.26      raeburn  5253:             $defcheck = ' checked="checked" ';
                   5254:         }
1.23      raeburn  5255:     }
1.25      raeburn  5256:     $output .= '<span class="LC_nobreak"><label>'.
1.93      raeburn  5257:                '<input type="checkbox" name="'.$context.'" '.
1.25      raeburn  5258:                'value="default"'.$defcheck.'/>'.
                   5259:                $othertitle.'</label></span></td>'.
                   5260:                '</tr></table></td></tr>';
                   5261:     return $output;
1.23      raeburn  5262: }
                   5263: 
                   5264: sub sorted_searchtitles {
                   5265:     my %searchtitles = &Apache::lonlocal::texthash(
                   5266:                          'uname' => 'username',
                   5267:                          'lastname' => 'last name',
                   5268:                          'lastfirst' => 'last name, first name',
                   5269:                      );
                   5270:     my @titleorder = ('uname','lastname','lastfirst');
                   5271:     return (\%searchtitles,\@titleorder);
                   5272: }
                   5273: 
1.25      raeburn  5274: sub sorted_searchtypes {
                   5275:     my %srchtypes_desc = (
                   5276:                            exact    => 'is exact match',
                   5277:                            contains => 'contains ..',
                   5278:                            begins   => 'begins with ..',
                   5279:                          );
                   5280:     my @srchtypeorder = ('exact','begins','contains');
                   5281:     return (\%srchtypes_desc,\@srchtypeorder);
                   5282: }
                   5283: 
1.3       raeburn  5284: sub usertype_update_row {
                   5285:     my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
                   5286:     my $datatable;
                   5287:     my $numinrow = 4;
                   5288:     foreach my $type (@{$types}) {
                   5289:         if (defined($usertypes->{$type})) {
                   5290:             $$rownums ++;
                   5291:             my $css_class = $$rownums%2?' class="LC_odd_row"':'';
                   5292:             $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
                   5293:                           '</td><td class="LC_left_item"><table>';
                   5294:             for (my $i=0; $i<@{$fields}; $i++) {
                   5295:                 my $rem = $i%($numinrow);
                   5296:                 if ($rem == 0) {
                   5297:                     if ($i > 0) {
                   5298:                         $datatable .= '</tr>';
                   5299:                     }
                   5300:                     $datatable .= '<tr>';
                   5301:                 }
                   5302:                 my $check = ' ';
1.39      raeburn  5303:                 if (ref($settings) eq 'HASH') {
                   5304:                     if (ref($settings->{'fields'}) eq 'HASH') {
                   5305:                         if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
                   5306:                             if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
                   5307:                                 $check = ' checked="checked" ';
                   5308:                             }
1.3       raeburn  5309:                         }
                   5310:                     }
                   5311:                 }
                   5312: 
                   5313:                 if ($i == @{$fields}-1) {
                   5314:                     my $colsleft = $numinrow - $rem;
                   5315:                     if ($colsleft > 1) {
                   5316:                         $datatable .= '<td colspan="'.$colsleft.'">';
                   5317:                     } else {
                   5318:                         $datatable .= '<td>';
                   5319:                     }
                   5320:                 } else {
                   5321:                     $datatable .= '<td>';
                   5322:                 }
1.8       raeburn  5323:                 $datatable .= '<span class="LC_nobreak"><label>'.
                   5324:                               '<input type="checkbox" name="updateable_'.$type.
                   5325:                               '_'.$fields->[$i].'" value="1"'.$check.'/>'.
                   5326:                               $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3       raeburn  5327:             }
                   5328:             $datatable .= '</tr></table></td></tr>';
                   5329:         }
                   5330:     }
                   5331:     return $datatable;
1.1       raeburn  5332: }
                   5333: 
                   5334: sub modify_login {
1.205     raeburn  5335:     my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168     raeburn  5336:     my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
                   5337:         %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
                   5338:     %title = ( coursecatalog => 'Display course catalog',
                   5339:                adminmail => 'Display administrator E-mail address',
1.188     raeburn  5340:                helpdesk  => 'Display "Contact Helpdesk" link',
1.168     raeburn  5341:                newuser => 'Link for visitors to create a user account',
                   5342:                loginheader => 'Log-in box header');
                   5343:     @offon = ('off','on');
1.112     raeburn  5344:     if (ref($domconfig{login}) eq 'HASH') {
                   5345:         if (ref($domconfig{login}{loginvia}) eq 'HASH') {
                   5346:             foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
                   5347:                 $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
                   5348:             }
                   5349:         }
                   5350:     }
1.9       raeburn  5351:     ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
                   5352:                                            \%domconfig,\%loginhash);
1.188     raeburn  5353:     my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42      raeburn  5354:     foreach my $item (@toggles) {
                   5355:         $loginhash{login}{$item} = $env{'form.'.$item};
                   5356:     }
1.41      raeburn  5357:     $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6       raeburn  5358:     if (ref($colchanges{'login'}) eq 'HASH') {  
                   5359:         $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
                   5360:                                          \%loginhash);
                   5361:     }
1.110     raeburn  5362: 
1.149     raeburn  5363:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.128     raeburn  5364:     my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110     raeburn  5365:     if (keys(%servers) > 1) {
                   5366:         foreach my $lonhost (keys(%servers)) {
1.128     raeburn  5367:             next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
                   5368:             if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
                   5369:                 if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
                   5370:                     $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
                   5371:                 } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
                   5372:                     if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
                   5373:                         $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
                   5374:                         $changes{'loginvia'}{$lonhost} = 1;
                   5375:                     } else {
                   5376:                         $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
                   5377:                         $changes{'loginvia'}{$lonhost} = 1;
                   5378:                     }
                   5379:                 } else {
                   5380:                     if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
                   5381:                         $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
                   5382:                         $changes{'loginvia'}{$lonhost} = 1;
                   5383:                     }
                   5384:                 }
                   5385:                 if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
                   5386:                     foreach my $item (@loginvia_attribs) {
                   5387:                         $loginhash{login}{loginvia}{$lonhost}{$item} = '';
                   5388:                     }
                   5389:                 } else {
                   5390:                     foreach my $item (@loginvia_attribs) {
                   5391:                         my $new = $env{'form.'.$lonhost.'_'.$item};
                   5392:                         if (($item eq 'serverpath') && ($new eq 'custom')) {
                   5393:                             $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
                   5394:                             if ($env{'form.'.$lonhost.'_custompath'} eq '') {
                   5395:                                 $new = '/';
                   5396:                             }
                   5397:                         }
                   5398:                         if (($item eq 'custompath') && 
                   5399:                             ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
                   5400:                             $new = '';
                   5401:                         }
                   5402:                         if ($new ne $curr_loginvia{$lonhost}{$item}) {
                   5403:                             $changes{'loginvia'}{$lonhost} = 1;
                   5404:                         }
                   5405:                         if ($item eq 'exempt') {
                   5406:                             $new =~ s/^\s+//;
                   5407:                             $new =~ s/\s+$//;
                   5408:                             my @poss_ips = split(/\s*[,:]\s*/,$new);
                   5409:                             my @okips;
                   5410:                             foreach my $ip (@poss_ips) {
                   5411:                                 if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
                   5412:                                     if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
                   5413:                                         push(@okips,$ip); 
                   5414:                                     }
                   5415:                                 }
                   5416:                             }
                   5417:                             if (@okips > 0) {
                   5418:                                 $new = join(',',@okips); 
                   5419:                             } else {
                   5420:                                 $new = ''; 
                   5421:                             }
                   5422:                         }
                   5423:                         $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
                   5424:                     }
                   5425:                 }
1.112     raeburn  5426:             } else {
1.128     raeburn  5427:                 if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
                   5428:                     $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112     raeburn  5429:                     $changes{'loginvia'}{$lonhost} = 1;
1.128     raeburn  5430:                     foreach my $item (@loginvia_attribs) {
                   5431:                         my $new = $env{'form.'.$lonhost.'_'.$item};
                   5432:                         if (($item eq 'serverpath') && ($new eq 'custom')) {
                   5433:                             if ($env{'form.'.$lonhost.'_custompath'} eq '') {
                   5434:                                 $new = '/';
                   5435:                             }
                   5436:                         }
                   5437:                         if (($item eq 'custompath') && 
                   5438:                             ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
                   5439:                             $new = '';
                   5440:                         }
                   5441:                         $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
                   5442:                     }
1.110     raeburn  5443:                 }
                   5444:             }
                   5445:         }
                   5446:     }
1.119     raeburn  5447: 
1.168     raeburn  5448:     my $servadm = $r->dir_config('lonAdmEMail');
                   5449:     my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
                   5450:     if (ref($domconfig{'login'}) eq 'HASH') {
                   5451:         if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
                   5452:             foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
                   5453:                 if ($lang eq 'nolang') {
                   5454:                     push(@currlangs,$lang);
                   5455:                 } elsif (defined($langchoices{$lang})) {
                   5456:                     push(@currlangs,$lang);
                   5457:                 } else {
                   5458:                     next;
                   5459:                 }
                   5460:             }
                   5461:         }
                   5462:     }
                   5463:     my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
                   5464:     if (@currlangs > 0) {
                   5465:         foreach my $lang (@currlangs) {
                   5466:             if (grep(/^\Q$lang\E$/,@delurls)) {
                   5467:                 $changes{'helpurl'}{$lang} = 1;
                   5468:             } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
                   5469:                 $changes{'helpurl'}{$lang} = 1;
                   5470:                 $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
                   5471:                 push(@newlangs,$lang);
                   5472:             } else {
                   5473:                 $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
                   5474:             }
                   5475:         }
                   5476:     }
                   5477:     unless (grep(/^nolang$/,@currlangs)) {
                   5478:         if ($env{'form.loginhelpurl_nolang.filename'}) {
                   5479:             $changes{'helpurl'}{'nolang'} = 1;
                   5480:             $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
                   5481:             push(@newlangs,'nolang');
                   5482:         }
                   5483:     }
                   5484:     if ($env{'form.loginhelpurl_add_lang'}) {
                   5485:         if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
                   5486:             ($env{'form.loginhelpurl_add_file.filename'})) {
                   5487:             $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
                   5488:             $addedfile = $env{'form.loginhelpurl_add_lang'};
                   5489:         }
                   5490:     }
                   5491:     if ((@newlangs > 0) || ($addedfile)) {
                   5492:         my $error;
                   5493:         my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
                   5494:         if ($configuserok eq 'ok') {
                   5495:             if ($switchserver) {
                   5496:                 $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
                   5497:             } elsif ($author_ok eq 'ok') {
                   5498:                 my @allnew = @newlangs;
                   5499:                 if ($addedfile ne '') {
                   5500:                     push(@allnew,$addedfile);
                   5501:                 }
                   5502:                 foreach my $lang (@allnew) {
                   5503:                     my $formelem = 'loginhelpurl_'.$lang;
                   5504:                     if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
                   5505:                         $formelem = 'loginhelpurl_add_file';
                   5506:                     }
                   5507:                     (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
                   5508:                                                                "help/$lang",'','',$newfile{$lang});
                   5509:                     if ($result eq 'ok') {
                   5510:                         $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
                   5511:                         $changes{'helpurl'}{$lang} = 1;
                   5512:                     } else {
                   5513:                         my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
                   5514:                         $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210     raeburn  5515:                         if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168     raeburn  5516:                             (!grep(/^\Q$lang\E$/,@delurls))) {
                   5517: 
                   5518:                             $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
                   5519:                         }
                   5520:                     }
                   5521:                 }
                   5522:             } else {
                   5523:                 $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);
                   5524:             }
                   5525:         } else {
                   5526:             $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);
                   5527:         }
                   5528:         if ($error) {
                   5529:             &Apache::lonnet::logthis($error);
                   5530:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   5531:         }
                   5532:     }
1.169     raeburn  5533:     &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168     raeburn  5534: 
                   5535:     my $defaulthelpfile = '/adm/loginproblems.html';
                   5536:     my $defaulttext = &mt('Default in use');
                   5537: 
1.1       raeburn  5538:     my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
                   5539:                                              $dom);
                   5540:     if ($putresult eq 'ok') {
1.188     raeburn  5541:         my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42      raeburn  5542:         my %defaultchecked = (
                   5543:                     'coursecatalog' => 'on',
1.188     raeburn  5544:                     'helpdesk'      => 'on',
1.42      raeburn  5545:                     'adminmail'     => 'off',
1.43      raeburn  5546:                     'newuser'       => 'off',
1.42      raeburn  5547:         );
1.55      raeburn  5548:         if (ref($domconfig{'login'}) eq 'HASH') {
                   5549:             foreach my $item (@toggles) {
                   5550:                 if ($defaultchecked{$item} eq 'on') { 
                   5551:                     if (($domconfig{'login'}{$item} eq '0') &&
                   5552:                         ($env{'form.'.$item} eq '1')) {
                   5553:                         $changes{$item} = 1;
                   5554:                     } elsif (($domconfig{'login'}{$item} eq '' ||
                   5555:                               $domconfig{'login'}{$item} eq '1') &&
                   5556:                              ($env{'form.'.$item} eq '0')) {
                   5557:                         $changes{$item} = 1;
                   5558:                     }
                   5559:                 } elsif ($defaultchecked{$item} eq 'off') {
                   5560:                     if (($domconfig{'login'}{$item} eq '1') &&
                   5561:                         ($env{'form.'.$item} eq '0')) {
                   5562:                         $changes{$item} = 1;
                   5563:                     } elsif (($domconfig{'login'}{$item} eq '' ||
                   5564:                               $domconfig{'login'}{$item} eq '0') &&
                   5565:                              ($env{'form.'.$item} eq '1')) {
                   5566:                         $changes{$item} = 1;
                   5567:                     }
1.42      raeburn  5568:                 }
                   5569:             }
1.41      raeburn  5570:         }
1.6       raeburn  5571:         if (keys(%changes) > 0 || $colchgtext) {
1.41      raeburn  5572:             &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212     raeburn  5573:             if (ref($lastactref) eq 'HASH') {
                   5574:                 $lastactref->{'domainconfig'} = 1;
                   5575:             }
1.1       raeburn  5576:             $resulttext = &mt('Changes made:').'<ul>';
                   5577:             foreach my $item (sort(keys(%changes))) {
1.135     bisitz   5578:                 if ($item eq 'loginvia') {
1.112     raeburn  5579:                     if (ref($changes{$item}) eq 'HASH') {
                   5580:                         $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
                   5581:                         foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128     raeburn  5582:                             if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
                   5583:                                 if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
                   5584:                                     my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
                   5585:                                     $protocol = 'http' if ($protocol ne 'https');
                   5586:                                     my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
                   5587: 
                   5588:                                     if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
                   5589:                                         $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
                   5590:                                     } else {
                   5591:                                         $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'}; 
                   5592:                                     }
                   5593:                                     $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
                   5594:                                     if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
                   5595:                                         $resulttext .= '&nbsp;'.&mt('No redirection for clients from following IPs:').'&nbsp;'.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
                   5596:                                     }
                   5597:                                     $resulttext .= '</li>';
                   5598:                                 } else {
                   5599:                                     $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
                   5600:                                 }
1.112     raeburn  5601:                             } else {
1.128     raeburn  5602:                                 $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112     raeburn  5603:                             }
                   5604:                         }
1.128     raeburn  5605:                         $resulttext .= '</ul></li>';
1.112     raeburn  5606:                     }
1.168     raeburn  5607:                 } elsif ($item eq 'helpurl') {
                   5608:                     if (ref($changes{$item}) eq 'HASH') {
                   5609:                         foreach my $lang (sort(keys(%{$changes{$item}}))) {
                   5610:                             if (grep(/^\Q$lang\E$/,@delurls)) {
                   5611:                                 my ($chg,$link);
                   5612:                                 $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
                   5613:                                 if ($lang eq 'nolang') {
                   5614:                                     $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
                   5615:                                 } else {
                   5616:                                     $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
                   5617:                                 }
                   5618:                                 $resulttext .= '<li>'.$chg.'</li>';
                   5619:                             } else {
                   5620:                                 my $chg;
                   5621:                                 if ($lang eq 'nolang') {
                   5622:                                     $chg = &mt('custom log-in help file for no preferred language');
                   5623:                                 } else {
                   5624:                                     $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
                   5625:                                 }
                   5626:                                 $resulttext .= '<li>'.&Apache::loncommon::modal_link(
                   5627:                                                       $loginhash{'login'}{'helpurl'}{$lang}.
                   5628:                                                       '?inhibitmenu=yes',$chg,600,500).
                   5629:                                                '</li>';
                   5630:                             }
                   5631:                         }
                   5632:                     }
1.169     raeburn  5633:                 } elsif ($item eq 'captcha') {
                   5634:                     if (ref($loginhash{'login'}) eq 'HASH') {
1.210     raeburn  5635:                         my $chgtxt;
1.169     raeburn  5636:                         if ($loginhash{'login'}{$item} eq 'notused') {
                   5637:                             $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
                   5638:                         } else {
                   5639:                             my %captchas = &captcha_phrases();
                   5640:                             if ($captchas{$loginhash{'login'}{$item}}) {
                   5641:                                 $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
                   5642:                             } else {
                   5643:                                 $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
                   5644:                             }
                   5645:                         }
                   5646:                         $resulttext .= '<li>'.$chgtxt.'</li>';
                   5647:                     }
                   5648:                 } elsif ($item eq 'recaptchakeys') {
                   5649:                     if (ref($loginhash{'login'}) eq 'HASH') {
                   5650:                         my ($privkey,$pubkey);
                   5651:                         if (ref($loginhash{'login'}{$item}) eq 'HASH') {
                   5652:                             $pubkey = $loginhash{'login'}{$item}{'public'};
                   5653:                             $privkey = $loginhash{'login'}{$item}{'private'};
                   5654:                         }
                   5655:                         my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
                   5656:                         if (!$pubkey) {
                   5657:                             $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
                   5658:                         } else {
                   5659:                             $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
                   5660:                         }
                   5661:                         if (!$privkey) {
                   5662:                             $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
                   5663:                         } else {
                   5664:                             $chgtxt .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
                   5665:                         }
                   5666:                         $chgtxt .= '</ul>';
                   5667:                         $resulttext .= '<li>'.$chgtxt.'</li>';
                   5668:                     }
1.41      raeburn  5669:                 } else {
                   5670:                     $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
                   5671:                 }
1.1       raeburn  5672:             }
1.6       raeburn  5673:             $resulttext .= $colchgtext.'</ul>';
1.1       raeburn  5674:         } else {
                   5675:             $resulttext = &mt('No changes made to log-in page settings');
                   5676:         }
                   5677:     } else {
1.11      albertel 5678:         $resulttext = '<span class="LC_error">'.
                   5679: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  5680:     }
1.6       raeburn  5681:     if ($errors) {
1.9       raeburn  5682:         $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6       raeburn  5683:                        $errors.'</ul>';
                   5684:     }
                   5685:     return $resulttext;
                   5686: }
                   5687: 
                   5688: sub color_font_choices {
                   5689:     my %choices =
                   5690:         &Apache::lonlocal::texthash (
                   5691:             img => "Header",
                   5692:             bgs => "Background colors",
                   5693:             links => "Link colors",
1.55      raeburn  5694:             images => "Images",
1.6       raeburn  5695:             font => "Font color",
1.201     raeburn  5696:             fontmenu => "Font menu",
1.76      raeburn  5697:             pgbg => "Page",
1.6       raeburn  5698:             tabbg => "Header",
                   5699:             sidebg => "Border",
                   5700:             link => "Link",
                   5701:             alink => "Active link",
                   5702:             vlink => "Visited link",
                   5703:         );
                   5704:     return %choices;
                   5705: }
                   5706: 
                   5707: sub modify_rolecolors {
1.205     raeburn  5708:     my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6       raeburn  5709:     my ($resulttext,%rolehash);
                   5710:     $rolehash{'rolecolors'} = {};
1.55      raeburn  5711:     if (ref($domconfig{'rolecolors'}) ne 'HASH') {
                   5712:         if ($domconfig{'rolecolors'} eq '') {
                   5713:             $domconfig{'rolecolors'} = {};
                   5714:         }
                   5715:     }
1.9       raeburn  5716:     my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6       raeburn  5717:                          $domconfig{'rolecolors'},$rolehash{'rolecolors'});
                   5718:     my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
                   5719:                                              $dom);
                   5720:     if ($putresult eq 'ok') {
                   5721:         if (keys(%changes) > 0) {
1.41      raeburn  5722:             &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212     raeburn  5723:             if (ref($lastactref) eq 'HASH') {
                   5724:                 $lastactref->{'domainconfig'} = 1;
                   5725:             }
1.6       raeburn  5726:             $resulttext = &display_colorchgs($dom,\%changes,$roles,
                   5727:                                              $rolehash{'rolecolors'});
                   5728:         } else {
                   5729:             $resulttext = &mt('No changes made to default color schemes');
                   5730:         }
                   5731:     } else {
1.11      albertel 5732:         $resulttext = '<span class="LC_error">'.
                   5733: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.6       raeburn  5734:     }
                   5735:     if ($errors) {
                   5736:         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
                   5737:                        $errors.'</ul>';
                   5738:     }
                   5739:     return $resulttext;
                   5740: }
                   5741: 
                   5742: sub modify_colors {
1.9       raeburn  5743:     my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12      raeburn  5744:     my (%changes,%choices);
1.51      raeburn  5745:     my @bgs;
1.6       raeburn  5746:     my @links = ('link','alink','vlink');
1.41      raeburn  5747:     my @logintext;
1.6       raeburn  5748:     my @images;
                   5749:     my $servadm = $r->dir_config('lonAdmEMail');
                   5750:     my $errors;
1.200     raeburn  5751:     my %defaults;
1.6       raeburn  5752:     foreach my $role (@{$roles}) {
                   5753:         if ($role eq 'login') {
1.12      raeburn  5754:             %choices = &login_choices();
1.41      raeburn  5755:             @logintext = ('textcol','bgcol');
1.12      raeburn  5756:         } else {
                   5757:             %choices = &color_font_choices();
                   5758:         }
                   5759:         if ($role eq 'login') {
1.41      raeburn  5760:             @images = ('img','logo','domlogo','login');
1.51      raeburn  5761:             @bgs = ('pgbg','mainbg','sidebg');
1.6       raeburn  5762:         } else {
                   5763:             @images = ('img');
1.200     raeburn  5764:             @bgs = ('pgbg','tabbg','sidebg');
                   5765:         }
                   5766:         my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
                   5767:         unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
                   5768:             $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
                   5769:         }
                   5770:         if ($role eq 'login') {
                   5771:             foreach my $item (@logintext) {
1.234   ! raeburn  5772:                 $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
        !          5773:                 if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
        !          5774:                     $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
        !          5775:                 }
        !          5776:                 unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.200     raeburn  5777:                     $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
                   5778:                 }
                   5779:             }
                   5780:         } else {
1.234   ! raeburn  5781:             $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
        !          5782:             if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
        !          5783:                 $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
        !          5784:             }
        !          5785:             unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.200     raeburn  5786:                 $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
                   5787:             }
1.6       raeburn  5788:         }
1.200     raeburn  5789:         foreach my $item (@bgs) {
1.234   ! raeburn  5790:             $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
        !          5791:             if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
        !          5792:                 $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
        !          5793:             }
        !          5794:             unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.200     raeburn  5795:                 $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
                   5796:             }
                   5797:         }
                   5798:         foreach my $item (@links) {
1.234   ! raeburn  5799:             $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
        !          5800:             if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
        !          5801:                 $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
        !          5802:             }
        !          5803:             unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.200     raeburn  5804:                 $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
                   5805:             }
1.6       raeburn  5806:         }
1.46      raeburn  5807:         my ($configuserok,$author_ok,$switchserver) = 
                   5808:             &config_check($dom,$confname,$servadm);
1.9       raeburn  5809:         my ($width,$height) = &thumb_dimensions();
1.40      raeburn  5810:         if (ref($domconfig->{$role}) ne 'HASH') {
                   5811:             $domconfig->{$role} = {};
                   5812:         }
1.8       raeburn  5813:         foreach my $img (@images) {
1.70      raeburn  5814:             if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {  
                   5815:                 if (defined($env{'form.login_showlogo_'.$img})) {
                   5816:                     $confhash->{$role}{'showlogo'}{$img} = 1;
                   5817:                 } else { 
                   5818:                     $confhash->{$role}{'showlogo'}{$img} = 0;
                   5819:                 }
                   5820:             } 
1.18      albertel 5821: 	    if ( ! $env{'form.'.$role.'_'.$img.'.filename'} 
                   5822: 		 && !defined($domconfig->{$role}{$img})
                   5823: 		 && !$env{'form.'.$role.'_del_'.$img}
                   5824: 		 && $env{'form.'.$role.'_import_'.$img}) {
                   5825: 		# import the old configured image from the .tab setting
                   5826: 		# if they haven't provided a new one 
                   5827: 		$domconfig->{$role}{$img} = 
                   5828: 		    $env{'form.'.$role.'_import_'.$img};
                   5829: 	    }
1.6       raeburn  5830:             if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9       raeburn  5831:                 my $error;
1.6       raeburn  5832:                 if ($configuserok eq 'ok') {
1.9       raeburn  5833:                     if ($switchserver) {
1.12      raeburn  5834:                         $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9       raeburn  5835:                     } else {
                   5836:                         if ($author_ok eq 'ok') {
                   5837:                             my ($result,$logourl) = 
                   5838:                                 &publishlogo($r,'upload',$role.'_'.$img,
                   5839:                                            $dom,$confname,$img,$width,$height);
                   5840:                             if ($result eq 'ok') {
                   5841:                                 $confhash->{$role}{$img} = $logourl;
1.12      raeburn  5842:                                 $changes{$role}{'images'}{$img} = 1;
1.9       raeburn  5843:                             } else {
1.12      raeburn  5844:                                 $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  5845:                             }
                   5846:                         } else {
1.46      raeburn  5847:                             $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  5848:                         }
                   5849:                     }
                   5850:                 } else {
1.46      raeburn  5851:                     $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  5852:                 }
                   5853:                 if ($error) {
1.8       raeburn  5854:                     &Apache::lonnet::logthis($error);
1.11      albertel 5855:                     $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8       raeburn  5856:                 }
                   5857:             } elsif ($domconfig->{$role}{$img} ne '') {
1.9       raeburn  5858:                 if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
                   5859:                     my $error;
                   5860:                     if ($configuserok eq 'ok') {
                   5861: # is confname an author?
                   5862:                         if ($switchserver eq '') {
                   5863:                             if ($author_ok eq 'ok') {
                   5864:                                 my ($result,$logourl) = 
                   5865:                                &publishlogo($r,'copy',$domconfig->{$role}{$img},
                   5866:                                             $dom,$confname,$img,$width,$height);
                   5867:                                 if ($result eq 'ok') {
                   5868:                                     $confhash->{$role}{$img} = $logourl;
1.18      albertel 5869: 				    $changes{$role}{'images'}{$img} = 1;
1.9       raeburn  5870:                                 }
                   5871:                             }
                   5872:                         }
                   5873:                     }
1.6       raeburn  5874:                 }
                   5875:             }
                   5876:         }
                   5877:         if (ref($domconfig) eq 'HASH') {
                   5878:             if (ref($domconfig->{$role}) eq 'HASH') {
                   5879:                 foreach my $img (@images) {
                   5880:                     if ($domconfig->{$role}{$img} ne '') {
                   5881:                         if ($env{'form.'.$role.'_del_'.$img}) {
                   5882:                             $confhash->{$role}{$img} = '';
1.12      raeburn  5883:                             $changes{$role}{'images'}{$img} = 1;
1.6       raeburn  5884:                         } else {
1.9       raeburn  5885:                             if ($confhash->{$role}{$img} eq '') {
                   5886:                                 $confhash->{$role}{$img} = $domconfig->{$role}{$img};
                   5887:                             }
1.6       raeburn  5888:                         }
                   5889:                     } else {
                   5890:                         if ($env{'form.'.$role.'_del_'.$img}) {
                   5891:                             $confhash->{$role}{$img} = '';
1.12      raeburn  5892:                             $changes{$role}{'images'}{$img} = 1;
1.6       raeburn  5893:                         } 
                   5894:                     }
1.70      raeburn  5895:                     if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
                   5896:                         if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
                   5897:                             if ($confhash->{$role}{'showlogo'}{$img} ne 
                   5898:                                 $domconfig->{$role}{'showlogo'}{$img}) {
                   5899:                                 $changes{$role}{'showlogo'}{$img} = 1; 
                   5900:                             }
                   5901:                         } else {
                   5902:                             if ($confhash->{$role}{'showlogo'}{$img} == 0) {
                   5903:                                 $changes{$role}{'showlogo'}{$img} = 1;
                   5904:                             }
                   5905:                         }
                   5906:                     }
                   5907:                 }
1.6       raeburn  5908:                 if ($domconfig->{$role}{'font'} ne '') {
                   5909:                     if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
                   5910:                         $changes{$role}{'font'} = 1;
                   5911:                     }
                   5912:                 } else {
                   5913:                     if ($confhash->{$role}{'font'}) {
                   5914:                         $changes{$role}{'font'} = 1;
                   5915:                     }
                   5916:                 }
1.107     raeburn  5917:                 if ($role ne 'login') {
                   5918:                     if ($domconfig->{$role}{'fontmenu'} ne '') {
                   5919:                         if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
                   5920:                             $changes{$role}{'fontmenu'} = 1;
                   5921:                         }
                   5922:                     } else {
                   5923:                         if ($confhash->{$role}{'fontmenu'}) {
                   5924:                             $changes{$role}{'fontmenu'} = 1;
                   5925:                         }
1.97      tempelho 5926:                     }
                   5927:                 }
1.6       raeburn  5928:                 foreach my $item (@bgs) {
                   5929:                     if ($domconfig->{$role}{$item} ne '') {
                   5930:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
                   5931:                             $changes{$role}{'bgs'}{$item} = 1;
                   5932:                         } 
                   5933:                     } else {
                   5934:                         if ($confhash->{$role}{$item}) {
                   5935:                             $changes{$role}{'bgs'}{$item} = 1;
                   5936:                         }
                   5937:                     }
                   5938:                 }
                   5939:                 foreach my $item (@links) {
                   5940:                     if ($domconfig->{$role}{$item} ne '') {
                   5941:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
                   5942:                             $changes{$role}{'links'}{$item} = 1;
                   5943:                         }
                   5944:                     } else {
                   5945:                         if ($confhash->{$role}{$item}) {
                   5946:                             $changes{$role}{'links'}{$item} = 1;
                   5947:                         }
                   5948:                     }
                   5949:                 }
1.41      raeburn  5950:                 foreach my $item (@logintext) {
                   5951:                     if ($domconfig->{$role}{$item} ne '') {
                   5952:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
                   5953:                             $changes{$role}{'logintext'}{$item} = 1;
                   5954:                         }
                   5955:                     } else {
                   5956:                         if ($confhash->{$role}{$item}) {
                   5957:                             $changes{$role}{'logintext'}{$item} = 1;
                   5958:                         }
                   5959:                     }
                   5960:                 }
1.6       raeburn  5961:             } else {
                   5962:                 &default_change_checker($role,\@images,\@links,\@bgs,
1.41      raeburn  5963:                                         \@logintext,$confhash,\%changes); 
1.6       raeburn  5964:             }
                   5965:         } else {
                   5966:             &default_change_checker($role,\@images,\@links,\@bgs,
1.41      raeburn  5967:                                     \@logintext,$confhash,\%changes); 
1.6       raeburn  5968:         }
                   5969:     }
                   5970:     return ($errors,%changes);
                   5971: }
                   5972: 
1.46      raeburn  5973: sub config_check {
                   5974:     my ($dom,$confname,$servadm) = @_;
                   5975:     my ($configuserok,$author_ok,$switchserver,%currroles);
                   5976:     my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
                   5977:     ($configuserok,%currroles) = &check_configuser($uhome,$dom,
                   5978:                                                    $confname,$servadm);
                   5979:     if ($configuserok eq 'ok') {
                   5980:         $switchserver = &check_switchserver($dom,$confname);
                   5981:         if ($switchserver eq '') {
                   5982:             $author_ok = &check_authorstatus($dom,$confname,%currroles);
                   5983:         }
                   5984:     }
                   5985:     return ($configuserok,$author_ok,$switchserver);
                   5986: }
                   5987: 
1.6       raeburn  5988: sub default_change_checker {
1.41      raeburn  5989:     my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6       raeburn  5990:     foreach my $item (@{$links}) {
                   5991:         if ($confhash->{$role}{$item}) {
                   5992:             $changes->{$role}{'links'}{$item} = 1;
                   5993:         }
                   5994:     }
                   5995:     foreach my $item (@{$bgs}) {
                   5996:         if ($confhash->{$role}{$item}) {
                   5997:             $changes->{$role}{'bgs'}{$item} = 1;
                   5998:         }
                   5999:     }
1.41      raeburn  6000:     foreach my $item (@{$logintext}) {
                   6001:         if ($confhash->{$role}{$item}) {
                   6002:             $changes->{$role}{'logintext'}{$item} = 1;
                   6003:         }
                   6004:     }
1.6       raeburn  6005:     foreach my $img (@{$images}) {
                   6006:         if ($env{'form.'.$role.'_del_'.$img}) {
                   6007:             $confhash->{$role}{$img} = '';
1.12      raeburn  6008:             $changes->{$role}{'images'}{$img} = 1;
1.6       raeburn  6009:         }
1.70      raeburn  6010:         if ($role eq 'login') {
                   6011:             if ($confhash->{$role}{'showlogo'}{$img} == 0) {
                   6012:                 $changes->{$role}{'showlogo'}{$img} = 1;
                   6013:             }
                   6014:         }
1.6       raeburn  6015:     }
                   6016:     if ($confhash->{$role}{'font'}) {
                   6017:         $changes->{$role}{'font'} = 1;
                   6018:     }
1.48      raeburn  6019: }
1.6       raeburn  6020: 
                   6021: sub display_colorchgs {
                   6022:     my ($dom,$changes,$roles,$confhash) = @_;
                   6023:     my (%choices,$resulttext);
                   6024:     if (!grep(/^login$/,@{$roles})) {
                   6025:         $resulttext = &mt('Changes made:').'<br />';
                   6026:     }
                   6027:     foreach my $role (@{$roles}) {
                   6028:         if ($role eq 'login') {
                   6029:             %choices = &login_choices();
                   6030:         } else {
                   6031:             %choices = &color_font_choices();
                   6032:         }
                   6033:         if (ref($changes->{$role}) eq 'HASH') {
                   6034:             if ($role ne 'login') {
                   6035:                 $resulttext .= '<h4>'.&mt($role).'</h4>';
                   6036:             }
                   6037:             foreach my $key (sort(keys(%{$changes->{$role}}))) {
                   6038:                 if ($role ne 'login') {
                   6039:                     $resulttext .= '<ul>';
                   6040:                 }
                   6041:                 if (ref($changes->{$role}{$key}) eq 'HASH') {
                   6042:                     if ($role ne 'login') {
                   6043:                         $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
                   6044:                     }
                   6045:                     foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70      raeburn  6046:                         if (($role eq 'login') && ($key eq 'showlogo')) {
                   6047:                             if ($confhash->{$role}{$key}{$item}) {
                   6048:                                 $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
                   6049:                             } else {
                   6050:                                 $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
                   6051:                             }
                   6052:                         } elsif ($confhash->{$role}{$item} eq '') {
1.6       raeburn  6053:                             $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
                   6054:                         } else {
1.12      raeburn  6055:                             my $newitem = $confhash->{$role}{$item};
                   6056:                             if ($key eq 'images') {
                   6057:                                 $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
                   6058:                             }
                   6059:                             $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6       raeburn  6060:                         }
                   6061:                     }
                   6062:                     if ($role ne 'login') {
                   6063:                         $resulttext .= '</ul></li>';
                   6064:                     }
                   6065:                 } else {
                   6066:                     if ($confhash->{$role}{$key} eq '') {
                   6067:                         $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
                   6068:                     } else {
                   6069:                         $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
                   6070:                     }
                   6071:                 }
                   6072:                 if ($role ne 'login') {
                   6073:                     $resulttext .= '</ul>';
                   6074:                 }
                   6075:             }
                   6076:         }
                   6077:     }
1.3       raeburn  6078:     return $resulttext;
1.1       raeburn  6079: }
                   6080: 
1.9       raeburn  6081: sub thumb_dimensions {
                   6082:     return ('200','50');
                   6083: }
                   6084: 
1.16      raeburn  6085: sub check_dimensions {
                   6086:     my ($inputfile) = @_;
                   6087:     my ($fullwidth,$fullheight);
                   6088:     if ($inputfile =~ m|^[/\w.\-]+$|) {
                   6089:         if (open(PIPE,"identify $inputfile 2>&1 |")) {
                   6090:             my $imageinfo = <PIPE>;
                   6091:             if (!close(PIPE)) {
                   6092:                 &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
                   6093:             }
                   6094:             chomp($imageinfo);
                   6095:             my ($fullsize) = 
1.21      raeburn  6096:                 ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16      raeburn  6097:             if ($fullsize) {
                   6098:                 ($fullwidth,$fullheight) = split(/x/,$fullsize);
                   6099:             }
                   6100:         }
                   6101:     }
                   6102:     return ($fullwidth,$fullheight);
                   6103: }
                   6104: 
1.9       raeburn  6105: sub check_configuser {
                   6106:     my ($uhome,$dom,$confname,$servadm) = @_;
                   6107:     my ($configuserok,%currroles);
                   6108:     if ($uhome eq 'no_host') {
                   6109:         srand( time() ^ ($$ + ($$ << 15))  ); # Seed rand.
                   6110:         my $configpass = &LONCAPA::Enrollment::create_password();
                   6111:         $configuserok = 
                   6112:             &Apache::lonnet::modifyuser($dom,$confname,'','internal',
                   6113:                              $configpass,'','','','','',undef,$servadm);
                   6114:     } else {
                   6115:         $configuserok = 'ok';
                   6116:         %currroles = 
                   6117:             &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
                   6118:     }
                   6119:     return ($configuserok,%currroles);
                   6120: }
                   6121: 
                   6122: sub check_authorstatus {
                   6123:     my ($dom,$confname,%currroles) = @_;
                   6124:     my $author_ok;
1.40      raeburn  6125:     if (!$currroles{':'.$dom.':au'}) {
1.9       raeburn  6126:         my $start = time;
                   6127:         my $end = 0;
                   6128:         $author_ok = 
                   6129:             &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47      raeburn  6130:                                         'au',$end,$start,'','','domconfig');
1.9       raeburn  6131:     } else {
                   6132:         $author_ok = 'ok';
                   6133:     }
                   6134:     return $author_ok;
                   6135: }
                   6136: 
                   6137: sub publishlogo {
1.46      raeburn  6138:     my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9       raeburn  6139:     my ($output,$fname,$logourl);
                   6140:     if ($action eq 'upload') {
                   6141:         $fname=$env{'form.'.$formname.'.filename'};
                   6142:         chop($env{'form.'.$formname});
                   6143:     } else {
                   6144:         ($fname) = ($formname =~ /([^\/]+)$/);
                   6145:     }
1.46      raeburn  6146:     if ($savefileas ne '') {
                   6147:         $fname = $savefileas;
                   6148:     }
1.9       raeburn  6149:     $fname=&Apache::lonnet::clean_filename($fname);
                   6150: # See if there is anything left
                   6151:     unless ($fname) { return ('error: no uploaded file'); }
                   6152:     $fname="$subdir/$fname";
1.210     raeburn  6153:     my $docroot=$r->dir_config('lonDocRoot');
1.164     raeburn  6154:     my $filepath="$docroot/priv";
                   6155:     my $relpath = "$dom/$confname";
1.9       raeburn  6156:     my ($fnamepath,$file,$fetchthumb);
                   6157:     $file=$fname;
                   6158:     if ($fname=~m|/|) {
                   6159:         ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
                   6160:     }
1.164     raeburn  6161:     my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9       raeburn  6162:     my $count;
1.164     raeburn  6163:     for ($count=5;$count<=$#parts;$count++) {
1.9       raeburn  6164:         $filepath.="/$parts[$count]";
                   6165:         if ((-e $filepath)!=1) {
                   6166:             mkdir($filepath,02770);
                   6167:         }
                   6168:     }
                   6169:     # Check for bad extension and disallow upload
                   6170:     if ($file=~/\.(\w+)$/ &&
                   6171:         (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
                   6172:         $output = 
1.207     bisitz   6173:             &mt('Invalid file extension ([_1]) - reserved for internal use.',$1); 
1.9       raeburn  6174:     } elsif ($file=~/\.(\w+)$/ &&
                   6175:         !defined(&Apache::loncommon::fileembstyle($1))) {
                   6176:         $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
                   6177:     } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.195     bisitz   6178:         $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  6179:     } elsif (-d "$filepath/$file") {
1.195     bisitz   6180:         $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9       raeburn  6181:     } else {
                   6182:         my $source = $filepath.'/'.$file;
                   6183:         my $logfile;
                   6184:         if (!open($logfile,">>$source".'.log')) {
1.196     raeburn  6185:             return (&mt('No write permission to Authoring Space'));
1.9       raeburn  6186:         }
                   6187:         print $logfile
                   6188: "\n================= Publish ".localtime()." ================\n".
                   6189: $env{'user.name'}.':'.$env{'user.domain'}."\n";
                   6190: # Save the file
                   6191:         if (!open(FH,'>'.$source)) {
                   6192:             &Apache::lonnet::logthis('Failed to create '.$source);
                   6193:             return (&mt('Failed to create file'));
                   6194:         }
                   6195:         if ($action eq 'upload') {
                   6196:             if (!print FH ($env{'form.'.$formname})) {
                   6197:                 &Apache::lonnet::logthis('Failed to write to '.$source);
                   6198:                 return (&mt('Failed to write file'));
                   6199:             }
                   6200:         } else {
                   6201:             my $original = &Apache::lonnet::filelocation('',$formname);
                   6202:             if(!copy($original,$source)) {
                   6203:                 &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
                   6204:                 return (&mt('Failed to write file'));
                   6205:             }
                   6206:         }
                   6207:         close(FH);
                   6208:         chmod(0660, $source); # Permissions to rw-rw---.
                   6209: 
                   6210:         my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
                   6211:         my $copyfile=$targetdir.'/'.$file;
                   6212: 
                   6213:         my @parts=split(/\//,$targetdir);
                   6214:         my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
                   6215:         for (my $count=5;$count<=$#parts;$count++) {
                   6216:             $path.="/$parts[$count]";
                   6217:             if (!-e $path) {
                   6218:                 print $logfile "\nCreating directory ".$path;
                   6219:                 mkdir($path,02770);
                   6220:             }
                   6221:         }
                   6222:         my $versionresult;
                   6223:         if (-e $copyfile) {
                   6224:             $versionresult = &logo_versioning($targetdir,$file,$logfile);
                   6225:         } else {
                   6226:             $versionresult = 'ok';
                   6227:         }
                   6228:         if ($versionresult eq 'ok') {
                   6229:             if (copy($source,$copyfile)) {
                   6230:                 print $logfile "\nCopied original source to ".$copyfile."\n";
                   6231:                 $output = 'ok';
                   6232:                 $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155     raeburn  6233:                 push(@{$modified_urls},[$copyfile,$source]);
                   6234:                 my $metaoutput = 
                   6235:                     &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
                   6236:                 unless ($registered_cleanup) {
                   6237:                     my $handlers = $r->get_handlers('PerlCleanupHandler');
                   6238:                     $r->set_handlers('PerlCleanupHandler' => [\&notifysubscribed,@{$handlers}]);
                   6239:                     $registered_cleanup=1;
                   6240:                 }
1.9       raeburn  6241:             } else {
                   6242:                 print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
                   6243:                 $output = &mt('Failed to copy file to RES space').", $!";
                   6244:             }
                   6245:             if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
                   6246:                 my $inputfile = $filepath.'/'.$file;
                   6247:                 my $outfile = $filepath.'/'.'tn-'.$file;
1.16      raeburn  6248:                 my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
                   6249:                 if ($fullwidth ne '' && $fullheight ne '') { 
                   6250:                     if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
                   6251:                         my $thumbsize = $thumbwidth.'x'.$thumbheight;
                   6252:                         system("convert -sample $thumbsize $inputfile $outfile");
                   6253:                         chmod(0660, $filepath.'/tn-'.$file);
                   6254:                         if (-e $outfile) {
                   6255:                             my $copyfile=$targetdir.'/tn-'.$file;
                   6256:                             if (copy($outfile,$copyfile)) {
                   6257:                                 print $logfile "\nCopied source to ".$copyfile."\n";
1.155     raeburn  6258:                                 my $thumb_metaoutput = 
                   6259:                                     &write_metadata($dom,$confname,$formname,
                   6260:                                                     $targetdir,'tn-'.$file,$logfile);
                   6261:                                 push(@{$modified_urls},[$copyfile,$outfile]);
                   6262:                                 unless ($registered_cleanup) {
                   6263:                                     my $handlers = $r->get_handlers('PerlCleanupHandler');
                   6264:                                     $r->set_handlers('PerlCleanupHandler' => [\&notifysubscribed,@{$handlers}]);
                   6265:                                     $registered_cleanup=1;
                   6266:                                 }
1.16      raeburn  6267:                             } else {
                   6268:                                 print $logfile "\nUnable to write ".$copyfile.
                   6269:                                                ':'.$!."\n";
                   6270:                             }
                   6271:                         }
1.9       raeburn  6272:                     }
                   6273:                 }
                   6274:             }
                   6275:         } else {
                   6276:             $output = $versionresult;
                   6277:         }
                   6278:     }
                   6279:     return ($output,$logourl);
                   6280: }
                   6281: 
                   6282: sub logo_versioning {
                   6283:     my ($targetdir,$file,$logfile) = @_;
                   6284:     my $target = $targetdir.'/'.$file;
                   6285:     my ($maxversion,$fn,$extn,$output);
                   6286:     $maxversion = 0;
                   6287:     if ($file =~ /^(.+)\.(\w+)$/) {
                   6288:         $fn=$1;
                   6289:         $extn=$2;
                   6290:     }
                   6291:     opendir(DIR,$targetdir);
                   6292:     while (my $filename=readdir(DIR)) {
                   6293:         if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
                   6294:             $maxversion=($1>$maxversion)?$1:$maxversion;
                   6295:         }
                   6296:     }
                   6297:     $maxversion++;
                   6298:     print $logfile "\nCreating old version ".$maxversion."\n";
                   6299:     my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
                   6300:     if (copy($target,$copyfile)) {
                   6301:         print $logfile "Copied old target to ".$copyfile."\n";
                   6302:         $copyfile=$copyfile.'.meta';
                   6303:         if (copy($target.'.meta',$copyfile)) {
                   6304:             print $logfile "Copied old target metadata to ".$copyfile."\n";
                   6305:             $output = 'ok';
                   6306:         } else {
                   6307:             print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
                   6308:             $output = &mt('Failed to copy old meta').", $!, ";
                   6309:         }
                   6310:     } else {
                   6311:         print $logfile "Unable to write ".$copyfile.':'.$!."\n";
                   6312:         $output = &mt('Failed to copy old target').", $!, ";
                   6313:     }
                   6314:     return $output;
                   6315: }
                   6316: 
                   6317: sub write_metadata {
                   6318:     my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
                   6319:     my (%metadatafields,%metadatakeys,$output);
                   6320:     $metadatafields{'title'}=$formname;
                   6321:     $metadatafields{'creationdate'}=time;
                   6322:     $metadatafields{'lastrevisiondate'}=time;
                   6323:     $metadatafields{'copyright'}='public';
                   6324:     $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
                   6325:                                          $env{'user.domain'};
                   6326:     $metadatafields{'authorspace'}=$confname.':'.$dom;
                   6327:     $metadatafields{'domain'}=$dom;
                   6328:     {
                   6329:         print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
                   6330:         my $mfh;
1.155     raeburn  6331:         if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
1.184     raeburn  6332:             foreach (sort(keys(%metadatafields))) {
1.155     raeburn  6333:                 unless ($_=~/\./) {
                   6334:                     my $unikey=$_;
                   6335:                     $unikey=~/^([A-Za-z]+)/;
                   6336:                     my $tag=$1;
                   6337:                     $tag=~tr/A-Z/a-z/;
                   6338:                     print $mfh "\n\<$tag";
                   6339:                     foreach (split(/\,/,$metadatakeys{$unikey})) {
                   6340:                         my $value=$metadatafields{$unikey.'.'.$_};
                   6341:                         $value=~s/\"/\'\'/g;
                   6342:                         print $mfh ' '.$_.'="'.$value.'"';
                   6343:                     }
                   6344:                     print $mfh '>'.
                   6345:                         &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
                   6346:                             .'</'.$tag.'>';
                   6347:                 }
                   6348:             }
                   6349:             $output = 'ok';
                   6350:             print $logfile "\nWrote metadata";
                   6351:             close($mfh);
                   6352:         } else {
                   6353:             print $logfile "\nFailed to open metadata file";
1.9       raeburn  6354:             $output = &mt('Could not write metadata');
                   6355:         }
                   6356:     }
1.155     raeburn  6357:     return $output;
                   6358: }
                   6359: 
                   6360: sub notifysubscribed {
                   6361:     foreach my $targetsource (@{$modified_urls}){
                   6362:         next unless (ref($targetsource) eq 'ARRAY');
                   6363:         my ($target,$source)=@{$targetsource};
                   6364:         if ($source ne '') {
                   6365:             if (open(my $logfh,'>>'.$source.'.log')) {
                   6366:                 print $logfh "\nCleanup phase: Notifications\n";
                   6367:                 my @subscribed=&subscribed_hosts($target);
                   6368:                 foreach my $subhost (@subscribed) {
                   6369:                     print $logfh "\nNotifying host ".$subhost.':';
                   6370:                     my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
                   6371:                     print $logfh $reply;
                   6372:                 }
                   6373:                 my @subscribedmeta=&subscribed_hosts("$target.meta");
                   6374:                 foreach my $subhost (@subscribedmeta) {
                   6375:                     print $logfh "\nNotifying host for metadata only ".$subhost.':';
                   6376:                     my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
                   6377:                                                         $subhost);
                   6378:                     print $logfh $reply;
                   6379:                 }
                   6380:                 print $logfh "\n============ Done ============\n";
1.160     raeburn  6381:                 close($logfh);
1.155     raeburn  6382:             }
                   6383:         }
                   6384:     }
                   6385:     return OK;
                   6386: }
                   6387: 
                   6388: sub subscribed_hosts {
                   6389:     my ($target) = @_;
                   6390:     my @subscribed;
                   6391:     if (open(my $fh,"<$target.subscription")) {
                   6392:         while (my $subline=<$fh>) {
                   6393:             if ($subline =~ /^($match_lonid):/) {
                   6394:                 my $host = $1;
                   6395:                 if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
                   6396:                     unless (grep(/^\Q$host\E$/,@subscribed)) {
                   6397:                         push(@subscribed,$host);
                   6398:                     }
                   6399:                 }
                   6400:             }
                   6401:         }
                   6402:     }
                   6403:     return @subscribed;
1.9       raeburn  6404: }
                   6405: 
                   6406: sub check_switchserver {
                   6407:     my ($dom,$confname) = @_;
                   6408:     my ($allowed,$switchserver);
                   6409:     my $home = &Apache::lonnet::homeserver($confname,$dom);
                   6410:     if ($home eq 'no_host') {
                   6411:         $home = &Apache::lonnet::domain($dom,'primary');
                   6412:     }
                   6413:     my @ids=&Apache::lonnet::current_machine_ids();
1.10      albertel 6414:     foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
                   6415:     if (!$allowed) {
1.180     raeburn  6416: 	$switchserver='<a href="/adm/switchserver?otherserver='.$home.'&amp;role=dc./'.$dom.'/&amp;destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9       raeburn  6417:     }
                   6418:     return $switchserver;
                   6419: }
                   6420: 
1.1       raeburn  6421: sub modify_quotas {
1.216     raeburn  6422:     my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101     raeburn  6423:     my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216     raeburn  6424:         %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
                   6425:         $author_ok,$switchserver,$errors);
1.86      raeburn  6426:     if ($action eq 'quotas') {
                   6427:         $context = 'tools'; 
1.163     raeburn  6428:     } else {
1.86      raeburn  6429:         $context = $action;
                   6430:     }
                   6431:     if ($context eq 'requestcourses') {
1.216     raeburn  6432:         @usertools = ('official','unofficial','community','textbook');
1.106     raeburn  6433:         @options =('norequest','approval','validate','autolimit');
1.101     raeburn  6434:         %validations = &Apache::lonnet::auto_courserequest_checks($dom);
                   6435:         %titles = &courserequest_titles();
                   6436:         $toolregexp = join('|',@usertools);
                   6437:         %conditions = &courserequest_conditions();
1.216     raeburn  6438:         $confname = $dom.'-domainconfig';
                   6439:         my $servadm = $r->dir_config('lonAdmEMail');
                   6440:         ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.163     raeburn  6441:     } elsif ($context eq 'requestauthor') {
                   6442:         @usertools = ('author');
                   6443:         %titles = &authorrequest_titles();
1.86      raeburn  6444:     } else {
1.162     raeburn  6445:         @usertools = ('aboutme','blog','webdav','portfolio');
1.101     raeburn  6446:         %titles = &tool_titles();
1.86      raeburn  6447:     }
1.212     raeburn  6448:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44      raeburn  6449:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1       raeburn  6450:     foreach my $key (keys(%env)) {
1.101     raeburn  6451:         if ($context eq 'requestcourses') {
                   6452:             if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
                   6453:                 my $item = $1;
                   6454:                 my $type = $2;
                   6455:                 if ($type =~ /^limit_(.+)/) {
                   6456:                     $limithash{$item}{$1} = $env{$key};
                   6457:                 } else {
                   6458:                     $confhash{$item}{$type} = $env{$key};
                   6459:                 }
                   6460:             }
1.163     raeburn  6461:         } elsif ($context eq 'requestauthor') {
                   6462:             if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
                   6463:                 $confhash{$1} = $env{$key};
                   6464:             }
1.101     raeburn  6465:         } else {
1.86      raeburn  6466:             if ($key =~ /^form\.quota_(.+)$/) {
                   6467:                 $confhash{'defaultquota'}{$1} = $env{$key};
1.197     raeburn  6468:             } elsif ($key =~ /^form\.authorquota_(.+)$/) {
                   6469:                 $confhash{'authorquota'}{$1} = $env{$key};
                   6470:             } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101     raeburn  6471:                 @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
                   6472:             }
1.72      raeburn  6473:         }
                   6474:     }
1.163     raeburn  6475:     if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.224     raeburn  6476:         my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102     raeburn  6477:         @approvalnotify = sort(@approvalnotify);
                   6478:         $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.218     raeburn  6479:         my @crstypes = ('official','unofficial','community','textbook');
                   6480:         my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
                   6481:         foreach my $type (@hasuniquecode) {
                   6482:             if (grep(/^\Q$type\E$/,@crstypes)) {
                   6483:                 $confhash{'uniquecode'}{$type} = 1;
                   6484:             }
1.216     raeburn  6485:         }
                   6486:         my ($newbook,@allpos);
                   6487:         if ($context eq 'requestcourses') {
                   6488:             if ($env{'form.addbook'}) {
                   6489:                 if (($env{'form.addbook_cnum'} =~ /^$match_courseid$/) &&
                   6490:                     ($env{'form.addbook_cdom'} =~ /^$match_domain$/)) {
                   6491:                     if (&Apache::lonnet::homeserver($env{'form.addbook_cnum'},
                   6492:                                                     $env{'form.addbook_cdom'}) eq 'no_host') {
                   6493:                         $errors .= '<li><span class="LC_error">'.&mt('Invalid LON-CAPA course for textbook').
                   6494:                                    '</span></li>';
                   6495:                     } else {
                   6496:                         $newbook = $env{'form.addbook_cdom'}.'_'.$env{'form.addbook_cnum'};
                   6497:                         my $position = $env{'form.addbook_pos'};
                   6498:                         $position =~ s/\D+//g;
                   6499:                         if ($position ne '') {
                   6500:                             $allpos[$position] = $newbook;
                   6501:                         }
                   6502:                     }
                   6503:                 } else {
                   6504:                     $errors .= '<li><span class="LC_error">'.&mt('Invalid LON-CAPA course for textbook').
                   6505:                                '</span></li>';
                   6506:                 }
                   6507:             }
                   6508:         }
1.102     raeburn  6509:         if (ref($domconfig{$action}) eq 'HASH') {
                   6510:             if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
                   6511:                 if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
                   6512:                     $changes{'notify'}{'approval'} = 1;
                   6513:                 }
                   6514:             } else {
1.144     raeburn  6515:                 if ($confhash{'notify'}{'approval'}) {
1.102     raeburn  6516:                     $changes{'notify'}{'approval'} = 1;
                   6517:                 }
                   6518:             }
1.218     raeburn  6519:             if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
                   6520:                 if (ref($confhash{'uniquecode'}) eq 'HASH') {
                   6521:                     foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
                   6522:                         unless ($confhash{'uniquecode'}{$crstype}) {
                   6523:                             $changes{'uniquecode'} = 1;
                   6524:                         }
                   6525:                     }
                   6526:                     unless ($changes{'uniquecode'}) {
                   6527:                         foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
                   6528:                             unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
                   6529:                                 $changes{'uniquecode'} = 1;
                   6530:                             }
                   6531:                         }
                   6532:                     }
                   6533:                } else {
                   6534:                    $changes{'uniquecode'} = 1;
                   6535:                }
                   6536:             } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
                   6537:                 $changes{'uniquecode'} = 1;
1.216     raeburn  6538:             }
                   6539:             if ($context eq 'requestcourses') {
                   6540:                 if (ref($domconfig{$action}{'textbooks'}) eq 'HASH') {
                   6541:                     my %deletions;
                   6542:                     my @todelete = &Apache::loncommon::get_env_multiple('form.book_del');
                   6543:                     if (@todelete) {
                   6544:                         map { $deletions{$_} = 1; } @todelete;
                   6545:                     }
                   6546:                     my %imgdeletions;
                   6547:                     my @todeleteimages = &Apache::loncommon::get_env_multiple('form.book_image_del');
                   6548:                     if (@todeleteimages) {
                   6549:                         map { $imgdeletions{$_} = 1; } @todeleteimages;
                   6550:                     }
                   6551:                     my $maxnum = $env{'form.book_maxnum'};
                   6552:                     for (my $i=0; $i<=$maxnum; $i++) {
                   6553:                         my $key = $env{'form.book_id_'.$i};
                   6554:                         if (ref($domconfig{$action}{'textbooks'}{$key}) eq 'HASH') {
                   6555:                             if ($deletions{$key}) {
                   6556:                                 if ($domconfig{$action}{'textbooks'}{$key}{'image'}) {
                   6557:                                     #FIXME need to obsolete item in RES space
                   6558:                                 }
                   6559:                                 next;
                   6560:                             } else {
                   6561:                                 my $newpos = $env{'form.'.$key};
                   6562:                                 $newpos =~ s/\D+//g;
                   6563:                                 foreach my $item ('subject','title','author') {
                   6564:                                     $confhash{'textbooks'}{$key}{$item} = $env{'form.book_'.$item.'_'.$i};
                   6565:                                     if ($domconfig{$action}{'textbooks'}{$key}{$item} ne $confhash{'textbooks'}{$key}{$item}) {
                   6566:                                         $changes{'textbooks'}{$key} = 1;
                   6567:                                     }
                   6568:                                 }
                   6569:                                 $allpos[$newpos] = $key;
                   6570:                             }
                   6571:                             if ($imgdeletions{$key}) {
                   6572:                                 $changes{'textbooks'}{$key} = 1;
                   6573:                                 #FIXME need to obsolete item in RES space
                   6574:                             } elsif ($env{'form.book_image_'.$i.'.filename'}) {
                   6575:                                 my ($cdom,$cnum) = split(/_/,$key);
                   6576:                                 my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,'book_image_'.$i,
                   6577:                                                                               $cdom,$cnum,$configuserok,
                   6578:                                                                               $switchserver,$author_ok);
                   6579:                                 if ($imgurl) {
                   6580:                                     $confhash{'textbooks'}{$key}{'image'} = $imgurl;
                   6581:                                     $changes{'textbooks'}{$key} = 1; 
                   6582:                                 }
                   6583:                                 if ($error) {
                   6584:                                     &Apache::lonnet::logthis($error);
                   6585:                                     $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   6586:                                 } 
                   6587:                             } elsif ($domconfig{$action}{'textbooks'}{$key}{'image'}) {
                   6588:                                 $confhash{'textbooks'}{$key}{'image'} = 
                   6589:                                     $domconfig{$action}{'textbooks'}{$key}{'image'};
                   6590:                             }
                   6591:                         }
                   6592:                     }
                   6593:                 }
                   6594:             }
1.102     raeburn  6595:         } else {
1.144     raeburn  6596:             if ($confhash{'notify'}{'approval'}) {
1.102     raeburn  6597:                 $changes{'notify'}{'approval'} = 1;
                   6598:             }
1.218     raeburn  6599:             if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216     raeburn  6600:                 $changes{'uniquecode'} = 1;
                   6601:             }
                   6602:         }
                   6603:         if ($context eq 'requestcourses') {
                   6604:             if ($newbook) {
                   6605:                 $changes{'textbooks'}{$newbook} = 1;
                   6606:                 foreach my $item ('subject','title','author') {
                   6607:                     $env{'form.addbook_'.$item} =~ s/(`)/'/g;
                   6608:                     if ($env{'form.addbook_'.$item}) {
                   6609:                         $confhash{'textbooks'}{$newbook}{$item} = $env{'form.addbook_'.$item};
                   6610:                     }
                   6611:                 }
                   6612:                 if ($env{'form.addbook_image.filename'} ne '') {
                   6613:                     my ($cdom,$cnum) = split(/_/,$newbook);
                   6614:                     my ($imageurl,$error) = 
                   6615:                         &process_textbook_image($r,$dom,$confname,'addbook_image',$cdom,$cnum,$configuserok,
                   6616:                                                 $switchserver,$author_ok);
                   6617:                     if ($imageurl) {
                   6618:                         $confhash{'textbooks'}{$newbook}{'image'} = $imageurl;
                   6619:                     }
                   6620:                     if ($error) {
                   6621:                         &Apache::lonnet::logthis($error);
                   6622:                         $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   6623:                     }
                   6624:                 }
                   6625:             }
                   6626:             if (@allpos > 0) {
                   6627:                 my $idx = 0;
                   6628:                 foreach my $item (@allpos) {
                   6629:                     if ($item ne '') {
                   6630:                         $confhash{'textbooks'}{$item}{'order'} = $idx;
                   6631:                         if (ref($domconfig{$action}) eq 'HASH') {
                   6632:                             if (ref($domconfig{$action}{'textbooks'}) eq 'HASH') {
                   6633:                                 if (ref($domconfig{$action}{'textbooks'}{$item}) eq 'HASH') {
                   6634:                                     if ($domconfig{$action}{'textbooks'}{$item}{'order'} ne $idx) {
                   6635:                                         $changes{'textbooks'}{$item} = 1;
                   6636:                                     }
                   6637:                                 }
                   6638:                             }
                   6639:                         }
                   6640:                         $idx ++;
                   6641:                     }
                   6642:                 }
                   6643:             }
1.102     raeburn  6644:         }
                   6645:     } else {
1.86      raeburn  6646:         $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.197     raeburn  6647:         $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86      raeburn  6648:     }
1.72      raeburn  6649:     foreach my $item (@usertools) {
                   6650:         foreach my $type (@{$types},'default','_LC_adv') {
1.104     raeburn  6651:             my $unset; 
1.101     raeburn  6652:             if ($context eq 'requestcourses') {
1.104     raeburn  6653:                 $unset = '0';
                   6654:                 if ($type eq '_LC_adv') {
                   6655:                     $unset = '';
                   6656:                 }
1.101     raeburn  6657:                 if ($confhash{$item}{$type} eq 'autolimit') {
                   6658:                     $confhash{$item}{$type} .= '=';
                   6659:                     unless ($limithash{$item}{$type} =~ /\D/) {
                   6660:                         $confhash{$item}{$type} .= $limithash{$item}{$type};
                   6661:                     }
                   6662:                 }
1.163     raeburn  6663:             } elsif ($context eq 'requestauthor') {
                   6664:                 $unset = '0';
                   6665:                 if ($type eq '_LC_adv') {
                   6666:                     $unset = '';
                   6667:                 }
1.72      raeburn  6668:             } else {
1.101     raeburn  6669:                 if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
                   6670:                     $confhash{$item}{$type} = 1;
                   6671:                 } else {
                   6672:                     $confhash{$item}{$type} = 0;
                   6673:                 }
1.72      raeburn  6674:             }
1.86      raeburn  6675:             if (ref($domconfig{$action}) eq 'HASH') {
1.163     raeburn  6676:                 if ($action eq 'requestauthor') {
                   6677:                     if ($domconfig{$action}{$type} ne $confhash{$type}) {
                   6678:                         $changes{$type} = 1;
                   6679:                     }
                   6680:                 } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86      raeburn  6681:                     if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
                   6682:                         $changes{$item}{$type} = 1;
                   6683:                     }
                   6684:                 } else {
                   6685:                     if ($context eq 'requestcourses') {
1.104     raeburn  6686:                         if ($confhash{$item}{$type} ne $unset) {
1.86      raeburn  6687:                             $changes{$item}{$type} = 1;
                   6688:                         }
                   6689:                     } else {
                   6690:                         if (!$confhash{$item}{$type}) {
                   6691:                             $changes{$item}{$type} = 1;
                   6692:                         }
                   6693:                     }
                   6694:                 }
                   6695:             } else {
                   6696:                 if ($context eq 'requestcourses') {
1.104     raeburn  6697:                     if ($confhash{$item}{$type} ne $unset) {
1.72      raeburn  6698:                         $changes{$item}{$type} = 1;
                   6699:                     }
1.163     raeburn  6700:                 } elsif ($context eq 'requestauthor') {
                   6701:                     if ($confhash{$type} ne $unset) {
                   6702:                         $changes{$type} = 1;
                   6703:                     }
1.72      raeburn  6704:                 } else {
                   6705:                     if (!$confhash{$item}{$type}) {
                   6706:                         $changes{$item}{$type} = 1;
                   6707:                     }
                   6708:                 }
                   6709:             }
1.1       raeburn  6710:         }
                   6711:     }
1.163     raeburn  6712:     unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86      raeburn  6713:         if (ref($domconfig{'quotas'}) eq 'HASH') {
                   6714:             if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
                   6715:                 foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
                   6716:                     if (exists($confhash{'defaultquota'}{$key})) {
                   6717:                         if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
                   6718:                             $changes{'defaultquota'}{$key} = 1;
                   6719:                         }
                   6720:                     } else {
                   6721:                         $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72      raeburn  6722:                     }
                   6723:                 }
1.86      raeburn  6724:             } else {
                   6725:                 foreach my $key (keys(%{$domconfig{'quotas'}})) {
                   6726:                     if (exists($confhash{'defaultquota'}{$key})) {
                   6727:                         if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
                   6728:                             $changes{'defaultquota'}{$key} = 1;
                   6729:                         }
                   6730:                     } else {
                   6731:                         $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72      raeburn  6732:                     }
1.1       raeburn  6733:                 }
                   6734:             }
1.197     raeburn  6735:             if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
                   6736:                 foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
                   6737:                     if (exists($confhash{'authorquota'}{$key})) {
                   6738:                         if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
                   6739:                             $changes{'authorquota'}{$key} = 1;
                   6740:                         }
                   6741:                     } else {
                   6742:                         $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
                   6743:                     }
                   6744:                 }
                   6745:             }
1.1       raeburn  6746:         }
1.86      raeburn  6747:         if (ref($confhash{'defaultquota'}) eq 'HASH') {
                   6748:             foreach my $key (keys(%{$confhash{'defaultquota'}})) {
                   6749:                 if (ref($domconfig{'quotas'}) eq 'HASH') {
                   6750:                     if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
                   6751:                         if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
                   6752:                             $changes{'defaultquota'}{$key} = 1;
                   6753:                         }
                   6754:                     } else {
                   6755:                         if (!exists($domconfig{'quotas'}{$key})) {
                   6756:                             $changes{'defaultquota'}{$key} = 1;
                   6757:                         }
1.72      raeburn  6758:                     }
                   6759:                 } else {
1.86      raeburn  6760:                     $changes{'defaultquota'}{$key} = 1;
1.55      raeburn  6761:                 }
1.1       raeburn  6762:             }
                   6763:         }
1.197     raeburn  6764:         if (ref($confhash{'authorquota'}) eq 'HASH') {
                   6765:             foreach my $key (keys(%{$confhash{'authorquota'}})) {
                   6766:                 if (ref($domconfig{'quotas'}) eq 'HASH') {
                   6767:                     if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
                   6768:                         if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
                   6769:                             $changes{'authorquota'}{$key} = 1;
                   6770:                         }
                   6771:                     } else {
                   6772:                         $changes{'authorquota'}{$key} = 1;
                   6773:                     }
                   6774:                 } else {
                   6775:                     $changes{'authorquota'}{$key} = 1;
                   6776:                 }
                   6777:             }
                   6778:         }
1.1       raeburn  6779:     }
1.72      raeburn  6780: 
1.163     raeburn  6781:     if ($context eq 'requestauthor') {
                   6782:         $domdefaults{'requestauthor'} = \%confhash;
                   6783:     } else {
                   6784:         foreach my $key (keys(%confhash)) {
1.216     raeburn  6785:             unless (($context eq 'requestcourses') && ($key eq 'textbooks')) {
                   6786:                 $domdefaults{$key} = $confhash{$key};
                   6787:             }
1.163     raeburn  6788:         }
1.72      raeburn  6789:     }
1.163     raeburn  6790: 
1.1       raeburn  6791:     my %quotahash = (
1.86      raeburn  6792:                       $action => { %confhash }
1.1       raeburn  6793:                     );
                   6794:     my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
                   6795:                                              $dom);
                   6796:     if ($putresult eq 'ok') {
                   6797:         if (keys(%changes) > 0) {
1.72      raeburn  6798:             my $cachetime = 24*60*60;
                   6799:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212     raeburn  6800:             if (ref($lastactref) eq 'HASH') {
                   6801:                 $lastactref->{'domdefaults'} = 1;
                   6802:             }
1.1       raeburn  6803:             $resulttext = &mt('Changes made:').'<ul>';
1.210     raeburn  6804:             unless (($context eq 'requestcourses') ||
1.163     raeburn  6805:                     ($context eq 'requestauthor')) {
1.86      raeburn  6806:                 if (ref($changes{'defaultquota'}) eq 'HASH') {
                   6807:                     $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
                   6808:                     foreach my $type (@{$types},'default') {
                   6809:                         if (defined($changes{'defaultquota'}{$type})) {
                   6810:                             my $typetitle = $usertypes->{$type};
                   6811:                             if ($type eq 'default') {
                   6812:                                 $typetitle = $othertitle;
                   6813:                             }
1.213     raeburn  6814:                             $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72      raeburn  6815:                         }
                   6816:                     }
1.86      raeburn  6817:                     $resulttext .= '</ul></li>';
1.72      raeburn  6818:                 }
1.197     raeburn  6819:                 if (ref($changes{'authorquota'}) eq 'HASH') {
1.223     bisitz   6820:                     $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.197     raeburn  6821:                     foreach my $type (@{$types},'default') {
                   6822:                         if (defined($changes{'authorquota'}{$type})) {
                   6823:                             my $typetitle = $usertypes->{$type};
                   6824:                             if ($type eq 'default') {
                   6825:                                 $typetitle = $othertitle;
                   6826:                             }
1.213     raeburn  6827:                             $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.197     raeburn  6828:                         }
                   6829:                     }
                   6830:                     $resulttext .= '</ul></li>';
                   6831:                 }
1.72      raeburn  6832:             }
1.80      raeburn  6833:             my %newenv;
1.72      raeburn  6834:             foreach my $item (@usertools) {
1.163     raeburn  6835:                 my (%haschgs,%inconf);
                   6836:                 if ($context eq 'requestauthor') {
                   6837:                     %haschgs = %changes;
1.210     raeburn  6838:                     %inconf = %confhash;
1.163     raeburn  6839:                 } else {
                   6840:                     if (ref($changes{$item}) eq 'HASH') {
                   6841:                         %haschgs = %{$changes{$item}};
                   6842:                     }
                   6843:                     if (ref($confhash{$item}) eq 'HASH') {
                   6844:                         %inconf = %{$confhash{$item}};
                   6845:                     }
                   6846:                 }
                   6847:                 if (keys(%haschgs) > 0) {
1.80      raeburn  6848:                     my $newacc = 
                   6849:                         &Apache::lonnet::usertools_access($env{'user.name'},
                   6850:                                                           $env{'user.domain'},
1.86      raeburn  6851:                                                           $item,'reload',$context);
1.210     raeburn  6852:                     if (($context eq 'requestcourses') ||
1.163     raeburn  6853:                         ($context eq 'requestauthor')) {
1.108     raeburn  6854:                         if ($env{'environment.canrequest.'.$item} ne $newacc) {
                   6855:                             $newenv{'environment.canrequest.'.$item} = $newacc;
1.86      raeburn  6856:                         }
                   6857:                     } else {
                   6858:                         if ($env{'environment.availabletools.'.$item} ne $newacc) { 
                   6859:                             $newenv{'environment.availabletools.'.$item} = $newacc;
                   6860:                         }
1.80      raeburn  6861:                     }
1.163     raeburn  6862:                     unless ($context eq 'requestauthor') {
                   6863:                         $resulttext .= '<li>'.$titles{$item}.'<ul>';
                   6864:                     }
1.72      raeburn  6865:                     foreach my $type (@{$types},'default','_LC_adv') {
1.163     raeburn  6866:                         if ($haschgs{$type}) {
1.72      raeburn  6867:                             my $typetitle = $usertypes->{$type};
                   6868:                             if ($type eq 'default') {
                   6869:                                 $typetitle = $othertitle;
                   6870:                             } elsif ($type eq '_LC_adv') {
                   6871:                                 $typetitle = 'LON-CAPA Advanced Users'; 
                   6872:                             }
1.163     raeburn  6873:                             if ($inconf{$type}) {
1.101     raeburn  6874:                                 if ($context eq 'requestcourses') {
                   6875:                                     my $cond;
1.163     raeburn  6876:                                     if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101     raeburn  6877:                                         if ($1 eq '') {
                   6878:                                             $cond = &mt('(Automatic processing of any request).');
                   6879:                                         } else {
                   6880:                                             $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
                   6881:                                         }
                   6882:                                     } else { 
1.163     raeburn  6883:                                         $cond = $conditions{$inconf{$type}};
1.101     raeburn  6884:                                     }
                   6885:                                     $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172     raeburn  6886:                                 } elsif ($context eq 'requestauthor') {
                   6887:                                     $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
                   6888:                                                              $titles{$inconf{$type}},$typetitle);
                   6889: 
1.101     raeburn  6890:                                 } else {
                   6891:                                     $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
                   6892:                                 }
1.72      raeburn  6893:                             } else {
1.104     raeburn  6894:                                 if ($type eq '_LC_adv') {
1.163     raeburn  6895:                                     if ($inconf{$type} eq '0') {
1.104     raeburn  6896:                                         $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
                   6897:                                     } else { 
                   6898:                                         $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
                   6899:                                     }
                   6900:                                 } else {
                   6901:                                     $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
                   6902:                                 }
1.72      raeburn  6903:                             }
                   6904:                         }
1.26      raeburn  6905:                     }
1.163     raeburn  6906:                     unless ($context eq 'requestauthor') {
                   6907:                         $resulttext .= '</ul></li>';
                   6908:                     }
1.26      raeburn  6909:                 }
1.1       raeburn  6910:             }
1.163     raeburn  6911:             if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102     raeburn  6912:                 if (ref($changes{'notify'}) eq 'HASH') {
                   6913:                     if ($changes{'notify'}{'approval'}) {
                   6914:                         if (ref($confhash{'notify'}) eq 'HASH') {
                   6915:                             if ($confhash{'notify'}{'approval'}) {
                   6916:                                 $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
                   6917:                             } else {
1.163     raeburn  6918:                                 $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102     raeburn  6919:                             }
                   6920:                         }
                   6921:                     }
                   6922:                 }
                   6923:             }
1.216     raeburn  6924:             if ($action eq 'requestcourses') {
                   6925:                 my @offon = ('off','on');
                   6926:                 if ($changes{'uniquecode'}) {
1.218     raeburn  6927:                     if (ref($confhash{'uniquecode'}) eq 'HASH') {
                   6928:                         my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
                   6929:                         $resulttext .= '<li>'.
                   6930:                                        &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
                   6931:                                        '</li>';
                   6932:                     } else {
                   6933:                         $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
                   6934:                                        '</li>';
                   6935:                     }
1.216     raeburn  6936:                 }
                   6937:                 if (ref($changes{'textbooks'}) eq 'HASH') {
                   6938:                     $resulttext .= '<li>'.&mt('Available textbooks updated').'<ul>';
                   6939:                     foreach my $key (sort(keys(%{$changes{'textbooks'}}))) {
                   6940:                         my %coursehash = &Apache::lonnet::coursedescription($key);
                   6941:                         my $coursetitle = $coursehash{'description'};
                   6942:                         my $position = $confhash{'textbooks'}{$key}{'order'} + 1;
                   6943:                         $resulttext .= '<li>';
                   6944:                         foreach my $item ('subject','title','author') {
                   6945:                             my $name = $item.':';
                   6946:                             $name =~ s/^(\w)/\U$1/;
                   6947:                             $resulttext .= &mt($name).' '.$confhash{'textbooks'}{$key}{$item}.'<br />';
                   6948:                         }
                   6949:                         $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
                   6950:                         if ($confhash{'textbooks'}{$key}{'image'}) {
                   6951:                             $resulttext .= ' '.&mt('Image: [_1]',
                   6952:                                                '<img src="'.$confhash{'textbooks'}{$key}{'image'}.'"'.
                   6953:                                                ' alt="Textbook cover" />').'<br />';
                   6954:                         }
                   6955:                         $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
                   6956:                     }
                   6957:                     $resulttext .= '</ul></li>';
                   6958:                 }
                   6959:             }
1.1       raeburn  6960:             $resulttext .= '</ul>';
1.80      raeburn  6961:             if (keys(%newenv)) {
                   6962:                 &Apache::lonnet::appenv(\%newenv);
                   6963:             }
1.1       raeburn  6964:         } else {
1.86      raeburn  6965:             if ($context eq 'requestcourses') {
                   6966:                 $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163     raeburn  6967:             } elsif ($context eq 'requestauthor') {
                   6968:                 $resulttext = &mt('No changes made to rights to request author space.');
1.86      raeburn  6969:             } else {
1.90      weissno  6970:                 $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86      raeburn  6971:             }
1.1       raeburn  6972:         }
                   6973:     } else {
1.11      albertel 6974:         $resulttext = '<span class="LC_error">'.
                   6975: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  6976:     }
1.216     raeburn  6977:     if ($errors) {
                   6978:         $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
                   6979:                        '<ul>'.$errors.'</ul></p>';
                   6980:     }
1.3       raeburn  6981:     return $resulttext;
1.1       raeburn  6982: }
                   6983: 
1.216     raeburn  6984: sub process_textbook_image {
                   6985:     my ($r,$dom,$confname,$caller,$cdom,$cnum,$configuserok,$switchserver,$author_ok) = @_;
                   6986:     my $filename = $env{'form.'.$caller.'.filename'};
                   6987:     my ($error,$url);
                   6988:     my ($width,$height) = (50,50);
                   6989:     if ($configuserok eq 'ok') {
                   6990:         if ($switchserver) {
                   6991:             $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
                   6992:                          $switchserver);
                   6993:         } elsif ($author_ok eq 'ok') {
                   6994:             my ($result,$imageurl) =
                   6995:                 &publishlogo($r,'upload',$caller,$dom,$confname,
                   6996:                              "textbooks/$dom/$cnum/cover",$width,$height);
                   6997:             if ($result eq 'ok') {
                   6998:                 $url = $imageurl;
                   6999:             } else {
                   7000:                 $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
                   7001:             }
                   7002:         } else {
                   7003:             $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);
                   7004:         }
                   7005:     } else {
                   7006:         $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);
                   7007:     }
                   7008:     return ($url,$error);
                   7009: }
                   7010: 
1.3       raeburn  7011: sub modify_autoenroll {
1.205     raeburn  7012:     my ($dom,$lastactref,%domconfig) = @_;
1.1       raeburn  7013:     my ($resulttext,%changes);
                   7014:     my %currautoenroll;
                   7015:     if (ref($domconfig{'autoenroll'}) eq 'HASH') {
                   7016:         foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
                   7017:             $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
                   7018:         }
                   7019:     }
                   7020:     my $autorun = &Apache::lonnet::auto_run(undef,$dom),
                   7021:     my %title = ( run => 'Auto-enrollment active',
1.129     raeburn  7022:                   sender => 'Sender for notification messages',
                   7023:                   coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)');
1.1       raeburn  7024:     my @offon = ('off','on');
1.17      raeburn  7025:     my $sender_uname = $env{'form.sender_uname'};
                   7026:     my $sender_domain = $env{'form.sender_domain'};
                   7027:     if ($sender_domain eq '') {
                   7028:         $sender_uname = '';
                   7029:     } elsif ($sender_uname eq '') {
                   7030:         $sender_domain = '';
                   7031:     }
1.129     raeburn  7032:     my $coowners = $env{'form.autoassign_coowners'};
1.1       raeburn  7033:     my %autoenrollhash =  (
1.129     raeburn  7034:                        autoenroll => { 'run' => $env{'form.autoenroll_run'},
                   7035:                                        'sender_uname' => $sender_uname,
                   7036:                                        'sender_domain' => $sender_domain,
                   7037:                                        'co-owners' => $coowners,
1.1       raeburn  7038:                                 }
                   7039:                      );
1.4       raeburn  7040:     my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
                   7041:                                              $dom);
1.1       raeburn  7042:     if ($putresult eq 'ok') {
                   7043:         if (exists($currautoenroll{'run'})) {
                   7044:              if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
                   7045:                  $changes{'run'} = 1;
                   7046:              }
                   7047:         } elsif ($autorun) {
                   7048:             if ($env{'form.autoenroll_run'} ne '1') {
1.23      raeburn  7049:                  $changes{'run'} = 1;
1.1       raeburn  7050:             }
                   7051:         }
1.17      raeburn  7052:         if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1       raeburn  7053:             $changes{'sender'} = 1;
                   7054:         }
1.17      raeburn  7055:         if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1       raeburn  7056:             $changes{'sender'} = 1;
                   7057:         }
1.129     raeburn  7058:         if ($currautoenroll{'co-owners'} ne '') {
                   7059:             if ($currautoenroll{'co-owners'} ne $coowners) {
                   7060:                 $changes{'coowners'} = 1;
                   7061:             }
                   7062:         } elsif ($coowners) {
                   7063:             $changes{'coowners'} = 1;
                   7064:         }      
1.1       raeburn  7065:         if (keys(%changes) > 0) {
                   7066:             $resulttext = &mt('Changes made:').'<ul>';
1.3       raeburn  7067:             if ($changes{'run'}) {
1.1       raeburn  7068:                 $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
                   7069:             }
                   7070:             if ($changes{'sender'}) {
1.17      raeburn  7071:                 if ($sender_uname eq '' || $sender_domain eq '') {
                   7072:                     $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
                   7073:                 } else {
                   7074:                     $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
                   7075:                 }
1.1       raeburn  7076:             }
1.129     raeburn  7077:             if ($changes{'coowners'}) {
                   7078:                 $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
                   7079:                 &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212     raeburn  7080:                 if (ref($lastactref) eq 'HASH') {
                   7081:                     $lastactref->{'domainconfig'} = 1;
                   7082:                 }
1.129     raeburn  7083:             }
1.1       raeburn  7084:             $resulttext .= '</ul>';
                   7085:         } else {
                   7086:             $resulttext = &mt('No changes made to auto-enrollment settings');
                   7087:         }
                   7088:     } else {
1.11      albertel 7089:         $resulttext = '<span class="LC_error">'.
                   7090: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  7091:     }
1.3       raeburn  7092:     return $resulttext;
1.1       raeburn  7093: }
                   7094: 
                   7095: sub modify_autoupdate {
1.3       raeburn  7096:     my ($dom,%domconfig) = @_;
1.1       raeburn  7097:     my ($resulttext,%currautoupdate,%fields,%changes);
                   7098:     if (ref($domconfig{'autoupdate'}) eq 'HASH') {
                   7099:         foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
                   7100:             $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
                   7101:         }
                   7102:     }
                   7103:     my @offon = ('off','on');
                   7104:     my %title = &Apache::lonlocal::texthash (
                   7105:                    run => 'Auto-update:',
                   7106:                    classlists => 'Updates to user information in classlists?'
                   7107:                 );
1.44      raeburn  7108:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1       raeburn  7109:     my %fieldtitles = &Apache::lonlocal::texthash (
                   7110:                         id => 'Student/Employee ID',
1.20      raeburn  7111:                         permanentemail => 'E-mail address',
1.1       raeburn  7112:                         lastname => 'Last Name',
                   7113:                         firstname => 'First Name',
                   7114:                         middlename => 'Middle Name',
1.132     raeburn  7115:                         generation => 'Generation',
1.1       raeburn  7116:                       );
1.142     raeburn  7117:     $othertitle = &mt('All users');
1.1       raeburn  7118:     if (keys(%{$usertypes}) >  0) {
1.26      raeburn  7119:         $othertitle = &mt('Other users');
1.1       raeburn  7120:     }
                   7121:     foreach my $key (keys(%env)) {
                   7122:         if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132     raeburn  7123:             my ($usertype,$item) = ($1,$2);
                   7124:             if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
                   7125:                 if ($usertype eq 'default') {   
                   7126:                     push(@{$fields{$1}},$2);
                   7127:                 } elsif (ref($types) eq 'ARRAY') {
                   7128:                     if (grep(/^\Q$usertype\E$/,@{$types})) {
                   7129:                         push(@{$fields{$1}},$2);
                   7130:                     }
                   7131:                 }
                   7132:             }
1.1       raeburn  7133:         }
                   7134:     }
1.131     raeburn  7135:     my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
                   7136:     @lockablenames = sort(@lockablenames);
                   7137:     if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
                   7138:         my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
                   7139:         if (@changed) {
                   7140:             $changes{'lockablenames'} = 1;
                   7141:         }
                   7142:     } else {
                   7143:         if (@lockablenames) {
                   7144:             $changes{'lockablenames'} = 1;
                   7145:         }
                   7146:     }
1.1       raeburn  7147:     my %updatehash = (
                   7148:                       autoupdate => { run => $env{'form.autoupdate_run'},
                   7149:                                       classlists => $env{'form.classlists'},
                   7150:                                       fields => {%fields},
1.131     raeburn  7151:                                       lockablenames => \@lockablenames,
1.1       raeburn  7152:                                     }
                   7153:                      );
                   7154:     foreach my $key (keys(%currautoupdate)) {
                   7155:         if (($key eq 'run') || ($key eq 'classlists')) {
                   7156:             if (exists($updatehash{autoupdate}{$key})) {
                   7157:                 if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
                   7158:                     $changes{$key} = 1;
                   7159:                 }
                   7160:             }
                   7161:         } elsif ($key eq 'fields') {
                   7162:             if (ref($currautoupdate{$key}) eq 'HASH') {
1.26      raeburn  7163:                 foreach my $item (@{$types},'default') {
1.1       raeburn  7164:                     if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
                   7165:                         my $change = 0;
                   7166:                         foreach my $type (@{$currautoupdate{$key}{$item}}) {
                   7167:                             if (!exists($fields{$item})) {
                   7168:                                 $change = 1;
1.132     raeburn  7169:                                 last;
1.1       raeburn  7170:                             } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26      raeburn  7171:                                 if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1       raeburn  7172:                                     $change = 1;
1.132     raeburn  7173:                                     last;
1.1       raeburn  7174:                                 }
                   7175:                             }
                   7176:                         }
                   7177:                         if ($change) {
                   7178:                             push(@{$changes{$key}},$item);
                   7179:                         }
1.26      raeburn  7180:                     } 
1.1       raeburn  7181:                 }
                   7182:             }
1.131     raeburn  7183:         } elsif ($key eq 'lockablenames') {
                   7184:             if (ref($currautoupdate{$key}) eq 'ARRAY') {
                   7185:                 my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
                   7186:                 if (@changed) {
                   7187:                     $changes{'lockablenames'} = 1;
                   7188:                 }
                   7189:             } else {
                   7190:                 if (@lockablenames) {
                   7191:                     $changes{'lockablenames'} = 1;
                   7192:                 }
                   7193:             }
                   7194:         }
                   7195:     }
                   7196:     unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
                   7197:         if (@lockablenames) {
                   7198:             $changes{'lockablenames'} = 1;
1.1       raeburn  7199:         }
                   7200:     }
1.26      raeburn  7201:     foreach my $item (@{$types},'default') {
                   7202:         if (defined($fields{$item})) {
                   7203:             if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132     raeburn  7204:                 if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
                   7205:                     my $change = 0;
                   7206:                     if (ref($fields{$item}) eq 'ARRAY') {
                   7207:                         foreach my $type (@{$fields{$item}}) {
                   7208:                             if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
                   7209:                                 $change = 1;
                   7210:                                 last;
                   7211:                             }
                   7212:                         }
                   7213:                     }
                   7214:                     if ($change) {
                   7215:                         push(@{$changes{'fields'}},$item);
                   7216:                     }
                   7217:                 } else {
1.26      raeburn  7218:                     push(@{$changes{'fields'}},$item);
                   7219:                 }
                   7220:             } else {
                   7221:                 push(@{$changes{'fields'}},$item);
1.1       raeburn  7222:             }
                   7223:         }
                   7224:     }
                   7225:     my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
                   7226:                                              $dom);
                   7227:     if ($putresult eq 'ok') {
                   7228:         if (keys(%changes) > 0) {
                   7229:             $resulttext = &mt('Changes made:').'<ul>';
                   7230:             foreach my $key (sort(keys(%changes))) {
1.131     raeburn  7231:                 if ($key eq 'lockablenames') {
                   7232:                     $resulttext .= '<li>';
                   7233:                     if (@lockablenames) {
                   7234:                         $usertypes->{'default'} = $othertitle;
                   7235:                         $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
                   7236:                                    join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
                   7237:                     } else {
                   7238:                         $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
                   7239:                     }
                   7240:                     $resulttext .= '</li>';
                   7241:                 } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1       raeburn  7242:                     foreach my $item (@{$changes{$key}}) {
                   7243:                         my @newvalues;
                   7244:                         foreach my $type (@{$fields{$item}}) {
                   7245:                             push(@newvalues,$fieldtitles{$type});
                   7246:                         }
1.3       raeburn  7247:                         my $newvaluestr;
                   7248:                         if (@newvalues > 0) {
                   7249:                             $newvaluestr = join(', ',@newvalues);
                   7250:                         } else {
                   7251:                             $newvaluestr = &mt('none');
1.6       raeburn  7252:                         }
1.1       raeburn  7253:                         if ($item eq 'default') {
1.26      raeburn  7254:                             $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1       raeburn  7255:                         } else {
1.26      raeburn  7256:                             $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1       raeburn  7257:                         }
                   7258:                     }
                   7259:                 } else {
                   7260:                     my $newvalue;
                   7261:                     if ($key eq 'run') {
                   7262:                         $newvalue = $offon[$env{'form.autoupdate_run'}];
                   7263:                     } else {
                   7264:                         $newvalue = $offon[$env{'form.'.$key}];
1.3       raeburn  7265:                     }
1.1       raeburn  7266:                     $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
                   7267:                 }
                   7268:             }
                   7269:             $resulttext .= '</ul>';
                   7270:         } else {
1.3       raeburn  7271:             $resulttext = &mt('No changes made to autoupdates');
1.1       raeburn  7272:         }
                   7273:     } else {
1.11      albertel 7274:         $resulttext = '<span class="LC_error">'.
                   7275: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  7276:     }
1.3       raeburn  7277:     return $resulttext;
1.1       raeburn  7278: }
                   7279: 
1.125     raeburn  7280: sub modify_autocreate {
                   7281:     my ($dom,%domconfig) = @_;
                   7282:     my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
                   7283:     if (ref($domconfig{'autocreate'}) eq 'HASH') {
                   7284:         foreach my $key (keys(%{$domconfig{'autocreate'}})) {
                   7285:             $currautocreate{$key} = $domconfig{'autocreate'}{$key};
                   7286:         }
                   7287:     }
                   7288:     my %title= ( xml => 'Auto-creation of courses in XML course description files',
                   7289:                  req => 'Auto-creation of validated requests for official courses',
                   7290:                  xmldc => 'Identity of course creator of courses from XML files',
                   7291:                );
                   7292:     my @types = ('xml','req');
                   7293:     foreach my $item (@types) {
                   7294:         $newvals{$item} = $env{'form.autocreate_'.$item};
                   7295:         $newvals{$item} =~ s/\D//g;
                   7296:         $newvals{$item} = 0 if ($newvals{$item} eq '');
                   7297:     }
                   7298:     $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
                   7299:     my %domcoords = &get_active_dcs($dom);
                   7300:     unless (exists($domcoords{$newvals{'xmldc'}})) {
                   7301:         $newvals{'xmldc'} = '';
                   7302:     } 
                   7303:     %autocreatehash =  (
                   7304:                         autocreate => { xml => $newvals{'xml'},
                   7305:                                         req => $newvals{'req'},
                   7306:                                       }
                   7307:                        );
                   7308:     if ($newvals{'xmldc'} ne '') {
                   7309:         $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
                   7310:     }
                   7311:     my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
                   7312:                                              $dom);
                   7313:     if ($putresult eq 'ok') {
                   7314:         my @items = @types;
                   7315:         if ($newvals{'xml'}) {
                   7316:             push(@items,'xmldc');
                   7317:         }
                   7318:         foreach my $item (@items) {
                   7319:             if (exists($currautocreate{$item})) {
                   7320:                 if ($currautocreate{$item} ne $newvals{$item}) {
                   7321:                     $changes{$item} = 1;
                   7322:                 }
                   7323:             } elsif ($newvals{$item}) {
                   7324:                 $changes{$item} = 1;
                   7325:             }
                   7326:         }
                   7327:         if (keys(%changes) > 0) {
                   7328:             my @offon = ('off','on'); 
                   7329:             $resulttext = &mt('Changes made:').'<ul>';
                   7330:             foreach my $item (@types) {
                   7331:                 if ($changes{$item}) {
                   7332:                     my $newtxt = $offon[$newvals{$item}];
1.178     raeburn  7333:                     $resulttext .= '<li>'.
                   7334:                                    &mt("$title{$item} set to [_1]$newtxt [_2]",
                   7335:                                        '<b>','</b>').
                   7336:                                    '</li>';
1.125     raeburn  7337:                 }
                   7338:             }
                   7339:             if ($changes{'xmldc'}) {
                   7340:                 my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
                   7341:                 my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178     raeburn  7342:                 $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>'; 
1.125     raeburn  7343:             }
                   7344:             $resulttext .= '</ul>';
                   7345:         } else {
                   7346:             $resulttext = &mt('No changes made to auto-creation settings');
                   7347:         }
                   7348:     } else {
                   7349:         $resulttext = '<span class="LC_error">'.
                   7350:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   7351:     }
                   7352:     return $resulttext;
                   7353: }
                   7354: 
1.23      raeburn  7355: sub modify_directorysrch {
                   7356:     my ($dom,%domconfig) = @_;
                   7357:     my ($resulttext,%changes);
                   7358:     my %currdirsrch;
                   7359:     if (ref($domconfig{'directorysrch'}) eq 'HASH') {
                   7360:         foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
                   7361:             $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
                   7362:         }
                   7363:     }
                   7364:     my %title = ( available => 'Directory search available',
1.24      raeburn  7365:                   localonly => 'Other domains can search',
1.23      raeburn  7366:                   searchby => 'Search types',
                   7367:                   searchtypes => 'Search latitude');
                   7368:     my @offon = ('off','on');
1.24      raeburn  7369:     my @otherdoms = ('Yes','No');
1.23      raeburn  7370: 
1.25      raeburn  7371:     my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');  
1.23      raeburn  7372:     my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
                   7373:     my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
                   7374: 
1.44      raeburn  7375:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26      raeburn  7376:     if (keys(%{$usertypes}) == 0) {
                   7377:         @cansearch = ('default');
                   7378:     } else {
                   7379:         if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
                   7380:             foreach my $type (@{$currdirsrch{'cansearch'}}) {
                   7381:                 if (!grep(/^\Q$type\E$/,@cansearch)) {
                   7382:                     push(@{$changes{'cansearch'}},$type);
                   7383:                 }
1.23      raeburn  7384:             }
1.26      raeburn  7385:             foreach my $type (@cansearch) {
                   7386:                 if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
                   7387:                     push(@{$changes{'cansearch'}},$type);
                   7388:                 }
1.23      raeburn  7389:             }
1.26      raeburn  7390:         } else {
                   7391:             push(@{$changes{'cansearch'}},@cansearch);
1.23      raeburn  7392:         }
                   7393:     }
                   7394: 
                   7395:     if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
                   7396:         foreach my $by (@{$currdirsrch{'searchby'}}) {
                   7397:             if (!grep(/^\Q$by\E$/,@searchby)) {
                   7398:                 push(@{$changes{'searchby'}},$by);
                   7399:             }
                   7400:         }
                   7401:         foreach my $by (@searchby) {
                   7402:             if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
                   7403:                 push(@{$changes{'searchby'}},$by);
                   7404:             }
                   7405:         }
                   7406:     } else {
                   7407:         push(@{$changes{'searchby'}},@searchby);
                   7408:     }
1.25      raeburn  7409: 
                   7410:     if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
                   7411:         foreach my $type (@{$currdirsrch{'searchtypes'}}) {
                   7412:             if (!grep(/^\Q$type\E$/,@searchtypes)) {
                   7413:                 push(@{$changes{'searchtypes'}},$type);
                   7414:             }
                   7415:         }
                   7416:         foreach my $type (@searchtypes) {
                   7417:             if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
                   7418:                 push(@{$changes{'searchtypes'}},$type);
                   7419:             }
                   7420:         }
                   7421:     } else {
                   7422:         if (exists($currdirsrch{'searchtypes'})) {
                   7423:             foreach my $type (@searchtypes) {  
                   7424:                 if ($type ne $currdirsrch{'searchtypes'}) { 
                   7425:                     push(@{$changes{'searchtypes'}},$type);
                   7426:                 }
                   7427:             }
                   7428:             if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
                   7429:                 push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
                   7430:             }   
                   7431:         } else {
                   7432:             push(@{$changes{'searchtypes'}},@searchtypes); 
                   7433:         }
                   7434:     }
                   7435: 
1.23      raeburn  7436:     my %dirsrch_hash =  (
                   7437:             directorysrch => { available => $env{'form.dirsrch_available'},
                   7438:                                cansearch => \@cansearch,
1.24      raeburn  7439:                                localonly => $env{'form.dirsrch_localonly'},
1.23      raeburn  7440:                                searchby => \@searchby,
1.25      raeburn  7441:                                searchtypes => \@searchtypes,
1.23      raeburn  7442:                              }
                   7443:             );
                   7444:     my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
                   7445:                                              $dom);
                   7446:     if ($putresult eq 'ok') {
                   7447:         if (exists($currdirsrch{'available'})) {
                   7448:              if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
                   7449:                  $changes{'available'} = 1;
                   7450:              }
                   7451:         } else {
                   7452:             if ($env{'form.dirsrch_available'} eq '1') {
                   7453:                 $changes{'available'} = 1;
                   7454:             }
                   7455:         }
1.24      raeburn  7456:         if (exists($currdirsrch{'localonly'})) {
                   7457:              if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
                   7458:                  $changes{'localonly'} = 1;
                   7459:              }
                   7460:         } else {
                   7461:             if ($env{'form.dirsrch_localonly'} eq '1') {
                   7462:                 $changes{'localonly'} = 1;
                   7463:             }
                   7464:         }
1.23      raeburn  7465:         if (keys(%changes) > 0) {
                   7466:             $resulttext = &mt('Changes made:').'<ul>';
                   7467:             if ($changes{'available'}) {
                   7468:                 $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
                   7469:             }
1.24      raeburn  7470:             if ($changes{'localonly'}) {
                   7471:                 $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
                   7472:             }
                   7473: 
1.23      raeburn  7474:             if (ref($changes{'cansearch'}) eq 'ARRAY') {
                   7475:                 my $chgtext;
1.26      raeburn  7476:                 if (ref($usertypes) eq 'HASH') {
                   7477:                     if (keys(%{$usertypes}) > 0) {
                   7478:                         foreach my $type (@{$types}) {
                   7479:                             if (grep(/^\Q$type\E$/,@cansearch)) {
                   7480:                                 $chgtext .= $usertypes->{$type}.'; ';
                   7481:                             }
                   7482:                         }
                   7483:                         if (grep(/^default$/,@cansearch)) {
                   7484:                             $chgtext .= $othertitle;
                   7485:                         } else {
                   7486:                             $chgtext =~ s/\; $//;
                   7487:                         }
1.210     raeburn  7488:                         $resulttext .=
1.178     raeburn  7489:                             '<li>'.
                   7490:                             &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
                   7491:                                 '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
                   7492:                             '</li>';
1.23      raeburn  7493:                     }
                   7494:                 }
                   7495:             }
                   7496:             if (ref($changes{'searchby'}) eq 'ARRAY') {
                   7497:                 my ($searchtitles,$titleorder) = &sorted_searchtitles();
                   7498:                 my $chgtext;
                   7499:                 foreach my $type (@{$titleorder}) {
                   7500:                     if (grep(/^\Q$type\E$/,@searchby)) {
                   7501:                         if (defined($searchtitles->{$type})) {
                   7502:                             $chgtext .= $searchtitles->{$type}.'; ';
                   7503:                         }
                   7504:                     }
                   7505:                 }
                   7506:                 $chgtext =~ s/\; $//;
                   7507:                 $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
                   7508:             }
1.25      raeburn  7509:             if (ref($changes{'searchtypes'}) eq 'ARRAY') {
                   7510:                 my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes(); 
                   7511:                 my $chgtext;
                   7512:                 foreach my $type (@{$srchtypeorder}) {
                   7513:                     if (grep(/^\Q$type\E$/,@searchtypes)) {
                   7514:                         if (defined($srchtypes_desc->{$type})) {
                   7515:                             $chgtext .= $srchtypes_desc->{$type}.'; ';
                   7516:                         }
                   7517:                     }
                   7518:                 }
                   7519:                 $chgtext =~ s/\; $//;
1.178     raeburn  7520:                 $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23      raeburn  7521:             }
                   7522:             $resulttext .= '</ul>';
                   7523:         } else {
                   7524:             $resulttext = &mt('No changes made to institution directory search settings');
                   7525:         }
                   7526:     } else {
                   7527:         $resulttext = '<span class="LC_error">'.
1.27      raeburn  7528:                       &mt('An error occurred: [_1]',$putresult).'</span>';
                   7529:     }
                   7530:     return $resulttext;
                   7531: }
                   7532: 
1.28      raeburn  7533: sub modify_contacts {
1.205     raeburn  7534:     my ($dom,$lastactref,%domconfig) = @_;
1.28      raeburn  7535:     my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
                   7536:     if (ref($domconfig{'contacts'}) eq 'HASH') {
                   7537:         foreach my $key (keys(%{$domconfig{'contacts'}})) {
                   7538:             $currsetting{$key} = $domconfig{'contacts'}{$key};
                   7539:         }
                   7540:     }
1.134     raeburn  7541:     my (%others,%to,%bcc);
1.28      raeburn  7542:     my @contacts = ('supportemail','adminemail');
1.102     raeburn  7543:     my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
1.203     raeburn  7544:                     'requestsmail','updatesmail','idconflictsmail');
                   7545:     my @toggles = ('reporterrors','reportupdates');
1.28      raeburn  7546:     foreach my $type (@mailings) {
                   7547:         @{$newsetting{$type}} = 
                   7548:             &Apache::loncommon::get_env_multiple('form.'.$type);
                   7549:         foreach my $item (@contacts) {
                   7550:             if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
                   7551:                 $contacts_hash{contacts}{$type}{$item} = 1;
                   7552:             } else {
                   7553:                 $contacts_hash{contacts}{$type}{$item} = 0;
                   7554:             }
                   7555:         }  
                   7556:         $others{$type} = $env{'form.'.$type.'_others'};
                   7557:         $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.134     raeburn  7558:         if ($type eq 'helpdeskmail') {
                   7559:             $bcc{$type} = $env{'form.'.$type.'_bcc'};
                   7560:             $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
                   7561:         }
1.28      raeburn  7562:     }
                   7563:     foreach my $item (@contacts) {
                   7564:         $to{$item} = $env{'form.'.$item};
                   7565:         $contacts_hash{'contacts'}{$item} = $to{$item};
                   7566:     }
1.203     raeburn  7567:     foreach my $item (@toggles) {
                   7568:         if ($env{'form.'.$item} =~ /^(0|1)$/) {
                   7569:             $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
                   7570:         }
                   7571:     }
1.28      raeburn  7572:     if (keys(%currsetting) > 0) {
                   7573:         foreach my $item (@contacts) {
                   7574:             if ($to{$item} ne $currsetting{$item}) {
                   7575:                 $changes{$item} = 1;
                   7576:             }
                   7577:         }
                   7578:         foreach my $type (@mailings) {
                   7579:             foreach my $item (@contacts) {
                   7580:                 if (ref($currsetting{$type}) eq 'HASH') {
                   7581:                     if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
                   7582:                         push(@{$changes{$type}},$item);
                   7583:                     }
                   7584:                 } else {
                   7585:                     push(@{$changes{$type}},@{$newsetting{$type}});
                   7586:                 }
                   7587:             }
                   7588:             if ($others{$type} ne $currsetting{$type}{'others'}) {
                   7589:                 push(@{$changes{$type}},'others');
                   7590:             }
1.134     raeburn  7591:             if ($type eq 'helpdeskmail') {   
                   7592:                 if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
                   7593:                     push(@{$changes{$type}},'bcc'); 
                   7594:                 }
                   7595:             }
1.28      raeburn  7596:         }
                   7597:     } else {
                   7598:         my %default;
                   7599:         $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
                   7600:         $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
                   7601:         $default{'errormail'} = 'adminemail';
                   7602:         $default{'packagesmail'} = 'adminemail';
                   7603:         $default{'helpdeskmail'} = 'supportemail';
1.89      raeburn  7604:         $default{'lonstatusmail'} = 'adminemail';
1.102     raeburn  7605:         $default{'requestsmail'} = 'adminemail';
1.190     raeburn  7606:         $default{'updatesmail'} = 'adminemail';
1.28      raeburn  7607:         foreach my $item (@contacts) {
                   7608:            if ($to{$item} ne $default{$item}) {
                   7609:               $changes{$item} = 1;
1.203     raeburn  7610:            }
1.28      raeburn  7611:         }
                   7612:         foreach my $type (@mailings) {
                   7613:             if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
                   7614:                
                   7615:                 push(@{$changes{$type}},@{$newsetting{$type}});
                   7616:             }
                   7617:             if ($others{$type} ne '') {
                   7618:                 push(@{$changes{$type}},'others');
1.134     raeburn  7619:             }
                   7620:             if ($type eq 'helpdeskmail') {
                   7621:                 if ($bcc{$type} ne '') {
                   7622:                     push(@{$changes{$type}},'bcc');
                   7623:                 }
                   7624:             }
1.28      raeburn  7625:         }
                   7626:     }
1.203     raeburn  7627:     foreach my $item (@toggles) {
                   7628:         if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
                   7629:             $changes{$item} = 1;
                   7630:         } elsif ((!$env{'form.'.$item}) &&
                   7631:                  (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
                   7632:             $changes{$item} = 1;
                   7633:         }
                   7634:     }
1.28      raeburn  7635:     my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
                   7636:                                              $dom);
                   7637:     if ($putresult eq 'ok') {
                   7638:         if (keys(%changes) > 0) {
1.205     raeburn  7639:             &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212     raeburn  7640:             if (ref($lastactref) eq 'HASH') {
                   7641:                 $lastactref->{'domainconfig'} = 1;
                   7642:             }
1.28      raeburn  7643:             my ($titles,$short_titles)  = &contact_titles();
                   7644:             $resulttext = &mt('Changes made:').'<ul>';
                   7645:             foreach my $item (@contacts) {
                   7646:                 if ($changes{$item}) {
                   7647:                     $resulttext .= '<li>'.$titles->{$item}.
                   7648:                                     &mt(' set to: ').
                   7649:                                     '<span class="LC_cusr_emph">'.
                   7650:                                     $to{$item}.'</span></li>';
                   7651:                 }
                   7652:             }
                   7653:             foreach my $type (@mailings) {
                   7654:                 if (ref($changes{$type}) eq 'ARRAY') {
                   7655:                     $resulttext .= '<li>'.$titles->{$type}.': ';
                   7656:                     my @text;
                   7657:                     foreach my $item (@{$newsetting{$type}}) {
                   7658:                         push(@text,$short_titles->{$item});
                   7659:                     }
                   7660:                     if ($others{$type} ne '') {
                   7661:                         push(@text,$others{$type});
                   7662:                     }
                   7663:                     $resulttext .= '<span class="LC_cusr_emph">'.
1.134     raeburn  7664:                                    join(', ',@text).'</span>';
                   7665:                     if ($type eq 'helpdeskmail') {
                   7666:                         if ($bcc{$type} ne '') {
                   7667:                             $resulttext .= '&nbsp;'.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
                   7668:                         }
                   7669:                     }
                   7670:                     $resulttext .= '</li>';
1.28      raeburn  7671:                 }
                   7672:             }
1.203     raeburn  7673:             my @offon = ('off','on');
                   7674:             if ($changes{'reporterrors'}) {
                   7675:                 $resulttext .= '<li>'.
                   7676:                                &mt('E-mail error reports to [_1] set to "'.
                   7677:                                    $offon[$env{'form.reporterrors'}].'".',
                   7678:                                    &Apache::loncommon::modal_link('http://loncapa.org/core.html',
                   7679:                                        &mt('LON-CAPA core group - MSU'),600,500)).
                   7680:                                '</li>';
                   7681:             }
                   7682:             if ($changes{'reportupdates'}) {
                   7683:                 $resulttext .= '<li>'.
                   7684:                                 &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
                   7685:                                     $offon[$env{'form.reportupdates'}].'".',
                   7686:                                     &Apache::loncommon::modal_link('http://loncapa.org/core.html',
                   7687:                                         &mt('LON-CAPA core group - MSU'),600,500)).
                   7688:                                 '</li>';
                   7689:             }
1.28      raeburn  7690:             $resulttext .= '</ul>';
                   7691:         } else {
1.34      raeburn  7692:             $resulttext = &mt('No changes made to contact information');
1.28      raeburn  7693:         }
                   7694:     } else {
                   7695:         $resulttext = '<span class="LC_error">'.
                   7696:             &mt('An error occurred: [_1].',$putresult).'</span>';
                   7697:     }
                   7698:     return $resulttext;
                   7699: }
                   7700: 
                   7701: sub modify_usercreation {
1.27      raeburn  7702:     my ($dom,%domconfig) = @_;
1.224     raeburn  7703:     my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43      raeburn  7704:     my $warningmsg;
1.27      raeburn  7705:     if (ref($domconfig{'usercreation'}) eq 'HASH') {
                   7706:         foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224     raeburn  7707:             if ($key eq 'cancreate') {
                   7708:                 if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
                   7709:                     foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
                   7710:                         if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
                   7711:                             ($item eq 'captcha') || ($item eq 'recaptchakeys')) {
                   7712:                             $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
                   7713:                         } else {
                   7714:                             $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
                   7715:                         }
                   7716:                     }
                   7717:                 }
                   7718:             } elsif ($key eq 'email_rule') {
                   7719:                 $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
                   7720:             } else {
                   7721:                 $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
                   7722:             }
1.27      raeburn  7723:         }
                   7724:     }
                   7725:     my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32      raeburn  7726:     my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224     raeburn  7727:     my @contexts = ('author','course','requestcrs');
1.34      raeburn  7728:     foreach my $item(@contexts) {
1.224     raeburn  7729:         $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93      raeburn  7730:     }
1.34      raeburn  7731:     if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
                   7732:         foreach my $item (@contexts) {
1.224     raeburn  7733:             if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
                   7734:                 push(@{$changes{'cancreate'}},$item);
1.50      raeburn  7735:             }
1.27      raeburn  7736:         }
1.34      raeburn  7737:     } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
                   7738:         foreach my $item (@contexts) {
1.43      raeburn  7739:             if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34      raeburn  7740:                 if ($cancreate{$item} ne 'any') {
                   7741:                     push(@{$changes{'cancreate'}},$item);
                   7742:                 }
                   7743:             } else {
                   7744:                 if ($cancreate{$item} ne 'none') {
                   7745:                     push(@{$changes{'cancreate'}},$item);
                   7746:                 }
1.27      raeburn  7747:             }
                   7748:         }
                   7749:     } else {
1.43      raeburn  7750:         foreach my $item (@contexts)  {
1.34      raeburn  7751:             push(@{$changes{'cancreate'}},$item);
                   7752:         }
1.27      raeburn  7753:     }
1.34      raeburn  7754: 
1.27      raeburn  7755:     if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
                   7756:         foreach my $type (@{$curr_usercreation{'username_rule'}}) {
                   7757:             if (!grep(/^\Q$type\E$/,@username_rule)) {
                   7758:                 push(@{$changes{'username_rule'}},$type);
                   7759:             }
                   7760:         }
                   7761:         foreach my $type (@username_rule) {
                   7762:             if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
                   7763:                 push(@{$changes{'username_rule'}},$type);
                   7764:             }
                   7765:         }
                   7766:     } else {
                   7767:         push(@{$changes{'username_rule'}},@username_rule);
                   7768:     }
                   7769: 
1.32      raeburn  7770:     if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
                   7771:         foreach my $type (@{$curr_usercreation{'id_rule'}}) {
                   7772:             if (!grep(/^\Q$type\E$/,@id_rule)) {
                   7773:                 push(@{$changes{'id_rule'}},$type);
                   7774:             }
                   7775:         }
                   7776:         foreach my $type (@id_rule) {
                   7777:             if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
                   7778:                 push(@{$changes{'id_rule'}},$type);
                   7779:             }
                   7780:         }
                   7781:     } else {
                   7782:         push(@{$changes{'id_rule'}},@id_rule);
                   7783:     }
                   7784: 
1.43      raeburn  7785:     my @authen_contexts = ('author','course','domain');
1.28      raeburn  7786:     my @authtypes = ('int','krb4','krb5','loc');
                   7787:     my %authhash;
1.43      raeburn  7788:     foreach my $item (@authen_contexts) {
1.28      raeburn  7789:         my @authallowed =  &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
                   7790:         foreach my $auth (@authtypes) {
                   7791:             if (grep(/^\Q$auth\E$/,@authallowed)) {
                   7792:                 $authhash{$item}{$auth} = 1;
                   7793:             } else {
                   7794:                 $authhash{$item}{$auth} = 0;
                   7795:             }
                   7796:         }
                   7797:     }
                   7798:     if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43      raeburn  7799:         foreach my $item (@authen_contexts) {
1.28      raeburn  7800:             if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
                   7801:                 foreach my $auth (@authtypes) {
                   7802:                     if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
                   7803:                         push(@{$changes{'authtypes'}},$item);
                   7804:                         last;
                   7805:                     }
                   7806:                 }
                   7807:             }
                   7808:         }
                   7809:     } else {
1.43      raeburn  7810:         foreach my $item (@authen_contexts) {
1.28      raeburn  7811:             push(@{$changes{'authtypes'}},$item);
                   7812:         }
                   7813:     }
                   7814: 
1.224     raeburn  7815:     $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'}; 
                   7816:     $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
                   7817:     $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
                   7818:     $save_usercreate{'id_rule'} = \@id_rule;
                   7819:     $save_usercreate{'username_rule'} = \@username_rule,
                   7820:     $save_usercreate{'authtypes'} = \%authhash;
                   7821: 
1.27      raeburn  7822:     my %usercreation_hash =  (
1.224     raeburn  7823:         usercreation     => \%save_usercreate,
                   7824:     );
1.27      raeburn  7825: 
                   7826:     my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
                   7827:                                              $dom);
1.50      raeburn  7828: 
1.224     raeburn  7829:     if ($putresult eq 'ok') {
                   7830:         if (keys(%changes) > 0) {
                   7831:             $resulttext = &mt('Changes made:').'<ul>';
                   7832:             if (ref($changes{'cancreate'}) eq 'ARRAY') {
                   7833:                 my %lt = &usercreation_types();
                   7834:                 foreach my $type (@{$changes{'cancreate'}}) {
                   7835:                     my $chgtext = $lt{$type}.', ';
                   7836:                     if ($cancreate{$type} eq 'none') {
                   7837:                         $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
                   7838:                     } elsif ($cancreate{$type} eq 'any') {
                   7839:                         $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
                   7840:                     } elsif ($cancreate{$type} eq 'official') {
                   7841:                         $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
                   7842:                     } elsif ($cancreate{$type} eq 'unofficial') {
                   7843:                         $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
                   7844:                     }
                   7845:                     $resulttext .= '<li>'.$chgtext.'</li>';
                   7846:                 }
                   7847:             }
                   7848:             if (ref($changes{'username_rule'}) eq 'ARRAY') {
                   7849:                 my ($rules,$ruleorder) = 
                   7850:                     &Apache::lonnet::inst_userrules($dom,'username');
                   7851:                 my $chgtext = '<ul>';
                   7852:                 foreach my $type (@username_rule) {
                   7853:                     if (ref($rules->{$type}) eq 'HASH') {
                   7854:                         $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
                   7855:                     }
                   7856:                 }
                   7857:                 $chgtext .= '</ul>';
                   7858:                 if (@username_rule > 0) {
                   7859:                     $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';     
                   7860:                 } else {
                   7861:                     $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>'; 
                   7862:                 }
                   7863:             }
                   7864:             if (ref($changes{'id_rule'}) eq 'ARRAY') {
                   7865:                 my ($idrules,$idruleorder) = 
                   7866:                     &Apache::lonnet::inst_userrules($dom,'id');
                   7867:                 my $chgtext = '<ul>';
                   7868:                 foreach my $type (@id_rule) {
                   7869:                     if (ref($idrules->{$type}) eq 'HASH') {
                   7870:                         $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
                   7871:                     }
                   7872:                 }
                   7873:                 $chgtext .= '</ul>';
                   7874:                 if (@id_rule > 0) {
                   7875:                     $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
                   7876:                 } else {
                   7877:                     $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
                   7878:                 }
                   7879:             }
                   7880:             my %authname = &authtype_names();
                   7881:             my %context_title = &context_names();
                   7882:             if (ref($changes{'authtypes'}) eq 'ARRAY') {
                   7883:                 my $chgtext = '<ul>';
                   7884:                 foreach my $type (@{$changes{'authtypes'}}) {
                   7885:                     my @allowed;
                   7886:                     $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
                   7887:                     foreach my $auth (@authtypes) {
                   7888:                         if ($authhash{$type}{$auth}) {
                   7889:                             push(@allowed,$authname{$auth});
                   7890:                         }
                   7891:                     }
                   7892:                     if (@allowed > 0) {
                   7893:                         $chgtext .= join(', ',@allowed).'</li>';
                   7894:                     } else {
                   7895:                         $chgtext .= &mt('none').'</li>';
                   7896:                     }
                   7897:                 }
                   7898:                 $chgtext .= '</ul>';
                   7899:                 $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
                   7900:                 $resulttext .= '</li>';
                   7901:             }
                   7902:             $resulttext .= '</ul>';
                   7903:         } else {
                   7904:             $resulttext = &mt('No changes made to user creation settings');
                   7905:         }
                   7906:     } else {
                   7907:         $resulttext = '<span class="LC_error">'.
                   7908:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   7909:     }
                   7910:     if ($warningmsg ne '') {
                   7911:         $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
                   7912:     }
                   7913:     return $resulttext;
                   7914: }
                   7915: 
                   7916: sub modify_selfcreation {
                   7917:     my ($dom,%domconfig) = @_;
                   7918:     my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%changes,%cancreate);
                   7919:     my (%save_usercreate,%save_usermodify);
1.228     raeburn  7920:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   7921:     if (ref($types) eq 'ARRAY') {
                   7922:         $usertypes->{'default'} = $othertitle;
                   7923:         push(@{$types},'default');
                   7924:     }
1.224     raeburn  7925: #
                   7926: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
                   7927: #
                   7928:     if (ref($domconfig{'usercreation'}) eq 'HASH') {
                   7929:         foreach my $key (keys(%{$domconfig{'usercreation'}})) {
                   7930:             if ($key eq 'cancreate') {
                   7931:                 if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
                   7932:                     foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
                   7933:                         if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
                   7934:                             ($item eq 'captcha') || ($item eq 'recaptchakeys') || 
                   7935:                             ($item eq 'emailusername') || ($item eq 'notify')) {
                   7936:                             $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
                   7937:                         } else {
                   7938:                             $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
                   7939:                         }
                   7940:                     }
                   7941:                 }
                   7942:             } elsif ($key eq 'email_rule') {
                   7943:                 $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
                   7944:             } else {
                   7945:                 $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
                   7946:             }
                   7947:         }
                   7948:     }
                   7949: #
                   7950: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
                   7951: #
                   7952:     if (ref($domconfig{'usermodification'}) eq 'HASH') {
                   7953:         foreach my $key (keys(%{$domconfig{'usermodification'}})) {
                   7954:             if ($key eq 'selfcreate') {
                   7955:                 $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
                   7956:             } else {
                   7957:                 $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
                   7958:             }
                   7959:         }
                   7960:     }
                   7961: 
                   7962:     my @contexts = ('selfcreate');
                   7963:     @{$cancreate{'selfcreate'}} = ();
                   7964:     %{$cancreate{'emailusername'}} = ();
                   7965:     @{$cancreate{'statustocreate'}} = ();
1.50      raeburn  7966:     my %selfcreatetypes = (
                   7967:                              sso   => 'users authenticated by institutional single sign on',
                   7968:                              login => 'users authenticated by institutional log-in',
1.224     raeburn  7969:                              email => 'users who provide a valid e-mail address for use as username (automatic creation)',
                   7970:                              emailapproval => 'users who provide a valid e-mail address for use as username (queued for Domain Coordinator review)',
1.50      raeburn  7971:                           );
1.224     raeburn  7972: #
                   7973: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
                   7974: # is permitted.
                   7975: #
1.228     raeburn  7976:     foreach my $item ('login','sso','email') {
1.224     raeburn  7977:         if ($item eq 'email') {
                   7978:             if ($env{'form.cancreate_email'} eq 'email') {
                   7979:                 push(@{$cancreate{'selfcreate'}},'email');
                   7980:             } elsif ($env{'form.cancreate_email'} eq 'emailapproval') {
                   7981:                 push(@{$cancreate{'selfcreate'}},'emailapproval');
                   7982:             }
                   7983:         } else {
                   7984:             if ($env{'form.cancreate_'.$item}) {
                   7985:                 push(@{$cancreate{'selfcreate'}},$item);
                   7986:             }
                   7987:         }
                   7988:     }
                   7989:     my (@email_rule,%userinfo,%savecaptcha);
                   7990:     my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
                   7991: #
1.228     raeburn  7992: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
                   7993: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.224     raeburn  7994: #
                   7995:     if (($env{'form.cancreate_email'} eq 'email') || ($env{'form.cancreate_email'} eq 'emailapproval')) {
1.228     raeburn  7996:         push(@contexts,'emailusername');
                   7997:         if (ref($types) eq 'ARRAY') {
                   7998:             foreach my $type (@{$types}) {
                   7999:                 if (ref($infofields) eq 'ARRAY') {
                   8000:                     foreach my $field (@{$infofields}) {
                   8001:                         if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
                   8002:                             $cancreate{'emailusername'}{$type}{$field} = $1;
                   8003:                         }
                   8004:                     }
1.224     raeburn  8005:                 }
                   8006:             }
                   8007:         }
                   8008: #
                   8009: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
                   8010: # queued requests for self-creation of account using e-mail address as username
                   8011: #
                   8012: 
                   8013:         my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
                   8014:         @approvalnotify = sort(@approvalnotify);
                   8015:         $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
                   8016:         if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
                   8017:             if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
                   8018:                 if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
                   8019:                     push(@{$changes{'cancreate'}},'notify');
                   8020:                 }
                   8021:             } else {
                   8022:                 if ($cancreate{'notify'}{'approval'}) {
                   8023:                     push(@{$changes{'cancreate'}},'notify');
                   8024:                 }
                   8025:             }
                   8026:         } elsif ($cancreate{'notify'}{'approval'}) {
                   8027:             push(@{$changes{'cancreate'}},'notify');
                   8028:         }
                   8029: 
                   8030: #
                   8031: # Retrieve rules (if any) governing types of e-mail address which may be used as a username
                   8032: #
                   8033:         @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
                   8034:         &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
                   8035:         if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
                   8036:             if (@{$curr_usercreation{'email_rule'}} > 0) {
                   8037:                 foreach my $type (@{$curr_usercreation{'email_rule'}}) {
                   8038:                     if (!grep(/^\Q$type\E$/,@email_rule)) {
                   8039:                         push(@{$changes{'email_rule'}},$type);
                   8040:                     }
                   8041:                 }
                   8042:             }
                   8043:             if (@email_rule > 0) {
                   8044:                 foreach my $type (@email_rule) {
                   8045:                     if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
                   8046:                         push(@{$changes{'email_rule'}},$type);
                   8047:                     }
                   8048:                 }
                   8049:             }
                   8050:         } elsif (@email_rule > 0) {
                   8051:             push(@{$changes{'email_rule'}},@email_rule);
                   8052:         }
                   8053:     }
                   8054: #  
                   8055: # Check if domain default is set appropriately, if selef-creation of accounts is to be available for
                   8056: # institutional log-in.
                   8057: #
                   8058:     if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
                   8059:         my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
                   8060:         if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) || 
                   8061:                ($domdefaults{'auth_def'} eq 'localauth'))) {
                   8062:             $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.').' '.
                   8063:                           &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.');
                   8064:         }
                   8065:     }
                   8066:     my @fields = ('lastname','firstname','middlename','generation',
                   8067:                   'permanentemail','id');
                   8068:     my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
                   8069: #
                   8070: # Where usernames may created for institutional log-in and/or institutional single sign on:
                   8071: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
                   8072: # may self-create accounts 
                   8073: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
                   8074: # which the user may supply, if institutional data is unavailable.
                   8075: #
                   8076:     if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
                   8077:         if (ref($types) eq 'ARRAY') {
1.228     raeburn  8078:             if (@{$types} > 1) {
1.224     raeburn  8079:                 @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
                   8080:                 push(@contexts,'statustocreate');
                   8081:             } else {
                   8082:                 undef($cancreate{'statustocreate'});
                   8083:             } 
                   8084:             foreach my $type (@{$types}) {
                   8085:                 my @modifiable =  &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
                   8086:                 foreach my $field (@fields) {
                   8087:                     if (grep(/^\Q$field\E$/,@modifiable)) {
                   8088:                         $save_usermodify{'selfcreate'}{$type}{$field} = 1;
                   8089:                     } else {
                   8090:                         $save_usermodify{'selfcreate'}{$type}{$field} = 0;
                   8091:                     }
                   8092:                 }
                   8093:             }
                   8094:             if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
                   8095:                 foreach my $type (@{$types}) {
                   8096:                     if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
                   8097:                         foreach my $field (@fields) {
                   8098:                             if ($save_usermodify{'selfcreate'}{$type}{$field} ne
                   8099:                                 $curr_usermodify{'selfcreate'}{$type}{$field}) {
                   8100:                                 push(@{$changes{'selfcreate'}},$type);
                   8101:                                 last;
                   8102:                             }
                   8103:                         }
                   8104:                     }
                   8105:                 }
                   8106:             } else {
                   8107:                 foreach my $type (@{$types}) {
                   8108:                     push(@{$changes{'selfcreate'}},$type);
                   8109:                 }
                   8110:             }
                   8111:         }
                   8112:     }
                   8113:     foreach my $item (@contexts) {
                   8114:         if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
                   8115:             foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
                   8116:                 if (ref($cancreate{$item}) eq 'ARRAY') {
                   8117:                     if (!grep(/^$curr$/,@{$cancreate{$item}})) {
                   8118:                         if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   8119:                             push(@{$changes{'cancreate'}},$item);
                   8120:                         }
                   8121:                     }
                   8122:                 }
                   8123:             }
                   8124:             if (ref($cancreate{$item}) eq 'ARRAY') {
                   8125:                 foreach my $type (@{$cancreate{$item}}) {
                   8126:                     if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
                   8127:                         if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   8128:                             push(@{$changes{'cancreate'}},$item);
                   8129:                         }
                   8130:                     }
                   8131:                 }
                   8132:             }
                   8133:         } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
                   8134:             if (ref($cancreate{$item}) eq 'HASH') {
                   8135:                 foreach my $curr (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
1.228     raeburn  8136:                     if (ref($curr_usercreation{'cancreate'}{$item}{$curr}) eq 'HASH') {
                   8137:                         foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$curr}})) {
                   8138:                             unless ($curr_usercreation{'cancreate'}{$item}{$curr}{$field} eq $cancreate{$item}{$curr}{$field}) {
                   8139:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   8140:                                     push(@{$changes{'cancreate'}},$item);
                   8141:                                 }
                   8142:                             }
                   8143:                         }
                   8144:                     } else {
                   8145:                         if (!$cancreate{$item}{$curr}) {
                   8146:                             if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   8147:                                 push(@{$changes{'cancreate'}},$item);
                   8148:                             }
1.224     raeburn  8149:                         }
                   8150:                     }
                   8151:                 }
                   8152:                 foreach my $field (keys(%{$cancreate{$item}})) {
1.228     raeburn  8153:                     if (ref($cancreate{$item}{$field}) eq 'HASH') {
                   8154:                         foreach my $inner (keys(%{$cancreate{$item}{$field}})) {
                   8155:                             if (ref($curr_usercreation{'cancreate'}{$item}{$field}) eq 'HASH') {
                   8156:                                 unless ($curr_usercreation{'cancreate'}{$item}{$field}{$inner} eq $cancreate{$item}{$field}{$inner}) {
                   8157:                                     if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   8158:                                         push(@{$changes{'cancreate'}},$item);
                   8159:                                     }
                   8160:                                 }
                   8161:                             } else {
                   8162:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   8163:                                     push(@{$changes{'cancreate'}},$item);
                   8164:                                 }
                   8165:                             }
                   8166:                         }
                   8167:                     } else {
                   8168:                         if (!$curr_usercreation{'cancreate'}{$item}{$field}) {
                   8169:                             if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   8170:                                 push(@{$changes{'cancreate'}},$item);
                   8171:                             }
1.224     raeburn  8172:                         }
                   8173:                     }
                   8174:                 }
                   8175:             }
                   8176:         } elsif ($curr_usercreation{'cancreate'}{$item}) {
                   8177:             if (ref($cancreate{$item}) eq 'ARRAY') {
                   8178:                 if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
                   8179:                     if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   8180:                         push(@{$changes{'cancreate'}},$item);
                   8181:                     }
                   8182:                 }
                   8183:             } elsif (ref($cancreate{$item}) eq 'HASH') {
                   8184:                 if (!$cancreate{$item}{$curr_usercreation{'cancreate'}{$item}}) {
                   8185:                     if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   8186:                         push(@{$changes{'cancreate'}},$item);
                   8187:                     }
                   8188:                 }
                   8189:             }
                   8190:         } elsif ($item eq 'emailusername') {
1.228     raeburn  8191:             if (ref($cancreate{$item}) eq 'HASH') {
                   8192:                 foreach my $type (keys(%{$cancreate{$item}})) {
                   8193:                     if (ref($cancreate{$item}{$type}) eq 'HASH') {
                   8194:                         foreach my $field (keys(%{$cancreate{$item}{$type}})) {
                   8195:                             if ($cancreate{$item}{$type}{$field}) {
                   8196:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   8197:                                     push(@{$changes{'cancreate'}},$item);
                   8198:                                 }
                   8199:                                 last;
                   8200:                             }
                   8201:                         }
                   8202:                     }
                   8203:                 }
1.224     raeburn  8204:             }
                   8205:         }
                   8206:     }
                   8207: #
                   8208: # Populate %save_usercreate hash with updates to self-creation configuration.
                   8209: #
                   8210:     $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
                   8211:     $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
                   8212:     $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
                   8213:     if (ref($cancreate{'notify'}) eq 'HASH') {
                   8214:         $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
                   8215:     }
                   8216:     if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
                   8217:         $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
                   8218:     }
                   8219:     $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
                   8220:     $save_usercreate{'emailrule'} = \@email_rule;
                   8221: 
                   8222:     my %userconfig_hash = (
                   8223:             usercreation     => \%save_usercreate,
                   8224:             usermodification => \%save_usermodify,
                   8225:     );
                   8226:     my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
                   8227:                                              $dom);
                   8228: #
                   8229: # Accumulate details of changes to domain cofiguration for self-creation of usernames in $resulttext
                   8230: #
1.27      raeburn  8231:     if ($putresult eq 'ok') {
                   8232:         if (keys(%changes) > 0) {
                   8233:             $resulttext = &mt('Changes made:').'<ul>';
                   8234:             if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224     raeburn  8235:                 my %lt = &selfcreation_types();
1.34      raeburn  8236:                 foreach my $type (@{$changes{'cancreate'}}) {
1.100     raeburn  8237:                     my $chgtext;
1.45      raeburn  8238:                     if ($type eq 'selfcreate') {
1.50      raeburn  8239:                         if (@{$cancreate{$type}} == 0) {
1.224     raeburn  8240:                             $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50      raeburn  8241:                         } else {
1.224     raeburn  8242:                             $chgtext .= &mt('Self-creation of a new account is permitted for:').
                   8243:                                         '<ul>';
1.50      raeburn  8244:                             foreach my $case (@{$cancreate{$type}}) {
                   8245:                                 $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
                   8246:                             }
                   8247:                             $chgtext .= '</ul>';
1.100     raeburn  8248:                             if (ref($cancreate{$type}) eq 'ARRAY') {
                   8249:                                 if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
                   8250:                                     if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
                   8251:                                         if (@{$cancreate{'statustocreate'}} == 0) {
1.224     raeburn  8252:                                             $chgtext .= '<br />'.
                   8253:                                                         '<span class="LC_warning">'.
                   8254:                                                         &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
                   8255:                                                         '</span>';
1.100     raeburn  8256:                                         }
                   8257:                                     }
                   8258:                                 }
                   8259:                             }
1.43      raeburn  8260:                         }
1.93      raeburn  8261:                     } elsif ($type eq 'statustocreate') {
1.96      raeburn  8262:                         if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
                   8263:                             (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
                   8264:                             if (@{$cancreate{'selfcreate'}} > 0) {
                   8265:                                 if (@{$cancreate{'statustocreate'}} == 0) {
1.100     raeburn  8266:                                     $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96      raeburn  8267:                                     if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224     raeburn  8268:                                         $chgtext .= '<br />'.
                   8269:                                                     '<span class="LC_warning">'.
                   8270:                                                     &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
                   8271:                                                     '</span>';
                   8272:                                     }
1.96      raeburn  8273:                                 } elsif (ref($usertypes) eq 'HASH') {
                   8274:                                     if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100     raeburn  8275:                                         $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
                   8276:                                     } else {
                   8277:                                         $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
                   8278:                                     }
                   8279:                                     $chgtext .= '<ul>';
                   8280:                                     foreach my $case (@{$cancreate{$type}}) {
                   8281:                                         if ($case eq 'default') {
                   8282:                                             $chgtext .= '<li>'.$othertitle.'</li>';
                   8283:                                         } else {
                   8284:                                             $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93      raeburn  8285:                                         }
                   8286:                                     }
1.100     raeburn  8287:                                     $chgtext .= '</ul>';
                   8288:                                     if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.224     raeburn  8289:                                         $chgtext .= '<br /><span class="LC_warning">'.
                   8290:                                                     &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
                   8291:                                                     '</span>';
1.100     raeburn  8292:                                     }
                   8293:                                 }
                   8294:                             } else {
                   8295:                                 if (@{$cancreate{$type}} == 0) {
                   8296:                                     $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
                   8297:                                 } else {
                   8298:                                     $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  8299:                                 }
                   8300:                             }
                   8301:                         }
1.165     raeburn  8302:                     } elsif ($type eq 'captcha') {
1.224     raeburn  8303:                         if ($savecaptcha{$type} eq 'notused') {
1.165     raeburn  8304:                             $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
                   8305:                         } else {
                   8306:                             my %captchas = &captcha_phrases();
1.224     raeburn  8307:                             if ($captchas{$savecaptcha{$type}}) {
                   8308:                                 $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165     raeburn  8309:                             } else {
1.210     raeburn  8310:                                 $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165     raeburn  8311:                             }
                   8312:                         }
                   8313:                     } elsif ($type eq 'recaptchakeys') {
                   8314:                         my ($privkey,$pubkey);
1.224     raeburn  8315:                         if (ref($savecaptcha{$type}) eq 'HASH') {
                   8316:                             $pubkey = $savecaptcha{$type}{'public'};
                   8317:                             $privkey = $savecaptcha{$type}{'private'};
1.165     raeburn  8318:                         }
                   8319:                         $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
                   8320:                         if (!$pubkey) {
                   8321:                             $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
                   8322:                         } else {
                   8323:                             $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
                   8324:                         }
                   8325:                         if (!$privkey) {
                   8326:                             $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
                   8327:                         } else {
                   8328:                             $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
                   8329:                         }
                   8330:                         $chgtext .= '</ul>';
1.224     raeburn  8331:                     } elsif ($type eq 'emailusername') {
                   8332:                         if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.228     raeburn  8333:                             if (ref($types) eq 'ARRAY') {
                   8334:                                 foreach my $type (@{$types}) {
                   8335:                                     if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
                   8336:                                         if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
                   8337:                                             $chgtext .= &mt('When self-creating account with e-mail as username, the following information will be provided by [_1]:',$usertypes->{$type}).
                   8338:                                                     '<ul>';
                   8339:                                             foreach my $field (@{$infofields}) {
                   8340:                                                 if ($cancreate{'emailusername'}{$type}{$field}) {
                   8341:                                                     $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
                   8342:                                                 }
                   8343:                                             }
                   8344:                                         }
                   8345:                                         $chgtext .= '</ul>';
                   8346:                                     } else {
                   8347:                                         $chgtext .= &mt('When self creating account with e-mail as username, no information besides e-mail address will be provided by [_1].',$usertypes->{$type}).'<br />';
1.224     raeburn  8348:                                     }
                   8349:                                 }
                   8350:                             }
                   8351:                         }
                   8352:                     } elsif ($type eq 'notify') {
                   8353:                         $chgtext = &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
                   8354:                         if (ref($changes{'cancreate'}) eq 'ARRAY') {
                   8355:                             if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
                   8356:                                 if ($cancreate{'notify'}{'approval'}) {
                   8357:                                     $chgtext = &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
                   8358:                                 }
                   8359:                             }
1.43      raeburn  8360:                         }
1.34      raeburn  8361:                     }
1.224     raeburn  8362:                     if ($chgtext) {
                   8363:                         $resulttext .= '<li>'.$chgtext.'</li>';
1.32      raeburn  8364:                     }
                   8365:                 }
                   8366:             }
1.43      raeburn  8367:             if (ref($changes{'email_rule'}) eq 'ARRAY') {
                   8368:                 my ($emailrules,$emailruleorder) =
                   8369:                     &Apache::lonnet::inst_userrules($dom,'email');
                   8370:                 my $chgtext = '<ul>';
                   8371:                 foreach my $type (@email_rule) {
                   8372:                     if (ref($emailrules->{$type}) eq 'HASH') {
                   8373:                         $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
                   8374:                     }
                   8375:                 }
                   8376:                 $chgtext .= '</ul>';
                   8377:                 if (@email_rule > 0) {
1.224     raeburn  8378:                     $resulttext .= '<li>'.
                   8379:                                    &mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').
                   8380:                                        $chgtext.
                   8381:                                    '</li>';
1.43      raeburn  8382:                 } else {
1.224     raeburn  8383:                     $resulttext .= '<li>'.
                   8384:                                    &mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').
                   8385:                                    '</li>';
1.43      raeburn  8386:                 }
                   8387:             }
1.224     raeburn  8388:             if (ref($changes{'selfcreate'}) eq 'ARRAY') {
                   8389:                 $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
                   8390:                 my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
                   8391:                 foreach my $type (@{$changes{'selfcreate'}}) {
                   8392:                     my $typename = $type;
                   8393:                     if (ref($usertypes) eq 'HASH') {
                   8394:                         if ($usertypes->{$type} ne '') {
                   8395:                             $typename = $usertypes->{$type};
                   8396:                         }
                   8397:                     }
                   8398:                     my @modifiable;
                   8399:                     $resulttext .= '<li>'.
                   8400:                                     &mt('Self-creation of account by users with status: [_1]',
                   8401:                                         '<span class="LC_cusr_emph">'.$typename.'</span>').
                   8402:                                     ' - '.&mt('modifiable fields (if institutional data blank): ');
                   8403:                     foreach my $field (@fields) {
                   8404:                         if ($save_usermodify{'selfcreate'}{$type}{$field}) {
                   8405:                             push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28      raeburn  8406:                         }
                   8407:                     }
1.224     raeburn  8408:                     if (@modifiable > 0) {
                   8409:                         $resulttext .= join(', ',@modifiable);
1.43      raeburn  8410:                     } else {
1.224     raeburn  8411:                         $resulttext .= &mt('none');
1.43      raeburn  8412:                     }
1.224     raeburn  8413:                     $resulttext .= '</li>';
1.28      raeburn  8414:                 }
1.224     raeburn  8415:                 $resulttext .= '</ul></li>';
1.28      raeburn  8416:             }
1.27      raeburn  8417:             $resulttext .= '</ul>';
                   8418:         } else {
1.224     raeburn  8419:             $resulttext = &mt('No changes made to self-creation settings');
1.27      raeburn  8420:         }
                   8421:     } else {
                   8422:         $resulttext = '<span class="LC_error">'.
1.23      raeburn  8423:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   8424:     }
1.43      raeburn  8425:     if ($warningmsg ne '') {
                   8426:         $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
                   8427:     }
1.23      raeburn  8428:     return $resulttext;
                   8429: }
                   8430: 
1.165     raeburn  8431: sub process_captcha {
                   8432:     my ($container,$changes,$newsettings,$current) = @_;
                   8433:     return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
                   8434:     $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
                   8435:     unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
                   8436:         $newsettings->{'captcha'} = 'original';
                   8437:     }
                   8438:     if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
1.210     raeburn  8439:         if ($container eq 'cancreate') {
1.169     raeburn  8440:             if (ref($changes->{'cancreate'}) eq 'ARRAY') {
                   8441:                 push(@{$changes->{'cancreate'}},'captcha');
                   8442:             } elsif (!defined($changes->{'cancreate'})) {
                   8443:                 $changes->{'cancreate'} = ['captcha'];
                   8444:             }
                   8445:         } else {
                   8446:             $changes->{'captcha'} = 1;
1.165     raeburn  8447:         }
                   8448:     }
                   8449:     my ($newpub,$newpriv,$currpub,$currpriv);
                   8450:     if ($newsettings->{'captcha'} eq 'recaptcha') {
                   8451:         $newpub = $env{'form.'.$container.'_recaptchapub'};
                   8452:         $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.169     raeburn  8453:         $newpub =~ s/\W//g;
                   8454:         $newpriv =~ s/\W//g;
                   8455:         $newsettings->{'recaptchakeys'} = {
                   8456:                                              public  => $newpub,
                   8457:                                              private => $newpriv,
                   8458:                                           };
1.165     raeburn  8459:     }
                   8460:     if (ref($current->{'recaptchakeys'}) eq 'HASH') {
                   8461:         $currpub = $current->{'recaptchakeys'}{'public'};
                   8462:         $currpriv = $current->{'recaptchakeys'}{'private'};
1.179     raeburn  8463:         unless ($newsettings->{'captcha'} eq 'recaptcha') {
                   8464:             $newsettings->{'recaptchakeys'} = {
                   8465:                                                  public  => '',
                   8466:                                                  private => '',
                   8467:                                               }
                   8468:         }
1.165     raeburn  8469:     }
                   8470:     if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169     raeburn  8471:         if ($container eq 'cancreate') {
                   8472:             if (ref($changes->{'cancreate'}) eq 'ARRAY') {
                   8473:                 push(@{$changes->{'cancreate'}},'recaptchakeys');
                   8474:             } elsif (!defined($changes->{'cancreate'})) {
                   8475:                 $changes->{'cancreate'} = ['recaptchakeys'];
                   8476:             }
                   8477:         } else {
1.210     raeburn  8478:             $changes->{'recaptchakeys'} = 1;
1.165     raeburn  8479:         }
                   8480:     }
                   8481:     return;
                   8482: }
                   8483: 
1.33      raeburn  8484: sub modify_usermodification {
                   8485:     my ($dom,%domconfig) = @_;
1.224     raeburn  8486:     my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33      raeburn  8487:     if (ref($domconfig{'usermodification'}) eq 'HASH') {
                   8488:         foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224     raeburn  8489:             if ($key eq 'selfcreate') {
                   8490:                 $modifyhash{$key} = $domconfig{'usermodification'}{$key};
                   8491:             } else {  
                   8492:                 $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
                   8493:             }
1.33      raeburn  8494:         }
                   8495:     }
1.224     raeburn  8496:     my @contexts = ('author','course');
1.33      raeburn  8497:     my %context_title = (
                   8498:                            author => 'In author context',
                   8499:                            course => 'In course context',
                   8500:                         );
                   8501:     my @fields = ('lastname','firstname','middlename','generation',
                   8502:                   'permanentemail','id');
                   8503:     my %roles = (
                   8504:                   author => ['ca','aa'],
                   8505:                   course => ['st','ep','ta','in','cr'],
                   8506:                 );
                   8507:     my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
                   8508:     foreach my $context (@contexts) {
                   8509:         foreach my $role (@{$roles{$context}}) {
                   8510:             my @modifiable =  &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
                   8511:             foreach my $item (@fields) {
                   8512:                 if (grep(/^\Q$item\E$/,@modifiable)) {
                   8513:                     $modifyhash{$context}{$role}{$item} = 1;
                   8514:                 } else {
                   8515:                     $modifyhash{$context}{$role}{$item} = 0;
                   8516:                 }
                   8517:             }
                   8518:         }
                   8519:         if (ref($curr_usermodification{$context}) eq 'HASH') {
                   8520:             foreach my $role (@{$roles{$context}}) {
                   8521:                 if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
                   8522:                     foreach my $field (@fields) {
                   8523:                         if ($modifyhash{$context}{$role}{$field} ne 
                   8524:                                 $curr_usermodification{$context}{$role}{$field}) {
                   8525:                             push(@{$changes{$context}},$role);
                   8526:                             last;
                   8527:                         }
                   8528:                     }
                   8529:                 }
                   8530:             }
                   8531:         } else {
                   8532:             foreach my $context (@contexts) {
                   8533:                 foreach my $role (@{$roles{$context}}) {
                   8534:                     push(@{$changes{$context}},$role);
                   8535:                 }
                   8536:             }
                   8537:         }
                   8538:     }
                   8539:     my %usermodification_hash =  (
                   8540:                                    usermodification => \%modifyhash,
                   8541:                                  );
                   8542:     my $putresult = &Apache::lonnet::put_dom('configuration',
                   8543:                                              \%usermodification_hash,$dom);
                   8544:     if ($putresult eq 'ok') {
                   8545:         if (keys(%changes) > 0) {
                   8546:             $resulttext = &mt('Changes made: ').'<ul>';
                   8547:             foreach my $context (@contexts) {
                   8548:                 if (ref($changes{$context}) eq 'ARRAY') {
                   8549:                     $resulttext .= '<li>'.$context_title{$context}.':<ul>';
                   8550:                     if (ref($changes{$context}) eq 'ARRAY') {
                   8551:                         foreach my $role (@{$changes{$context}}) {
                   8552:                             my $rolename;
1.224     raeburn  8553:                             if ($role eq 'cr') {
                   8554:                                 $rolename = &mt('Custom');
1.33      raeburn  8555:                             } else {
1.224     raeburn  8556:                                 $rolename = &Apache::lonnet::plaintext($role);
1.33      raeburn  8557:                             }
                   8558:                             my @modifiable;
1.224     raeburn  8559:                             $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33      raeburn  8560:                             foreach my $field (@fields) {
                   8561:                                 if ($modifyhash{$context}{$role}{$field}) {
                   8562:                                     push(@modifiable,$fieldtitles{$field});
                   8563:                                 }
                   8564:                             }
                   8565:                             if (@modifiable > 0) {
                   8566:                                 $resulttext .= join(', ',@modifiable);
                   8567:                             } else {
                   8568:                                 $resulttext .= &mt('none'); 
                   8569:                             }
                   8570:                             $resulttext .= '</li>';
                   8571:                         }
                   8572:                         $resulttext .= '</ul></li>';
                   8573:                     }
                   8574:                 }
                   8575:             }
                   8576:             $resulttext .= '</ul>';
                   8577:         } else {
                   8578:             $resulttext = &mt('No changes made to user modification settings');
                   8579:         }
                   8580:     } else {
                   8581:         $resulttext = '<span class="LC_error">'.
                   8582:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   8583:     }
                   8584:     return $resulttext;
                   8585: }
                   8586: 
1.43      raeburn  8587: sub modify_defaults {
1.212     raeburn  8588:     my ($dom,$lastactref,%domconfig) = @_;
1.43      raeburn  8589:     my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212     raeburn  8590:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.141     raeburn  8591:     my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
1.43      raeburn  8592:     my @authtypes = ('internal','krb4','krb5','localauth');
                   8593:     foreach my $item (@items) {
                   8594:         $newvalues{$item} = $env{'form.'.$item};
                   8595:         if ($item eq 'auth_def') {
                   8596:             if ($newvalues{$item} ne '') {
                   8597:                 if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
                   8598:                     push(@errors,$item);
                   8599:                 }
                   8600:             }
                   8601:         } elsif ($item eq 'lang_def') {
                   8602:             if ($newvalues{$item} ne '') {
                   8603:                 if ($newvalues{$item} =~ /^(\w+)/) {
                   8604:                     my $langcode = $1;
1.103     raeburn  8605:                     if ($langcode ne 'x_chef') {
                   8606:                         if (code2language($langcode) eq '') {
                   8607:                             push(@errors,$item);
                   8608:                         }
1.43      raeburn  8609:                     }
                   8610:                 } else {
                   8611:                     push(@errors,$item);
                   8612:                 }
                   8613:             }
1.54      raeburn  8614:         } elsif ($item eq 'timezone_def') {
                   8615:             if ($newvalues{$item} ne '') {
1.62      raeburn  8616:                 if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54      raeburn  8617:                     push(@errors,$item);   
                   8618:                 }
                   8619:             }
1.68      raeburn  8620:         } elsif ($item eq 'datelocale_def') {
                   8621:             if ($newvalues{$item} ne '') {
                   8622:                 my @datelocale_ids = DateTime::Locale->ids();
                   8623:                 if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
                   8624:                     push(@errors,$item);
                   8625:                 }
                   8626:             }
1.141     raeburn  8627:         } elsif ($item eq 'portal_def') {
                   8628:             if ($newvalues{$item} ne '') {
                   8629:                 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])\/?$/) {
                   8630:                     push(@errors,$item);
                   8631:                 }
                   8632:             }
1.43      raeburn  8633:         }
                   8634:         if (grep(/^\Q$item\E$/,@errors)) {
                   8635:             $newvalues{$item} = $domdefaults{$item};
                   8636:         } elsif ($domdefaults{$item} ne $newvalues{$item}) {
                   8637:             $changes{$item} = 1;
                   8638:         }
1.72      raeburn  8639:         $domdefaults{$item} = $newvalues{$item};
1.43      raeburn  8640:     }
                   8641:     my %defaults_hash = (
1.72      raeburn  8642:                          defaults => \%newvalues,
                   8643:                         );
1.43      raeburn  8644:     my $title = &defaults_titles();
                   8645:     my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
                   8646:                                              $dom);
                   8647:     if ($putresult eq 'ok') {
                   8648:         if (keys(%changes) > 0) {
                   8649:             $resulttext = &mt('Changes made:').'<ul>';
1.212     raeburn  8650:             my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43      raeburn  8651:             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";
                   8652:             foreach my $item (sort(keys(%changes))) {
                   8653:                 my $value = $env{'form.'.$item};
                   8654:                 if ($value eq '') {
                   8655:                     $value = &mt('none');
                   8656:                 } elsif ($item eq 'auth_def') {
                   8657:                     my %authnames = &authtype_names();
                   8658:                     my %shortauth = (
                   8659:                              internal => 'int',
                   8660:                              krb4 => 'krb4',
                   8661:                              krb5 => 'krb5',
                   8662:                              localauth  => 'loc',
                   8663:                     );
                   8664:                     $value = $authnames{$shortauth{$value}};
                   8665:                 }
                   8666:                 $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
                   8667:                 $mailmsgtext .= "$title->{$item} set to $value\n";  
                   8668:             }
                   8669:             $resulttext .= '</ul>';
                   8670:             $mailmsgtext .= "\n";
                   8671:             my $cachetime = 24*60*60;
1.72      raeburn  8672:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212     raeburn  8673:             if (ref($lastactref) eq 'HASH') {
                   8674:                 $lastactref->{'domdefaults'} = 1;
                   8675:             }
1.68      raeburn  8676:             if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203     raeburn  8677:                 my $notify = 1;
                   8678:                 if (ref($domconfig{'contacts'}) eq 'HASH') {
                   8679:                     if ($domconfig{'contacts'}{'reportupdates'} == 0) {
                   8680:                         $notify = 0;
                   8681:                     }
                   8682:                 }
                   8683:                 if ($notify) {
                   8684:                     &Apache::lonmsg::sendemail('installrecord@loncapa.org',
                   8685:                                                "LON-CAPA Domain Settings Change - $dom",
                   8686:                                                $mailmsgtext);
                   8687:                 }
1.54      raeburn  8688:             }
1.43      raeburn  8689:         } else {
1.54      raeburn  8690:             $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43      raeburn  8691:         }
                   8692:     } else {
                   8693:         $resulttext = '<span class="LC_error">'.
                   8694:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   8695:     }
                   8696:     if (@errors > 0) {
                   8697:         $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
                   8698:         foreach my $item (@errors) {
                   8699:             $resulttext .= ' "'.$title->{$item}.'",';
                   8700:         }
                   8701:         $resulttext =~ s/,$//;
                   8702:     }
                   8703:     return $resulttext;
                   8704: }
                   8705: 
1.46      raeburn  8706: sub modify_scantron {
1.205     raeburn  8707:     my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46      raeburn  8708:     my ($resulttext,%confhash,%changes,$errors);
                   8709:     my $custom = 'custom.tab';
                   8710:     my $default = 'default.tab';
                   8711:     my $servadm = $r->dir_config('lonAdmEMail');
                   8712:     my ($configuserok,$author_ok,$switchserver) = 
                   8713:         &config_check($dom,$confname,$servadm);
                   8714:     if ($env{'form.scantronformat.filename'} ne '') {
                   8715:         my $error;
                   8716:         if ($configuserok eq 'ok') {
                   8717:             if ($switchserver) {
1.130     raeburn  8718:                 $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46      raeburn  8719:             } else {
                   8720:                 if ($author_ok eq 'ok') {
                   8721:                     my ($result,$scantronurl) =
                   8722:                         &publishlogo($r,'upload','scantronformat',$dom,
                   8723:                                      $confname,'scantron','','',$custom);
                   8724:                     if ($result eq 'ok') {
                   8725:                         $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48      raeburn  8726:                         $changes{'scantronformat'} = 1;
1.46      raeburn  8727:                     } else {
                   8728:                         $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
                   8729:                     }
                   8730:                 } else {
                   8731:                     $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);
                   8732:                 }
                   8733:             }
                   8734:         } else {
                   8735:             $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);
                   8736:         }
                   8737:         if ($error) {
                   8738:             &Apache::lonnet::logthis($error);
                   8739:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   8740:         }
                   8741:     }
1.48      raeburn  8742:     if (ref($domconfig{'scantron'}) eq 'HASH') {
                   8743:         if ($domconfig{'scantron'}{'scantronformat'} ne '') {
                   8744:             if ($env{'form.scantronformat_del'}) {
                   8745:                 $confhash{'scantron'}{'scantronformat'} = '';
                   8746:                 $changes{'scantronformat'} = 1;
1.46      raeburn  8747:             }
                   8748:         }
                   8749:     }
                   8750:     if (keys(%confhash) > 0) {
                   8751:         my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
                   8752:                                                  $dom);
                   8753:         if ($putresult eq 'ok') {
                   8754:             if (keys(%changes) > 0) {
1.48      raeburn  8755:                 if (ref($confhash{'scantron'}) eq 'HASH') {
                   8756:                     $resulttext = &mt('Changes made:').'<ul>';
                   8757:                     if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130     raeburn  8758:                         $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48      raeburn  8759:                     } else {
1.130     raeburn  8760:                         $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46      raeburn  8761:                     }
1.48      raeburn  8762:                     $resulttext .= '</ul>';
                   8763:                 } else {
1.130     raeburn  8764:                     $resulttext = &mt('Changes made to bubblesheet format file.');
1.46      raeburn  8765:                 }
                   8766:                 $resulttext .= '</ul>';
                   8767:                 &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212     raeburn  8768:                 if (ref($lastactref) eq 'HASH') {
                   8769:                     $lastactref->{'domainconfig'} = 1;
                   8770:                 }
1.46      raeburn  8771:             } else {
1.130     raeburn  8772:                 $resulttext = &mt('No changes made to bubblesheet format file');
1.46      raeburn  8773:             }
                   8774:         } else {
                   8775:             $resulttext = '<span class="LC_error">'.
                   8776:                 &mt('An error occurred: [_1]',$putresult).'</span>';
                   8777:         }
                   8778:     } else {
1.130     raeburn  8779:         $resulttext = &mt('No changes made to bubblesheet format file'); 
1.46      raeburn  8780:     }
                   8781:     if ($errors) {
                   8782:         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
                   8783:                        $errors.'</ul>';
                   8784:     }
                   8785:     return $resulttext;
                   8786: }
                   8787: 
1.48      raeburn  8788: sub modify_coursecategories {
                   8789:     my ($dom,%domconfig) = @_;
1.57      raeburn  8790:     my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
                   8791:         $cathash);
1.48      raeburn  8792:     my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.55      raeburn  8793:     if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57      raeburn  8794:         $cathash = $domconfig{'coursecategories'}{'cats'};
                   8795:         if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
                   8796:             $changes{'togglecats'} = 1;
                   8797:             $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
                   8798:         }
                   8799:         if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
                   8800:             $changes{'categorize'} = 1;
                   8801:             $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
                   8802:         }
1.120     raeburn  8803:         if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
                   8804:             $changes{'togglecatscomm'} = 1;
                   8805:             $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
                   8806:         }
                   8807:         if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
                   8808:             $changes{'categorizecomm'} = 1;
                   8809:             $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
                   8810:         }
1.57      raeburn  8811:     } else {
                   8812:         $changes{'togglecats'} = 1;
                   8813:         $changes{'categorize'} = 1;
1.124     raeburn  8814:         $changes{'togglecatscomm'} = 1;
                   8815:         $changes{'categorizecomm'} = 1;
1.87      raeburn  8816:         $domconfig{'coursecategories'} = {
                   8817:                                              togglecats => $env{'form.togglecats'},
                   8818:                                              categorize => $env{'form.categorize'},
1.124     raeburn  8819:                                              togglecatscomm => $env{'form.togglecatscomm'},
                   8820:                                              categorizecomm => $env{'form.categorizecomm'},
1.120     raeburn  8821:                                          };
1.57      raeburn  8822:     }
                   8823:     if (ref($cathash) eq 'HASH') {
                   8824:         if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '')  && ($env{'form.instcode'} == 0)) {
1.55      raeburn  8825:             push (@deletecategory,'instcode::0');
                   8826:         }
1.120     raeburn  8827:         if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '')  && ($env{'form.communities'} == 0)) {
                   8828:             push(@deletecategory,'communities::0');
                   8829:         }
1.48      raeburn  8830:     }
1.57      raeburn  8831:     my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
                   8832:     if (ref($cathash) eq 'HASH') {
1.48      raeburn  8833:         if (@deletecategory > 0) {
                   8834:             #FIXME Need to remove category from all courses using a deleted category 
1.57      raeburn  8835:             &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48      raeburn  8836:             foreach my $item (@deletecategory) {
1.57      raeburn  8837:                 if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
                   8838:                     delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48      raeburn  8839:                     $deletions{$item} = 1;
1.57      raeburn  8840:                     &recurse_cat_deletes($item,$cathash,\%deletions);
1.48      raeburn  8841:                 }
                   8842:             }
                   8843:         }
1.57      raeburn  8844:         foreach my $item (keys(%{$cathash})) {
1.48      raeburn  8845:             my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57      raeburn  8846:             if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48      raeburn  8847:                 $reorderings{$item} = 1;
1.57      raeburn  8848:                 $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48      raeburn  8849:             }
                   8850:             if ($env{'form.addcategory_name_'.$item} ne '') {
                   8851:                 my $newcat = $env{'form.addcategory_name_'.$item};
                   8852:                 my $newdepth = $depth+1;
                   8853:                 my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57      raeburn  8854:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48      raeburn  8855:                 $adds{$newitem} = 1; 
                   8856:             }
                   8857:             if ($env{'form.subcat_'.$item} ne '') {
                   8858:                 my $newcat = $env{'form.subcat_'.$item};
                   8859:                 my $newdepth = $depth+1;
                   8860:                 my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57      raeburn  8861:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48      raeburn  8862:                 $adds{$newitem} = 1;
                   8863:             }
                   8864:         }
                   8865:     }
                   8866:     if ($env{'form.instcode'} eq '1') {
1.57      raeburn  8867:         if (ref($cathash) eq 'HASH') {
1.48      raeburn  8868:             my $newitem = 'instcode::0';
1.57      raeburn  8869:             if ($cathash->{$newitem} eq '') {  
                   8870:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48      raeburn  8871:                 $adds{$newitem} = 1;
                   8872:             }
                   8873:         } else {
                   8874:             my $newitem = 'instcode::0';
1.57      raeburn  8875:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48      raeburn  8876:             $adds{$newitem} = 1;
                   8877:         }
                   8878:     }
1.120     raeburn  8879:     if ($env{'form.communities'} eq '1') {
                   8880:         if (ref($cathash) eq 'HASH') {
                   8881:             my $newitem = 'communities::0';
                   8882:             if ($cathash->{$newitem} eq '') {
                   8883:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
                   8884:                 $adds{$newitem} = 1;
                   8885:             }
                   8886:         } else {
                   8887:             my $newitem = 'communities::0';
                   8888:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
                   8889:             $adds{$newitem} = 1;
                   8890:         }
                   8891:     }
1.48      raeburn  8892:     if ($env{'form.addcategory_name'} ne '') {
1.120     raeburn  8893:         if (($env{'form.addcategory_name'} ne 'instcode') &&
                   8894:             ($env{'form.addcategory_name'} ne 'communities')) {
                   8895:             my $newitem = &escape($env{'form.addcategory_name'}).'::0';
                   8896:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
                   8897:             $adds{$newitem} = 1;
                   8898:         }
1.48      raeburn  8899:     }
1.57      raeburn  8900:     my $putresult;
1.48      raeburn  8901:     if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
                   8902:         if (keys(%deletions) > 0) {
                   8903:             foreach my $key (keys(%deletions)) {
                   8904:                 if ($predelallitems{$key} ne '') {
                   8905:                     $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
                   8906:                 }
                   8907:             }
                   8908:         }
                   8909:         my (@chkcats,@chktrails,%chkallitems);
1.57      raeburn  8910:         &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48      raeburn  8911:         if (ref($chkcats[0]) eq 'ARRAY') {
                   8912:             my $depth = 0;
                   8913:             my $chg = 0;
                   8914:             for (my $i=0; $i<@{$chkcats[0]}; $i++) {
                   8915:                 my $name = $chkcats[0][$i];
                   8916:                 my $item;
                   8917:                 if ($name eq '') {
                   8918:                     $chg ++;
                   8919:                 } else {
                   8920:                     $item = &escape($name).'::0';
                   8921:                     if ($chg) {
1.57      raeburn  8922:                         $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48      raeburn  8923:                     }
                   8924:                     $depth ++; 
1.57      raeburn  8925:                     &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48      raeburn  8926:                     $depth --;
                   8927:                 }
                   8928:             }
                   8929:         }
1.57      raeburn  8930:     }
                   8931:     if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
                   8932:         $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48      raeburn  8933:         if ($putresult eq 'ok') {
1.57      raeburn  8934:             my %title = (
1.120     raeburn  8935:                          togglecats     => 'Show/Hide a course in catalog',
                   8936:                          categorize     => 'Assign a category to a course',
                   8937:                          togglecatscomm => 'Show/Hide a community in catalog',
                   8938:                          categorizecomm => 'Assign a category to a community',
1.57      raeburn  8939:                         );
                   8940:             my %level = (
1.120     raeburn  8941:                          dom  => 'set in Domain ("Modify Course/Community")',
                   8942:                          crs  => 'set in Course ("Course Configuration")',
                   8943:                          comm => 'set in Community ("Community Configuration")',
1.57      raeburn  8944:                         );
1.48      raeburn  8945:             $resulttext = &mt('Changes made:').'<ul>';
1.57      raeburn  8946:             if ($changes{'togglecats'}) {
                   8947:                 $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>'; 
                   8948:             }
                   8949:             if ($changes{'categorize'}) {
                   8950:                 $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48      raeburn  8951:             }
1.120     raeburn  8952:             if ($changes{'togglecatscomm'}) {
                   8953:                 $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
                   8954:             }
                   8955:             if ($changes{'categorizecomm'}) {
                   8956:                 $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
                   8957:             }
1.57      raeburn  8958:             if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
                   8959:                 my $cathash;
                   8960:                 if (ref($domconfig{'coursecategories'}) eq 'HASH') {
                   8961:                     $cathash = $domconfig{'coursecategories'}{'cats'};
                   8962:                 } else {
                   8963:                     $cathash = {};
                   8964:                 } 
                   8965:                 my (@cats,@trails,%allitems);
                   8966:                     &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
                   8967:                 if (keys(%deletions) > 0) {
                   8968:                     $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
                   8969:                     foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) { 
                   8970:                         $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
                   8971:                     }
                   8972:                     $resulttext .= '</ul></li>';
                   8973:                 }
                   8974:                 if (keys(%reorderings) > 0) {
                   8975:                     my %sort_by_trail;
                   8976:                     $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
                   8977:                     foreach my $key (keys(%reorderings)) {
                   8978:                         if ($allitems{$key} ne '') {
                   8979:                             $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
                   8980:                         }
1.48      raeburn  8981:                     }
1.57      raeburn  8982:                     foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
                   8983:                         $resulttext .= '<li>'.$trails[$trail].'</li>';
                   8984:                     }
                   8985:                     $resulttext .= '</ul></li>';
1.48      raeburn  8986:                 }
1.57      raeburn  8987:                 if (keys(%adds) > 0) {
                   8988:                     my %sort_by_trail;
                   8989:                     $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
                   8990:                     foreach my $key (keys(%adds)) {
                   8991:                         if ($allitems{$key} ne '') {
                   8992:                             $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
                   8993:                         }
                   8994:                     }
                   8995:                     foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
                   8996:                         $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48      raeburn  8997:                     }
1.57      raeburn  8998:                     $resulttext .= '</ul></li>';
1.48      raeburn  8999:                 }
                   9000:             }
                   9001:             $resulttext .= '</ul>';
                   9002:         } else {
                   9003:             $resulttext = '<span class="LC_error">'.
1.57      raeburn  9004:                           &mt('An error occurred: [_1]',$putresult).'</span>';
1.48      raeburn  9005:         }
                   9006:     } else {
1.120     raeburn  9007:         $resulttext = &mt('No changes made to course and community categories');
1.48      raeburn  9008:     }
                   9009:     return $resulttext;
                   9010: }
                   9011: 
1.69      raeburn  9012: sub modify_serverstatuses {
                   9013:     my ($dom,%domconfig) = @_;
                   9014:     my ($resulttext,%changes,%currserverstatus,%newserverstatus);
                   9015:     if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
                   9016:         %currserverstatus = %{$domconfig{'serverstatuses'}};
                   9017:     }
                   9018:     my @pages = &serverstatus_pages();
                   9019:     foreach my $type (@pages) {
                   9020:         $newserverstatus{$type}{'namedusers'} = '';
                   9021:         $newserverstatus{$type}{'machines'} = '';
                   9022:         if (defined($env{'form.'.$type.'_namedusers'})) {
                   9023:             my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
                   9024:             my @okusers;
                   9025:             foreach my $user (@users) {
                   9026:                 my ($uname,$udom) = split(/:/,$user);
                   9027:                 if (($udom =~ /^$match_domain$/) &&   
                   9028:                     (&Apache::lonnet::domain($udom)) &&
                   9029:                     ($uname =~ /^$match_username$/)) {
                   9030:                     if (!grep(/^\Q$user\E/,@okusers)) {
                   9031:                         push(@okusers,$user);
                   9032:                     }
                   9033:                 }
                   9034:             }
                   9035:             if (@okusers > 0) {
                   9036:                  @okusers = sort(@okusers);
                   9037:                  $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
                   9038:             }
                   9039:         }
                   9040:         if (defined($env{'form.'.$type.'_machines'})) {
                   9041:             my @machines = split(/,/,$env{'form.'.$type.'_machines'});
                   9042:             my @okmachines;
                   9043:             foreach my $ip (@machines) {
                   9044:                 my @parts = split(/\./,$ip);
                   9045:                 next if (@parts < 4);
                   9046:                 my $badip = 0;
                   9047:                 for (my $i=0; $i<4; $i++) {
                   9048:                     if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
                   9049:                         $badip = 1;
                   9050:                         last;
                   9051:                     }
                   9052:                 }
                   9053:                 if (!$badip) {
                   9054:                     push(@okmachines,$ip);     
                   9055:                 }
                   9056:             }
                   9057:             @okmachines = sort(@okmachines);
                   9058:             $newserverstatus{$type}{'machines'} = join(',',@okmachines);
                   9059:         }
                   9060:     }
                   9061:     my %serverstatushash =  (
                   9062:                                 serverstatuses => \%newserverstatus,
                   9063:                             );
                   9064:     foreach my $type (@pages) {
1.83      raeburn  9065:         foreach my $setting ('namedusers','machines') {
1.84      raeburn  9066:             my (@current,@new);
1.83      raeburn  9067:             if (ref($currserverstatus{$type}) eq 'HASH') {
1.84      raeburn  9068:                 if ($currserverstatus{$type}{$setting} ne '') { 
                   9069:                     @current = split(/,/,$currserverstatus{$type}{$setting});
                   9070:                 }
                   9071:             }
                   9072:             if ($newserverstatus{$type}{$setting} ne '') {
                   9073:                 @new = split(/,/,$newserverstatus{$type}{$setting});
1.83      raeburn  9074:             }
                   9075:             if (@current > 0) {
                   9076:                 if (@new > 0) {
                   9077:                     foreach my $item (@current) {
                   9078:                         if (!grep(/^\Q$item\E$/,@new)) {
                   9079:                             $changes{$type}{$setting} = 1;
1.82      raeburn  9080:                             last;
                   9081:                         }
                   9082:                     }
1.84      raeburn  9083:                     foreach my $item (@new) {
                   9084:                         if (!grep(/^\Q$item\E$/,@current)) {
                   9085:                             $changes{$type}{$setting} = 1;
                   9086:                             last;
1.82      raeburn  9087:                         }
                   9088:                     }
                   9089:                 } else {
1.83      raeburn  9090:                     $changes{$type}{$setting} = 1;
1.69      raeburn  9091:                 }
1.83      raeburn  9092:             } elsif (@new > 0) {
                   9093:                 $changes{$type}{$setting} = 1;
1.69      raeburn  9094:             }
                   9095:         }
                   9096:     }
                   9097:     if (keys(%changes) > 0) {
1.81      raeburn  9098:         my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69      raeburn  9099:         my $putresult = &Apache::lonnet::put_dom('configuration',
                   9100:                                                  \%serverstatushash,$dom);
                   9101:         if ($putresult eq 'ok') {
                   9102:             $resulttext .= &mt('Changes made:').'<ul>';
                   9103:             foreach my $type (@pages) {
1.84      raeburn  9104:                 if (ref($changes{$type}) eq 'HASH') {
1.69      raeburn  9105:                     $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84      raeburn  9106:                     if ($changes{$type}{'namedusers'}) {
1.69      raeburn  9107:                         if ($newserverstatus{$type}{'namedusers'} eq '') {
                   9108:                             $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
                   9109:                         } else {
                   9110:                             $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
                   9111:                         }
1.84      raeburn  9112:                     }
                   9113:                     if ($changes{$type}{'machines'}) {
1.69      raeburn  9114:                         if ($newserverstatus{$type}{'machines'} eq '') {
                   9115:                             $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
                   9116:                         } else {
                   9117:                             $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
                   9118:                         }
                   9119: 
                   9120:                     }
                   9121:                     $resulttext .= '</ul></li>';
                   9122:                 }
                   9123:             }
                   9124:             $resulttext .= '</ul>';
                   9125:         } else {
                   9126:             $resulttext = '<span class="LC_error">'.
                   9127:                           &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
                   9128: 
                   9129:         }
                   9130:     } else {
                   9131:         $resulttext = &mt('No changes made to access to server status pages');
                   9132:     }
                   9133:     return $resulttext;
                   9134: }
                   9135: 
1.118     jms      9136: sub modify_helpsettings {
1.122     jms      9137:     my ($r,$dom,$confname,%domconfig) = @_;
1.166     raeburn  9138:     my ($resulttext,$errors,%changes,%helphash);
                   9139:     my %defaultchecked = ('submitbugs' => 'on');
                   9140:     my @offon = ('off','on');
1.118     jms      9141:     my @toggles = ('submitbugs');
                   9142:     if (ref($domconfig{'helpsettings'}) eq 'HASH') {
                   9143:         foreach my $item (@toggles) {
1.166     raeburn  9144:             if ($defaultchecked{$item} eq 'on') { 
                   9145:                 if ($domconfig{'helpsettings'}{$item} eq '') {
                   9146:                     if ($env{'form.'.$item} eq '0') {
                   9147:                         $changes{$item} = 1;
                   9148:                     }
                   9149:                 } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
                   9150:                     $changes{$item} = 1;
                   9151:                 }
                   9152:             } elsif ($defaultchecked{$item} eq 'off') {
                   9153:                 if ($domconfig{'helpsettings'}{$item} eq '') {
                   9154:                     if ($env{'form.'.$item} eq '1') {
                   9155:                         $changes{$item} = 1;
                   9156:                     }
                   9157:                 } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
                   9158:                     $changes{$item} = 1;
                   9159:                 }
                   9160:             }
1.210     raeburn  9161:             if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
1.166     raeburn  9162:                 $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
                   9163:             }
                   9164:         }
1.118     jms      9165:     }
1.123     jms      9166:     my $putresult;
                   9167:     if (keys(%changes) > 0) {
1.166     raeburn  9168:         $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168     raeburn  9169:         if ($putresult eq 'ok') {
1.166     raeburn  9170:             $resulttext = &mt('Changes made:').'<ul>';
                   9171:             foreach my $item (sort(keys(%changes))) {
                   9172:                 if ($item eq 'submitbugs') {
                   9173:                     $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
                   9174:                                               &Apache::loncommon::modal_link('http://bugs.loncapa.org',
                   9175:                                               &mt('LON-CAPA bug tracker'),600,500)).'</li>';
                   9176:                 }
                   9177:             }
                   9178:             $resulttext .= '</ul>';
                   9179:         } else {
                   9180:             $resulttext = &mt('No changes made to help settings');
1.168     raeburn  9181:             $errors .= '<li><span class="LC_error">'.
                   9182:                        &mt('An error occurred storing the settings: [_1]',
                   9183:                            $putresult).'</span></li>';
1.166     raeburn  9184:         }
1.118     jms      9185:     }
                   9186:     if ($errors) {
1.168     raeburn  9187:         $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.118     jms      9188:                        $errors.'</ul>';
                   9189:     }
                   9190:     return $resulttext;
                   9191: }
                   9192: 
1.121     raeburn  9193: sub modify_coursedefaults {
1.212     raeburn  9194:     my ($dom,$lastactref,%domconfig) = @_;
1.121     raeburn  9195:     my ($resulttext,$errors,%changes,%defaultshash);
                   9196:     my %defaultchecked = ('canuse_pdfforms' => 'off');
                   9197:     my @toggles = ('canuse_pdfforms');
1.198     raeburn  9198:     my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.216     raeburn  9199:                    'uploadquota_community','uploadquota_textbook');
                   9200:     my @types = ('official','unofficial','community','textbook');
1.198     raeburn  9201:     my %staticdefaults = (
                   9202:                            anonsurvey_threshold => 10,
                   9203:                            uploadquota          => 500,
                   9204:                          );
1.121     raeburn  9205: 
                   9206:     $defaultshash{'coursedefaults'} = {};
                   9207: 
                   9208:     if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
                   9209:         if ($domconfig{'coursedefaults'} eq '') {
                   9210:             $domconfig{'coursedefaults'} = {};
                   9211:         }
                   9212:     }
                   9213: 
                   9214:     if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
                   9215:         foreach my $item (@toggles) {
                   9216:             if ($defaultchecked{$item} eq 'on') {
                   9217:                 if (($domconfig{'coursedefaults'}{$item} eq '') &&
                   9218:                     ($env{'form.'.$item} eq '0')) {
                   9219:                     $changes{$item} = 1;
1.192     raeburn  9220:                 } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121     raeburn  9221:                     $changes{$item} = 1;
                   9222:                 }
                   9223:             } elsif ($defaultchecked{$item} eq 'off') {
                   9224:                 if (($domconfig{'coursedefaults'}{$item} eq '') &&
                   9225:                     ($env{'form.'.$item} eq '1')) {
                   9226:                     $changes{$item} = 1;
                   9227:                 } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
                   9228:                     $changes{$item} = 1;
                   9229:                 }
                   9230:             }
                   9231:             $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
                   9232:         }
1.198     raeburn  9233:         foreach my $item (@numbers) {
                   9234:             my ($currdef,$newdef);
1.208     raeburn  9235:             $newdef = $env{'form.'.$item};
1.198     raeburn  9236:             if ($item eq 'anonsurvey_threshold') {
                   9237:                 $currdef = $domconfig{'coursedefaults'}{$item};
                   9238:                 $newdef =~ s/\D//g;
                   9239:                 if ($newdef eq '' || $newdef < 1) {
                   9240:                     $newdef = 1;
                   9241:                 }
                   9242:                 $defaultshash{'coursedefaults'}{$item} = $newdef;
                   9243:             } else {
                   9244:                 my ($type) = ($item =~ /^\Quploadquota_\E(\w+)$/);
                   9245:                 if (ref($domconfig{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
                   9246:                     $currdef = $domconfig{'coursedefaults'}{'uploadquota'}{$type};
                   9247:                 }
                   9248:                 $newdef =~ s/[^\w.\-]//g;
                   9249:                 $defaultshash{'coursedefaults'}{'uploadquota'}{$type} = $newdef;
                   9250:             }
                   9251:             if ($currdef ne $newdef) {
                   9252:                 my $staticdef;
                   9253:                 if ($item eq 'anonsurvey_threshold') {
                   9254:                     unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
                   9255:                         $changes{$item} = 1;
                   9256:                     }
                   9257:                 } else {
                   9258:                     unless (($currdef eq '') && ($newdef == $staticdefaults{'uploadquota'})) {
                   9259:                         $changes{'uploadquota'} = 1;
                   9260:                     }
                   9261:                 }
1.139     raeburn  9262:             }
                   9263:         }
1.231     raeburn  9264: 
1.192     raeburn  9265:         my $officialcreds = $env{'form.official_credits'};
1.216     raeburn  9266:         $officialcreds =~ s/[^\d.]+//g;
1.192     raeburn  9267:         my $unofficialcreds = $env{'form.unofficial_credits'};
1.216     raeburn  9268:         $unofficialcreds =~ s/[^\d.]+//g;
                   9269:         my $textbookcreds = $env{'form.textbook_credits'};
                   9270:         $textbookcreds =~ s/[^\d.]+//g;
1.192     raeburn  9271:         if (ref($domconfig{'coursedefaults'}{'coursecredits'} ne 'HASH') &&
                   9272:                 ($env{'form.coursecredits'} eq '1')) {
                   9273:                 $changes{'coursecredits'} = 1;
                   9274:         } else {
                   9275:             if (($domconfig{'coursedefaults'}{'coursecredits'}{'official'} ne $officialcreds)  ||
1.216     raeburn  9276:                 ($domconfig{'coursedefaults'}{'coursecredits'}{'unofficial'} ne $unofficialcreds) ||
                   9277:                 ($domconfig{'coursedefaults'}{'coursecredits'}{'textbook'} ne $textbookcreds)) {
1.192     raeburn  9278:                 $changes{'coursecredits'} = 1;
                   9279:             }
                   9280:         }
                   9281:         $defaultshash{'coursedefaults'}{'coursecredits'} = {
                   9282:             official   => $officialcreds,
                   9283:             unofficial => $unofficialcreds,
1.216     raeburn  9284:             textbook   => $textbookcreds,
1.192     raeburn  9285:         }
1.121     raeburn  9286:     }
                   9287:     my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
                   9288:                                              $dom);
                   9289:     if ($putresult eq 'ok') {
                   9290:         if (keys(%changes) > 0) {
1.213     raeburn  9291:             my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.230     raeburn  9292:             if (($changes{'canuse_pdfforms'}) || ($changes{'coursecredits'}) || 
1.231     raeburn  9293:                 ($changes{'uploadquota'})) { 
1.192     raeburn  9294:                 if ($changes{'canuse_pdfforms'}) {
                   9295:                     $domdefaults{'canuse_pdfforms'}=$defaultshash{'coursedefaults'}{'canuse_pdfforms'};
                   9296:                 }
                   9297:                 if ($changes{'coursecredits'}) {
                   9298:                     if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
                   9299:                         $domdefaults{'officialcredits'} =
                   9300:                             $defaultshash{'coursedefaults'}{'coursecredits'}{'official'};
                   9301:                         $domdefaults{'unofficialcredits'} =
                   9302:                             $defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'};
1.216     raeburn  9303:                         $domdefaults{'textbookcredits'} =
                   9304:                             $domdefaults{'coursedefaults'}{'coursecredits'}{'textbook'};
1.192     raeburn  9305:                     }
                   9306:                 }
1.198     raeburn  9307:                 if ($changes{'uploadquota'}) {
                   9308:                     if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
                   9309:                         foreach my $type (@types) {
                   9310:                             $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
                   9311:                         }
                   9312:                     }
                   9313:                 }
1.121     raeburn  9314:                 my $cachetime = 24*60*60;
                   9315:                 &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212     raeburn  9316:                 if (ref($lastactref) eq 'HASH') {
                   9317:                     $lastactref->{'domdefaults'} = 1;
                   9318:                 }
1.121     raeburn  9319:             }
                   9320:             $resulttext = &mt('Changes made:').'<ul>';
                   9321:             foreach my $item (sort(keys(%changes))) {
                   9322:                 if ($item eq 'canuse_pdfforms') {
                   9323:                     if ($env{'form.'.$item} eq '1') {
                   9324:                         $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
                   9325:                     } else {
                   9326:                         $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
                   9327:                     }
1.139     raeburn  9328:                 } elsif ($item eq 'anonsurvey_threshold') {
1.192     raeburn  9329:                     $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198     raeburn  9330:                 } elsif ($item eq 'uploadquota') {
                   9331:                     if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
                   9332:                         $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
                   9333:                                        '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
                   9334:                                        '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216     raeburn  9335:                                        '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
                   9336: 
1.198     raeburn  9337:                                        '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
                   9338:                                        '</ul>'.
                   9339:                                        '</li>';
                   9340:                     } else {
                   9341:                         $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
                   9342:                     }
1.192     raeburn  9343:                 } elsif ($item eq 'coursecredits') {
                   9344:                     if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
                   9345:                         if (($domdefaults{'officialcredits'} eq '') &&
1.216     raeburn  9346:                             ($domdefaults{'unofficialcredits'} eq '') &&
                   9347:                             ($domdefaults{'textbookcredits'} eq '')) {
1.192     raeburn  9348:                             $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
                   9349:                         } else {
                   9350:                             $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
                   9351:                                            '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
                   9352:                                            '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216     raeburn  9353:                                            '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192     raeburn  9354:                                            '</ul>'.
                   9355:                                            '</li>';
                   9356:                         }
                   9357:                     } else {
                   9358:                         $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
                   9359:                     }
1.140     raeburn  9360:                 }
1.121     raeburn  9361:             }
                   9362:             $resulttext .= '</ul>';
                   9363:         } else {
                   9364:             $resulttext = &mt('No changes made to course defaults');
                   9365:         }
                   9366:     } else {
                   9367:         $resulttext = '<span class="LC_error">'.
                   9368:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   9369:     }
                   9370:     return $resulttext;
                   9371: }
                   9372: 
1.231     raeburn  9373: sub modify_selfenrollment {
                   9374:     my ($dom,$lastactref,%domconfig) = @_;
                   9375:     my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
                   9376:     my @types = ('official','unofficial','community','textbook');
                   9377:     my %titles = &tool_titles();
1.232     raeburn  9378:     my %descs = &Apache::lonuserutils::selfenroll_default_descs();
                   9379:     ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
1.231     raeburn  9380:     $ordered{'default'} = ['types','registered','approval','limit'];
                   9381: 
                   9382:     my (%roles,%shown,%toplevel);
                   9383:     $roles{'0'} = &Apache::lonnet::plaintext('dc');
                   9384: 
                   9385:     if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
                   9386:         if ($domconfig{'selfenrollment'} eq '') {
                   9387:             $domconfig{'selfenrollment'} = {};
                   9388:         }
                   9389:     }
                   9390:     %toplevel = (
                   9391:                   admin      => 'Configuration Rights',
                   9392:                   default    => 'Default settings',
                   9393:                   validation => 'Validation of self-enrollment requests',
                   9394:                 );
1.233     raeburn  9395:     my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
1.231     raeburn  9396: 
                   9397:     if (ref($ordered{'admin'}) eq 'ARRAY') {
                   9398:         foreach my $item (@{$ordered{'admin'}}) {
                   9399:             foreach my $type (@types) {
                   9400:                 if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
                   9401:                     $selfenrollhash{'admin'}{$type}{$item} = 1;
                   9402:                 } else {
                   9403:                     $selfenrollhash{'admin'}{$type}{$item} = 0;
                   9404:                 }
                   9405:                 if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
                   9406:                     if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
                   9407:                         if ($selfenrollhash{'admin'}{$type}{$item} ne
                   9408:                             $domconfig{'selfenrollment'}{'admin'}{$type}{$item})  {
                   9409:                             push(@{$changes{'admin'}{$type}},$item);
                   9410:                         }
                   9411:                     } else {
                   9412:                         if (!$selfenrollhash{'admin'}{$type}{$item}) {
                   9413:                             push(@{$changes{'admin'}{$type}},$item);
                   9414:                         }
                   9415:                     }
                   9416:                 } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
                   9417:                     push(@{$changes{'admin'}{$type}},$item);
                   9418:                 }
                   9419:             }
                   9420:         }
                   9421:     }
                   9422: 
                   9423:     foreach my $item (@{$ordered{'default'}}) {
                   9424:         foreach my $type (@types) {
                   9425:             my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
                   9426:             if ($item eq 'types') {
                   9427:                 unless (($value eq 'all') || ($value eq 'dom')) {
                   9428:                     $value = '';
                   9429:                 }
                   9430:             } elsif ($item eq 'registered') {
                   9431:                 unless ($value eq '1') {
                   9432:                     $value = 0;
                   9433:                 }
                   9434:             } elsif ($item eq 'approval') {
                   9435:                 unless ($value =~ /^[012]$/) {
                   9436:                     $value = 0;
                   9437:                 }
                   9438:             } else {
                   9439:                 unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
                   9440:                     $value = 'none';
                   9441:                 }
                   9442:             }
                   9443:             $selfenrollhash{'default'}{$type}{$item} = $value;
                   9444:             if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
                   9445:                 if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
                   9446:                     if ($selfenrollhash{'default'}{$type}{$item} ne
                   9447:                          $domconfig{'selfenrollment'}{'default'}{$type}{$item})  {
                   9448:                          push(@{$changes{'default'}{$type}},$item);
                   9449:                     }
                   9450:                 } else {
                   9451:                     push(@{$changes{'default'}{$type}},$item);
                   9452:                 }
                   9453:             } else {
                   9454:                 push(@{$changes{'default'}{$type}},$item);
                   9455:             }
                   9456:             if ($item eq 'limit') {
                   9457:                 if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
                   9458:                     $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
                   9459:                     if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
                   9460:                         $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
                   9461:                     }
                   9462:                 } else {
                   9463:                     $selfenrollhash{'default'}{$type}{'cap'} = '';
                   9464:                 }
                   9465:                 if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
                   9466:                     if ($selfenrollhash{'default'}{$type}{'cap'} ne
                   9467:                          $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'})  {
                   9468:                          push(@{$changes{'default'}{$type}},'cap');
                   9469:                     }
                   9470:                 } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
                   9471:                     push(@{$changes{'default'}{$type}},'cap');
                   9472:                 }
                   9473:             }
                   9474:         }
                   9475:     }
                   9476: 
                   9477:     foreach my $item (@{$itemsref}) {
                   9478:         if ($item eq 'fields') {
                   9479:             my @changed;
                   9480:             @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
                   9481:             if (@{$selfenrollhash{'validation'}{$item}} > 0) {
                   9482:                 @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
                   9483:             }
                   9484:             if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
                   9485:                 if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
                   9486:                     @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
                   9487:                                                                   $domconfig{'selfenrollment'}{'validation'}{$item});
                   9488:                 } else {
                   9489:                     @changed = @{$selfenrollhash{'validation'}{$item}};
                   9490:                 }
                   9491:             } else {
                   9492:                 @changed = @{$selfenrollhash{'validation'}{$item}};
                   9493:             }
                   9494:             if (@changed) {
                   9495:                 if ($selfenrollhash{'validation'}{$item}) { 
                   9496:                     $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
                   9497:                 } else {
                   9498:                     $changes{'validation'}{$item} = &mt('None');
                   9499:                 }
                   9500:             }
                   9501:         } else {
                   9502:             $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
                   9503:             if ($item eq 'markup') {
                   9504:                if ($env{'form.selfenroll_validation_'.$item}) {
                   9505:                    $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
                   9506:                }
                   9507:             }
                   9508:             if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
                   9509:                 if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
                   9510:                     $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
                   9511:                 }
                   9512:             }
                   9513:         }
                   9514:     }
                   9515: 
                   9516:     my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
                   9517:                                              $dom);
                   9518:     if ($putresult eq 'ok') {
                   9519:         if (keys(%changes) > 0) {
                   9520:             my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
                   9521:             $resulttext = &mt('Changes made:').'<ul>';
                   9522:             foreach my $key ('admin','default','validation') {
                   9523:                 if (ref($changes{$key}) eq 'HASH') {
                   9524:                     $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
                   9525:                     if ($key eq 'validation') {
                   9526:                         foreach my $item (@{$itemsref}) {
                   9527:                             if (exists($changes{$key}{$item})) {
                   9528:                                 if ($item eq 'markup') {
                   9529:                                     $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
                   9530:                                                               '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
                   9531:                                 } else {  
                   9532:                                     $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
                   9533:                                                               '<b>'.$changes{$key}{$item}.'</b>').'</li>';
                   9534:                                 }
                   9535:                             }
                   9536:                         }
                   9537:                     } else {
                   9538:                         foreach my $type (@types) {
                   9539:                             if ($type eq 'community') {
                   9540:                                 $roles{'1'} = &mt('Community personnel');
                   9541:                             } else {
                   9542:                                 $roles{'1'} = &mt('Course personnel');
                   9543:                             }
                   9544:                             if (ref($changes{$key}{$type}) eq 'ARRAY') {
1.232     raeburn  9545:                                 if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
                   9546:                                     if ($key eq 'admin') {
                   9547:                                         my @mgrdc = ();
                   9548:                                         if (ref($ordered{$key}) eq 'ARRAY') {
                   9549:                                             foreach my $item (@{$ordered{'admin'}}) {
                   9550:                                                 if (ref($selfenrollhash{$key}{$type}) eq 'HASH') { 
                   9551:                                                     if ($selfenrollhash{$key}{$type}{$item} eq '0') {
                   9552:                                                         push(@mgrdc,$item);
                   9553:                                                     }
                   9554:                                                 }
                   9555:                                             }
                   9556:                                             if (@mgrdc) {
                   9557:                                                 $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
                   9558:                                             } else {
                   9559:                                                 delete($domdefaults{$type.'selfenrolladmdc'});
                   9560:                                             }
                   9561:                                         }
                   9562:                                     } else {
                   9563:                                         if (ref($ordered{$key}) eq 'ARRAY') {
                   9564:                                             foreach my $item (@{$ordered{$key}}) {
                   9565:                                                 if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
                   9566:                                                     $domdefaults{$type.'selfenroll'.$item} =
                   9567:                                                         $selfenrollhash{$key}{$type}{$item};
                   9568:                                                 }
                   9569:                                             }
                   9570:                                         }
                   9571:                                     }
                   9572:                                 }
1.231     raeburn  9573:                                 $resulttext .= '<li>'.$titles{$type}.'<ul>';
                   9574:                                 foreach my $item (@{$ordered{$key}}) {
                   9575:                                     if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
                   9576:                                         $resulttext .= '<li>';
                   9577:                                         if ($key eq 'admin') {
                   9578:                                             $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
                   9579:                                                                '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
                   9580:                                         } else {
                   9581:                                             $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
                   9582:                                                                '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
                   9583:                                         }
                   9584:                                         $resulttext .= '</li>';
                   9585:                                     }
                   9586:                                 }
                   9587:                                 $resulttext .= '</ul></li>';
                   9588:                             }
                   9589:                         }
                   9590:                         $resulttext .= '</ul></li>'; 
                   9591:                     }
                   9592:                 }
1.232     raeburn  9593:                 if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
                   9594:                     my $cachetime = 24*60*60;
                   9595:                     &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
                   9596:                     if (ref($lastactref) eq 'HASH') {
                   9597:                         $lastactref->{'domdefaults'} = 1;
                   9598:                     }
                   9599:                 }
1.231     raeburn  9600:             }
                   9601:             $resulttext .= '</ul>';
                   9602:         } else {
                   9603:             $resulttext = &mt('No changes made to self-enrollment settings');
                   9604:         }
                   9605:     } else {
                   9606:         $resulttext = '<span class="LC_error">'.
                   9607:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   9608:     }
                   9609:     return $resulttext;
                   9610: }
                   9611: 
1.137     raeburn  9612: sub modify_usersessions {
1.212     raeburn  9613:     my ($dom,$lastactref,%domconfig) = @_;
1.145     raeburn  9614:     my @hostingtypes = ('version','excludedomain','includedomain');
                   9615:     my @offloadtypes = ('primary','default');
                   9616:     my %types = (
                   9617:                   remote => \@hostingtypes,
                   9618:                   hosted => \@hostingtypes,
                   9619:                   spares => \@offloadtypes,
                   9620:                 );
                   9621:     my @prefixes = ('remote','hosted','spares');
1.137     raeburn  9622:     my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138     raeburn  9623:     my (%by_ip,%by_location,@intdoms);
                   9624:     &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
                   9625:     my @locations = sort(keys(%by_location));
1.137     raeburn  9626:     my (%defaultshash,%changes);
                   9627:     foreach my $prefix (@prefixes) {
                   9628:         $defaultshash{'usersessions'}{$prefix} = {};
                   9629:     }
1.212     raeburn  9630:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137     raeburn  9631:     my $resulttext;
1.138     raeburn  9632:     my %iphost = &Apache::lonnet::get_iphost();
1.137     raeburn  9633:     foreach my $prefix (@prefixes) {
1.145     raeburn  9634:         next if ($prefix eq 'spares');
                   9635:         foreach my $type (@{$types{$prefix}}) {
1.137     raeburn  9636:             my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
                   9637:             if ($type eq 'version') {
                   9638:                 my $value = $env{'form.'.$prefix.'_'.$type};
                   9639:                 my $okvalue;
                   9640:                 if ($value ne '') {
                   9641:                     if (grep(/^\Q$value\E$/,@lcversions)) {
                   9642:                         $okvalue = $value;
                   9643:                     }
                   9644:                 }
                   9645:                 if (ref($domconfig{'usersessions'}) eq 'HASH') {
                   9646:                     if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
                   9647:                         if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
                   9648:                             if ($inuse == 0) {
                   9649:                                 $changes{$prefix}{$type} = 1;
                   9650:                             } else {
                   9651:                                 if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
                   9652:                                     $changes{$prefix}{$type} = 1;
                   9653:                                 }
                   9654:                                 if ($okvalue ne '') {
                   9655:                                     $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
                   9656:                                 } 
                   9657:                             }
                   9658:                         } else {
                   9659:                             if (($inuse == 1) && ($okvalue ne '')) {
                   9660:                                 $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
                   9661:                                 $changes{$prefix}{$type} = 1;
                   9662:                             }
                   9663:                         }
                   9664:                     } else {
                   9665:                         if (($inuse == 1) && ($okvalue ne '')) {
                   9666:                             $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
                   9667:                             $changes{$prefix}{$type} = 1;
                   9668:                         }
                   9669:                     }
                   9670:                 } else {
                   9671:                     if (($inuse == 1) && ($okvalue ne '')) {
                   9672:                         $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
                   9673:                         $changes{$prefix}{$type} = 1;
                   9674:                     }
                   9675:                 }
                   9676:             } else {
                   9677:                 my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
                   9678:                 my @okvals;
                   9679:                 foreach my $val (@vals) {
1.138     raeburn  9680:                     if ($val =~ /:/) {
                   9681:                         my @items = split(/:/,$val);
                   9682:                         foreach my $item (@items) {
                   9683:                             if (ref($by_location{$item}) eq 'ARRAY') {
                   9684:                                 push(@okvals,$item);
                   9685:                             }
                   9686:                         }
                   9687:                     } else {
                   9688:                         if (ref($by_location{$val}) eq 'ARRAY') {
                   9689:                             push(@okvals,$val);
                   9690:                         }
1.137     raeburn  9691:                     }
                   9692:                 }
                   9693:                 @okvals = sort(@okvals);
                   9694:                 if (ref($domconfig{'usersessions'}) eq 'HASH') {
                   9695:                     if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
                   9696:                         if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
                   9697:                             if ($inuse == 0) {
                   9698:                                 $changes{$prefix}{$type} = 1; 
                   9699:                             } else {
                   9700:                                 $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
                   9701:                                 my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
                   9702:                                 if (@changed > 0) {
                   9703:                                     $changes{$prefix}{$type} = 1;
                   9704:                                 }
                   9705:                             }
                   9706:                         } else {
                   9707:                             if ($inuse == 1) {
                   9708:                                 $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
                   9709:                                 $changes{$prefix}{$type} = 1;
                   9710:                             }
                   9711:                         } 
                   9712:                     } else {
                   9713:                         if ($inuse == 1) {
                   9714:                             $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
                   9715:                             $changes{$prefix}{$type} = 1;
                   9716:                         }
                   9717:                     }
                   9718:                 } else {
                   9719:                     if ($inuse == 1) {
                   9720:                         $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
                   9721:                         $changes{$prefix}{$type} = 1;
                   9722:                     }
                   9723:                 }
                   9724:             }
                   9725:         }
                   9726:     }
1.145     raeburn  9727: 
                   9728:     my @alldoms = &Apache::lonnet::all_domains();
1.149     raeburn  9729:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145     raeburn  9730:     my %spareid = &current_offloads_to($dom,$domconfig{'usersessions'},\%servers);
                   9731:     my $savespares;
                   9732: 
                   9733:     foreach my $lonhost (sort(keys(%servers))) {
                   9734:         my $serverhomeID =
                   9735:             &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152     raeburn  9736:         my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145     raeburn  9737:         $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
                   9738:         my %spareschg;
                   9739:         foreach my $type (@{$types{'spares'}}) {
                   9740:             my @okspares;
                   9741:             my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
                   9742:             foreach my $server (@checked) {
1.152     raeburn  9743:                 if (&Apache::lonnet::hostname($server) ne '') {
                   9744:                     unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
                   9745:                         unless (grep(/^\Q$server\E$/,@okspares)) {
                   9746:                             push(@okspares,$server);
                   9747:                         }
1.145     raeburn  9748:                     }
                   9749:                 }
                   9750:             }
                   9751:             my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
                   9752:             my $newspare;
1.152     raeburn  9753:             if (($new ne '') && (&Apache::lonnet::hostname($new))) {
                   9754:                 unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145     raeburn  9755:                     $newspare = $new;
                   9756:                 }
                   9757:             }
1.152     raeburn  9758:             my @spares;
                   9759:             if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
                   9760:                 @spares = sort(@okspares,$newspare);
                   9761:             } else {
                   9762:                 @spares = sort(@okspares);
                   9763:             }
                   9764:             $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145     raeburn  9765:             if (ref($spareid{$lonhost}) eq 'HASH') {
                   9766:                 if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152     raeburn  9767:                     my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145     raeburn  9768:                     if (@diffs > 0) {
                   9769:                         $spareschg{$type} = 1;
                   9770:                     }
                   9771:                 }
                   9772:             }
                   9773:         }
                   9774:         if (keys(%spareschg) > 0) {
                   9775:             $changes{'spares'}{$lonhost} = \%spareschg;
                   9776:         }
                   9777:     }
                   9778: 
                   9779:     if (ref($domconfig{'usersessions'}) eq 'HASH') {
                   9780:         if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
                   9781:             if (ref($changes{'spares'}) eq 'HASH') {
                   9782:                 if (keys(%{$changes{'spares'}}) > 0) {
                   9783:                     $savespares = 1;
                   9784:                 }
                   9785:             }
                   9786:         } else {
                   9787:             $savespares = 1;
                   9788:         }
                   9789:     }
                   9790: 
1.147     raeburn  9791:     my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
                   9792:     if ((keys(%changes) > 0) || ($savespares)) {
1.137     raeburn  9793:         my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
                   9794:                                                  $dom);
                   9795:         if ($putresult eq 'ok') {
                   9796:             if (ref($defaultshash{'usersessions'}) eq 'HASH') {
                   9797:                 if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
                   9798:                     $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
                   9799:                 }
                   9800:                 if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
                   9801:                     $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
                   9802:                 }
                   9803:             }
                   9804:             my $cachetime = 24*60*60;
                   9805:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212     raeburn  9806:             if (ref($lastactref) eq 'HASH') {
                   9807:                 $lastactref->{'domdefaults'} = 1;
                   9808:             }
1.147     raeburn  9809:             if (keys(%changes) > 0) {
                   9810:                 my %lt = &usersession_titles();
                   9811:                 $resulttext = &mt('Changes made:').'<ul>';
                   9812:                 foreach my $prefix (@prefixes) {
                   9813:                     if (ref($changes{$prefix}) eq 'HASH') {
                   9814:                         $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
                   9815:                         if ($prefix eq 'spares') {
                   9816:                             if (ref($changes{$prefix}) eq 'HASH') {
                   9817:                                 foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
                   9818:                                     $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148     raeburn  9819:                                     my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211     raeburn  9820:                                     my $cachekey = &escape('spares').':'.&escape($lonhostdom);
                   9821:                                     &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147     raeburn  9822:                                     if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
                   9823:                                         foreach my $type (@{$types{$prefix}}) {
                   9824:                                             if ($changes{$prefix}{$lonhost}{$type}) {
                   9825:                                                 my $offloadto = &mt('None');
                   9826:                                                 if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
                   9827:                                                     if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {   
                   9828:                                                         $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
                   9829:                                                     }
1.145     raeburn  9830:                                                 }
1.147     raeburn  9831:                                                 $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).('&nbsp;'x3);
1.145     raeburn  9832:                                             }
1.137     raeburn  9833:                                         }
                   9834:                                     }
1.147     raeburn  9835:                                     $resulttext .= '</li>';
1.137     raeburn  9836:                                 }
                   9837:                             }
1.147     raeburn  9838:                         } else {
                   9839:                             foreach my $type (@{$types{$prefix}}) {
                   9840:                                 if (defined($changes{$prefix}{$type})) {
                   9841:                                     my $newvalue;
                   9842:                                     if (ref($defaultshash{'usersessions'}) eq 'HASH') {
                   9843:                                         if (ref($defaultshash{'usersessions'}{$prefix})) {
                   9844:                                             if ($type eq 'version') {
                   9845:                                                 $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
                   9846:                                             } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
                   9847:                                                 if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
                   9848:                                                     $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
                   9849:                                                 }
1.145     raeburn  9850:                                             }
                   9851:                                         }
                   9852:                                     }
1.147     raeburn  9853:                                     if ($newvalue eq '') {
                   9854:                                         if ($type eq 'version') {
                   9855:                                             $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
                   9856:                                         } else {
                   9857:                                             $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
                   9858:                                         }
1.145     raeburn  9859:                                     } else {
1.147     raeburn  9860:                                         if ($type eq 'version') {
                   9861:                                             $newvalue .= ' '.&mt('(or later)'); 
                   9862:                                         }
                   9863:                                         $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145     raeburn  9864:                                     }
1.137     raeburn  9865:                                 }
                   9866:                             }
                   9867:                         }
1.147     raeburn  9868:                         $resulttext .= '</ul>';
1.137     raeburn  9869:                     }
                   9870:                 }
1.147     raeburn  9871:                 $resulttext .= '</ul>';
                   9872:             } else {
                   9873:                 $resulttext = $nochgmsg;
1.137     raeburn  9874:             }
                   9875:         } else {
                   9876:             $resulttext = '<span class="LC_error">'.
                   9877:                           &mt('An error occurred: [_1]',$putresult).'</span>';
                   9878:         }
                   9879:     } else {
1.147     raeburn  9880:         $resulttext = $nochgmsg;
1.137     raeburn  9881:     }
                   9882:     return $resulttext;
                   9883: }
                   9884: 
1.150     raeburn  9885: sub modify_loadbalancing {
                   9886:     my ($dom,%domconfig) = @_;
                   9887:     my $primary_id = &Apache::lonnet::domain($dom,'primary');
                   9888:     my $intdom = &Apache::lonnet::internet_dom($primary_id);
                   9889:     my ($othertitle,$usertypes,$types) =
                   9890:         &Apache::loncommon::sorted_inst_types($dom);
                   9891:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
                   9892:     my @sparestypes = ('primary','default');
                   9893:     my %typetitles = &sparestype_titles();
                   9894:     my $resulttext;
1.171     raeburn  9895:     my (%currbalancer,%currtargets,%currrules,%existing);
                   9896:     if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
                   9897:         %existing = %{$domconfig{'loadbalancing'}};
                   9898:     }
                   9899:     &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
                   9900:                               \%currtargets,\%currrules);
                   9901:     my ($saveloadbalancing,%defaultshash,%changes);
                   9902:     my ($alltypes,$othertypes,$titles) =
                   9903:         &loadbalancing_titles($dom,$intdom,$usertypes,$types);
                   9904:     my %ruletitles = &offloadtype_text();
                   9905:     my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
                   9906:     for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
                   9907:         my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
                   9908:         if ($balancer eq '') {
                   9909:             next;
                   9910:         }
1.210     raeburn  9911:         if (!exists($servers{$balancer})) {
1.171     raeburn  9912:             if (exists($currbalancer{$balancer})) {
                   9913:                 push(@{$changes{'delete'}},$balancer);
1.150     raeburn  9914:             }
1.171     raeburn  9915:             next;
                   9916:         }
                   9917:         if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
                   9918:             push(@{$changes{'delete'}},$balancer);
                   9919:             next;
                   9920:         }
                   9921:         if (!exists($currbalancer{$balancer})) {
                   9922:             push(@{$changes{'add'}},$balancer);
                   9923:         }
                   9924:         $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
                   9925:         $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
                   9926:         $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
                   9927:         unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
                   9928:             $saveloadbalancing = 1;
                   9929:         }
                   9930:         foreach my $sparetype (@sparestypes) {
                   9931:             my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
                   9932:             my @offloadto;
                   9933:             foreach my $target (@targets) {
                   9934:                 if (($servers{$target}) && ($target ne $balancer)) {
                   9935:                     if ($sparetype eq 'default') {
                   9936:                         if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
                   9937:                             next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150     raeburn  9938:                         }
                   9939:                     }
1.171     raeburn  9940:                     unless(grep(/^\Q$target\E$/,@offloadto)) {
                   9941:                         push(@offloadto,$target);
                   9942:                     }
1.150     raeburn  9943:                 }
1.171     raeburn  9944:                 $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150     raeburn  9945:             }
                   9946:         }
1.171     raeburn  9947:         if (ref($currtargets{$balancer}) eq 'HASH') {
1.150     raeburn  9948:             foreach my $sparetype (@sparestypes) {
1.171     raeburn  9949:                 if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
                   9950:                     my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150     raeburn  9951:                     if (@targetdiffs > 0) {
1.171     raeburn  9952:                         $changes{'curr'}{$balancer}{'targets'} = 1;
1.150     raeburn  9953:                     }
1.171     raeburn  9954:                 } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
                   9955:                     if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
                   9956:                         $changes{'curr'}{$balancer}{'targets'} = 1;
1.150     raeburn  9957:                     }
                   9958:                 }
                   9959:             }
                   9960:         } else {
1.171     raeburn  9961:             if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210     raeburn  9962:                 foreach my $sparetype (@sparestypes) {
1.171     raeburn  9963:                     if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
                   9964:                         if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
                   9965:                             $changes{'curr'}{$balancer}{'targets'} = 1;
                   9966:                         }
1.150     raeburn  9967:                     }
                   9968:                 }
1.210     raeburn  9969:             }
1.150     raeburn  9970:         }
                   9971:         my $ishomedom;
1.171     raeburn  9972:         if (&Apache::lonnet::host_domain($balancer) eq $dom) {
                   9973:             $ishomedom = 1;
1.150     raeburn  9974:         }
                   9975:         if (ref($alltypes) eq 'ARRAY') {
                   9976:             foreach my $type (@{$alltypes}) {
                   9977:                 my $rule;
1.210     raeburn  9978:                 unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150     raeburn  9979:                          (!$ishomedom)) {
1.171     raeburn  9980:                     $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
                   9981:                 }
                   9982:                 if ($rule eq 'specific') {
                   9983:                     $rule = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.150     raeburn  9984:                 }
1.171     raeburn  9985:                 $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
                   9986:                 if (ref($currrules{$balancer}) eq 'HASH') {
                   9987:                     if ($rule ne $currrules{$balancer}{$type}) {
                   9988:                         $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150     raeburn  9989:                     }
                   9990:                 } elsif ($rule ne '') {
1.171     raeburn  9991:                     $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150     raeburn  9992:                 }
                   9993:             }
                   9994:         }
1.171     raeburn  9995:     }
                   9996:     my $nochgmsg = &mt('No changes made to Load Balancer settings.');
                   9997:     if ((keys(%changes) > 0) || ($saveloadbalancing)) {
                   9998:         unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
                   9999:             $defaultshash{'loadbalancing'} = {};
                   10000:         }
                   10001:         my $putresult = &Apache::lonnet::put_dom('configuration',
                   10002:                                                  \%defaultshash,$dom);
                   10003:         if ($putresult eq 'ok') {
                   10004:             if (keys(%changes) > 0) {
                   10005:                 if (ref($changes{'delete'}) eq 'ARRAY') {
                   10006:                     foreach my $balancer (sort(@{$changes{'delete'}})) {
                   10007:                         $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.211     raeburn  10008:                         my $cachekey = &escape('loadbalancing').':'.&escape($dom);
                   10009:                         &Apache::lonnet::remote_devalidate_cache($balancer,[$cachekey]);
1.150     raeburn  10010:                     }
1.171     raeburn  10011:                 }
                   10012:                 if (ref($changes{'add'}) eq 'ARRAY') {
1.210     raeburn  10013:                     foreach my $balancer (sort(@{$changes{'add'}})) {
1.171     raeburn  10014:                         $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
                   10015:                     }
                   10016:                 }
                   10017:                 if (ref($changes{'curr'}) eq 'HASH') {
                   10018:                     foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
                   10019:                         if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
                   10020:                             if ($changes{'curr'}{$balancer}{'targets'}) {
                   10021:                                 my %offloadstr;
                   10022:                                 foreach my $sparetype (@sparestypes) {
                   10023:                                     if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
                   10024:                                         if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
                   10025:                                             $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
                   10026:                                         }
                   10027:                                     }
1.150     raeburn  10028:                                 }
1.171     raeburn  10029:                                 if (keys(%offloadstr) == 0) {
                   10030:                                     $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150     raeburn  10031:                                 } else {
1.171     raeburn  10032:                                     my $showoffload;
                   10033:                                     foreach my $sparetype (@sparestypes) {
                   10034:                                         $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>:&nbsp;';
                   10035:                                         if (defined($offloadstr{$sparetype})) {
                   10036:                                             $showoffload .= $offloadstr{$sparetype};
                   10037:                                         } else {
                   10038:                                             $showoffload .= &mt('None');
                   10039:                                         }
                   10040:                                         $showoffload .= ('&nbsp;'x3);
                   10041:                                     }
                   10042:                                     $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150     raeburn  10043:                                 }
                   10044:                             }
                   10045:                         }
1.171     raeburn  10046:                         if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
                   10047:                             if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
                   10048:                                 foreach my $type (@{$alltypes}) {
                   10049:                                     if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
                   10050:                                         my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
                   10051:                                         my $balancetext;
                   10052:                                         if ($rule eq '') {
                   10053:                                             $balancetext =  $ruletitles{'default'};
1.209     raeburn  10054:                                         } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
                   10055:                                                  ($rule eq 'balancer') || ($rule eq 'offloadedto')) {
1.171     raeburn  10056:                                             $balancetext =  $ruletitles{$rule};
                   10057:                                         } else {
                   10058:                                             $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
                   10059:                                         }
1.210     raeburn  10060:                                         $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150     raeburn  10061:                                     }
                   10062:                                 }
                   10063:                             }
                   10064:                         }
1.215     raeburn  10065:                         my $cachekey = &escape('loadbalancing').':'.&escape($dom);
1.211     raeburn  10066:                         &Apache::lonnet::remote_devalidate_cache($balancer,[$cachekey]);
1.150     raeburn  10067:                     }
1.171     raeburn  10068:                 }
                   10069:                 if ($resulttext ne '') {
                   10070:                     $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150     raeburn  10071:                 } else {
                   10072:                     $resulttext = $nochgmsg;
                   10073:                 }
                   10074:             } else {
1.171     raeburn  10075:                 $resulttext = $nochgmsg;
1.150     raeburn  10076:             }
                   10077:         } else {
1.171     raeburn  10078:             $resulttext = '<span class="LC_error">'.
                   10079:                           &mt('An error occurred: [_1]',$putresult).'</span>';
1.150     raeburn  10080:         }
                   10081:     } else {
1.171     raeburn  10082:         $resulttext = $nochgmsg;
1.150     raeburn  10083:     }
                   10084:     return $resulttext;
                   10085: }
                   10086: 
1.48      raeburn  10087: sub recurse_check {
                   10088:     my ($chkcats,$categories,$depth,$name) = @_;
                   10089:     if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
                   10090:         my $chg = 0;
                   10091:         for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
                   10092:             my $category = $chkcats->[$depth]{$name}[$j];
                   10093:             my $item;
                   10094:             if ($category eq '') {
                   10095:                 $chg ++;
                   10096:             } else {
                   10097:                 my $deeper = $depth + 1;
                   10098:                 $item = &escape($category).':'.&escape($name).':'.$depth;
                   10099:                 if ($chg) {
                   10100:                     $categories->{$item} -= $chg;
                   10101:                 }
                   10102:                 &recurse_check($chkcats,$categories,$deeper,$category);
                   10103:                 $deeper --;
                   10104:             }
                   10105:         }
                   10106:     }
                   10107:     return;
                   10108: }
                   10109: 
                   10110: sub recurse_cat_deletes {
                   10111:     my ($item,$coursecategories,$deletions) = @_;
                   10112:     my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
                   10113:     my $subdepth = $depth + 1;
                   10114:     if (ref($coursecategories) eq 'HASH') {
                   10115:         foreach my $subitem (keys(%{$coursecategories})) {
                   10116:             my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
                   10117:             if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
                   10118:                 delete($coursecategories->{$subitem});
                   10119:                 $deletions->{$subitem} = 1;
                   10120:                 &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168     raeburn  10121:             }
1.48      raeburn  10122:         }
                   10123:     }
                   10124:     return;
                   10125: }
                   10126: 
1.125     raeburn  10127: sub get_active_dcs {
                   10128:     my ($dom) = @_;
1.191     raeburn  10129:     my $now = time;
                   10130:     my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
1.125     raeburn  10131:     my %domcoords;
                   10132:     my $numdcs = 0;
                   10133:     foreach my $server (keys(%dompersonnel)) {
                   10134:         foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
                   10135:             my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
1.191     raeburn  10136:             $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
1.125     raeburn  10137:         }
                   10138:     }
                   10139:     return %domcoords;
                   10140: }
                   10141: 
                   10142: sub active_dc_picker {
1.191     raeburn  10143:     my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.125     raeburn  10144:     my %domcoords = &get_active_dcs($dom); 
1.191     raeburn  10145:     my @domcoord = keys(%domcoords);
                   10146:     if (keys(%currhash)) {
                   10147:         foreach my $dc (keys(%currhash)) {
                   10148:             unless (exists($domcoords{$dc})) {
                   10149:                 push(@domcoord,$dc);
                   10150:             }
                   10151:         }
                   10152:     }
                   10153:     @domcoord = sort(@domcoord);
1.210     raeburn  10154:     my $numdcs = scalar(@domcoord);
1.191     raeburn  10155:     my $rows = 0;
                   10156:     my $table;
1.125     raeburn  10157:     if ($numdcs > 1) {
1.191     raeburn  10158:         $table = '<table>';
                   10159:         for (my $i=0; $i<@domcoord; $i++) {
1.125     raeburn  10160:             my $rem = $i%($numinrow);
                   10161:             if ($rem == 0) {
                   10162:                 if ($i > 0) {
1.191     raeburn  10163:                     $table .= '</tr>';
1.125     raeburn  10164:                 }
1.191     raeburn  10165:                 $table .= '<tr>';
                   10166:                 $rows ++;
1.125     raeburn  10167:             }
1.191     raeburn  10168:             my $check = '';
                   10169:             if ($inputtype eq 'radio') {
                   10170:                 if (keys(%currhash) == 0) {
                   10171:                     if (!$i) {
                   10172:                         $check = ' checked="checked"';
                   10173:                     }
                   10174:                 } elsif (exists($currhash{$domcoord[$i]})) {
                   10175:                     $check = ' checked="checked"';
                   10176:                 }
                   10177:             } else {
                   10178:                 if (exists($currhash{$domcoord[$i]})) {
                   10179:                     $check = ' checked="checked"';
1.125     raeburn  10180:                 }
                   10181:             }
1.191     raeburn  10182:             if ($i == @domcoord - 1) {
1.125     raeburn  10183:                 my $colsleft = $numinrow - $rem;
                   10184:                 if ($colsleft > 1) {
1.191     raeburn  10185:                     $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125     raeburn  10186:                 } else {
1.191     raeburn  10187:                     $table .= '<td class="LC_left_item">';
1.125     raeburn  10188:                 }
                   10189:             } else {
1.191     raeburn  10190:                 $table .= '<td class="LC_left_item">';
                   10191:             }
                   10192:             my ($dcname,$dcdom) = split(':',$domcoord[$i]);
                   10193:             my $user = &Apache::loncommon::plainname($dcname,$dcdom);
                   10194:             $table .= '<span class="LC_nobreak"><label>'.
                   10195:                       '<input type="'.$inputtype.'" name="'.$name.'"'.
                   10196:                       ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
                   10197:             if ($user ne $dcname.':'.$dcdom) {
1.219     raeburn  10198:                 $table .=  ' ('.$dcname.':'.$dcdom.')';
1.191     raeburn  10199:             }
1.219     raeburn  10200:             $table .= '</label></span></td>';
1.191     raeburn  10201:         }
                   10202:         $table .= '</tr></table>';
                   10203:     } elsif ($numdcs == 1) {
1.219     raeburn  10204:         my ($dcname,$dcdom) = split(':',$domcoord[0]);
                   10205:         my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191     raeburn  10206:         if ($inputtype eq 'radio') {
1.219     raeburn  10207:             $table .= '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
                   10208:             if ($user ne $dcname.':'.$dcdom) {
                   10209:                 $table .=  ' ('.$dcname.':'.$dcdom.')';
                   10210:             }
1.191     raeburn  10211:         } else {
                   10212:             my $check;
                   10213:             if (exists($currhash{$domcoord[0]})) {
                   10214:                 $check = ' checked="checked"';
1.125     raeburn  10215:             }
1.219     raeburn  10216:             $table .= '<span class="LC_nobreak"><label>'.
                   10217:                       '<input type="checkbox" name="'.$name.'" '.
                   10218:                       'value="'.$domcoord[0].'"'.$check.' />'.$user;
                   10219:             if ($user ne $dcname.':'.$dcdom) {
1.220     raeburn  10220:                 $table .=  ' ('.$dcname.':'.$dcdom.')';
1.219     raeburn  10221:             }
1.220     raeburn  10222:             $table .= '</label></span>';
1.191     raeburn  10223:             $rows ++;
1.125     raeburn  10224:         }
                   10225:     }
1.191     raeburn  10226:     return ($numdcs,$table,$rows);
1.125     raeburn  10227: }
                   10228: 
1.137     raeburn  10229: sub usersession_titles {
                   10230:     return &Apache::lonlocal::texthash(
                   10231:                hosted => 'Hosting of sessions for users from other domains on servers in this domain',
                   10232:                remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145     raeburn  10233:                spares => 'Servers offloaded to, when busy',
1.137     raeburn  10234:                version => 'LON-CAPA version requirement',
1.138     raeburn  10235:                excludedomain => 'Allow all, but exclude specific domains',
                   10236:                includedomain => 'Deny all, but include specific domains',
1.145     raeburn  10237:                primary => 'Primary (checked first)',
1.154     raeburn  10238:                default => 'Default',
1.137     raeburn  10239:            );
                   10240: }
                   10241: 
1.152     raeburn  10242: sub id_for_thisdom {
                   10243:     my (%servers) = @_;
                   10244:     my %altids;
                   10245:     foreach my $server (keys(%servers)) {
                   10246:         my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
                   10247:         if ($serverhome ne $server) {
                   10248:             $altids{$serverhome} = $server;
                   10249:         }
                   10250:     }
                   10251:     return %altids;
                   10252: }
                   10253: 
1.150     raeburn  10254: sub count_servers {
                   10255:     my ($currbalancer,%servers) = @_;
                   10256:     my (@spares,$numspares);
                   10257:     foreach my $lonhost (sort(keys(%servers))) {
                   10258:         next if ($currbalancer eq $lonhost);
                   10259:         push(@spares,$lonhost);
                   10260:     }
                   10261:     if ($currbalancer) {
                   10262:         $numspares = scalar(@spares);
                   10263:     } else {
                   10264:         $numspares = scalar(@spares) - 1;
                   10265:     }
                   10266:     return ($numspares,@spares);
                   10267: }
                   10268: 
                   10269: sub lonbalance_targets_js {
1.171     raeburn  10270:     my ($dom,$types,$servers,$settings) = @_;
1.150     raeburn  10271:     my $select = &mt('Select');
                   10272:     my ($alltargets,$allishome,$allinsttypes,@alltypes);
                   10273:     if (ref($servers) eq 'HASH') {
                   10274:         $alltargets = join("','",sort(keys(%{$servers})));
                   10275:         my @homedoms;
                   10276:         foreach my $server (sort(keys(%{$servers}))) {
                   10277:             if (&Apache::lonnet::host_domain($server) eq $dom) {
                   10278:                 push(@homedoms,'1');
                   10279:             } else {
                   10280:                 push(@homedoms,'0');
                   10281:             }
                   10282:         }
                   10283:         $allishome = join("','",@homedoms);
                   10284:     }
                   10285:     if (ref($types) eq 'ARRAY') {
                   10286:         if (@{$types} > 0) {
                   10287:             @alltypes = @{$types};
                   10288:         }
                   10289:     }
                   10290:     push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
                   10291:     $allinsttypes = join("','",@alltypes);
1.171     raeburn  10292:     my (%currbalancer,%currtargets,%currrules,%existing);
                   10293:     if (ref($settings) eq 'HASH') {
                   10294:         %existing = %{$settings};
                   10295:     }
                   10296:     &get_loadbalancers_config($servers,\%existing,\%currbalancer,
                   10297:                               \%currtargets,\%currrules);
1.210     raeburn  10298:     my $balancers = join("','",sort(keys(%currbalancer)));
1.150     raeburn  10299:     return <<"END";
                   10300: 
                   10301: <script type="text/javascript">
                   10302: // <![CDATA[
                   10303: 
1.171     raeburn  10304: currBalancers = new Array('$balancers');
                   10305: 
                   10306: function toggleTargets(balnum) {
                   10307:     var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
                   10308:     var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
                   10309:     var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
                   10310:     var prevbalancer = prevhostitem.value;
                   10311:     var baltotal = document.getElementById('loadbalancing_total').value;
                   10312:     prevhostitem.value = balancer;
                   10313:     if (prevbalancer != '') {
                   10314:         var prevIdx = currBalancers.indexOf(prevbalancer);
                   10315:         if (prevIdx != -1) {
                   10316:             currBalancers.splice(prevIdx,1);
                   10317:         }
                   10318:     }
1.150     raeburn  10319:     if (balancer == '') {
1.171     raeburn  10320:         hideSpares(balnum);
1.150     raeburn  10321:     } else {
1.171     raeburn  10322:         var currIdx = currBalancers.indexOf(balancer);
                   10323:         if (currIdx == -1) {
                   10324:             currBalancers.push(balancer);
                   10325:         }
1.150     raeburn  10326:         var homedoms = new Array('$allishome');
1.171     raeburn  10327:         var ishomedom = homedoms[lonhostitem.selectedIndex];
                   10328:         showSpares(balancer,ishomedom,balnum);
1.150     raeburn  10329:     }
1.171     raeburn  10330:     balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150     raeburn  10331:     return;
                   10332: }
                   10333: 
1.171     raeburn  10334: function showSpares(balancer,ishomedom,balnum) {
1.150     raeburn  10335:     var alltargets = new Array('$alltargets');
                   10336:     var insttypes = new Array('$allinsttypes');
1.151     raeburn  10337:     var offloadtypes = new Array('primary','default');
                   10338: 
1.171     raeburn  10339:     document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
                   10340:     document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152     raeburn  10341:  
1.151     raeburn  10342:     for (var i=0; i<offloadtypes.length; i++) {
                   10343:         var count = 0;
                   10344:         for (var j=0; j<alltargets.length; j++) {
                   10345:             if (alltargets[j] != balancer) {
1.171     raeburn  10346:                 var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
                   10347:                 item.value = alltargets[j];
                   10348:                 item.style.textAlign='left';
                   10349:                 item.style.textFace='normal';
                   10350:                 document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
                   10351:                 if (currBalancers.indexOf(alltargets[j]) == -1) {
                   10352:                     item.disabled = '';
                   10353:                 } else {
                   10354:                     item.disabled = 'disabled';
                   10355:                     item.checked = false;
                   10356:                 }
1.151     raeburn  10357:                 count ++;
                   10358:             }
1.150     raeburn  10359:         }
                   10360:     }
1.151     raeburn  10361:     for (var k=0; k<insttypes.length; k++) {
                   10362:         if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150     raeburn  10363:             if (ishomedom == 1) {
1.171     raeburn  10364:                 document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
                   10365:                 document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150     raeburn  10366:             } else {
1.171     raeburn  10367:                 document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
                   10368:                 document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150     raeburn  10369:             }
                   10370:         } else {
1.171     raeburn  10371:             document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
                   10372:             document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150     raeburn  10373:         }
1.151     raeburn  10374:         if ((insttypes[k] != '_LC_external') && 
                   10375:             ((insttypes[k] != '_LC_internetdom') ||
                   10376:              ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171     raeburn  10377:             var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
                   10378:             item.options.length = 0;
                   10379:             item.options[0] = new Option("","",true,true);
1.210     raeburn  10380:             var idx = 0;
1.151     raeburn  10381:             for (var m=0; m<alltargets.length; m++) {
1.171     raeburn  10382:                 if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
                   10383:                     idx ++;
                   10384:                     item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150     raeburn  10385:                 }
                   10386:             }
                   10387:         }
                   10388:     }
                   10389:     return;
                   10390: }
                   10391: 
1.171     raeburn  10392: function hideSpares(balnum) {
1.150     raeburn  10393:     var alltargets = new Array('$alltargets');
                   10394:     var insttypes = new Array('$allinsttypes');
                   10395:     var offloadtypes = new Array('primary','default');
                   10396: 
1.171     raeburn  10397:     document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
                   10398:     document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150     raeburn  10399: 
                   10400:     var total = alltargets.length - 1;
                   10401:     for (var i=0; i<offloadtypes; i++) {
                   10402:         for (var j=0; j<total; j++) {
1.171     raeburn  10403:            document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
                   10404:            document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
                   10405:            document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151     raeburn  10406:         }
1.150     raeburn  10407:     }
                   10408:     for (var k=0; k<insttypes.length; k++) {
1.171     raeburn  10409:         document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
                   10410:         document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151     raeburn  10411:         if (insttypes[k] != '_LC_external') {
1.171     raeburn  10412:             document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
                   10413:             document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150     raeburn  10414:         }
                   10415:     }
                   10416:     return;
                   10417: }
                   10418: 
1.171     raeburn  10419: function checkOffloads(item,balnum,type) {
1.150     raeburn  10420:     var alltargets = new Array('$alltargets');
                   10421:     var offloadtypes = new Array('primary','default');
                   10422:     if (item.checked) {
                   10423:         var total = alltargets.length - 1;
                   10424:         var other;
                   10425:         if (type == offloadtypes[0]) {
1.151     raeburn  10426:             other = offloadtypes[1];
1.150     raeburn  10427:         } else {
1.151     raeburn  10428:             other = offloadtypes[0];
1.150     raeburn  10429:         }
                   10430:         for (var i=0; i<total; i++) {
1.171     raeburn  10431:             var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150     raeburn  10432:             if (server == item.value) {
1.171     raeburn  10433:                 if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
                   10434:                     document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150     raeburn  10435:                 }
                   10436:             }
                   10437:         }
                   10438:     }
                   10439:     return;
                   10440: }
                   10441: 
1.171     raeburn  10442: function singleServerToggle(balnum,type) {
                   10443:     var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150     raeburn  10444:     if (offloadtoSelIdx == 0) {
1.171     raeburn  10445:         document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
                   10446:         document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150     raeburn  10447: 
                   10448:     } else {
1.171     raeburn  10449:         document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
                   10450:         document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150     raeburn  10451:     }
                   10452:     return;
                   10453: }
                   10454: 
1.171     raeburn  10455: function balanceruleChange(formname,balnum,type) {
1.150     raeburn  10456:     if (type == '_LC_external') {
1.171     raeburn  10457:         return;
1.150     raeburn  10458:     }
1.171     raeburn  10459:     var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150     raeburn  10460:     for (var i=0; i<typesRules.length; i++) {
                   10461:         if (formname.elements[typesRules[i]].checked) {
                   10462:             if (formname.elements[typesRules[i]].value != 'specific') {
1.171     raeburn  10463:                 document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
                   10464:                 document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150     raeburn  10465:             } else {
1.171     raeburn  10466:                 document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
                   10467:             }
                   10468:         }
                   10469:     }
                   10470:     return;
                   10471: }
                   10472: 
                   10473: function balancerDeleteChange(balnum) {
                   10474:     var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
                   10475:     var baltotal = document.getElementById('loadbalancing_total').value;
                   10476:     var addtarget;
                   10477:     var removetarget;
                   10478:     var action = 'delete';
                   10479:     if (document.getElementById('loadbalancing_delete_'+balnum)) {
                   10480:         var lonhost = hostitem.value;
                   10481:         var currIdx = currBalancers.indexOf(lonhost);
                   10482:         if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
                   10483:             if (currIdx != -1) {
                   10484:                 currBalancers.splice(currIdx,1);
                   10485:             }
                   10486:             addtarget = lonhost;
                   10487:         } else {
                   10488:             if (currIdx == -1) {
                   10489:                 currBalancers.push(lonhost);
                   10490:             }
                   10491:             removetarget = lonhost;
                   10492:             action = 'undelete';
                   10493:         }
                   10494:         balancerChange(balnum,baltotal,action,addtarget,removetarget);
                   10495:     }
                   10496:     return;
                   10497: }
                   10498: 
                   10499: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
                   10500:     if (baltotal > 1) {
                   10501:         var offloadtypes = new Array('primary','default');
                   10502:         var alltargets = new Array('$alltargets');
                   10503:         var insttypes = new Array('$allinsttypes');
                   10504:         for (var i=0; i<baltotal; i++) {
                   10505:             if (i != balnum) {
                   10506:                 for (var j=0; j<offloadtypes.length; j++) {
                   10507:                     var total = alltargets.length - 1;
                   10508:                     for (var k=0; k<total; k++) {
                   10509:                         var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
                   10510:                         var server = serveritem.value;
                   10511:                         if ((action == 'delete') || (action == 'change' && addtarget != ''))  {
                   10512:                             if (server == addtarget) {
                   10513:                                 serveritem.disabled = '';
                   10514:                             }
                   10515:                         }
                   10516:                         if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
                   10517:                             if (server == removetarget) {
                   10518:                                 serveritem.disabled = 'disabled';
                   10519:                                 serveritem.checked = false;
                   10520:                             }
                   10521:                         }
                   10522:                     }
                   10523:                 }
                   10524:                 for (var j=0; j<insttypes.length; j++) {
                   10525:                     if (insttypes[j] != '_LC_external') {
                   10526:                         if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
                   10527:                             var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
                   10528:                             var currSel = singleserver.selectedIndex;
                   10529:                             var currVal = singleserver.options[currSel].value;
                   10530:                             if ((action == 'delete') || (action == 'change' && addtarget != '')) {
                   10531:                                 var numoptions = singleserver.options.length;
                   10532:                                 var needsnew = 1;
                   10533:                                 for (var k=0; k<numoptions; k++) {
                   10534:                                     if (singleserver.options[k] == addtarget) {
                   10535:                                         needsnew = 0;
                   10536:                                         break;
                   10537:                                     }
                   10538:                                 }
                   10539:                                 if (needsnew == 1) {
                   10540:                                     singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
                   10541:                                 }
                   10542:                             }
                   10543:                             if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
                   10544:                                 singleserver.options.length = 0;
                   10545:                                 if ((currVal) && (currVal != removetarget)) {
                   10546:                                     singleserver.options[0] = new Option("","",false,false);
                   10547:                                 } else {
                   10548:                                     singleserver.options[0] = new Option("","",true,true);
                   10549:                                 }
                   10550:                                 var idx = 0;
                   10551:                                 for (var m=0; m<alltargets.length; m++) {
                   10552:                                     if (currBalancers.indexOf(alltargets[m]) == -1) {
                   10553:                                         idx ++;
                   10554:                                         if (currVal == alltargets[m]) {
                   10555:                                             singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
                   10556:                                         } else {
                   10557:                                             singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
                   10558:                                         }
                   10559:                                     }
                   10560:                                 }
                   10561:                             }
                   10562:                         }
                   10563:                     }
                   10564:                 }
1.150     raeburn  10565:             }
                   10566:         }
                   10567:     }
                   10568:     return;
                   10569: }
                   10570: 
1.152     raeburn  10571: // ]]>
                   10572: </script>
                   10573: 
                   10574: END
                   10575: }
                   10576: 
                   10577: sub new_spares_js {
                   10578:     my @sparestypes = ('primary','default');
                   10579:     my $types = join("','",@sparestypes);
                   10580:     my $select = &mt('Select');
                   10581:     return <<"END";
                   10582: 
                   10583: <script type="text/javascript">
                   10584: // <![CDATA[
                   10585: 
                   10586: function updateNewSpares(formname,lonhost) {
                   10587:     var types = new Array('$types');
                   10588:     var include = new Array();
                   10589:     var exclude = new Array();
                   10590:     for (var i=0; i<types.length; i++) {
                   10591:         var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
                   10592:         for (var j=0; j<spareboxes.length; j++) {
                   10593:             if (formname.elements[spareboxes[j]].checked) {
                   10594:                 exclude.push(formname.elements[spareboxes[j]].value);
                   10595:             } else {
                   10596:                 include.push(formname.elements[spareboxes[j]].value);
                   10597:             }
                   10598:         }
                   10599:     }
                   10600:     for (var i=0; i<types.length; i++) {
                   10601:         var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
                   10602:         var selIdx = newSpare.selectedIndex;
                   10603:         var currnew = newSpare.options[selIdx].value;
                   10604:         var okSpares = new Array();
                   10605:         for (var j=0; j<newSpare.options.length; j++) {
                   10606:             var possible = newSpare.options[j].value;
                   10607:             if (possible != '') {
                   10608:                 if (exclude.indexOf(possible) == -1) {
                   10609:                     okSpares.push(possible);
                   10610:                 } else {
                   10611:                     if (currnew == possible) {
                   10612:                         selIdx = 0;
                   10613:                     }
                   10614:                 }
                   10615:             }
                   10616:         }
                   10617:         for (var k=0; k<include.length; k++) {
                   10618:             if (okSpares.indexOf(include[k]) == -1) {
                   10619:                 okSpares.push(include[k]);
                   10620:             }
                   10621:         }
                   10622:         okSpares.sort();
                   10623:         newSpare.options.length = 0;
                   10624:         if (selIdx == 0) {
                   10625:             newSpare.options[0] = new Option("$select","",true,true);
                   10626:         } else {
                   10627:             newSpare.options[0] = new Option("$select","",false,false);
                   10628:         }
                   10629:         for (var m=0; m<okSpares.length; m++) {
                   10630:             var idx = m+1;
                   10631:             var selThis = 0;
                   10632:             if (selIdx != 0) {
                   10633:                 if (okSpares[m] == currnew) {
                   10634:                     selThis = 1;
                   10635:                 }
                   10636:             }
                   10637:             if (selThis == 1) {
                   10638:                 newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
                   10639:             } else {
                   10640:                 newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
                   10641:             }
                   10642:         }
                   10643:     }
                   10644:     return;
                   10645: }
                   10646: 
                   10647: function checkNewSpares(lonhost,type) {
                   10648:     var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
                   10649:     var chosen =  newSpare.options[newSpare.selectedIndex].value;
                   10650:     if (chosen != '') { 
                   10651:         var othertype;
                   10652:         var othernewSpare;
                   10653:         if (type == 'primary') {
                   10654:             othernewSpare = document.getElementById('newspare_default_'+lonhost);
                   10655:         }
                   10656:         if (type == 'default') {
                   10657:             othernewSpare = document.getElementById('newspare_primary_'+lonhost);
                   10658:         }
                   10659:         if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
                   10660:             othernewSpare.selectedIndex = 0;
                   10661:         }
                   10662:     }
                   10663:     return;
                   10664: }
                   10665: 
                   10666: // ]]>
                   10667: </script>
                   10668: 
                   10669: END
                   10670: 
                   10671: }
                   10672: 
                   10673: sub common_domprefs_js {
                   10674:     return <<"END";
                   10675: 
                   10676: <script type="text/javascript">
                   10677: // <![CDATA[
                   10678: 
1.150     raeburn  10679: function getIndicesByName(formname,item) {
1.152     raeburn  10680:     var group = new Array();
1.150     raeburn  10681:     for (var i=0;i<formname.elements.length;i++) {
                   10682:         if (formname.elements[i].name == item) {
1.152     raeburn  10683:             group.push(formname.elements[i].id);
1.150     raeburn  10684:         }
                   10685:     }
1.152     raeburn  10686:     return group;
1.150     raeburn  10687: }
                   10688: 
                   10689: // ]]>
                   10690: </script>
                   10691: 
                   10692: END
1.152     raeburn  10693: 
1.150     raeburn  10694: }
                   10695: 
1.165     raeburn  10696: sub recaptcha_js {
                   10697:     my %lt = &captcha_phrases();
                   10698:     return <<"END";
                   10699: 
                   10700: <script type="text/javascript">
                   10701: // <![CDATA[
                   10702: 
                   10703: function updateCaptcha(caller,context) {
                   10704:     var privitem;
                   10705:     var pubitem;
                   10706:     var privtext;
                   10707:     var pubtext;
                   10708:     if (document.getElementById(context+'_recaptchapub')) {
                   10709:         pubitem = document.getElementById(context+'_recaptchapub');
                   10710:     } else {
                   10711:         return;
                   10712:     }
                   10713:     if (document.getElementById(context+'_recaptchapriv')) {
                   10714:         privitem = document.getElementById(context+'_recaptchapriv');
                   10715:     } else {
                   10716:         return;
                   10717:     }
                   10718:     if (document.getElementById(context+'_recaptchapubtxt')) {
                   10719:         pubtext = document.getElementById(context+'_recaptchapubtxt');
                   10720:     } else {
                   10721:         return;
                   10722:     }
                   10723:     if (document.getElementById(context+'_recaptchaprivtxt')) {
                   10724:         privtext = document.getElementById(context+'_recaptchaprivtxt');
                   10725:     } else {
                   10726:         return;
                   10727:     }
                   10728:     if (caller.checked) {
                   10729:         if (caller.value == 'recaptcha') {
                   10730:             pubitem.type = 'text';
                   10731:             privitem.type = 'text';
                   10732:             pubitem.size = '40';
                   10733:             privitem.size = '40';
                   10734:             pubtext.innerHTML = "$lt{'pub'}";
                   10735:             privtext.innerHTML = "$lt{'priv'}";
                   10736:         } else {
                   10737:             pubitem.type = 'hidden';
                   10738:             privitem.type = 'hidden';
                   10739:             pubtext.innerHTML = '';
                   10740:             privtext.innerHTML = '';
                   10741:         }
                   10742:     }
                   10743:     return;
                   10744: }
                   10745: 
                   10746: // ]]>
                   10747: </script>
                   10748: 
                   10749: END
                   10750: 
                   10751: }
                   10752: 
1.192     raeburn  10753: sub credits_js {
                   10754:     return <<"END";
                   10755: 
                   10756: <script type="text/javascript">
                   10757: // <![CDATA[
                   10758: 
                   10759: function toggleCredits(domForm) {
                   10760:     if (document.getElementById('credits')) {
                   10761:         creditsitem = document.getElementById('credits');
                   10762:         var creditsLength = domForm.coursecredits.length;
                   10763:         if (creditsLength) {
                   10764:             var currval;
                   10765:             for (var i=0; i<creditsLength; i++) {
                   10766:                 if (domForm.coursecredits[i].checked) {
                   10767:                    currval = domForm.coursecredits[i].value;
                   10768:                 }
                   10769:             }
                   10770:             if (currval == 1) {
                   10771:                 creditsitem.style.display = 'block';
                   10772:             } else {
                   10773:                 creditsitem.style.display = 'none';
                   10774:             }
                   10775:         }
                   10776:     }
                   10777:     return;
                   10778: }
                   10779: 
                   10780: // ]]>
                   10781: </script>
                   10782: 
                   10783: END
                   10784: 
                   10785: }
                   10786: 
1.165     raeburn  10787: sub captcha_phrases {
                   10788:     return &Apache::lonlocal::texthash (
                   10789:                  priv => 'Private key',
                   10790:                  pub  => 'Public key',
                   10791:                  original  => 'original (CAPTCHA)',
                   10792:                  recaptcha => 'successor (ReCAPTCHA)',
                   10793:                  notused   => 'unused',
                   10794:     );
                   10795: }
                   10796: 
1.205     raeburn  10797: sub devalidate_remote_domconfs {
1.212     raeburn  10798:     my ($dom,$cachekeys) = @_;
                   10799:     return unless (ref($cachekeys) eq 'HASH');
1.205     raeburn  10800:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
                   10801:     my %thismachine;
                   10802:     map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.212     raeburn  10803:     my @posscached = ('domainconfig','domdefaults');
1.205     raeburn  10804:     if (keys(%servers) > 1) {
                   10805:         foreach my $server (keys(%servers)) {
                   10806:             next if ($thismachine{$server});
1.212     raeburn  10807:             my @cached;
                   10808:             foreach my $name (@posscached) {
                   10809:                 if ($cachekeys->{$name}) {
                   10810:                     push(@cached,&escape($name).':'.&escape($dom));
                   10811:                 }
                   10812:             }
                   10813:             if (@cached) {
                   10814:                 &Apache::lonnet::remote_devalidate_cache($server,\@cached);
                   10815:             }
1.205     raeburn  10816:         }
                   10817:     }
                   10818:     return;
                   10819: }
                   10820: 
1.3       raeburn  10821: 1;

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