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

1.1       raeburn     1: # The LearningOnline Network with CAPA
                      2: # Handler to set domain-wide configuration settings
                      3: #
1.155   ! raeburn     4: # $Id: domainprefs.pm,v 1.154 2011/08/17 11:16:59 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 
                     48: for use by individuals affliated with the institution.  Accordingly, each domain
                     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 
                     89: number of rows displayed on the page, and $action is the context (either quotas 
                     90: or requestcourses).
                     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,
                     97: used by course owners to request creation of a course.
                     98: 
                     99: Outputs: 1
                    100: 
                    101: $datatable  - HTML containing form elements which allow settings to be changed. 
                    102: 
                    103: In the case of course requests, radio buttons are displayed for each institutional
                    104: affiliate type (and also default, and _LC_adv) for each of the course types 
                    105: (official, unofficial and community).  In each case the radio buttons allow the 
                    106: selection of one of four values:
                    107: 
1.104     raeburn   108: 0, approval, validate, autolimit=N (where N is blank, or a positive integer).
1.101     raeburn   109: which have the following effects:
                    110: 
                    111: 0
                    112: 
                    113: =over
                    114: 
                    115: - course requests are not allowed for this course types/affiliation
                    116: 
                    117: =back
                    118: 
1.104     raeburn   119: approval 
1.101     raeburn   120: 
                    121: =over 
                    122: 
                    123: - course requests must be approved by a Doman Coordinator in the 
                    124: course's domain
                    125: 
                    126: =back
                    127: 
                    128: validate 
                    129: 
                    130: =over
                    131: 
                    132: - an institutional validation (e.g., check requestor is instructor
                    133: of record) needs to be passed before the course will be created.  The required
                    134: validation is in localenroll.pm on the primary library server for the course 
                    135: domain.
                    136: 
                    137: =back
                    138: 
                    139: autolimit 
                    140: 
                    141: =over
                    142:  
1.143     raeburn   143: - course requests will be processed automatically up to a limit of
1.101     raeburn   144: N requests for the course type for the particular requestor.
                    145: If N is undefined, there is no limit to the number of course requests
                    146: which a course owner may submit and have processed automatically. 
                    147: 
                    148: =back
                    149: 
                    150: =item modify_quotas() 
                    151: 
                    152: =back
                    153: 
                    154: =cut
                    155: 
1.1       raeburn   156: package Apache::domainprefs;
                    157: 
                    158: use strict;
                    159: use Apache::Constants qw(:common :http);
                    160: use Apache::lonnet;
                    161: use Apache::loncommon();
                    162: use Apache::lonhtmlcommon();
                    163: use Apache::lonlocal;
1.43      raeburn   164: use Apache::lonmsg();
1.91      raeburn   165: use Apache::lonconfigsettings;
1.69      raeburn   166: use LONCAPA qw(:DEFAULT :match);
1.6       raeburn   167: use LONCAPA::Enrollment;
1.81      raeburn   168: use LONCAPA::lonauthcgi();
1.9       raeburn   169: use File::Copy;
1.43      raeburn   170: use Locale::Language;
1.62      raeburn   171: use DateTime::TimeZone;
1.68      raeburn   172: use DateTime::Locale;
1.1       raeburn   173: 
1.155   ! raeburn   174: my $registered_cleanup;
        !           175: my $modified_urls;
        !           176: 
1.1       raeburn   177: sub handler {
                    178:     my $r=shift;
                    179:     if ($r->header_only) {
                    180:         &Apache::loncommon::content_type($r,'text/html');
                    181:         $r->send_http_header;
                    182:         return OK;
                    183:     }
                    184: 
1.91      raeburn   185:     my $context = 'domain';
1.1       raeburn   186:     my $dom = $env{'request.role.domain'};
1.5       albertel  187:     my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1       raeburn   188:     if (&Apache::lonnet::allowed('mau',$dom)) {
                    189:         &Apache::loncommon::content_type($r,'text/html');
                    190:         $r->send_http_header;
                    191:     } else {
                    192:         $env{'user.error.msg'}=
                    193:         "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
                    194:         return HTTP_NOT_ACCEPTABLE;
                    195:     }
1.155   ! raeburn   196: 
        !           197:     $registered_cleanup=0;
        !           198:     @{$modified_urls}=();
        !           199: 
1.1       raeburn   200:     &Apache::lonhtmlcommon::clear_breadcrumbs();
                    201:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.58      raeburn   202:                                             ['phase','actions']);
1.30      raeburn   203:     my $phase = 'pickactions';
1.3       raeburn   204:     if ( exists($env{'form.phase'}) ) {
                    205:         $phase = $env{'form.phase'};
                    206:     }
1.150     raeburn   207:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.3       raeburn   208:     my %domconfig =
1.6       raeburn   209:       &Apache::lonnet::get_dom('configuration',['login','rolecolors',
1.125     raeburn   210:                 'quotas','autoenroll','autoupdate','autocreate',
                    211:                 'directorysrch','usercreation','usermodification',
                    212:                 'contacts','defaults','scantron','coursecategories',
                    213:                 'serverstatuses','requestcourses','helpsettings',
1.150     raeburn   214:                 'coursedefaults','usersessions','loadbalancing'],$dom);
1.43      raeburn   215:     my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll',
1.125     raeburn   216:                        'autoupdate','autocreate','directorysrch','contacts',
1.48      raeburn   217:                        'usercreation','usermodification','scantron',
1.121     raeburn   218:                        'requestcourses','coursecategories','serverstatuses','helpsettings',
1.137     raeburn   219:                        'coursedefaults','usersessions');
1.150     raeburn   220:     if (keys(%servers) > 1) {
                    221:         push(@prefs_order,'loadbalancing');
                    222:     }
1.30      raeburn   223:     my %prefs = (
                    224:         'rolecolors' =>
                    225:                    { text => 'Default color schemes',
1.67      raeburn   226:                      help => 'Domain_Configuration_Color_Schemes',
1.30      raeburn   227:                      header => [{col1 => 'Student Settings',
                    228:                                  col2 => '',},
                    229:                                 {col1 => 'Coordinator Settings',
                    230:                                  col2 => '',},
                    231:                                 {col1 => 'Author Settings',
                    232:                                  col2 => '',},
                    233:                                 {col1 => 'Administrator Settings',
                    234:                                  col2 => '',}],
                    235:                     },
1.110     raeburn   236:         'login' =>
1.30      raeburn   237:                     { text => 'Log-in page options',
1.67      raeburn   238:                       help => 'Domain_Configuration_Login_Page',
1.30      raeburn   239:                       header => [{col1 => 'Item',
                    240:                                   col2 => '',}],
                    241:                     },
1.110     raeburn   242: 
1.43      raeburn   243:         'defaults' => 
1.141     raeburn   244:                     { text => 'Default authentication/language/timezone/portal',
1.67      raeburn   245:                       help => 'Domain_Configuration_LangTZAuth',
1.43      raeburn   246:                       header => [{col1 => 'Setting',
                    247:                                   col2 => 'Value'}],
                    248:                     },
1.30      raeburn   249:         'quotas' => 
1.133     raeburn   250:                     { text => 'User blogs, personal information pages, portfolios',
1.67      raeburn   251:                       help => 'Domain_Configuration_Quotas',
1.77      raeburn   252:                       header => [{col1 => 'User affiliation',
1.72      raeburn   253:                                   col2 => 'Available tools',
                    254:                                   col3 => 'Portfolio quota',}],
1.30      raeburn   255:                     },
                    256:         'autoenroll' =>
                    257:                    { text => 'Auto-enrollment settings',
1.67      raeburn   258:                      help => 'Domain_Configuration_Auto_Enrollment',
1.30      raeburn   259:                      header => [{col1 => 'Configuration setting',
                    260:                                  col2 => 'Value(s)'}],
                    261:                    },
                    262:         'autoupdate' => 
                    263:                    { text => 'Auto-update settings',
1.67      raeburn   264:                      help => 'Domain_Configuration_Auto_Updates',
1.30      raeburn   265:                      header => [{col1 => 'Setting',
                    266:                                  col2 => 'Value',},
1.131     raeburn   267:                                 {col1 => 'Setting',
                    268:                                  col2 => 'Affiliation'},
1.43      raeburn   269:                                 {col1 => 'User population',
1.131     raeburn   270:                                  col2 => 'Updateable user data'}],
1.30      raeburn   271:                   },
1.125     raeburn   272:         'autocreate' => 
                    273:                   { text => 'Auto-course creation settings',
                    274:                      help => 'Domain_Configuration_Auto_Creation',
                    275:                      header => [{col1 => 'Configuration Setting',
                    276:                                  col2 => 'Value',}],
                    277:                   },
1.30      raeburn   278:         'directorysrch' => 
                    279:                   { text => 'Institutional directory searches',
1.67      raeburn   280:                     help => 'Domain_Configuration_InstDirectory_Search',
1.30      raeburn   281:                     header => [{col1 => 'Setting',
                    282:                                 col2 => 'Value',}],
                    283:                   },
                    284:         'contacts' =>
                    285:                   { text => 'Contact Information',
1.67      raeburn   286:                     help => 'Domain_Configuration_Contact_Info',
1.30      raeburn   287:                     header => [{col1 => 'Setting',
                    288:                                 col2 => 'Value',}],
                    289:                   },
                    290: 
                    291:         'usercreation' => 
                    292:                   { text => 'User creation',
1.67      raeburn   293:                     help => 'Domain_Configuration_User_Creation',
1.43      raeburn   294:                     header => [{col1 => 'Format rule type',
                    295:                                 col2 => 'Format rules in force'},
1.34      raeburn   296:                                {col1 => 'User account creation',
                    297:                                 col2 => 'Usernames which may be created',},
1.30      raeburn   298:                                {col1 => 'Context',
1.43      raeburn   299:                                 col2 => 'Assignable authentication types'}],
1.30      raeburn   300:                   },
1.69      raeburn   301:         'usermodification' =>
1.33      raeburn   302:                   { text => 'User modification',
1.67      raeburn   303:                     help => 'Domain_Configuration_User_Modification',
1.33      raeburn   304:                     header => [{col1 => 'Target user has role',
                    305:                                 col2 => 'User information updateable in author context'},
                    306:                                {col1 => 'Target user has role',
1.63      raeburn   307:                                 col2 => 'User information updateable in course context'},
                    308:                                {col1 => "Status of user",
                    309:                                 col2 => 'Information settable when self-creating account (if directory data blank)'}],
1.33      raeburn   310:                   },
1.69      raeburn   311:         'scantron' =>
1.95      www       312:                   { text => 'Bubblesheet format file',
1.67      raeburn   313:                     help => 'Domain_Configuration_Scantron_Format',
1.46      raeburn   314:                     header => [ {col1 => 'Item',
                    315:                                  col2 => '',
                    316:                               }],
                    317:                   },
1.86      raeburn   318:         'requestcourses' => 
                    319:                  {text => 'Request creation of courses',
                    320:                   help => 'Domain_Configuration_Request_Courses',
                    321:                   header => [{col1 => 'User affiliation',
1.102     raeburn   322:                               col2 => 'Availability/Processing of requests',},
                    323:                              {col1 => 'Setting',
                    324:                               col2 => 'Value'}],
1.86      raeburn   325:                  },
1.69      raeburn   326:         'coursecategories' =>
1.120     raeburn   327:                   { text => 'Cataloging of courses/communities',
1.67      raeburn   328:                     help => 'Domain_Configuration_Cataloging_Courses',
1.69      raeburn   329:                     header => [{col1 => 'Category settings',
1.57      raeburn   330:                                 col2 => '',},
                    331:                                {col1 => 'Categories',
                    332:                                 col2 => '',
                    333:                                }],
1.69      raeburn   334:                   },
                    335:         'serverstatuses' =>
1.77      raeburn   336:                  {text   => 'Access to server status pages',
1.69      raeburn   337:                   help   => 'Domain_Configuration_Server_Status',
                    338:                   header => [{col1 => 'Status Page',
                    339:                               col2 => 'Other named users',
                    340:                               col3 => 'Specific IPs',
                    341:                             }],
                    342:                  },
1.118     jms       343:         'helpsettings' =>
                    344:                  {text   => 'Help page settings',
                    345:                   help   => 'Domain_Configuration_Help_Settings',
1.122     jms       346:                   header => [{col1 => 'Authenticated Help Settings',
                    347:                               col2 => ''},
                    348:                              {col1 => 'Unauthenticated Help Settings',
                    349:                               col2 => ''}],
1.118     jms       350:                  },
1.121     raeburn   351:         'coursedefaults' => 
                    352:                  {text => 'Course/Community defaults',
                    353:                   help => 'Domain_Configuration_Course_Defaults',
1.139     raeburn   354:                   header => [{col1 => 'Defaults which can be overridden in each course by a CC',
                    355:                               col2 => 'Value',},
                    356:                              {col1 => 'Defaults which can be overridden for each course by a DC',
                    357:                               col2 => 'Value',},],
1.121     raeburn   358:                  },
1.120     raeburn   359:         'privacy' => 
                    360:                  {text   => 'User Privacy',
                    361:                   help   => 'Domain_Configuration_User_Privacy',
                    362:                   header => [{col1 => 'Setting',
                    363:                               col2 => 'Value',}],
                    364:                  },
1.141     raeburn   365:         'usersessions' =>
1.145     raeburn   366:                  {text  => 'User session hosting/offloading',
1.137     raeburn   367:                   help  => 'Domain_Configuration_User_Sessions',
1.145     raeburn   368:                   header => [{col1 => 'Domain server',
                    369:                               col2 => 'Servers to offload sessions to when busy'},
                    370:                              {col1 => 'Hosting of users from other domains',
1.137     raeburn   371:                               col2 => 'Rules'},
                    372:                              {col1 => "Hosting domain's own users elsewhere",
                    373:                               col2 => 'Rules'}],
                    374:                  },
1.150     raeburn   375:          'loadbalancing' =>
                    376:                  {text  => 'Dedicated Load Balancer',
                    377:                   help  => 'Domain_Configuration_Load_Balancing',
                    378:                   header => [{col1 => 'Server',
                    379:                               col2 => 'Default destinations',
                    380:                               col3 => 'User affliation',
                    381:                               col4 => 'Overrides'},
                    382:                             ],
                    383:                  },
1.3       raeburn   384:     );
1.110     raeburn   385:     if (keys(%servers) > 1) {
                    386:         $prefs{'login'}  = { text   => 'Log-in page options',
                    387:                              help   => 'Domain_Configuration_Login_Page',
                    388:                             header => [{col1 => 'Log-in Service',
                    389:                                         col2 => 'Server Setting',},
                    390:                                        {col1 => 'Log-in Page Items',
                    391:                                         col2 => ''}],
                    392:                            };
                    393:     }
1.6       raeburn   394:     my @roles = ('student','coordinator','author','admin');
1.30      raeburn   395:     my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3       raeburn   396:     &Apache::lonhtmlcommon::add_breadcrumb
1.30      raeburn   397:     ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133     raeburn   398:       text=>"Settings to display/modify"});
1.9       raeburn   399:     my $confname = $dom.'-domainconfig';
1.3       raeburn   400:     if ($phase eq 'process') {
1.91      raeburn   401:         &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,\@roles);
1.30      raeburn   402:     } elsif ($phase eq 'display') {
1.152     raeburn   403:         my $js;
                    404:         if (keys(%servers) > 1) {
                    405:             my ($othertitle,$usertypes,$types) =
                    406:                 &Apache::loncommon::sorted_inst_types($dom);
                    407:             $js = &lonbalance_targets_js($dom,$types,\%servers).
                    408:                   &new_spares_js().
1.153     raeburn   409:                   &common_domprefs_js().
                    410:                   &Apache::loncommon::javascript_array_indexof();
1.152     raeburn   411:         }
1.150     raeburn   412:         &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1       raeburn   413:     } else {
1.21      raeburn   414:         if (keys(%domconfig) == 0) {
                    415:             my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29      raeburn   416:             my @ids=&Apache::lonnet::current_machine_ids();
                    417:             if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21      raeburn   418:                 my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41      raeburn   419:                 my @loginimages = ('img','logo','domlogo','login');
1.21      raeburn   420:                 my $custom_img_count = 0;
                    421:                 foreach my $img (@loginimages) {
                    422:                     if ($designhash{$dom.'.login.'.$img} ne '') {
                    423:                         $custom_img_count ++;
                    424:                     }
                    425:                 }
                    426:                 foreach my $role (@roles) {
                    427:                     if ($designhash{$dom.'.'.$role.'.img'} ne '') {
                    428:                         $custom_img_count ++;
                    429:                     }
                    430:                 }
                    431:                 if ($custom_img_count > 0) {
1.94      raeburn   432:                     &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21      raeburn   433:                     my $switch_server = &check_switchserver($dom,$confname);
1.29      raeburn   434:                     $r->print(
                    435:     &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
                    436:     &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
                    437:     &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 />'.
                    438:     &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
                    439:                     if ($switch_server) {
1.30      raeburn   440:                         $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29      raeburn   441:                     }
1.91      raeburn   442:                     $r->print(&Apache::loncommon::end_page());
1.21      raeburn   443:                     return OK;
                    444:                 }
                    445:             }
                    446:         }
1.91      raeburn   447:         &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3       raeburn   448:     }
                    449:     return OK;
                    450: }
                    451: 
                    452: sub process_changes {
1.92      raeburn   453:     my ($r,$dom,$confname,$action,$roles,$values) = @_;
                    454:     my %domconfig;
                    455:     if (ref($values) eq 'HASH') {
                    456:         %domconfig = %{$values};
                    457:     }
1.3       raeburn   458:     my $output;
                    459:     if ($action eq 'login') {
1.9       raeburn   460:         $output = &modify_login($r,$dom,$confname,%domconfig);
1.6       raeburn   461:     } elsif ($action eq 'rolecolors') {
1.9       raeburn   462:         $output = &modify_rolecolors($r,$dom,$confname,$roles,
                    463:                                      %domconfig);
1.3       raeburn   464:     } elsif ($action eq 'quotas') {
1.86      raeburn   465:         $output = &modify_quotas($dom,$action,%domconfig);
1.3       raeburn   466:     } elsif ($action eq 'autoenroll') {
                    467:         $output = &modify_autoenroll($dom,%domconfig);
                    468:     } elsif ($action eq 'autoupdate') {
                    469:         $output = &modify_autoupdate($dom,%domconfig);
1.125     raeburn   470:     } elsif ($action eq 'autocreate') {
                    471:         $output = &modify_autocreate($dom,%domconfig);
1.23      raeburn   472:     } elsif ($action eq 'directorysrch') {
                    473:         $output = &modify_directorysrch($dom,%domconfig);
1.27      raeburn   474:     } elsif ($action eq 'usercreation') {
1.28      raeburn   475:         $output = &modify_usercreation($dom,%domconfig);
1.33      raeburn   476:     } elsif ($action eq 'usermodification') {
                    477:         $output = &modify_usermodification($dom,%domconfig);
1.28      raeburn   478:     } elsif ($action eq 'contacts') {
                    479:         $output = &modify_contacts($dom,%domconfig);
1.43      raeburn   480:     } elsif ($action eq 'defaults') {
                    481:         $output = &modify_defaults($dom,$r);
1.46      raeburn   482:     } elsif ($action eq 'scantron') {
1.48      raeburn   483:         $output = &modify_scantron($r,$dom,$confname,%domconfig);
                    484:     } elsif ($action eq 'coursecategories') {
                    485:         $output = &modify_coursecategories($dom,%domconfig);
1.69      raeburn   486:     } elsif ($action eq 'serverstatuses') {
                    487:         $output = &modify_serverstatuses($dom,%domconfig);
1.86      raeburn   488:     } elsif ($action eq 'requestcourses') {
                    489:         $output = &modify_quotas($dom,$action,%domconfig);
1.118     jms       490:     } elsif ($action eq 'helpsettings') {
1.122     jms       491:         $output = &modify_helpsettings($r,$dom,$confname,%domconfig);
1.121     raeburn   492:     } elsif ($action eq 'coursedefaults') {
                    493:         $output = &modify_coursedefaults($dom,%domconfig);
1.137     raeburn   494:     } elsif ($action eq 'usersessions') {
                    495:         $output = &modify_usersessions($dom,%domconfig);
1.150     raeburn   496:     } elsif ($action eq 'loadbalancing') {
                    497:         $output = &modify_loadbalancing($dom,%domconfig);
1.3       raeburn   498:     }
                    499:     return $output;
                    500: }
                    501: 
                    502: sub print_config_box {
1.9       raeburn   503:     my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30      raeburn   504:     my $rowtotal = 0;
1.49      raeburn   505:     my $output;
                    506:     if ($action eq 'coursecategories') {
                    507:         $output = &coursecategories_javascript($settings);
1.91      raeburn   508:     }
1.49      raeburn   509:     $output .= 
1.30      raeburn   510:          '<table class="LC_nested_outer">
1.3       raeburn   511:           <tr>
1.66      raeburn   512:            <th align="left" valign="middle"><span class="LC_nobreak">'.
                    513:            &mt($item->{text}).'&nbsp;'.
                    514:            &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
                    515:           '</tr>';
1.30      raeburn   516:     $rowtotal ++;
1.110     raeburn   517:     my $numheaders = 1;
                    518:     if (ref($item->{'header'}) eq 'ARRAY') {
                    519:         $numheaders = scalar(@{$item->{'header'}});
                    520:     }
                    521:     if ($numheaders > 1) {
1.64      raeburn   522:         my $colspan = '';
1.145     raeburn   523:         my $rightcolspan = '';
1.122     jms       524:         if (($action eq 'rolecolors') || ($action eq 'coursecategories') || ($action eq 'helpsettings')) {
1.64      raeburn   525:             $colspan = ' colspan="2"';
                    526:         }
1.145     raeburn   527:         if ($action eq 'usersessions') {
                    528:             $rightcolspan = ' colspan="3"'; 
                    529:         }
1.30      raeburn   530:         $output .= '
1.3       raeburn   531:           <tr>
                    532:            <td>
                    533:             <table class="LC_nested">
                    534:              <tr class="LC_info_row">
1.59      bisitz    535:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145     raeburn   536:               <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30      raeburn   537:              </tr>';
1.69      raeburn   538:         $rowtotal ++;
1.6       raeburn   539:         if ($action eq 'autoupdate') {
1.30      raeburn   540:             $output .= &print_autoupdate('top',$dom,$settings,\$rowtotal);
1.28      raeburn   541:         } elsif ($action eq 'usercreation') {
1.33      raeburn   542:             $output .= &print_usercreation('top',$dom,$settings,\$rowtotal);
                    543:         } elsif ($action eq 'usermodification') {
                    544:             $output .= &print_usermodification('top',$dom,$settings,\$rowtotal);
1.57      raeburn   545:         } elsif ($action eq 'coursecategories') {
                    546:             $output .= &print_coursecategories('top',$dom,$item,$settings,\$rowtotal);
1.110     raeburn   547:         } elsif ($action eq 'login') {
                    548:             $output .= &print_login('top',$dom,$confname,$phase,$settings,\$rowtotal);
                    549:             $colspan = ' colspan="2"';
1.102     raeburn   550:         } elsif ($action eq 'requestcourses') {
                    551:             $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.118     jms       552:         } elsif ($action eq 'helpsettings') {
1.122     jms       553:             $output .= &print_helpsettings('top',$dom,$confname,$settings,\$rowtotal);
1.137     raeburn   554:         } elsif ($action eq 'usersessions') {
                    555:             $output .= &print_usersessions('top',$dom,$settings,\$rowtotal); 
1.122     jms       556:         } elsif ($action eq 'rolecolors') {
1.30      raeburn   557:             $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.139     raeburn   558:         } elsif ($action eq 'coursedefaults') {
                    559:             $output .= &print_coursedefaults('top',$dom,$settings,\$rowtotal);
1.6       raeburn   560:         }
1.30      raeburn   561:         $output .= '
1.6       raeburn   562:            </table>
                    563:           </td>
                    564:          </tr>
                    565:          <tr>
                    566:            <td>
                    567:             <table class="LC_nested">
                    568:              <tr class="LC_info_row">
1.59      bisitz    569:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>';
1.57      raeburn   570:         $output .= '
1.59      bisitz    571:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30      raeburn   572:              </tr>';
                    573:             $rowtotal ++;
1.6       raeburn   574:         if ($action eq 'autoupdate') {
1.131     raeburn   575:             $output .= &print_autoupdate('middle',$dom,$settings,\$rowtotal).'
                    576:            </table>
                    577:           </td>
                    578:          </tr>
                    579:          <tr>
                    580:            <td>
                    581:             <table class="LC_nested">
                    582:              <tr class="LC_info_row">
                    583:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
                    584:               <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>      </tr>'.
                    585:             &print_autoupdate('bottom',$dom,$settings,\$rowtotal);
                    586:             $rowtotal ++;
1.28      raeburn   587:         } elsif ($action eq 'usercreation') {
1.34      raeburn   588:             $output .= &print_usercreation('middle',$dom,$settings,\$rowtotal).'
                    589:            </table>
                    590:           </td>
                    591:          </tr>
                    592:          <tr>
                    593:            <td>
                    594:             <table class="LC_nested">
                    595:              <tr class="LC_info_row">
1.59      bisitz    596:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
                    597:               <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>             </tr>'.
1.34      raeburn   598:             &print_usercreation('bottom',$dom,$settings,\$rowtotal);
                    599:             $rowtotal ++;
1.33      raeburn   600:         } elsif ($action eq 'usermodification') {
1.63      raeburn   601:             $output .= &print_usermodification('middle',$dom,$settings,\$rowtotal).'
                    602:            </table>
                    603:           </td>
                    604:          </tr>
                    605:          <tr>
                    606:            <td>
                    607:             <table class="LC_nested">
                    608:              <tr class="LC_info_row">
                    609:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
                    610:               <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>      </tr>'.
                    611:                        &print_usermodification('bottom',$dom,$settings,\$rowtotal);
                    612:             $rowtotal ++;
1.57      raeburn   613:         } elsif ($action eq 'coursecategories') {
                    614:             $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.110     raeburn   615:         } elsif ($action eq 'login') {
                    616:             $output .= &print_login('bottom',$dom,$confname,$phase,$settings,\$rowtotal);
1.102     raeburn   617:         } elsif ($action eq 'requestcourses') {
                    618:             $output .= &print_courserequestmail($dom,$settings,\$rowtotal);
1.122     jms       619:         } elsif ($action eq 'helpsettings') {
                    620:             $output .= &print_helpsettings('bottom',$dom,$confname,$settings,\$rowtotal);
1.137     raeburn   621:         } elsif ($action eq 'usersessions') {
1.145     raeburn   622:             $output .= &print_usersessions('middle',$dom,$settings,\$rowtotal).'
                    623:            </table>
                    624:           </td>
                    625:          </tr>
                    626:          <tr>
                    627:            <td>
                    628:             <table class="LC_nested">
                    629:              <tr class="LC_info_row">
                    630:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
                    631:               <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>      </tr>'.
                    632:                        &print_usersessions('bottom',$dom,$settings,\$rowtotal);
                    633:             $rowtotal ++;
1.139     raeburn   634:         } elsif ($action eq 'coursedefaults') {
                    635:             $output .= &print_coursedefaults('bottom',$dom,$settings,\$rowtotal);
1.122     jms       636:         } elsif ($action eq 'rolecolors') {
1.30      raeburn   637:             $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6       raeburn   638:            </table>
                    639:           </td>
                    640:          </tr>
                    641:          <tr>
                    642:            <td>
                    643:             <table class="LC_nested">
                    644:              <tr class="LC_info_row">
1.69      raeburn   645:               <td class="LC_left_item"'.$colspan.' valign="top">'.
                    646:                &mt($item->{'header'}->[2]->{'col1'}).'</td>
                    647:               <td class="LC_right_item" valign="top">'.
                    648:                &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3       raeburn   649:              </tr>'.
1.30      raeburn   650:             &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3       raeburn   651:            </table>
                    652:           </td>
                    653:          </tr>
                    654:          <tr>
                    655:            <td>
                    656:             <table class="LC_nested">
                    657:              <tr class="LC_info_row">
1.59      bisitz    658:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
                    659:               <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3       raeburn   660:              </tr>'.
1.30      raeburn   661:             &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
                    662:             $rowtotal += 2;
1.6       raeburn   663:         }
1.3       raeburn   664:     } else {
1.30      raeburn   665:         $output .= '
1.3       raeburn   666:           <tr>
                    667:            <td>
                    668:             <table class="LC_nested">
1.30      raeburn   669:              <tr class="LC_info_row">';
1.24      raeburn   670:         if (($action eq 'login') || ($action eq 'directorysrch')) {
1.30      raeburn   671:             $output .= '  
1.59      bisitz    672:               <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69      raeburn   673:         } elsif ($action eq 'serverstatuses') {
                    674:             $output .= '
                    675:               <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
                    676:               '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
                    677: 
1.6       raeburn   678:         } else {
1.30      raeburn   679:             $output .= '
1.69      raeburn   680:               <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
                    681:         }
1.72      raeburn   682:         if (defined($item->{'header'}->[0]->{'col3'})) {
                    683:             $output .= '<td class="LC_left_item" valign="top">'.
                    684:                        &mt($item->{'header'}->[0]->{'col2'});
                    685:             if ($action eq 'serverstatuses') {
                    686:                 $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
                    687:             } 
1.69      raeburn   688:         } else {
                    689:             $output .= '<td class="LC_right_item" valign="top">'.
                    690:                        &mt($item->{'header'}->[0]->{'col2'});
                    691:         }
                    692:         $output .= '</td>';
                    693:         if ($item->{'header'}->[0]->{'col3'}) {
1.150     raeburn   694:             if (defined($item->{'header'}->[0]->{'col4'})) {
                    695:                 $output .= '<td class="LC_left_item" valign="top">'.
                    696:                             &mt($item->{'header'}->[0]->{'col3'});
                    697:             } else {
                    698:                 $output .= '<td class="LC_right_item" valign="top">'.
                    699:                            &mt($item->{'header'}->[0]->{'col3'});
                    700:             }
1.69      raeburn   701:             if ($action eq 'serverstatuses') {
                    702:                 $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
                    703:             }
                    704:             $output .= '</td>';
1.6       raeburn   705:         }
1.150     raeburn   706:         if ($item->{'header'}->[0]->{'col4'}) {
                    707:             $output .= '<td class="LC_right_item" valign="top">'.
                    708:                        &mt($item->{'header'}->[0]->{'col4'});
                    709:         }
1.69      raeburn   710:         $output .= '</tr>';
1.48      raeburn   711:         $rowtotal ++;
1.3       raeburn   712:         if ($action eq 'login') {
1.110     raeburn   713:             $output .= &print_login('bottom',$dom,$confname,$phase,$settings,
                    714:                                     \$rowtotal);
1.3       raeburn   715:         } elsif ($action eq 'quotas') {
1.86      raeburn   716:             $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.3       raeburn   717:         } elsif ($action eq 'autoenroll') {
1.30      raeburn   718:             $output .= &print_autoenroll($dom,$settings,\$rowtotal);
1.125     raeburn   719:         } elsif ($action eq 'autocreate') {
                    720:             $output .= &print_autocreate($dom,$settings,\$rowtotal);
1.23      raeburn   721:         } elsif ($action eq 'directorysrch') {
1.30      raeburn   722:             $output .= &print_directorysrch($dom,$settings,\$rowtotal);
1.28      raeburn   723:         } elsif ($action eq 'contacts') {
1.30      raeburn   724:             $output .= &print_contacts($dom,$settings,\$rowtotal);
1.43      raeburn   725:         } elsif ($action eq 'defaults') {
                    726:             $output .= &print_defaults($dom,\$rowtotal);
1.46      raeburn   727:         } elsif ($action eq 'scantron') {
                    728:             $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
1.69      raeburn   729:         } elsif ($action eq 'serverstatuses') {
                    730:             $output .= &print_serverstatuses($dom,$settings,\$rowtotal);
1.118     jms       731:         } elsif ($action eq 'helpsettings') {
1.122     jms       732:             $output .= &print_helpsettings('top',$dom,$confname,$settings,\$rowtotal);
1.150     raeburn   733:         } elsif ($action eq 'loadbalancing') {
                    734:             $output .= &print_loadbalancing($dom,$settings,\$rowtotal);
1.121     raeburn   735:         }
1.3       raeburn   736:     }
1.30      raeburn   737:     $output .= '
1.3       raeburn   738:    </table>
                    739:   </td>
                    740:  </tr>
1.30      raeburn   741: </table><br />';
                    742:     return ($output,$rowtotal);
1.1       raeburn   743: }
                    744: 
1.3       raeburn   745: sub print_login {
1.110     raeburn   746:     my ($position,$dom,$confname,$phase,$settings,$rowtotal) = @_;
                    747:     my ($css_class,$datatable);
1.6       raeburn   748:     my %choices = &login_choices();
1.110     raeburn   749: 
                    750:     if ($position eq 'top') {
1.149     raeburn   751:         my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110     raeburn   752:         my $choice = $choices{'disallowlogin'};
                    753:         $css_class = ' class="LC_odd_row"';
1.128     raeburn   754:         $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110     raeburn   755:                       '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128     raeburn   756:                       '<th>'.$choices{'server'}.'</th>'.
                    757:                       '<th>'.$choices{'serverpath'}.'</th>'.
                    758:                       '<th>'.$choices{'custompath'}.'</th>'.
                    759:                       '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110     raeburn   760:         my %disallowed;
                    761:         if (ref($settings) eq 'HASH') {
                    762:             if (ref($settings->{'loginvia'}) eq 'HASH') {
                    763:                %disallowed = %{$settings->{'loginvia'}};
                    764:             }
                    765:         }
                    766:         foreach my $lonhost (sort(keys(%servers))) {
                    767:             my $direct = 'selected="selected"';
1.128     raeburn   768:             if (ref($disallowed{$lonhost}) eq 'HASH') {
                    769:                 if ($disallowed{$lonhost}{'server'} ne '') {
                    770:                     $direct = '';
                    771:                 }
1.110     raeburn   772:             }
1.115     raeburn   773:             $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128     raeburn   774:                           '<td><select name="'.$lonhost.'_server">'.
1.110     raeburn   775:                           '<option value=""'.$direct.'>'.$choices{'directlogin'}.
                    776:                           '</option>';
                    777:             foreach my $hostid (keys(%servers)) {
1.115     raeburn   778:                 next if ($servers{$hostid} eq $servers{$lonhost});
1.110     raeburn   779:                 my $selected = '';
1.128     raeburn   780:                 if (ref($disallowed{$lonhost}) eq 'HASH') {
                    781:                     if ($hostid eq $disallowed{$lonhost}{'server'}) {
                    782:                         $selected = 'selected="selected"';
                    783:                     }
1.110     raeburn   784:                 }
                    785:                 $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
                    786:                               $servers{$hostid}.'</option>';
                    787:             }
1.128     raeburn   788:             $datatable .= '</select></td>'.
                    789:                           '<td><select name="'.$lonhost.'_serverpath">';
                    790:             foreach my $path ('','/','/adm/login','/adm/roles','custom') {
                    791:                 my $pathname = $path;
                    792:                 if ($path eq 'custom') {
                    793:                     $pathname = &mt('Custom Path').' ->';
                    794:                 }
                    795:                 my $selected = '';
                    796:                 if (ref($disallowed{$lonhost}) eq 'HASH') {
                    797:                     if ($path eq $disallowed{$lonhost}{'serverpath'}) {
                    798:                         $selected = 'selected="selected"';
                    799:                     }
                    800:                 } elsif ($path eq '') {
                    801:                     $selected = 'selected="selected"';
                    802:                 }
                    803:                 $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
                    804:             }
                    805:             $datatable .= '</select></td>';
                    806:             my ($custom,$exempt);
                    807:             if (ref($disallowed{$lonhost}) eq 'HASH') {
                    808:                 $custom = $disallowed{$lonhost}{'custompath'};
                    809:                 $exempt = $disallowed{$lonhost}{'exempt'};
                    810:             }
                    811:             $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
                    812:                           '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
                    813:                           '</tr>';
1.110     raeburn   814:         }
                    815:         $datatable .= '</table></td></tr>';
                    816:         return $datatable;
                    817:     }
                    818: 
1.42      raeburn   819:     my %defaultchecked = ( 
1.43      raeburn   820:                            'coursecatalog' => 'on',
                    821:                            'adminmail'     => 'off',
                    822:                            'newuser'       => 'off',
                    823:                          );
1.118     jms       824:     my @toggles = ('coursecatalog','adminmail','newuser');
1.42      raeburn   825:     my (%checkedon,%checkedoff);
                    826:     foreach my $item (@toggles) {
                    827:         if ($defaultchecked{$item} eq 'on') { 
                    828:             $checkedon{$item} = ' checked="checked" ';
                    829:             $checkedoff{$item} = ' ';
                    830:         } elsif ($defaultchecked{$item} eq 'off') {
                    831:             $checkedoff{$item} = ' checked="checked" ';
                    832:             $checkedon{$item} = ' ';
                    833:         }
                    834:     }
1.41      raeburn   835:     my @images = ('img','logo','domlogo','login');
                    836:     my @logintext = ('textcol','bgcol');
1.6       raeburn   837:     my @bgs = ('pgbg','mainbg','sidebg');
                    838:     my @links = ('link','alink','vlink');
1.7       albertel  839:     my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6       raeburn   840:     my %defaultdesign = %Apache::loncommon::defaultdesign;
                    841:     my (%is_custom,%designs);
                    842:     my %defaults = (
                    843:                    font => $defaultdesign{'login.font'},
                    844:                    );
                    845:     foreach my $item (@images) {
                    846:         $defaults{$item} = $defaultdesign{'login.'.$item};
1.70      raeburn   847:         $defaults{'showlogo'}{$item} = 1;
1.6       raeburn   848:     }
                    849:     foreach my $item (@bgs) {
                    850:         $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
                    851:     }
1.41      raeburn   852:     foreach my $item (@logintext) {
                    853:         $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
                    854:     }
1.6       raeburn   855:     foreach my $item (@links) {
                    856:         $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
                    857:     }
1.3       raeburn   858:     if (ref($settings) eq 'HASH') {
1.42      raeburn   859:         foreach my $item (@toggles) {
                    860:             if ($settings->{$item} eq '1') {
                    861:                 $checkedon{$item} =  ' checked="checked" ';
                    862:                 $checkedoff{$item} = ' ';
                    863:             } elsif ($settings->{$item} eq '0') {
                    864:                 $checkedoff{$item} =  ' checked="checked" ';
                    865:                 $checkedon{$item} = ' ';
                    866:             }
1.1       raeburn   867:         }
1.6       raeburn   868:         foreach my $item (@images) {
1.70      raeburn   869:             if (defined($settings->{$item})) {
1.6       raeburn   870:                 $designs{$item} = $settings->{$item};
                    871:                 $is_custom{$item} = 1;
                    872:             }
1.70      raeburn   873:             if (defined($settings->{'showlogo'}{$item})) {
                    874:                 $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
                    875:             }
1.6       raeburn   876:         }
1.41      raeburn   877:         foreach my $item (@logintext) {
                    878:             if ($settings->{$item} ne '') {
                    879:                 $designs{'logintext'}{$item} = $settings->{$item};
                    880:                 $is_custom{$item} = 1;
                    881:             }
                    882:         }
1.6       raeburn   883:         if ($settings->{'font'} ne '') {
                    884:             $designs{'font'} = $settings->{'font'};
                    885:             $is_custom{'font'} = 1;
                    886:         }
                    887:         foreach my $item (@bgs) {
                    888:             if ($settings->{$item} ne '') {
                    889:                 $designs{'bgs'}{$item} = $settings->{$item};
                    890:                 $is_custom{$item} = 1;
                    891:             }
                    892:         }
                    893:         foreach my $item (@links) {
                    894:             if ($settings->{$item} ne '') {
                    895:                 $designs{'links'}{$item} = $settings->{$item};
                    896:                 $is_custom{$item} = 1;
                    897:             }
                    898:         }
                    899:     } else {
                    900:         if ($designhash{$dom.'.login.font'} ne '') {
                    901:             $designs{'font'} = $designhash{$dom.'.login.font'};
                    902:             $is_custom{'font'} = 1;
                    903:         }
1.8       raeburn   904:         foreach my $item (@images) {
                    905:             if ($designhash{$dom.'.login.'.$item} ne '') {
                    906:                 $designs{$item} = $designhash{$dom.'.login.'.$item};
                    907:                 $is_custom{$item} = 1;
                    908:             }
                    909:         }
1.6       raeburn   910:         foreach my $item (@bgs) {
                    911:             if ($designhash{$dom.'.login.'.$item} ne '') {
                    912:                 $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
                    913:                 $is_custom{$item} = 1;
                    914:             }
                    915:         }
                    916:         foreach my $item (@links) {
                    917:             if ($designhash{$dom.'.login.'.$item} ne '') {
                    918:                 $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
                    919:                 $is_custom{$item} = 1;
                    920:             }
                    921:         }
1.1       raeburn   922:     }
1.6       raeburn   923:     my %alt_text = &Apache::lonlocal::texthash  ( img => 'Log-in banner',
                    924:                                                   logo => 'Institution Logo',
1.41      raeburn   925:                                                   domlogo => 'Domain Logo',
                    926:                                                   login => 'Login box');
1.6       raeburn   927:     my $itemcount = 1;
1.42      raeburn   928:     foreach my $item (@toggles) {
                    929:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                    930:         $datatable .=  
                    931:             '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
                    932:             '</td><td>'.
                    933:             '<span class="LC_nobreak"><label><input type="radio" name="'.
                    934:             $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
                    935:             '</label>&nbsp;<label><input type="radio" name="'.$item.'"'.
                    936:             $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
                    937:             '</tr>';
                    938:         $itemcount ++;
                    939:     }
1.135     bisitz    940:     $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1.6       raeburn   941:     $datatable .= '</tr></table></td></tr>';
                    942:     return $datatable;
                    943: }
                    944: 
                    945: sub login_choices {
                    946:     my %choices =
                    947:         &Apache::lonlocal::texthash (
1.116     bisitz    948:             coursecatalog => 'Display Course/Community Catalog link?',
1.110     raeburn   949:             adminmail     => "Display Administrator's E-mail Address?",
                    950:             disallowlogin => "Login page requests redirected",
                    951:             hostid        => "Server",
1.128     raeburn   952:             server        => "Redirect to:",
                    953:             serverpath    => "Path",
                    954:             custompath    => "Custom", 
                    955:             exempt        => "Exempt IP(s)",
1.110     raeburn   956:             directlogin   => "No redirect",
                    957:             newuser       => "Link to create a user account",
                    958:             img           => "Header",
                    959:             logo          => "Main Logo",
                    960:             domlogo       => "Domain Logo",
                    961:             login         => "Log-in Header", 
                    962:             textcol       => "Text color",
                    963:             bgcol         => "Box color",
                    964:             bgs           => "Background colors",
                    965:             links         => "Link colors",
                    966:             font          => "Font color",
                    967:             pgbg          => "Header",
                    968:             mainbg        => "Page",
                    969:             sidebg        => "Login box",
                    970:             link          => "Link",
                    971:             alink         => "Active link",
                    972:             vlink         => "Visited link",
1.6       raeburn   973:         );
                    974:     return %choices;
                    975: }
                    976: 
                    977: sub print_rolecolors {
1.30      raeburn   978:     my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6       raeburn   979:     my %choices = &color_font_choices();
                    980:     my @bgs = ('pgbg','tabbg','sidebg');
                    981:     my @links = ('link','alink','vlink');
                    982:     my @images = ('img');
                    983:     my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7       albertel  984:     my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6       raeburn   985:     my %defaultdesign = %Apache::loncommon::defaultdesign;
                    986:     my (%is_custom,%designs);
                    987:     my %defaults = (
                    988:                    img => $defaultdesign{$role.'.img'},
                    989:                    font => $defaultdesign{$role.'.font'},
1.97      tempelho  990: 		   fontmenu => $defaultdesign{$role.'.fontmenu'},
1.6       raeburn   991:                    );
                    992:     foreach my $item (@bgs) {
                    993:         $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
                    994:     }
                    995:     foreach my $item (@links) {
                    996:         $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
                    997:     }
                    998:     if (ref($settings) eq 'HASH') {
                    999:         if (ref($settings->{$role}) eq 'HASH') {
                   1000:             if ($settings->{$role}->{'img'} ne '') {
                   1001:                 $designs{'img'} = $settings->{$role}->{'img'};
                   1002:                 $is_custom{'img'} = 1;
                   1003:             }
                   1004:             if ($settings->{$role}->{'font'} ne '') {
                   1005:                 $designs{'font'} = $settings->{$role}->{'font'};
                   1006:                 $is_custom{'font'} = 1;
                   1007:             }
1.97      tempelho 1008:             if ($settings->{$role}->{'fontmenu'} ne '') {
                   1009:                 $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
                   1010:                 $is_custom{'fontmenu'} = 1;
                   1011:             }
1.6       raeburn  1012:             foreach my $item (@bgs) {
                   1013:                 if ($settings->{$role}->{$item} ne '') {
                   1014:                     $designs{'bgs'}{$item} = $settings->{$role}->{$item};
                   1015:                     $is_custom{$item} = 1;
                   1016:                 }
                   1017:             }
                   1018:             foreach my $item (@links) {
                   1019:                 if ($settings->{$role}->{$item} ne '') {
                   1020:                     $designs{'links'}{$item} = $settings->{$role}->{$item};
                   1021:                     $is_custom{$item} = 1;
                   1022:                 }
                   1023:             }
                   1024:         }
                   1025:     } else {
                   1026:         if ($designhash{$dom.'.'.$role.'.img'} ne '') {
                   1027:             $designs{img} = $designhash{$dom.'.'.$role.'.img'};
                   1028:             $is_custom{'img'} = 1;
                   1029:         }
1.97      tempelho 1030:         if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
                   1031:             $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
                   1032:             $is_custom{'fontmenu'} = 1; 
                   1033:         }
1.6       raeburn  1034:         if ($designhash{$dom.'.'.$role.'.font'} ne '') {
                   1035:             $designs{font} = $designhash{$dom.'.'.$role.'.font'};
                   1036:             $is_custom{'font'} = 1;
                   1037:         }
                   1038:         foreach my $item (@bgs) {
                   1039:             if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
                   1040:                 $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
                   1041:                 $is_custom{$item} = 1;
                   1042:             
                   1043:             }
                   1044:         }
                   1045:         foreach my $item (@links) {
                   1046:             if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
                   1047:                 $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
                   1048:                 $is_custom{$item} = 1;
                   1049:             }
                   1050:         }
                   1051:     }
                   1052:     my $itemcount = 1;
1.30      raeburn  1053:     my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6       raeburn  1054:     $datatable .= '</tr></table></td></tr>';
                   1055:     return $datatable;
                   1056: }
                   1057: 
                   1058: sub display_color_options {
1.9       raeburn  1059:     my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135     bisitz   1060:         $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.6       raeburn  1061:     my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.134     raeburn  1062:     my $datatable = '<tr'.$css_class.'>'.
1.6       raeburn  1063:         '<td>'.$choices->{'font'}.'</td>';
                   1064:     if (!$is_custom->{'font'}) {
1.30      raeburn  1065:         $datatable .=  '<td>'.&mt('Default in use:').'&nbsp;<span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6       raeburn  1066:     } else {
                   1067:         $datatable .= '<td>&nbsp;</td>';
                   1068:     }
                   1069:     my $fontlink = &color_pick($phase,$role,'font',$choices->{'font'},$designs->{'font'});
1.8       raeburn  1070:     $datatable .= '<td><span class="LC_nobreak">'.
1.6       raeburn  1071:                   '<input type="text" size="10" name="'.$role.'_font"'.
1.8       raeburn  1072:                   ' value="'.$designs->{'font'}.'" />&nbsp;'.$fontlink.
1.30      raeburn  1073:                   '&nbsp;<span id="css_'.$role.'_font" style="background-color: '.
                   1074:                   $designs->{'font'}.';">&nbsp;&nbsp;&nbsp;</span>'.
1.8       raeburn  1075:                   '</span></td></tr>';
1.107     raeburn  1076:     unless ($role eq 'login') { 
                   1077:         $datatable .= '<tr'.$css_class.'>'.
                   1078:                       '<td>'.$choices->{'fontmenu'}.'</td>';
                   1079:         if (!$is_custom->{'fontmenu'}) {
                   1080:             $datatable .=  '<td>'.&mt('Default in use:').'&nbsp;<span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
                   1081:         } else {
                   1082:             $datatable .= '<td>&nbsp;</td>';
                   1083:         }
                   1084:         $fontlink = &color_pick($phase,$role,'fontmenu',$choices->{'fontmenu'},$designs->{'fontmenu'});
                   1085:         $datatable .= '<td><span class="LC_nobreak">'.
                   1086:                       '<input type="text" size="10" name="'.$role.'_fontmenu"'.
                   1087:                       ' value="'.$designs->{'fontmenu'}.'" />&nbsp;'.$fontlink.
                   1088:                       '&nbsp;<span id="css_'.$role.'_fontmenu" style="background-color: '.
                   1089:                       $designs->{'fontmenu'}.';">&nbsp;&nbsp;&nbsp;</span>'.
                   1090:                       '</span></td></tr>';
1.97      tempelho 1091:     }
1.9       raeburn  1092:     my $switchserver = &check_switchserver($dom,$confname);
1.6       raeburn  1093:     foreach my $img (@{$images}) {
1.18      albertel 1094: 	$itemcount ++;
1.6       raeburn  1095:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8       raeburn  1096:         $datatable .= '<tr'.$css_class.'>'.
1.70      raeburn  1097:                       '<td>'.$choices->{$img};
1.41      raeburn  1098:         my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70      raeburn  1099:         if ($role eq 'login') {
                   1100:             if ($img eq 'login') {
                   1101:                 $login_hdr_pick =
1.135     bisitz   1102:                     &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70      raeburn  1103:                 $logincolors =
                   1104:                     &login_text_colors($img,$role,$logintext,$phase,$choices,
                   1105:                                             $designs);
                   1106:             } elsif ($img ne 'domlogo') {
                   1107:                 $datatable.= &logo_display_options($img,$defaults,$designs);
                   1108:             }
                   1109:         }
                   1110:         $datatable .= '</td>';
1.6       raeburn  1111:         if ($designs->{$img} ne '') {
                   1112:             $imgfile = $designs->{$img};
1.18      albertel 1113: 	    $img_import = ($imgfile =~ m{^/adm/});
1.6       raeburn  1114:         } else {
                   1115:             $imgfile = $defaults->{$img};
                   1116:         }
                   1117:         if ($imgfile) {
1.9       raeburn  1118:             my ($showfile,$fullsize);
                   1119:             if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6       raeburn  1120:                 my $urldir = $1;
                   1121:                 my $filename = $2;
                   1122:                 my @info = &Apache::lonnet::stat_file($designs->{$img});
                   1123:                 if (@info) {
                   1124:                     my $thumbfile = 'tn-'.$filename;
                   1125:                     my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
                   1126:                     if (@thumb) {
                   1127:                         $showfile = $urldir.'/'.$thumbfile;
                   1128:                     } else {
                   1129:                         $showfile = $imgfile;
                   1130:                     }
                   1131:                 } else {
                   1132:                     $showfile = '';
                   1133:                 }
                   1134:             } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16      raeburn  1135:                 $showfile = $imgfile;
1.6       raeburn  1136:                 my $imgdir = $1;
                   1137:                 my $filename = $2;
                   1138:                 if (-e "/home/httpd/html/$imgdir/tn-".$filename) {
                   1139:                     $showfile = "/$imgdir/tn-".$filename;
                   1140:                 } else {
                   1141:                     my $input = "/home/httpd/html".$imgfile;
                   1142:                     my $output = '/home/httpd/html/'.$imgdir.'/tn-'.$filename;
                   1143:                     if (!-e $output) {
1.9       raeburn  1144:                         my ($width,$height) = &thumb_dimensions();
1.16      raeburn  1145:                         my ($fullwidth,$fullheight) = &check_dimensions($input);
                   1146:                         if ($fullwidth ne '' && $fullheight ne '') {
                   1147:                             if ($fullwidth > $width && $fullheight > $height) { 
                   1148:                                 my $size = $width.'x'.$height;
                   1149:                                 system("convert -sample $size $input $output");
                   1150:                                 $showfile = '/'.$imgdir.'/tn-'.$filename;
                   1151:                             }
                   1152:                         }
1.6       raeburn  1153:                     }
                   1154:                 }
1.16      raeburn  1155:             }
1.6       raeburn  1156:             if ($showfile) {
1.40      raeburn  1157:                 if ($showfile =~ m{^/(adm|res)/}) {
                   1158:                     if ($showfile =~ m{^/res/}) {
                   1159:                         my $local_showfile =
                   1160:                             &Apache::lonnet::filelocation('',$showfile);
                   1161:                         &Apache::lonnet::repcopy($local_showfile);
                   1162:                     }
                   1163:                     $showfile = &Apache::loncommon::lonhttpdurl($showfile);
                   1164:                 }
                   1165:                 if ($imgfile) {
                   1166:                     if ($imgfile  =~ m{^/(adm|res)/}) {
                   1167:                         if ($imgfile =~ m{^/res/}) {
                   1168:                             my $local_imgfile =
                   1169:                                 &Apache::lonnet::filelocation('',$imgfile);
                   1170:                             &Apache::lonnet::repcopy($local_imgfile);
                   1171:                         }
                   1172:                         $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
                   1173:                     } else {
                   1174:                         $fullsize = $imgfile;
                   1175:                     }
                   1176:                 }
1.41      raeburn  1177:                 $datatable .= '<td>';
                   1178:                 if ($img eq 'login') {
1.135     bisitz   1179:                     $datatable .= $login_hdr_pick;
                   1180:                 } 
1.41      raeburn  1181:                 $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
                   1182:                                              $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6       raeburn  1183:             } else {
                   1184:                 $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
                   1185:                               &mt('Upload:');
                   1186:             }
                   1187:         } else {
                   1188:             $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
                   1189:                           &mt('Upload:');
                   1190:         }
1.9       raeburn  1191:         if ($switchserver) {
                   1192:             $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   1193:         } else {
1.135     bisitz   1194:             if ($img ne 'login') { # suppress file selection for Log-in header
                   1195:                 $datatable .='&nbsp;<input type="file" name="'.$role.'_'.$img.'" />';
                   1196:             }
1.9       raeburn  1197:         }
                   1198:         $datatable .= '</td></tr>';
1.6       raeburn  1199:     }
                   1200:     $itemcount ++;
                   1201:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   1202:     $datatable .= '<tr'.$css_class.'>'.
                   1203:                   '<td>'.$choices->{'bgs'}.'</td>';
                   1204:     my $bgs_def;
                   1205:     foreach my $item (@{$bgs}) {
                   1206:         if (!$is_custom->{$item}) {
1.70      raeburn  1207:             $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  1208:         }
                   1209:     }
                   1210:     if ($bgs_def) {
1.8       raeburn  1211:         $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6       raeburn  1212:     } else {
                   1213:         $datatable .= '<td>&nbsp;</td>';
                   1214:     }
                   1215:     $datatable .= '<td class="LC_right_item">'.
                   1216:                   '<table border="0"><tr>';
                   1217:     foreach my $item (@{$bgs}) {
                   1218:         my $link = &color_pick($phase,$role,$item,$choices->{$item},$designs->{'bgs'}{$item});
                   1219:         $datatable .= '<td align="center">'.$link;
                   1220:         if ($designs->{'bgs'}{$item}) {
1.30      raeburn  1221:             $datatable .= '&nbsp;<span id="css_'.$role.'_'.$item.'" style="background-color: '.$designs->{'bgs'}{$item}.';">&nbsp;&nbsp;&nbsp;</span>';
1.6       raeburn  1222:         }
                   1223:         $datatable .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.$designs->{'bgs'}{$item}.
1.41      raeburn  1224:                       '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6       raeburn  1225:     }
                   1226:     $datatable .= '</tr></table></td></tr>';
                   1227:     $itemcount ++;
                   1228:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   1229:     $datatable .= '<tr'.$css_class.'>'.
                   1230:                   '<td>'.$choices->{'links'}.'</td>';
                   1231:     my $links_def;
                   1232:     foreach my $item (@{$links}) {
                   1233:         if (!$is_custom->{$item}) {
1.30      raeburn  1234:             $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  1235:         }
                   1236:     }
                   1237:     if ($links_def) {
1.8       raeburn  1238:         $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6       raeburn  1239:     } else {
                   1240:         $datatable .= '<td>&nbsp;</td>';
                   1241:     }
                   1242:     $datatable .= '<td class="LC_right_item">'.
                   1243:                   '<table border="0"><tr>';
                   1244:     foreach my $item (@{$links}) {
1.30      raeburn  1245:         $datatable .= '<td align="center">'."\n".
                   1246:                       &color_pick($phase,$role,$item,$choices->{$item},
                   1247:                                   $designs->{'links'}{$item});
1.6       raeburn  1248:         if ($designs->{'links'}{$item}) {
1.30      raeburn  1249:             $datatable.='&nbsp;<span id="css_'.$role.'_'.$item.'" style="background-color: '.$designs->{'links'}{$item}.';">&nbsp;&nbsp;&nbsp;</span>';
1.6       raeburn  1250:         }
                   1251:         $datatable .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.$designs->{'links'}{$item}.
                   1252:                       '" /></td>';
                   1253:     }
1.30      raeburn  1254:     $$rowtotal += $itemcount;
1.3       raeburn  1255:     return $datatable;
                   1256: }
                   1257: 
1.70      raeburn  1258: sub logo_display_options {
                   1259:     my ($img,$defaults,$designs) = @_;
                   1260:     my $checkedon;
                   1261:     if (ref($defaults) eq 'HASH') {
                   1262:         if (ref($defaults->{'showlogo'}) eq 'HASH') {
                   1263:             if ($defaults->{'showlogo'}{$img}) {
                   1264:                 $checkedon = 'checked="checked" ';     
                   1265:             }
                   1266:         } 
                   1267:     }
                   1268:     if (ref($designs) eq 'HASH') {
                   1269:         if (ref($designs->{'showlogo'}) eq 'HASH') {
                   1270:             if (defined($designs->{'showlogo'}{$img})) {
                   1271:                 if ($designs->{'showlogo'}{$img} == 0) {
                   1272:                     $checkedon = '';
                   1273:                 } elsif ($designs->{'showlogo'}{$img} == 1) {
                   1274:                     $checkedon = 'checked="checked" ';
                   1275:                 }
                   1276:             }
                   1277:         }
                   1278:     }
                   1279:     return '<br /><label>&nbsp;&nbsp;<input type="checkbox" name="'.
                   1280:            'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
                   1281:            &mt('show').'</label>'."\n";
                   1282: }
                   1283: 
1.41      raeburn  1284: sub login_header_options  {
1.135     bisitz   1285:     my ($img,$role,$defaults,$is_custom,$choices) = @_;
                   1286:     my $output = '';
1.41      raeburn  1287:     if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135     bisitz   1288:         $output .= &mt('Text default(s):').'<br />';
1.41      raeburn  1289:         if (!$is_custom->{'textcol'}) {
                   1290:             $output .= $choices->{'textcol'}.':&nbsp;'.$defaults->{'logintext'}{'textcol'}.
                   1291:                        '&nbsp;&nbsp;&nbsp;';
                   1292:         }
                   1293:         if (!$is_custom->{'bgcol'}) {
                   1294:             $output .= $choices->{'bgcol'}.':&nbsp;'.
                   1295:                        '<span id="css_'.$role.'_font" style="background-color: '.
                   1296:                        $defaults->{'logintext'}{'bgcol'}.';">&nbsp;&nbsp;&nbsp;</span>';
                   1297:         }
                   1298:         $output .= '<br />';
                   1299:     }
                   1300:     $output .='<br />';
                   1301:     return $output;
                   1302: }
                   1303: 
                   1304: sub login_text_colors {
                   1305:     my ($img,$role,$logintext,$phase,$choices,$designs) = @_;
                   1306:     my $color_menu = '<table border="0"><tr>';
                   1307:     foreach my $item (@{$logintext}) {
                   1308:         my $link = &color_pick($phase,$role,$item,$choices->{$item},$designs->{'logintext'}{$item});
                   1309:         $color_menu .= '<td align="center">'.$link;
                   1310:         if ($designs->{'logintext'}{$item}) {
                   1311:             $color_menu .= '&nbsp;<span id="css_'.$role.'_'.$item.'" style="background-color: '.$designs->{'logintext'}{$item}.';">&nbsp;&nbsp;&nbsp;</span>';
                   1312:         }
                   1313:         $color_menu .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.
                   1314:                        $designs->{'logintext'}{$item}.'" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>'.
                   1315:                        '<td>&nbsp;</td>';
                   1316:     }
                   1317:     $color_menu .= '</tr></table><br />';
                   1318:     return $color_menu;
                   1319: }
                   1320: 
                   1321: sub image_changes {
                   1322:     my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
                   1323:     my $output;
1.135     bisitz   1324:     if ($img eq 'login') {
                   1325:             # suppress image for Log-in header
                   1326:     } elsif (!$is_custom) {
1.70      raeburn  1327:         if ($img ne 'domlogo') {
1.41      raeburn  1328:             $output .= &mt('Default image:').'<br />';
                   1329:         } else {
                   1330:             $output .= &mt('Default in use:').'<br />';
                   1331:         }
                   1332:     }
1.135     bisitz   1333:     if ($img eq 'login') { # suppress image for Log-in header
                   1334:         $output .= '<td>'.$logincolors;
1.41      raeburn  1335:     } else {
1.135     bisitz   1336:         if ($img_import) {
                   1337:             $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
                   1338:         }
                   1339:         $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
                   1340:                    $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
                   1341:         if ($is_custom) {
                   1342:             $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
                   1343:                        '<input type="checkbox" name="'.
                   1344:                        $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
                   1345:                        '</label>&nbsp;'.&mt('Replace:').'</span><br />';
                   1346:         } else {
                   1347:             $output .= '<td valign="bottom">'.$logincolors.&mt('Upload:').'<br />';
                   1348:         }
1.41      raeburn  1349:     }
                   1350:     return $output;
                   1351: }
                   1352: 
1.6       raeburn  1353: sub color_pick {
                   1354:     my ($phase,$role,$item,$desc,$curcol) = @_;
                   1355:     my $link = '<a href="javascript:pjump('."'color_custom','".$desc.
                   1356:                "','".$curcol."','".$role.'_'.$item."','parmform.pres','psub'".
                   1357:                ');">'.$desc.'</a>';
                   1358:     return $link;
                   1359: }
                   1360: 
1.3       raeburn  1361: sub print_quotas {
1.86      raeburn  1362:     my ($dom,$settings,$rowtotal,$action) = @_;
                   1363:     my $context;
                   1364:     if ($action eq 'quotas') {
                   1365:         $context = 'tools';
                   1366:     } else {
                   1367:         $context = $action;
                   1368:     }
1.101     raeburn  1369:     my ($datatable,$defaultquota,@usertools,@options,%validations);
1.44      raeburn  1370:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3       raeburn  1371:     my $typecount = 0;
1.101     raeburn  1372:     my ($css_class,%titles);
1.86      raeburn  1373:     if ($context eq 'requestcourses') {
1.98      raeburn  1374:         @usertools = ('official','unofficial','community');
1.106     raeburn  1375:         @options =('norequest','approval','validate','autolimit');
1.101     raeburn  1376:         %validations = &Apache::lonnet::auto_courserequest_checks($dom);
                   1377:         %titles = &courserequest_titles();
1.86      raeburn  1378:     } else {
                   1379:         @usertools = ('aboutme','blog','portfolio');
1.101     raeburn  1380:         %titles = &tool_titles();
1.86      raeburn  1381:     }
1.26      raeburn  1382:     if (ref($types) eq 'ARRAY') {
1.23      raeburn  1383:         foreach my $type (@{$types}) {
1.72      raeburn  1384:             my $currdefquota;
1.86      raeburn  1385:             unless ($context eq 'requestcourses') {
                   1386:                 if (ref($settings) eq 'HASH') {
                   1387:                     if (ref($settings->{defaultquota}) eq 'HASH') {
                   1388:                         $currdefquota = $settings->{defaultquota}->{$type}; 
                   1389:                     } else {
                   1390:                         $currdefquota = $settings->{$type};
                   1391:                     }
1.78      raeburn  1392:                 }
1.72      raeburn  1393:             }
1.3       raeburn  1394:             if (defined($usertypes->{$type})) {
                   1395:                 $typecount ++;
                   1396:                 $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72      raeburn  1397:                 $datatable .= '<tr'.$css_class.'>'.
1.3       raeburn  1398:                               '<td>'.$usertypes->{$type}.'</td>'.
1.72      raeburn  1399:                               '<td class="LC_left_item">';
1.101     raeburn  1400:                 if ($context eq 'requestcourses') {
                   1401:                     $datatable .= '<table><tr>';
                   1402:                 }
                   1403:                 my %cell;  
1.72      raeburn  1404:                 foreach my $item (@usertools) {
1.101     raeburn  1405:                     if ($context eq 'requestcourses') {
                   1406:                         my ($curroption,$currlimit);
                   1407:                         if (ref($settings) eq 'HASH') {
                   1408:                             if (ref($settings->{$item}) eq 'HASH') {
                   1409:                                 $curroption = $settings->{$item}->{$type};
                   1410:                                 if ($curroption =~ /^autolimit=(\d*)$/) {
                   1411:                                     $currlimit = $1; 
                   1412:                                 }
                   1413:                             }
                   1414:                         }
                   1415:                         if (!$curroption) {
                   1416:                             $curroption = 'norequest';
                   1417:                         }
                   1418:                         $datatable .= '<th>'.$titles{$item}.'</th>';
                   1419:                         foreach my $option (@options) {
                   1420:                             my $val = $option;
                   1421:                             if ($option eq 'norequest') {
                   1422:                                 $val = 0;  
                   1423:                             }
                   1424:                             if ($option eq 'validate') {
                   1425:                                 my $canvalidate = 0;
                   1426:                                 if (ref($validations{$item}) eq 'HASH') { 
                   1427:                                     if ($validations{$item}{$type}) {
                   1428:                                         $canvalidate = 1;
                   1429:                                     }
                   1430:                                 }
                   1431:                                 next if (!$canvalidate);
                   1432:                             }
                   1433:                             my $checked = '';
                   1434:                             if ($option eq $curroption) {
                   1435:                                 $checked = ' checked="checked"';
                   1436:                             } elsif ($option eq 'autolimit') {
                   1437:                                 if ($curroption =~ /^autolimit/) {
                   1438:                                     $checked = ' checked="checked"';
                   1439:                                 }                       
                   1440:                             } 
                   1441:                             $cell{$item} .= '<span class="LC_nobreak"><label>'.
                   1442:                                   '<input type="radio" name="crsreq_'.$item.
                   1443:                                   '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127     raeburn  1444:                                   $titles{$option}.'</label>';
1.101     raeburn  1445:                             if ($option eq 'autolimit') {
1.127     raeburn  1446:                                 $cell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
1.101     raeburn  1447:                                                 $item.'_limit_'.$type.'" size="1" '.
1.103     raeburn  1448:                                                 'value="'.$currlimit.'" />';
1.101     raeburn  1449:                             }
1.127     raeburn  1450:                             $cell{$item} .= '</span> ';
1.103     raeburn  1451:                             if ($option eq 'autolimit') {
1.127     raeburn  1452:                                 $cell{$item} .= $titles{'unlimited'};
1.103     raeburn  1453:                             }
1.101     raeburn  1454:                         }
                   1455:                     } else {
                   1456:                         my $checked = 'checked="checked" ';
                   1457:                         if (ref($settings) eq 'HASH') {
                   1458:                             if (ref($settings->{$item}) eq 'HASH') {
                   1459:                                 if ($settings->{$item}->{$type} == 0) {
                   1460:                                     $checked = '';
                   1461:                                 } elsif ($settings->{$item}->{$type} == 1) {
                   1462:                                     $checked =  'checked="checked" ';
                   1463:                                 }
1.78      raeburn  1464:                             }
1.72      raeburn  1465:                         }
1.101     raeburn  1466:                         $datatable .= '<span class="LC_nobreak"><label>'.
                   1467:                                       '<input type="checkbox" name="'.$context.'_'.$item.
                   1468:                                       '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
                   1469:                                       '</label></span>&nbsp; ';
1.72      raeburn  1470:                     }
1.101     raeburn  1471:                 }
                   1472:                 if ($context eq 'requestcourses') {
                   1473:                     $datatable .= '</tr><tr>';
                   1474:                     foreach my $item (@usertools) {
1.106     raeburn  1475:                         $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';  
1.101     raeburn  1476:                     }
                   1477:                     $datatable .= '</tr></table>';
1.72      raeburn  1478:                 }
1.86      raeburn  1479:                 $datatable .= '</td>';
                   1480:                 unless ($context eq 'requestcourses') {
                   1481:                     $datatable .= 
                   1482:                               '<td class="LC_right_item"><span class="LC_nobreak">'.
1.3       raeburn  1483:                               '<input type="text" name="quota_'.$type.
1.72      raeburn  1484:                               '" value="'.$currdefquota.
1.86      raeburn  1485:                               '" size="5" /> Mb</span></td>';
                   1486:                 }
                   1487:                 $datatable .= '</tr>';
1.3       raeburn  1488:             }
                   1489:         }
                   1490:     }
1.86      raeburn  1491:     unless ($context eq 'requestcourses') {
                   1492:         $defaultquota = '20';
                   1493:         if (ref($settings) eq 'HASH') {
                   1494:             if (ref($settings->{'defaultquota'}) eq 'HASH') {
                   1495:                 $defaultquota = $settings->{'defaultquota'}->{'default'};
                   1496:             } elsif (defined($settings->{'default'})) {
                   1497:                 $defaultquota = $settings->{'default'};
                   1498:             }
1.3       raeburn  1499:         }
                   1500:     }
                   1501:     $typecount ++;
                   1502:     $css_class = $typecount%2?' class="LC_odd_row"':'';
                   1503:     $datatable .= '<tr'.$css_class.'>'.
1.26      raeburn  1504:                   '<td>'.$othertitle.'</td>'.
1.72      raeburn  1505:                   '<td class="LC_left_item">';
1.101     raeburn  1506:     if ($context eq 'requestcourses') {
                   1507:         $datatable .= '<table><tr>';
                   1508:     }
                   1509:     my %defcell;
1.72      raeburn  1510:     foreach my $item (@usertools) {
1.101     raeburn  1511:         if ($context eq 'requestcourses') {
                   1512:             my ($curroption,$currlimit);
                   1513:             if (ref($settings) eq 'HASH') {
                   1514:                 if (ref($settings->{$item}) eq 'HASH') {
                   1515:                     $curroption = $settings->{$item}->{'default'};
                   1516:                     if ($curroption =~ /^autolimit=(\d*)$/) {
                   1517:                         $currlimit = $1;
                   1518:                     }
                   1519:                 }
                   1520:             }
                   1521:             if (!$curroption) {
                   1522:                 $curroption = 'norequest';
                   1523:             }
                   1524:             $datatable .= '<th>'.$titles{$item}.'</th>';
                   1525:             foreach my $option (@options) {
                   1526:                 my $val = $option;
                   1527:                 if ($option eq 'norequest') {
                   1528:                     $val = 0;
                   1529:                 }
                   1530:                 if ($option eq 'validate') {
                   1531:                     my $canvalidate = 0;
                   1532:                     if (ref($validations{$item}) eq 'HASH') {
                   1533:                         if ($validations{$item}{'default'}) {
                   1534:                             $canvalidate = 1;
                   1535:                         }
                   1536:                     }
                   1537:                     next if (!$canvalidate);
                   1538:                 }
                   1539:                 my $checked = '';
                   1540:                 if ($option eq $curroption) {
                   1541:                     $checked = ' checked="checked"';
                   1542:                 } elsif ($option eq 'autolimit') {
                   1543:                     if ($curroption =~ /^autolimit/) {
                   1544:                         $checked = ' checked="checked"';
                   1545:                     }
                   1546:                 }
                   1547:                 $defcell{$item} .= '<span class="LC_nobreak"><label>'.
                   1548:                                   '<input type="radio" name="crsreq_'.$item.
                   1549:                                   '_default" value="'.$val.'"'.$checked.' />'.
                   1550:                                   $titles{$option}.'</label>';
                   1551:                 if ($option eq 'autolimit') {
1.127     raeburn  1552:                     $defcell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
1.101     raeburn  1553:                                        $item.'_limit_default" size="1" '.
                   1554:                                        'value="'.$currlimit.'" />';
                   1555:                 }
1.127     raeburn  1556:                 $defcell{$item} .= '</span> ';
1.104     raeburn  1557:                 if ($option eq 'autolimit') {
1.127     raeburn  1558:                     $defcell{$item} .= $titles{'unlimited'};
1.104     raeburn  1559:                 }
1.101     raeburn  1560:             }
                   1561:         } else {
                   1562:             my $checked = 'checked="checked" ';
                   1563:             if (ref($settings) eq 'HASH') {
                   1564:                 if (ref($settings->{$item}) eq 'HASH') {
                   1565:                     if ($settings->{$item}->{'default'} == 0) {
                   1566:                         $checked = '';
                   1567:                     } elsif ($settings->{$item}->{'default'} == 1) {
                   1568:                         $checked = 'checked="checked" ';
                   1569:                     }
1.78      raeburn  1570:                 }
1.72      raeburn  1571:             }
1.101     raeburn  1572:             $datatable .= '<span class="LC_nobreak"><label>'.
                   1573:                           '<input type="checkbox" name="'.$context.'_'.$item.
                   1574:                           '" value="default" '.$checked.'/>'.$titles{$item}.
                   1575:                           '</label></span>&nbsp; ';
                   1576:         }
                   1577:     }
                   1578:     if ($context eq 'requestcourses') {
                   1579:         $datatable .= '</tr><tr>';
                   1580:         foreach my $item (@usertools) {
1.106     raeburn  1581:             $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72      raeburn  1582:         }
1.101     raeburn  1583:         $datatable .= '</tr></table>';
1.72      raeburn  1584:     }
1.86      raeburn  1585:     $datatable .= '</td>';
                   1586:     unless ($context eq 'requestcourses') {
                   1587:         $datatable .= '<td class="LC_right_item"><span class="LC_nobreak">'.
                   1588:                       '<input type="text" name="defaultquota" value="'.
                   1589:                       $defaultquota.'" size="5" /> Mb</span></td>';
                   1590:     }
                   1591:     $datatable .= '</tr>';
1.72      raeburn  1592:     $typecount ++;
                   1593:     $css_class = $typecount%2?' class="LC_odd_row"':'';
                   1594:     $datatable .= '<tr'.$css_class.'>'.
1.104     raeburn  1595:                   '<td>'.&mt('LON-CAPA Advanced Users').' ';
                   1596:     if ($context eq 'requestcourses') {
1.109     raeburn  1597:         $datatable .= &mt('(overrides affiliation, if set)').
                   1598:                       '</td>'.
                   1599:                       '<td class="LC_left_item">'.
                   1600:                       '<table><tr>';
1.101     raeburn  1601:     } else {
1.109     raeburn  1602:         $datatable .= &mt('(overrides affiliation, if checked)').
                   1603:                       '</td>'.
                   1604:                       '<td class="LC_left_item" colspan="2">'.
                   1605:                       '<br />';
1.101     raeburn  1606:     }
                   1607:     my %advcell;
1.72      raeburn  1608:     foreach my $item (@usertools) {
1.101     raeburn  1609:         if ($context eq 'requestcourses') {
                   1610:             my ($curroption,$currlimit);
                   1611:             if (ref($settings) eq 'HASH') {
                   1612:                 if (ref($settings->{$item}) eq 'HASH') {
                   1613:                     $curroption = $settings->{$item}->{'_LC_adv'};
                   1614:                     if ($curroption =~ /^autolimit=(\d*)$/) {
                   1615:                         $currlimit = $1;
                   1616:                     }
                   1617:                 }
                   1618:             }
                   1619:             $datatable .= '<th>'.$titles{$item}.'</th>';
1.104     raeburn  1620:             my $checked = '';
                   1621:             if ($curroption eq '') {
                   1622:                 $checked = ' checked="checked"';
                   1623:             }
                   1624:             $advcell{$item} .= '<span class="LC_nobreak"><label>'.
                   1625:                                '<input type="radio" name="crsreq_'.$item.
                   1626:                                '__LC_adv" value=""'.$checked.' />'.
                   1627:                                &mt('No override set').'</label></span>&nbsp; ';
1.101     raeburn  1628:             foreach my $option (@options) {
                   1629:                 my $val = $option;
                   1630:                 if ($option eq 'norequest') {
                   1631:                     $val = 0;
                   1632:                 }
                   1633:                 if ($option eq 'validate') {
                   1634:                     my $canvalidate = 0;
                   1635:                     if (ref($validations{$item}) eq 'HASH') {
                   1636:                         if ($validations{$item}{'_LC_adv'}) {
                   1637:                             $canvalidate = 1;
                   1638:                         }
                   1639:                     }
                   1640:                     next if (!$canvalidate);
                   1641:                 }
                   1642:                 my $checked = '';
1.104     raeburn  1643:                 if ($val eq $curroption) {
1.101     raeburn  1644:                     $checked = ' checked="checked"';
                   1645:                 } elsif ($option eq 'autolimit') {
                   1646:                     if ($curroption =~ /^autolimit/) {
                   1647:                         $checked = ' checked="checked"';
                   1648:                     }
                   1649:                 }
                   1650:                 $advcell{$item} .= '<span class="LC_nobreak"><label>'.
                   1651:                                   '<input type="radio" name="crsreq_'.$item.
                   1652:                                   '__LC_adv" value="'.$val.'"'.$checked.' />'.
                   1653:                                   $titles{$option}.'</label>';
                   1654:                 if ($option eq 'autolimit') {
1.127     raeburn  1655:                     $advcell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
1.101     raeburn  1656:                                        $item.'_limit__LC_adv" size="1" '.
                   1657:                                        'value="'.$currlimit.'" />';
                   1658:                 }
1.127     raeburn  1659:                 $advcell{$item} .= '</span> ';
1.104     raeburn  1660:                 if ($option eq 'autolimit') {
1.127     raeburn  1661:                     $advcell{$item} .= $titles{'unlimited'};
1.104     raeburn  1662:                 }
1.101     raeburn  1663:             }
                   1664:         } else {
                   1665:             my $checked = 'checked="checked" ';
                   1666:             if (ref($settings) eq 'HASH') {
                   1667:                 if (ref($settings->{$item}) eq 'HASH') {
                   1668:                     if ($settings->{$item}->{'_LC_adv'} == 0) {
                   1669:                         $checked = '';
                   1670:                     } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
                   1671:                         $checked = 'checked="checked" ';
                   1672:                     }
1.79      raeburn  1673:                 }
1.72      raeburn  1674:             }
1.101     raeburn  1675:             $datatable .= '<span class="LC_nobreak"><label>'.
                   1676:                           '<input type="checkbox" name="'.$context.'_'.$item.
                   1677:                           '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
                   1678:                           '</label></span>&nbsp; ';
                   1679:         }
                   1680:     }
                   1681:     if ($context eq 'requestcourses') {
                   1682:         $datatable .= '</tr><tr>';
                   1683:         foreach my $item (@usertools) {
1.106     raeburn  1684:             $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72      raeburn  1685:         }
1.101     raeburn  1686:         $datatable .= '</tr></table>';
1.72      raeburn  1687:     }
1.98      raeburn  1688:     $datatable .= '</td></tr>';
1.30      raeburn  1689:     $$rowtotal += $typecount;
1.3       raeburn  1690:     return $datatable;
                   1691: }
                   1692: 
1.102     raeburn  1693: sub print_courserequestmail {
                   1694:     my ($dom,$settings,$rowtotal) = @_;
1.104     raeburn  1695:     my ($now,$datatable,%dompersonnel,@domcoord,@currapproval,$rows);
1.102     raeburn  1696:     $now = time;
                   1697:     $rows = 0;
                   1698:     %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
                   1699:     foreach my $server (keys(%dompersonnel)) {
                   1700:         foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
                   1701:             my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
                   1702:             if (!grep(/^$uname:$udom$/,@domcoord)) {
                   1703:                 push(@domcoord,$uname.':'.$udom);
                   1704:             }
                   1705:         }
                   1706:     }
                   1707:     if (ref($settings) eq 'HASH') {
                   1708:         if (ref($settings->{'notify'}) eq 'HASH') {
                   1709:             if ($settings->{'notify'}{'approval'} ne '') {
1.104     raeburn  1710:                @currapproval = split(',',$settings->{'notify'}{'approval'});
1.102     raeburn  1711:             }
                   1712:         }
                   1713:     }
1.104     raeburn  1714:     if (@currapproval) {
                   1715:         foreach my $dc (@currapproval) {
1.102     raeburn  1716:             unless (grep(/^\Q$dc\E$/,@domcoord)) {
                   1717:                 push(@domcoord,$dc);
                   1718:             }
                   1719:         }
                   1720:     }
                   1721:     @domcoord = sort(@domcoord);
                   1722:     my $numinrow = 4;
                   1723:     my $numdc = @domcoord;
                   1724:     my $css_class = 'class="LC_odd_row"';
                   1725:     $datatable = '<tr'.$css_class.'>'.
                   1726:                  ' <td>'.&mt('Receive notification of course requests requiring approval.').
                   1727:                  ' </td>'.
                   1728:                  ' <td class="LC_left_item">';
                   1729:     if (@domcoord > 0) {
                   1730:         $datatable .= '<table>';
                   1731:         for (my $i=0; $i<$numdc; $i++) {
                   1732:             my $rem = $i%($numinrow);
                   1733:             if ($rem == 0) {
                   1734:                 if ($i > 0) {
                   1735:                     $datatable .= '</tr>';
                   1736:                 }
                   1737:                 $datatable .= '<tr>';
                   1738:                 $rows ++;
                   1739:             }
                   1740:             my $check = ' ';
1.104     raeburn  1741:             if (grep(/^\Q$domcoord[$i]\E$/,@currapproval)) {
1.102     raeburn  1742:                 $check = ' checked="checked" ';
                   1743:             }
                   1744:             my ($uname,$udom) = split(':',$domcoord[$i]);
                   1745:             my $fullname = &Apache::loncommon::plainname($uname,$udom);
                   1746:             if ($i == $numdc-1) {
                   1747:                 my $colsleft = $numinrow-$rem;
                   1748:                 if ($colsleft > 1) {
                   1749:                     $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
                   1750:                 } else {
                   1751:                     $datatable .= '<td class="LC_left_item">';
                   1752:                 }
                   1753:             } else {
                   1754:                 $datatable .= '<td class="LC_left_item">';
                   1755:             }
                   1756:             $datatable .= '<span class="LC_nobreak"><label>'.
                   1757:                           '<input type="checkbox" name="reqapprovalnotify" '.
                   1758:                           'value="'.$domcoord[$i].'"'.$check.'/>'.
                   1759:                           $fullname.'</label></span></td>';
                   1760:         }
                   1761:         $datatable .= '</tr></table>';
                   1762:     } else {
                   1763:         $datatable .= &mt('There are no active Domain Coordinators');
                   1764:         $rows ++;
                   1765:     }
                   1766:     $datatable .='</td></tr>';
                   1767:     $$rowtotal += $rows;
                   1768:     return $datatable;
                   1769: }
                   1770: 
1.3       raeburn  1771: sub print_autoenroll {
1.30      raeburn  1772:     my ($dom,$settings,$rowtotal) = @_;
1.3       raeburn  1773:     my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.129     raeburn  1774:     my ($defdom,$runon,$runoff,$coownerson,$coownersoff);
1.3       raeburn  1775:     if (ref($settings) eq 'HASH') {
                   1776:         if (exists($settings->{'run'})) {
                   1777:             if ($settings->{'run'} eq '0') {
                   1778:                 $runoff = ' checked="checked" ';
                   1779:                 $runon = ' ';
                   1780:             } else {
                   1781:                 $runon = ' checked="checked" ';
                   1782:                 $runoff = ' ';
                   1783:             }
                   1784:         } else {
                   1785:             if ($autorun) {
                   1786:                 $runon = ' checked="checked" ';
                   1787:                 $runoff = ' ';
                   1788:             } else {
                   1789:                 $runoff = ' checked="checked" ';
                   1790:                 $runon = ' ';
                   1791:             }
                   1792:         }
1.129     raeburn  1793:         if (exists($settings->{'co-owners'})) {
                   1794:             if ($settings->{'co-owners'} eq '0') {
                   1795:                 $coownersoff = ' checked="checked" ';
                   1796:                 $coownerson = ' ';
                   1797:             } else {
                   1798:                 $coownerson = ' checked="checked" ';
                   1799:                 $coownersoff = ' ';
                   1800:             }
                   1801:         } else {
                   1802:             $coownersoff = ' checked="checked" ';
                   1803:             $coownerson = ' ';
                   1804:         }
1.3       raeburn  1805:         if (exists($settings->{'sender_domain'})) {
                   1806:             $defdom = $settings->{'sender_domain'};
                   1807:         }
1.14      raeburn  1808:     } else {
                   1809:         if ($autorun) {
                   1810:             $runon = ' checked="checked" ';
                   1811:             $runoff = ' ';
                   1812:         } else {
                   1813:             $runoff = ' checked="checked" ';
                   1814:             $runon = ' ';
                   1815:         }
1.3       raeburn  1816:     }
                   1817:     my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39      raeburn  1818:     my $notif_sender;
                   1819:     if (ref($settings) eq 'HASH') {
                   1820:         $notif_sender = $settings->{'sender_uname'};
                   1821:     }
1.3       raeburn  1822:     my $datatable='<tr class="LC_odd_row">'.
                   1823:                   '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8       raeburn  1824:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3       raeburn  1825:                   '<input type="radio" name="autoenroll_run"'.
1.8       raeburn  1826:                   $runon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   1827:                   '<label><input type="radio" name="autoenroll_run"'.
1.14      raeburn  1828:                   $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3       raeburn  1829:                   '</tr><tr>'.
                   1830:                   '<td>'.&mt('Notification messages - sender').
1.8       raeburn  1831:                   '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3       raeburn  1832:                   &mt('username').':&nbsp;'.
                   1833:                   '<input type="text" name="sender_uname" value="'.
1.39      raeburn  1834:                   $notif_sender.'" size="10" />&nbsp;&nbsp;'.&mt('domain').
1.129     raeburn  1835:                   ':&nbsp;'.$domform.'</span></td></tr>'.
                   1836:                   '<tr class="LC_odd_row">'.
                   1837:                   '<td>'.&mt('Automatically assign co-ownership').'</td>'.
                   1838:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   1839:                   '<input type="radio" name="autoassign_coowners"'.
                   1840:                   $coownerson.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   1841:                   '<label><input type="radio" name="autoassign_coowners"'.
                   1842:                   $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
                   1843:                   '</tr>';
                   1844:     $$rowtotal += 3;
1.3       raeburn  1845:     return $datatable;
                   1846: }
                   1847: 
                   1848: sub print_autoupdate {
1.30      raeburn  1849:     my ($position,$dom,$settings,$rowtotal) = @_;
1.3       raeburn  1850:     my $datatable;
                   1851:     if ($position eq 'top') {
                   1852:         my $updateon = ' ';
                   1853:         my $updateoff = ' checked="checked" ';
                   1854:         my $classlistson = ' ';
                   1855:         my $classlistsoff = ' checked="checked" ';
                   1856:         if (ref($settings) eq 'HASH') {
                   1857:             if ($settings->{'run'} eq '1') {
                   1858:                 $updateon = $updateoff;
                   1859:                 $updateoff = ' ';
                   1860:             }
                   1861:             if ($settings->{'classlists'} eq '1') {
                   1862:                 $classlistson = $classlistsoff;
                   1863:                 $classlistsoff = ' ';
                   1864:             }
                   1865:         }
                   1866:         my %title = (
                   1867:                    run => 'Auto-update active?',
                   1868:                    classlists => 'Update information in classlists?',
                   1869:                     );
                   1870:         $datatable = '<tr class="LC_odd_row">'. 
                   1871:                   '<td>'.&mt($title{'run'}).'</td>'.
1.8       raeburn  1872:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3       raeburn  1873:                   '<input type="radio" name="autoupdate_run"'.
1.8       raeburn  1874:                   $updateon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   1875:                   '<label><input type="radio" name="autoupdate_run"'.
                   1876:                   $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3       raeburn  1877:                   '</tr><tr>'.
                   1878:                   '<td>'.&mt($title{'classlists'}).'</td>'.
1.8       raeburn  1879:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
                   1880:                   '<label><input type="radio" name="classlists"'.
                   1881:                   $classlistson.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   1882:                   '<label><input type="radio" name="classlists"'.
                   1883:                   $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3       raeburn  1884:                   '</tr>';
1.30      raeburn  1885:         $$rowtotal += 2;
1.131     raeburn  1886:     } elsif ($position eq 'middle') {
                   1887:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   1888:         my $numinrow = 3;
                   1889:         my $locknamesettings;
                   1890:         $datatable .= &insttypes_row($settings,$types,$usertypes,
                   1891:                                      $dom,$numinrow,$othertitle,
                   1892:                                     'lockablenames');
                   1893:         $$rowtotal ++;
1.3       raeburn  1894:     } else {
1.44      raeburn  1895:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132     raeburn  1896:         my @fields = ('lastname','firstname','middlename','generation',
1.20      raeburn  1897:                       'permanentemail','id');
1.33      raeburn  1898:         my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3       raeburn  1899:         my $numrows = 0;
1.26      raeburn  1900:         if (ref($types) eq 'ARRAY') {
                   1901:             if (@{$types} > 0) {
                   1902:                 $datatable = 
                   1903:                     &usertype_update_row($settings,$usertypes,\%fieldtitles,
                   1904:                                          \@fields,$types,\$numrows);
1.30      raeburn  1905:                     $$rowtotal += @{$types}; 
1.26      raeburn  1906:             }
1.3       raeburn  1907:         }
                   1908:         $datatable .= 
                   1909:             &usertype_update_row($settings,{'default' => $othertitle},
                   1910:                                  \%fieldtitles,\@fields,['default'],
                   1911:                                  \$numrows);
1.30      raeburn  1912:         $$rowtotal ++;     
1.3       raeburn  1913:     }
                   1914:     return $datatable;
                   1915: }
                   1916: 
1.125     raeburn  1917: sub print_autocreate {
                   1918:     my ($dom,$settings,$rowtotal) = @_;
                   1919:     my (%createon,%createoff);
                   1920:     my $curr_dc;
                   1921:     my @types = ('xml','req');
                   1922:     if (ref($settings) eq 'HASH') {
                   1923:         foreach my $item (@types) {
                   1924:             $createoff{$item} = ' checked="checked" ';
                   1925:             $createon{$item} = ' ';
                   1926:             if (exists($settings->{$item})) {
                   1927:                 if ($settings->{$item}) {
                   1928:                     $createon{$item} = ' checked="checked" ';
                   1929:                     $createoff{$item} = ' ';
                   1930:                 }
                   1931:             }
                   1932:         }
                   1933:         $curr_dc = $settings->{'xmldc'};
                   1934:     } else {
                   1935:         foreach my $item (@types) {
                   1936:             $createoff{$item} = ' checked="checked" ';
                   1937:             $createon{$item} = ' ';
                   1938:         }
                   1939:     }
                   1940:     $$rowtotal += 2;
                   1941:     my $datatable='<tr class="LC_odd_row">'.
                   1942:                   '<td>'.&mt('Create pending official courses from XML files').'</td>'.
                   1943:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   1944:                   '<input type="radio" name="autocreate_xml"'.
                   1945:                   $createon{'xml'}.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   1946:                   '<label><input type="radio" name="autocreate_xml"'.
1.143     raeburn  1947:                   $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
                   1948:                   '</td></tr><tr>'.
                   1949:                   '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
                   1950:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   1951:                   '<input type="radio" name="autocreate_req"'.
                   1952:                   $createon{'req'}.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   1953:                   '<label><input type="radio" name="autocreate_req"'.
                   1954:                   $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.125     raeburn  1955:     my ($numdc,$dctable) = &active_dc_picker($dom,$curr_dc);
                   1956:     if ($numdc > 1) {
1.143     raeburn  1957:         $datatable .= '</td></tr><tr class="LC_odd_row"><td>'.
                   1958:                       &mt('Course creation processed as: (choose Dom. Coord.)').
                   1959:                       '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.125     raeburn  1960:         $$rowtotal ++ ;
                   1961:     } else {
1.143     raeburn  1962:         $datatable .= $dctable.'</td></tr>';
1.125     raeburn  1963:     }
                   1964:     return $datatable;
                   1965: }
                   1966: 
1.23      raeburn  1967: sub print_directorysrch {
1.30      raeburn  1968:     my ($dom,$settings,$rowtotal) = @_;
1.23      raeburn  1969:     my $srchon = ' ';
                   1970:     my $srchoff = ' checked="checked" ';
1.25      raeburn  1971:     my ($exacton,$containson,$beginson);
1.24      raeburn  1972:     my $localon = ' ';
                   1973:     my $localoff = ' checked="checked" ';
1.23      raeburn  1974:     if (ref($settings) eq 'HASH') {
                   1975:         if ($settings->{'available'} eq '1') {
                   1976:             $srchon = $srchoff;
                   1977:             $srchoff = ' ';
                   1978:         }
1.24      raeburn  1979:         if ($settings->{'localonly'} eq '1') {
                   1980:             $localon = $localoff;
                   1981:             $localoff = ' ';
                   1982:         }
1.25      raeburn  1983:         if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
                   1984:             foreach my $type (@{$settings->{'searchtypes'}}) {
                   1985:                 if ($type eq 'exact') {
                   1986:                     $exacton = ' checked="checked" ';
                   1987:                 } elsif ($type eq 'contains') {
                   1988:                     $containson = ' checked="checked" ';
                   1989:                 } elsif ($type eq 'begins') {
                   1990:                     $beginson = ' checked="checked" ';
                   1991:                 }
                   1992:             }
                   1993:         } else {
                   1994:             if ($settings->{'searchtypes'} eq 'exact') {
                   1995:                 $exacton = ' checked="checked" ';
                   1996:             } elsif ($settings->{'searchtypes'} eq 'contains') {
                   1997:                 $containson = ' checked="checked" ';
                   1998:             } elsif ($settings->{'searchtypes'} eq 'specify') {
                   1999:                 $exacton = ' checked="checked" ';
                   2000:                 $containson = ' checked="checked" ';
                   2001:             }
1.23      raeburn  2002:         }
                   2003:     }
                   2004:     my ($searchtitles,$titleorder) = &sorted_searchtitles();
1.45      raeburn  2005:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23      raeburn  2006: 
                   2007:     my $numinrow = 4;
1.26      raeburn  2008:     my $cansrchrow = 0;
1.23      raeburn  2009:     my $datatable='<tr class="LC_odd_row">'.
1.30      raeburn  2010:                   '<td colspan="2"><span class ="LC_nobreak">'.&mt('Directory search available?').'</span></td>'.
1.23      raeburn  2011:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   2012:                   '<input type="radio" name="dirsrch_available"'.
                   2013:                   $srchon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   2014:                   '<label><input type="radio" name="dirsrch_available"'.
                   2015:                   $srchoff.' value="0" />'.&mt('No').'</label></span></td>'.
                   2016:                   '</tr><tr>'.
1.30      raeburn  2017:                   '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search?').'</span></td>'.
1.24      raeburn  2018:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   2019:                   '<input type="radio" name="dirsrch_localonly"'.
                   2020:                   $localoff.' value="0" />'.&mt('Yes').'</label>&nbsp;'.
                   2021:                   '<label><input type="radio" name="dirsrch_localonly"'.
                   2022:                   $localon.' value="1" />'.&mt('No').'</label></span></td>'.
1.25      raeburn  2023:                   '</tr>';
1.30      raeburn  2024:     $$rowtotal += 2;
1.26      raeburn  2025:     if (ref($usertypes) eq 'HASH') {
                   2026:         if (keys(%{$usertypes}) > 0) {
1.93      raeburn  2027:             $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
                   2028:                                          $numinrow,$othertitle,'cansearch');
1.26      raeburn  2029:             $cansrchrow = 1;
                   2030:         }
                   2031:     }
                   2032:     if ($cansrchrow) {
1.30      raeburn  2033:         $$rowtotal ++;
1.26      raeburn  2034:         $datatable .= '<tr>';
                   2035:     } else {
                   2036:         $datatable .= '<tr class="LC_odd_row">';
                   2037:     }
1.30      raeburn  2038:     $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
                   2039:                   '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
1.25      raeburn  2040:     foreach my $title (@{$titleorder}) {
                   2041:         if (defined($searchtitles->{$title})) {
                   2042:             my $check = ' ';
1.93      raeburn  2043:             if (ref($settings) eq 'HASH') {
1.39      raeburn  2044:                 if (ref($settings->{'searchby'}) eq 'ARRAY') {
                   2045:                     if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
                   2046:                         $check = ' checked="checked" ';
                   2047:                     }
1.25      raeburn  2048:                 }
                   2049:             }
                   2050:             $datatable .= '<td class="LC_left_item">'.
                   2051:                           '<span class="LC_nobreak"><label>'.
                   2052:                           '<input type="checkbox" name="searchby" '.
                   2053:                           'value="'.$title.'"'.$check.'/>'.
                   2054:                           $searchtitles->{$title}.'</label></span></td>';
                   2055:         }
                   2056:     }
1.26      raeburn  2057:     $datatable .= '</tr></table></td></tr>';
1.30      raeburn  2058:     $$rowtotal ++;
1.26      raeburn  2059:     if ($cansrchrow) {
                   2060:         $datatable .= '<tr class="LC_odd_row">';
                   2061:     } else {
                   2062:         $datatable .= '<tr>';
                   2063:     }
1.30      raeburn  2064:     $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.   
1.26      raeburn  2065:                   '<td class="LC_left_item" colspan="2">'.
1.25      raeburn  2066:                   '<span class="LC_nobreak"><label>'.
                   2067:                   '<input type="checkbox" name="searchtypes" '.
                   2068:                   $exacton.' value="exact" />'.&mt('Exact match').
                   2069:                   '</label>&nbsp;'.
                   2070:                   '<label><input type="checkbox" name="searchtypes" '.
                   2071:                   $beginson.' value="begins" />'.&mt('Begins with').
                   2072:                   '</label>&nbsp;'.
                   2073:                   '<label><input type="checkbox" name="searchtypes" '.
                   2074:                   $containson.' value="contains" />'.&mt('Contains').
                   2075:                   '</label></span></td></tr>';
1.30      raeburn  2076:     $$rowtotal ++;
1.25      raeburn  2077:     return $datatable;
                   2078: }
                   2079: 
1.28      raeburn  2080: sub print_contacts {
1.30      raeburn  2081:     my ($dom,$settings,$rowtotal) = @_;
1.28      raeburn  2082:     my $datatable;
                   2083:     my @contacts = ('adminemail','supportemail');
1.134     raeburn  2084:     my (%checked,%to,%otheremails,%bccemails);
1.102     raeburn  2085:     my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail',
                   2086:                     'requestsmail');
1.28      raeburn  2087:     foreach my $type (@mailings) {
                   2088:         $otheremails{$type} = '';
                   2089:     }
1.134     raeburn  2090:     $bccemails{'helpdeskmail'} = '';
1.28      raeburn  2091:     if (ref($settings) eq 'HASH') {
                   2092:         foreach my $item (@contacts) {
                   2093:             if (exists($settings->{$item})) {
                   2094:                 $to{$item} = $settings->{$item};
                   2095:             }
                   2096:         }
                   2097:         foreach my $type (@mailings) {
                   2098:             if (exists($settings->{$type})) {
                   2099:                 if (ref($settings->{$type}) eq 'HASH') {
                   2100:                     foreach my $item (@contacts) {
                   2101:                         if ($settings->{$type}{$item}) {
                   2102:                             $checked{$type}{$item} = ' checked="checked" ';
                   2103:                         }
                   2104:                     }
                   2105:                     $otheremails{$type} = $settings->{$type}{'others'};
1.134     raeburn  2106:                     if ($type eq 'helpdeskmail') {
                   2107:                         $bccemails{$type} = $settings->{$type}{'bcc'};
                   2108:                     }
1.28      raeburn  2109:                 }
1.89      raeburn  2110:             } elsif ($type eq 'lonstatusmail') {
                   2111:                 $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.28      raeburn  2112:             }
                   2113:         }
                   2114:     } else {
                   2115:         $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
                   2116:         $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
                   2117:         $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
                   2118:         $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.89      raeburn  2119:         $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
                   2120:         $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" '; 
1.102     raeburn  2121:         $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
1.28      raeburn  2122:     }
                   2123:     my ($titles,$short_titles) = &contact_titles();
                   2124:     my $rownum = 0;
                   2125:     my $css_class;
                   2126:     foreach my $item (@contacts) {
1.69      raeburn  2127:         $rownum ++;
                   2128:         $css_class = $rownum%2?' class="LC_odd_row"':'';
1.30      raeburn  2129:         $datatable .= '<tr'.$css_class.'>'. 
                   2130:                   '<td><span class="LC_nobreak">'.$titles->{$item}.
                   2131:                   '</span></td><td class="LC_right_item">'.
1.28      raeburn  2132:                   '<input type="text" name="'.$item.'" value="'.
                   2133:                   $to{$item}.'" /></td></tr>';
                   2134:     }
                   2135:     foreach my $type (@mailings) {
1.69      raeburn  2136:         $rownum ++;
                   2137:         $css_class = $rownum%2?' class="LC_odd_row"':'';
1.28      raeburn  2138:         $datatable .= '<tr'.$css_class.'>'.
1.30      raeburn  2139:                       '<td><span class="LC_nobreak">'.
                   2140:                       $titles->{$type}.': </span></td>'.
1.28      raeburn  2141:                       '<td class="LC_left_item">'.
                   2142:                       '<span class="LC_nobreak">';
                   2143:         foreach my $item (@contacts) {
                   2144:             $datatable .= '<label>'.
                   2145:                           '<input type="checkbox" name="'.$type.'"'.
                   2146:                           $checked{$type}{$item}.
                   2147:                           ' value="'.$item.'" />'.$short_titles->{$item}.
                   2148:                           '</label>&nbsp;';
                   2149:         }
                   2150:         $datatable .= '</span><br />'.&mt('Others').':&nbsp;&nbsp;'.
                   2151:                       '<input type="text" name="'.$type.'_others" '.
1.134     raeburn  2152:                       'value="'.$otheremails{$type}.'"  />';
                   2153:         if ($type eq 'helpdeskmail') {
1.136     raeburn  2154:             $datatable .= '<br />'.&mt('Bcc:').('&nbsp;'x6).
1.134     raeburn  2155:                           '<input type="text" name="'.$type.'_bcc" '.
                   2156:                           'value="'.$bccemails{$type}.'"  />';
                   2157:         }
                   2158:         $datatable .= '</td></tr>'."\n";
1.28      raeburn  2159:     }
1.30      raeburn  2160:     $$rowtotal += $rownum;
1.28      raeburn  2161:     return $datatable;
                   2162: }
                   2163: 
1.118     jms      2164: sub print_helpsettings {
1.122     jms      2165: 
                   2166: 	my ($position,$dom,$confname,$settings,$rowtotal) = @_;
                   2167: 	my ($css_class,$datatable);
                   2168: 	
                   2169: 	my $switchserver = &check_switchserver($dom,$confname);
                   2170: 	
                   2171: 	my $itemcount = 1;
                   2172: 	
                   2173: 	if ($position eq 'top') {
                   2174: 		
                   2175: 		my (%checkedon,%checkedoff,%choices,%defaultchecked,@toggles);
                   2176: 		
                   2177: 		%choices =
                   2178: 			&Apache::lonlocal::texthash (
                   2179: 				submitbugs => 'Display &quot;Submit a bug&quot; link?',
                   2180: 		);
                   2181: 		
                   2182: 		%defaultchecked = ('submitbugs' => 'on');
                   2183: 		
                   2184: 		@toggles = ('submitbugs',);
                   2185: 		
                   2186: 		foreach my $item (@toggles) {
                   2187: 			if ($defaultchecked{$item} eq 'on') { 
                   2188: 				$checkedon{$item} = ' checked="checked" ';
                   2189: 				$checkedoff{$item} = ' ';
                   2190: 			} elsif ($defaultchecked{$item} eq 'off') {
                   2191: 				$checkedoff{$item} = ' checked="checked" ';
                   2192: 				$checkedon{$item} = ' ';
                   2193: 			}
                   2194: 		}
                   2195: 		
                   2196: 		if (ref($settings) eq 'HASH') {
                   2197: 			foreach my $item (@toggles) {
                   2198: 				if ($settings->{$item} eq '1') {
                   2199: 					$checkedon{$item} =  ' checked="checked" ';
                   2200: 					$checkedoff{$item} = ' ';
                   2201: 				} elsif ($settings->{$item} eq '0') {
                   2202: 					$checkedoff{$item} =  ' checked="checked" ';
                   2203: 					$checkedon{$item} = ' ';
                   2204: 				}
                   2205: 			}
                   2206: 		 }
                   2207: 		
                   2208: 		 foreach my $item (@toggles) {
                   2209: 			$css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   2210: 			$datatable .=  
                   2211: 				'<tr'.$css_class.'>
                   2212: 				<td><span class="LC_nobreak">'.$choices{$item}.'</span></td>
                   2213: 				<td><span class="LC_nobreak">&nbsp;</span></td>
                   2214: 				<td class="LC_right_item"><span class="LC_nobreak">
                   2215: 				<label><input type="radio" name="'.$item.'" '.$checkedon{$item}.' value="1" />'.&mt('Yes').'</label>&nbsp;
                   2216: 				<label><input type="radio" name="'.$item.'" '.$checkedoff{$item}.' value="0" />'.&mt('No').'</label>'.
                   2217: 				'</span></td>'.
                   2218: 				'</tr>';
                   2219: 			$itemcount ++;
                   2220: 		 }
                   2221:      
                   2222:      } else {
                   2223:      
                   2224:      	$css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   2225:      	
                   2226:      	$datatable .= '<tr'.$css_class.'>';
                   2227:      	
                   2228:      	if (ref($settings) eq 'HASH') {
                   2229: 			if ($settings->{'loginhelpurl'} ne '') {
                   2230: 				my($directory, $filename) = $settings->{'loginhelpurl'} =~ m/(.*\/)(.*)$/;
                   2231: 				$datatable .= '<td width="33%"><span class="LC_left_item"><label><a href="'.$settings->{'loginhelpurl'}.'" target="_blank">'.&mt('Custom Login Page Help File In Use').'</a></label></span></td>';
                   2232: 				$datatable .= '<td width="33%"><span class="LC_right_item"><label><input type="checkbox" name="loginhelpurl_del" value="1" />'.&mt('Delete?').'</label></span></td>'
                   2233: 			} else {
                   2234: 				$datatable .= '<td width="33%"><span class="LC_left_item"><label>'.&mt('Default Login Page Help File In Use').'</label></span></td>';
                   2235: 				$datatable .= '<td width="33%"><span class="LC_right_item">&nbsp;</span></td>';
                   2236: 			}
                   2237: 		} else {
                   2238: 			$datatable .= '<td><span class="LC_left_item">&nbsp;</span></td>';
                   2239: 			$datatable .= '<td><span class="LC_right_item">&nbsp;</span></td>';
                   2240: 		}
                   2241:     	
                   2242:      	$datatable .= '<td width="33%"><span class="LC_right_item">';
                   2243:      	if ($switchserver) {
                   2244:             $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   2245:         } else {
                   2246:         	$datatable .= &mt('Upload Custom Login Page Help File:');
                   2247:             $datatable .='<input type="file" name="loginhelpurl" />';
                   2248:         }
                   2249:         $datatable .= '</span></td></tr>';
                   2250:         
                   2251:      }
                   2252:      
                   2253:      return $datatable;
                   2254: 	
1.121     raeburn  2255: }
                   2256: 
1.122     jms      2257: 
1.121     raeburn  2258: sub radiobutton_prefs {
                   2259:     my ($settings,$toggles,$defaultchecked,$choices,$itemcount) = @_;
                   2260:     return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
                   2261:                    (ref($choices) eq 'HASH'));
                   2262: 
                   2263:     my (%checkedon,%checkedoff,$datatable,$css_class);
                   2264: 
                   2265:     foreach my $item (@{$toggles}) {
                   2266:         if ($defaultchecked->{$item} eq 'on') {
1.118     jms      2267:             $checkedon{$item} = ' checked="checked" ';
                   2268:             $checkedoff{$item} = ' ';
1.121     raeburn  2269:         } elsif ($defaultchecked->{$item} eq 'off') {
1.118     jms      2270:             $checkedoff{$item} = ' checked="checked" ';
                   2271:             $checkedon{$item} = ' ';
                   2272:         }
                   2273:     }
                   2274:     if (ref($settings) eq 'HASH') {
1.121     raeburn  2275:         foreach my $item (@{$toggles}) {
1.118     jms      2276:             if ($settings->{$item} eq '1') {
                   2277:                 $checkedon{$item} =  ' checked="checked" ';
                   2278:                 $checkedoff{$item} = ' ';
                   2279:             } elsif ($settings->{$item} eq '0') {
                   2280:                 $checkedoff{$item} =  ' checked="checked" ';
                   2281:                 $checkedon{$item} = ' ';
                   2282:             }
                   2283:         }
1.121     raeburn  2284:     }
                   2285:     foreach my $item (@{$toggles}) {
1.118     jms      2286:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121     raeburn  2287:         $datatable .=
                   2288:             '<tr'.$css_class.'><td><span class="LC_nobreak">'.$choices->{$item}.
1.118     jms      2289:             '</span></td>'.
                   2290:             '<td class="LC_right_item"><span class="LC_nobreak">'.
                   2291:             '<label><input type="radio" name="'.
                   2292:             $item.'" '.$checkedon{$item}.' value="1" />'.&mt('Yes').
                   2293:             '</label>&nbsp;<label><input type="radio" name="'.$item.'" '.
                   2294:             $checkedoff{$item}.' value="0" />'.&mt('No').'</label>'.
                   2295:             '</span></td>'.
                   2296:             '</tr>';
                   2297:         $itemcount ++;
1.121     raeburn  2298:     }
                   2299:     return ($datatable,$itemcount);
                   2300: }
                   2301: 
                   2302: sub print_coursedefaults {
1.139     raeburn  2303:     my ($position,$dom,$settings,$rowtotal) = @_;
1.121     raeburn  2304:     my ($css_class,$datatable);
                   2305:     my $itemcount = 1;
1.139     raeburn  2306:     if ($position eq 'top') {
                   2307:         my (%checkedon,%checkedoff,%choices,%defaultchecked,@toggles);
                   2308:         %choices =
                   2309:             &Apache::lonlocal::texthash (
                   2310:                 canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
                   2311:         );
                   2312:         %defaultchecked = ('canuse_pdfforms' => 'off');
                   2313:         @toggles = ('canuse_pdfforms',);
                   2314:         ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.121     raeburn  2315:                                                  \%choices,$itemcount);
1.139     raeburn  2316:         $$rowtotal += $itemcount;
                   2317:     } else {
                   2318:         $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   2319:         my %choices =
                   2320:             &Apache::lonlocal::texthash (
                   2321:                 anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
                   2322:         );
                   2323:         my $currdefresponder;
                   2324:         if (ref($settings) eq 'HASH') {
                   2325:             $currdefresponder = $settings->{'anonsurvey_threshold'};
                   2326:         }
                   2327:         if (!$currdefresponder) {
                   2328:             $currdefresponder = 10;
                   2329:         } elsif ($currdefresponder < 1) {
                   2330:             $currdefresponder = 1;
                   2331:         }
                   2332:         $datatable .=
                   2333:                '<tr'.$css_class.'><td><span class="LC_nobreak">'.$choices{'anonsurvey_threshold'}.
                   2334:                 '</span></td>'.
                   2335:                 '<td class="LC_right_item"><span class="LC_nobreak">'.
                   2336:                 '<input type="text" name="anonsurvey_threshold"'.
                   2337:                 ' value="'.$currdefresponder.'" size="5" /></span>'.
                   2338:                 '</td></tr>';
                   2339:     }
1.121     raeburn  2340:     return $datatable;
1.118     jms      2341: }
                   2342: 
1.137     raeburn  2343: sub print_usersessions {
                   2344:     my ($position,$dom,$settings,$rowtotal) = @_;
                   2345:     my ($css_class,$datatable,%checked,%choices);
1.140     raeburn  2346:     my (%by_ip,%by_location,@intdoms);
                   2347:     &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145     raeburn  2348: 
                   2349:     my @alldoms = &Apache::lonnet::all_domains();
1.152     raeburn  2350:     my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149     raeburn  2351:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152     raeburn  2352:     my %altids = &id_for_thisdom(%servers);
1.145     raeburn  2353:     my $itemcount = 1;
                   2354:     if ($position eq 'top') {
1.152     raeburn  2355:         if (keys(%serverhomes) > 1) {
1.145     raeburn  2356:             my %spareid = &current_offloads_to($dom,$settings,\%servers);
1.152     raeburn  2357:             $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$rowtotal);
1.145     raeburn  2358:         } else {
1.140     raeburn  2359:             $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150     raeburn  2360:                           &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140     raeburn  2361:         }
1.137     raeburn  2362:     } else {
1.145     raeburn  2363:         if (keys(%by_location) == 0) {
                   2364:             $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150     raeburn  2365:                           &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145     raeburn  2366:         } else {
                   2367:             my %lt = &usersession_titles();
                   2368:             my $numinrow = 5;
                   2369:             my $prefix;
                   2370:             my @types;
                   2371:             if ($position eq 'bottom') {
                   2372:                 $prefix = 'remote';
                   2373:                 @types = ('version','excludedomain','includedomain');
                   2374:             } else {
                   2375:                 $prefix = 'hosted';
                   2376:                 @types = ('excludedomain','includedomain');
                   2377:             }
                   2378:             my (%current,%checkedon,%checkedoff);
                   2379:             my @lcversions = &Apache::lonnet::all_loncaparevs();
                   2380:             my @locations = sort(keys(%by_location));
                   2381:             foreach my $type (@types) {
                   2382:                 $checkedon{$type} = '';
                   2383:                 $checkedoff{$type} = ' checked="checked"';
                   2384:             }
                   2385:             if (ref($settings) eq 'HASH') {
                   2386:                 if (ref($settings->{$prefix}) eq 'HASH') {
                   2387:                     foreach my $key (keys(%{$settings->{$prefix}})) {
                   2388:                         $current{$key} = $settings->{$prefix}{$key};
                   2389:                         if ($key eq 'version') {
                   2390:                             if ($current{$key} ne '') {
                   2391:                                 $checkedon{$key} = ' checked="checked"';
                   2392:                                 $checkedoff{$key} = '';
                   2393:                             }
                   2394:                         } elsif (ref($current{$key}) eq 'ARRAY') {
                   2395:                             $checkedon{$key} = ' checked="checked"';
                   2396:                             $checkedoff{$key} = '';
                   2397:                         }
1.137     raeburn  2398:                     }
                   2399:                 }
                   2400:             }
1.145     raeburn  2401:             foreach my $type (@types) {
                   2402:                 next if ($type ne 'version' && !@locations);
                   2403:                 $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   2404:                 $datatable .= '<tr'.$css_class.'>
                   2405:                                <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
                   2406:                                <span class="LC_nobreak">&nbsp;
                   2407:                                <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>&nbsp;
                   2408:                                <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
                   2409:                 if ($type eq 'version') {
                   2410:                     my $selector = '<select name="'.$prefix.'_version">';
                   2411:                     foreach my $version (@lcversions) {
                   2412:                         my $selected = '';
                   2413:                         if ($current{'version'} eq $version) {
                   2414:                             $selected = ' selected="selected"';
                   2415:                         }
                   2416:                         $selector .= ' <option value="'.$version.'"'.
                   2417:                                      $selected.'>'.$version.'</option>';
                   2418:                     }
                   2419:                     $selector .= '</select> ';
                   2420:                     $datatable .= &mt('remote server must be version: [_1] or later',$selector);
                   2421:                 } else {
                   2422:                     $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
                   2423:                                  'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
                   2424:                                  ' />'.('&nbsp;'x2).
                   2425:                                  '<input type="button" value="'.&mt('uncheck all').'" '.
                   2426:                                  'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
                   2427:                                  "\n".
                   2428:                                  '</div><div><table>';
                   2429:                     my $rem;
                   2430:                     for (my $i=0; $i<@locations; $i++) {
                   2431:                         my ($showloc,$value,$checkedtype);
                   2432:                         if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
                   2433:                             my $ip = $by_location{$locations[$i]}->[0];
                   2434:                             if (ref($by_ip{$ip}) eq 'ARRAY') {
                   2435:                                  $value = join(':',@{$by_ip{$ip}});
                   2436:                                 $showloc = join(', ',@{$by_ip{$ip}});
                   2437:                                 if (ref($current{$type}) eq 'ARRAY') {
                   2438:                                     foreach my $loc (@{$by_ip{$ip}}) {  
                   2439:                                         if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
                   2440:                                             $checkedtype = ' checked="checked"';
                   2441:                                             last;
                   2442:                                         }
                   2443:                                     }
1.138     raeburn  2444:                                 }
                   2445:                             }
                   2446:                         }
1.145     raeburn  2447:                         $rem = $i%($numinrow);
                   2448:                         if ($rem == 0) {
                   2449:                             if ($i > 0) {
                   2450:                                 $datatable .= '</tr>';
                   2451:                             }
                   2452:                             $datatable .= '<tr>';
                   2453:                         }
                   2454:                         $datatable .= '<td class="LC_left_item">'.
                   2455:                                       '<span class="LC_nobreak"><label>'.
                   2456:                                       '<input type="checkbox" name="'.$prefix.'_'.$type.
                   2457:                                       '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
                   2458:                                       '</label></span></td>';
1.137     raeburn  2459:                     }
1.145     raeburn  2460:                     $rem = @locations%($numinrow);
                   2461:                     my $colsleft = $numinrow - $rem;
                   2462:                     if ($colsleft > 1 ) {
                   2463:                         $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   2464:                                       '&nbsp;</td>';
                   2465:                     } elsif ($colsleft == 1) {
                   2466:                         $datatable .= '<td class="LC_left_item">&nbsp;</td>';
1.137     raeburn  2467:                     }
1.145     raeburn  2468:                     $datatable .= '</tr></table>';
1.137     raeburn  2469:                 }
1.145     raeburn  2470:                 $datatable .= '</td></tr>';
                   2471:                 $itemcount ++;
1.137     raeburn  2472:             }
                   2473:         }
                   2474:     }
                   2475:     $$rowtotal += $itemcount;
                   2476:     return $datatable;
                   2477: }
                   2478: 
1.138     raeburn  2479: sub build_location_hashes {
                   2480:     my ($intdoms,$by_ip,$by_location) = @_;
                   2481:     return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
                   2482:                   (ref($by_location) eq 'HASH')); 
                   2483:     my %iphost = &Apache::lonnet::get_iphost();
                   2484:     my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
                   2485:     my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
                   2486:     if (ref($iphost{$primary_ip}) eq 'ARRAY') {
                   2487:         foreach my $id (@{$iphost{$primary_ip}}) {
                   2488:             my $intdom = &Apache::lonnet::internet_dom($id);
                   2489:             unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
                   2490:                 push(@{$intdoms},$intdom);
                   2491:             }
                   2492:         }
                   2493:     }
                   2494:     foreach my $ip (keys(%iphost)) {
                   2495:         if (ref($iphost{$ip}) eq 'ARRAY') {
                   2496:             foreach my $id (@{$iphost{$ip}}) {
                   2497:                 my $location = &Apache::lonnet::internet_dom($id);
                   2498:                 if ($location) {
                   2499:                     next if (grep(/^\Q$location\E$/,@{$intdoms}));
                   2500:                     if (ref($by_ip->{$ip}) eq 'ARRAY') {
                   2501:                         unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
                   2502:                             push(@{$by_ip->{$ip}},$location);
                   2503:                         }
                   2504:                     } else {
                   2505:                         $by_ip->{$ip} = [$location];
                   2506:                     }
                   2507:                 }
                   2508:             }
                   2509:         }
                   2510:     }
                   2511:     foreach my $ip (sort(keys(%{$by_ip}))) {
                   2512:         if (ref($by_ip->{$ip}) eq 'ARRAY') {
                   2513:             @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
                   2514:             my $first = $by_ip->{$ip}->[0];
                   2515:             if (ref($by_location->{$first}) eq 'ARRAY') {
                   2516:                 unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
                   2517:                     push(@{$by_location->{$first}},$ip);
                   2518:                 }
                   2519:             } else {
                   2520:                 $by_location->{$first} = [$ip];
                   2521:             }
                   2522:         }
                   2523:     }
                   2524:     return;
                   2525: }
                   2526: 
1.145     raeburn  2527: sub current_offloads_to {
                   2528:     my ($dom,$settings,$servers) = @_;
                   2529:     my (%spareid,%otherdomconfigs);
1.152     raeburn  2530:     if (ref($servers) eq 'HASH') {
1.145     raeburn  2531:         foreach my $lonhost (sort(keys(%{$servers}))) {
                   2532:             my $gotspares;
1.152     raeburn  2533:             if (ref($settings) eq 'HASH') {
                   2534:                 if (ref($settings->{'spares'}) eq 'HASH') {
                   2535:                     if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
                   2536:                         $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
                   2537:                         $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
                   2538:                         $gotspares = 1;
                   2539:                     }
1.145     raeburn  2540:                 }
                   2541:             }
                   2542:             unless ($gotspares) {
                   2543:                 my $gotspares;
                   2544:                 my $serverhomeID =
                   2545:                     &Apache::lonnet::get_server_homeID($servers->{$lonhost});
                   2546:                 my $serverhomedom =
                   2547:                     &Apache::lonnet::host_domain($serverhomeID);
                   2548:                 if ($serverhomedom ne $dom) {
                   2549:                     if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
                   2550:                         if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
                   2551:                             if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
                   2552:                                 $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
                   2553:                                 $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
                   2554:                                 $gotspares = 1;
                   2555:                             }
                   2556:                         }
                   2557:                     } else {
                   2558:                         $otherdomconfigs{$serverhomedom} =
                   2559:                             &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
                   2560:                         if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
                   2561:                             if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
                   2562:                                 if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
                   2563:                                     if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
                   2564:                                         $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
                   2565:                                         $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
                   2566:                                         $gotspares = 1;
                   2567:                                     }
                   2568:                                 }
                   2569:                             }
                   2570:                         }
                   2571:                     }
                   2572:                 }
                   2573:             }
                   2574:             unless ($gotspares) {
                   2575:                 if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
                   2576:                     $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
                   2577:                     $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
                   2578:                } else {
                   2579:                     my $server_hostname = &Apache::lonnet::hostname($lonhost);
                   2580:                     my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
                   2581:                     if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
                   2582:                         $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
                   2583:                         $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
                   2584:                     } else {
1.150     raeburn  2585:                         my %what = (
                   2586:                              spareid => 1,
                   2587:                         );
                   2588:                         my ($result,$returnhash) = 
                   2589:                             &Apache::lonnet::get_remote_globals($lonhost,\%what);
                   2590:                         if ($result eq 'ok') { 
                   2591:                             if (ref($returnhash) eq 'HASH') {
                   2592:                                 if (ref($returnhash->{'spareid'}) eq 'HASH') {
                   2593:                                     $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
                   2594:                                     $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
                   2595:                                 }
                   2596:                             }
1.145     raeburn  2597:                         }
                   2598:                     }
                   2599:                 }
                   2600:             }
                   2601:         }
                   2602:     }
                   2603:     return %spareid;
                   2604: }
                   2605: 
                   2606: sub spares_row {
1.152     raeburn  2607:     my ($dom,$servers,$spareid,$serverhomes,$altids,$rowtotal) = @_;
1.145     raeburn  2608:     my $css_class;
                   2609:     my $numinrow = 4;
                   2610:     my $itemcount = 1;
                   2611:     my $datatable;
1.152     raeburn  2612:     my %typetitles = &sparestype_titles();
                   2613:     if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145     raeburn  2614:         foreach my $server (sort(keys(%{$servers}))) {
1.152     raeburn  2615:             my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
                   2616:             my ($othercontrol,$serverdom);
                   2617:             if ($serverhome ne $server) {
                   2618:                 $serverdom = &Apache::lonnet::host_domain($serverhome);
                   2619:                 $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
                   2620:             } else {
                   2621:                 $serverdom = &Apache::lonnet::host_domain($server);
                   2622:                 if ($serverdom ne $dom) {
                   2623:                     $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
                   2624:                 }
                   2625:             }
                   2626:             next unless (ref($spareid->{$server}) eq 'HASH');
1.145     raeburn  2627:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   2628:             $datatable .= '<tr'.$css_class.'>
                   2629:                            <td rowspan="2">
1.152     raeburn  2630:                             <span class="LC_nobreak"><b>'.$server.'</b> when busy, offloads to:</span></td>'."\n";
1.145     raeburn  2631:             my (%current,%canselect);
1.152     raeburn  2632:             my @choices = 
                   2633:                 &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
                   2634:             foreach my $type ('primary','default') {
                   2635:                 if (ref($spareid->{$server}) eq 'HASH') {
1.145     raeburn  2636:                     if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
                   2637:                         my @spares = @{$spareid->{$server}{$type}};
                   2638:                         if (@spares > 0) {
1.152     raeburn  2639:                             if ($othercontrol) {
                   2640:                                 $current{$type} = join(', ',@spares);
                   2641:                             } else {
                   2642:                                 $current{$type} .= '<table>';
                   2643:                                 my $numspares = scalar(@spares);
                   2644:                                 for (my $i=0;  $i<@spares; $i++) {
                   2645:                                     my $rem = $i%($numinrow);
                   2646:                                     if ($rem == 0) {
                   2647:                                         if ($i > 0) {
                   2648:                                             $current{$type} .= '</tr>';
                   2649:                                         }
                   2650:                                         $current{$type} .= '<tr>';
1.145     raeburn  2651:                                     }
1.152     raeburn  2652:                                     $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;'.
                   2653:                                                        $spareid->{$server}{$type}[$i].
                   2654:                                                        '</label></td>'."\n";
                   2655:                                 }
                   2656:                                 my $rem = @spares%($numinrow);
                   2657:                                 my $colsleft = $numinrow - $rem;
                   2658:                                 if ($colsleft > 1 ) {
                   2659:                                     $current{$type} .= '<td colspan="'.$colsleft.
                   2660:                                                        '" class="LC_left_item">'.
                   2661:                                                        '&nbsp;</td>';
                   2662:                                 } elsif ($colsleft == 1) {
                   2663:                                     $current{$type} .= '<td class="LC_left_item">&nbsp;</td>'."\n";
1.145     raeburn  2664:                                 }
1.152     raeburn  2665:                                 $current{$type} .= '</tr></table>';
1.150     raeburn  2666:                             }
1.145     raeburn  2667:                         }
                   2668:                     }
                   2669:                     if ($current{$type} eq '') {
                   2670:                         $current{$type} = &mt('None specified');
                   2671:                     }
1.152     raeburn  2672:                     if ($othercontrol) {
                   2673:                         if ($type eq 'primary') {
                   2674:                             $canselect{$type} = $othercontrol;
                   2675:                         }
                   2676:                     } else {
                   2677:                         $canselect{$type} = 
                   2678:                             &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').'&nbsp;'.
                   2679:                             '<select name="newspare_'.$type.'_'.$server.'" '.
                   2680:                             'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
                   2681:                             '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
                   2682:                         if (@choices > 0) {
                   2683:                             foreach my $lonhost (@choices) {
                   2684:                                 $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
                   2685:                             }
                   2686:                         }
                   2687:                         $canselect{$type} .= '</select>'."\n";
                   2688:                     }
                   2689:                 } else {
                   2690:                     $current{$type} = &mt('Could not be determined');
                   2691:                     if ($type eq 'primary') {
                   2692:                         $canselect{$type} =  $othercontrol;
                   2693:                     }
1.145     raeburn  2694:                 }
1.152     raeburn  2695:                 if ($type eq 'default') {
                   2696:                     $datatable .= '<tr'.$css_class.'>';
                   2697:                 }
                   2698:                 $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
                   2699:                               '<td>'.$current{$type}.'</td>'."\n".
                   2700:                               '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145     raeburn  2701:             }
                   2702:             $itemcount ++;
                   2703:         }
                   2704:     }
                   2705:     $$rowtotal += $itemcount;
                   2706:     return $datatable;
                   2707: }
                   2708: 
1.152     raeburn  2709: sub possible_newspares {
                   2710:     my ($server,$currspares,$serverhomes,$altids) = @_;
                   2711:     my $serverhostname = &Apache::lonnet::hostname($server);
                   2712:     my %excluded;
                   2713:     if ($serverhostname ne '') {
                   2714:         %excluded = (
                   2715:                        $serverhostname => 1,
                   2716:                     );
                   2717:     }
                   2718:     if (ref($currspares) eq 'HASH') {
                   2719:         foreach my $type (keys(%{$currspares})) {
                   2720:             if (ref($currspares->{$type}) eq 'ARRAY') {
                   2721:                 if (@{$currspares->{$type}} > 0) {
                   2722:                     foreach my $curr (@{$currspares->{$type}}) {
                   2723:                         my $hostname = &Apache::lonnet::hostname($curr);
                   2724:                         $excluded{$hostname} = 1;
                   2725:                     }
                   2726:                 }
                   2727:             }
                   2728:         }
                   2729:     }
                   2730:     my @choices;
                   2731:     if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
                   2732:         if (keys(%{$serverhomes}) > 1) {
                   2733:             foreach my $name (sort(keys(%{$serverhomes}))) {
                   2734:                 unless ($excluded{$name}) {
                   2735:                     if (exists($altids->{$serverhomes->{$name}})) {
                   2736:                         push(@choices,$altids->{$serverhomes->{$name}});
                   2737:                     } else {
                   2738:                         push(@choices,$serverhomes->{$name});
1.145     raeburn  2739:                     }
                   2740:                 }
                   2741:             }
                   2742:         }
                   2743:     }
1.152     raeburn  2744:     return sort(@choices);
1.145     raeburn  2745: }
                   2746: 
1.150     raeburn  2747: sub print_loadbalancing {
                   2748:     my ($dom,$settings,$rowtotal) = @_;
                   2749:     my $primary_id = &Apache::lonnet::domain($dom,'primary');
                   2750:     my $intdom = &Apache::lonnet::internet_dom($primary_id);
                   2751:     my $numinrow = 1;
                   2752:     my $datatable;
                   2753:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
                   2754:     my ($currbalancer,$currtargets,$currrules);
                   2755:     if (keys(%servers) > 1) {
                   2756:         if (ref($settings) eq 'HASH') {
                   2757:             $currbalancer = $settings->{'lonhost'};
                   2758:             $currtargets = $settings->{'targets'};
                   2759:             $currrules = $settings->{'rules'};
                   2760:         } else {
                   2761:             ($currbalancer,$currtargets) = 
                   2762:                 &Apache::lonnet::get_lonbalancer_config(\%servers);
                   2763:         }
                   2764:     } else {
                   2765:         return;
                   2766:     }
                   2767:     my ($othertitle,$usertypes,$types) =
                   2768:         &Apache::loncommon::sorted_inst_types($dom);
                   2769:     my $rownum = 6;
                   2770:     if (ref($types) eq 'ARRAY') {
                   2771:         $rownum += scalar(@{$types});
                   2772:     }
1.153     raeburn  2773:     my $css_class = ' class="LC_odd_row"';
1.150     raeburn  2774:     my $targets_div_style = 'display: none';
                   2775:     my $disabled_div_style = 'display: block';
                   2776:     my $homedom_div_style = 'display: none';
                   2777:     $datatable = '<tr'.$css_class.'>'.
                   2778:                  '<td rowspan="'.$rownum.'" valign="top">'.
                   2779:                  '<p><select name="loadbalancing_lonhost" onchange="toggleTargets();">'."\n".
                   2780:                  '<option value=""';
                   2781:     if (($currbalancer eq '') || (!grep(/^\Q$currbalancer\E$/,keys(%servers)))) {
                   2782:         $datatable .= ' selected="selected"';
                   2783:     } else {
                   2784:         $targets_div_style = 'display: block';
                   2785:         $disabled_div_style = 'display: none';
                   2786:         if ($dom eq &Apache::lonnet::host_domain($currbalancer)) {
                   2787:             $homedom_div_style = 'display: block'; 
                   2788:         }
                   2789:     }
                   2790:     $datatable .= '>'.&mt('None').'</option>'."\n";
                   2791:     foreach my $lonhost (sort(keys(%servers))) {
                   2792:         my $selected;
                   2793:         if ($lonhost eq $currbalancer) {
                   2794:             $selected .= ' selected="selected"';
                   2795:         }
                   2796:         $datatable .= '<option value="'.$lonhost.'"'.$selected.'>'.$lonhost.'</option>'."\n";
                   2797:     }
                   2798:     $datatable .= '</select></p></td><td rowspan="'.$rownum.'" valign="top">'.
                   2799:                   '<div id="loadbalancing_disabled" style="'.$disabled_div_style.'">'.&mt('No dedicated Load Balancer').'</div>'."\n".
                   2800:                   '<div id="loadbalancing_targets" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
                   2801:     my ($numspares,@spares) = &count_servers($currbalancer,%servers);
                   2802:     my @sparestypes = ('primary','default');
                   2803:     my %typetitles = &sparestype_titles();
                   2804:     foreach my $sparetype (@sparestypes) {
                   2805:         my $targettable;
                   2806:         for (my $i=0; $i<$numspares; $i++) {
                   2807:             my $checked;
                   2808:             if (ref($currtargets) eq 'HASH') {
                   2809:                 if (ref($currtargets->{$sparetype}) eq 'ARRAY') {
                   2810:                     if (grep(/^\Q$spares[$i]\E$/,@{$currtargets->{$sparetype}})) {
                   2811:                         $checked = ' checked="checked"';
                   2812:                     }
                   2813:                 }
                   2814:             }
                   2815:             my $chkboxval;
                   2816:             if (($currbalancer ne '') && (grep((/^\Q$currbalancer\E$/,keys(%servers))))) {
                   2817:                 $chkboxval = $spares[$i];
                   2818:             }
                   2819:             $targettable .= '<td><label><input type="checkbox" name="loadbalancing_target_'.$sparetype.'"'.
                   2820:                       $checked.' value="'.$chkboxval.'" id="loadbalancing_target_'.$sparetype.'_'.$i.'" onclick="checkOffloads('."this,'$sparetype'".');" /><span id="loadbalancing_targettxt_'.$sparetype.'_'.$i.'">&nbsp;'.$chkboxval.
                   2821:                       '</span></label></td>';
                   2822:             my $rem = $i%($numinrow);
                   2823:             if ($rem == 0) {
                   2824:                 if ($i > 0) {
                   2825:                     $targettable .= '</tr>';
                   2826:                 }
                   2827:                 $targettable .= '<tr>';
                   2828:             }
                   2829:         }
                   2830:         if ($targettable ne '') {
                   2831:             my $rem = $numspares%($numinrow);
                   2832:             my $colsleft = $numinrow - $rem;
                   2833:             if ($colsleft > 1 ) {
                   2834:                 $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   2835:                                 '&nbsp;</td>';
                   2836:             } elsif ($colsleft == 1) {
                   2837:                 $targettable .= '<td class="LC_left_item">&nbsp;</td>';
                   2838:             }
                   2839:             $datatable .=  '<i>'.$typetitles{$sparetype}.'</i><br />'.
                   2840:                            '<table><tr>'.$targettable.'</table><br />';
                   2841:         }
                   2842:     }
                   2843:     $datatable .= '</div></td></tr>'.
                   2844:                   &loadbalancing_rules($dom,$intdom,$currrules,$othertitle,
                   2845:                                        $usertypes,$types,\%servers,$currbalancer,
1.153     raeburn  2846:                                        $targets_div_style,$homedom_div_style,$css_class);
1.150     raeburn  2847:     $$rowtotal += $rownum;
                   2848:     return $datatable;
                   2849: }
                   2850: 
                   2851: sub loadbalancing_rules {
                   2852:     my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.153     raeburn  2853:         $currbalancer,$targets_div_style,$homedom_div_style,$css_class) = @_;
1.150     raeburn  2854:     my $output;
                   2855:     my ($alltypes,$othertypes,$titles) = 
                   2856:         &loadbalancing_titles($dom,$intdom,$usertypes,$types);
                   2857:     if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH'))  {
                   2858:         foreach my $type (@{$alltypes}) {
                   2859:             my $current;
                   2860:             if (ref($currrules) eq 'HASH') {
                   2861:                 $current = $currrules->{$type};
                   2862:             }
                   2863:             if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
                   2864:                 if ($dom ne &Apache::lonnet::host_domain($currbalancer)) {
                   2865:                     $current = '';
                   2866:                 }
                   2867:             }
                   2868:             $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
                   2869:                                              $servers,$currbalancer,$dom,
1.153     raeburn  2870:                                              $targets_div_style,$homedom_div_style,$css_class);
1.150     raeburn  2871:         }
                   2872:     }
                   2873:     return $output;
                   2874: }
                   2875: 
                   2876: sub loadbalancing_titles {
                   2877:     my ($dom,$intdom,$usertypes,$types) = @_;
                   2878:     my %othertypes = (
                   2879:            '_LC_adv'         => &mt('Advanced users from [_1]',$dom),
                   2880:            '_LC_author'      => &mt('Users from [_1] with author role',$dom),
                   2881:            '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
                   2882:            '_LC_external'    => &mt('Users not from [_1]',$intdom),
                   2883:                      );
                   2884:     my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external');
                   2885:     if (ref($types) eq 'ARRAY') {
                   2886:         unshift(@alltypes,@{$types},'default');
                   2887:     }
                   2888:     my %titles;
                   2889:     foreach my $type (@alltypes) {
                   2890:         if ($type =~ /^_LC_/) {
                   2891:             $titles{$type} = $othertypes{$type};
                   2892:         } elsif ($type eq 'default') {
                   2893:             $titles{$type} = &mt('All users from [_1]',$dom);
                   2894:             if (ref($types) eq 'ARRAY') {
                   2895:                 if (@{$types} > 0) {
                   2896:                     $titles{$type} = &mt('Other users from [_1]',$dom);
                   2897:                 }
                   2898:             }
                   2899:         } elsif (ref($usertypes) eq 'HASH') {
                   2900:             $titles{$type} = $usertypes->{$type};
                   2901:         }
                   2902:     }
                   2903:     return (\@alltypes,\%othertypes,\%titles);
                   2904: }
                   2905: 
                   2906: sub loadbalance_rule_row {
                   2907:     my ($type,$title,$current,$servers,$currbalancer,$dom,$targets_div_style,
1.153     raeburn  2908:         $homedom_div_style,$css_class) = @_;
1.150     raeburn  2909:     my @rulenames = ('default','homeserver');
                   2910:     my %ruletitles = &offloadtype_text();
                   2911:     if ($type eq '_LC_external') {
                   2912:         push(@rulenames,'externalbalancer');
                   2913:     } else {
                   2914:         push(@rulenames,'specific');
                   2915:     }
                   2916:     my $style = $targets_div_style;
                   2917:     if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
                   2918:         $style = $homedom_div_style;
                   2919:     }
                   2920:     my $output = 
1.153     raeburn  2921:         '<tr'.$css_class.'><td valign="top"><div id="balanceruletitle_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
1.150     raeburn  2922:         '<td><div id="balancerule_'.$type.'" style="'.$style.'">'."\n";
                   2923:     for (my $i=0; $i<@rulenames; $i++) {
                   2924:         my $rule = $rulenames[$i];
                   2925:         my ($checked,$extra);
                   2926:         if ($rulenames[$i] eq 'default') {
                   2927:             $rule = '';
                   2928:         }
                   2929:         if ($rulenames[$i] eq 'specific') {
                   2930:             if (ref($servers) eq 'HASH') {
                   2931:                 my $default;
                   2932:                 if (($current ne '') && (exists($servers->{$current}))) {
                   2933:                     $checked = ' checked="checked"';
                   2934:                 }
                   2935:                 unless ($checked) {
                   2936:                     $default = ' selected="selected"';
                   2937:                 }
                   2938:                 $extra = ':&nbsp;<select name="loadbalancing_singleserver_'.$type.
                   2939:                          '" id="loadbalancing_singleserver_'.$type.
                   2940:                          '" onchange="singleServerToggle('."'$type'".')">'."\n".
                   2941:                          '<option value=""'.$default.'></option>'."\n";
                   2942:                 foreach my $lonhost (sort(keys(%{$servers}))) {
                   2943:                     next if ($lonhost eq $currbalancer);
                   2944:                     my $selected;
                   2945:                     if ($lonhost eq $current) {
                   2946:                         $selected = ' selected="selected"';
                   2947:                     }
                   2948:                     $extra .= '<option value="'.$lonhost.'"'.$selected.'>'.$lonhost.'</option>';
                   2949:                 }
                   2950:                 $extra .= '</select>';
                   2951:             }
                   2952:         } elsif ($rule eq $current) {
                   2953:             $checked = ' checked="checked"';
                   2954:         }
                   2955:         $output .= '<span class="LC_nobreak"><label>'.
                   2956:                    '<input type="radio" name="loadbalancing_rules_'.$type.
                   2957:                    '" id="loadbalancing_rules_'.$type.'_'.$i.'" value="'.
                   2958:                    $rule.'" onclick="balanceruleChange('."this.form,'$type'".
                   2959:                    ')"'.$checked.' />&nbsp;'.$ruletitles{$rulenames[$i]}.
                   2960:                    '</label>'.$extra.'</span><br />'."\n";
                   2961:     }
                   2962:     $output .= '</div></td></tr>'."\n";
                   2963:     return $output;
                   2964: }
                   2965: 
                   2966: sub offloadtype_text {
                   2967:     my %ruletitles = &Apache::lonlocal::texthash (
                   2968:            'default'          => 'Offloads to default destinations',
                   2969:            'homeserver'       => "Offloads to user's home server",
                   2970:            'externalbalancer' => "Offloads to Load Balancer in user's domain",
                   2971:            'specific'         => 'Offloads to specific server',
                   2972:     );
                   2973:     return %ruletitles;
                   2974: }
                   2975: 
                   2976: sub sparestype_titles {
                   2977:     my %typestitles = &Apache::lonlocal::texthash (
                   2978:                           'primary' => 'primary',
                   2979:                           'default' => 'default',
                   2980:                       );
                   2981:     return %typestitles;
                   2982: }
                   2983: 
1.28      raeburn  2984: sub contact_titles {
                   2985:     my %titles = &Apache::lonlocal::texthash (
                   2986:                    'supportemail' => 'Support E-mail address',
1.69      raeburn  2987:                    'adminemail'   => 'Default Server Admin E-mail address',
1.28      raeburn  2988:                    'errormail'    => 'Error reports to be e-mailed to',
                   2989:                    'packagesmail' => 'Package update alerts to be e-mailed to',
1.89      raeburn  2990:                    'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
                   2991:                    'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
1.102     raeburn  2992:                    'requestsmail' => 'E-mail from course requests requiring approval',
1.28      raeburn  2993:                  );
                   2994:     my %short_titles = &Apache::lonlocal::texthash (
                   2995:                            adminemail   => 'Admin E-mail address',
                   2996:                            supportemail => 'Support E-mail',
                   2997:                        );   
                   2998:     return (\%titles,\%short_titles);
                   2999: }
                   3000: 
1.72      raeburn  3001: sub tool_titles {
                   3002:     my %titles = &Apache::lonlocal::texthash (
1.90      weissno  3003:                      aboutme    => 'Personal Information Page',
1.86      raeburn  3004:                      blog       => 'Blog',
                   3005:                      portfolio  => 'Portfolio',
1.88      bisitz   3006:                      official   => 'Official courses (with institutional codes)',
                   3007:                      unofficial => 'Unofficial courses',
1.98      raeburn  3008:                      community  => 'Communities',
1.86      raeburn  3009:                  );
1.72      raeburn  3010:     return %titles;
                   3011: }
                   3012: 
1.101     raeburn  3013: sub courserequest_titles {
                   3014:     my %titles = &Apache::lonlocal::texthash (
                   3015:                                    official   => 'Official',
                   3016:                                    unofficial => 'Unofficial',
                   3017:                                    community  => 'Communities',
                   3018:                                    norequest  => 'Not allowed',
1.104     raeburn  3019:                                    approval   => 'Approval by Dom. Coord.',
1.101     raeburn  3020:                                    validate   => 'With validation',
                   3021:                                    autolimit  => 'Numerical limit',
1.103     raeburn  3022:                                    unlimited  => '(blank for unlimited)',
1.101     raeburn  3023:                  );
                   3024:     return %titles;
                   3025: }
                   3026: 
                   3027: sub courserequest_conditions {
                   3028:     my %conditions = &Apache::lonlocal::texthash (
1.104     raeburn  3029:        approval    => '(Processing of request subject to approval by Domain Coordinator).',
1.101     raeburn  3030:        validate   => '(Processing of request subject to instittutional validation).',
                   3031:                  );
                   3032:     return %conditions;
                   3033: }
                   3034: 
                   3035: 
1.27      raeburn  3036: sub print_usercreation {
1.30      raeburn  3037:     my ($position,$dom,$settings,$rowtotal) = @_;
1.27      raeburn  3038:     my $numinrow = 4;
1.28      raeburn  3039:     my $datatable;
                   3040:     if ($position eq 'top') {
1.30      raeburn  3041:         $$rowtotal ++;
1.34      raeburn  3042:         my $rowcount = 0;
1.32      raeburn  3043:         my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28      raeburn  3044:         if (ref($rules) eq 'HASH') {
                   3045:             if (keys(%{$rules}) > 0) {
1.32      raeburn  3046:                 $datatable .= &user_formats_row('username',$settings,$rules,
                   3047:                                                 $ruleorder,$numinrow,$rowcount);
1.30      raeburn  3048:                 $$rowtotal ++;
1.32      raeburn  3049:                 $rowcount ++;
                   3050:             }
                   3051:         }
                   3052:         my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
                   3053:         if (ref($idrules) eq 'HASH') {
                   3054:             if (keys(%{$idrules}) > 0) {
                   3055:                 $datatable .= &user_formats_row('id',$settings,$idrules,
                   3056:                                                 $idruleorder,$numinrow,$rowcount);
                   3057:                 $$rowtotal ++;
                   3058:                 $rowcount ++;
1.28      raeburn  3059:             }
                   3060:         }
1.43      raeburn  3061:         my ($emailrules,$emailruleorder) = 
                   3062:             &Apache::lonnet::inst_userrules($dom,'email');
                   3063:         if (ref($emailrules) eq 'HASH') {
                   3064:             if (keys(%{$emailrules}) > 0) {
                   3065:                 $datatable .= &user_formats_row('email',$settings,$emailrules,
                   3066:                                                 $emailruleorder,$numinrow,$rowcount);
                   3067:                 $$rowtotal ++;
                   3068:                 $rowcount ++;
                   3069:             }
                   3070:         }
1.39      raeburn  3071:         if ($rowcount == 0) {
                   3072:             $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';  
                   3073:             $$rowtotal ++;
                   3074:             $rowcount ++;
                   3075:         }
1.34      raeburn  3076:     } elsif ($position eq 'middle') {
1.100     raeburn  3077:         my @creators = ('author','course','requestcrs','selfcreate');
1.37      raeburn  3078:         my ($rules,$ruleorder) =
                   3079:             &Apache::lonnet::inst_userrules($dom,'username');
1.34      raeburn  3080:         my %lt = &usercreation_types();
                   3081:         my %checked;
1.50      raeburn  3082:         my @selfcreate; 
1.34      raeburn  3083:         if (ref($settings) eq 'HASH') {
                   3084:             if (ref($settings->{'cancreate'}) eq 'HASH') {
                   3085:                 foreach my $item (@creators) {
                   3086:                     $checked{$item} = $settings->{'cancreate'}{$item};
                   3087:                 }
1.50      raeburn  3088:                 if (ref($settings->{'cancreate'}{'selfcreate'}) eq 'ARRAY') {
                   3089:                     @selfcreate = @{$settings->{'cancreate'}{'selfcreate'}};
                   3090:                 } elsif ($settings->{'cancreate'}{'selfcreate'} ne '') {
                   3091:                     if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
                   3092:                         @selfcreate = ('email','login','sso');
                   3093:                     } elsif ($settings->{'cancreate'}{'selfcreate'} ne 'none') {
                   3094:                         @selfcreate = ($settings->{'cancreate'}{'selfcreate'});
                   3095:                     }
                   3096:                 }
1.34      raeburn  3097:             } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
                   3098:                 foreach my $item (@creators) {
                   3099:                     if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
                   3100:                         $checked{$item} = 'none';
                   3101:                     }
                   3102:                 }
                   3103:             }
                   3104:         }
                   3105:         my $rownum = 0;
                   3106:         foreach my $item (@creators) {
                   3107:             $rownum ++;
1.50      raeburn  3108:             if ($item ne 'selfcreate') {  
                   3109:                 if ($checked{$item} eq '') {
1.43      raeburn  3110:                     $checked{$item} = 'any';
                   3111:                 }
1.34      raeburn  3112:             }
                   3113:             my $css_class;
                   3114:             if ($rownum%2) {
                   3115:                 $css_class = '';
                   3116:             } else {
                   3117:                 $css_class = ' class="LC_odd_row" ';
                   3118:             }
                   3119:             $datatable .= '<tr'.$css_class.'>'.
                   3120:                          '<td><span class="LC_nobreak">'.$lt{$item}.
                   3121:                          '</span></td><td align="right">';
1.50      raeburn  3122:             my @options;
1.45      raeburn  3123:             if ($item eq 'selfcreate') {
1.43      raeburn  3124:                 push(@options,('email','login','sso'));
                   3125:             } else {
1.50      raeburn  3126:                 @options = ('any');
1.43      raeburn  3127:                 if (ref($rules) eq 'HASH') {
                   3128:                     if (keys(%{$rules}) > 0) {
                   3129:                         push(@options,('official','unofficial'));
                   3130:                     }
1.37      raeburn  3131:                 }
1.50      raeburn  3132:                 push(@options,'none');
1.37      raeburn  3133:             }
                   3134:             foreach my $option (@options) {
1.50      raeburn  3135:                 my $type = 'radio';
1.34      raeburn  3136:                 my $check = ' ';
1.50      raeburn  3137:                 if ($item eq 'selfcreate') {
                   3138:                     $type = 'checkbox';
                   3139:                     if (grep(/^\Q$option\E$/,@selfcreate)) {
                   3140:                         $check = ' checked="checked" ';
                   3141:                     }
                   3142:                 } else {
                   3143:                     if ($checked{$item} eq $option) {
                   3144:                         $check = ' checked="checked" ';
                   3145:                     }
1.34      raeburn  3146:                 } 
                   3147:                 $datatable .= '<span class="LC_nobreak"><label>'.
1.50      raeburn  3148:                               '<input type="'.$type.'" name="can_createuser_'.
1.34      raeburn  3149:                               $item.'" value="'.$option.'"'.$check.'/>&nbsp;'.
                   3150:                               $lt{$option}.'</label>&nbsp;&nbsp;</span>';
                   3151:             }
                   3152:             $datatable .= '</td></tr>';
                   3153:         }
1.93      raeburn  3154:         my ($othertitle,$usertypes,$types) =
                   3155:             &Apache::loncommon::sorted_inst_types($dom);
                   3156:         if (ref($usertypes) eq 'HASH') {
                   3157:             if (keys(%{$usertypes}) > 0) {
1.99      raeburn  3158:                 my $createsettings;
                   3159:                 if (ref($settings) eq 'HASH') {
                   3160:                     $createsettings = $settings->{cancreate};
                   3161:                 }
                   3162:                 $datatable .= &insttypes_row($createsettings,$types,$usertypes,
1.93      raeburn  3163:                                              $dom,$numinrow,$othertitle,
                   3164:                                              'statustocreate');
                   3165:                 $$rowtotal ++;
                   3166:             }
                   3167:         }
1.28      raeburn  3168:     } else {
                   3169:         my @contexts = ('author','course','domain');
                   3170:         my @authtypes = ('int','krb4','krb5','loc');
                   3171:         my %checked;
                   3172:         if (ref($settings) eq 'HASH') {
                   3173:             if (ref($settings->{'authtypes'}) eq 'HASH') {
                   3174:                 foreach my $item (@contexts) {
                   3175:                     if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
                   3176:                         foreach my $auth (@authtypes) {
                   3177:                             if ($settings->{'authtypes'}{$item}{$auth}) {
                   3178:                                 $checked{$item}{$auth} = ' checked="checked" ';
                   3179:                             }
                   3180:                         }
                   3181:                     }
                   3182:                 }
1.27      raeburn  3183:             }
1.35      raeburn  3184:         } else {
                   3185:             foreach my $item (@contexts) {
1.36      raeburn  3186:                 foreach my $auth (@authtypes) {
1.35      raeburn  3187:                     $checked{$item}{$auth} = ' checked="checked" ';
                   3188:                 }
                   3189:             }
1.27      raeburn  3190:         }
1.28      raeburn  3191:         my %title = &context_names();
                   3192:         my %authname = &authtype_names();
                   3193:         my $rownum = 0;
                   3194:         my $css_class; 
                   3195:         foreach my $item (@contexts) {
                   3196:             if ($rownum%2) {
                   3197:                 $css_class = '';
                   3198:             } else {
                   3199:                 $css_class = ' class="LC_odd_row" ';
                   3200:             }
1.30      raeburn  3201:             $datatable .=   '<tr'.$css_class.'>'.
1.28      raeburn  3202:                             '<td>'.$title{$item}.
                   3203:                             '</td><td class="LC_left_item">'.
                   3204:                             '<span class="LC_nobreak">';
                   3205:             foreach my $auth (@authtypes) {
                   3206:                 $datatable .= '<label>'. 
                   3207:                               '<input type="checkbox" name="'.$item.'_auth" '.
                   3208:                               $checked{$item}{$auth}.' value="'.$auth.'" />'.
                   3209:                               $authname{$auth}.'</label>&nbsp;';
                   3210:             }
                   3211:             $datatable .= '</span></td></tr>';
                   3212:             $rownum ++;
1.27      raeburn  3213:         }
1.30      raeburn  3214:         $$rowtotal += $rownum;
1.27      raeburn  3215:     }
                   3216:     return $datatable;
                   3217: }
                   3218: 
1.32      raeburn  3219: sub user_formats_row {
                   3220:     my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
                   3221:     my $output;
                   3222:     my %text = (
                   3223:                    'username' => 'new usernames',
                   3224:                    'id'       => 'IDs',
1.45      raeburn  3225:                    'email'    => 'self-created accounts (e-mail)',
1.32      raeburn  3226:                );
                   3227:     my $css_class = $rowcount%2?' class="LC_odd_row"':'';
                   3228:     $output = '<tr '.$css_class.'>'.
1.63      raeburn  3229:               '<td><span class="LC_nobreak">';
                   3230:     if ($type eq 'email') {
                   3231:         $output .= &mt("Formats disallowed for $text{$type}: ");
                   3232:     } else {
                   3233:         $output .= &mt("Format rules to check for $text{$type}: ");
                   3234:     }
                   3235:     $output .= '</span></td>'.
                   3236:                '<td class="LC_left_item" colspan="2"><table>';
1.27      raeburn  3237:     my $rem;
                   3238:     if (ref($ruleorder) eq 'ARRAY') {
                   3239:         for (my $i=0; $i<@{$ruleorder}; $i++) {
                   3240:             if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
                   3241:                 my $rem = $i%($numinrow);
                   3242:                 if ($rem == 0) {
                   3243:                     if ($i > 0) {
                   3244:                         $output .= '</tr>';
                   3245:                     }
                   3246:                     $output .= '<tr>';
                   3247:                 }
                   3248:                 my $check = ' ';
1.39      raeburn  3249:                 if (ref($settings) eq 'HASH') {
                   3250:                     if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
                   3251:                         if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
                   3252:                             $check = ' checked="checked" ';
                   3253:                         }
1.27      raeburn  3254:                     }
                   3255:                 }
                   3256:                 $output .= '<td class="LC_left_item">'.
                   3257:                            '<span class="LC_nobreak"><label>'.
1.32      raeburn  3258:                            '<input type="checkbox" name="'.$type.'_rule" '.
1.27      raeburn  3259:                            'value="'.$ruleorder->[$i].'"'.$check.'/>'.
                   3260:                            $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
                   3261:             }
                   3262:         }
                   3263:         $rem = @{$ruleorder}%($numinrow);
                   3264:     }
                   3265:     my $colsleft = $numinrow - $rem;
                   3266:     if ($colsleft > 1 ) {
                   3267:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   3268:                    '&nbsp;</td>';
                   3269:     } elsif ($colsleft == 1) {
                   3270:         $output .= '<td class="LC_left_item">&nbsp;</td>';
                   3271:     }
                   3272:     $output .= '</tr></table></td></tr>';
                   3273:     return $output;
                   3274: }
                   3275: 
1.34      raeburn  3276: sub usercreation_types {
                   3277:     my %lt = &Apache::lonlocal::texthash (
                   3278:                     author     => 'When adding a co-author',
                   3279:                     course     => 'When adding a user to a course',
1.100     raeburn  3280:                     requestcrs => 'When requesting a course',
1.45      raeburn  3281:                     selfcreate => 'User creates own account', 
1.34      raeburn  3282:                     any        => 'Any',
                   3283:                     official   => 'Institutional only ',
                   3284:                     unofficial => 'Non-institutional only',
1.85      schafran 3285:                     email      => 'E-mail address',
1.43      raeburn  3286:                     login      => 'Institutional Login',
                   3287:                     sso        => 'SSO', 
1.34      raeburn  3288:                     none       => 'None',
                   3289:     );
                   3290:     return %lt;
1.48      raeburn  3291: }
1.34      raeburn  3292: 
1.28      raeburn  3293: sub authtype_names {
                   3294:     my %lt = &Apache::lonlocal::texthash(
                   3295:                       int    => 'Internal',
                   3296:                       krb4   => 'Kerberos 4',
                   3297:                       krb5   => 'Kerberos 5',
                   3298:                       loc    => 'Local',
                   3299:                   );
                   3300:     return %lt;
                   3301: }
                   3302: 
                   3303: sub context_names {
                   3304:     my %context_title = &Apache::lonlocal::texthash(
                   3305:        author => 'Creating users when an Author',
                   3306:        course => 'Creating users when in a course',
                   3307:        domain => 'Creating users when a Domain Coordinator',
                   3308:     );
                   3309:     return %context_title;
                   3310: }
                   3311: 
1.33      raeburn  3312: sub print_usermodification {
                   3313:     my ($position,$dom,$settings,$rowtotal) = @_;
                   3314:     my $numinrow = 4;
                   3315:     my ($context,$datatable,$rowcount);
                   3316:     if ($position eq 'top') {
                   3317:         $rowcount = 0;
                   3318:         $context = 'author'; 
                   3319:         foreach my $role ('ca','aa') {
                   3320:             $datatable .= &modifiable_userdata_row($context,$role,$settings,
                   3321:                                                    $numinrow,$rowcount);
                   3322:             $$rowtotal ++;
                   3323:             $rowcount ++;
                   3324:         }
1.63      raeburn  3325:     } elsif ($position eq 'middle') {
1.33      raeburn  3326:         $context = 'course';
                   3327:         $rowcount = 0;
                   3328:         foreach my $role ('st','ep','ta','in','cr') {
                   3329:             $datatable .= &modifiable_userdata_row($context,$role,$settings,
                   3330:                                                    $numinrow,$rowcount);
                   3331:             $$rowtotal ++;
                   3332:             $rowcount ++;
                   3333:         }
1.63      raeburn  3334:     } elsif ($position eq 'bottom') {
                   3335:         $context = 'selfcreate';
                   3336:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   3337:         $usertypes->{'default'} = $othertitle;
                   3338:         if (ref($types) eq 'ARRAY') {
                   3339:             push(@{$types},'default');
                   3340:             $usertypes->{'default'} = $othertitle;
                   3341:             foreach my $status (@{$types}) {
                   3342:                 $datatable .= &modifiable_userdata_row($context,$status,$settings,
                   3343:                                                        $numinrow,$rowcount,$usertypes);
                   3344:                 $$rowtotal ++;
                   3345:                 $rowcount ++;
                   3346:             }
                   3347:         }
1.33      raeburn  3348:     }
                   3349:     return $datatable;
                   3350: }
                   3351: 
1.43      raeburn  3352: sub print_defaults {
                   3353:     my ($dom,$rowtotal) = @_;
1.68      raeburn  3354:     my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
1.141     raeburn  3355:                  'datelocale_def','portal_def');
1.43      raeburn  3356:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.141     raeburn  3357:     my $titles = &defaults_titles($dom);
1.43      raeburn  3358:     my $rownum = 0;
                   3359:     my ($datatable,$css_class);
                   3360:     foreach my $item (@items) {
                   3361:         if ($rownum%2) {
                   3362:             $css_class = '';
                   3363:         } else {
                   3364:             $css_class = ' class="LC_odd_row" ';
                   3365:         }
                   3366:         $datatable .= '<tr'.$css_class.'>'.
                   3367:                   '<td><span class="LC_nobreak">'.$titles->{$item}.
                   3368:                   '</span></td><td class="LC_right_item">';
                   3369:         if ($item eq 'auth_def') {
                   3370:             my @authtypes = ('internal','krb4','krb5','localauth');
                   3371:             my %shortauth = (
                   3372:                              internal => 'int',
                   3373:                              krb4 => 'krb4',
                   3374:                              krb5 => 'krb5',
                   3375:                              localauth  => 'loc'
                   3376:                            );
                   3377:             my %authnames = &authtype_names();
                   3378:             foreach my $auth (@authtypes) {
                   3379:                 my $checked = ' ';
                   3380:                 if ($domdefaults{$item} eq $auth) {
                   3381:                     $checked = ' checked="checked" ';
                   3382:                 }
                   3383:                 $datatable .= '<label><input type="radio" name="'.$item.
                   3384:                               '" value="'.$auth.'"'.$checked.'/>'.
                   3385:                               $authnames{$shortauth{$auth}}.'</label>&nbsp;&nbsp;';
                   3386:             }
1.54      raeburn  3387:         } elsif ($item eq 'timezone_def') {
                   3388:             my $includeempty = 1;
                   3389:             $datatable .= &Apache::loncommon::select_timezone($item,$domdefaults{$item},undef,$includeempty);
1.68      raeburn  3390:         } elsif ($item eq 'datelocale_def') {
                   3391:             my $includeempty = 1;
                   3392:             $datatable .= &Apache::loncommon::select_datelocale($item,$domdefaults{$item},undef,$includeempty);
1.43      raeburn  3393:         } else {
1.141     raeburn  3394:             my $size;
                   3395:             if ($item eq 'portal_def') {
                   3396:                 $size = ' size="25"';
                   3397:             }
1.43      raeburn  3398:             $datatable .= '<input type="text" name="'.$item.'" value="'.
1.141     raeburn  3399:                           $domdefaults{$item}.'"'.$size.' />';
1.43      raeburn  3400:         }
                   3401:         $datatable .= '</td></tr>';
                   3402:         $rownum ++;
                   3403:     }
                   3404:     $$rowtotal += $rownum;
                   3405:     return $datatable;
                   3406: }
                   3407: 
                   3408: sub defaults_titles {
1.141     raeburn  3409:     my ($dom) = @_;
1.43      raeburn  3410:     my %titles = &Apache::lonlocal::texthash (
                   3411:                    'auth_def'      => 'Default authentication type',
                   3412:                    'auth_arg_def'  => 'Default authentication argument',
                   3413:                    'lang_def'      => 'Default language',
1.54      raeburn  3414:                    'timezone_def'  => 'Default timezone',
1.68      raeburn  3415:                    'datelocale_def' => 'Default locale for dates',
1.141     raeburn  3416:                    'portal_def'     => 'Portal/Default URL',
1.43      raeburn  3417:                  );
1.141     raeburn  3418:     if ($dom) {
                   3419:         my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
                   3420:         my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
                   3421:         my $protocol = $Apache::lonnet::protocol{$uprimary_id};
                   3422:         $protocol = 'http' if ($protocol ne 'https');
                   3423:         if ($uint_dom) {
                   3424:             $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
                   3425:                                          $uint_dom);
                   3426:         }
                   3427:     }
1.43      raeburn  3428:     return (\%titles);
                   3429: }
                   3430: 
1.46      raeburn  3431: sub print_scantronformat {
                   3432:     my ($r,$dom,$confname,$settings,$rowtotal) = @_;
                   3433:     my $itemcount = 1;
1.60      raeburn  3434:     my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
                   3435:         %confhash);
1.46      raeburn  3436:     my $switchserver = &check_switchserver($dom,$confname);
                   3437:     my %lt = &Apache::lonlocal::texthash (
1.95      www      3438:                 default => 'Default bubblesheet format file error',
                   3439:                 custom  => 'Custom bubblesheet format file error',
1.46      raeburn  3440:              );
                   3441:     my %scantronfiles = (
                   3442:         default => 'default.tab',
                   3443:         custom => 'custom.tab',
                   3444:     );
                   3445:     foreach my $key (keys(%scantronfiles)) {
                   3446:         $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
                   3447:                               .$scantronfiles{$key};
                   3448:     }
                   3449:     my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
                   3450:     if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
                   3451:         if (!$switchserver) {
                   3452:             my $servadm = $r->dir_config('lonAdmEMail');
                   3453:             my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
                   3454:             if ($configuserok eq 'ok') {
                   3455:                 if ($author_ok eq 'ok') {
                   3456:                     my %legacyfile = (
                   3457:  default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab', 
                   3458:  custom  => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab', 
                   3459:                     );
                   3460:                     my %md5chk;
                   3461:                     foreach my $type (keys(%legacyfile)) {
1.60      raeburn  3462:                         ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
                   3463:                         chomp($md5chk{$type});
1.46      raeburn  3464:                     }
                   3465:                     if ($md5chk{'default'} ne $md5chk{'custom'}) {
                   3466:                         foreach my $type (keys(%legacyfile)) {
1.60      raeburn  3467:                             ($scantronurls{$type},my $error) = 
1.46      raeburn  3468:                                 &legacy_scantronformat($r,$dom,$confname,
                   3469:                                                  $type,$legacyfile{$type},
                   3470:                                                  $scantronurls{$type},
                   3471:                                                  $scantronfiles{$type});
1.60      raeburn  3472:                             if ($error ne '') {
                   3473:                                 $error{$type} = $error;
                   3474:                             }
                   3475:                         }
                   3476:                         if (keys(%error) == 0) {
                   3477:                             $is_custom = 1;
                   3478:                             $confhash{'scantron'}{'scantronformat'} = 
                   3479:                                 $scantronurls{'custom'};
                   3480:                             my $putresult = 
                   3481:                                 &Apache::lonnet::put_dom('configuration',
                   3482:                                                          \%confhash,$dom);
                   3483:                             if ($putresult ne 'ok') {
                   3484:                                 $error{'custom'} = 
                   3485:                                     '<span class="LC_error">'.
                   3486:                                     &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
                   3487:                             }
1.46      raeburn  3488:                         }
                   3489:                     } else {
1.60      raeburn  3490:                         ($scantronurls{'default'},my $error) =
1.46      raeburn  3491:                             &legacy_scantronformat($r,$dom,$confname,
                   3492:                                           'default',$legacyfile{'default'},
                   3493:                                           $scantronurls{'default'},
                   3494:                                           $scantronfiles{'default'});
1.60      raeburn  3495:                         if ($error eq '') {
                   3496:                             $confhash{'scantron'}{'scantronformat'} = ''; 
                   3497:                             my $putresult =
                   3498:                                 &Apache::lonnet::put_dom('configuration',
                   3499:                                                          \%confhash,$dom);
                   3500:                             if ($putresult ne 'ok') {
                   3501:                                 $error{'default'} =
                   3502:                                     '<span class="LC_error">'.
                   3503:                                     &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
                   3504:                             }
                   3505:                         } else {
                   3506:                             $error{'default'} = $error;
                   3507:                         }
1.46      raeburn  3508:                     }
                   3509:                 }
                   3510:             }
                   3511:         } else {
1.95      www      3512:             $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46      raeburn  3513:         }
                   3514:     }
                   3515:     if (ref($settings) eq 'HASH') {
                   3516:         if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
                   3517:             my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
                   3518:             if ((!@info) || ($info[0] eq 'no_such_dir')) {
                   3519:                 $scantronurl = '';
                   3520:             } else {
                   3521:                 $scantronurl = $settings->{'scantronformat'};
                   3522:             }
                   3523:             $is_custom = 1;
                   3524:         } else {
                   3525:             $scantronurl = $scantronurls{'default'};
                   3526:         }
                   3527:     } else {
1.60      raeburn  3528:         if ($is_custom) {
                   3529:             $scantronurl = $scantronurls{'custom'};
                   3530:         } else {
                   3531:             $scantronurl = $scantronurls{'default'};
                   3532:         }
1.46      raeburn  3533:     }
                   3534:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   3535:     $datatable .= '<tr'.$css_class.'>';
                   3536:     if (!$is_custom) {
1.65      raeburn  3537:         $datatable .= '<td>'.&mt('Default in use:').'<br />'.
                   3538:                       '<span class="LC_nobreak">';
1.46      raeburn  3539:         if ($scantronurl) {
                   3540:             $datatable .= '<a href="'.$scantronurl.'" target="_blank">'.
1.130     raeburn  3541:                           &mt('Default bubblesheet format file').'</a>';
1.46      raeburn  3542:         } else {
                   3543:             $datatable = &mt('File unavailable for display');
                   3544:         }
1.65      raeburn  3545:         $datatable .= '</span></td>';
1.60      raeburn  3546:         if (keys(%error) == 0) { 
                   3547:             $datatable .= '<td valign="bottom">';
                   3548:             if (!$switchserver) {
                   3549:                 $datatable .= &mt('Upload:').'<br />';
                   3550:             }
                   3551:         } else {
                   3552:             my $errorstr;
                   3553:             foreach my $key (sort(keys(%error))) {
                   3554:                 $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
                   3555:             }
                   3556:             $datatable .= '<td>'.$errorstr;
                   3557:         }
1.46      raeburn  3558:     } else {
                   3559:         if (keys(%error) > 0) {
                   3560:             my $errorstr;
                   3561:             foreach my $key (sort(keys(%error))) {
                   3562:                 $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
                   3563:             } 
1.60      raeburn  3564:             $datatable .= '<td>'.$errorstr.'</td><td>&nbsp;';
1.46      raeburn  3565:         } elsif ($scantronurl) {
1.65      raeburn  3566:             $datatable .= '<td><span class="LC_nobreak">'.
                   3567:                           '<a href="'.$scantronurl.'" target="_blank">'.
1.130     raeburn  3568:                           &mt('Custom bubblesheet format file').'</a><label>'.
1.65      raeburn  3569:                           '<input type="checkbox" name="scantronformat_del"'.
                   3570:                           '" value="1" />'.&mt('Delete?').'</label></span></td>'.
                   3571:                           '<td><span class="LC_nobreak">&nbsp;'.
                   3572:                           &mt('Replace:').'</span><br />';
1.46      raeburn  3573:         }
                   3574:     }
                   3575:     if (keys(%error) == 0) {
                   3576:         if ($switchserver) {
                   3577:             $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   3578:         } else {
1.65      raeburn  3579:             $datatable .='<span class="LC_nobreak">&nbsp;'.
                   3580:                          '<input type="file" name="scantronformat" /></span>';
1.46      raeburn  3581:         }
                   3582:     }
                   3583:     $datatable .= '</td></tr>';
                   3584:     $$rowtotal ++;
                   3585:     return $datatable;
                   3586: }
                   3587: 
                   3588: sub legacy_scantronformat {
                   3589:     my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
                   3590:     my ($url,$error);
                   3591:     my @statinfo = &Apache::lonnet::stat_file($newurl);
                   3592:     if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
                   3593:         (my $result,$url) =
                   3594:             &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
                   3595:                          '','',$newfile);
                   3596:         if ($result ne 'ok') {
1.130     raeburn  3597:             $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46      raeburn  3598:         }
                   3599:     }
                   3600:     return ($url,$error);
                   3601: }
1.43      raeburn  3602: 
1.49      raeburn  3603: sub print_coursecategories {
1.57      raeburn  3604:     my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
                   3605:     my $datatable;
                   3606:     if ($position eq 'top') {
                   3607:         my $toggle_cats_crs = ' ';
                   3608:         my $toggle_cats_dom = ' checked="checked" ';
                   3609:         my $can_cat_crs = ' ';
                   3610:         my $can_cat_dom = ' checked="checked" ';
1.120     raeburn  3611:         my $toggle_catscomm_comm = ' ';
                   3612:         my $toggle_catscomm_dom = ' checked="checked" ';
                   3613:         my $can_catcomm_comm = ' ';
                   3614:         my $can_catcomm_dom = ' checked="checked" ';
                   3615: 
1.57      raeburn  3616:         if (ref($settings) eq 'HASH') {
                   3617:             if ($settings->{'togglecats'} eq 'crs') {
                   3618:                 $toggle_cats_crs = $toggle_cats_dom;
                   3619:                 $toggle_cats_dom = ' ';
                   3620:             }
                   3621:             if ($settings->{'categorize'} eq 'crs') {
                   3622:                 $can_cat_crs = $can_cat_dom;
                   3623:                 $can_cat_dom = ' ';
                   3624:             }
1.120     raeburn  3625:             if ($settings->{'togglecatscomm'} eq 'comm') {
                   3626:                 $toggle_catscomm_comm = $toggle_catscomm_dom;
                   3627:                 $toggle_catscomm_dom = ' ';
                   3628:             }
                   3629:             if ($settings->{'categorizecomm'} eq 'comm') {
                   3630:                 $can_catcomm_comm = $can_catcomm_dom;
                   3631:                 $can_catcomm_dom = ' ';
                   3632:             }
1.57      raeburn  3633:         }
                   3634:         my %title = &Apache::lonlocal::texthash (
1.120     raeburn  3635:                      togglecats     => 'Show/Hide a course in catalog',
                   3636:                      togglecatscomm => 'Show/Hide a community in catalog',
                   3637:                      categorize     => 'Assign a category to a course',
                   3638:                      categorizecomm => 'Assign a category to a community',
1.57      raeburn  3639:                     );
                   3640:         my %level = &Apache::lonlocal::texthash (
1.120     raeburn  3641:                      dom  => 'Set in Domain',
                   3642:                      crs  => 'Set in Course',
                   3643:                      comm => 'Set in Community',
1.57      raeburn  3644:                     );
                   3645:         $datatable = '<tr class="LC_odd_row">'.
                   3646:                   '<td>'.$title{'togglecats'}.'</td>'.
                   3647:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   3648:                   '<input type="radio" name="togglecats"'.
                   3649:                   $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   3650:                   '<label><input type="radio" name="togglecats"'.
                   3651:                   $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
                   3652:                   '</tr><tr>'.
                   3653:                   '<td>'.$title{'categorize'}.'</td>'.
                   3654:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
                   3655:                   '<label><input type="radio" name="categorize"'.
                   3656:                   $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   3657:                   '<label><input type="radio" name="categorize"'.
                   3658:                   $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120     raeburn  3659:                   '</tr><tr class="LC_odd_row">'.
                   3660:                   '<td>'.$title{'togglecatscomm'}.'</td>'.
                   3661:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   3662:                   '<input type="radio" name="togglecatscomm"'.
                   3663:                   $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   3664:                   '<label><input type="radio" name="togglecatscomm"'.
                   3665:                   $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
                   3666:                   '</tr><tr>'.
                   3667:                   '<td>'.$title{'categorizecomm'}.'</td>'.
                   3668:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
                   3669:                   '<label><input type="radio" name="categorizecomm"'.
                   3670:                   $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   3671:                   '<label><input type="radio" name="categorizecomm"'.
                   3672:                   $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57      raeburn  3673:                   '</tr>';
1.120     raeburn  3674:         $$rowtotal += 4;
1.57      raeburn  3675:     } else {
                   3676:         my $css_class;
                   3677:         my $itemcount = 1;
                   3678:         my $cathash; 
                   3679:         if (ref($settings) eq 'HASH') {
                   3680:             $cathash = $settings->{'cats'};
                   3681:         }
                   3682:         if (ref($cathash) eq 'HASH') {
                   3683:             my (@cats,@trails,%allitems,%idx,@jsarray);
                   3684:             &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
                   3685:                                                    \%allitems,\%idx,\@jsarray);
                   3686:             my $maxdepth = scalar(@cats);
                   3687:             my $colattrib = '';
                   3688:             if ($maxdepth > 2) {
                   3689:                 $colattrib = ' colspan="2" ';
                   3690:             }
                   3691:             my @path;
                   3692:             if (@cats > 0) {
                   3693:                 if (ref($cats[0]) eq 'ARRAY') {
                   3694:                     my $numtop = @{$cats[0]};
                   3695:                     my $maxnum = $numtop;
1.120     raeburn  3696:                     my %default_names = (
                   3697:                           instcode    => &mt('Official courses'),
                   3698:                           communities => &mt('Communities'),
                   3699:                     );
                   3700: 
                   3701:                     if ((!grep(/^instcode$/,@{$cats[0]})) || 
                   3702:                         ($cathash->{'instcode::0'} eq '') ||
                   3703:                         (!grep(/^communities$/,@{$cats[0]})) || 
                   3704:                         ($cathash->{'communities::0'} eq '')) {
1.57      raeburn  3705:                         $maxnum ++;
                   3706:                     }
                   3707:                     my $lastidx;
                   3708:                     for (my $i=0; $i<$numtop; $i++) {
                   3709:                         my $parent = $cats[0][$i];
                   3710:                         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   3711:                         my $item = &escape($parent).'::0';
                   3712:                         my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
                   3713:                         $lastidx = $idx{$item};
                   3714:                         $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
                   3715:                                       .'<select name="'.$item.'"'.$chgstr.'>';
                   3716:                         for (my $k=0; $k<=$maxnum; $k++) {
                   3717:                             my $vpos = $k+1;
                   3718:                             my $selstr;
                   3719:                             if ($k == $i) {
                   3720:                                 $selstr = ' selected="selected" ';
                   3721:                             }
                   3722:                             $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   3723:                         }
                   3724:                         $datatable .= '</select></td><td>';
1.120     raeburn  3725:                         if ($parent eq 'instcode' || $parent eq 'communities') {
                   3726:                             $datatable .=  '<span class="LC_nobreak">'
                   3727:                                            .$default_names{$parent}.'</span>';
                   3728:                             if ($parent eq 'instcode') {
                   3729:                                 $datatable .= '<br /><span class="LC_nobreak">('
                   3730:                                               .&mt('with institutional codes')
                   3731:                                               .')</span></td><td'.$colattrib.'>';
                   3732:                             } else {
                   3733:                                 $datatable .= '<table><tr><td>';
                   3734:                             }
                   3735:                             $datatable .= '<span class="LC_nobreak">'
                   3736:                                           .'<label><input type="radio" name="'
                   3737:                                           .$parent.'" value="1" checked="checked" />'
                   3738:                                           .&mt('Display').'</label>';
                   3739:                             if ($parent eq 'instcode') {
                   3740:                                 $datatable .= '&nbsp;';
                   3741:                             } else {
                   3742:                                 $datatable .= '</span></td></tr><tr><td>'
                   3743:                                               .'<span class="LC_nobreak">';
                   3744:                             }
                   3745:                             $datatable .= '<label><input type="radio" name="'
                   3746:                                           .$parent.'" value="0" />'
                   3747:                                           .&mt('Do not display').'</label></span>';
                   3748:                             if ($parent eq 'communities') {
                   3749:                                 $datatable .= '</td></tr></table>';
                   3750:                             }
                   3751:                             $datatable .= '</td>';
1.57      raeburn  3752:                         } else {
                   3753:                             $datatable .= $parent
                   3754:                                           .'&nbsp;<label><input type="checkbox" name="deletecategory" '
                   3755:                                           .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
                   3756:                         }
                   3757:                         my $depth = 1;
                   3758:                         push(@path,$parent);
                   3759:                         $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
                   3760:                         pop(@path);
                   3761:                         $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
                   3762:                         $itemcount ++;
                   3763:                     }
1.48      raeburn  3764:                     $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57      raeburn  3765:                     my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
                   3766:                     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48      raeburn  3767:                     for (my $k=0; $k<=$maxnum; $k++) {
                   3768:                         my $vpos = $k+1;
                   3769:                         my $selstr;
1.57      raeburn  3770:                         if ($k == $numtop) {
1.48      raeburn  3771:                             $selstr = ' selected="selected" ';
                   3772:                         }
                   3773:                         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   3774:                     }
1.59      bisitz   3775:                     $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').'&nbsp;'
1.57      raeburn  3776:                                   .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
                   3777:                                   .'</tr>'."\n";
1.48      raeburn  3778:                     $itemcount ++;
1.120     raeburn  3779:                     foreach my $default ('instcode','communities') {
                   3780:                         if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
                   3781:                             $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   3782:                             my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
                   3783:                             $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
                   3784:                                           '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
                   3785:                             for (my $k=0; $k<=$maxnum; $k++) {
                   3786:                                 my $vpos = $k+1;
                   3787:                                 my $selstr;
                   3788:                                 if ($k == $maxnum) {
                   3789:                                     $selstr = ' selected="selected" ';
                   3790:                                 }
                   3791:                                 $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57      raeburn  3792:                             }
1.120     raeburn  3793:                             $datatable .= '</select></span></td>'.
                   3794:                                           '<td><span class="LC_nobreak">'.
                   3795:                                           $default_names{$default}.'</span>';
                   3796:                             if ($default eq 'instcode') {
                   3797:                                 $datatable .= '<br /><span class="LC_nobreak">(' 
                   3798:                                               .&mt('with institutional codes').')</span>';
                   3799:                             }
                   3800:                             $datatable .= '</td>'
                   3801:                                           .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
                   3802:                                           .&mt('Display').'</label>&nbsp;'
                   3803:                                           .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
                   3804:                                           .&mt('Do not display').'</label></span></td></tr>';
1.48      raeburn  3805:                         }
                   3806:                     }
                   3807:                 }
1.57      raeburn  3808:             } else {
                   3809:                 $datatable .= &initialize_categories($itemcount);
1.48      raeburn  3810:             }
                   3811:         } else {
1.57      raeburn  3812:             $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[0]->{'col2'}.'</td>'
                   3813:                           .&initialize_categories($itemcount);
1.48      raeburn  3814:         }
1.57      raeburn  3815:         $$rowtotal += $itemcount;
1.48      raeburn  3816:     }
                   3817:     return $datatable;
                   3818: }
                   3819: 
1.69      raeburn  3820: sub print_serverstatuses {
                   3821:     my ($dom,$settings,$rowtotal) = @_;
                   3822:     my $datatable;
                   3823:     my @pages = &serverstatus_pages();
                   3824:     my (%namedaccess,%machineaccess);
                   3825:     foreach my $type (@pages) {
                   3826:         $namedaccess{$type} = '';
                   3827:         $machineaccess{$type}= '';
                   3828:     }
                   3829:     if (ref($settings) eq 'HASH') {
                   3830:         foreach my $type (@pages) {
                   3831:             if (exists($settings->{$type})) {
                   3832:                 if (ref($settings->{$type}) eq 'HASH') {
                   3833:                     foreach my $key (keys(%{$settings->{$type}})) {
                   3834:                         if ($key eq 'namedusers') {
                   3835:                             $namedaccess{$type} = $settings->{$type}->{$key};
                   3836:                         } elsif ($key eq 'machines') {
                   3837:                             $machineaccess{$type} = $settings->{$type}->{$key};
                   3838:                         }
                   3839:                     }
                   3840:                 }
                   3841:             }
                   3842:         }
                   3843:     }
1.81      raeburn  3844:     my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69      raeburn  3845:     my $rownum = 0;
                   3846:     my $css_class;
                   3847:     foreach my $type (@pages) {
                   3848:         $rownum ++;
                   3849:         $css_class = $rownum%2?' class="LC_odd_row"':'';
                   3850:         $datatable .= '<tr'.$css_class.'>'.
                   3851:                       '<td><span class="LC_nobreak">'.
                   3852:                       $titles->{$type}.'</span></td>'.
                   3853:                       '<td class="LC_left_item">'.
                   3854:                       '<input type="text" name="'.$type.'_namedusers" '.
                   3855:                       'value="'.$namedaccess{$type}.'" size="30" /></td>'.
                   3856:                       '<td class="LC_right_item">'.
                   3857:                       '<span class="LC_nobreak">'.
                   3858:                       '<input type="text" name="'.$type.'_machines" '.
                   3859:                       'value="'.$machineaccess{$type}.'" size="10" />'.
                   3860:                       '</td></tr>'."\n";
                   3861:     }
                   3862:     $$rowtotal += $rownum;
                   3863:     return $datatable;
                   3864: }
                   3865: 
                   3866: sub serverstatus_pages {
                   3867:     return ('userstatus','lonstatus','loncron','server-status','codeversions',
                   3868:             'clusterstatus','metadata_keywords','metadata_harvest',
1.113     raeburn  3869:             'takeoffline','takeonline','showenv','toggledebug');
1.69      raeburn  3870: }
                   3871: 
1.49      raeburn  3872: sub coursecategories_javascript {
                   3873:     my ($settings) = @_;
1.57      raeburn  3874:     my ($output,$jstext,$cathash);
1.49      raeburn  3875:     if (ref($settings) eq 'HASH') {
1.57      raeburn  3876:         $cathash = $settings->{'cats'};
                   3877:     }
                   3878:     if (ref($cathash) eq 'HASH') {
1.49      raeburn  3879:         my (@cats,@jsarray,%idx);
1.57      raeburn  3880:         &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49      raeburn  3881:         if (@jsarray > 0) {
                   3882:             $jstext = '    var categories = Array('.scalar(@jsarray).');'."\n";
                   3883:             for (my $i=0; $i<@jsarray; $i++) {
                   3884:                 if (ref($jsarray[$i]) eq 'ARRAY') {
                   3885:                     my $catstr = join('","',@{$jsarray[$i]});
                   3886:                     $jstext .= '    categories['.$i.'] = Array("'.$catstr.'");'."\n";
                   3887:                 }
                   3888:             }
                   3889:         }
                   3890:     } else {
                   3891:         $jstext  = '    var categories = Array(1);'."\n".
                   3892:                    '    categories[0] = Array("instcode_pos");'."\n"; 
                   3893:     }
1.120     raeburn  3894:     my $instcode_reserved = &mt('The name: "instcode" is a reserved category');
                   3895:     my $communities_reserved = &mt('The name: "communities" is a reserved category');
                   3896:     my $choose_again = '\\n'.&mt('Please use a different name for the new top level category'); 
1.49      raeburn  3897:     $output = <<"ENDSCRIPT";
                   3898: <script type="text/javascript">
1.109     raeburn  3899: // <![CDATA[
1.49      raeburn  3900: function reorderCats(form,parent,item,idx) {
                   3901:     var changedVal;
                   3902: $jstext
                   3903:     var newpos = 'addcategory_pos';
                   3904:     var current = new Array;
                   3905:     if (parent == '') {
                   3906:         var has_instcode = 0;
                   3907:         var maxtop = categories[idx].length;
                   3908:         for (var j=0; j<maxtop; j++) {
                   3909:             if (categories[idx][j] == 'instcode::0') {
                   3910:                 has_instcode == 1;
                   3911:             }
                   3912:         }
                   3913:         if (has_instcode == 0) {
                   3914:             categories[idx][maxtop] = 'instcode_pos';
                   3915:         }
                   3916:     } else {
                   3917:         newpos += '_'+parent;
                   3918:     }
                   3919:     var maxh = 1 + categories[idx].length;
                   3920:     var current = new Array;
                   3921:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
                   3922:     if (item == newpos) {
                   3923:         changedVal = newitemVal;
                   3924:     } else {
                   3925:         changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
                   3926:         current[newitemVal] = newpos;
                   3927:     }
                   3928:     for (var i=0; i<categories[idx].length; i++) {
                   3929:         var elementName = categories[idx][i];
                   3930:         if (elementName != item) {
                   3931:             if (form.elements[elementName]) {
                   3932:                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   3933:                 current[currVal] = elementName;
                   3934:             }
                   3935:         }
                   3936:     }
                   3937:     var oldVal;
                   3938:     for (var j=0; j<maxh; j++) {
                   3939:         if (current[j] == undefined) {
                   3940:             oldVal = j;
                   3941:         }
                   3942:     }
                   3943:     if (oldVal < changedVal) {
                   3944:         for (var k=oldVal+1; k<=changedVal ; k++) {
                   3945:            var elementName = current[k];
                   3946:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   3947:         }
                   3948:     } else {
                   3949:         for (var k=changedVal; k<oldVal; k++) {
                   3950:             var elementName = current[k];
                   3951:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   3952:         }
                   3953:     }
                   3954:     return;
                   3955: }
1.120     raeburn  3956: 
                   3957: function categoryCheck(form) {
                   3958:     if (form.elements['addcategory_name'].value == 'instcode') {
                   3959:         alert('$instcode_reserved\\n$choose_again');
                   3960:         return false;
                   3961:     }
                   3962:     if (form.elements['addcategory_name'].value == 'communities') {
                   3963:         alert('$communities_reserved\\n$choose_again');
                   3964:         return false;
                   3965:     }
                   3966:     return true;
                   3967: }
                   3968: 
1.109     raeburn  3969: // ]]>
1.49      raeburn  3970: </script>
                   3971: 
                   3972: ENDSCRIPT
                   3973:     return $output;
                   3974: }
                   3975: 
1.48      raeburn  3976: sub initialize_categories {
                   3977:     my ($itemcount) = @_;
1.120     raeburn  3978:     my ($datatable,$css_class,$chgstr);
                   3979:     my %default_names = (
                   3980:                       instcode    => 'Official courses (with institutional codes)',
                   3981:                       communities => 'Communities',
                   3982:                         );
                   3983:     my $select0 = ' selected="selected"';
                   3984:     my $select1 = '';
                   3985:     foreach my $default ('instcode','communities') {
                   3986:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   3987:         $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
                   3988:         if ($default eq 'communities') {
                   3989:             $select1 = $select0;
                   3990:             $select0 = '';
                   3991:         }
                   3992:         $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
                   3993:                      .'<select name="'.$default.'_pos">'
                   3994:                      .'<option value="0"'.$select0.'>1</option>'
                   3995:                      .'<option value="1"'.$select1.'>2</option>'
                   3996:                      .'<option value="2">3</option></select>&nbsp;'
                   3997:                      .$default_names{$default}
                   3998:                      .'</span></td><td><span class="LC_nobreak">'
                   3999:                      .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
                   4000:                      .&mt('Display').'</label>&nbsp;<label>'
                   4001:                      .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48      raeburn  4002:                  .'</label></span></td></tr>';
1.120     raeburn  4003:         $itemcount ++;
                   4004:     }
1.48      raeburn  4005:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49      raeburn  4006:     $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48      raeburn  4007:     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120     raeburn  4008:                   .'<select name="addcategory_pos"'.$chgstr.'>'
                   4009:                   .'<option value="0">1</option>'
                   4010:                   .'<option value="1">2</option>'
                   4011:                   .'<option value="2" selected="selected">3</option></select>&nbsp;'
1.48      raeburn  4012:                   .&mt('Add category').'</td><td>'.&mt('Name:')
                   4013:                   .'&nbsp;<input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
                   4014:     return $datatable;
                   4015: }
                   4016: 
                   4017: sub build_category_rows {
1.49      raeburn  4018:     my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
                   4019:     my ($text,$name,$item,$chgstr);
1.48      raeburn  4020:     if (ref($cats) eq 'ARRAY') {
                   4021:         my $maxdepth = scalar(@{$cats});
                   4022:         if (ref($cats->[$depth]) eq 'HASH') {
                   4023:             if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
                   4024:                 my $numchildren = @{$cats->[$depth]{$parent}};
                   4025:                 my $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   4026:                 $text .= '<td><table class="LC_datatable">';
1.49      raeburn  4027:                 my ($idxnum,$parent_name,$parent_item);
                   4028:                 my $higher = $depth - 1;
                   4029:                 if ($higher == 0) {
                   4030:                     $parent_name = &escape($parent).'::'.$higher;
                   4031:                 } else {
                   4032:                     if (ref($path) eq 'ARRAY') {
                   4033:                         $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
                   4034:                     }
                   4035:                 }
                   4036:                 $parent_item = 'addcategory_pos_'.$parent_name;
1.48      raeburn  4037:                 for (my $j=0; $j<=$numchildren; $j++) {
1.49      raeburn  4038:                     if ($j < $numchildren) {
1.48      raeburn  4039:                         $name = $cats->[$depth]{$parent}[$j];
                   4040:                         $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49      raeburn  4041:                         $idxnum = $idx->{$item};
                   4042:                     } else {
                   4043:                         $name = $parent_name;
                   4044:                         $item = $parent_item;
1.48      raeburn  4045:                     }
1.49      raeburn  4046:                     $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
                   4047:                     $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48      raeburn  4048:                     for (my $i=0; $i<=$numchildren; $i++) {
                   4049:                         my $vpos = $i+1;
                   4050:                         my $selstr;
                   4051:                         if ($j == $i) {
                   4052:                             $selstr = ' selected="selected" ';
                   4053:                         }
                   4054:                         $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
                   4055:                     }
                   4056:                     $text .= '</select>&nbsp;';
                   4057:                     if ($j < $numchildren) {
                   4058:                         my $deeper = $depth+1;
                   4059:                         $text .= $name.'&nbsp;'
                   4060:                                  .'<label><input type="checkbox" name="deletecategory" value="'
                   4061:                                  .$item.'" />'.&mt('Delete').'</label></span></td><td>';
                   4062:                         if(ref($path) eq 'ARRAY') {
                   4063:                             push(@{$path},$name);
1.49      raeburn  4064:                             $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48      raeburn  4065:                             pop(@{$path});
                   4066:                         }
                   4067:                     } else {
1.59      bisitz   4068:                         $text .= &mt('Add subcategory:').'&nbsp;</span><input type="textbox" size="20" name="addcategory_name_';
1.48      raeburn  4069:                         if ($j == $numchildren) {
                   4070:                             $text .= $name;
                   4071:                         } else {
                   4072:                             $text .= $item;
                   4073:                         }
                   4074:                         $text .= '" value="" />';
                   4075:                     }
                   4076:                     $text .= '</td></tr>';
                   4077:                 }
                   4078:                 $text .= '</table></td>';
                   4079:             } else {
                   4080:                 my $higher = $depth-1;
                   4081:                 if ($higher == 0) {
                   4082:                     $name = &escape($parent).'::'.$higher;
                   4083:                 } else {
                   4084:                     if (ref($path) eq 'ARRAY') {
                   4085:                         $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
                   4086:                     }
                   4087:                 }
                   4088:                 my $colspan;
                   4089:                 if ($parent ne 'instcode') {
                   4090:                     $colspan = $maxdepth - $depth - 1;
                   4091:                     $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
                   4092:                 }
                   4093:             }
                   4094:         }
                   4095:     }
                   4096:     return $text;
                   4097: }
                   4098: 
1.33      raeburn  4099: sub modifiable_userdata_row {
1.63      raeburn  4100:     my ($context,$role,$settings,$numinrow,$rowcount,$usertypes) = @_;
1.33      raeburn  4101:     my $rolename;
1.63      raeburn  4102:     if ($context eq 'selfcreate') {
                   4103:         if (ref($usertypes) eq 'HASH') {
                   4104:             $rolename = $usertypes->{$role};
                   4105:         } else {
                   4106:             $rolename = $role;
                   4107:         }
1.33      raeburn  4108:     } else {
1.63      raeburn  4109:         if ($role eq 'cr') {
                   4110:             $rolename = &mt('Custom role');
                   4111:         } else {
                   4112:             $rolename = &Apache::lonnet::plaintext($role);
                   4113:         }
1.33      raeburn  4114:     }
                   4115:     my @fields = ('lastname','firstname','middlename','generation',
                   4116:                   'permanentemail','id');
                   4117:     my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
                   4118:     my $output;
                   4119:     my $css_class = $rowcount%2?' class="LC_odd_row"':'';
                   4120:     $output = '<tr '.$css_class.'>'.
                   4121:               '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
                   4122:               '<td class="LC_left_item" colspan="2"><table>';
                   4123:     my $rem;
                   4124:     my %checks;
                   4125:     if (ref($settings) eq 'HASH') {
                   4126:         if (ref($settings->{$context}) eq 'HASH') {
                   4127:             if (ref($settings->{$context}->{$role}) eq 'HASH') {
                   4128:                 foreach my $field (@fields) {
                   4129:                     if ($settings->{$context}->{$role}->{$field}) {
                   4130:                         $checks{$field} = ' checked="checked" ';
                   4131:                     }
                   4132:                 }
                   4133:             }
                   4134:         }
                   4135:     }
                   4136:     for (my $i=0; $i<@fields; $i++) {
                   4137:         my $rem = $i%($numinrow);
                   4138:         if ($rem == 0) {
                   4139:             if ($i > 0) {
                   4140:                 $output .= '</tr>';
                   4141:             }
                   4142:             $output .= '<tr>';
                   4143:         }
                   4144:         my $check = ' ';
                   4145:         if (exists($checks{$fields[$i]})) {
                   4146:             $check = $checks{$fields[$i]}
                   4147:         } else {
                   4148:             if ($role eq 'st') {
                   4149:                 if (ref($settings) ne 'HASH') {
                   4150:                     $check = ' checked="checked" '; 
                   4151:                 }
                   4152:             }
                   4153:         }
                   4154:         $output .= '<td class="LC_left_item">'.
                   4155:                    '<span class="LC_nobreak"><label>'.
                   4156:                    '<input type="checkbox" name="canmodify_'.$role.'" '.
                   4157:                    'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
                   4158:                    '</label></span></td>';
                   4159:         $rem = @fields%($numinrow);
                   4160:     }
                   4161:     my $colsleft = $numinrow - $rem;
                   4162:     if ($colsleft > 1 ) {
                   4163:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   4164:                    '&nbsp;</td>';
                   4165:     } elsif ($colsleft == 1) {
                   4166:         $output .= '<td class="LC_left_item">&nbsp;</td>';
                   4167:     }
                   4168:     $output .= '</tr></table></td></tr>';
                   4169:     return $output;
                   4170: }
1.28      raeburn  4171: 
1.93      raeburn  4172: sub insttypes_row {
                   4173:     my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context) = @_;
                   4174:     my %lt = &Apache::lonlocal::texthash (
                   4175:                       cansearch => 'Users allowed to search',
                   4176:                       statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131     raeburn  4177:                       lockablenames => 'User preference to lock name',
1.93      raeburn  4178:              );
                   4179:     my $showdom;
                   4180:     if ($context eq 'cansearch') {
                   4181:         $showdom = ' ('.$dom.')';
                   4182:     }
1.25      raeburn  4183:     my $output =  '<tr class="LC_odd_row">'.
1.93      raeburn  4184:                   '<td>'.$lt{$context}.$showdom.
1.24      raeburn  4185:                   '</td><td class="LC_left_item" colspan="2"><table>';
1.26      raeburn  4186:     my $rem;
                   4187:     if (ref($types) eq 'ARRAY') {
                   4188:         for (my $i=0; $i<@{$types}; $i++) {
                   4189:             if (defined($usertypes->{$types->[$i]})) {
                   4190:                 my $rem = $i%($numinrow);
                   4191:                 if ($rem == 0) {
                   4192:                     if ($i > 0) {
                   4193:                         $output .= '</tr>';
                   4194:                     }
                   4195:                     $output .= '<tr>';
1.23      raeburn  4196:                 }
1.26      raeburn  4197:                 my $check = ' ';
1.99      raeburn  4198:                 if (ref($settings) eq 'HASH') {
                   4199:                     if (ref($settings->{$context}) eq 'ARRAY') {
                   4200:                         if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
                   4201:                             $check = ' checked="checked" ';
                   4202:                         }
                   4203:                     } elsif ($context eq 'statustocreate') {
1.26      raeburn  4204:                         $check = ' checked="checked" ';
                   4205:                     }
1.23      raeburn  4206:                 }
1.26      raeburn  4207:                 $output .= '<td class="LC_left_item">'.
                   4208:                            '<span class="LC_nobreak"><label>'.
1.93      raeburn  4209:                            '<input type="checkbox" name="'.$context.'" '.
1.26      raeburn  4210:                            'value="'.$types->[$i].'"'.$check.'/>'.
                   4211:                            $usertypes->{$types->[$i]}.'</label></span></td>';
1.23      raeburn  4212:             }
                   4213:         }
1.26      raeburn  4214:         $rem = @{$types}%($numinrow);
1.23      raeburn  4215:     }
                   4216:     my $colsleft = $numinrow - $rem;
1.131     raeburn  4217:     if (($rem == 0) && (@{$types} > 0)) {
                   4218:         $output .= '<tr>';
                   4219:     }
1.23      raeburn  4220:     if ($colsleft > 1) {
1.25      raeburn  4221:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23      raeburn  4222:     } else {
1.25      raeburn  4223:         $output .= '<td class="LC_left_item">';
1.23      raeburn  4224:     }
                   4225:     my $defcheck = ' ';
1.99      raeburn  4226:     if (ref($settings) eq 'HASH') {  
                   4227:         if (ref($settings->{$context}) eq 'ARRAY') {
                   4228:             if (grep(/^default$/,@{$settings->{$context}})) {
                   4229:                 $defcheck = ' checked="checked" ';
                   4230:             }
                   4231:         } elsif ($context eq 'statustocreate') {
1.26      raeburn  4232:             $defcheck = ' checked="checked" ';
                   4233:         }
1.23      raeburn  4234:     }
1.25      raeburn  4235:     $output .= '<span class="LC_nobreak"><label>'.
1.93      raeburn  4236:                '<input type="checkbox" name="'.$context.'" '.
1.25      raeburn  4237:                'value="default"'.$defcheck.'/>'.
                   4238:                $othertitle.'</label></span></td>'.
                   4239:                '</tr></table></td></tr>';
                   4240:     return $output;
1.23      raeburn  4241: }
                   4242: 
                   4243: sub sorted_searchtitles {
                   4244:     my %searchtitles = &Apache::lonlocal::texthash(
                   4245:                          'uname' => 'username',
                   4246:                          'lastname' => 'last name',
                   4247:                          'lastfirst' => 'last name, first name',
                   4248:                      );
                   4249:     my @titleorder = ('uname','lastname','lastfirst');
                   4250:     return (\%searchtitles,\@titleorder);
                   4251: }
                   4252: 
1.25      raeburn  4253: sub sorted_searchtypes {
                   4254:     my %srchtypes_desc = (
                   4255:                            exact    => 'is exact match',
                   4256:                            contains => 'contains ..',
                   4257:                            begins   => 'begins with ..',
                   4258:                          );
                   4259:     my @srchtypeorder = ('exact','begins','contains');
                   4260:     return (\%srchtypes_desc,\@srchtypeorder);
                   4261: }
                   4262: 
1.3       raeburn  4263: sub usertype_update_row {
                   4264:     my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
                   4265:     my $datatable;
                   4266:     my $numinrow = 4;
                   4267:     foreach my $type (@{$types}) {
                   4268:         if (defined($usertypes->{$type})) {
                   4269:             $$rownums ++;
                   4270:             my $css_class = $$rownums%2?' class="LC_odd_row"':'';
                   4271:             $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
                   4272:                           '</td><td class="LC_left_item"><table>';
                   4273:             for (my $i=0; $i<@{$fields}; $i++) {
                   4274:                 my $rem = $i%($numinrow);
                   4275:                 if ($rem == 0) {
                   4276:                     if ($i > 0) {
                   4277:                         $datatable .= '</tr>';
                   4278:                     }
                   4279:                     $datatable .= '<tr>';
                   4280:                 }
                   4281:                 my $check = ' ';
1.39      raeburn  4282:                 if (ref($settings) eq 'HASH') {
                   4283:                     if (ref($settings->{'fields'}) eq 'HASH') {
                   4284:                         if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
                   4285:                             if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
                   4286:                                 $check = ' checked="checked" ';
                   4287:                             }
1.3       raeburn  4288:                         }
                   4289:                     }
                   4290:                 }
                   4291: 
                   4292:                 if ($i == @{$fields}-1) {
                   4293:                     my $colsleft = $numinrow - $rem;
                   4294:                     if ($colsleft > 1) {
                   4295:                         $datatable .= '<td colspan="'.$colsleft.'">';
                   4296:                     } else {
                   4297:                         $datatable .= '<td>';
                   4298:                     }
                   4299:                 } else {
                   4300:                     $datatable .= '<td>';
                   4301:                 }
1.8       raeburn  4302:                 $datatable .= '<span class="LC_nobreak"><label>'.
                   4303:                               '<input type="checkbox" name="updateable_'.$type.
                   4304:                               '_'.$fields->[$i].'" value="1"'.$check.'/>'.
                   4305:                               $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3       raeburn  4306:             }
                   4307:             $datatable .= '</tr></table></td></tr>';
                   4308:         }
                   4309:     }
                   4310:     return $datatable;
1.1       raeburn  4311: }
                   4312: 
                   4313: sub modify_login {
1.9       raeburn  4314:     my ($r,$dom,$confname,%domconfig) = @_;
1.6       raeburn  4315:     my ($resulttext,$errors,$colchgtext,%changes,%colchanges);
1.1       raeburn  4316:     my %title = ( coursecatalog => 'Display course catalog',
1.41      raeburn  4317:                   adminmail => 'Display administrator E-mail address',
1.43      raeburn  4318:                   newuser => 'Link for visitors to create a user account',
1.41      raeburn  4319:                   loginheader => 'Log-in box header');
1.3       raeburn  4320:     my @offon = ('off','on');
1.112     raeburn  4321:     my %curr_loginvia;
                   4322:     if (ref($domconfig{login}) eq 'HASH') {
                   4323:         if (ref($domconfig{login}{loginvia}) eq 'HASH') {
                   4324:             foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
                   4325:                 $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
                   4326:             }
                   4327:         }
                   4328:     }
1.6       raeburn  4329:     my %loginhash;
1.9       raeburn  4330:     ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
                   4331:                                            \%domconfig,\%loginhash);
1.118     jms      4332:     my @toggles = ('coursecatalog','adminmail','newuser');
1.42      raeburn  4333:     foreach my $item (@toggles) {
                   4334:         $loginhash{login}{$item} = $env{'form.'.$item};
                   4335:     }
1.41      raeburn  4336:     $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6       raeburn  4337:     if (ref($colchanges{'login'}) eq 'HASH') {  
                   4338:         $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
                   4339:                                          \%loginhash);
                   4340:     }
1.110     raeburn  4341: 
1.149     raeburn  4342:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.128     raeburn  4343:     my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110     raeburn  4344:     if (keys(%servers) > 1) {
                   4345:         foreach my $lonhost (keys(%servers)) {
1.128     raeburn  4346:             next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
                   4347:             if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
                   4348:                 if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
                   4349:                     $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
                   4350:                 } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
                   4351:                     if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
                   4352:                         $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
                   4353:                         $changes{'loginvia'}{$lonhost} = 1;
                   4354:                     } else {
                   4355:                         $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
                   4356:                         $changes{'loginvia'}{$lonhost} = 1;
                   4357:                     }
                   4358:                 } else {
                   4359:                     if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
                   4360:                         $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
                   4361:                         $changes{'loginvia'}{$lonhost} = 1;
                   4362:                     }
                   4363:                 }
                   4364:                 if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
                   4365:                     foreach my $item (@loginvia_attribs) {
                   4366:                         $loginhash{login}{loginvia}{$lonhost}{$item} = '';
                   4367:                     }
                   4368:                 } else {
                   4369:                     foreach my $item (@loginvia_attribs) {
                   4370:                         my $new = $env{'form.'.$lonhost.'_'.$item};
                   4371:                         if (($item eq 'serverpath') && ($new eq 'custom')) {
                   4372:                             $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
                   4373:                             if ($env{'form.'.$lonhost.'_custompath'} eq '') {
                   4374:                                 $new = '/';
                   4375:                             }
                   4376:                         }
                   4377:                         if (($item eq 'custompath') && 
                   4378:                             ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
                   4379:                             $new = '';
                   4380:                         }
                   4381:                         if ($new ne $curr_loginvia{$lonhost}{$item}) {
                   4382:                             $changes{'loginvia'}{$lonhost} = 1;
                   4383:                         }
                   4384:                         if ($item eq 'exempt') {
                   4385:                             $new =~ s/^\s+//;
                   4386:                             $new =~ s/\s+$//;
                   4387:                             my @poss_ips = split(/\s*[,:]\s*/,$new);
                   4388:                             my @okips;
                   4389:                             foreach my $ip (@poss_ips) {
                   4390:                                 if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
                   4391:                                     if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
                   4392:                                         push(@okips,$ip); 
                   4393:                                     }
                   4394:                                 }
                   4395:                             }
                   4396:                             if (@okips > 0) {
                   4397:                                 $new = join(',',@okips); 
                   4398:                             } else {
                   4399:                                 $new = ''; 
                   4400:                             }
                   4401:                         }
                   4402: 
                   4403:                         $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
                   4404:                     }
                   4405:                 }
1.112     raeburn  4406:             } else {
1.128     raeburn  4407:                 if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
                   4408:                     $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112     raeburn  4409:                     $changes{'loginvia'}{$lonhost} = 1;
1.128     raeburn  4410:                     foreach my $item (@loginvia_attribs) {
                   4411:                         my $new = $env{'form.'.$lonhost.'_'.$item};
                   4412:                         if (($item eq 'serverpath') && ($new eq 'custom')) {
                   4413:                             if ($env{'form.'.$lonhost.'_custompath'} eq '') {
                   4414:                                 $new = '/';
                   4415:                             }
                   4416:                         }
                   4417:                         if (($item eq 'custompath') && 
                   4418:                             ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
                   4419:                             $new = '';
                   4420:                         }
                   4421:                         $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
                   4422:                     }
1.110     raeburn  4423:                 }
                   4424:             }
                   4425:         }
                   4426:     }
1.119     raeburn  4427: 
1.1       raeburn  4428:     my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
                   4429:                                              $dom);
                   4430:     if ($putresult eq 'ok') {
1.118     jms      4431:         my @toggles = ('coursecatalog','adminmail','newuser');
1.42      raeburn  4432:         my %defaultchecked = (
                   4433:                     'coursecatalog' => 'on',
                   4434:                     'adminmail'     => 'off',
1.43      raeburn  4435:                     'newuser'       => 'off',
1.42      raeburn  4436:         );
1.55      raeburn  4437:         if (ref($domconfig{'login'}) eq 'HASH') {
                   4438:             foreach my $item (@toggles) {
                   4439:                 if ($defaultchecked{$item} eq 'on') { 
                   4440:                     if (($domconfig{'login'}{$item} eq '0') &&
                   4441:                         ($env{'form.'.$item} eq '1')) {
                   4442:                         $changes{$item} = 1;
                   4443:                     } elsif (($domconfig{'login'}{$item} eq '' ||
                   4444:                               $domconfig{'login'}{$item} eq '1') &&
                   4445:                              ($env{'form.'.$item} eq '0')) {
                   4446:                         $changes{$item} = 1;
                   4447:                     }
                   4448:                 } elsif ($defaultchecked{$item} eq 'off') {
                   4449:                     if (($domconfig{'login'}{$item} eq '1') &&
                   4450:                         ($env{'form.'.$item} eq '0')) {
                   4451:                         $changes{$item} = 1;
                   4452:                     } elsif (($domconfig{'login'}{$item} eq '' ||
                   4453:                               $domconfig{'login'}{$item} eq '0') &&
                   4454:                              ($env{'form.'.$item} eq '1')) {
                   4455:                         $changes{$item} = 1;
                   4456:                     }
1.42      raeburn  4457:                 }
                   4458:             }
1.41      raeburn  4459:         }
1.6       raeburn  4460:         if (keys(%changes) > 0 || $colchgtext) {
1.41      raeburn  4461:             &Apache::loncommon::devalidate_domconfig_cache($dom);
1.1       raeburn  4462:             $resulttext = &mt('Changes made:').'<ul>';
                   4463:             foreach my $item (sort(keys(%changes))) {
1.135     bisitz   4464:                 if ($item eq 'loginvia') {
1.112     raeburn  4465:                     if (ref($changes{$item}) eq 'HASH') {
                   4466:                         $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
                   4467:                         foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128     raeburn  4468:                             if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
                   4469:                                 if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
                   4470:                                     my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
                   4471:                                     $protocol = 'http' if ($protocol ne 'https');
                   4472:                                     my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
                   4473: 
                   4474:                                     if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
                   4475:                                         $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
                   4476:                                     } else {
                   4477:                                         $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'}; 
                   4478:                                     }
                   4479:                                     $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
                   4480:                                     if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
                   4481:                                         $resulttext .= '&nbsp;'.&mt('No redirection for clients from following IPs:').'&nbsp;'.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
                   4482:                                     }
                   4483:                                     $resulttext .= '</li>';
                   4484:                                 } else {
                   4485:                                     $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
                   4486:                                 }
1.112     raeburn  4487:                             } else {
1.128     raeburn  4488:                                 $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112     raeburn  4489:                             }
                   4490:                         }
1.128     raeburn  4491:                         $resulttext .= '</ul></li>';
1.112     raeburn  4492:                     }
1.41      raeburn  4493:                 } else {
                   4494:                     $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
                   4495:                 }
1.1       raeburn  4496:             }
1.6       raeburn  4497:             $resulttext .= $colchgtext.'</ul>';
1.1       raeburn  4498:         } else {
                   4499:             $resulttext = &mt('No changes made to log-in page settings');
                   4500:         }
                   4501:     } else {
1.11      albertel 4502:         $resulttext = '<span class="LC_error">'.
                   4503: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  4504:     }
1.6       raeburn  4505:     if ($errors) {
1.9       raeburn  4506:         $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6       raeburn  4507:                        $errors.'</ul>';
                   4508:     }
                   4509:     return $resulttext;
                   4510: }
                   4511: 
                   4512: sub color_font_choices {
                   4513:     my %choices =
                   4514:         &Apache::lonlocal::texthash (
                   4515:             img => "Header",
                   4516:             bgs => "Background colors",
                   4517:             links => "Link colors",
1.55      raeburn  4518:             images => "Images",
1.6       raeburn  4519:             font => "Font color",
1.97      tempelho 4520:             fontmenu => "Font Menu",
1.76      raeburn  4521:             pgbg => "Page",
1.6       raeburn  4522:             tabbg => "Header",
                   4523:             sidebg => "Border",
                   4524:             link => "Link",
                   4525:             alink => "Active link",
                   4526:             vlink => "Visited link",
                   4527:         );
                   4528:     return %choices;
                   4529: }
                   4530: 
                   4531: sub modify_rolecolors {
1.9       raeburn  4532:     my ($r,$dom,$confname,$roles,%domconfig) = @_;
1.6       raeburn  4533:     my ($resulttext,%rolehash);
                   4534:     $rolehash{'rolecolors'} = {};
1.55      raeburn  4535:     if (ref($domconfig{'rolecolors'}) ne 'HASH') {
                   4536:         if ($domconfig{'rolecolors'} eq '') {
                   4537:             $domconfig{'rolecolors'} = {};
                   4538:         }
                   4539:     }
1.9       raeburn  4540:     my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6       raeburn  4541:                          $domconfig{'rolecolors'},$rolehash{'rolecolors'});
                   4542:     my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
                   4543:                                              $dom);
                   4544:     if ($putresult eq 'ok') {
                   4545:         if (keys(%changes) > 0) {
1.41      raeburn  4546:             &Apache::loncommon::devalidate_domconfig_cache($dom);
1.6       raeburn  4547:             $resulttext = &display_colorchgs($dom,\%changes,$roles,
                   4548:                                              $rolehash{'rolecolors'});
                   4549:         } else {
                   4550:             $resulttext = &mt('No changes made to default color schemes');
                   4551:         }
                   4552:     } else {
1.11      albertel 4553:         $resulttext = '<span class="LC_error">'.
                   4554: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.6       raeburn  4555:     }
                   4556:     if ($errors) {
                   4557:         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
                   4558:                        $errors.'</ul>';
                   4559:     }
                   4560:     return $resulttext;
                   4561: }
                   4562: 
                   4563: sub modify_colors {
1.9       raeburn  4564:     my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12      raeburn  4565:     my (%changes,%choices);
1.51      raeburn  4566:     my @bgs;
1.6       raeburn  4567:     my @links = ('link','alink','vlink');
1.41      raeburn  4568:     my @logintext;
1.6       raeburn  4569:     my @images;
                   4570:     my $servadm = $r->dir_config('lonAdmEMail');
                   4571:     my $errors;
                   4572:     foreach my $role (@{$roles}) {
                   4573:         if ($role eq 'login') {
1.12      raeburn  4574:             %choices = &login_choices();
1.41      raeburn  4575:             @logintext = ('textcol','bgcol');
1.12      raeburn  4576:         } else {
                   4577:             %choices = &color_font_choices();
1.107     raeburn  4578:             $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
1.12      raeburn  4579:         }
                   4580:         if ($role eq 'login') {
1.41      raeburn  4581:             @images = ('img','logo','domlogo','login');
1.51      raeburn  4582:             @bgs = ('pgbg','mainbg','sidebg');
1.6       raeburn  4583:         } else {
                   4584:             @images = ('img');
1.51      raeburn  4585:             @bgs = ('pgbg','tabbg','sidebg'); 
1.6       raeburn  4586:         }
                   4587:         $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
1.41      raeburn  4588:         foreach my $item (@bgs,@links,@logintext) {
1.6       raeburn  4589:             $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
                   4590:         }
1.46      raeburn  4591:         my ($configuserok,$author_ok,$switchserver) = 
                   4592:             &config_check($dom,$confname,$servadm);
1.9       raeburn  4593:         my ($width,$height) = &thumb_dimensions();
1.40      raeburn  4594:         if (ref($domconfig->{$role}) ne 'HASH') {
                   4595:             $domconfig->{$role} = {};
                   4596:         }
1.8       raeburn  4597:         foreach my $img (@images) {
1.70      raeburn  4598:             if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {  
                   4599:                 if (defined($env{'form.login_showlogo_'.$img})) {
                   4600:                     $confhash->{$role}{'showlogo'}{$img} = 1;
                   4601:                 } else { 
                   4602:                     $confhash->{$role}{'showlogo'}{$img} = 0;
                   4603:                 }
                   4604:             } 
1.18      albertel 4605: 	    if ( ! $env{'form.'.$role.'_'.$img.'.filename'} 
                   4606: 		 && !defined($domconfig->{$role}{$img})
                   4607: 		 && !$env{'form.'.$role.'_del_'.$img}
                   4608: 		 && $env{'form.'.$role.'_import_'.$img}) {
                   4609: 		# import the old configured image from the .tab setting
                   4610: 		# if they haven't provided a new one 
                   4611: 		$domconfig->{$role}{$img} = 
                   4612: 		    $env{'form.'.$role.'_import_'.$img};
                   4613: 	    }
1.6       raeburn  4614:             if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9       raeburn  4615:                 my $error;
1.6       raeburn  4616:                 if ($configuserok eq 'ok') {
1.9       raeburn  4617:                     if ($switchserver) {
1.12      raeburn  4618:                         $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9       raeburn  4619:                     } else {
                   4620:                         if ($author_ok eq 'ok') {
                   4621:                             my ($result,$logourl) = 
                   4622:                                 &publishlogo($r,'upload',$role.'_'.$img,
                   4623:                                            $dom,$confname,$img,$width,$height);
                   4624:                             if ($result eq 'ok') {
                   4625:                                 $confhash->{$role}{$img} = $logourl;
1.12      raeburn  4626:                                 $changes{$role}{'images'}{$img} = 1;
1.9       raeburn  4627:                             } else {
1.12      raeburn  4628:                                 $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  4629:                             }
                   4630:                         } else {
1.46      raeburn  4631:                             $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  4632:                         }
                   4633:                     }
                   4634:                 } else {
1.46      raeburn  4635:                     $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  4636:                 }
                   4637:                 if ($error) {
1.8       raeburn  4638:                     &Apache::lonnet::logthis($error);
1.11      albertel 4639:                     $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8       raeburn  4640:                 }
                   4641:             } elsif ($domconfig->{$role}{$img} ne '') {
1.9       raeburn  4642:                 if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
                   4643:                     my $error;
                   4644:                     if ($configuserok eq 'ok') {
                   4645: # is confname an author?
                   4646:                         if ($switchserver eq '') {
                   4647:                             if ($author_ok eq 'ok') {
                   4648:                                 my ($result,$logourl) = 
                   4649:                                &publishlogo($r,'copy',$domconfig->{$role}{$img},
                   4650:                                             $dom,$confname,$img,$width,$height);
                   4651:                                 if ($result eq 'ok') {
                   4652:                                     $confhash->{$role}{$img} = $logourl;
1.18      albertel 4653: 				    $changes{$role}{'images'}{$img} = 1;
1.9       raeburn  4654:                                 }
                   4655:                             }
                   4656:                         }
                   4657:                     }
1.6       raeburn  4658:                 }
                   4659:             }
                   4660:         }
                   4661:         if (ref($domconfig) eq 'HASH') {
                   4662:             if (ref($domconfig->{$role}) eq 'HASH') {
                   4663:                 foreach my $img (@images) {
                   4664:                     if ($domconfig->{$role}{$img} ne '') {
                   4665:                         if ($env{'form.'.$role.'_del_'.$img}) {
                   4666:                             $confhash->{$role}{$img} = '';
1.12      raeburn  4667:                             $changes{$role}{'images'}{$img} = 1;
1.6       raeburn  4668:                         } else {
1.9       raeburn  4669:                             if ($confhash->{$role}{$img} eq '') {
                   4670:                                 $confhash->{$role}{$img} = $domconfig->{$role}{$img};
                   4671:                             }
1.6       raeburn  4672:                         }
                   4673:                     } else {
                   4674:                         if ($env{'form.'.$role.'_del_'.$img}) {
                   4675:                             $confhash->{$role}{$img} = '';
1.12      raeburn  4676:                             $changes{$role}{'images'}{$img} = 1;
1.6       raeburn  4677:                         } 
                   4678:                     }
1.70      raeburn  4679:                     if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
                   4680:                         if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
                   4681:                             if ($confhash->{$role}{'showlogo'}{$img} ne 
                   4682:                                 $domconfig->{$role}{'showlogo'}{$img}) {
                   4683:                                 $changes{$role}{'showlogo'}{$img} = 1; 
                   4684:                             }
                   4685:                         } else {
                   4686:                             if ($confhash->{$role}{'showlogo'}{$img} == 0) {
                   4687:                                 $changes{$role}{'showlogo'}{$img} = 1;
                   4688:                             }
                   4689:                         }
                   4690:                     }
                   4691:                 }
1.6       raeburn  4692:                 if ($domconfig->{$role}{'font'} ne '') {
                   4693:                     if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
                   4694:                         $changes{$role}{'font'} = 1;
                   4695:                     }
                   4696:                 } else {
                   4697:                     if ($confhash->{$role}{'font'}) {
                   4698:                         $changes{$role}{'font'} = 1;
                   4699:                     }
                   4700:                 }
1.107     raeburn  4701:                 if ($role ne 'login') {
                   4702:                     if ($domconfig->{$role}{'fontmenu'} ne '') {
                   4703:                         if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
                   4704:                             $changes{$role}{'fontmenu'} = 1;
                   4705:                         }
                   4706:                     } else {
                   4707:                         if ($confhash->{$role}{'fontmenu'}) {
                   4708:                             $changes{$role}{'fontmenu'} = 1;
                   4709:                         }
1.97      tempelho 4710:                     }
                   4711:                 }
1.6       raeburn  4712:                 foreach my $item (@bgs) {
                   4713:                     if ($domconfig->{$role}{$item} ne '') {
                   4714:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
                   4715:                             $changes{$role}{'bgs'}{$item} = 1;
                   4716:                         } 
                   4717:                     } else {
                   4718:                         if ($confhash->{$role}{$item}) {
                   4719:                             $changes{$role}{'bgs'}{$item} = 1;
                   4720:                         }
                   4721:                     }
                   4722:                 }
                   4723:                 foreach my $item (@links) {
                   4724:                     if ($domconfig->{$role}{$item} ne '') {
                   4725:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
                   4726:                             $changes{$role}{'links'}{$item} = 1;
                   4727:                         }
                   4728:                     } else {
                   4729:                         if ($confhash->{$role}{$item}) {
                   4730:                             $changes{$role}{'links'}{$item} = 1;
                   4731:                         }
                   4732:                     }
                   4733:                 }
1.41      raeburn  4734:                 foreach my $item (@logintext) {
                   4735:                     if ($domconfig->{$role}{$item} ne '') {
                   4736:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
                   4737:                             $changes{$role}{'logintext'}{$item} = 1;
                   4738:                         }
                   4739:                     } else {
                   4740:                         if ($confhash->{$role}{$item}) {
                   4741:                             $changes{$role}{'logintext'}{$item} = 1;
                   4742:                         }
                   4743:                     }
                   4744:                 }
1.6       raeburn  4745:             } else {
                   4746:                 &default_change_checker($role,\@images,\@links,\@bgs,
1.41      raeburn  4747:                                         \@logintext,$confhash,\%changes); 
1.6       raeburn  4748:             }
                   4749:         } else {
                   4750:             &default_change_checker($role,\@images,\@links,\@bgs,
1.41      raeburn  4751:                                     \@logintext,$confhash,\%changes); 
1.6       raeburn  4752:         }
                   4753:     }
                   4754:     return ($errors,%changes);
                   4755: }
                   4756: 
1.46      raeburn  4757: sub config_check {
                   4758:     my ($dom,$confname,$servadm) = @_;
                   4759:     my ($configuserok,$author_ok,$switchserver,%currroles);
                   4760:     my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
                   4761:     ($configuserok,%currroles) = &check_configuser($uhome,$dom,
                   4762:                                                    $confname,$servadm);
                   4763:     if ($configuserok eq 'ok') {
                   4764:         $switchserver = &check_switchserver($dom,$confname);
                   4765:         if ($switchserver eq '') {
                   4766:             $author_ok = &check_authorstatus($dom,$confname,%currroles);
                   4767:         }
                   4768:     }
                   4769:     return ($configuserok,$author_ok,$switchserver);
                   4770: }
                   4771: 
1.6       raeburn  4772: sub default_change_checker {
1.41      raeburn  4773:     my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6       raeburn  4774:     foreach my $item (@{$links}) {
                   4775:         if ($confhash->{$role}{$item}) {
                   4776:             $changes->{$role}{'links'}{$item} = 1;
                   4777:         }
                   4778:     }
                   4779:     foreach my $item (@{$bgs}) {
                   4780:         if ($confhash->{$role}{$item}) {
                   4781:             $changes->{$role}{'bgs'}{$item} = 1;
                   4782:         }
                   4783:     }
1.41      raeburn  4784:     foreach my $item (@{$logintext}) {
                   4785:         if ($confhash->{$role}{$item}) {
                   4786:             $changes->{$role}{'logintext'}{$item} = 1;
                   4787:         }
                   4788:     }
1.6       raeburn  4789:     foreach my $img (@{$images}) {
                   4790:         if ($env{'form.'.$role.'_del_'.$img}) {
                   4791:             $confhash->{$role}{$img} = '';
1.12      raeburn  4792:             $changes->{$role}{'images'}{$img} = 1;
1.6       raeburn  4793:         }
1.70      raeburn  4794:         if ($role eq 'login') {
                   4795:             if ($confhash->{$role}{'showlogo'}{$img} == 0) {
                   4796:                 $changes->{$role}{'showlogo'}{$img} = 1;
                   4797:             }
                   4798:         }
1.6       raeburn  4799:     }
                   4800:     if ($confhash->{$role}{'font'}) {
                   4801:         $changes->{$role}{'font'} = 1;
                   4802:     }
1.48      raeburn  4803: }
1.6       raeburn  4804: 
                   4805: sub display_colorchgs {
                   4806:     my ($dom,$changes,$roles,$confhash) = @_;
                   4807:     my (%choices,$resulttext);
                   4808:     if (!grep(/^login$/,@{$roles})) {
                   4809:         $resulttext = &mt('Changes made:').'<br />';
                   4810:     }
                   4811:     foreach my $role (@{$roles}) {
                   4812:         if ($role eq 'login') {
                   4813:             %choices = &login_choices();
                   4814:         } else {
                   4815:             %choices = &color_font_choices();
                   4816:         }
                   4817:         if (ref($changes->{$role}) eq 'HASH') {
                   4818:             if ($role ne 'login') {
                   4819:                 $resulttext .= '<h4>'.&mt($role).'</h4>';
                   4820:             }
                   4821:             foreach my $key (sort(keys(%{$changes->{$role}}))) {
                   4822:                 if ($role ne 'login') {
                   4823:                     $resulttext .= '<ul>';
                   4824:                 }
                   4825:                 if (ref($changes->{$role}{$key}) eq 'HASH') {
                   4826:                     if ($role ne 'login') {
                   4827:                         $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
                   4828:                     }
                   4829:                     foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70      raeburn  4830:                         if (($role eq 'login') && ($key eq 'showlogo')) {
                   4831:                             if ($confhash->{$role}{$key}{$item}) {
                   4832:                                 $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
                   4833:                             } else {
                   4834:                                 $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
                   4835:                             }
                   4836:                         } elsif ($confhash->{$role}{$item} eq '') {
1.6       raeburn  4837:                             $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
                   4838:                         } else {
1.12      raeburn  4839:                             my $newitem = $confhash->{$role}{$item};
                   4840:                             if ($key eq 'images') {
                   4841:                                 $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
                   4842:                             }
                   4843:                             $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6       raeburn  4844:                         }
                   4845:                     }
                   4846:                     if ($role ne 'login') {
                   4847:                         $resulttext .= '</ul></li>';
                   4848:                     }
                   4849:                 } else {
                   4850:                     if ($confhash->{$role}{$key} eq '') {
                   4851:                         $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
                   4852:                     } else {
                   4853:                         $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
                   4854:                     }
                   4855:                 }
                   4856:                 if ($role ne 'login') {
                   4857:                     $resulttext .= '</ul>';
                   4858:                 }
                   4859:             }
                   4860:         }
                   4861:     }
1.3       raeburn  4862:     return $resulttext;
1.1       raeburn  4863: }
                   4864: 
1.9       raeburn  4865: sub thumb_dimensions {
                   4866:     return ('200','50');
                   4867: }
                   4868: 
1.16      raeburn  4869: sub check_dimensions {
                   4870:     my ($inputfile) = @_;
                   4871:     my ($fullwidth,$fullheight);
                   4872:     if ($inputfile =~ m|^[/\w.\-]+$|) {
                   4873:         if (open(PIPE,"identify $inputfile 2>&1 |")) {
                   4874:             my $imageinfo = <PIPE>;
                   4875:             if (!close(PIPE)) {
                   4876:                 &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
                   4877:             }
                   4878:             chomp($imageinfo);
                   4879:             my ($fullsize) = 
1.21      raeburn  4880:                 ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16      raeburn  4881:             if ($fullsize) {
                   4882:                 ($fullwidth,$fullheight) = split(/x/,$fullsize);
                   4883:             }
                   4884:         }
                   4885:     }
                   4886:     return ($fullwidth,$fullheight);
                   4887: }
                   4888: 
1.9       raeburn  4889: sub check_configuser {
                   4890:     my ($uhome,$dom,$confname,$servadm) = @_;
                   4891:     my ($configuserok,%currroles);
                   4892:     if ($uhome eq 'no_host') {
                   4893:         srand( time() ^ ($$ + ($$ << 15))  ); # Seed rand.
                   4894:         my $configpass = &LONCAPA::Enrollment::create_password();
                   4895:         $configuserok = 
                   4896:             &Apache::lonnet::modifyuser($dom,$confname,'','internal',
                   4897:                              $configpass,'','','','','',undef,$servadm);
                   4898:     } else {
                   4899:         $configuserok = 'ok';
                   4900:         %currroles = 
                   4901:             &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
                   4902:     }
                   4903:     return ($configuserok,%currroles);
                   4904: }
                   4905: 
                   4906: sub check_authorstatus {
                   4907:     my ($dom,$confname,%currroles) = @_;
                   4908:     my $author_ok;
1.40      raeburn  4909:     if (!$currroles{':'.$dom.':au'}) {
1.9       raeburn  4910:         my $start = time;
                   4911:         my $end = 0;
                   4912:         $author_ok = 
                   4913:             &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47      raeburn  4914:                                         'au',$end,$start,'','','domconfig');
1.9       raeburn  4915:     } else {
                   4916:         $author_ok = 'ok';
                   4917:     }
                   4918:     return $author_ok;
                   4919: }
                   4920: 
                   4921: sub publishlogo {
1.46      raeburn  4922:     my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9       raeburn  4923:     my ($output,$fname,$logourl);
                   4924:     if ($action eq 'upload') {
                   4925:         $fname=$env{'form.'.$formname.'.filename'};
                   4926:         chop($env{'form.'.$formname});
                   4927:     } else {
                   4928:         ($fname) = ($formname =~ /([^\/]+)$/);
                   4929:     }
1.46      raeburn  4930:     if ($savefileas ne '') {
                   4931:         $fname = $savefileas;
                   4932:     }
1.9       raeburn  4933:     $fname=&Apache::lonnet::clean_filename($fname);
                   4934: # See if there is anything left
                   4935:     unless ($fname) { return ('error: no uploaded file'); }
                   4936:     $fname="$subdir/$fname";
                   4937:     my $filepath='/home/'.$confname.'/public_html';
                   4938:     my ($fnamepath,$file,$fetchthumb);
                   4939:     $file=$fname;
                   4940:     if ($fname=~m|/|) {
                   4941:         ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
                   4942:     }
                   4943:     my @parts=split(/\//,$filepath.'/'.$fnamepath);
                   4944:     my $count;
                   4945:     for ($count=4;$count<=$#parts;$count++) {
                   4946:         $filepath.="/$parts[$count]";
                   4947:         if ((-e $filepath)!=1) {
                   4948:             mkdir($filepath,02770);
                   4949:         }
                   4950:     }
                   4951:     # Check for bad extension and disallow upload
                   4952:     if ($file=~/\.(\w+)$/ &&
                   4953:         (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
                   4954:         $output = 
                   4955:             &mt('Invalid file extension ([_1]) - reserved for LONCAPA use.',$1); 
                   4956:     } elsif ($file=~/\.(\w+)$/ &&
                   4957:         !defined(&Apache::loncommon::fileembstyle($1))) {
                   4958:         $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
                   4959:     } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.46      raeburn  4960:         $output = &mt('File name not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
1.9       raeburn  4961:     } elsif (-d "$filepath/$file") {
                   4962:         $output = &mt('File name is a directory name - rename the file and re-upload');
                   4963:     } else {
                   4964:         my $source = $filepath.'/'.$file;
                   4965:         my $logfile;
                   4966:         if (!open($logfile,">>$source".'.log')) {
                   4967:             return (&mt('No write permission to Construction Space'));
                   4968:         }
                   4969:         print $logfile
                   4970: "\n================= Publish ".localtime()." ================\n".
                   4971: $env{'user.name'}.':'.$env{'user.domain'}."\n";
                   4972: # Save the file
                   4973:         if (!open(FH,'>'.$source)) {
                   4974:             &Apache::lonnet::logthis('Failed to create '.$source);
                   4975:             return (&mt('Failed to create file'));
                   4976:         }
                   4977:         if ($action eq 'upload') {
                   4978:             if (!print FH ($env{'form.'.$formname})) {
                   4979:                 &Apache::lonnet::logthis('Failed to write to '.$source);
                   4980:                 return (&mt('Failed to write file'));
                   4981:             }
                   4982:         } else {
                   4983:             my $original = &Apache::lonnet::filelocation('',$formname);
                   4984:             if(!copy($original,$source)) {
                   4985:                 &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
                   4986:                 return (&mt('Failed to write file'));
                   4987:             }
                   4988:         }
                   4989:         close(FH);
                   4990:         chmod(0660, $source); # Permissions to rw-rw---.
                   4991: 
                   4992:         my $docroot=$r->dir_config('lonDocRoot');
                   4993:         my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
                   4994:         my $copyfile=$targetdir.'/'.$file;
                   4995: 
                   4996:         my @parts=split(/\//,$targetdir);
                   4997:         my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
                   4998:         for (my $count=5;$count<=$#parts;$count++) {
                   4999:             $path.="/$parts[$count]";
                   5000:             if (!-e $path) {
                   5001:                 print $logfile "\nCreating directory ".$path;
                   5002:                 mkdir($path,02770);
                   5003:             }
                   5004:         }
                   5005:         my $versionresult;
                   5006:         if (-e $copyfile) {
                   5007:             $versionresult = &logo_versioning($targetdir,$file,$logfile);
                   5008:         } else {
                   5009:             $versionresult = 'ok';
                   5010:         }
                   5011:         if ($versionresult eq 'ok') {
                   5012:             if (copy($source,$copyfile)) {
                   5013:                 print $logfile "\nCopied original source to ".$copyfile."\n";
                   5014:                 $output = 'ok';
                   5015:                 $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155   ! raeburn  5016:                 push(@{$modified_urls},[$copyfile,$source]);
        !          5017:                 my $metaoutput = 
        !          5018:                     &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
        !          5019:                 unless ($registered_cleanup) {
        !          5020:                     my $handlers = $r->get_handlers('PerlCleanupHandler');
        !          5021:                     $r->set_handlers('PerlCleanupHandler' => [\&notifysubscribed,@{$handlers}]);
        !          5022:                     $registered_cleanup=1;
        !          5023:                 }
1.9       raeburn  5024:             } else {
                   5025:                 print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
                   5026:                 $output = &mt('Failed to copy file to RES space').", $!";
                   5027:             }
                   5028:             if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
                   5029:                 my $inputfile = $filepath.'/'.$file;
                   5030:                 my $outfile = $filepath.'/'.'tn-'.$file;
1.16      raeburn  5031:                 my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
                   5032:                 if ($fullwidth ne '' && $fullheight ne '') { 
                   5033:                     if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
                   5034:                         my $thumbsize = $thumbwidth.'x'.$thumbheight;
                   5035:                         system("convert -sample $thumbsize $inputfile $outfile");
                   5036:                         chmod(0660, $filepath.'/tn-'.$file);
                   5037:                         if (-e $outfile) {
                   5038:                             my $copyfile=$targetdir.'/tn-'.$file;
                   5039:                             if (copy($outfile,$copyfile)) {
                   5040:                                 print $logfile "\nCopied source to ".$copyfile."\n";
1.155   ! raeburn  5041:                                 my $thumb_metaoutput = 
        !          5042:                                     &write_metadata($dom,$confname,$formname,
        !          5043:                                                     $targetdir,'tn-'.$file,$logfile);
        !          5044:                                 push(@{$modified_urls},[$copyfile,$outfile]);
        !          5045:                                 unless ($registered_cleanup) {
        !          5046:                                     my $handlers = $r->get_handlers('PerlCleanupHandler');
        !          5047:                                     $r->set_handlers('PerlCleanupHandler' => [\&notifysubscribed,@{$handlers}]);
        !          5048:                                     $registered_cleanup=1;
        !          5049:                                 }
1.16      raeburn  5050:                             } else {
                   5051:                                 print $logfile "\nUnable to write ".$copyfile.
                   5052:                                                ':'.$!."\n";
                   5053:                             }
                   5054:                         }
1.9       raeburn  5055:                     }
                   5056:                 }
                   5057:             }
                   5058:         } else {
                   5059:             $output = $versionresult;
                   5060:         }
                   5061:     }
                   5062:     return ($output,$logourl);
                   5063: }
                   5064: 
                   5065: sub logo_versioning {
                   5066:     my ($targetdir,$file,$logfile) = @_;
                   5067:     my $target = $targetdir.'/'.$file;
                   5068:     my ($maxversion,$fn,$extn,$output);
                   5069:     $maxversion = 0;
                   5070:     if ($file =~ /^(.+)\.(\w+)$/) {
                   5071:         $fn=$1;
                   5072:         $extn=$2;
                   5073:     }
                   5074:     opendir(DIR,$targetdir);
                   5075:     while (my $filename=readdir(DIR)) {
                   5076:         if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
                   5077:             $maxversion=($1>$maxversion)?$1:$maxversion;
                   5078:         }
                   5079:     }
                   5080:     $maxversion++;
                   5081:     print $logfile "\nCreating old version ".$maxversion."\n";
                   5082:     my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
                   5083:     if (copy($target,$copyfile)) {
                   5084:         print $logfile "Copied old target to ".$copyfile."\n";
                   5085:         $copyfile=$copyfile.'.meta';
                   5086:         if (copy($target.'.meta',$copyfile)) {
                   5087:             print $logfile "Copied old target metadata to ".$copyfile."\n";
                   5088:             $output = 'ok';
                   5089:         } else {
                   5090:             print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
                   5091:             $output = &mt('Failed to copy old meta').", $!, ";
                   5092:         }
                   5093:     } else {
                   5094:         print $logfile "Unable to write ".$copyfile.':'.$!."\n";
                   5095:         $output = &mt('Failed to copy old target').", $!, ";
                   5096:     }
                   5097:     return $output;
                   5098: }
                   5099: 
                   5100: sub write_metadata {
                   5101:     my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
                   5102:     my (%metadatafields,%metadatakeys,$output);
                   5103:     $metadatafields{'title'}=$formname;
                   5104:     $metadatafields{'creationdate'}=time;
                   5105:     $metadatafields{'lastrevisiondate'}=time;
                   5106:     $metadatafields{'copyright'}='public';
                   5107:     $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
                   5108:                                          $env{'user.domain'};
                   5109:     $metadatafields{'authorspace'}=$confname.':'.$dom;
                   5110:     $metadatafields{'domain'}=$dom;
                   5111:     {
                   5112:         print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
                   5113:         my $mfh;
1.155   ! raeburn  5114:         if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
        !          5115:             foreach (sort keys %metadatafields) {
        !          5116:                 unless ($_=~/\./) {
        !          5117:                     my $unikey=$_;
        !          5118:                     $unikey=~/^([A-Za-z]+)/;
        !          5119:                     my $tag=$1;
        !          5120:                     $tag=~tr/A-Z/a-z/;
        !          5121:                     print $mfh "\n\<$tag";
        !          5122:                     foreach (split(/\,/,$metadatakeys{$unikey})) {
        !          5123:                         my $value=$metadatafields{$unikey.'.'.$_};
        !          5124:                         $value=~s/\"/\'\'/g;
        !          5125:                         print $mfh ' '.$_.'="'.$value.'"';
        !          5126:                     }
        !          5127:                     print $mfh '>'.
        !          5128:                         &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
        !          5129:                             .'</'.$tag.'>';
        !          5130:                 }
        !          5131:             }
        !          5132:             $output = 'ok';
        !          5133:             print $logfile "\nWrote metadata";
        !          5134:             close($mfh);
        !          5135:         } else {
        !          5136:             print $logfile "\nFailed to open metadata file";
1.9       raeburn  5137:             $output = &mt('Could not write metadata');
                   5138:         }
                   5139:     }
1.155   ! raeburn  5140:     return $output;
        !          5141: }
        !          5142: 
        !          5143: sub notifysubscribed {
        !          5144:     foreach my $targetsource (@{$modified_urls}){
        !          5145:         next unless (ref($targetsource) eq 'ARRAY');
        !          5146:         my ($target,$source)=@{$targetsource};
        !          5147:         if ($source ne '') {
        !          5148:             if (open(my $logfh,'>>'.$source.'.log')) {
        !          5149:                 print $logfh "\nCleanup phase: Notifications\n";
        !          5150:                 my @subscribed=&subscribed_hosts($target);
        !          5151:                 foreach my $subhost (@subscribed) {
        !          5152:                     print $logfh "\nNotifying host ".$subhost.':';
        !          5153:                     my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
        !          5154:                     print $logfh $reply;
        !          5155:                 }
        !          5156:                 my @subscribedmeta=&subscribed_hosts("$target.meta");
        !          5157:                 foreach my $subhost (@subscribedmeta) {
        !          5158:                     print $logfh "\nNotifying host for metadata only ".$subhost.':';
        !          5159:                     my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
        !          5160:                                                         $subhost);
        !          5161:                     print $logfh $reply;
        !          5162:                 }
        !          5163:                 print $logfh "\n============ Done ============\n";
        !          5164:                 close(logfh);
        !          5165:             }
        !          5166:         }
        !          5167:     }
        !          5168:     return OK;
        !          5169: }
        !          5170: 
        !          5171: sub subscribed_hosts {
        !          5172:     my ($target) = @_;
        !          5173:     my @subscribed;
        !          5174:     if (open(my $fh,"<$target.subscription")) {
        !          5175:         while (my $subline=<$fh>) {
        !          5176:             if ($subline =~ /^($match_lonid):/) {
        !          5177:                 my $host = $1;
        !          5178:                 if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
        !          5179:                     unless (grep(/^\Q$host\E$/,@subscribed)) {
        !          5180:                         push(@subscribed,$host);
        !          5181:                     }
        !          5182:                 }
        !          5183:             }
        !          5184:         }
        !          5185:     }
        !          5186:     return @subscribed;
1.9       raeburn  5187: }
                   5188: 
                   5189: sub check_switchserver {
                   5190:     my ($dom,$confname) = @_;
                   5191:     my ($allowed,$switchserver);
                   5192:     my $home = &Apache::lonnet::homeserver($confname,$dom);
                   5193:     if ($home eq 'no_host') {
                   5194:         $home = &Apache::lonnet::domain($dom,'primary');
                   5195:     }
                   5196:     my @ids=&Apache::lonnet::current_machine_ids();
1.10      albertel 5197:     foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
                   5198:     if (!$allowed) {
                   5199: 	$switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/">'.&mt('Switch Server').'</a>';
1.9       raeburn  5200:     }
                   5201:     return $switchserver;
                   5202: }
                   5203: 
1.1       raeburn  5204: sub modify_quotas {
1.86      raeburn  5205:     my ($dom,$action,%domconfig) = @_;
1.101     raeburn  5206:     my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
                   5207:         %limithash,$toolregexp,%conditions,$resulttext,%changes);
1.86      raeburn  5208:     if ($action eq 'quotas') {
                   5209:         $context = 'tools'; 
                   5210:     } else { 
                   5211:         $context = $action;
                   5212:     }
                   5213:     if ($context eq 'requestcourses') {
1.98      raeburn  5214:         @usertools = ('official','unofficial','community');
1.106     raeburn  5215:         @options =('norequest','approval','validate','autolimit');
1.101     raeburn  5216:         %validations = &Apache::lonnet::auto_courserequest_checks($dom);
                   5217:         %titles = &courserequest_titles();
                   5218:         $toolregexp = join('|',@usertools);
                   5219:         %conditions = &courserequest_conditions();
1.86      raeburn  5220:     } else {
                   5221:         @usertools = ('aboutme','blog','portfolio');
1.101     raeburn  5222:         %titles = &tool_titles();
1.86      raeburn  5223:     }
1.72      raeburn  5224:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.44      raeburn  5225:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1       raeburn  5226:     foreach my $key (keys(%env)) {
1.101     raeburn  5227:         if ($context eq 'requestcourses') {
                   5228:             if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
                   5229:                 my $item = $1;
                   5230:                 my $type = $2;
                   5231:                 if ($type =~ /^limit_(.+)/) {
                   5232:                     $limithash{$item}{$1} = $env{$key};
                   5233:                 } else {
                   5234:                     $confhash{$item}{$type} = $env{$key};
                   5235:                 }
                   5236:             }
                   5237:         } else {
1.86      raeburn  5238:             if ($key =~ /^form\.quota_(.+)$/) {
                   5239:                 $confhash{'defaultquota'}{$1} = $env{$key};
                   5240:             }
1.101     raeburn  5241:             if ($key =~ /^form\.\Q$context\E_(.+)$/) {
                   5242:                 @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
                   5243:             }
1.72      raeburn  5244:         }
                   5245:     }
1.102     raeburn  5246:     if ($context eq 'requestcourses') {
                   5247:         my @approvalnotify = &Apache::loncommon::get_env_multiple('form.reqapprovalnotify');
                   5248:         @approvalnotify = sort(@approvalnotify);
                   5249:         $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
                   5250:         if (ref($domconfig{$action}) eq 'HASH') {
                   5251:             if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
                   5252:                 if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
                   5253:                     $changes{'notify'}{'approval'} = 1;
                   5254:                 }
                   5255:             } else {
1.144     raeburn  5256:                 if ($confhash{'notify'}{'approval'}) {
1.102     raeburn  5257:                     $changes{'notify'}{'approval'} = 1;
                   5258:                 }
                   5259:             }
                   5260:         } else {
1.144     raeburn  5261:             if ($confhash{'notify'}{'approval'}) {
1.102     raeburn  5262:                 $changes{'notify'}{'approval'} = 1;
                   5263:             }
                   5264:         }
                   5265:     } else {
1.86      raeburn  5266:         $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
                   5267:     }
1.72      raeburn  5268:     foreach my $item (@usertools) {
                   5269:         foreach my $type (@{$types},'default','_LC_adv') {
1.104     raeburn  5270:             my $unset; 
1.101     raeburn  5271:             if ($context eq 'requestcourses') {
1.104     raeburn  5272:                 $unset = '0';
                   5273:                 if ($type eq '_LC_adv') {
                   5274:                     $unset = '';
                   5275:                 }
1.101     raeburn  5276:                 if ($confhash{$item}{$type} eq 'autolimit') {
                   5277:                     $confhash{$item}{$type} .= '=';
                   5278:                     unless ($limithash{$item}{$type} =~ /\D/) {
                   5279:                         $confhash{$item}{$type} .= $limithash{$item}{$type};
                   5280:                     }
                   5281:                 }
1.72      raeburn  5282:             } else {
1.101     raeburn  5283:                 if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
                   5284:                     $confhash{$item}{$type} = 1;
                   5285:                 } else {
                   5286:                     $confhash{$item}{$type} = 0;
                   5287:                 }
1.72      raeburn  5288:             }
1.86      raeburn  5289:             if (ref($domconfig{$action}) eq 'HASH') {
                   5290:                 if (ref($domconfig{$action}{$item}) eq 'HASH') {
                   5291:                     if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
                   5292:                         $changes{$item}{$type} = 1;
                   5293:                     }
                   5294:                 } else {
                   5295:                     if ($context eq 'requestcourses') {
1.104     raeburn  5296:                         if ($confhash{$item}{$type} ne $unset) {
1.86      raeburn  5297:                             $changes{$item}{$type} = 1;
                   5298:                         }
                   5299:                     } else {
                   5300:                         if (!$confhash{$item}{$type}) {
                   5301:                             $changes{$item}{$type} = 1;
                   5302:                         }
                   5303:                     }
                   5304:                 }
                   5305:             } else {
                   5306:                 if ($context eq 'requestcourses') {
1.104     raeburn  5307:                     if ($confhash{$item}{$type} ne $unset) {
1.72      raeburn  5308:                         $changes{$item}{$type} = 1;
                   5309:                     }
                   5310:                 } else {
                   5311:                     if (!$confhash{$item}{$type}) {
                   5312:                         $changes{$item}{$type} = 1;
                   5313:                     }
                   5314:                 }
                   5315:             }
1.1       raeburn  5316:         }
                   5317:     }
1.86      raeburn  5318:     unless ($context eq 'requestcourses') {
                   5319:         if (ref($domconfig{'quotas'}) eq 'HASH') {
                   5320:             if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
                   5321:                 foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
                   5322:                     if (exists($confhash{'defaultquota'}{$key})) {
                   5323:                         if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
                   5324:                             $changes{'defaultquota'}{$key} = 1;
                   5325:                         }
                   5326:                     } else {
                   5327:                         $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72      raeburn  5328:                     }
                   5329:                 }
1.86      raeburn  5330:             } else {
                   5331:                 foreach my $key (keys(%{$domconfig{'quotas'}})) {
                   5332:                     if (exists($confhash{'defaultquota'}{$key})) {
                   5333:                         if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
                   5334:                             $changes{'defaultquota'}{$key} = 1;
                   5335:                         }
                   5336:                     } else {
                   5337:                         $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72      raeburn  5338:                     }
1.1       raeburn  5339:                 }
                   5340:             }
                   5341:         }
1.86      raeburn  5342:         if (ref($confhash{'defaultquota'}) eq 'HASH') {
                   5343:             foreach my $key (keys(%{$confhash{'defaultquota'}})) {
                   5344:                 if (ref($domconfig{'quotas'}) eq 'HASH') {
                   5345:                     if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
                   5346:                         if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
                   5347:                             $changes{'defaultquota'}{$key} = 1;
                   5348:                         }
                   5349:                     } else {
                   5350:                         if (!exists($domconfig{'quotas'}{$key})) {
                   5351:                             $changes{'defaultquota'}{$key} = 1;
                   5352:                         }
1.72      raeburn  5353:                     }
                   5354:                 } else {
1.86      raeburn  5355:                     $changes{'defaultquota'}{$key} = 1;
1.55      raeburn  5356:                 }
1.1       raeburn  5357:             }
                   5358:         }
                   5359:     }
1.72      raeburn  5360: 
                   5361:     foreach my $key (keys(%confhash)) {
                   5362:         $domdefaults{$key} = $confhash{$key};
                   5363:     }
                   5364:    
1.1       raeburn  5365:     my %quotahash = (
1.86      raeburn  5366:                       $action => { %confhash }
1.1       raeburn  5367:                     );
                   5368:     my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
                   5369:                                              $dom);
                   5370:     if ($putresult eq 'ok') {
                   5371:         if (keys(%changes) > 0) {
1.72      raeburn  5372:             my $cachetime = 24*60*60;
                   5373:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
                   5374: 
1.1       raeburn  5375:             $resulttext = &mt('Changes made:').'<ul>';
1.86      raeburn  5376:             unless ($context eq 'requestcourses') {
                   5377:                 if (ref($changes{'defaultquota'}) eq 'HASH') {
                   5378:                     $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
                   5379:                     foreach my $type (@{$types},'default') {
                   5380:                         if (defined($changes{'defaultquota'}{$type})) {
                   5381:                             my $typetitle = $usertypes->{$type};
                   5382:                             if ($type eq 'default') {
                   5383:                                 $typetitle = $othertitle;
                   5384:                             }
                   5385:                             $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72      raeburn  5386:                         }
                   5387:                     }
1.86      raeburn  5388:                     $resulttext .= '</ul></li>';
1.72      raeburn  5389:                 }
                   5390:             }
1.80      raeburn  5391:             my %newenv;
1.72      raeburn  5392:             foreach my $item (@usertools) {
                   5393:                 if (ref($changes{$item}) eq 'HASH') {
1.80      raeburn  5394:                     my $newacc = 
                   5395:                         &Apache::lonnet::usertools_access($env{'user.name'},
                   5396:                                                           $env{'user.domain'},
1.86      raeburn  5397:                                                           $item,'reload',$context);
                   5398:                     if ($context eq 'requestcourses') {
1.108     raeburn  5399:                         if ($env{'environment.canrequest.'.$item} ne $newacc) {
                   5400:                             $newenv{'environment.canrequest.'.$item} = $newacc;
1.86      raeburn  5401:                         }
                   5402:                     } else {
                   5403:                         if ($env{'environment.availabletools.'.$item} ne $newacc) { 
                   5404:                             $newenv{'environment.availabletools.'.$item} = $newacc;
                   5405:                         }
1.80      raeburn  5406:                     }
1.72      raeburn  5407:                     $resulttext .= '<li>'.$titles{$item}.'<ul>';
                   5408:                     foreach my $type (@{$types},'default','_LC_adv') {
                   5409:                         if ($changes{$item}{$type}) {
                   5410:                             my $typetitle = $usertypes->{$type};
                   5411:                             if ($type eq 'default') {
                   5412:                                 $typetitle = $othertitle;
                   5413:                             } elsif ($type eq '_LC_adv') {
                   5414:                                 $typetitle = 'LON-CAPA Advanced Users'; 
                   5415:                             }
                   5416:                             if ($confhash{$item}{$type}) {
1.101     raeburn  5417:                                 if ($context eq 'requestcourses') {
                   5418:                                     my $cond;
                   5419:                                     if ($confhash{$item}{$type} =~ /^autolimit=(\d*)$/) {
                   5420:                                         if ($1 eq '') {
                   5421:                                             $cond = &mt('(Automatic processing of any request).');
                   5422:                                         } else {
                   5423:                                             $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
                   5424:                                         }
                   5425:                                     } else { 
                   5426:                                         $cond = $conditions{$confhash{$item}{$type}};
                   5427:                                     }
                   5428:                                     $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
                   5429:                                 } else {
                   5430:                                     $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
                   5431:                                 }
1.72      raeburn  5432:                             } else {
1.104     raeburn  5433:                                 if ($type eq '_LC_adv') {
                   5434:                                     if ($confhash{$item}{$type} eq '0') {
                   5435:                                         $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
                   5436:                                     } else { 
                   5437:                                         $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
                   5438:                                     }
                   5439:                                 } else {
                   5440:                                     $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
                   5441:                                 }
1.72      raeburn  5442:                             }
                   5443:                         }
1.26      raeburn  5444:                     }
1.72      raeburn  5445:                     $resulttext .= '</ul></li>';
1.26      raeburn  5446:                 }
1.1       raeburn  5447:             }
1.102     raeburn  5448:             if ($action eq 'requestcourses') {
                   5449:                 if (ref($changes{'notify'}) eq 'HASH') {
                   5450:                     if ($changes{'notify'}{'approval'}) {
                   5451:                         if (ref($confhash{'notify'}) eq 'HASH') {
                   5452:                             if ($confhash{'notify'}{'approval'}) {
                   5453:                                 $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
                   5454:                             } else {
                   5455:                                 $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of course requests requiring approval.').'</li>';
                   5456:                             }
                   5457:                         }
                   5458:                     }
                   5459:                 }
                   5460:             }
1.1       raeburn  5461:             $resulttext .= '</ul>';
1.80      raeburn  5462:             if (keys(%newenv)) {
                   5463:                 &Apache::lonnet::appenv(\%newenv);
                   5464:             }
1.1       raeburn  5465:         } else {
1.86      raeburn  5466:             if ($context eq 'requestcourses') {
                   5467:                 $resulttext = &mt('No changes made to rights to request creation of courses.');
                   5468:             } else {
1.90      weissno  5469:                 $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86      raeburn  5470:             }
1.1       raeburn  5471:         }
                   5472:     } else {
1.11      albertel 5473:         $resulttext = '<span class="LC_error">'.
                   5474: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  5475:     }
1.3       raeburn  5476:     return $resulttext;
1.1       raeburn  5477: }
                   5478: 
1.3       raeburn  5479: sub modify_autoenroll {
                   5480:     my ($dom,%domconfig) = @_;
1.1       raeburn  5481:     my ($resulttext,%changes);
                   5482:     my %currautoenroll;
                   5483:     if (ref($domconfig{'autoenroll'}) eq 'HASH') {
                   5484:         foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
                   5485:             $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
                   5486:         }
                   5487:     }
                   5488:     my $autorun = &Apache::lonnet::auto_run(undef,$dom),
                   5489:     my %title = ( run => 'Auto-enrollment active',
1.129     raeburn  5490:                   sender => 'Sender for notification messages',
                   5491:                   coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)');
1.1       raeburn  5492:     my @offon = ('off','on');
1.17      raeburn  5493:     my $sender_uname = $env{'form.sender_uname'};
                   5494:     my $sender_domain = $env{'form.sender_domain'};
                   5495:     if ($sender_domain eq '') {
                   5496:         $sender_uname = '';
                   5497:     } elsif ($sender_uname eq '') {
                   5498:         $sender_domain = '';
                   5499:     }
1.129     raeburn  5500:     my $coowners = $env{'form.autoassign_coowners'};
1.1       raeburn  5501:     my %autoenrollhash =  (
1.129     raeburn  5502:                        autoenroll => { 'run' => $env{'form.autoenroll_run'},
                   5503:                                        'sender_uname' => $sender_uname,
                   5504:                                        'sender_domain' => $sender_domain,
                   5505:                                        'co-owners' => $coowners,
1.1       raeburn  5506:                                 }
                   5507:                      );
1.4       raeburn  5508:     my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
                   5509:                                              $dom);
1.1       raeburn  5510:     if ($putresult eq 'ok') {
                   5511:         if (exists($currautoenroll{'run'})) {
                   5512:              if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
                   5513:                  $changes{'run'} = 1;
                   5514:              }
                   5515:         } elsif ($autorun) {
                   5516:             if ($env{'form.autoenroll_run'} ne '1') {
1.23      raeburn  5517:                  $changes{'run'} = 1;
1.1       raeburn  5518:             }
                   5519:         }
1.17      raeburn  5520:         if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1       raeburn  5521:             $changes{'sender'} = 1;
                   5522:         }
1.17      raeburn  5523:         if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1       raeburn  5524:             $changes{'sender'} = 1;
                   5525:         }
1.129     raeburn  5526:         if ($currautoenroll{'co-owners'} ne '') {
                   5527:             if ($currautoenroll{'co-owners'} ne $coowners) {
                   5528:                 $changes{'coowners'} = 1;
                   5529:             }
                   5530:         } elsif ($coowners) {
                   5531:             $changes{'coowners'} = 1;
                   5532:         }      
1.1       raeburn  5533:         if (keys(%changes) > 0) {
                   5534:             $resulttext = &mt('Changes made:').'<ul>';
1.3       raeburn  5535:             if ($changes{'run'}) {
1.1       raeburn  5536:                 $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
                   5537:             }
                   5538:             if ($changes{'sender'}) {
1.17      raeburn  5539:                 if ($sender_uname eq '' || $sender_domain eq '') {
                   5540:                     $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
                   5541:                 } else {
                   5542:                     $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
                   5543:                 }
1.1       raeburn  5544:             }
1.129     raeburn  5545:             if ($changes{'coowners'}) {
                   5546:                 $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
                   5547:                 &Apache::loncommon::devalidate_domconfig_cache($dom);
                   5548:             }
1.1       raeburn  5549:             $resulttext .= '</ul>';
                   5550:         } else {
                   5551:             $resulttext = &mt('No changes made to auto-enrollment settings');
                   5552:         }
                   5553:     } else {
1.11      albertel 5554:         $resulttext = '<span class="LC_error">'.
                   5555: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  5556:     }
1.3       raeburn  5557:     return $resulttext;
1.1       raeburn  5558: }
                   5559: 
                   5560: sub modify_autoupdate {
1.3       raeburn  5561:     my ($dom,%domconfig) = @_;
1.1       raeburn  5562:     my ($resulttext,%currautoupdate,%fields,%changes);
                   5563:     if (ref($domconfig{'autoupdate'}) eq 'HASH') {
                   5564:         foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
                   5565:             $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
                   5566:         }
                   5567:     }
                   5568:     my @offon = ('off','on');
                   5569:     my %title = &Apache::lonlocal::texthash (
                   5570:                    run => 'Auto-update:',
                   5571:                    classlists => 'Updates to user information in classlists?'
                   5572:                 );
1.44      raeburn  5573:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1       raeburn  5574:     my %fieldtitles = &Apache::lonlocal::texthash (
                   5575:                         id => 'Student/Employee ID',
1.20      raeburn  5576:                         permanentemail => 'E-mail address',
1.1       raeburn  5577:                         lastname => 'Last Name',
                   5578:                         firstname => 'First Name',
                   5579:                         middlename => 'Middle Name',
1.132     raeburn  5580:                         generation => 'Generation',
1.1       raeburn  5581:                       );
1.142     raeburn  5582:     $othertitle = &mt('All users');
1.1       raeburn  5583:     if (keys(%{$usertypes}) >  0) {
1.26      raeburn  5584:         $othertitle = &mt('Other users');
1.1       raeburn  5585:     }
                   5586:     foreach my $key (keys(%env)) {
                   5587:         if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132     raeburn  5588:             my ($usertype,$item) = ($1,$2);
                   5589:             if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
                   5590:                 if ($usertype eq 'default') {   
                   5591:                     push(@{$fields{$1}},$2);
                   5592:                 } elsif (ref($types) eq 'ARRAY') {
                   5593:                     if (grep(/^\Q$usertype\E$/,@{$types})) {
                   5594:                         push(@{$fields{$1}},$2);
                   5595:                     }
                   5596:                 }
                   5597:             }
1.1       raeburn  5598:         }
                   5599:     }
1.131     raeburn  5600:     my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
                   5601:     @lockablenames = sort(@lockablenames);
                   5602:     if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
                   5603:         my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
                   5604:         if (@changed) {
                   5605:             $changes{'lockablenames'} = 1;
                   5606:         }
                   5607:     } else {
                   5608:         if (@lockablenames) {
                   5609:             $changes{'lockablenames'} = 1;
                   5610:         }
                   5611:     }
1.1       raeburn  5612:     my %updatehash = (
                   5613:                       autoupdate => { run => $env{'form.autoupdate_run'},
                   5614:                                       classlists => $env{'form.classlists'},
                   5615:                                       fields => {%fields},
1.131     raeburn  5616:                                       lockablenames => \@lockablenames,
1.1       raeburn  5617:                                     }
                   5618:                      );
                   5619:     foreach my $key (keys(%currautoupdate)) {
                   5620:         if (($key eq 'run') || ($key eq 'classlists')) {
                   5621:             if (exists($updatehash{autoupdate}{$key})) {
                   5622:                 if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
                   5623:                     $changes{$key} = 1;
                   5624:                 }
                   5625:             }
                   5626:         } elsif ($key eq 'fields') {
                   5627:             if (ref($currautoupdate{$key}) eq 'HASH') {
1.26      raeburn  5628:                 foreach my $item (@{$types},'default') {
1.1       raeburn  5629:                     if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
                   5630:                         my $change = 0;
                   5631:                         foreach my $type (@{$currautoupdate{$key}{$item}}) {
                   5632:                             if (!exists($fields{$item})) {
                   5633:                                 $change = 1;
1.132     raeburn  5634:                                 last;
1.1       raeburn  5635:                             } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26      raeburn  5636:                                 if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1       raeburn  5637:                                     $change = 1;
1.132     raeburn  5638:                                     last;
1.1       raeburn  5639:                                 }
                   5640:                             }
                   5641:                         }
                   5642:                         if ($change) {
                   5643:                             push(@{$changes{$key}},$item);
                   5644:                         }
1.26      raeburn  5645:                     } 
1.1       raeburn  5646:                 }
                   5647:             }
1.131     raeburn  5648:         } elsif ($key eq 'lockablenames') {
                   5649:             if (ref($currautoupdate{$key}) eq 'ARRAY') {
                   5650:                 my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
                   5651:                 if (@changed) {
                   5652:                     $changes{'lockablenames'} = 1;
                   5653:                 }
                   5654:             } else {
                   5655:                 if (@lockablenames) {
                   5656:                     $changes{'lockablenames'} = 1;
                   5657:                 }
                   5658:             }
                   5659:         }
                   5660:     }
                   5661:     unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
                   5662:         if (@lockablenames) {
                   5663:             $changes{'lockablenames'} = 1;
1.1       raeburn  5664:         }
                   5665:     }
1.26      raeburn  5666:     foreach my $item (@{$types},'default') {
                   5667:         if (defined($fields{$item})) {
                   5668:             if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132     raeburn  5669:                 if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
                   5670:                     my $change = 0;
                   5671:                     if (ref($fields{$item}) eq 'ARRAY') {
                   5672:                         foreach my $type (@{$fields{$item}}) {
                   5673:                             if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
                   5674:                                 $change = 1;
                   5675:                                 last;
                   5676:                             }
                   5677:                         }
                   5678:                     }
                   5679:                     if ($change) {
                   5680:                         push(@{$changes{'fields'}},$item);
                   5681:                     }
                   5682:                 } else {
1.26      raeburn  5683:                     push(@{$changes{'fields'}},$item);
                   5684:                 }
                   5685:             } else {
                   5686:                 push(@{$changes{'fields'}},$item);
1.1       raeburn  5687:             }
                   5688:         }
                   5689:     }
                   5690:     my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
                   5691:                                              $dom);
                   5692:     if ($putresult eq 'ok') {
                   5693:         if (keys(%changes) > 0) {
                   5694:             $resulttext = &mt('Changes made:').'<ul>';
                   5695:             foreach my $key (sort(keys(%changes))) {
1.131     raeburn  5696:                 if ($key eq 'lockablenames') {
                   5697:                     $resulttext .= '<li>';
                   5698:                     if (@lockablenames) {
                   5699:                         $usertypes->{'default'} = $othertitle;
                   5700:                         $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
                   5701:                                    join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
                   5702:                     } else {
                   5703:                         $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
                   5704:                     }
                   5705:                     $resulttext .= '</li>';
                   5706:                 } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1       raeburn  5707:                     foreach my $item (@{$changes{$key}}) {
                   5708:                         my @newvalues;
                   5709:                         foreach my $type (@{$fields{$item}}) {
                   5710:                             push(@newvalues,$fieldtitles{$type});
                   5711:                         }
1.3       raeburn  5712:                         my $newvaluestr;
                   5713:                         if (@newvalues > 0) {
                   5714:                             $newvaluestr = join(', ',@newvalues);
                   5715:                         } else {
                   5716:                             $newvaluestr = &mt('none');
1.6       raeburn  5717:                         }
1.1       raeburn  5718:                         if ($item eq 'default') {
1.26      raeburn  5719:                             $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1       raeburn  5720:                         } else {
1.26      raeburn  5721:                             $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1       raeburn  5722:                         }
                   5723:                     }
                   5724:                 } else {
                   5725:                     my $newvalue;
                   5726:                     if ($key eq 'run') {
                   5727:                         $newvalue = $offon[$env{'form.autoupdate_run'}];
                   5728:                     } else {
                   5729:                         $newvalue = $offon[$env{'form.'.$key}];
1.3       raeburn  5730:                     }
1.1       raeburn  5731:                     $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
                   5732:                 }
                   5733:             }
                   5734:             $resulttext .= '</ul>';
                   5735:         } else {
1.3       raeburn  5736:             $resulttext = &mt('No changes made to autoupdates');
1.1       raeburn  5737:         }
                   5738:     } else {
1.11      albertel 5739:         $resulttext = '<span class="LC_error">'.
                   5740: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  5741:     }
1.3       raeburn  5742:     return $resulttext;
1.1       raeburn  5743: }
                   5744: 
1.125     raeburn  5745: sub modify_autocreate {
                   5746:     my ($dom,%domconfig) = @_;
                   5747:     my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
                   5748:     if (ref($domconfig{'autocreate'}) eq 'HASH') {
                   5749:         foreach my $key (keys(%{$domconfig{'autocreate'}})) {
                   5750:             $currautocreate{$key} = $domconfig{'autocreate'}{$key};
                   5751:         }
                   5752:     }
                   5753:     my %title= ( xml => 'Auto-creation of courses in XML course description files',
                   5754:                  req => 'Auto-creation of validated requests for official courses',
                   5755:                  xmldc => 'Identity of course creator of courses from XML files',
                   5756:                );
                   5757:     my @types = ('xml','req');
                   5758:     foreach my $item (@types) {
                   5759:         $newvals{$item} = $env{'form.autocreate_'.$item};
                   5760:         $newvals{$item} =~ s/\D//g;
                   5761:         $newvals{$item} = 0 if ($newvals{$item} eq '');
                   5762:     }
                   5763:     $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
                   5764:     my %domcoords = &get_active_dcs($dom);
                   5765:     unless (exists($domcoords{$newvals{'xmldc'}})) {
                   5766:         $newvals{'xmldc'} = '';
                   5767:     } 
                   5768:     %autocreatehash =  (
                   5769:                         autocreate => { xml => $newvals{'xml'},
                   5770:                                         req => $newvals{'req'},
                   5771:                                       }
                   5772:                        );
                   5773:     if ($newvals{'xmldc'} ne '') {
                   5774:         $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
                   5775:     }
                   5776:     my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
                   5777:                                              $dom);
                   5778:     if ($putresult eq 'ok') {
                   5779:         my @items = @types;
                   5780:         if ($newvals{'xml'}) {
                   5781:             push(@items,'xmldc');
                   5782:         }
                   5783:         foreach my $item (@items) {
                   5784:             if (exists($currautocreate{$item})) {
                   5785:                 if ($currautocreate{$item} ne $newvals{$item}) {
                   5786:                     $changes{$item} = 1;
                   5787:                 }
                   5788:             } elsif ($newvals{$item}) {
                   5789:                 $changes{$item} = 1;
                   5790:             }
                   5791:         }
                   5792:         if (keys(%changes) > 0) {
                   5793:             my @offon = ('off','on'); 
                   5794:             $resulttext = &mt('Changes made:').'<ul>';
                   5795:             foreach my $item (@types) {
                   5796:                 if ($changes{$item}) {
                   5797:                     my $newtxt = $offon[$newvals{$item}];
                   5798:                     $resulttext .= '<li>'.&mt("$title{$item} set to [_1]$newtxt [_2]",'<b>','</b>').'</li>';
                   5799:                 }
                   5800:             }
                   5801:             if ($changes{'xmldc'}) {
                   5802:                 my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
                   5803:                 my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
                   5804:                 $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]$newtxt [_2]",'<b>','</b>').'</li>'; 
                   5805:             }
                   5806:             $resulttext .= '</ul>';
                   5807:         } else {
                   5808:             $resulttext = &mt('No changes made to auto-creation settings');
                   5809:         }
                   5810:     } else {
                   5811:         $resulttext = '<span class="LC_error">'.
                   5812:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   5813:     }
                   5814:     return $resulttext;
                   5815: }
                   5816: 
1.23      raeburn  5817: sub modify_directorysrch {
                   5818:     my ($dom,%domconfig) = @_;
                   5819:     my ($resulttext,%changes);
                   5820:     my %currdirsrch;
                   5821:     if (ref($domconfig{'directorysrch'}) eq 'HASH') {
                   5822:         foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
                   5823:             $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
                   5824:         }
                   5825:     }
                   5826:     my %title = ( available => 'Directory search available',
1.24      raeburn  5827:                   localonly => 'Other domains can search',
1.23      raeburn  5828:                   searchby => 'Search types',
                   5829:                   searchtypes => 'Search latitude');
                   5830:     my @offon = ('off','on');
1.24      raeburn  5831:     my @otherdoms = ('Yes','No');
1.23      raeburn  5832: 
1.25      raeburn  5833:     my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');  
1.23      raeburn  5834:     my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
                   5835:     my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
                   5836: 
1.44      raeburn  5837:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26      raeburn  5838:     if (keys(%{$usertypes}) == 0) {
                   5839:         @cansearch = ('default');
                   5840:     } else {
                   5841:         if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
                   5842:             foreach my $type (@{$currdirsrch{'cansearch'}}) {
                   5843:                 if (!grep(/^\Q$type\E$/,@cansearch)) {
                   5844:                     push(@{$changes{'cansearch'}},$type);
                   5845:                 }
1.23      raeburn  5846:             }
1.26      raeburn  5847:             foreach my $type (@cansearch) {
                   5848:                 if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
                   5849:                     push(@{$changes{'cansearch'}},$type);
                   5850:                 }
1.23      raeburn  5851:             }
1.26      raeburn  5852:         } else {
                   5853:             push(@{$changes{'cansearch'}},@cansearch);
1.23      raeburn  5854:         }
                   5855:     }
                   5856: 
                   5857:     if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
                   5858:         foreach my $by (@{$currdirsrch{'searchby'}}) {
                   5859:             if (!grep(/^\Q$by\E$/,@searchby)) {
                   5860:                 push(@{$changes{'searchby'}},$by);
                   5861:             }
                   5862:         }
                   5863:         foreach my $by (@searchby) {
                   5864:             if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
                   5865:                 push(@{$changes{'searchby'}},$by);
                   5866:             }
                   5867:         }
                   5868:     } else {
                   5869:         push(@{$changes{'searchby'}},@searchby);
                   5870:     }
1.25      raeburn  5871: 
                   5872:     if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
                   5873:         foreach my $type (@{$currdirsrch{'searchtypes'}}) {
                   5874:             if (!grep(/^\Q$type\E$/,@searchtypes)) {
                   5875:                 push(@{$changes{'searchtypes'}},$type);
                   5876:             }
                   5877:         }
                   5878:         foreach my $type (@searchtypes) {
                   5879:             if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
                   5880:                 push(@{$changes{'searchtypes'}},$type);
                   5881:             }
                   5882:         }
                   5883:     } else {
                   5884:         if (exists($currdirsrch{'searchtypes'})) {
                   5885:             foreach my $type (@searchtypes) {  
                   5886:                 if ($type ne $currdirsrch{'searchtypes'}) { 
                   5887:                     push(@{$changes{'searchtypes'}},$type);
                   5888:                 }
                   5889:             }
                   5890:             if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
                   5891:                 push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
                   5892:             }   
                   5893:         } else {
                   5894:             push(@{$changes{'searchtypes'}},@searchtypes); 
                   5895:         }
                   5896:     }
                   5897: 
1.23      raeburn  5898:     my %dirsrch_hash =  (
                   5899:             directorysrch => { available => $env{'form.dirsrch_available'},
                   5900:                                cansearch => \@cansearch,
1.24      raeburn  5901:                                localonly => $env{'form.dirsrch_localonly'},
1.23      raeburn  5902:                                searchby => \@searchby,
1.25      raeburn  5903:                                searchtypes => \@searchtypes,
1.23      raeburn  5904:                              }
                   5905:             );
                   5906:     my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
                   5907:                                              $dom);
                   5908:     if ($putresult eq 'ok') {
                   5909:         if (exists($currdirsrch{'available'})) {
                   5910:              if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
                   5911:                  $changes{'available'} = 1;
                   5912:              }
                   5913:         } else {
                   5914:             if ($env{'form.dirsrch_available'} eq '1') {
                   5915:                 $changes{'available'} = 1;
                   5916:             }
                   5917:         }
1.24      raeburn  5918:         if (exists($currdirsrch{'localonly'})) {
                   5919:              if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
                   5920:                  $changes{'localonly'} = 1;
                   5921:              }
                   5922:         } else {
                   5923:             if ($env{'form.dirsrch_localonly'} eq '1') {
                   5924:                 $changes{'localonly'} = 1;
                   5925:             }
                   5926:         }
1.23      raeburn  5927:         if (keys(%changes) > 0) {
                   5928:             $resulttext = &mt('Changes made:').'<ul>';
                   5929:             if ($changes{'available'}) {
                   5930:                 $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
                   5931:             }
1.24      raeburn  5932:             if ($changes{'localonly'}) {
                   5933:                 $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
                   5934:             }
                   5935: 
1.23      raeburn  5936:             if (ref($changes{'cansearch'}) eq 'ARRAY') {
                   5937:                 my $chgtext;
1.26      raeburn  5938:                 if (ref($usertypes) eq 'HASH') {
                   5939:                     if (keys(%{$usertypes}) > 0) {
                   5940:                         foreach my $type (@{$types}) {
                   5941:                             if (grep(/^\Q$type\E$/,@cansearch)) {
                   5942:                                 $chgtext .= $usertypes->{$type}.'; ';
                   5943:                             }
                   5944:                         }
                   5945:                         if (grep(/^default$/,@cansearch)) {
                   5946:                             $chgtext .= $othertitle;
                   5947:                         } else {
                   5948:                             $chgtext =~ s/\; $//;
                   5949:                         }
                   5950:                         $resulttext .= '<li>'.&mt("Users from domain '<span class=\"LC_cusr_emph\">[_1]</span>' permitted to search the institutional directory set to: [_2]",$dom,$chgtext).'</li>';
1.23      raeburn  5951:                     }
                   5952:                 }
                   5953:             }
                   5954:             if (ref($changes{'searchby'}) eq 'ARRAY') {
                   5955:                 my ($searchtitles,$titleorder) = &sorted_searchtitles();
                   5956:                 my $chgtext;
                   5957:                 foreach my $type (@{$titleorder}) {
                   5958:                     if (grep(/^\Q$type\E$/,@searchby)) {
                   5959:                         if (defined($searchtitles->{$type})) {
                   5960:                             $chgtext .= $searchtitles->{$type}.'; ';
                   5961:                         }
                   5962:                     }
                   5963:                 }
                   5964:                 $chgtext =~ s/\; $//;
                   5965:                 $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
                   5966:             }
1.25      raeburn  5967:             if (ref($changes{'searchtypes'}) eq 'ARRAY') {
                   5968:                 my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes(); 
                   5969:                 my $chgtext;
                   5970:                 foreach my $type (@{$srchtypeorder}) {
                   5971:                     if (grep(/^\Q$type\E$/,@searchtypes)) {
                   5972:                         if (defined($srchtypes_desc->{$type})) {
                   5973:                             $chgtext .= $srchtypes_desc->{$type}.'; ';
                   5974:                         }
                   5975:                     }
                   5976:                 }
                   5977:                 $chgtext =~ s/\; $//;
                   5978:                 $resulttext .= '<li>'.&mt("$title{'searchtypes'} set to: \"[_1]\"",$chgtext).'</li>';
1.23      raeburn  5979:             }
                   5980:             $resulttext .= '</ul>';
                   5981:         } else {
                   5982:             $resulttext = &mt('No changes made to institution directory search settings');
                   5983:         }
                   5984:     } else {
                   5985:         $resulttext = '<span class="LC_error">'.
1.27      raeburn  5986:                       &mt('An error occurred: [_1]',$putresult).'</span>';
                   5987:     }
                   5988:     return $resulttext;
                   5989: }
                   5990: 
1.28      raeburn  5991: sub modify_contacts {
                   5992:     my ($dom,%domconfig) = @_;
                   5993:     my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
                   5994:     if (ref($domconfig{'contacts'}) eq 'HASH') {
                   5995:         foreach my $key (keys(%{$domconfig{'contacts'}})) {
                   5996:             $currsetting{$key} = $domconfig{'contacts'}{$key};
                   5997:         }
                   5998:     }
1.134     raeburn  5999:     my (%others,%to,%bcc);
1.28      raeburn  6000:     my @contacts = ('supportemail','adminemail');
1.102     raeburn  6001:     my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
                   6002:                     'requestsmail');
1.28      raeburn  6003:     foreach my $type (@mailings) {
                   6004:         @{$newsetting{$type}} = 
                   6005:             &Apache::loncommon::get_env_multiple('form.'.$type);
                   6006:         foreach my $item (@contacts) {
                   6007:             if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
                   6008:                 $contacts_hash{contacts}{$type}{$item} = 1;
                   6009:             } else {
                   6010:                 $contacts_hash{contacts}{$type}{$item} = 0;
                   6011:             }
                   6012:         }  
                   6013:         $others{$type} = $env{'form.'.$type.'_others'};
                   6014:         $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.134     raeburn  6015:         if ($type eq 'helpdeskmail') {
                   6016:             $bcc{$type} = $env{'form.'.$type.'_bcc'};
                   6017:             $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
                   6018:         }
1.28      raeburn  6019:     }
                   6020:     foreach my $item (@contacts) {
                   6021:         $to{$item} = $env{'form.'.$item};
                   6022:         $contacts_hash{'contacts'}{$item} = $to{$item};
                   6023:     }
                   6024:     if (keys(%currsetting) > 0) {
                   6025:         foreach my $item (@contacts) {
                   6026:             if ($to{$item} ne $currsetting{$item}) {
                   6027:                 $changes{$item} = 1;
                   6028:             }
                   6029:         }
                   6030:         foreach my $type (@mailings) {
                   6031:             foreach my $item (@contacts) {
                   6032:                 if (ref($currsetting{$type}) eq 'HASH') {
                   6033:                     if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
                   6034:                         push(@{$changes{$type}},$item);
                   6035:                     }
                   6036:                 } else {
                   6037:                     push(@{$changes{$type}},@{$newsetting{$type}});
                   6038:                 }
                   6039:             }
                   6040:             if ($others{$type} ne $currsetting{$type}{'others'}) {
                   6041:                 push(@{$changes{$type}},'others');
                   6042:             }
1.134     raeburn  6043:             if ($type eq 'helpdeskmail') {   
                   6044:                 if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
                   6045:                     push(@{$changes{$type}},'bcc'); 
                   6046:                 }
                   6047:             }
1.28      raeburn  6048:         }
                   6049:     } else {
                   6050:         my %default;
                   6051:         $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
                   6052:         $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
                   6053:         $default{'errormail'} = 'adminemail';
                   6054:         $default{'packagesmail'} = 'adminemail';
                   6055:         $default{'helpdeskmail'} = 'supportemail';
1.89      raeburn  6056:         $default{'lonstatusmail'} = 'adminemail';
1.102     raeburn  6057:         $default{'requestsmail'} = 'adminemail';
1.28      raeburn  6058:         foreach my $item (@contacts) {
                   6059:            if ($to{$item} ne $default{$item}) {
                   6060:               $changes{$item} = 1;
                   6061:            } 
                   6062:         }
                   6063:         foreach my $type (@mailings) {
                   6064:             if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
                   6065:                
                   6066:                 push(@{$changes{$type}},@{$newsetting{$type}});
                   6067:             }
                   6068:             if ($others{$type} ne '') {
                   6069:                 push(@{$changes{$type}},'others');
1.134     raeburn  6070:             }
                   6071:             if ($type eq 'helpdeskmail') {
                   6072:                 if ($bcc{$type} ne '') {
                   6073:                     push(@{$changes{$type}},'bcc');
                   6074:                 }
                   6075:             }
1.28      raeburn  6076:         }
                   6077:     }
                   6078:     my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
                   6079:                                              $dom);
                   6080:     if ($putresult eq 'ok') {
                   6081:         if (keys(%changes) > 0) {
                   6082:             my ($titles,$short_titles)  = &contact_titles();
                   6083:             $resulttext = &mt('Changes made:').'<ul>';
                   6084:             foreach my $item (@contacts) {
                   6085:                 if ($changes{$item}) {
                   6086:                     $resulttext .= '<li>'.$titles->{$item}.
                   6087:                                     &mt(' set to: ').
                   6088:                                     '<span class="LC_cusr_emph">'.
                   6089:                                     $to{$item}.'</span></li>';
                   6090:                 }
                   6091:             }
                   6092:             foreach my $type (@mailings) {
                   6093:                 if (ref($changes{$type}) eq 'ARRAY') {
                   6094:                     $resulttext .= '<li>'.$titles->{$type}.': ';
                   6095:                     my @text;
                   6096:                     foreach my $item (@{$newsetting{$type}}) {
                   6097:                         push(@text,$short_titles->{$item});
                   6098:                     }
                   6099:                     if ($others{$type} ne '') {
                   6100:                         push(@text,$others{$type});
                   6101:                     }
                   6102:                     $resulttext .= '<span class="LC_cusr_emph">'.
1.134     raeburn  6103:                                    join(', ',@text).'</span>';
                   6104:                     if ($type eq 'helpdeskmail') {
                   6105:                         if ($bcc{$type} ne '') {
                   6106:                             $resulttext .= '&nbsp;'.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
                   6107:                         }
                   6108:                     }
                   6109:                     $resulttext .= '</li>';
1.28      raeburn  6110:                 }
                   6111:             }
                   6112:             $resulttext .= '</ul>';
                   6113:         } else {
1.34      raeburn  6114:             $resulttext = &mt('No changes made to contact information');
1.28      raeburn  6115:         }
                   6116:     } else {
                   6117:         $resulttext = '<span class="LC_error">'.
                   6118:             &mt('An error occurred: [_1].',$putresult).'</span>';
                   6119:     }
                   6120:     return $resulttext;
                   6121: }
                   6122: 
                   6123: sub modify_usercreation {
1.27      raeburn  6124:     my ($dom,%domconfig) = @_;
1.34      raeburn  6125:     my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate);
1.43      raeburn  6126:     my $warningmsg;
1.27      raeburn  6127:     if (ref($domconfig{'usercreation'}) eq 'HASH') {
                   6128:         foreach my $key (keys(%{$domconfig{'usercreation'}})) {
                   6129:             $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
                   6130:         }
                   6131:     }
                   6132:     my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32      raeburn  6133:     my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.43      raeburn  6134:     my @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
1.100     raeburn  6135:     my @contexts = ('author','course','requestcrs','selfcreate');
1.34      raeburn  6136:     foreach my $item(@contexts) {
1.45      raeburn  6137:         if ($item eq 'selfcreate') {
1.50      raeburn  6138:             @{$cancreate{$item}} = &Apache::loncommon::get_env_multiple('form.can_createuser_'.$item);
1.43      raeburn  6139:             my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
                   6140:             if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) || ($domdefaults{'auth_def'} eq 'localauth'))) {
1.50      raeburn  6141:                 if (ref($cancreate{$item}) eq 'ARRAY') { 
                   6142:                     if (grep(/^login$/,@{$cancreate{$item}})) {
                   6143:                         $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.').' '.&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.');   
                   6144:                     }
1.43      raeburn  6145:                 }
                   6146:             }
1.50      raeburn  6147:         } else {
                   6148:             $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.43      raeburn  6149:         }
1.34      raeburn  6150:     }
1.93      raeburn  6151:     my ($othertitle,$usertypes,$types) = 
                   6152:         &Apache::loncommon::sorted_inst_types($dom);
                   6153:     if (ref($types) eq 'ARRAY') {
                   6154:         if (@{$types} > 0) {
                   6155:             @{$cancreate{'statustocreate'}} = 
                   6156:                 &Apache::loncommon::get_env_multiple('form.statustocreate');
1.103     raeburn  6157:         } else {
                   6158:             @{$cancreate{'statustocreate'}} = ();
1.93      raeburn  6159:         }
                   6160:         push(@contexts,'statustocreate');
                   6161:     }
1.34      raeburn  6162:     if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
                   6163:         foreach my $item (@contexts) {
1.93      raeburn  6164:             if (($item eq 'selfcreate') || ($item eq 'statustocreate')) {
                   6165:                 if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
1.50      raeburn  6166:                     foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
1.103     raeburn  6167:                         if (ref($cancreate{$item}) eq 'ARRAY') {
                   6168:                             if (!grep(/^$curr$/,@{$cancreate{$item}})) {
                   6169:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   6170:                                     push(@{$changes{'cancreate'}},$item);
                   6171:                                 }
1.50      raeburn  6172:                             }
                   6173:                         }
                   6174:                     }
                   6175:                 } else {
                   6176:                     if ($curr_usercreation{'cancreate'}{$item} eq '') {
                   6177:                         if (@{$cancreate{$item}} > 0) {
                   6178:                             if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   6179:                                 push(@{$changes{'cancreate'}},$item);
                   6180:                             }
                   6181:                         }
                   6182:                     } else {
                   6183:                         if ($curr_usercreation{'cancreate'}{$item} eq 'any') {
                   6184:                             if (@{$cancreate{$item}} < 3) {
                   6185:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   6186:                                     push(@{$changes{'cancreate'}},$item);
                   6187:                                 }
                   6188:                             }
                   6189:                         } elsif ($curr_usercreation{'cancreate'}{$item} eq 'none') {
                   6190:                             if (@{$cancreate{$item}} > 0) {
                   6191:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   6192:                                     push(@{$changes{'cancreate'}},$item);
                   6193:                                 }
                   6194:                             }
                   6195:                         } elsif (!grep(/^$curr_usercreation{'cancreate'}{$item}$/,@{$cancreate{$item}})) {
                   6196:                             if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   6197:                                 push(@{$changes{'cancreate'}},$item);
                   6198:                             }
                   6199:                         }
                   6200:                     }
                   6201:                 }
                   6202:                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   6203:                     foreach my $type (@{$cancreate{$item}}) {
                   6204:                         if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
                   6205:                             if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
                   6206:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   6207:                                     push(@{$changes{'cancreate'}},$item);
                   6208:                                 }
                   6209:                             }
                   6210:                         } elsif (($curr_usercreation{'cancreate'}{$item} ne 'any') &&
                   6211:                                  ($curr_usercreation{'cancreate'}{$item} ne 'none')) {
                   6212:                             if ($curr_usercreation{'cancreate'}{$item} ne $type) {
                   6213:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   6214:                                     push(@{$changes{'cancreate'}},$item);
                   6215:                                 }
                   6216:                             }
                   6217:                         }
                   6218:                     }
                   6219:                 }
                   6220:             } else {
                   6221:                 if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
                   6222:                     push(@{$changes{'cancreate'}},$item);
                   6223:                 }
                   6224:             }
1.27      raeburn  6225:         }
1.34      raeburn  6226:     } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
                   6227:         foreach my $item (@contexts) {
1.43      raeburn  6228:             if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34      raeburn  6229:                 if ($cancreate{$item} ne 'any') {
                   6230:                     push(@{$changes{'cancreate'}},$item);
                   6231:                 }
                   6232:             } else {
                   6233:                 if ($cancreate{$item} ne 'none') {
                   6234:                     push(@{$changes{'cancreate'}},$item);
                   6235:                 }
1.27      raeburn  6236:             }
                   6237:         }
                   6238:     } else {
1.43      raeburn  6239:         foreach my $item (@contexts)  {
1.34      raeburn  6240:             push(@{$changes{'cancreate'}},$item);
                   6241:         }
1.27      raeburn  6242:     }
1.34      raeburn  6243: 
1.27      raeburn  6244:     if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
                   6245:         foreach my $type (@{$curr_usercreation{'username_rule'}}) {
                   6246:             if (!grep(/^\Q$type\E$/,@username_rule)) {
                   6247:                 push(@{$changes{'username_rule'}},$type);
                   6248:             }
                   6249:         }
                   6250:         foreach my $type (@username_rule) {
                   6251:             if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
                   6252:                 push(@{$changes{'username_rule'}},$type);
                   6253:             }
                   6254:         }
                   6255:     } else {
                   6256:         push(@{$changes{'username_rule'}},@username_rule);
                   6257:     }
                   6258: 
1.32      raeburn  6259:     if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
                   6260:         foreach my $type (@{$curr_usercreation{'id_rule'}}) {
                   6261:             if (!grep(/^\Q$type\E$/,@id_rule)) {
                   6262:                 push(@{$changes{'id_rule'}},$type);
                   6263:             }
                   6264:         }
                   6265:         foreach my $type (@id_rule) {
                   6266:             if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
                   6267:                 push(@{$changes{'id_rule'}},$type);
                   6268:             }
                   6269:         }
                   6270:     } else {
                   6271:         push(@{$changes{'id_rule'}},@id_rule);
                   6272:     }
                   6273: 
1.43      raeburn  6274:     if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
                   6275:         foreach my $type (@{$curr_usercreation{'email_rule'}}) {
                   6276:             if (!grep(/^\Q$type\E$/,@email_rule)) {
                   6277:                 push(@{$changes{'email_rule'}},$type);
                   6278:             }
                   6279:         }
                   6280:         foreach my $type (@email_rule) {
                   6281:             if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
                   6282:                 push(@{$changes{'email_rule'}},$type);
                   6283:             }
                   6284:         }
                   6285:     } else {
                   6286:         push(@{$changes{'email_rule'}},@email_rule);
                   6287:     }
                   6288: 
                   6289:     my @authen_contexts = ('author','course','domain');
1.28      raeburn  6290:     my @authtypes = ('int','krb4','krb5','loc');
                   6291:     my %authhash;
1.43      raeburn  6292:     foreach my $item (@authen_contexts) {
1.28      raeburn  6293:         my @authallowed =  &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
                   6294:         foreach my $auth (@authtypes) {
                   6295:             if (grep(/^\Q$auth\E$/,@authallowed)) {
                   6296:                 $authhash{$item}{$auth} = 1;
                   6297:             } else {
                   6298:                 $authhash{$item}{$auth} = 0;
                   6299:             }
                   6300:         }
                   6301:     }
                   6302:     if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43      raeburn  6303:         foreach my $item (@authen_contexts) {
1.28      raeburn  6304:             if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
                   6305:                 foreach my $auth (@authtypes) {
                   6306:                     if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
                   6307:                         push(@{$changes{'authtypes'}},$item);
                   6308:                         last;
                   6309:                     }
                   6310:                 }
                   6311:             }
                   6312:         }
                   6313:     } else {
1.43      raeburn  6314:         foreach my $item (@authen_contexts) {
1.28      raeburn  6315:             push(@{$changes{'authtypes'}},$item);
                   6316:         }
                   6317:     }
                   6318: 
1.27      raeburn  6319:     my %usercreation_hash =  (
1.28      raeburn  6320:             usercreation => {
1.34      raeburn  6321:                               cancreate     => \%cancreate,
1.27      raeburn  6322:                               username_rule => \@username_rule,
1.32      raeburn  6323:                               id_rule       => \@id_rule,
1.43      raeburn  6324:                               email_rule    => \@email_rule,
1.32      raeburn  6325:                               authtypes     => \%authhash,
1.27      raeburn  6326:                             }
                   6327:             );
                   6328: 
                   6329:     my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
                   6330:                                              $dom);
1.50      raeburn  6331: 
                   6332:     my %selfcreatetypes = (
                   6333:                              sso   => 'users authenticated by institutional single sign on',
                   6334:                              login => 'users authenticated by institutional log-in',
                   6335:                              email => 'users who provide a valid e-mail address for use as the username',
                   6336:                           );
1.27      raeburn  6337:     if ($putresult eq 'ok') {
                   6338:         if (keys(%changes) > 0) {
                   6339:             $resulttext = &mt('Changes made:').'<ul>';
                   6340:             if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.34      raeburn  6341:                 my %lt = &usercreation_types();
                   6342:                 foreach my $type (@{$changes{'cancreate'}}) {
1.100     raeburn  6343:                     my $chgtext;
                   6344:                     unless ($type eq 'statustocreate') {
                   6345:                         $chgtext = $lt{$type}.', ';
                   6346:                     }
1.45      raeburn  6347:                     if ($type eq 'selfcreate') {
1.50      raeburn  6348:                         if (@{$cancreate{$type}} == 0) {
1.43      raeburn  6349:                             $chgtext .= &mt('creation of a new user account is not permitted.');
1.50      raeburn  6350:                         } else {
1.100     raeburn  6351:                             $chgtext .= &mt('creation of a new account is permitted for:').'<ul>';
1.50      raeburn  6352:                             foreach my $case (@{$cancreate{$type}}) {
                   6353:                                 $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
                   6354:                             }
                   6355:                             $chgtext .= '</ul>';
1.100     raeburn  6356:                             if (ref($cancreate{$type}) eq 'ARRAY') {
                   6357:                                 if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
                   6358:                                     if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
                   6359:                                         if (@{$cancreate{'statustocreate'}} == 0) {
                   6360:                                             $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
                   6361:                                         }
                   6362:                                     }
                   6363:                                 }
                   6364:                             }
1.43      raeburn  6365:                         }
1.93      raeburn  6366:                     } elsif ($type eq 'statustocreate') {
1.96      raeburn  6367:                         if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
                   6368:                             (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
                   6369:                             if (@{$cancreate{'selfcreate'}} > 0) {
                   6370:                                 if (@{$cancreate{'statustocreate'}} == 0) {
1.100     raeburn  6371: 
                   6372:                                     $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96      raeburn  6373:                                     if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.100     raeburn  6374:                                         $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
                   6375:                                     } 
1.96      raeburn  6376:                                 } elsif (ref($usertypes) eq 'HASH') {
                   6377:                                     if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100     raeburn  6378:                                         $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
                   6379:                                     } else {
                   6380:                                         $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
                   6381:                                     }
                   6382:                                     $chgtext .= '<ul>';
                   6383:                                     foreach my $case (@{$cancreate{$type}}) {
                   6384:                                         if ($case eq 'default') {
                   6385:                                             $chgtext .= '<li>'.$othertitle.'</li>';
                   6386:                                         } else {
                   6387:                                             $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93      raeburn  6388:                                         }
                   6389:                                     }
1.100     raeburn  6390:                                     $chgtext .= '</ul>';
                   6391:                                     if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
                   6392:                                         $chgtext .= '<br /><span class="LC_warning">'.&mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').'</span>';
                   6393:                                     }
                   6394:                                 }
                   6395:                             } else {
                   6396:                                 if (@{$cancreate{$type}} == 0) {
                   6397:                                     $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
                   6398:                                 } else {
                   6399:                                     $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  6400:                                 }
                   6401:                             }
                   6402:                         }
1.43      raeburn  6403:                     } else {
                   6404:                         if ($cancreate{$type} eq 'none') {
                   6405:                             $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
                   6406:                         } elsif ($cancreate{$type} eq 'any') {
                   6407:                             $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
                   6408:                         } elsif ($cancreate{$type} eq 'official') {
                   6409:                             $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
                   6410:                         } elsif ($cancreate{$type} eq 'unofficial') {
                   6411:                             $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
                   6412:                         }
1.34      raeburn  6413:                     }
                   6414:                     $resulttext .= '<li>'.$chgtext.'</li>';
1.27      raeburn  6415:                 }
                   6416:             }
                   6417:             if (ref($changes{'username_rule'}) eq 'ARRAY') {
1.32      raeburn  6418:                 my ($rules,$ruleorder) = 
                   6419:                     &Apache::lonnet::inst_userrules($dom,'username');
1.27      raeburn  6420:                 my $chgtext = '<ul>';
                   6421:                 foreach my $type (@username_rule) {
                   6422:                     if (ref($rules->{$type}) eq 'HASH') {
                   6423:                         $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
                   6424:                     }
                   6425:                 }
                   6426:                 $chgtext .= '</ul>';
                   6427:                 if (@username_rule > 0) {
                   6428:                     $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';     
                   6429:                 } else {
1.28      raeburn  6430:                     $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>'; 
1.27      raeburn  6431:                 }
                   6432:             }
1.32      raeburn  6433:             if (ref($changes{'id_rule'}) eq 'ARRAY') {
                   6434:                 my ($idrules,$idruleorder) = 
                   6435:                     &Apache::lonnet::inst_userrules($dom,'id');
                   6436:                 my $chgtext = '<ul>';
                   6437:                 foreach my $type (@id_rule) {
                   6438:                     if (ref($idrules->{$type}) eq 'HASH') {
                   6439:                         $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
                   6440:                     }
                   6441:                 }
                   6442:                 $chgtext .= '</ul>';
                   6443:                 if (@id_rule > 0) {
                   6444:                     $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
                   6445:                 } else {
                   6446:                     $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
                   6447:                 }
                   6448:             }
1.43      raeburn  6449:             if (ref($changes{'email_rule'}) eq 'ARRAY') {
                   6450:                 my ($emailrules,$emailruleorder) =
                   6451:                     &Apache::lonnet::inst_userrules($dom,'email');
                   6452:                 my $chgtext = '<ul>';
                   6453:                 foreach my $type (@email_rule) {
                   6454:                     if (ref($emailrules->{$type}) eq 'HASH') {
                   6455:                         $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
                   6456:                     }
                   6457:                 }
                   6458:                 $chgtext .= '</ul>';
                   6459:                 if (@email_rule > 0) {
                   6460:                     $resulttext .= '<li>'.&mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').$chgtext.'</li>';
                   6461:                 } else {
                   6462:                     $resulttext .= '<li>'.&mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').'</li>';
                   6463:                 }
                   6464:             }
                   6465: 
1.28      raeburn  6466:             my %authname = &authtype_names();
                   6467:             my %context_title = &context_names();
                   6468:             if (ref($changes{'authtypes'}) eq 'ARRAY') {
                   6469:                 my $chgtext = '<ul>';
                   6470:                 foreach my $type (@{$changes{'authtypes'}}) {
                   6471:                     my @allowed;
                   6472:                     $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
                   6473:                     foreach my $auth (@authtypes) {
                   6474:                         if ($authhash{$type}{$auth}) {
                   6475:                             push(@allowed,$authname{$auth});
                   6476:                         }
                   6477:                     }
1.43      raeburn  6478:                     if (@allowed > 0) {
                   6479:                         $chgtext .= join(', ',@allowed).'</li>';
                   6480:                     } else {
                   6481:                         $chgtext .= &mt('none').'</li>';
                   6482:                     }
1.28      raeburn  6483:                 }
                   6484:                 $chgtext .= '</ul>';
                   6485:                 $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
                   6486:                 $resulttext .= '</li>';
                   6487:             }
1.27      raeburn  6488:             $resulttext .= '</ul>';
                   6489:         } else {
1.28      raeburn  6490:             $resulttext = &mt('No changes made to user creation settings');
1.27      raeburn  6491:         }
                   6492:     } else {
                   6493:         $resulttext = '<span class="LC_error">'.
1.23      raeburn  6494:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   6495:     }
1.43      raeburn  6496:     if ($warningmsg ne '') {
                   6497:         $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
                   6498:     }
1.23      raeburn  6499:     return $resulttext;
                   6500: }
                   6501: 
1.33      raeburn  6502: sub modify_usermodification {
                   6503:     my ($dom,%domconfig) = @_;
                   6504:     my ($resulttext,%curr_usermodification,%changes);
                   6505:     if (ref($domconfig{'usermodification'}) eq 'HASH') {
                   6506:         foreach my $key (keys(%{$domconfig{'usermodification'}})) {
                   6507:             $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
                   6508:         }
                   6509:     }
1.63      raeburn  6510:     my @contexts = ('author','course','selfcreate');
1.33      raeburn  6511:     my %context_title = (
                   6512:                            author => 'In author context',
                   6513:                            course => 'In course context',
1.63      raeburn  6514:                            selfcreate => 'When self creating account', 
1.33      raeburn  6515:                         );
                   6516:     my @fields = ('lastname','firstname','middlename','generation',
                   6517:                   'permanentemail','id');
                   6518:     my %roles = (
                   6519:                   author => ['ca','aa'],
                   6520:                   course => ['st','ep','ta','in','cr'],
                   6521:                 );
1.63      raeburn  6522:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   6523:     if (ref($types) eq 'ARRAY') {
                   6524:         push(@{$types},'default');
                   6525:         $usertypes->{'default'} = $othertitle;
                   6526:     }
                   6527:     $roles{'selfcreate'} = $types;  
1.33      raeburn  6528:     my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
                   6529:     my %modifyhash;
                   6530:     foreach my $context (@contexts) {
                   6531:         foreach my $role (@{$roles{$context}}) {
                   6532:             my @modifiable =  &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
                   6533:             foreach my $item (@fields) {
                   6534:                 if (grep(/^\Q$item\E$/,@modifiable)) {
                   6535:                     $modifyhash{$context}{$role}{$item} = 1;
                   6536:                 } else {
                   6537:                     $modifyhash{$context}{$role}{$item} = 0;
                   6538:                 }
                   6539:             }
                   6540:         }
                   6541:         if (ref($curr_usermodification{$context}) eq 'HASH') {
                   6542:             foreach my $role (@{$roles{$context}}) {
                   6543:                 if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
                   6544:                     foreach my $field (@fields) {
                   6545:                         if ($modifyhash{$context}{$role}{$field} ne 
                   6546:                                 $curr_usermodification{$context}{$role}{$field}) {
                   6547:                             push(@{$changes{$context}},$role);
                   6548:                             last;
                   6549:                         }
                   6550:                     }
                   6551:                 }
                   6552:             }
                   6553:         } else {
                   6554:             foreach my $context (@contexts) {
                   6555:                 foreach my $role (@{$roles{$context}}) {
                   6556:                     push(@{$changes{$context}},$role);
                   6557:                 }
                   6558:             }
                   6559:         }
                   6560:     }
                   6561:     my %usermodification_hash =  (
                   6562:                                    usermodification => \%modifyhash,
                   6563:                                  );
                   6564:     my $putresult = &Apache::lonnet::put_dom('configuration',
                   6565:                                              \%usermodification_hash,$dom);
                   6566:     if ($putresult eq 'ok') {
                   6567:         if (keys(%changes) > 0) {
                   6568:             $resulttext = &mt('Changes made: ').'<ul>';
                   6569:             foreach my $context (@contexts) {
                   6570:                 if (ref($changes{$context}) eq 'ARRAY') {
                   6571:                     $resulttext .= '<li>'.$context_title{$context}.':<ul>';
                   6572:                     if (ref($changes{$context}) eq 'ARRAY') {
                   6573:                         foreach my $role (@{$changes{$context}}) {
                   6574:                             my $rolename;
1.63      raeburn  6575:                             if ($context eq 'selfcreate') {
                   6576:                                 $rolename = $role;
                   6577:                                 if (ref($usertypes) eq 'HASH') {
                   6578:                                     if ($usertypes->{$role} ne '') {
                   6579:                                         $rolename = $usertypes->{$role};
                   6580:                                     }
                   6581:                                 }
1.33      raeburn  6582:                             } else {
1.63      raeburn  6583:                                 if ($role eq 'cr') {
                   6584:                                     $rolename = &mt('Custom');
                   6585:                                 } else {
                   6586:                                     $rolename = &Apache::lonnet::plaintext($role);
                   6587:                                 }
1.33      raeburn  6588:                             }
                   6589:                             my @modifiable;
1.63      raeburn  6590:                             if ($context eq 'selfcreate') {
1.126     bisitz   6591:                                 $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Self-creation of account by users with status: [_1]',$rolename).'</span> - '.&mt('modifiable fields (if institutional data blank): ');
1.63      raeburn  6592:                             } else {
                   6593:                                 $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
                   6594:                             }
1.33      raeburn  6595:                             foreach my $field (@fields) {
                   6596:                                 if ($modifyhash{$context}{$role}{$field}) {
                   6597:                                     push(@modifiable,$fieldtitles{$field});
                   6598:                                 }
                   6599:                             }
                   6600:                             if (@modifiable > 0) {
                   6601:                                 $resulttext .= join(', ',@modifiable);
                   6602:                             } else {
                   6603:                                 $resulttext .= &mt('none'); 
                   6604:                             }
                   6605:                             $resulttext .= '</li>';
                   6606:                         }
                   6607:                         $resulttext .= '</ul></li>';
                   6608:                     }
                   6609:                 }
                   6610:             }
                   6611:             $resulttext .= '</ul>';
                   6612:         } else {
                   6613:             $resulttext = &mt('No changes made to user modification settings');
                   6614:         }
                   6615:     } else {
                   6616:         $resulttext = '<span class="LC_error">'.
                   6617:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   6618:     }
                   6619:     return $resulttext;
                   6620: }
                   6621: 
1.43      raeburn  6622: sub modify_defaults {
                   6623:     my ($dom,$r) = @_;
                   6624:     my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
                   6625:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.141     raeburn  6626:     my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
1.43      raeburn  6627:     my @authtypes = ('internal','krb4','krb5','localauth');
                   6628:     foreach my $item (@items) {
                   6629:         $newvalues{$item} = $env{'form.'.$item};
                   6630:         if ($item eq 'auth_def') {
                   6631:             if ($newvalues{$item} ne '') {
                   6632:                 if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
                   6633:                     push(@errors,$item);
                   6634:                 }
                   6635:             }
                   6636:         } elsif ($item eq 'lang_def') {
                   6637:             if ($newvalues{$item} ne '') {
                   6638:                 if ($newvalues{$item} =~ /^(\w+)/) {
                   6639:                     my $langcode = $1;
1.103     raeburn  6640:                     if ($langcode ne 'x_chef') {
                   6641:                         if (code2language($langcode) eq '') {
                   6642:                             push(@errors,$item);
                   6643:                         }
1.43      raeburn  6644:                     }
                   6645:                 } else {
                   6646:                     push(@errors,$item);
                   6647:                 }
                   6648:             }
1.54      raeburn  6649:         } elsif ($item eq 'timezone_def') {
                   6650:             if ($newvalues{$item} ne '') {
1.62      raeburn  6651:                 if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54      raeburn  6652:                     push(@errors,$item);   
                   6653:                 }
                   6654:             }
1.68      raeburn  6655:         } elsif ($item eq 'datelocale_def') {
                   6656:             if ($newvalues{$item} ne '') {
                   6657:                 my @datelocale_ids = DateTime::Locale->ids();
                   6658:                 if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
                   6659:                     push(@errors,$item);
                   6660:                 }
                   6661:             }
1.141     raeburn  6662:         } elsif ($item eq 'portal_def') {
                   6663:             if ($newvalues{$item} ne '') {
                   6664:                 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])\/?$/) {
                   6665:                     push(@errors,$item);
                   6666:                 }
                   6667:             }
1.43      raeburn  6668:         }
                   6669:         if (grep(/^\Q$item\E$/,@errors)) {
                   6670:             $newvalues{$item} = $domdefaults{$item};
                   6671:         } elsif ($domdefaults{$item} ne $newvalues{$item}) {
                   6672:             $changes{$item} = 1;
                   6673:         }
1.72      raeburn  6674:         $domdefaults{$item} = $newvalues{$item};
1.43      raeburn  6675:     }
                   6676:     my %defaults_hash = (
1.72      raeburn  6677:                          defaults => \%newvalues,
                   6678:                         );
1.43      raeburn  6679:     my $title = &defaults_titles();
                   6680:     my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
                   6681:                                              $dom);
                   6682:     if ($putresult eq 'ok') {
                   6683:         if (keys(%changes) > 0) {
                   6684:             $resulttext = &mt('Changes made:').'<ul>';
                   6685:             my $version = $r->dir_config('lonVersion');
                   6686:             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";
                   6687:             foreach my $item (sort(keys(%changes))) {
                   6688:                 my $value = $env{'form.'.$item};
                   6689:                 if ($value eq '') {
                   6690:                     $value = &mt('none');
                   6691:                 } elsif ($item eq 'auth_def') {
                   6692:                     my %authnames = &authtype_names();
                   6693:                     my %shortauth = (
                   6694:                              internal => 'int',
                   6695:                              krb4 => 'krb4',
                   6696:                              krb5 => 'krb5',
                   6697:                              localauth  => 'loc',
                   6698:                     );
                   6699:                     $value = $authnames{$shortauth{$value}};
                   6700:                 }
                   6701:                 $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
                   6702:                 $mailmsgtext .= "$title->{$item} set to $value\n";  
                   6703:             }
                   6704:             $resulttext .= '</ul>';
                   6705:             $mailmsgtext .= "\n";
                   6706:             my $cachetime = 24*60*60;
1.72      raeburn  6707:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.68      raeburn  6708:             if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.54      raeburn  6709:                 my $sysmail = $r->dir_config('lonSysEMail');
                   6710:                 &Apache::lonmsg::sendemail($sysmail,"LON-CAPA Domain Settings Change - $dom",$mailmsgtext);
                   6711:             }
1.43      raeburn  6712:         } else {
1.54      raeburn  6713:             $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43      raeburn  6714:         }
                   6715:     } else {
                   6716:         $resulttext = '<span class="LC_error">'.
                   6717:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   6718:     }
                   6719:     if (@errors > 0) {
                   6720:         $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
                   6721:         foreach my $item (@errors) {
                   6722:             $resulttext .= ' "'.$title->{$item}.'",';
                   6723:         }
                   6724:         $resulttext =~ s/,$//;
                   6725:     }
                   6726:     return $resulttext;
                   6727: }
                   6728: 
1.46      raeburn  6729: sub modify_scantron {
1.48      raeburn  6730:     my ($r,$dom,$confname,%domconfig) = @_;
1.46      raeburn  6731:     my ($resulttext,%confhash,%changes,$errors);
                   6732:     my $custom = 'custom.tab';
                   6733:     my $default = 'default.tab';
                   6734:     my $servadm = $r->dir_config('lonAdmEMail');
                   6735:     my ($configuserok,$author_ok,$switchserver) = 
                   6736:         &config_check($dom,$confname,$servadm);
                   6737:     if ($env{'form.scantronformat.filename'} ne '') {
                   6738:         my $error;
                   6739:         if ($configuserok eq 'ok') {
                   6740:             if ($switchserver) {
1.130     raeburn  6741:                 $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46      raeburn  6742:             } else {
                   6743:                 if ($author_ok eq 'ok') {
                   6744:                     my ($result,$scantronurl) =
                   6745:                         &publishlogo($r,'upload','scantronformat',$dom,
                   6746:                                      $confname,'scantron','','',$custom);
                   6747:                     if ($result eq 'ok') {
                   6748:                         $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48      raeburn  6749:                         $changes{'scantronformat'} = 1;
1.46      raeburn  6750:                     } else {
                   6751:                         $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
                   6752:                     }
                   6753:                 } else {
                   6754:                     $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);
                   6755:                 }
                   6756:             }
                   6757:         } else {
                   6758:             $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);
                   6759:         }
                   6760:         if ($error) {
                   6761:             &Apache::lonnet::logthis($error);
                   6762:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   6763:         }
                   6764:     }
1.48      raeburn  6765:     if (ref($domconfig{'scantron'}) eq 'HASH') {
                   6766:         if ($domconfig{'scantron'}{'scantronformat'} ne '') {
                   6767:             if ($env{'form.scantronformat_del'}) {
                   6768:                 $confhash{'scantron'}{'scantronformat'} = '';
                   6769:                 $changes{'scantronformat'} = 1;
1.46      raeburn  6770:             }
                   6771:         }
                   6772:     }
                   6773:     if (keys(%confhash) > 0) {
                   6774:         my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
                   6775:                                                  $dom);
                   6776:         if ($putresult eq 'ok') {
                   6777:             if (keys(%changes) > 0) {
1.48      raeburn  6778:                 if (ref($confhash{'scantron'}) eq 'HASH') {
                   6779:                     $resulttext = &mt('Changes made:').'<ul>';
                   6780:                     if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130     raeburn  6781:                         $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48      raeburn  6782:                     } else {
1.130     raeburn  6783:                         $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46      raeburn  6784:                     }
1.48      raeburn  6785:                     $resulttext .= '</ul>';
                   6786:                 } else {
1.130     raeburn  6787:                     $resulttext = &mt('Changes made to bubblesheet format file.');
1.46      raeburn  6788:                 }
                   6789:                 $resulttext .= '</ul>';
                   6790:                 &Apache::loncommon::devalidate_domconfig_cache($dom);
                   6791:             } else {
1.130     raeburn  6792:                 $resulttext = &mt('No changes made to bubblesheet format file');
1.46      raeburn  6793:             }
                   6794:         } else {
                   6795:             $resulttext = '<span class="LC_error">'.
                   6796:                 &mt('An error occurred: [_1]',$putresult).'</span>';
                   6797:         }
                   6798:     } else {
1.130     raeburn  6799:         $resulttext = &mt('No changes made to bubblesheet format file'); 
1.46      raeburn  6800:     }
                   6801:     if ($errors) {
                   6802:         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
                   6803:                        $errors.'</ul>';
                   6804:     }
                   6805:     return $resulttext;
                   6806: }
                   6807: 
1.48      raeburn  6808: sub modify_coursecategories {
                   6809:     my ($dom,%domconfig) = @_;
1.57      raeburn  6810:     my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
                   6811:         $cathash);
1.48      raeburn  6812:     my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.55      raeburn  6813:     if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57      raeburn  6814:         $cathash = $domconfig{'coursecategories'}{'cats'};
                   6815:         if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
                   6816:             $changes{'togglecats'} = 1;
                   6817:             $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
                   6818:         }
                   6819:         if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
                   6820:             $changes{'categorize'} = 1;
                   6821:             $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
                   6822:         }
1.120     raeburn  6823:         if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
                   6824:             $changes{'togglecatscomm'} = 1;
                   6825:             $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
                   6826:         }
                   6827:         if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
                   6828:             $changes{'categorizecomm'} = 1;
                   6829:             $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
                   6830:         }
1.57      raeburn  6831:     } else {
                   6832:         $changes{'togglecats'} = 1;
                   6833:         $changes{'categorize'} = 1;
1.124     raeburn  6834:         $changes{'togglecatscomm'} = 1;
                   6835:         $changes{'categorizecomm'} = 1;
1.87      raeburn  6836:         $domconfig{'coursecategories'} = {
                   6837:                                              togglecats => $env{'form.togglecats'},
                   6838:                                              categorize => $env{'form.categorize'},
1.124     raeburn  6839:                                              togglecatscomm => $env{'form.togglecatscomm'},
                   6840:                                              categorizecomm => $env{'form.categorizecomm'},
1.120     raeburn  6841:                                          };
1.57      raeburn  6842:     }
                   6843:     if (ref($cathash) eq 'HASH') {
                   6844:         if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '')  && ($env{'form.instcode'} == 0)) {
1.55      raeburn  6845:             push (@deletecategory,'instcode::0');
                   6846:         }
1.120     raeburn  6847:         if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '')  && ($env{'form.communities'} == 0)) {
                   6848:             push(@deletecategory,'communities::0');
                   6849:         }
1.48      raeburn  6850:     }
1.57      raeburn  6851:     my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
                   6852:     if (ref($cathash) eq 'HASH') {
1.48      raeburn  6853:         if (@deletecategory > 0) {
                   6854:             #FIXME Need to remove category from all courses using a deleted category 
1.57      raeburn  6855:             &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48      raeburn  6856:             foreach my $item (@deletecategory) {
1.57      raeburn  6857:                 if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
                   6858:                     delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48      raeburn  6859:                     $deletions{$item} = 1;
1.57      raeburn  6860:                     &recurse_cat_deletes($item,$cathash,\%deletions);
1.48      raeburn  6861:                 }
                   6862:             }
                   6863:         }
1.57      raeburn  6864:         foreach my $item (keys(%{$cathash})) {
1.48      raeburn  6865:             my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57      raeburn  6866:             if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48      raeburn  6867:                 $reorderings{$item} = 1;
1.57      raeburn  6868:                 $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48      raeburn  6869:             }
                   6870:             if ($env{'form.addcategory_name_'.$item} ne '') {
                   6871:                 my $newcat = $env{'form.addcategory_name_'.$item};
                   6872:                 my $newdepth = $depth+1;
                   6873:                 my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57      raeburn  6874:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48      raeburn  6875:                 $adds{$newitem} = 1; 
                   6876:             }
                   6877:             if ($env{'form.subcat_'.$item} ne '') {
                   6878:                 my $newcat = $env{'form.subcat_'.$item};
                   6879:                 my $newdepth = $depth+1;
                   6880:                 my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57      raeburn  6881:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48      raeburn  6882:                 $adds{$newitem} = 1;
                   6883:             }
                   6884:         }
                   6885:     }
                   6886:     if ($env{'form.instcode'} eq '1') {
1.57      raeburn  6887:         if (ref($cathash) eq 'HASH') {
1.48      raeburn  6888:             my $newitem = 'instcode::0';
1.57      raeburn  6889:             if ($cathash->{$newitem} eq '') {  
                   6890:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48      raeburn  6891:                 $adds{$newitem} = 1;
                   6892:             }
                   6893:         } else {
                   6894:             my $newitem = 'instcode::0';
1.57      raeburn  6895:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48      raeburn  6896:             $adds{$newitem} = 1;
                   6897:         }
                   6898:     }
1.120     raeburn  6899:     if ($env{'form.communities'} eq '1') {
                   6900:         if (ref($cathash) eq 'HASH') {
                   6901:             my $newitem = 'communities::0';
                   6902:             if ($cathash->{$newitem} eq '') {
                   6903:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
                   6904:                 $adds{$newitem} = 1;
                   6905:             }
                   6906:         } else {
                   6907:             my $newitem = 'communities::0';
                   6908:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
                   6909:             $adds{$newitem} = 1;
                   6910:         }
                   6911:     }
1.48      raeburn  6912:     if ($env{'form.addcategory_name'} ne '') {
1.120     raeburn  6913:         if (($env{'form.addcategory_name'} ne 'instcode') &&
                   6914:             ($env{'form.addcategory_name'} ne 'communities')) {
                   6915:             my $newitem = &escape($env{'form.addcategory_name'}).'::0';
                   6916:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
                   6917:             $adds{$newitem} = 1;
                   6918:         }
1.48      raeburn  6919:     }
1.57      raeburn  6920:     my $putresult;
1.48      raeburn  6921:     if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
                   6922:         if (keys(%deletions) > 0) {
                   6923:             foreach my $key (keys(%deletions)) {
                   6924:                 if ($predelallitems{$key} ne '') {
                   6925:                     $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
                   6926:                 }
                   6927:             }
                   6928:         }
                   6929:         my (@chkcats,@chktrails,%chkallitems);
1.57      raeburn  6930:         &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48      raeburn  6931:         if (ref($chkcats[0]) eq 'ARRAY') {
                   6932:             my $depth = 0;
                   6933:             my $chg = 0;
                   6934:             for (my $i=0; $i<@{$chkcats[0]}; $i++) {
                   6935:                 my $name = $chkcats[0][$i];
                   6936:                 my $item;
                   6937:                 if ($name eq '') {
                   6938:                     $chg ++;
                   6939:                 } else {
                   6940:                     $item = &escape($name).'::0';
                   6941:                     if ($chg) {
1.57      raeburn  6942:                         $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48      raeburn  6943:                     }
                   6944:                     $depth ++; 
1.57      raeburn  6945:                     &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48      raeburn  6946:                     $depth --;
                   6947:                 }
                   6948:             }
                   6949:         }
1.57      raeburn  6950:     }
                   6951:     if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
                   6952:         $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48      raeburn  6953:         if ($putresult eq 'ok') {
1.57      raeburn  6954:             my %title = (
1.120     raeburn  6955:                          togglecats     => 'Show/Hide a course in catalog',
                   6956:                          categorize     => 'Assign a category to a course',
                   6957:                          togglecatscomm => 'Show/Hide a community in catalog',
                   6958:                          categorizecomm => 'Assign a category to a community',
1.57      raeburn  6959:                         );
                   6960:             my %level = (
1.120     raeburn  6961:                          dom  => 'set in Domain ("Modify Course/Community")',
                   6962:                          crs  => 'set in Course ("Course Configuration")',
                   6963:                          comm => 'set in Community ("Community Configuration")',
1.57      raeburn  6964:                         );
1.48      raeburn  6965:             $resulttext = &mt('Changes made:').'<ul>';
1.57      raeburn  6966:             if ($changes{'togglecats'}) {
                   6967:                 $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>'; 
                   6968:             }
                   6969:             if ($changes{'categorize'}) {
                   6970:                 $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48      raeburn  6971:             }
1.120     raeburn  6972:             if ($changes{'togglecatscomm'}) {
                   6973:                 $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
                   6974:             }
                   6975:             if ($changes{'categorizecomm'}) {
                   6976:                 $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
                   6977:             }
1.57      raeburn  6978:             if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
                   6979:                 my $cathash;
                   6980:                 if (ref($domconfig{'coursecategories'}) eq 'HASH') {
                   6981:                     $cathash = $domconfig{'coursecategories'}{'cats'};
                   6982:                 } else {
                   6983:                     $cathash = {};
                   6984:                 } 
                   6985:                 my (@cats,@trails,%allitems);
                   6986:                     &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
                   6987:                 if (keys(%deletions) > 0) {
                   6988:                     $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
                   6989:                     foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) { 
                   6990:                         $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
                   6991:                     }
                   6992:                     $resulttext .= '</ul></li>';
                   6993:                 }
                   6994:                 if (keys(%reorderings) > 0) {
                   6995:                     my %sort_by_trail;
                   6996:                     $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
                   6997:                     foreach my $key (keys(%reorderings)) {
                   6998:                         if ($allitems{$key} ne '') {
                   6999:                             $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
                   7000:                         }
1.48      raeburn  7001:                     }
1.57      raeburn  7002:                     foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
                   7003:                         $resulttext .= '<li>'.$trails[$trail].'</li>';
                   7004:                     }
                   7005:                     $resulttext .= '</ul></li>';
1.48      raeburn  7006:                 }
1.57      raeburn  7007:                 if (keys(%adds) > 0) {
                   7008:                     my %sort_by_trail;
                   7009:                     $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
                   7010:                     foreach my $key (keys(%adds)) {
                   7011:                         if ($allitems{$key} ne '') {
                   7012:                             $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
                   7013:                         }
                   7014:                     }
                   7015:                     foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
                   7016:                         $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48      raeburn  7017:                     }
1.57      raeburn  7018:                     $resulttext .= '</ul></li>';
1.48      raeburn  7019:                 }
                   7020:             }
                   7021:             $resulttext .= '</ul>';
                   7022:         } else {
                   7023:             $resulttext = '<span class="LC_error">'.
1.57      raeburn  7024:                           &mt('An error occurred: [_1]',$putresult).'</span>';
1.48      raeburn  7025:         }
                   7026:     } else {
1.120     raeburn  7027:         $resulttext = &mt('No changes made to course and community categories');
1.48      raeburn  7028:     }
                   7029:     return $resulttext;
                   7030: }
                   7031: 
1.69      raeburn  7032: sub modify_serverstatuses {
                   7033:     my ($dom,%domconfig) = @_;
                   7034:     my ($resulttext,%changes,%currserverstatus,%newserverstatus);
                   7035:     if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
                   7036:         %currserverstatus = %{$domconfig{'serverstatuses'}};
                   7037:     }
                   7038:     my @pages = &serverstatus_pages();
                   7039:     foreach my $type (@pages) {
                   7040:         $newserverstatus{$type}{'namedusers'} = '';
                   7041:         $newserverstatus{$type}{'machines'} = '';
                   7042:         if (defined($env{'form.'.$type.'_namedusers'})) {
                   7043:             my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
                   7044:             my @okusers;
                   7045:             foreach my $user (@users) {
                   7046:                 my ($uname,$udom) = split(/:/,$user);
                   7047:                 if (($udom =~ /^$match_domain$/) &&   
                   7048:                     (&Apache::lonnet::domain($udom)) &&
                   7049:                     ($uname =~ /^$match_username$/)) {
                   7050:                     if (!grep(/^\Q$user\E/,@okusers)) {
                   7051:                         push(@okusers,$user);
                   7052:                     }
                   7053:                 }
                   7054:             }
                   7055:             if (@okusers > 0) {
                   7056:                  @okusers = sort(@okusers);
                   7057:                  $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
                   7058:             }
                   7059:         }
                   7060:         if (defined($env{'form.'.$type.'_machines'})) {
                   7061:             my @machines = split(/,/,$env{'form.'.$type.'_machines'});
                   7062:             my @okmachines;
                   7063:             foreach my $ip (@machines) {
                   7064:                 my @parts = split(/\./,$ip);
                   7065:                 next if (@parts < 4);
                   7066:                 my $badip = 0;
                   7067:                 for (my $i=0; $i<4; $i++) {
                   7068:                     if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
                   7069:                         $badip = 1;
                   7070:                         last;
                   7071:                     }
                   7072:                 }
                   7073:                 if (!$badip) {
                   7074:                     push(@okmachines,$ip);     
                   7075:                 }
                   7076:             }
                   7077:             @okmachines = sort(@okmachines);
                   7078:             $newserverstatus{$type}{'machines'} = join(',',@okmachines);
                   7079:         }
                   7080:     }
                   7081:     my %serverstatushash =  (
                   7082:                                 serverstatuses => \%newserverstatus,
                   7083:                             );
                   7084:     foreach my $type (@pages) {
1.83      raeburn  7085:         foreach my $setting ('namedusers','machines') {
1.84      raeburn  7086:             my (@current,@new);
1.83      raeburn  7087:             if (ref($currserverstatus{$type}) eq 'HASH') {
1.84      raeburn  7088:                 if ($currserverstatus{$type}{$setting} ne '') { 
                   7089:                     @current = split(/,/,$currserverstatus{$type}{$setting});
                   7090:                 }
                   7091:             }
                   7092:             if ($newserverstatus{$type}{$setting} ne '') {
                   7093:                 @new = split(/,/,$newserverstatus{$type}{$setting});
1.83      raeburn  7094:             }
                   7095:             if (@current > 0) {
                   7096:                 if (@new > 0) {
                   7097:                     foreach my $item (@current) {
                   7098:                         if (!grep(/^\Q$item\E$/,@new)) {
                   7099:                             $changes{$type}{$setting} = 1;
1.82      raeburn  7100:                             last;
                   7101:                         }
                   7102:                     }
1.84      raeburn  7103:                     foreach my $item (@new) {
                   7104:                         if (!grep(/^\Q$item\E$/,@current)) {
                   7105:                             $changes{$type}{$setting} = 1;
                   7106:                             last;
1.82      raeburn  7107:                         }
                   7108:                     }
                   7109:                 } else {
1.83      raeburn  7110:                     $changes{$type}{$setting} = 1;
1.69      raeburn  7111:                 }
1.83      raeburn  7112:             } elsif (@new > 0) {
                   7113:                 $changes{$type}{$setting} = 1;
1.69      raeburn  7114:             }
                   7115:         }
                   7116:     }
                   7117:     if (keys(%changes) > 0) {
1.81      raeburn  7118:         my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69      raeburn  7119:         my $putresult = &Apache::lonnet::put_dom('configuration',
                   7120:                                                  \%serverstatushash,$dom);
                   7121:         if ($putresult eq 'ok') {
                   7122:             $resulttext .= &mt('Changes made:').'<ul>';
                   7123:             foreach my $type (@pages) {
1.84      raeburn  7124:                 if (ref($changes{$type}) eq 'HASH') {
1.69      raeburn  7125:                     $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84      raeburn  7126:                     if ($changes{$type}{'namedusers'}) {
1.69      raeburn  7127:                         if ($newserverstatus{$type}{'namedusers'} eq '') {
                   7128:                             $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
                   7129:                         } else {
                   7130:                             $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
                   7131:                         }
1.84      raeburn  7132:                     }
                   7133:                     if ($changes{$type}{'machines'}) {
1.69      raeburn  7134:                         if ($newserverstatus{$type}{'machines'} eq '') {
                   7135:                             $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
                   7136:                         } else {
                   7137:                             $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
                   7138:                         }
                   7139: 
                   7140:                     }
                   7141:                     $resulttext .= '</ul></li>';
                   7142:                 }
                   7143:             }
                   7144:             $resulttext .= '</ul>';
                   7145:         } else {
                   7146:             $resulttext = '<span class="LC_error">'.
                   7147:                           &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
                   7148: 
                   7149:         }
                   7150:     } else {
                   7151:         $resulttext = &mt('No changes made to access to server status pages');
                   7152:     }
                   7153:     return $resulttext;
                   7154: }
                   7155: 
1.118     jms      7156: sub modify_helpsettings {
1.122     jms      7157:     my ($r,$dom,$confname,%domconfig) = @_;
1.118     jms      7158:  	my ($resulttext,$errors,%changes,%helphash);
                   7159:  	
1.122     jms      7160:  	my $customhelpfile  = $env{'form.loginhelpurl.filename'};
                   7161:     my $defaulthelpfile = 'defaulthelp.html';
                   7162:  	my $servadm = $r->dir_config('lonAdmEMail');
                   7163:     my ($configuserok,$author_ok,$switchserver) = 
                   7164:         &config_check($dom,$confname,$servadm);
                   7165:  	
1.118     jms      7166:  	my %defaultchecked = ('submitbugs'	=> 'on');
                   7167:  	my @offon = ('off','on');
1.122     jms      7168:     my %title = ( submitbugs     => 'Display link for users to submit a bug', 
                   7169:     			  loginhelpurl  => 'Unauthenticated login help page set to custom file');
                   7170:     			  
1.118     jms      7171:     my @toggles = ('submitbugs');
                   7172: 
                   7173:     $helphash{'helpsettings'} = {};
                   7174:     
                   7175:     if (ref($domconfig{'helpsettings'}) ne 'HASH') {
                   7176:         if ($domconfig{'helpsettings'} eq '') {
                   7177:             $domconfig{'helpsettings'} = {};
                   7178:         }
                   7179:     }
                   7180:     
                   7181:     if (ref($domconfig{'helpsettings'}) eq 'HASH') {
                   7182:     	
                   7183:         foreach my $item (@toggles) {
                   7184:         	
                   7185: 			if ($defaultchecked{$item} eq 'on') { 
                   7186: 				if (($domconfig{'helpsettings'}{$item} eq '') &&
                   7187: 					 ($env{'form.'.$item} eq '0')) {
                   7188: 					$changes{$item} = 1;
                   7189: 				} elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
                   7190: 					$changes{$item} = 1;
                   7191: 				}
                   7192: 			} elsif ($defaultchecked{$item} eq 'off') {
                   7193: 				if (($domconfig{'helpsettings'}{$item} eq '') &&
                   7194: 					 ($env{'form.'.$item} eq '1')) {
                   7195: 					$changes{$item} = 1;
                   7196: 				} elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
                   7197: 					$changes{$item} = 1;
                   7198: 				}
                   7199: 			}
                   7200: 			$helphash{'helpsettings'}{$item} = $env{'form.'.$item};
1.122     jms      7201: 		}
                   7202: 		
                   7203: 		if ($customhelpfile ne '') {
                   7204: 			my $error;
                   7205: 			if ($configuserok eq 'ok') {
                   7206: 				if ($switchserver) {
                   7207: 					$error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
                   7208: 				} else {
                   7209: 					if ($author_ok eq 'ok') {
                   7210: 						my ($result,$loginhelpurl) =
                   7211: 							&publishlogo($r,'upload','loginhelpurl',$dom,
                   7212: 										 $confname,'help','','',$customhelpfile);
                   7213: 						if ($result eq 'ok') {
                   7214: 							$helphash{'helpsettings'}{'loginhelpurl'} = $loginhelpurl;
                   7215: 							$changes{'loginhelpurl'} = 1;
                   7216: 						} else {
                   7217: 							$error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customhelpfile,$result);
                   7218: 						}
                   7219: 					} else {
                   7220: 						$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].",$customhelpfile,$confname,$dom,$author_ok);
                   7221: 					}
                   7222: 				}
                   7223: 			} else {
                   7224: 				$error = &mt("Upload of [_1] failed because a Domain Configuration user ([_2]) could not be created in domain: [_3].  Error was: [_4].",$customhelpfile,$confname,$dom,$configuserok);
                   7225: 			}
                   7226: 			if ($error) {
                   7227: 				&Apache::lonnet::logthis($error);
                   7228: 				$errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   7229: 			}
                   7230: 		}
                   7231: 		
                   7232:         if ($domconfig{'helpsettings'}{'loginhelpurl'} ne '') {
                   7233:             if ($env{'form.loginhelpurl_del'}) {
                   7234:                 $helphash{'helpsettings'}{'loginhelpurl'} = '';
                   7235:                 $changes{'loginhelpurl'} = 1;
                   7236:             }
                   7237:         }
1.118     jms      7238:     }
                   7239:     
1.123     jms      7240:     
                   7241:     my $putresult;
                   7242:     
                   7243:     if (keys(%changes) > 0) {
                   7244:     	$putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
                   7245:     } else {
                   7246:     	$putresult = 'ok';
                   7247:     }
1.118     jms      7248:                                              
                   7249:     if ($putresult eq 'ok') {
                   7250:         if (keys(%changes) > 0) {
                   7251: 			$resulttext = &mt('Changes made:').'<ul>';
                   7252: 			foreach my $item (sort(keys(%changes))) {
                   7253: 				if ($item eq 'submitbugs') {
                   7254: 					$resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
                   7255: 				}
1.122     jms      7256: 				if ($item eq 'loginhelpurl') {
                   7257: 					if ($helphash{'helpsettings'}{'loginhelpurl'} eq '') {
                   7258:                         $resulttext .= '<li>'.&mt('[_1] help file removed; [_2] file will be used for the unathorized help page in this domain.',$customhelpfile,$defaulthelpfile).'</li>';
                   7259:                     } else {
                   7260:                         $resulttext .= '<li>'.&mt("$title{$item} [_1]",$customhelpfile).'</li>';
                   7261:                     }
                   7262: 				}
1.118     jms      7263: 			}
                   7264: 			$resulttext .= '</ul>';
                   7265: 		} else {
                   7266: 			$resulttext = &mt('No changes made to help settings');
                   7267: 		}
                   7268:     } else {
                   7269:         $resulttext = '<span class="LC_error">'.
                   7270: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
                   7271:     }
                   7272:     if ($errors) {
                   7273:         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
                   7274:                        $errors.'</ul>';
                   7275:     }
                   7276:     return $resulttext;
                   7277: }
                   7278: 
1.121     raeburn  7279: sub modify_coursedefaults {
                   7280:     my ($dom,%domconfig) = @_;
                   7281:     my ($resulttext,$errors,%changes,%defaultshash);
                   7282:     my %defaultchecked = ('canuse_pdfforms' => 'off');
                   7283:     my @offon = ('off','on');
                   7284:     my @toggles = ('canuse_pdfforms');
                   7285: 
                   7286:     $defaultshash{'coursedefaults'} = {};
                   7287: 
                   7288:     if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
                   7289:         if ($domconfig{'coursedefaults'} eq '') {
                   7290:             $domconfig{'coursedefaults'} = {};
                   7291:         }
                   7292:     }
                   7293: 
                   7294:     if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
                   7295:         foreach my $item (@toggles) {
                   7296:             if ($defaultchecked{$item} eq 'on') {
                   7297:                 if (($domconfig{'coursedefaults'}{$item} eq '') &&
                   7298:                     ($env{'form.'.$item} eq '0')) {
                   7299:                     $changes{$item} = 1;
                   7300:                 } elsif ($domconfig{'coursdefaults'}{$item} ne $env{'form.'.$item}) {
                   7301:                     $changes{$item} = 1;
                   7302:                 }
                   7303:             } elsif ($defaultchecked{$item} eq 'off') {
                   7304:                 if (($domconfig{'coursedefaults'}{$item} eq '') &&
                   7305:                     ($env{'form.'.$item} eq '1')) {
                   7306:                     $changes{$item} = 1;
                   7307:                 } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
                   7308:                     $changes{$item} = 1;
                   7309:                 }
                   7310:             }
                   7311:             $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
                   7312:         }
1.139     raeburn  7313:         my $currdefresponder = $domconfig{'coursedefaults'}{'anonsurvey_threshold'};
                   7314:         my $newdefresponder = $env{'form.anonsurvey_threshold'};
                   7315:         $newdefresponder =~ s/\D//g;
                   7316:         if ($newdefresponder eq '' || $newdefresponder < 1) {
                   7317:             $newdefresponder = 1;
                   7318:         }
                   7319:         $defaultshash{'coursedefaults'}{'anonsurvey_threshold'} = $newdefresponder;
                   7320:         if ($currdefresponder ne $newdefresponder) {
                   7321:             unless ($currdefresponder eq '' && $newdefresponder == 10) {
                   7322:                 $changes{'anonsurvey_threshold'} = 1;
                   7323:             }
                   7324:         }
1.121     raeburn  7325:     }
                   7326:     my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
                   7327:                                              $dom);
                   7328:     if ($putresult eq 'ok') {
                   7329:         if (keys(%changes) > 0) {
                   7330:             if ($changes{'canuse_pdfforms'}) {
                   7331:                 my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
                   7332:                 $domdefaults{'canuse_pdfforms'}=$defaultshash{'coursedefaults'}{'canuse_pdfforms'};
                   7333:                 my $cachetime = 24*60*60;
                   7334:                 &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
                   7335:             }
                   7336:             $resulttext = &mt('Changes made:').'<ul>';
                   7337:             foreach my $item (sort(keys(%changes))) {
                   7338:                 if ($item eq 'canuse_pdfforms') {
                   7339:                     if ($env{'form.'.$item} eq '1') {
                   7340:                         $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
                   7341:                     } else {
                   7342:                         $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
                   7343:                     }
1.139     raeburn  7344:                 } elsif ($item eq 'anonsurvey_threshold') {
                   7345:                         $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.140     raeburn  7346:                 }
1.121     raeburn  7347:             }
                   7348:             $resulttext .= '</ul>';
                   7349:         } else {
                   7350:             $resulttext = &mt('No changes made to course defaults');
                   7351:         }
                   7352:     } else {
                   7353:         $resulttext = '<span class="LC_error">'.
                   7354:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   7355:     }
                   7356:     return $resulttext;
                   7357: }
                   7358: 
1.137     raeburn  7359: sub modify_usersessions {
                   7360:     my ($dom,%domconfig) = @_;
1.145     raeburn  7361:     my @hostingtypes = ('version','excludedomain','includedomain');
                   7362:     my @offloadtypes = ('primary','default');
                   7363:     my %types = (
                   7364:                   remote => \@hostingtypes,
                   7365:                   hosted => \@hostingtypes,
                   7366:                   spares => \@offloadtypes,
                   7367:                 );
                   7368:     my @prefixes = ('remote','hosted','spares');
1.137     raeburn  7369:     my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138     raeburn  7370:     my (%by_ip,%by_location,@intdoms);
                   7371:     &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
                   7372:     my @locations = sort(keys(%by_location));
1.137     raeburn  7373:     my (%defaultshash,%changes);
                   7374:     foreach my $prefix (@prefixes) {
                   7375:         $defaultshash{'usersessions'}{$prefix} = {};
                   7376:     }
                   7377:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
                   7378:     my $resulttext;
1.138     raeburn  7379:     my %iphost = &Apache::lonnet::get_iphost();
1.137     raeburn  7380:     foreach my $prefix (@prefixes) {
1.145     raeburn  7381:         next if ($prefix eq 'spares');
                   7382:         foreach my $type (@{$types{$prefix}}) {
1.137     raeburn  7383:             my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
                   7384:             if ($type eq 'version') {
                   7385:                 my $value = $env{'form.'.$prefix.'_'.$type};
                   7386:                 my $okvalue;
                   7387:                 if ($value ne '') {
                   7388:                     if (grep(/^\Q$value\E$/,@lcversions)) {
                   7389:                         $okvalue = $value;
                   7390:                     }
                   7391:                 }
                   7392:                 if (ref($domconfig{'usersessions'}) eq 'HASH') {
                   7393:                     if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
                   7394:                         if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
                   7395:                             if ($inuse == 0) {
                   7396:                                 $changes{$prefix}{$type} = 1;
                   7397:                             } else {
                   7398:                                 if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
                   7399:                                     $changes{$prefix}{$type} = 1;
                   7400:                                 }
                   7401:                                 if ($okvalue ne '') {
                   7402:                                     $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
                   7403:                                 } 
                   7404:                             }
                   7405:                         } else {
                   7406:                             if (($inuse == 1) && ($okvalue ne '')) {
                   7407:                                 $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
                   7408:                                 $changes{$prefix}{$type} = 1;
                   7409:                             }
                   7410:                         }
                   7411:                     } else {
                   7412:                         if (($inuse == 1) && ($okvalue ne '')) {
                   7413:                             $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
                   7414:                             $changes{$prefix}{$type} = 1;
                   7415:                         }
                   7416:                     }
                   7417:                 } else {
                   7418:                     if (($inuse == 1) && ($okvalue ne '')) {
                   7419:                         $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
                   7420:                         $changes{$prefix}{$type} = 1;
                   7421:                     }
                   7422:                 }
                   7423:             } else {
                   7424:                 my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
                   7425:                 my @okvals;
                   7426:                 foreach my $val (@vals) {
1.138     raeburn  7427:                     if ($val =~ /:/) {
                   7428:                         my @items = split(/:/,$val);
                   7429:                         foreach my $item (@items) {
                   7430:                             if (ref($by_location{$item}) eq 'ARRAY') {
                   7431:                                 push(@okvals,$item);
                   7432:                             }
                   7433:                         }
                   7434:                     } else {
                   7435:                         if (ref($by_location{$val}) eq 'ARRAY') {
                   7436:                             push(@okvals,$val);
                   7437:                         }
1.137     raeburn  7438:                     }
                   7439:                 }
                   7440:                 @okvals = sort(@okvals);
                   7441:                 if (ref($domconfig{'usersessions'}) eq 'HASH') {
                   7442:                     if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
                   7443:                         if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
                   7444:                             if ($inuse == 0) {
                   7445:                                 $changes{$prefix}{$type} = 1; 
                   7446:                             } else {
                   7447:                                 $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
                   7448:                                 my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
                   7449:                                 if (@changed > 0) {
                   7450:                                     $changes{$prefix}{$type} = 1;
                   7451:                                 }
                   7452:                             }
                   7453:                         } else {
                   7454:                             if ($inuse == 1) {
                   7455:                                 $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
                   7456:                                 $changes{$prefix}{$type} = 1;
                   7457:                             }
                   7458:                         } 
                   7459:                     } else {
                   7460:                         if ($inuse == 1) {
                   7461:                             $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
                   7462:                             $changes{$prefix}{$type} = 1;
                   7463:                         }
                   7464:                     }
                   7465:                 } else {
                   7466:                     if ($inuse == 1) {
                   7467:                         $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
                   7468:                         $changes{$prefix}{$type} = 1;
                   7469:                     }
                   7470:                 }
                   7471:             }
                   7472:         }
                   7473:     }
1.145     raeburn  7474: 
                   7475:     my @alldoms = &Apache::lonnet::all_domains();
1.149     raeburn  7476:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145     raeburn  7477:     my %spareid = &current_offloads_to($dom,$domconfig{'usersessions'},\%servers);
                   7478:     my $savespares;
                   7479: 
                   7480:     foreach my $lonhost (sort(keys(%servers))) {
                   7481:         my $serverhomeID =
                   7482:             &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152     raeburn  7483:         my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145     raeburn  7484:         $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
                   7485:         my %spareschg;
                   7486:         foreach my $type (@{$types{'spares'}}) {
                   7487:             my @okspares;
                   7488:             my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
                   7489:             foreach my $server (@checked) {
1.152     raeburn  7490:                 if (&Apache::lonnet::hostname($server) ne '') {
                   7491:                     unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
                   7492:                         unless (grep(/^\Q$server\E$/,@okspares)) {
                   7493:                             push(@okspares,$server);
                   7494:                         }
1.145     raeburn  7495:                     }
                   7496:                 }
                   7497:             }
                   7498:             my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
                   7499:             my $newspare;
1.152     raeburn  7500:             if (($new ne '') && (&Apache::lonnet::hostname($new))) {
                   7501:                 unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145     raeburn  7502:                     $newspare = $new;
                   7503:                 }
                   7504:             }
1.152     raeburn  7505:             my @spares;
                   7506:             if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
                   7507:                 @spares = sort(@okspares,$newspare);
                   7508:             } else {
                   7509:                 @spares = sort(@okspares);
                   7510:             }
                   7511:             $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145     raeburn  7512:             if (ref($spareid{$lonhost}) eq 'HASH') {
                   7513:                 if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152     raeburn  7514:                     my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145     raeburn  7515:                     if (@diffs > 0) {
                   7516:                         $spareschg{$type} = 1;
                   7517:                     }
                   7518:                 }
                   7519:             }
                   7520:         }
                   7521:         if (keys(%spareschg) > 0) {
                   7522:             $changes{'spares'}{$lonhost} = \%spareschg;
                   7523:         }
                   7524:     }
                   7525: 
                   7526:     if (ref($domconfig{'usersessions'}) eq 'HASH') {
                   7527:         if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
                   7528:             if (ref($changes{'spares'}) eq 'HASH') {
                   7529:                 if (keys(%{$changes{'spares'}}) > 0) {
                   7530:                     $savespares = 1;
                   7531:                 }
                   7532:             }
                   7533:         } else {
                   7534:             $savespares = 1;
                   7535:         }
                   7536:     }
                   7537: 
1.147     raeburn  7538:     my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
                   7539:     if ((keys(%changes) > 0) || ($savespares)) {
1.137     raeburn  7540:         my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
                   7541:                                                  $dom);
                   7542:         if ($putresult eq 'ok') {
                   7543:             if (ref($defaultshash{'usersessions'}) eq 'HASH') {
                   7544:                 if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
                   7545:                     $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
                   7546:                 }
                   7547:                 if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
                   7548:                     $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
                   7549:                 }
                   7550:             }
                   7551:             my $cachetime = 24*60*60;
                   7552:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.147     raeburn  7553:             if (keys(%changes) > 0) {
                   7554:                 my %lt = &usersession_titles();
                   7555:                 $resulttext = &mt('Changes made:').'<ul>';
                   7556:                 foreach my $prefix (@prefixes) {
                   7557:                     if (ref($changes{$prefix}) eq 'HASH') {
                   7558:                         $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
                   7559:                         if ($prefix eq 'spares') {
                   7560:                             if (ref($changes{$prefix}) eq 'HASH') {
                   7561:                                 foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
                   7562:                                     $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148     raeburn  7563:                                     my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
                   7564:                                     &Apache::lonnet::remote_devalidate_cache($lonhost,'spares',$lonhostdom);
1.147     raeburn  7565:                                     if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
                   7566:                                         foreach my $type (@{$types{$prefix}}) {
                   7567:                                             if ($changes{$prefix}{$lonhost}{$type}) {
                   7568:                                                 my $offloadto = &mt('None');
                   7569:                                                 if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
                   7570:                                                     if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {   
                   7571:                                                         $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
                   7572:                                                     }
1.145     raeburn  7573:                                                 }
1.147     raeburn  7574:                                                 $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).('&nbsp;'x3);
1.145     raeburn  7575:                                             }
1.137     raeburn  7576:                                         }
                   7577:                                     }
1.147     raeburn  7578:                                     $resulttext .= '</li>';
1.137     raeburn  7579:                                 }
                   7580:                             }
1.147     raeburn  7581:                         } else {
                   7582:                             foreach my $type (@{$types{$prefix}}) {
                   7583:                                 if (defined($changes{$prefix}{$type})) {
                   7584:                                     my $newvalue;
                   7585:                                     if (ref($defaultshash{'usersessions'}) eq 'HASH') {
                   7586:                                         if (ref($defaultshash{'usersessions'}{$prefix})) {
                   7587:                                             if ($type eq 'version') {
                   7588:                                                 $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
                   7589:                                             } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
                   7590:                                                 if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
                   7591:                                                     $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
                   7592:                                                 }
1.145     raeburn  7593:                                             }
                   7594:                                         }
                   7595:                                     }
1.147     raeburn  7596:                                     if ($newvalue eq '') {
                   7597:                                         if ($type eq 'version') {
                   7598:                                             $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
                   7599:                                         } else {
                   7600:                                             $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
                   7601:                                         }
1.145     raeburn  7602:                                     } else {
1.147     raeburn  7603:                                         if ($type eq 'version') {
                   7604:                                             $newvalue .= ' '.&mt('(or later)'); 
                   7605:                                         }
                   7606:                                         $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145     raeburn  7607:                                     }
1.137     raeburn  7608:                                 }
                   7609:                             }
                   7610:                         }
1.147     raeburn  7611:                         $resulttext .= '</ul>';
1.137     raeburn  7612:                     }
                   7613:                 }
1.147     raeburn  7614:                 $resulttext .= '</ul>';
                   7615:             } else {
                   7616:                 $resulttext = $nochgmsg;
1.137     raeburn  7617:             }
                   7618:         } else {
                   7619:             $resulttext = '<span class="LC_error">'.
                   7620:                           &mt('An error occurred: [_1]',$putresult).'</span>';
                   7621:         }
                   7622:     } else {
1.147     raeburn  7623:         $resulttext = $nochgmsg;
1.137     raeburn  7624:     }
                   7625:     return $resulttext;
                   7626: }
                   7627: 
1.150     raeburn  7628: sub modify_loadbalancing {
                   7629:     my ($dom,%domconfig) = @_;
                   7630:     my $primary_id = &Apache::lonnet::domain($dom,'primary');
                   7631:     my $intdom = &Apache::lonnet::internet_dom($primary_id);
                   7632:     my ($othertitle,$usertypes,$types) =
                   7633:         &Apache::loncommon::sorted_inst_types($dom);
                   7634:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
                   7635:     my @sparestypes = ('primary','default');
                   7636:     my %typetitles = &sparestype_titles();
                   7637:     my $resulttext;
                   7638:     if (keys(%servers) > 1) {
                   7639:         my ($currbalancer,$currtargets,$currrules);
                   7640:         if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
                   7641:             $currbalancer = $domconfig{'loadbalancing'}{'lonhost'};
                   7642:             $currtargets = $domconfig{'loadbalancing'}{'targets'};
                   7643:             $currrules = $domconfig{'loadbalancing'}{'rules'};
                   7644:         } else {
                   7645:             ($currbalancer,$currtargets) = 
                   7646:                 &Apache::lonnet::get_lonbalancer_config(\%servers);
                   7647:         }
                   7648:         my ($saveloadbalancing,%defaultshash,%changes);
                   7649:         my ($alltypes,$othertypes,$titles) =
                   7650:             &loadbalancing_titles($dom,$intdom,$usertypes,$types);
                   7651:         my %ruletitles = &offloadtype_text();
                   7652:         my $balancer = $env{'form.loadbalancing_lonhost'};
                   7653:         if (!$servers{$balancer}) {
                   7654:             undef($balancer);
                   7655:         }
                   7656:         if ($currbalancer ne $balancer) {
                   7657:             $changes{'lonhost'} = 1;
                   7658:         }
                   7659:         $defaultshash{'loadbalancing'}{'lonhost'} = $balancer;
                   7660:         if ($balancer ne '') {
                   7661:             unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
                   7662:                 $saveloadbalancing = 1;
                   7663:             }
                   7664:             foreach my $sparetype (@sparestypes) {
                   7665:                 my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$sparetype);
1.151     raeburn  7666:                 my @offloadto;
1.150     raeburn  7667:                 foreach my $target (@targets) {
                   7668:                     if (($servers{$target}) && ($target ne $balancer)) {
                   7669:                         if ($sparetype eq 'default') {
                   7670:                             if (ref($defaultshash{'loadbalancing'}{'targets'}{'primary'}) eq 'ARRAY') {
                   7671:                                 next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{'targets'}{'primary'}}));
                   7672:                             }
                   7673:                         }
                   7674:                         unless(grep(/^\Q$target\E$/,@offloadto)) {
                   7675:                             push(@offloadto,$target);
                   7676:                         }
                   7677:                     }
                   7678:                     $defaultshash{'loadbalancing'}{'targets'}{$sparetype} = \@offloadto;
                   7679:                 }
                   7680:             }
                   7681:         } else {
                   7682:             foreach my $sparetype (@sparestypes) {
                   7683:                 $defaultshash{'loadbalancing'}{'targets'}{$sparetype} = [];
                   7684:             }
                   7685:         }
                   7686:         if (ref($currtargets) eq 'HASH') {
                   7687:             foreach my $sparetype (@sparestypes) {
                   7688:                 if (ref($currtargets->{$sparetype}) eq 'ARRAY') {
                   7689:                     my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets->{$sparetype},$defaultshash{'loadbalancing'}{'targets'}{$sparetype});
                   7690:                     if (@targetdiffs > 0) {
                   7691:                         $changes{'targets'} = 1;
                   7692:                     }
                   7693:                 } elsif (ref($defaultshash{'loadbalancing'}{'targets'}{$sparetype}) eq 'ARRAY') {
                   7694:                     if (@{$defaultshash{'loadbalancing'}{'targets'}{$sparetype}} > 0) {
                   7695:                         $changes{'targets'} = 1;
                   7696:                     }
                   7697:                 }
                   7698:             }
                   7699:         } else {
                   7700:             foreach my $sparetype (@sparestypes) {
                   7701:                 if (ref($defaultshash{'loadbalancing'}{'targets'}{$sparetype}) eq 'ARRAY') {
                   7702:                     if (@{$defaultshash{'loadbalancing'}{'targets'}{$sparetype}} > 0) {
                   7703:                         $changes{'targets'} = 1;  
                   7704:                     }
                   7705:                 }
                   7706:             }  
                   7707:         }
                   7708:         my $ishomedom;
                   7709:         if ($balancer ne '') {
                   7710:             if (&Apache::lonnet::host_domain($balancer) eq $dom) {
                   7711:                 $ishomedom = 1;
                   7712:             }
                   7713:         }
                   7714:         if (ref($alltypes) eq 'ARRAY') {
                   7715:             foreach my $type (@{$alltypes}) {
                   7716:                 my $rule;
                   7717:                 if ($balancer ne '') {
                   7718:                     unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) && 
                   7719:                          (!$ishomedom)) {
                   7720:                         $rule = $env{'form.loadbalancing_rules_'.$type};
                   7721:                     }
                   7722:                     if ($rule eq 'specific') {
                   7723:                         $rule = $env{'form.loadbalancing_singleserver_'.$type};
                   7724:                     }
                   7725:                 }
                   7726:                 $defaultshash{'loadbalancing'}{'rules'}{$type} = $rule;
                   7727:                 if (ref($currrules) eq 'HASH') {
                   7728:                     if ($rule ne $currrules->{$type}) {
                   7729:                         $changes{'rules'}{$type} = 1;
                   7730:                     }
                   7731:                 } elsif ($rule ne '') {
                   7732:                     $changes{'rules'}{$type} = 1;
                   7733:                 }
                   7734:             }
                   7735:         }
                   7736:         my $nochgmsg = &mt('No changes made to Load Balancer settings.');
                   7737:         if ((keys(%changes) > 0) || ($saveloadbalancing)) {
                   7738:             my $putresult = &Apache::lonnet::put_dom('configuration',
                   7739:                                                      \%defaultshash,$dom);
                   7740:             if ($putresult eq 'ok') {
                   7741:                 if (keys(%changes) > 0) {
                   7742:                     if ($changes{'lonhost'}) {
                   7743:                         if ($currbalancer ne '') {
                   7744:                             &Apache::lonnet::remote_devalidate_cache($currbalancer,'loadbalancing',$dom);
                   7745:                         }
                   7746:                         if ($balancer eq '') {
                   7747:                             $resulttext .= '<li>'.&mt('Load Balancing with dedicated server discontinued').'</li>'; 
                   7748:                         } else {
                   7749:                             &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
                   7750:                             $resulttext .= '<li>'.&mt('Dedicated Load Balancer server set to [_1]',$balancer);
                   7751:                         }
                   7752:                     } else {
                   7753:                         &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
                   7754:                     }
                   7755:                     if (($changes{'targets'}) && ($balancer ne '')) {
                   7756:                         my %offloadstr;
                   7757:                         foreach my $sparetype (@sparestypes) {
                   7758:                             if (ref($defaultshash{'loadbalancing'}{'targets'}{$sparetype}) eq 'ARRAY') {
                   7759:                                 if (@{$defaultshash{'loadbalancing'}{'targets'}{$sparetype}} > 0) {
                   7760:                                     $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{'targets'}{$sparetype}});
                   7761:                                 }
                   7762:                             }
                   7763:                         }
                   7764:                         if (keys(%offloadstr) == 0) {
                   7765:                             $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
                   7766:                         } else {
                   7767:                             my $showoffload;
                   7768:                             foreach my $sparetype (@sparestypes) {
                   7769:                                 $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>:&nbsp;';
                   7770:                                 if (defined($offloadstr{$sparetype})) {
                   7771:                                     $showoffload .= $offloadstr{$sparetype};
                   7772:                                 } else {
                   7773:                                     $showoffload .= &mt('None');
                   7774:                                 }
                   7775:                                 $showoffload .= ('&nbsp;'x3);
                   7776:                             }
                   7777:                             $resulttext .= '<li>'.&mt('By default, Load Balancer server set to offload to: [_1]',$showoffload).'</li>';
                   7778:                         }
                   7779:                     }
                   7780:                     if ((ref($changes{'rules'}) eq 'HASH') && ($balancer ne '')) {
                   7781:                         if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
                   7782:                             foreach my $type (@{$alltypes}) {
                   7783:                                 if ($changes{'rules'}{$type}) {
                   7784:                                     my $rule = $defaultshash{'loadbalancing'}{'rules'}{$type};
                   7785:                                     my $balancetext;
                   7786:                                     if ($rule eq '') {
                   7787:                                         $balancetext =  $ruletitles{'default'};
                   7788:                                     } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer')) {
                   7789:                                         $balancetext =  $ruletitles{$rule};
                   7790:                                     } else {
                   7791:                                         $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{'rules'}{$type});
                   7792:                                     }
                   7793:                                     $resulttext .= '<li>'.&mt('Load Balancing for [_1] set to: [_2]',$titles->{$type},$balancetext).'</li>';     
                   7794:                                 }
                   7795:                             }
                   7796:                         }
                   7797:                     }
                   7798:                     if ($resulttext ne '') {
                   7799:                         $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
                   7800:                     } else {
                   7801:                         $resulttext = $nochgmsg;
                   7802:                     }
                   7803:                 } else {
                   7804:                     $resulttext = $nochgmsg;
                   7805:                     if ($balancer ne '') {
                   7806:                         &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
                   7807:                     }
                   7808:                 }
                   7809:             } else {
                   7810:                 $resulttext = '<span class="LC_error">'.
                   7811:                               &mt('An error occurred: [_1]',$putresult).'</span>';
                   7812:             }
                   7813:         } else {
                   7814:             $resulttext = $nochgmsg;
                   7815:         }
                   7816:     } else {
                   7817:         $resulttext =  &mt('Load Balancing unavailable as this domain only has one server.');
                   7818:     }
                   7819:     return $resulttext;
                   7820: }
                   7821: 
1.48      raeburn  7822: sub recurse_check {
                   7823:     my ($chkcats,$categories,$depth,$name) = @_;
                   7824:     if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
                   7825:         my $chg = 0;
                   7826:         for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
                   7827:             my $category = $chkcats->[$depth]{$name}[$j];
                   7828:             my $item;
                   7829:             if ($category eq '') {
                   7830:                 $chg ++;
                   7831:             } else {
                   7832:                 my $deeper = $depth + 1;
                   7833:                 $item = &escape($category).':'.&escape($name).':'.$depth;
                   7834:                 if ($chg) {
                   7835:                     $categories->{$item} -= $chg;
                   7836:                 }
                   7837:                 &recurse_check($chkcats,$categories,$deeper,$category);
                   7838:                 $deeper --;
                   7839:             }
                   7840:         }
                   7841:     }
                   7842:     return;
                   7843: }
                   7844: 
                   7845: sub recurse_cat_deletes {
                   7846:     my ($item,$coursecategories,$deletions) = @_;
                   7847:     my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
                   7848:     my $subdepth = $depth + 1;
                   7849:     if (ref($coursecategories) eq 'HASH') {
                   7850:         foreach my $subitem (keys(%{$coursecategories})) {
                   7851:             my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
                   7852:             if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
                   7853:                 delete($coursecategories->{$subitem});
                   7854:                 $deletions->{$subitem} = 1;
                   7855:                 &recurse_cat_deletes($subitem,$coursecategories,$deletions);
                   7856:             }  
                   7857:         }
                   7858:     }
                   7859:     return;
                   7860: }
                   7861: 
1.125     raeburn  7862: sub get_active_dcs {
                   7863:     my ($dom) = @_;
                   7864:     my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc']);
                   7865:     my %domcoords;
                   7866:     my $numdcs = 0;
                   7867:     my $now = time;
                   7868:     foreach my $server (keys(%dompersonnel)) {
                   7869:         foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
                   7870:             my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
                   7871:             my ($end,$start) = split(':',$dompersonnel{$server}{$user});
                   7872:             if (($end eq '') || ($end == 0) || ($end > $now)) {
                   7873:                 if ($start <= $now) {
                   7874:                     $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
                   7875:                 }
                   7876:             }
                   7877:         }
                   7878:     }
                   7879:     return %domcoords;
                   7880: }
                   7881: 
                   7882: sub active_dc_picker {
                   7883:     my ($dom,$curr_dc) = @_;
                   7884:     my %domcoords = &get_active_dcs($dom); 
                   7885:     my @dcs = sort(keys(%domcoords));
                   7886:     my $numdcs = scalar(@dcs); 
                   7887:     my $datatable;
                   7888:     my $numinrow = 2;
                   7889:     if ($numdcs > 1) {
                   7890:         $datatable = '<table>';
                   7891:         for (my $i=0; $i<@dcs; $i++) {
                   7892:             my $rem = $i%($numinrow);
                   7893:             if ($rem == 0) {
                   7894:                 if ($i > 0) {
                   7895:                     $datatable .= '</tr>';
                   7896:                 }
                   7897:                 $datatable .= '<tr>';
                   7898:             }
                   7899:             my $check = ' ';
                   7900:             if ($curr_dc eq '') {
                   7901:                 if (!$i) { 
                   7902:                     $check = ' checked="checked" ';
                   7903:                 }
                   7904:             } elsif ($dcs[$i] eq $curr_dc) {
                   7905:                 $check = ' checked="checked" ';
                   7906:             }
                   7907:             if ($i == @dcs - 1) {
                   7908:                 my $colsleft = $numinrow - $rem;
                   7909:                 if ($colsleft > 1) {
                   7910:                     $datatable .= '<td colspan="'.$colsleft.'">';
                   7911:                 } else {
                   7912:                     $datatable .= '<td>';
                   7913:                 }
                   7914:             } else {
                   7915:                 $datatable .= '<td>';
                   7916:             }
                   7917:             my ($dcname,$dcdom) = split(':',$dcs[$i]);
                   7918:             $datatable .= '<span class="LC_nobreak"><label>'.
                   7919:                           '<input type="radio" name="autocreate_xmldc"'.
                   7920:                           ' value="'.$dcs[$i].'"'.$check.'/>'.
                   7921:                           &Apache::loncommon::plainname($dcname,$dcdom).
                   7922:                           '</label></span></td>';
                   7923:         }
                   7924:         $datatable .= '</tr></table>';
                   7925:     } elsif (@dcs) {
                   7926:         $datatable .= '<input type="hidden" name="autocreate_dc" value="'.
                   7927:                       $dcs[0].'" />';
                   7928:     }
                   7929:     return ($numdcs,$datatable);
                   7930: }
                   7931: 
1.137     raeburn  7932: sub usersession_titles {
                   7933:     return &Apache::lonlocal::texthash(
                   7934:                hosted => 'Hosting of sessions for users from other domains on servers in this domain',
                   7935:                remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145     raeburn  7936:                spares => 'Servers offloaded to, when busy',
1.137     raeburn  7937:                version => 'LON-CAPA version requirement',
1.138     raeburn  7938:                excludedomain => 'Allow all, but exclude specific domains',
                   7939:                includedomain => 'Deny all, but include specific domains',
1.145     raeburn  7940:                primary => 'Primary (checked first)',
1.154     raeburn  7941:                default => 'Default',
1.137     raeburn  7942:            );
                   7943: }
                   7944: 
1.152     raeburn  7945: sub id_for_thisdom {
                   7946:     my (%servers) = @_;
                   7947:     my %altids;
                   7948:     foreach my $server (keys(%servers)) {
                   7949:         my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
                   7950:         if ($serverhome ne $server) {
                   7951:             $altids{$serverhome} = $server;
                   7952:         }
                   7953:     }
                   7954:     return %altids;
                   7955: }
                   7956: 
1.150     raeburn  7957: sub count_servers {
                   7958:     my ($currbalancer,%servers) = @_;
                   7959:     my (@spares,$numspares);
                   7960:     foreach my $lonhost (sort(keys(%servers))) {
                   7961:         next if ($currbalancer eq $lonhost);
                   7962:         push(@spares,$lonhost);
                   7963:     }
                   7964:     if ($currbalancer) {
                   7965:         $numspares = scalar(@spares);
                   7966:     } else {
                   7967:         $numspares = scalar(@spares) - 1;
                   7968:     }
                   7969:     return ($numspares,@spares);
                   7970: }
                   7971: 
                   7972: sub lonbalance_targets_js {
                   7973:     my ($dom,$types,$servers) = @_;
                   7974:     my $select = &mt('Select');
                   7975:     my ($alltargets,$allishome,$allinsttypes,@alltypes);
                   7976:     if (ref($servers) eq 'HASH') {
                   7977:         $alltargets = join("','",sort(keys(%{$servers})));
                   7978:         my @homedoms;
                   7979:         foreach my $server (sort(keys(%{$servers}))) {
                   7980:             if (&Apache::lonnet::host_domain($server) eq $dom) {
                   7981:                 push(@homedoms,'1');
                   7982:             } else {
                   7983:                 push(@homedoms,'0');
                   7984:             }
                   7985:         }
                   7986:         $allishome = join("','",@homedoms);
                   7987:     }
                   7988:     if (ref($types) eq 'ARRAY') {
                   7989:         if (@{$types} > 0) {
                   7990:             @alltypes = @{$types};
                   7991:         }
                   7992:     }
                   7993:     push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
                   7994:     $allinsttypes = join("','",@alltypes);
                   7995:     return <<"END";
                   7996: 
                   7997: <script type="text/javascript">
                   7998: // <![CDATA[
                   7999: 
                   8000: function toggleTargets() {
                   8001:     var balancer = document.display.loadbalancing_lonhost.options[document.display.loadbalancing_lonhost.selectedIndex].value;
                   8002:     if (balancer == '') {
                   8003:         hideSpares();
                   8004:     } else {
                   8005:         var homedoms = new Array('$allishome');
                   8006:         var ishomedom = homedoms[document.display.loadbalancing_lonhost.selectedIndex];
                   8007:         showSpares(balancer,ishomedom);
                   8008:     }
                   8009:     return;
                   8010: }
                   8011: 
                   8012: function showSpares(balancer,ishomedom) {
                   8013:     var alltargets = new Array('$alltargets');
                   8014:     var insttypes = new Array('$allinsttypes');
1.151     raeburn  8015:     var offloadtypes = new Array('primary','default');
                   8016: 
1.150     raeburn  8017:     document.getElementById('loadbalancing_targets').style.display='block';
                   8018:     document.getElementById('loadbalancing_disabled').style.display='none';
1.152     raeburn  8019:  
1.151     raeburn  8020:     for (var i=0; i<offloadtypes.length; i++) {
                   8021:         var count = 0;
                   8022:         for (var j=0; j<alltargets.length; j++) {
                   8023:             if (alltargets[j] != balancer) {
                   8024:                 document.getElementById('loadbalancing_target_'+offloadtypes[i]+'_'+count).value = alltargets[j];
                   8025:                 document.getElementById('loadbalancing_targettxt_'+offloadtypes[i]+'_'+count).style.textAlign='left';
                   8026:                 document.getElementById('loadbalancing_targettxt_'+offloadtypes[i]+'_'+count).style.textFace='normal';
                   8027:                 document.getElementById('loadbalancing_targettxt_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
                   8028:                 count ++;
                   8029:             }
1.150     raeburn  8030:         }
                   8031:     }
1.151     raeburn  8032:     for (var k=0; k<insttypes.length; k++) {
                   8033:         if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150     raeburn  8034:             if (ishomedom == 1) {
1.151     raeburn  8035:                 document.getElementById('balanceruletitle_'+insttypes[k]).style.display='block';
                   8036:                 document.getElementById('balancerule_'+insttypes[k]).style.display='block';
1.150     raeburn  8037:             } else {
1.151     raeburn  8038:                 document.getElementById('balanceruletitle_'+insttypes[k]).style.display='none';
                   8039:                 document.getElementById('balancerule_'+insttypes[k]).style.display='none';
1.150     raeburn  8040: 
                   8041:             }
                   8042:         } else {
1.151     raeburn  8043:             document.getElementById('balanceruletitle_'+insttypes[k]).style.display='block';
                   8044:             document.getElementById('balancerule_'+insttypes[k]).style.display='block';
1.150     raeburn  8045:         }
1.151     raeburn  8046:         if ((insttypes[k] != '_LC_external') && 
                   8047:             ((insttypes[k] != '_LC_internetdom') ||
                   8048:              ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
                   8049:             document.getElementById('loadbalancing_singleserver_'+insttypes[k]).options[0] = new Option("","",true,true);
                   8050:             for (var m=0; m<alltargets.length; m++) {
                   8051:                 var idx = m+1;
                   8052:                 if (alltargets[m] != balancer) {
                   8053:                     document.getElementById('loadbalancing_singleserver_'+insttypes[k]).options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150     raeburn  8054:                 }
                   8055:             }
                   8056:         }
                   8057:     }
                   8058:     return;
                   8059: }
                   8060: 
                   8061: function hideSpares() {
                   8062:     var alltargets = new Array('$alltargets');
                   8063:     var insttypes = new Array('$allinsttypes');
                   8064:     var offloadtypes = new Array('primary','default');
                   8065: 
                   8066:     document.getElementById('loadbalancing_targets').style.display='none';
                   8067:     document.getElementById('loadbalancing_disabled').style.display='block';
                   8068: 
                   8069:     var total = alltargets.length - 1;
                   8070:     for (var i=0; i<offloadtypes; i++) {
                   8071:         for (var j=0; j<total; j++) {
                   8072:            document.getElementById('loadbalancing_target_'+offloadtypes[i]+'_'+j).checked = false;
                   8073:            document.getElementById('loadbalancing_target_'+offloadtypes[i]+'_'+j).value = '';
                   8074:            document.getElementById('loadbalancing_targettxt_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151     raeburn  8075:         }
1.150     raeburn  8076:     }
                   8077:     for (var k=0; k<insttypes.length; k++) {
1.151     raeburn  8078:         document.getElementById('balanceruletitle_'+insttypes[k]).style.display='none';
                   8079:         document.getElementById('balancerule_'+insttypes[k]).style.display='none';
                   8080:         if (insttypes[k] != '_LC_external') {
                   8081:             document.getElementById('loadbalancing_singleserver_'+insttypes[k]).length = 0;
                   8082:             document.getElementById('loadbalancing_singleserver_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150     raeburn  8083:         }
                   8084:     }
                   8085:     return;
                   8086: }
                   8087: 
                   8088: function checkOffloads(item,type) {
                   8089:     var alltargets = new Array('$alltargets');
                   8090:     var offloadtypes = new Array('primary','default');
                   8091:     if (item.checked) {
                   8092:         var total = alltargets.length - 1;
                   8093:         var other;
                   8094:         if (type == offloadtypes[0]) {
1.151     raeburn  8095:             other = offloadtypes[1];
1.150     raeburn  8096:         } else {
1.151     raeburn  8097:             other = offloadtypes[0];
1.150     raeburn  8098:         }
                   8099:         for (var i=0; i<total; i++) {
                   8100:             var server = document.getElementById('loadbalancing_target_'+other+'_'+i).value;
                   8101:             if (server == item.value) {
                   8102:                 if (document.getElementById('loadbalancing_target_'+other+'_'+i).checked) {
                   8103:                     document.getElementById('loadbalancing_target_'+other+'_'+i).checked = false;
                   8104:                 }
                   8105:             }
                   8106:         }
                   8107:     }
                   8108:     return;
                   8109: }
                   8110: 
                   8111: function singleServerToggle(type) {
                   8112:     var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+type).selectedIndex;
                   8113:     if (offloadtoSelIdx == 0) {
                   8114:         document.getElementById('loadbalancing_rules_'+type+'_0').checked = true;
                   8115:         document.getElementById('loadbalancing_singleserver_'+type).options[0].text = '';
                   8116: 
                   8117:     } else {
                   8118:         document.getElementById('loadbalancing_rules_'+type+'_2').checked = true;
                   8119:         document.getElementById('loadbalancing_singleserver_'+type).options[0].text = '$select';
                   8120:     }
                   8121:     return;
                   8122: }
                   8123: 
                   8124: function balanceruleChange(formname,type) {
                   8125:     if (type == '_LC_external') {
                   8126:         return; 
                   8127:     }
                   8128:     var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+type);
                   8129:     for (var i=0; i<typesRules.length; i++) {
                   8130:         if (formname.elements[typesRules[i]].checked) {
                   8131:             if (formname.elements[typesRules[i]].value != 'specific') {
                   8132:                 document.getElementById('loadbalancing_singleserver_'+type).selectedIndex = 0;
                   8133:                 document.getElementById('loadbalancing_singleserver_'+type).options[0].text = '';
                   8134:             } else {
                   8135:                 document.getElementById('loadbalancing_singleserver_'+type).options[0].text = '$select';
                   8136:             }
                   8137:         }
                   8138:     }
                   8139:     return;
                   8140: }
                   8141: 
1.152     raeburn  8142: // ]]>
                   8143: </script>
                   8144: 
                   8145: END
                   8146: }
                   8147: 
                   8148: sub new_spares_js {
                   8149:     my @sparestypes = ('primary','default');
                   8150:     my $types = join("','",@sparestypes);
                   8151:     my $select = &mt('Select');
                   8152:     return <<"END";
                   8153: 
                   8154: <script type="text/javascript">
                   8155: // <![CDATA[
                   8156: 
                   8157: function updateNewSpares(formname,lonhost) {
                   8158:     var types = new Array('$types');
                   8159:     var include = new Array();
                   8160:     var exclude = new Array();
                   8161:     for (var i=0; i<types.length; i++) {
                   8162:         var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
                   8163:         for (var j=0; j<spareboxes.length; j++) {
                   8164:             if (formname.elements[spareboxes[j]].checked) {
                   8165:                 exclude.push(formname.elements[spareboxes[j]].value);
                   8166:             } else {
                   8167:                 include.push(formname.elements[spareboxes[j]].value);
                   8168:             }
                   8169:         }
                   8170:     }
                   8171:     for (var i=0; i<types.length; i++) {
                   8172:         var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
                   8173:         var selIdx = newSpare.selectedIndex;
                   8174:         var currnew = newSpare.options[selIdx].value;
                   8175:         var okSpares = new Array();
                   8176:         for (var j=0; j<newSpare.options.length; j++) {
                   8177:             var possible = newSpare.options[j].value;
                   8178:             if (possible != '') {
                   8179:                 if (exclude.indexOf(possible) == -1) {
                   8180:                     okSpares.push(possible);
                   8181:                 } else {
                   8182:                     if (currnew == possible) {
                   8183:                         selIdx = 0;
                   8184:                     }
                   8185:                 }
                   8186:             }
                   8187:         }
                   8188:         for (var k=0; k<include.length; k++) {
                   8189:             if (okSpares.indexOf(include[k]) == -1) {
                   8190:                 okSpares.push(include[k]);
                   8191:             }
                   8192:         }
                   8193:         okSpares.sort();
                   8194:         newSpare.options.length = 0;
                   8195:         if (selIdx == 0) {
                   8196:             newSpare.options[0] = new Option("$select","",true,true);
                   8197:         } else {
                   8198:             newSpare.options[0] = new Option("$select","",false,false);
                   8199:         }
                   8200:         for (var m=0; m<okSpares.length; m++) {
                   8201:             var idx = m+1;
                   8202:             var selThis = 0;
                   8203:             if (selIdx != 0) {
                   8204:                 if (okSpares[m] == currnew) {
                   8205:                     selThis = 1;
                   8206:                 }
                   8207:             }
                   8208:             if (selThis == 1) {
                   8209:                 newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
                   8210:             } else {
                   8211:                 newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
                   8212:             }
                   8213:         }
                   8214:     }
                   8215:     return;
                   8216: }
                   8217: 
                   8218: function checkNewSpares(lonhost,type) {
                   8219:     var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
                   8220:     var chosen =  newSpare.options[newSpare.selectedIndex].value;
                   8221:     if (chosen != '') { 
                   8222:         var othertype;
                   8223:         var othernewSpare;
                   8224:         if (type == 'primary') {
                   8225:             othernewSpare = document.getElementById('newspare_default_'+lonhost);
                   8226:         }
                   8227:         if (type == 'default') {
                   8228:             othernewSpare = document.getElementById('newspare_primary_'+lonhost);
                   8229:         }
                   8230:         if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
                   8231:             othernewSpare.selectedIndex = 0;
                   8232:         }
                   8233:     }
                   8234:     return;
                   8235: }
                   8236: 
                   8237: // ]]>
                   8238: </script>
                   8239: 
                   8240: END
                   8241: 
                   8242: }
                   8243: 
                   8244: sub common_domprefs_js {
                   8245:     return <<"END";
                   8246: 
                   8247: <script type="text/javascript">
                   8248: // <![CDATA[
                   8249: 
1.150     raeburn  8250: function getIndicesByName(formname,item) {
1.152     raeburn  8251:     var group = new Array();
1.150     raeburn  8252:     for (var i=0;i<formname.elements.length;i++) {
                   8253:         if (formname.elements[i].name == item) {
1.152     raeburn  8254:             group.push(formname.elements[i].id);
1.150     raeburn  8255:         }
                   8256:     }
1.152     raeburn  8257:     return group;
1.150     raeburn  8258: }
                   8259: 
                   8260: // ]]>
                   8261: </script>
                   8262: 
                   8263: END
1.152     raeburn  8264: 
1.150     raeburn  8265: }
                   8266: 
1.3       raeburn  8267: 1;

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