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

1.1       raeburn     1: # The LearningOnline Network with CAPA
                      2: # Handler to set domain-wide configuration settings
                      3: #
1.153   ! raeburn     4: # $Id: domainprefs.pm,v 1.152 2011/08/10 14:54:42 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: 
                    174: sub handler {
                    175:     my $r=shift;
                    176:     if ($r->header_only) {
                    177:         &Apache::loncommon::content_type($r,'text/html');
                    178:         $r->send_http_header;
                    179:         return OK;
                    180:     }
                    181: 
1.91      raeburn   182:     my $context = 'domain';
1.1       raeburn   183:     my $dom = $env{'request.role.domain'};
1.5       albertel  184:     my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1       raeburn   185:     if (&Apache::lonnet::allowed('mau',$dom)) {
                    186:         &Apache::loncommon::content_type($r,'text/html');
                    187:         $r->send_http_header;
                    188:     } else {
                    189:         $env{'user.error.msg'}=
                    190:         "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
                    191:         return HTTP_NOT_ACCEPTABLE;
                    192:     }
                    193:     &Apache::lonhtmlcommon::clear_breadcrumbs();
                    194:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.58      raeburn   195:                                             ['phase','actions']);
1.30      raeburn   196:     my $phase = 'pickactions';
1.3       raeburn   197:     if ( exists($env{'form.phase'}) ) {
                    198:         $phase = $env{'form.phase'};
                    199:     }
1.150     raeburn   200:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.3       raeburn   201:     my %domconfig =
1.6       raeburn   202:       &Apache::lonnet::get_dom('configuration',['login','rolecolors',
1.125     raeburn   203:                 'quotas','autoenroll','autoupdate','autocreate',
                    204:                 'directorysrch','usercreation','usermodification',
                    205:                 'contacts','defaults','scantron','coursecategories',
                    206:                 'serverstatuses','requestcourses','helpsettings',
1.150     raeburn   207:                 'coursedefaults','usersessions','loadbalancing'],$dom);
1.43      raeburn   208:     my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll',
1.125     raeburn   209:                        'autoupdate','autocreate','directorysrch','contacts',
1.48      raeburn   210:                        'usercreation','usermodification','scantron',
1.121     raeburn   211:                        'requestcourses','coursecategories','serverstatuses','helpsettings',
1.137     raeburn   212:                        'coursedefaults','usersessions');
1.150     raeburn   213:     if (keys(%servers) > 1) {
                    214:         push(@prefs_order,'loadbalancing');
                    215:     }
1.30      raeburn   216:     my %prefs = (
                    217:         'rolecolors' =>
                    218:                    { text => 'Default color schemes',
1.67      raeburn   219:                      help => 'Domain_Configuration_Color_Schemes',
1.30      raeburn   220:                      header => [{col1 => 'Student Settings',
                    221:                                  col2 => '',},
                    222:                                 {col1 => 'Coordinator Settings',
                    223:                                  col2 => '',},
                    224:                                 {col1 => 'Author Settings',
                    225:                                  col2 => '',},
                    226:                                 {col1 => 'Administrator Settings',
                    227:                                  col2 => '',}],
                    228:                     },
1.110     raeburn   229:         'login' =>
1.30      raeburn   230:                     { text => 'Log-in page options',
1.67      raeburn   231:                       help => 'Domain_Configuration_Login_Page',
1.30      raeburn   232:                       header => [{col1 => 'Item',
                    233:                                   col2 => '',}],
                    234:                     },
1.110     raeburn   235: 
1.43      raeburn   236:         'defaults' => 
1.141     raeburn   237:                     { text => 'Default authentication/language/timezone/portal',
1.67      raeburn   238:                       help => 'Domain_Configuration_LangTZAuth',
1.43      raeburn   239:                       header => [{col1 => 'Setting',
                    240:                                   col2 => 'Value'}],
                    241:                     },
1.30      raeburn   242:         'quotas' => 
1.133     raeburn   243:                     { text => 'User blogs, personal information pages, portfolios',
1.67      raeburn   244:                       help => 'Domain_Configuration_Quotas',
1.77      raeburn   245:                       header => [{col1 => 'User affiliation',
1.72      raeburn   246:                                   col2 => 'Available tools',
                    247:                                   col3 => 'Portfolio quota',}],
1.30      raeburn   248:                     },
                    249:         'autoenroll' =>
                    250:                    { text => 'Auto-enrollment settings',
1.67      raeburn   251:                      help => 'Domain_Configuration_Auto_Enrollment',
1.30      raeburn   252:                      header => [{col1 => 'Configuration setting',
                    253:                                  col2 => 'Value(s)'}],
                    254:                    },
                    255:         'autoupdate' => 
                    256:                    { text => 'Auto-update settings',
1.67      raeburn   257:                      help => 'Domain_Configuration_Auto_Updates',
1.30      raeburn   258:                      header => [{col1 => 'Setting',
                    259:                                  col2 => 'Value',},
1.131     raeburn   260:                                 {col1 => 'Setting',
                    261:                                  col2 => 'Affiliation'},
1.43      raeburn   262:                                 {col1 => 'User population',
1.131     raeburn   263:                                  col2 => 'Updateable user data'}],
1.30      raeburn   264:                   },
1.125     raeburn   265:         'autocreate' => 
                    266:                   { text => 'Auto-course creation settings',
                    267:                      help => 'Domain_Configuration_Auto_Creation',
                    268:                      header => [{col1 => 'Configuration Setting',
                    269:                                  col2 => 'Value',}],
                    270:                   },
1.30      raeburn   271:         'directorysrch' => 
                    272:                   { text => 'Institutional directory searches',
1.67      raeburn   273:                     help => 'Domain_Configuration_InstDirectory_Search',
1.30      raeburn   274:                     header => [{col1 => 'Setting',
                    275:                                 col2 => 'Value',}],
                    276:                   },
                    277:         'contacts' =>
                    278:                   { text => 'Contact Information',
1.67      raeburn   279:                     help => 'Domain_Configuration_Contact_Info',
1.30      raeburn   280:                     header => [{col1 => 'Setting',
                    281:                                 col2 => 'Value',}],
                    282:                   },
                    283: 
                    284:         'usercreation' => 
                    285:                   { text => 'User creation',
1.67      raeburn   286:                     help => 'Domain_Configuration_User_Creation',
1.43      raeburn   287:                     header => [{col1 => 'Format rule type',
                    288:                                 col2 => 'Format rules in force'},
1.34      raeburn   289:                                {col1 => 'User account creation',
                    290:                                 col2 => 'Usernames which may be created',},
1.30      raeburn   291:                                {col1 => 'Context',
1.43      raeburn   292:                                 col2 => 'Assignable authentication types'}],
1.30      raeburn   293:                   },
1.69      raeburn   294:         'usermodification' =>
1.33      raeburn   295:                   { text => 'User modification',
1.67      raeburn   296:                     help => 'Domain_Configuration_User_Modification',
1.33      raeburn   297:                     header => [{col1 => 'Target user has role',
                    298:                                 col2 => 'User information updateable in author context'},
                    299:                                {col1 => 'Target user has role',
1.63      raeburn   300:                                 col2 => 'User information updateable in course context'},
                    301:                                {col1 => "Status of user",
                    302:                                 col2 => 'Information settable when self-creating account (if directory data blank)'}],
1.33      raeburn   303:                   },
1.69      raeburn   304:         'scantron' =>
1.95      www       305:                   { text => 'Bubblesheet format file',
1.67      raeburn   306:                     help => 'Domain_Configuration_Scantron_Format',
1.46      raeburn   307:                     header => [ {col1 => 'Item',
                    308:                                  col2 => '',
                    309:                               }],
                    310:                   },
1.86      raeburn   311:         'requestcourses' => 
                    312:                  {text => 'Request creation of courses',
                    313:                   help => 'Domain_Configuration_Request_Courses',
                    314:                   header => [{col1 => 'User affiliation',
1.102     raeburn   315:                               col2 => 'Availability/Processing of requests',},
                    316:                              {col1 => 'Setting',
                    317:                               col2 => 'Value'}],
1.86      raeburn   318:                  },
1.69      raeburn   319:         'coursecategories' =>
1.120     raeburn   320:                   { text => 'Cataloging of courses/communities',
1.67      raeburn   321:                     help => 'Domain_Configuration_Cataloging_Courses',
1.69      raeburn   322:                     header => [{col1 => 'Category settings',
1.57      raeburn   323:                                 col2 => '',},
                    324:                                {col1 => 'Categories',
                    325:                                 col2 => '',
                    326:                                }],
1.69      raeburn   327:                   },
                    328:         'serverstatuses' =>
1.77      raeburn   329:                  {text   => 'Access to server status pages',
1.69      raeburn   330:                   help   => 'Domain_Configuration_Server_Status',
                    331:                   header => [{col1 => 'Status Page',
                    332:                               col2 => 'Other named users',
                    333:                               col3 => 'Specific IPs',
                    334:                             }],
                    335:                  },
1.118     jms       336:         'helpsettings' =>
                    337:                  {text   => 'Help page settings',
                    338:                   help   => 'Domain_Configuration_Help_Settings',
1.122     jms       339:                   header => [{col1 => 'Authenticated Help Settings',
                    340:                               col2 => ''},
                    341:                              {col1 => 'Unauthenticated Help Settings',
                    342:                               col2 => ''}],
1.118     jms       343:                  },
1.121     raeburn   344:         'coursedefaults' => 
                    345:                  {text => 'Course/Community defaults',
                    346:                   help => 'Domain_Configuration_Course_Defaults',
1.139     raeburn   347:                   header => [{col1 => 'Defaults which can be overridden in each course by a CC',
                    348:                               col2 => 'Value',},
                    349:                              {col1 => 'Defaults which can be overridden for each course by a DC',
                    350:                               col2 => 'Value',},],
1.121     raeburn   351:                  },
1.120     raeburn   352:         'privacy' => 
                    353:                  {text   => 'User Privacy',
                    354:                   help   => 'Domain_Configuration_User_Privacy',
                    355:                   header => [{col1 => 'Setting',
                    356:                               col2 => 'Value',}],
                    357:                  },
1.141     raeburn   358:         'usersessions' =>
1.145     raeburn   359:                  {text  => 'User session hosting/offloading',
1.137     raeburn   360:                   help  => 'Domain_Configuration_User_Sessions',
1.145     raeburn   361:                   header => [{col1 => 'Domain server',
                    362:                               col2 => 'Servers to offload sessions to when busy'},
                    363:                              {col1 => 'Hosting of users from other domains',
1.137     raeburn   364:                               col2 => 'Rules'},
                    365:                              {col1 => "Hosting domain's own users elsewhere",
                    366:                               col2 => 'Rules'}],
                    367:                  },
1.150     raeburn   368:          'loadbalancing' =>
                    369:                  {text  => 'Dedicated Load Balancer',
                    370:                   help  => 'Domain_Configuration_Load_Balancing',
                    371:                   header => [{col1 => 'Server',
                    372:                               col2 => 'Default destinations',
                    373:                               col3 => 'User affliation',
                    374:                               col4 => 'Overrides'},
                    375:                             ],
                    376:                  },
1.3       raeburn   377:     );
1.110     raeburn   378:     if (keys(%servers) > 1) {
                    379:         $prefs{'login'}  = { text   => 'Log-in page options',
                    380:                              help   => 'Domain_Configuration_Login_Page',
                    381:                             header => [{col1 => 'Log-in Service',
                    382:                                         col2 => 'Server Setting',},
                    383:                                        {col1 => 'Log-in Page Items',
                    384:                                         col2 => ''}],
                    385:                            };
                    386:     }
1.6       raeburn   387:     my @roles = ('student','coordinator','author','admin');
1.30      raeburn   388:     my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3       raeburn   389:     &Apache::lonhtmlcommon::add_breadcrumb
1.30      raeburn   390:     ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133     raeburn   391:       text=>"Settings to display/modify"});
1.9       raeburn   392:     my $confname = $dom.'-domainconfig';
1.3       raeburn   393:     if ($phase eq 'process') {
1.91      raeburn   394:         &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,\@roles);
1.30      raeburn   395:     } elsif ($phase eq 'display') {
1.152     raeburn   396:         my $js;
                    397:         if (keys(%servers) > 1) {
                    398:             my ($othertitle,$usertypes,$types) =
                    399:                 &Apache::loncommon::sorted_inst_types($dom);
                    400:             $js = &lonbalance_targets_js($dom,$types,\%servers).
                    401:                   &new_spares_js().
1.153   ! raeburn   402:                   &common_domprefs_js().
        !           403:                   &Apache::loncommon::javascript_array_indexof();
1.152     raeburn   404:         }
1.150     raeburn   405:         &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1       raeburn   406:     } else {
1.21      raeburn   407:         if (keys(%domconfig) == 0) {
                    408:             my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29      raeburn   409:             my @ids=&Apache::lonnet::current_machine_ids();
                    410:             if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21      raeburn   411:                 my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41      raeburn   412:                 my @loginimages = ('img','logo','domlogo','login');
1.21      raeburn   413:                 my $custom_img_count = 0;
                    414:                 foreach my $img (@loginimages) {
                    415:                     if ($designhash{$dom.'.login.'.$img} ne '') {
                    416:                         $custom_img_count ++;
                    417:                     }
                    418:                 }
                    419:                 foreach my $role (@roles) {
                    420:                     if ($designhash{$dom.'.'.$role.'.img'} ne '') {
                    421:                         $custom_img_count ++;
                    422:                     }
                    423:                 }
                    424:                 if ($custom_img_count > 0) {
1.94      raeburn   425:                     &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21      raeburn   426:                     my $switch_server = &check_switchserver($dom,$confname);
1.29      raeburn   427:                     $r->print(
                    428:     &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
                    429:     &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
                    430:     &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 />'.
                    431:     &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
                    432:                     if ($switch_server) {
1.30      raeburn   433:                         $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29      raeburn   434:                     }
1.91      raeburn   435:                     $r->print(&Apache::loncommon::end_page());
1.21      raeburn   436:                     return OK;
                    437:                 }
                    438:             }
                    439:         }
1.91      raeburn   440:         &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3       raeburn   441:     }
                    442:     return OK;
                    443: }
                    444: 
                    445: sub process_changes {
1.92      raeburn   446:     my ($r,$dom,$confname,$action,$roles,$values) = @_;
                    447:     my %domconfig;
                    448:     if (ref($values) eq 'HASH') {
                    449:         %domconfig = %{$values};
                    450:     }
1.3       raeburn   451:     my $output;
                    452:     if ($action eq 'login') {
1.9       raeburn   453:         $output = &modify_login($r,$dom,$confname,%domconfig);
1.6       raeburn   454:     } elsif ($action eq 'rolecolors') {
1.9       raeburn   455:         $output = &modify_rolecolors($r,$dom,$confname,$roles,
                    456:                                      %domconfig);
1.3       raeburn   457:     } elsif ($action eq 'quotas') {
1.86      raeburn   458:         $output = &modify_quotas($dom,$action,%domconfig);
1.3       raeburn   459:     } elsif ($action eq 'autoenroll') {
                    460:         $output = &modify_autoenroll($dom,%domconfig);
                    461:     } elsif ($action eq 'autoupdate') {
                    462:         $output = &modify_autoupdate($dom,%domconfig);
1.125     raeburn   463:     } elsif ($action eq 'autocreate') {
                    464:         $output = &modify_autocreate($dom,%domconfig);
1.23      raeburn   465:     } elsif ($action eq 'directorysrch') {
                    466:         $output = &modify_directorysrch($dom,%domconfig);
1.27      raeburn   467:     } elsif ($action eq 'usercreation') {
1.28      raeburn   468:         $output = &modify_usercreation($dom,%domconfig);
1.33      raeburn   469:     } elsif ($action eq 'usermodification') {
                    470:         $output = &modify_usermodification($dom,%domconfig);
1.28      raeburn   471:     } elsif ($action eq 'contacts') {
                    472:         $output = &modify_contacts($dom,%domconfig);
1.43      raeburn   473:     } elsif ($action eq 'defaults') {
                    474:         $output = &modify_defaults($dom,$r);
1.46      raeburn   475:     } elsif ($action eq 'scantron') {
1.48      raeburn   476:         $output = &modify_scantron($r,$dom,$confname,%domconfig);
                    477:     } elsif ($action eq 'coursecategories') {
                    478:         $output = &modify_coursecategories($dom,%domconfig);
1.69      raeburn   479:     } elsif ($action eq 'serverstatuses') {
                    480:         $output = &modify_serverstatuses($dom,%domconfig);
1.86      raeburn   481:     } elsif ($action eq 'requestcourses') {
                    482:         $output = &modify_quotas($dom,$action,%domconfig);
1.118     jms       483:     } elsif ($action eq 'helpsettings') {
1.122     jms       484:         $output = &modify_helpsettings($r,$dom,$confname,%domconfig);
1.121     raeburn   485:     } elsif ($action eq 'coursedefaults') {
                    486:         $output = &modify_coursedefaults($dom,%domconfig);
1.137     raeburn   487:     } elsif ($action eq 'usersessions') {
                    488:         $output = &modify_usersessions($dom,%domconfig);
1.150     raeburn   489:     } elsif ($action eq 'loadbalancing') {
                    490:         $output = &modify_loadbalancing($dom,%domconfig);
1.3       raeburn   491:     }
                    492:     return $output;
                    493: }
                    494: 
                    495: sub print_config_box {
1.9       raeburn   496:     my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30      raeburn   497:     my $rowtotal = 0;
1.49      raeburn   498:     my $output;
                    499:     if ($action eq 'coursecategories') {
                    500:         $output = &coursecategories_javascript($settings);
1.91      raeburn   501:     }
1.49      raeburn   502:     $output .= 
1.30      raeburn   503:          '<table class="LC_nested_outer">
1.3       raeburn   504:           <tr>
1.66      raeburn   505:            <th align="left" valign="middle"><span class="LC_nobreak">'.
                    506:            &mt($item->{text}).'&nbsp;'.
                    507:            &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
                    508:           '</tr>';
1.30      raeburn   509:     $rowtotal ++;
1.110     raeburn   510:     my $numheaders = 1;
                    511:     if (ref($item->{'header'}) eq 'ARRAY') {
                    512:         $numheaders = scalar(@{$item->{'header'}});
                    513:     }
                    514:     if ($numheaders > 1) {
1.64      raeburn   515:         my $colspan = '';
1.145     raeburn   516:         my $rightcolspan = '';
1.122     jms       517:         if (($action eq 'rolecolors') || ($action eq 'coursecategories') || ($action eq 'helpsettings')) {
1.64      raeburn   518:             $colspan = ' colspan="2"';
                    519:         }
1.145     raeburn   520:         if ($action eq 'usersessions') {
                    521:             $rightcolspan = ' colspan="3"'; 
                    522:         }
1.30      raeburn   523:         $output .= '
1.3       raeburn   524:           <tr>
                    525:            <td>
                    526:             <table class="LC_nested">
                    527:              <tr class="LC_info_row">
1.59      bisitz    528:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145     raeburn   529:               <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30      raeburn   530:              </tr>';
1.69      raeburn   531:         $rowtotal ++;
1.6       raeburn   532:         if ($action eq 'autoupdate') {
1.30      raeburn   533:             $output .= &print_autoupdate('top',$dom,$settings,\$rowtotal);
1.28      raeburn   534:         } elsif ($action eq 'usercreation') {
1.33      raeburn   535:             $output .= &print_usercreation('top',$dom,$settings,\$rowtotal);
                    536:         } elsif ($action eq 'usermodification') {
                    537:             $output .= &print_usermodification('top',$dom,$settings,\$rowtotal);
1.57      raeburn   538:         } elsif ($action eq 'coursecategories') {
                    539:             $output .= &print_coursecategories('top',$dom,$item,$settings,\$rowtotal);
1.110     raeburn   540:         } elsif ($action eq 'login') {
                    541:             $output .= &print_login('top',$dom,$confname,$phase,$settings,\$rowtotal);
                    542:             $colspan = ' colspan="2"';
1.102     raeburn   543:         } elsif ($action eq 'requestcourses') {
                    544:             $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.118     jms       545:         } elsif ($action eq 'helpsettings') {
1.122     jms       546:             $output .= &print_helpsettings('top',$dom,$confname,$settings,\$rowtotal);
1.137     raeburn   547:         } elsif ($action eq 'usersessions') {
                    548:             $output .= &print_usersessions('top',$dom,$settings,\$rowtotal); 
1.122     jms       549:         } elsif ($action eq 'rolecolors') {
1.30      raeburn   550:             $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.139     raeburn   551:         } elsif ($action eq 'coursedefaults') {
                    552:             $output .= &print_coursedefaults('top',$dom,$settings,\$rowtotal);
1.6       raeburn   553:         }
1.30      raeburn   554:         $output .= '
1.6       raeburn   555:            </table>
                    556:           </td>
                    557:          </tr>
                    558:          <tr>
                    559:            <td>
                    560:             <table class="LC_nested">
                    561:              <tr class="LC_info_row">
1.59      bisitz    562:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>';
1.57      raeburn   563:         $output .= '
1.59      bisitz    564:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30      raeburn   565:              </tr>';
                    566:             $rowtotal ++;
1.6       raeburn   567:         if ($action eq 'autoupdate') {
1.131     raeburn   568:             $output .= &print_autoupdate('middle',$dom,$settings,\$rowtotal).'
                    569:            </table>
                    570:           </td>
                    571:          </tr>
                    572:          <tr>
                    573:            <td>
                    574:             <table class="LC_nested">
                    575:              <tr class="LC_info_row">
                    576:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
                    577:               <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>      </tr>'.
                    578:             &print_autoupdate('bottom',$dom,$settings,\$rowtotal);
                    579:             $rowtotal ++;
1.28      raeburn   580:         } elsif ($action eq 'usercreation') {
1.34      raeburn   581:             $output .= &print_usercreation('middle',$dom,$settings,\$rowtotal).'
                    582:            </table>
                    583:           </td>
                    584:          </tr>
                    585:          <tr>
                    586:            <td>
                    587:             <table class="LC_nested">
                    588:              <tr class="LC_info_row">
1.59      bisitz    589:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
                    590:               <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>             </tr>'.
1.34      raeburn   591:             &print_usercreation('bottom',$dom,$settings,\$rowtotal);
                    592:             $rowtotal ++;
1.33      raeburn   593:         } elsif ($action eq 'usermodification') {
1.63      raeburn   594:             $output .= &print_usermodification('middle',$dom,$settings,\$rowtotal).'
                    595:            </table>
                    596:           </td>
                    597:          </tr>
                    598:          <tr>
                    599:            <td>
                    600:             <table class="LC_nested">
                    601:              <tr class="LC_info_row">
                    602:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
                    603:               <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>      </tr>'.
                    604:                        &print_usermodification('bottom',$dom,$settings,\$rowtotal);
                    605:             $rowtotal ++;
1.57      raeburn   606:         } elsif ($action eq 'coursecategories') {
                    607:             $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.110     raeburn   608:         } elsif ($action eq 'login') {
                    609:             $output .= &print_login('bottom',$dom,$confname,$phase,$settings,\$rowtotal);
1.102     raeburn   610:         } elsif ($action eq 'requestcourses') {
                    611:             $output .= &print_courserequestmail($dom,$settings,\$rowtotal);
1.122     jms       612:         } elsif ($action eq 'helpsettings') {
                    613:             $output .= &print_helpsettings('bottom',$dom,$confname,$settings,\$rowtotal);
1.137     raeburn   614:         } elsif ($action eq 'usersessions') {
1.145     raeburn   615:             $output .= &print_usersessions('middle',$dom,$settings,\$rowtotal).'
                    616:            </table>
                    617:           </td>
                    618:          </tr>
                    619:          <tr>
                    620:            <td>
                    621:             <table class="LC_nested">
                    622:              <tr class="LC_info_row">
                    623:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
                    624:               <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>      </tr>'.
                    625:                        &print_usersessions('bottom',$dom,$settings,\$rowtotal);
                    626:             $rowtotal ++;
1.139     raeburn   627:         } elsif ($action eq 'coursedefaults') {
                    628:             $output .= &print_coursedefaults('bottom',$dom,$settings,\$rowtotal);
1.122     jms       629:         } elsif ($action eq 'rolecolors') {
1.30      raeburn   630:             $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6       raeburn   631:            </table>
                    632:           </td>
                    633:          </tr>
                    634:          <tr>
                    635:            <td>
                    636:             <table class="LC_nested">
                    637:              <tr class="LC_info_row">
1.69      raeburn   638:               <td class="LC_left_item"'.$colspan.' valign="top">'.
                    639:                &mt($item->{'header'}->[2]->{'col1'}).'</td>
                    640:               <td class="LC_right_item" valign="top">'.
                    641:                &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3       raeburn   642:              </tr>'.
1.30      raeburn   643:             &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3       raeburn   644:            </table>
                    645:           </td>
                    646:          </tr>
                    647:          <tr>
                    648:            <td>
                    649:             <table class="LC_nested">
                    650:              <tr class="LC_info_row">
1.59      bisitz    651:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
                    652:               <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3       raeburn   653:              </tr>'.
1.30      raeburn   654:             &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
                    655:             $rowtotal += 2;
1.6       raeburn   656:         }
1.3       raeburn   657:     } else {
1.30      raeburn   658:         $output .= '
1.3       raeburn   659:           <tr>
                    660:            <td>
                    661:             <table class="LC_nested">
1.30      raeburn   662:              <tr class="LC_info_row">';
1.24      raeburn   663:         if (($action eq 'login') || ($action eq 'directorysrch')) {
1.30      raeburn   664:             $output .= '  
1.59      bisitz    665:               <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69      raeburn   666:         } elsif ($action eq 'serverstatuses') {
                    667:             $output .= '
                    668:               <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
                    669:               '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
                    670: 
1.6       raeburn   671:         } else {
1.30      raeburn   672:             $output .= '
1.69      raeburn   673:               <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
                    674:         }
1.72      raeburn   675:         if (defined($item->{'header'}->[0]->{'col3'})) {
                    676:             $output .= '<td class="LC_left_item" valign="top">'.
                    677:                        &mt($item->{'header'}->[0]->{'col2'});
                    678:             if ($action eq 'serverstatuses') {
                    679:                 $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
                    680:             } 
1.69      raeburn   681:         } else {
                    682:             $output .= '<td class="LC_right_item" valign="top">'.
                    683:                        &mt($item->{'header'}->[0]->{'col2'});
                    684:         }
                    685:         $output .= '</td>';
                    686:         if ($item->{'header'}->[0]->{'col3'}) {
1.150     raeburn   687:             if (defined($item->{'header'}->[0]->{'col4'})) {
                    688:                 $output .= '<td class="LC_left_item" valign="top">'.
                    689:                             &mt($item->{'header'}->[0]->{'col3'});
                    690:             } else {
                    691:                 $output .= '<td class="LC_right_item" valign="top">'.
                    692:                            &mt($item->{'header'}->[0]->{'col3'});
                    693:             }
1.69      raeburn   694:             if ($action eq 'serverstatuses') {
                    695:                 $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
                    696:             }
                    697:             $output .= '</td>';
1.6       raeburn   698:         }
1.150     raeburn   699:         if ($item->{'header'}->[0]->{'col4'}) {
                    700:             $output .= '<td class="LC_right_item" valign="top">'.
                    701:                        &mt($item->{'header'}->[0]->{'col4'});
                    702:         }
1.69      raeburn   703:         $output .= '</tr>';
1.48      raeburn   704:         $rowtotal ++;
1.3       raeburn   705:         if ($action eq 'login') {
1.110     raeburn   706:             $output .= &print_login('bottom',$dom,$confname,$phase,$settings,
                    707:                                     \$rowtotal);
1.3       raeburn   708:         } elsif ($action eq 'quotas') {
1.86      raeburn   709:             $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.3       raeburn   710:         } elsif ($action eq 'autoenroll') {
1.30      raeburn   711:             $output .= &print_autoenroll($dom,$settings,\$rowtotal);
1.125     raeburn   712:         } elsif ($action eq 'autocreate') {
                    713:             $output .= &print_autocreate($dom,$settings,\$rowtotal);
1.23      raeburn   714:         } elsif ($action eq 'directorysrch') {
1.30      raeburn   715:             $output .= &print_directorysrch($dom,$settings,\$rowtotal);
1.28      raeburn   716:         } elsif ($action eq 'contacts') {
1.30      raeburn   717:             $output .= &print_contacts($dom,$settings,\$rowtotal);
1.43      raeburn   718:         } elsif ($action eq 'defaults') {
                    719:             $output .= &print_defaults($dom,\$rowtotal);
1.46      raeburn   720:         } elsif ($action eq 'scantron') {
                    721:             $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
1.69      raeburn   722:         } elsif ($action eq 'serverstatuses') {
                    723:             $output .= &print_serverstatuses($dom,$settings,\$rowtotal);
1.118     jms       724:         } elsif ($action eq 'helpsettings') {
1.122     jms       725:             $output .= &print_helpsettings('top',$dom,$confname,$settings,\$rowtotal);
1.150     raeburn   726:         } elsif ($action eq 'loadbalancing') {
                    727:             $output .= &print_loadbalancing($dom,$settings,\$rowtotal);
1.121     raeburn   728:         }
1.3       raeburn   729:     }
1.30      raeburn   730:     $output .= '
1.3       raeburn   731:    </table>
                    732:   </td>
                    733:  </tr>
1.30      raeburn   734: </table><br />';
                    735:     return ($output,$rowtotal);
1.1       raeburn   736: }
                    737: 
1.3       raeburn   738: sub print_login {
1.110     raeburn   739:     my ($position,$dom,$confname,$phase,$settings,$rowtotal) = @_;
                    740:     my ($css_class,$datatable);
1.6       raeburn   741:     my %choices = &login_choices();
1.110     raeburn   742: 
                    743:     if ($position eq 'top') {
1.149     raeburn   744:         my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110     raeburn   745:         my $choice = $choices{'disallowlogin'};
                    746:         $css_class = ' class="LC_odd_row"';
1.128     raeburn   747:         $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110     raeburn   748:                       '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128     raeburn   749:                       '<th>'.$choices{'server'}.'</th>'.
                    750:                       '<th>'.$choices{'serverpath'}.'</th>'.
                    751:                       '<th>'.$choices{'custompath'}.'</th>'.
                    752:                       '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110     raeburn   753:         my %disallowed;
                    754:         if (ref($settings) eq 'HASH') {
                    755:             if (ref($settings->{'loginvia'}) eq 'HASH') {
                    756:                %disallowed = %{$settings->{'loginvia'}};
                    757:             }
                    758:         }
                    759:         foreach my $lonhost (sort(keys(%servers))) {
                    760:             my $direct = 'selected="selected"';
1.128     raeburn   761:             if (ref($disallowed{$lonhost}) eq 'HASH') {
                    762:                 if ($disallowed{$lonhost}{'server'} ne '') {
                    763:                     $direct = '';
                    764:                 }
1.110     raeburn   765:             }
1.115     raeburn   766:             $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128     raeburn   767:                           '<td><select name="'.$lonhost.'_server">'.
1.110     raeburn   768:                           '<option value=""'.$direct.'>'.$choices{'directlogin'}.
                    769:                           '</option>';
                    770:             foreach my $hostid (keys(%servers)) {
1.115     raeburn   771:                 next if ($servers{$hostid} eq $servers{$lonhost});
1.110     raeburn   772:                 my $selected = '';
1.128     raeburn   773:                 if (ref($disallowed{$lonhost}) eq 'HASH') {
                    774:                     if ($hostid eq $disallowed{$lonhost}{'server'}) {
                    775:                         $selected = 'selected="selected"';
                    776:                     }
1.110     raeburn   777:                 }
                    778:                 $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
                    779:                               $servers{$hostid}.'</option>';
                    780:             }
1.128     raeburn   781:             $datatable .= '</select></td>'.
                    782:                           '<td><select name="'.$lonhost.'_serverpath">';
                    783:             foreach my $path ('','/','/adm/login','/adm/roles','custom') {
                    784:                 my $pathname = $path;
                    785:                 if ($path eq 'custom') {
                    786:                     $pathname = &mt('Custom Path').' ->';
                    787:                 }
                    788:                 my $selected = '';
                    789:                 if (ref($disallowed{$lonhost}) eq 'HASH') {
                    790:                     if ($path eq $disallowed{$lonhost}{'serverpath'}) {
                    791:                         $selected = 'selected="selected"';
                    792:                     }
                    793:                 } elsif ($path eq '') {
                    794:                     $selected = 'selected="selected"';
                    795:                 }
                    796:                 $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
                    797:             }
                    798:             $datatable .= '</select></td>';
                    799:             my ($custom,$exempt);
                    800:             if (ref($disallowed{$lonhost}) eq 'HASH') {
                    801:                 $custom = $disallowed{$lonhost}{'custompath'};
                    802:                 $exempt = $disallowed{$lonhost}{'exempt'};
                    803:             }
                    804:             $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
                    805:                           '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
                    806:                           '</tr>';
1.110     raeburn   807:         }
                    808:         $datatable .= '</table></td></tr>';
                    809:         return $datatable;
                    810:     }
                    811: 
1.42      raeburn   812:     my %defaultchecked = ( 
1.43      raeburn   813:                            'coursecatalog' => 'on',
                    814:                            'adminmail'     => 'off',
                    815:                            'newuser'       => 'off',
                    816:                          );
1.118     jms       817:     my @toggles = ('coursecatalog','adminmail','newuser');
1.42      raeburn   818:     my (%checkedon,%checkedoff);
                    819:     foreach my $item (@toggles) {
                    820:         if ($defaultchecked{$item} eq 'on') { 
                    821:             $checkedon{$item} = ' checked="checked" ';
                    822:             $checkedoff{$item} = ' ';
                    823:         } elsif ($defaultchecked{$item} eq 'off') {
                    824:             $checkedoff{$item} = ' checked="checked" ';
                    825:             $checkedon{$item} = ' ';
                    826:         }
                    827:     }
1.41      raeburn   828:     my @images = ('img','logo','domlogo','login');
                    829:     my @logintext = ('textcol','bgcol');
1.6       raeburn   830:     my @bgs = ('pgbg','mainbg','sidebg');
                    831:     my @links = ('link','alink','vlink');
1.7       albertel  832:     my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6       raeburn   833:     my %defaultdesign = %Apache::loncommon::defaultdesign;
                    834:     my (%is_custom,%designs);
                    835:     my %defaults = (
                    836:                    font => $defaultdesign{'login.font'},
                    837:                    );
                    838:     foreach my $item (@images) {
                    839:         $defaults{$item} = $defaultdesign{'login.'.$item};
1.70      raeburn   840:         $defaults{'showlogo'}{$item} = 1;
1.6       raeburn   841:     }
                    842:     foreach my $item (@bgs) {
                    843:         $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
                    844:     }
1.41      raeburn   845:     foreach my $item (@logintext) {
                    846:         $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
                    847:     }
1.6       raeburn   848:     foreach my $item (@links) {
                    849:         $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
                    850:     }
1.3       raeburn   851:     if (ref($settings) eq 'HASH') {
1.42      raeburn   852:         foreach my $item (@toggles) {
                    853:             if ($settings->{$item} eq '1') {
                    854:                 $checkedon{$item} =  ' checked="checked" ';
                    855:                 $checkedoff{$item} = ' ';
                    856:             } elsif ($settings->{$item} eq '0') {
                    857:                 $checkedoff{$item} =  ' checked="checked" ';
                    858:                 $checkedon{$item} = ' ';
                    859:             }
1.1       raeburn   860:         }
1.6       raeburn   861:         foreach my $item (@images) {
1.70      raeburn   862:             if (defined($settings->{$item})) {
1.6       raeburn   863:                 $designs{$item} = $settings->{$item};
                    864:                 $is_custom{$item} = 1;
                    865:             }
1.70      raeburn   866:             if (defined($settings->{'showlogo'}{$item})) {
                    867:                 $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
                    868:             }
1.6       raeburn   869:         }
1.41      raeburn   870:         foreach my $item (@logintext) {
                    871:             if ($settings->{$item} ne '') {
                    872:                 $designs{'logintext'}{$item} = $settings->{$item};
                    873:                 $is_custom{$item} = 1;
                    874:             }
                    875:         }
1.6       raeburn   876:         if ($settings->{'font'} ne '') {
                    877:             $designs{'font'} = $settings->{'font'};
                    878:             $is_custom{'font'} = 1;
                    879:         }
                    880:         foreach my $item (@bgs) {
                    881:             if ($settings->{$item} ne '') {
                    882:                 $designs{'bgs'}{$item} = $settings->{$item};
                    883:                 $is_custom{$item} = 1;
                    884:             }
                    885:         }
                    886:         foreach my $item (@links) {
                    887:             if ($settings->{$item} ne '') {
                    888:                 $designs{'links'}{$item} = $settings->{$item};
                    889:                 $is_custom{$item} = 1;
                    890:             }
                    891:         }
                    892:     } else {
                    893:         if ($designhash{$dom.'.login.font'} ne '') {
                    894:             $designs{'font'} = $designhash{$dom.'.login.font'};
                    895:             $is_custom{'font'} = 1;
                    896:         }
1.8       raeburn   897:         foreach my $item (@images) {
                    898:             if ($designhash{$dom.'.login.'.$item} ne '') {
                    899:                 $designs{$item} = $designhash{$dom.'.login.'.$item};
                    900:                 $is_custom{$item} = 1;
                    901:             }
                    902:         }
1.6       raeburn   903:         foreach my $item (@bgs) {
                    904:             if ($designhash{$dom.'.login.'.$item} ne '') {
                    905:                 $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
                    906:                 $is_custom{$item} = 1;
                    907:             }
                    908:         }
                    909:         foreach my $item (@links) {
                    910:             if ($designhash{$dom.'.login.'.$item} ne '') {
                    911:                 $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
                    912:                 $is_custom{$item} = 1;
                    913:             }
                    914:         }
1.1       raeburn   915:     }
1.6       raeburn   916:     my %alt_text = &Apache::lonlocal::texthash  ( img => 'Log-in banner',
                    917:                                                   logo => 'Institution Logo',
1.41      raeburn   918:                                                   domlogo => 'Domain Logo',
                    919:                                                   login => 'Login box');
1.6       raeburn   920:     my $itemcount = 1;
1.42      raeburn   921:     foreach my $item (@toggles) {
                    922:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                    923:         $datatable .=  
                    924:             '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
                    925:             '</td><td>'.
                    926:             '<span class="LC_nobreak"><label><input type="radio" name="'.
                    927:             $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
                    928:             '</label>&nbsp;<label><input type="radio" name="'.$item.'"'.
                    929:             $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
                    930:             '</tr>';
                    931:         $itemcount ++;
                    932:     }
1.135     bisitz    933:     $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1.6       raeburn   934:     $datatable .= '</tr></table></td></tr>';
                    935:     return $datatable;
                    936: }
                    937: 
                    938: sub login_choices {
                    939:     my %choices =
                    940:         &Apache::lonlocal::texthash (
1.116     bisitz    941:             coursecatalog => 'Display Course/Community Catalog link?',
1.110     raeburn   942:             adminmail     => "Display Administrator's E-mail Address?",
                    943:             disallowlogin => "Login page requests redirected",
                    944:             hostid        => "Server",
1.128     raeburn   945:             server        => "Redirect to:",
                    946:             serverpath    => "Path",
                    947:             custompath    => "Custom", 
                    948:             exempt        => "Exempt IP(s)",
1.110     raeburn   949:             directlogin   => "No redirect",
                    950:             newuser       => "Link to create a user account",
                    951:             img           => "Header",
                    952:             logo          => "Main Logo",
                    953:             domlogo       => "Domain Logo",
                    954:             login         => "Log-in Header", 
                    955:             textcol       => "Text color",
                    956:             bgcol         => "Box color",
                    957:             bgs           => "Background colors",
                    958:             links         => "Link colors",
                    959:             font          => "Font color",
                    960:             pgbg          => "Header",
                    961:             mainbg        => "Page",
                    962:             sidebg        => "Login box",
                    963:             link          => "Link",
                    964:             alink         => "Active link",
                    965:             vlink         => "Visited link",
1.6       raeburn   966:         );
                    967:     return %choices;
                    968: }
                    969: 
                    970: sub print_rolecolors {
1.30      raeburn   971:     my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6       raeburn   972:     my %choices = &color_font_choices();
                    973:     my @bgs = ('pgbg','tabbg','sidebg');
                    974:     my @links = ('link','alink','vlink');
                    975:     my @images = ('img');
                    976:     my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7       albertel  977:     my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6       raeburn   978:     my %defaultdesign = %Apache::loncommon::defaultdesign;
                    979:     my (%is_custom,%designs);
                    980:     my %defaults = (
                    981:                    img => $defaultdesign{$role.'.img'},
                    982:                    font => $defaultdesign{$role.'.font'},
1.97      tempelho  983: 		   fontmenu => $defaultdesign{$role.'.fontmenu'},
1.6       raeburn   984:                    );
                    985:     foreach my $item (@bgs) {
                    986:         $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
                    987:     }
                    988:     foreach my $item (@links) {
                    989:         $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
                    990:     }
                    991:     if (ref($settings) eq 'HASH') {
                    992:         if (ref($settings->{$role}) eq 'HASH') {
                    993:             if ($settings->{$role}->{'img'} ne '') {
                    994:                 $designs{'img'} = $settings->{$role}->{'img'};
                    995:                 $is_custom{'img'} = 1;
                    996:             }
                    997:             if ($settings->{$role}->{'font'} ne '') {
                    998:                 $designs{'font'} = $settings->{$role}->{'font'};
                    999:                 $is_custom{'font'} = 1;
                   1000:             }
1.97      tempelho 1001:             if ($settings->{$role}->{'fontmenu'} ne '') {
                   1002:                 $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
                   1003:                 $is_custom{'fontmenu'} = 1;
                   1004:             }
1.6       raeburn  1005:             foreach my $item (@bgs) {
                   1006:                 if ($settings->{$role}->{$item} ne '') {
                   1007:                     $designs{'bgs'}{$item} = $settings->{$role}->{$item};
                   1008:                     $is_custom{$item} = 1;
                   1009:                 }
                   1010:             }
                   1011:             foreach my $item (@links) {
                   1012:                 if ($settings->{$role}->{$item} ne '') {
                   1013:                     $designs{'links'}{$item} = $settings->{$role}->{$item};
                   1014:                     $is_custom{$item} = 1;
                   1015:                 }
                   1016:             }
                   1017:         }
                   1018:     } else {
                   1019:         if ($designhash{$dom.'.'.$role.'.img'} ne '') {
                   1020:             $designs{img} = $designhash{$dom.'.'.$role.'.img'};
                   1021:             $is_custom{'img'} = 1;
                   1022:         }
1.97      tempelho 1023:         if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
                   1024:             $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
                   1025:             $is_custom{'fontmenu'} = 1; 
                   1026:         }
1.6       raeburn  1027:         if ($designhash{$dom.'.'.$role.'.font'} ne '') {
                   1028:             $designs{font} = $designhash{$dom.'.'.$role.'.font'};
                   1029:             $is_custom{'font'} = 1;
                   1030:         }
                   1031:         foreach my $item (@bgs) {
                   1032:             if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
                   1033:                 $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
                   1034:                 $is_custom{$item} = 1;
                   1035:             
                   1036:             }
                   1037:         }
                   1038:         foreach my $item (@links) {
                   1039:             if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
                   1040:                 $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
                   1041:                 $is_custom{$item} = 1;
                   1042:             }
                   1043:         }
                   1044:     }
                   1045:     my $itemcount = 1;
1.30      raeburn  1046:     my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6       raeburn  1047:     $datatable .= '</tr></table></td></tr>';
                   1048:     return $datatable;
                   1049: }
                   1050: 
                   1051: sub display_color_options {
1.9       raeburn  1052:     my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135     bisitz   1053:         $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.6       raeburn  1054:     my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.134     raeburn  1055:     my $datatable = '<tr'.$css_class.'>'.
1.6       raeburn  1056:         '<td>'.$choices->{'font'}.'</td>';
                   1057:     if (!$is_custom->{'font'}) {
1.30      raeburn  1058:         $datatable .=  '<td>'.&mt('Default in use:').'&nbsp;<span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6       raeburn  1059:     } else {
                   1060:         $datatable .= '<td>&nbsp;</td>';
                   1061:     }
                   1062:     my $fontlink = &color_pick($phase,$role,'font',$choices->{'font'},$designs->{'font'});
1.8       raeburn  1063:     $datatable .= '<td><span class="LC_nobreak">'.
1.6       raeburn  1064:                   '<input type="text" size="10" name="'.$role.'_font"'.
1.8       raeburn  1065:                   ' value="'.$designs->{'font'}.'" />&nbsp;'.$fontlink.
1.30      raeburn  1066:                   '&nbsp;<span id="css_'.$role.'_font" style="background-color: '.
                   1067:                   $designs->{'font'}.';">&nbsp;&nbsp;&nbsp;</span>'.
1.8       raeburn  1068:                   '</span></td></tr>';
1.107     raeburn  1069:     unless ($role eq 'login') { 
                   1070:         $datatable .= '<tr'.$css_class.'>'.
                   1071:                       '<td>'.$choices->{'fontmenu'}.'</td>';
                   1072:         if (!$is_custom->{'fontmenu'}) {
                   1073:             $datatable .=  '<td>'.&mt('Default in use:').'&nbsp;<span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
                   1074:         } else {
                   1075:             $datatable .= '<td>&nbsp;</td>';
                   1076:         }
                   1077:         $fontlink = &color_pick($phase,$role,'fontmenu',$choices->{'fontmenu'},$designs->{'fontmenu'});
                   1078:         $datatable .= '<td><span class="LC_nobreak">'.
                   1079:                       '<input type="text" size="10" name="'.$role.'_fontmenu"'.
                   1080:                       ' value="'.$designs->{'fontmenu'}.'" />&nbsp;'.$fontlink.
                   1081:                       '&nbsp;<span id="css_'.$role.'_fontmenu" style="background-color: '.
                   1082:                       $designs->{'fontmenu'}.';">&nbsp;&nbsp;&nbsp;</span>'.
                   1083:                       '</span></td></tr>';
1.97      tempelho 1084:     }
1.9       raeburn  1085:     my $switchserver = &check_switchserver($dom,$confname);
1.6       raeburn  1086:     foreach my $img (@{$images}) {
1.18      albertel 1087: 	$itemcount ++;
1.6       raeburn  1088:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8       raeburn  1089:         $datatable .= '<tr'.$css_class.'>'.
1.70      raeburn  1090:                       '<td>'.$choices->{$img};
1.41      raeburn  1091:         my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70      raeburn  1092:         if ($role eq 'login') {
                   1093:             if ($img eq 'login') {
                   1094:                 $login_hdr_pick =
1.135     bisitz   1095:                     &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70      raeburn  1096:                 $logincolors =
                   1097:                     &login_text_colors($img,$role,$logintext,$phase,$choices,
                   1098:                                             $designs);
                   1099:             } elsif ($img ne 'domlogo') {
                   1100:                 $datatable.= &logo_display_options($img,$defaults,$designs);
                   1101:             }
                   1102:         }
                   1103:         $datatable .= '</td>';
1.6       raeburn  1104:         if ($designs->{$img} ne '') {
                   1105:             $imgfile = $designs->{$img};
1.18      albertel 1106: 	    $img_import = ($imgfile =~ m{^/adm/});
1.6       raeburn  1107:         } else {
                   1108:             $imgfile = $defaults->{$img};
                   1109:         }
                   1110:         if ($imgfile) {
1.9       raeburn  1111:             my ($showfile,$fullsize);
                   1112:             if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6       raeburn  1113:                 my $urldir = $1;
                   1114:                 my $filename = $2;
                   1115:                 my @info = &Apache::lonnet::stat_file($designs->{$img});
                   1116:                 if (@info) {
                   1117:                     my $thumbfile = 'tn-'.$filename;
                   1118:                     my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
                   1119:                     if (@thumb) {
                   1120:                         $showfile = $urldir.'/'.$thumbfile;
                   1121:                     } else {
                   1122:                         $showfile = $imgfile;
                   1123:                     }
                   1124:                 } else {
                   1125:                     $showfile = '';
                   1126:                 }
                   1127:             } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16      raeburn  1128:                 $showfile = $imgfile;
1.6       raeburn  1129:                 my $imgdir = $1;
                   1130:                 my $filename = $2;
                   1131:                 if (-e "/home/httpd/html/$imgdir/tn-".$filename) {
                   1132:                     $showfile = "/$imgdir/tn-".$filename;
                   1133:                 } else {
                   1134:                     my $input = "/home/httpd/html".$imgfile;
                   1135:                     my $output = '/home/httpd/html/'.$imgdir.'/tn-'.$filename;
                   1136:                     if (!-e $output) {
1.9       raeburn  1137:                         my ($width,$height) = &thumb_dimensions();
1.16      raeburn  1138:                         my ($fullwidth,$fullheight) = &check_dimensions($input);
                   1139:                         if ($fullwidth ne '' && $fullheight ne '') {
                   1140:                             if ($fullwidth > $width && $fullheight > $height) { 
                   1141:                                 my $size = $width.'x'.$height;
                   1142:                                 system("convert -sample $size $input $output");
                   1143:                                 $showfile = '/'.$imgdir.'/tn-'.$filename;
                   1144:                             }
                   1145:                         }
1.6       raeburn  1146:                     }
                   1147:                 }
1.16      raeburn  1148:             }
1.6       raeburn  1149:             if ($showfile) {
1.40      raeburn  1150:                 if ($showfile =~ m{^/(adm|res)/}) {
                   1151:                     if ($showfile =~ m{^/res/}) {
                   1152:                         my $local_showfile =
                   1153:                             &Apache::lonnet::filelocation('',$showfile);
                   1154:                         &Apache::lonnet::repcopy($local_showfile);
                   1155:                     }
                   1156:                     $showfile = &Apache::loncommon::lonhttpdurl($showfile);
                   1157:                 }
                   1158:                 if ($imgfile) {
                   1159:                     if ($imgfile  =~ m{^/(adm|res)/}) {
                   1160:                         if ($imgfile =~ m{^/res/}) {
                   1161:                             my $local_imgfile =
                   1162:                                 &Apache::lonnet::filelocation('',$imgfile);
                   1163:                             &Apache::lonnet::repcopy($local_imgfile);
                   1164:                         }
                   1165:                         $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
                   1166:                     } else {
                   1167:                         $fullsize = $imgfile;
                   1168:                     }
                   1169:                 }
1.41      raeburn  1170:                 $datatable .= '<td>';
                   1171:                 if ($img eq 'login') {
1.135     bisitz   1172:                     $datatable .= $login_hdr_pick;
                   1173:                 } 
1.41      raeburn  1174:                 $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
                   1175:                                              $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6       raeburn  1176:             } else {
                   1177:                 $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
                   1178:                               &mt('Upload:');
                   1179:             }
                   1180:         } else {
                   1181:             $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
                   1182:                           &mt('Upload:');
                   1183:         }
1.9       raeburn  1184:         if ($switchserver) {
                   1185:             $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   1186:         } else {
1.135     bisitz   1187:             if ($img ne 'login') { # suppress file selection for Log-in header
                   1188:                 $datatable .='&nbsp;<input type="file" name="'.$role.'_'.$img.'" />';
                   1189:             }
1.9       raeburn  1190:         }
                   1191:         $datatable .= '</td></tr>';
1.6       raeburn  1192:     }
                   1193:     $itemcount ++;
                   1194:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   1195:     $datatable .= '<tr'.$css_class.'>'.
                   1196:                   '<td>'.$choices->{'bgs'}.'</td>';
                   1197:     my $bgs_def;
                   1198:     foreach my $item (@{$bgs}) {
                   1199:         if (!$is_custom->{$item}) {
1.70      raeburn  1200:             $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  1201:         }
                   1202:     }
                   1203:     if ($bgs_def) {
1.8       raeburn  1204:         $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6       raeburn  1205:     } else {
                   1206:         $datatable .= '<td>&nbsp;</td>';
                   1207:     }
                   1208:     $datatable .= '<td class="LC_right_item">'.
                   1209:                   '<table border="0"><tr>';
                   1210:     foreach my $item (@{$bgs}) {
                   1211:         my $link = &color_pick($phase,$role,$item,$choices->{$item},$designs->{'bgs'}{$item});
                   1212:         $datatable .= '<td align="center">'.$link;
                   1213:         if ($designs->{'bgs'}{$item}) {
1.30      raeburn  1214:             $datatable .= '&nbsp;<span id="css_'.$role.'_'.$item.'" style="background-color: '.$designs->{'bgs'}{$item}.';">&nbsp;&nbsp;&nbsp;</span>';
1.6       raeburn  1215:         }
                   1216:         $datatable .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.$designs->{'bgs'}{$item}.
1.41      raeburn  1217:                       '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6       raeburn  1218:     }
                   1219:     $datatable .= '</tr></table></td></tr>';
                   1220:     $itemcount ++;
                   1221:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   1222:     $datatable .= '<tr'.$css_class.'>'.
                   1223:                   '<td>'.$choices->{'links'}.'</td>';
                   1224:     my $links_def;
                   1225:     foreach my $item (@{$links}) {
                   1226:         if (!$is_custom->{$item}) {
1.30      raeburn  1227:             $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  1228:         }
                   1229:     }
                   1230:     if ($links_def) {
1.8       raeburn  1231:         $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6       raeburn  1232:     } else {
                   1233:         $datatable .= '<td>&nbsp;</td>';
                   1234:     }
                   1235:     $datatable .= '<td class="LC_right_item">'.
                   1236:                   '<table border="0"><tr>';
                   1237:     foreach my $item (@{$links}) {
1.30      raeburn  1238:         $datatable .= '<td align="center">'."\n".
                   1239:                       &color_pick($phase,$role,$item,$choices->{$item},
                   1240:                                   $designs->{'links'}{$item});
1.6       raeburn  1241:         if ($designs->{'links'}{$item}) {
1.30      raeburn  1242:             $datatable.='&nbsp;<span id="css_'.$role.'_'.$item.'" style="background-color: '.$designs->{'links'}{$item}.';">&nbsp;&nbsp;&nbsp;</span>';
1.6       raeburn  1243:         }
                   1244:         $datatable .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.$designs->{'links'}{$item}.
                   1245:                       '" /></td>';
                   1246:     }
1.30      raeburn  1247:     $$rowtotal += $itemcount;
1.3       raeburn  1248:     return $datatable;
                   1249: }
                   1250: 
1.70      raeburn  1251: sub logo_display_options {
                   1252:     my ($img,$defaults,$designs) = @_;
                   1253:     my $checkedon;
                   1254:     if (ref($defaults) eq 'HASH') {
                   1255:         if (ref($defaults->{'showlogo'}) eq 'HASH') {
                   1256:             if ($defaults->{'showlogo'}{$img}) {
                   1257:                 $checkedon = 'checked="checked" ';     
                   1258:             }
                   1259:         } 
                   1260:     }
                   1261:     if (ref($designs) eq 'HASH') {
                   1262:         if (ref($designs->{'showlogo'}) eq 'HASH') {
                   1263:             if (defined($designs->{'showlogo'}{$img})) {
                   1264:                 if ($designs->{'showlogo'}{$img} == 0) {
                   1265:                     $checkedon = '';
                   1266:                 } elsif ($designs->{'showlogo'}{$img} == 1) {
                   1267:                     $checkedon = 'checked="checked" ';
                   1268:                 }
                   1269:             }
                   1270:         }
                   1271:     }
                   1272:     return '<br /><label>&nbsp;&nbsp;<input type="checkbox" name="'.
                   1273:            'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
                   1274:            &mt('show').'</label>'."\n";
                   1275: }
                   1276: 
1.41      raeburn  1277: sub login_header_options  {
1.135     bisitz   1278:     my ($img,$role,$defaults,$is_custom,$choices) = @_;
                   1279:     my $output = '';
1.41      raeburn  1280:     if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135     bisitz   1281:         $output .= &mt('Text default(s):').'<br />';
1.41      raeburn  1282:         if (!$is_custom->{'textcol'}) {
                   1283:             $output .= $choices->{'textcol'}.':&nbsp;'.$defaults->{'logintext'}{'textcol'}.
                   1284:                        '&nbsp;&nbsp;&nbsp;';
                   1285:         }
                   1286:         if (!$is_custom->{'bgcol'}) {
                   1287:             $output .= $choices->{'bgcol'}.':&nbsp;'.
                   1288:                        '<span id="css_'.$role.'_font" style="background-color: '.
                   1289:                        $defaults->{'logintext'}{'bgcol'}.';">&nbsp;&nbsp;&nbsp;</span>';
                   1290:         }
                   1291:         $output .= '<br />';
                   1292:     }
                   1293:     $output .='<br />';
                   1294:     return $output;
                   1295: }
                   1296: 
                   1297: sub login_text_colors {
                   1298:     my ($img,$role,$logintext,$phase,$choices,$designs) = @_;
                   1299:     my $color_menu = '<table border="0"><tr>';
                   1300:     foreach my $item (@{$logintext}) {
                   1301:         my $link = &color_pick($phase,$role,$item,$choices->{$item},$designs->{'logintext'}{$item});
                   1302:         $color_menu .= '<td align="center">'.$link;
                   1303:         if ($designs->{'logintext'}{$item}) {
                   1304:             $color_menu .= '&nbsp;<span id="css_'.$role.'_'.$item.'" style="background-color: '.$designs->{'logintext'}{$item}.';">&nbsp;&nbsp;&nbsp;</span>';
                   1305:         }
                   1306:         $color_menu .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.
                   1307:                        $designs->{'logintext'}{$item}.'" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>'.
                   1308:                        '<td>&nbsp;</td>';
                   1309:     }
                   1310:     $color_menu .= '</tr></table><br />';
                   1311:     return $color_menu;
                   1312: }
                   1313: 
                   1314: sub image_changes {
                   1315:     my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
                   1316:     my $output;
1.135     bisitz   1317:     if ($img eq 'login') {
                   1318:             # suppress image for Log-in header
                   1319:     } elsif (!$is_custom) {
1.70      raeburn  1320:         if ($img ne 'domlogo') {
1.41      raeburn  1321:             $output .= &mt('Default image:').'<br />';
                   1322:         } else {
                   1323:             $output .= &mt('Default in use:').'<br />';
                   1324:         }
                   1325:     }
1.135     bisitz   1326:     if ($img eq 'login') { # suppress image for Log-in header
                   1327:         $output .= '<td>'.$logincolors;
1.41      raeburn  1328:     } else {
1.135     bisitz   1329:         if ($img_import) {
                   1330:             $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
                   1331:         }
                   1332:         $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
                   1333:                    $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
                   1334:         if ($is_custom) {
                   1335:             $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
                   1336:                        '<input type="checkbox" name="'.
                   1337:                        $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
                   1338:                        '</label>&nbsp;'.&mt('Replace:').'</span><br />';
                   1339:         } else {
                   1340:             $output .= '<td valign="bottom">'.$logincolors.&mt('Upload:').'<br />';
                   1341:         }
1.41      raeburn  1342:     }
                   1343:     return $output;
                   1344: }
                   1345: 
1.6       raeburn  1346: sub color_pick {
                   1347:     my ($phase,$role,$item,$desc,$curcol) = @_;
                   1348:     my $link = '<a href="javascript:pjump('."'color_custom','".$desc.
                   1349:                "','".$curcol."','".$role.'_'.$item."','parmform.pres','psub'".
                   1350:                ');">'.$desc.'</a>';
                   1351:     return $link;
                   1352: }
                   1353: 
1.3       raeburn  1354: sub print_quotas {
1.86      raeburn  1355:     my ($dom,$settings,$rowtotal,$action) = @_;
                   1356:     my $context;
                   1357:     if ($action eq 'quotas') {
                   1358:         $context = 'tools';
                   1359:     } else {
                   1360:         $context = $action;
                   1361:     }
1.101     raeburn  1362:     my ($datatable,$defaultquota,@usertools,@options,%validations);
1.44      raeburn  1363:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3       raeburn  1364:     my $typecount = 0;
1.101     raeburn  1365:     my ($css_class,%titles);
1.86      raeburn  1366:     if ($context eq 'requestcourses') {
1.98      raeburn  1367:         @usertools = ('official','unofficial','community');
1.106     raeburn  1368:         @options =('norequest','approval','validate','autolimit');
1.101     raeburn  1369:         %validations = &Apache::lonnet::auto_courserequest_checks($dom);
                   1370:         %titles = &courserequest_titles();
1.86      raeburn  1371:     } else {
                   1372:         @usertools = ('aboutme','blog','portfolio');
1.101     raeburn  1373:         %titles = &tool_titles();
1.86      raeburn  1374:     }
1.26      raeburn  1375:     if (ref($types) eq 'ARRAY') {
1.23      raeburn  1376:         foreach my $type (@{$types}) {
1.72      raeburn  1377:             my $currdefquota;
1.86      raeburn  1378:             unless ($context eq 'requestcourses') {
                   1379:                 if (ref($settings) eq 'HASH') {
                   1380:                     if (ref($settings->{defaultquota}) eq 'HASH') {
                   1381:                         $currdefquota = $settings->{defaultquota}->{$type}; 
                   1382:                     } else {
                   1383:                         $currdefquota = $settings->{$type};
                   1384:                     }
1.78      raeburn  1385:                 }
1.72      raeburn  1386:             }
1.3       raeburn  1387:             if (defined($usertypes->{$type})) {
                   1388:                 $typecount ++;
                   1389:                 $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72      raeburn  1390:                 $datatable .= '<tr'.$css_class.'>'.
1.3       raeburn  1391:                               '<td>'.$usertypes->{$type}.'</td>'.
1.72      raeburn  1392:                               '<td class="LC_left_item">';
1.101     raeburn  1393:                 if ($context eq 'requestcourses') {
                   1394:                     $datatable .= '<table><tr>';
                   1395:                 }
                   1396:                 my %cell;  
1.72      raeburn  1397:                 foreach my $item (@usertools) {
1.101     raeburn  1398:                     if ($context eq 'requestcourses') {
                   1399:                         my ($curroption,$currlimit);
                   1400:                         if (ref($settings) eq 'HASH') {
                   1401:                             if (ref($settings->{$item}) eq 'HASH') {
                   1402:                                 $curroption = $settings->{$item}->{$type};
                   1403:                                 if ($curroption =~ /^autolimit=(\d*)$/) {
                   1404:                                     $currlimit = $1; 
                   1405:                                 }
                   1406:                             }
                   1407:                         }
                   1408:                         if (!$curroption) {
                   1409:                             $curroption = 'norequest';
                   1410:                         }
                   1411:                         $datatable .= '<th>'.$titles{$item}.'</th>';
                   1412:                         foreach my $option (@options) {
                   1413:                             my $val = $option;
                   1414:                             if ($option eq 'norequest') {
                   1415:                                 $val = 0;  
                   1416:                             }
                   1417:                             if ($option eq 'validate') {
                   1418:                                 my $canvalidate = 0;
                   1419:                                 if (ref($validations{$item}) eq 'HASH') { 
                   1420:                                     if ($validations{$item}{$type}) {
                   1421:                                         $canvalidate = 1;
                   1422:                                     }
                   1423:                                 }
                   1424:                                 next if (!$canvalidate);
                   1425:                             }
                   1426:                             my $checked = '';
                   1427:                             if ($option eq $curroption) {
                   1428:                                 $checked = ' checked="checked"';
                   1429:                             } elsif ($option eq 'autolimit') {
                   1430:                                 if ($curroption =~ /^autolimit/) {
                   1431:                                     $checked = ' checked="checked"';
                   1432:                                 }                       
                   1433:                             } 
                   1434:                             $cell{$item} .= '<span class="LC_nobreak"><label>'.
                   1435:                                   '<input type="radio" name="crsreq_'.$item.
                   1436:                                   '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127     raeburn  1437:                                   $titles{$option}.'</label>';
1.101     raeburn  1438:                             if ($option eq 'autolimit') {
1.127     raeburn  1439:                                 $cell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
1.101     raeburn  1440:                                                 $item.'_limit_'.$type.'" size="1" '.
1.103     raeburn  1441:                                                 'value="'.$currlimit.'" />';
1.101     raeburn  1442:                             }
1.127     raeburn  1443:                             $cell{$item} .= '</span> ';
1.103     raeburn  1444:                             if ($option eq 'autolimit') {
1.127     raeburn  1445:                                 $cell{$item} .= $titles{'unlimited'};
1.103     raeburn  1446:                             }
1.101     raeburn  1447:                         }
                   1448:                     } else {
                   1449:                         my $checked = 'checked="checked" ';
                   1450:                         if (ref($settings) eq 'HASH') {
                   1451:                             if (ref($settings->{$item}) eq 'HASH') {
                   1452:                                 if ($settings->{$item}->{$type} == 0) {
                   1453:                                     $checked = '';
                   1454:                                 } elsif ($settings->{$item}->{$type} == 1) {
                   1455:                                     $checked =  'checked="checked" ';
                   1456:                                 }
1.78      raeburn  1457:                             }
1.72      raeburn  1458:                         }
1.101     raeburn  1459:                         $datatable .= '<span class="LC_nobreak"><label>'.
                   1460:                                       '<input type="checkbox" name="'.$context.'_'.$item.
                   1461:                                       '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
                   1462:                                       '</label></span>&nbsp; ';
1.72      raeburn  1463:                     }
1.101     raeburn  1464:                 }
                   1465:                 if ($context eq 'requestcourses') {
                   1466:                     $datatable .= '</tr><tr>';
                   1467:                     foreach my $item (@usertools) {
1.106     raeburn  1468:                         $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';  
1.101     raeburn  1469:                     }
                   1470:                     $datatable .= '</tr></table>';
1.72      raeburn  1471:                 }
1.86      raeburn  1472:                 $datatable .= '</td>';
                   1473:                 unless ($context eq 'requestcourses') {
                   1474:                     $datatable .= 
                   1475:                               '<td class="LC_right_item"><span class="LC_nobreak">'.
1.3       raeburn  1476:                               '<input type="text" name="quota_'.$type.
1.72      raeburn  1477:                               '" value="'.$currdefquota.
1.86      raeburn  1478:                               '" size="5" /> Mb</span></td>';
                   1479:                 }
                   1480:                 $datatable .= '</tr>';
1.3       raeburn  1481:             }
                   1482:         }
                   1483:     }
1.86      raeburn  1484:     unless ($context eq 'requestcourses') {
                   1485:         $defaultquota = '20';
                   1486:         if (ref($settings) eq 'HASH') {
                   1487:             if (ref($settings->{'defaultquota'}) eq 'HASH') {
                   1488:                 $defaultquota = $settings->{'defaultquota'}->{'default'};
                   1489:             } elsif (defined($settings->{'default'})) {
                   1490:                 $defaultquota = $settings->{'default'};
                   1491:             }
1.3       raeburn  1492:         }
                   1493:     }
                   1494:     $typecount ++;
                   1495:     $css_class = $typecount%2?' class="LC_odd_row"':'';
                   1496:     $datatable .= '<tr'.$css_class.'>'.
1.26      raeburn  1497:                   '<td>'.$othertitle.'</td>'.
1.72      raeburn  1498:                   '<td class="LC_left_item">';
1.101     raeburn  1499:     if ($context eq 'requestcourses') {
                   1500:         $datatable .= '<table><tr>';
                   1501:     }
                   1502:     my %defcell;
1.72      raeburn  1503:     foreach my $item (@usertools) {
1.101     raeburn  1504:         if ($context eq 'requestcourses') {
                   1505:             my ($curroption,$currlimit);
                   1506:             if (ref($settings) eq 'HASH') {
                   1507:                 if (ref($settings->{$item}) eq 'HASH') {
                   1508:                     $curroption = $settings->{$item}->{'default'};
                   1509:                     if ($curroption =~ /^autolimit=(\d*)$/) {
                   1510:                         $currlimit = $1;
                   1511:                     }
                   1512:                 }
                   1513:             }
                   1514:             if (!$curroption) {
                   1515:                 $curroption = 'norequest';
                   1516:             }
                   1517:             $datatable .= '<th>'.$titles{$item}.'</th>';
                   1518:             foreach my $option (@options) {
                   1519:                 my $val = $option;
                   1520:                 if ($option eq 'norequest') {
                   1521:                     $val = 0;
                   1522:                 }
                   1523:                 if ($option eq 'validate') {
                   1524:                     my $canvalidate = 0;
                   1525:                     if (ref($validations{$item}) eq 'HASH') {
                   1526:                         if ($validations{$item}{'default'}) {
                   1527:                             $canvalidate = 1;
                   1528:                         }
                   1529:                     }
                   1530:                     next if (!$canvalidate);
                   1531:                 }
                   1532:                 my $checked = '';
                   1533:                 if ($option eq $curroption) {
                   1534:                     $checked = ' checked="checked"';
                   1535:                 } elsif ($option eq 'autolimit') {
                   1536:                     if ($curroption =~ /^autolimit/) {
                   1537:                         $checked = ' checked="checked"';
                   1538:                     }
                   1539:                 }
                   1540:                 $defcell{$item} .= '<span class="LC_nobreak"><label>'.
                   1541:                                   '<input type="radio" name="crsreq_'.$item.
                   1542:                                   '_default" value="'.$val.'"'.$checked.' />'.
                   1543:                                   $titles{$option}.'</label>';
                   1544:                 if ($option eq 'autolimit') {
1.127     raeburn  1545:                     $defcell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
1.101     raeburn  1546:                                        $item.'_limit_default" size="1" '.
                   1547:                                        'value="'.$currlimit.'" />';
                   1548:                 }
1.127     raeburn  1549:                 $defcell{$item} .= '</span> ';
1.104     raeburn  1550:                 if ($option eq 'autolimit') {
1.127     raeburn  1551:                     $defcell{$item} .= $titles{'unlimited'};
1.104     raeburn  1552:                 }
1.101     raeburn  1553:             }
                   1554:         } else {
                   1555:             my $checked = 'checked="checked" ';
                   1556:             if (ref($settings) eq 'HASH') {
                   1557:                 if (ref($settings->{$item}) eq 'HASH') {
                   1558:                     if ($settings->{$item}->{'default'} == 0) {
                   1559:                         $checked = '';
                   1560:                     } elsif ($settings->{$item}->{'default'} == 1) {
                   1561:                         $checked = 'checked="checked" ';
                   1562:                     }
1.78      raeburn  1563:                 }
1.72      raeburn  1564:             }
1.101     raeburn  1565:             $datatable .= '<span class="LC_nobreak"><label>'.
                   1566:                           '<input type="checkbox" name="'.$context.'_'.$item.
                   1567:                           '" value="default" '.$checked.'/>'.$titles{$item}.
                   1568:                           '</label></span>&nbsp; ';
                   1569:         }
                   1570:     }
                   1571:     if ($context eq 'requestcourses') {
                   1572:         $datatable .= '</tr><tr>';
                   1573:         foreach my $item (@usertools) {
1.106     raeburn  1574:             $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72      raeburn  1575:         }
1.101     raeburn  1576:         $datatable .= '</tr></table>';
1.72      raeburn  1577:     }
1.86      raeburn  1578:     $datatable .= '</td>';
                   1579:     unless ($context eq 'requestcourses') {
                   1580:         $datatable .= '<td class="LC_right_item"><span class="LC_nobreak">'.
                   1581:                       '<input type="text" name="defaultquota" value="'.
                   1582:                       $defaultquota.'" size="5" /> Mb</span></td>';
                   1583:     }
                   1584:     $datatable .= '</tr>';
1.72      raeburn  1585:     $typecount ++;
                   1586:     $css_class = $typecount%2?' class="LC_odd_row"':'';
                   1587:     $datatable .= '<tr'.$css_class.'>'.
1.104     raeburn  1588:                   '<td>'.&mt('LON-CAPA Advanced Users').' ';
                   1589:     if ($context eq 'requestcourses') {
1.109     raeburn  1590:         $datatable .= &mt('(overrides affiliation, if set)').
                   1591:                       '</td>'.
                   1592:                       '<td class="LC_left_item">'.
                   1593:                       '<table><tr>';
1.101     raeburn  1594:     } else {
1.109     raeburn  1595:         $datatable .= &mt('(overrides affiliation, if checked)').
                   1596:                       '</td>'.
                   1597:                       '<td class="LC_left_item" colspan="2">'.
                   1598:                       '<br />';
1.101     raeburn  1599:     }
                   1600:     my %advcell;
1.72      raeburn  1601:     foreach my $item (@usertools) {
1.101     raeburn  1602:         if ($context eq 'requestcourses') {
                   1603:             my ($curroption,$currlimit);
                   1604:             if (ref($settings) eq 'HASH') {
                   1605:                 if (ref($settings->{$item}) eq 'HASH') {
                   1606:                     $curroption = $settings->{$item}->{'_LC_adv'};
                   1607:                     if ($curroption =~ /^autolimit=(\d*)$/) {
                   1608:                         $currlimit = $1;
                   1609:                     }
                   1610:                 }
                   1611:             }
                   1612:             $datatable .= '<th>'.$titles{$item}.'</th>';
1.104     raeburn  1613:             my $checked = '';
                   1614:             if ($curroption eq '') {
                   1615:                 $checked = ' checked="checked"';
                   1616:             }
                   1617:             $advcell{$item} .= '<span class="LC_nobreak"><label>'.
                   1618:                                '<input type="radio" name="crsreq_'.$item.
                   1619:                                '__LC_adv" value=""'.$checked.' />'.
                   1620:                                &mt('No override set').'</label></span>&nbsp; ';
1.101     raeburn  1621:             foreach my $option (@options) {
                   1622:                 my $val = $option;
                   1623:                 if ($option eq 'norequest') {
                   1624:                     $val = 0;
                   1625:                 }
                   1626:                 if ($option eq 'validate') {
                   1627:                     my $canvalidate = 0;
                   1628:                     if (ref($validations{$item}) eq 'HASH') {
                   1629:                         if ($validations{$item}{'_LC_adv'}) {
                   1630:                             $canvalidate = 1;
                   1631:                         }
                   1632:                     }
                   1633:                     next if (!$canvalidate);
                   1634:                 }
                   1635:                 my $checked = '';
1.104     raeburn  1636:                 if ($val eq $curroption) {
1.101     raeburn  1637:                     $checked = ' checked="checked"';
                   1638:                 } elsif ($option eq 'autolimit') {
                   1639:                     if ($curroption =~ /^autolimit/) {
                   1640:                         $checked = ' checked="checked"';
                   1641:                     }
                   1642:                 }
                   1643:                 $advcell{$item} .= '<span class="LC_nobreak"><label>'.
                   1644:                                   '<input type="radio" name="crsreq_'.$item.
                   1645:                                   '__LC_adv" value="'.$val.'"'.$checked.' />'.
                   1646:                                   $titles{$option}.'</label>';
                   1647:                 if ($option eq 'autolimit') {
1.127     raeburn  1648:                     $advcell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
1.101     raeburn  1649:                                        $item.'_limit__LC_adv" size="1" '.
                   1650:                                        'value="'.$currlimit.'" />';
                   1651:                 }
1.127     raeburn  1652:                 $advcell{$item} .= '</span> ';
1.104     raeburn  1653:                 if ($option eq 'autolimit') {
1.127     raeburn  1654:                     $advcell{$item} .= $titles{'unlimited'};
1.104     raeburn  1655:                 }
1.101     raeburn  1656:             }
                   1657:         } else {
                   1658:             my $checked = 'checked="checked" ';
                   1659:             if (ref($settings) eq 'HASH') {
                   1660:                 if (ref($settings->{$item}) eq 'HASH') {
                   1661:                     if ($settings->{$item}->{'_LC_adv'} == 0) {
                   1662:                         $checked = '';
                   1663:                     } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
                   1664:                         $checked = 'checked="checked" ';
                   1665:                     }
1.79      raeburn  1666:                 }
1.72      raeburn  1667:             }
1.101     raeburn  1668:             $datatable .= '<span class="LC_nobreak"><label>'.
                   1669:                           '<input type="checkbox" name="'.$context.'_'.$item.
                   1670:                           '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
                   1671:                           '</label></span>&nbsp; ';
                   1672:         }
                   1673:     }
                   1674:     if ($context eq 'requestcourses') {
                   1675:         $datatable .= '</tr><tr>';
                   1676:         foreach my $item (@usertools) {
1.106     raeburn  1677:             $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72      raeburn  1678:         }
1.101     raeburn  1679:         $datatable .= '</tr></table>';
1.72      raeburn  1680:     }
1.98      raeburn  1681:     $datatable .= '</td></tr>';
1.30      raeburn  1682:     $$rowtotal += $typecount;
1.3       raeburn  1683:     return $datatable;
                   1684: }
                   1685: 
1.102     raeburn  1686: sub print_courserequestmail {
                   1687:     my ($dom,$settings,$rowtotal) = @_;
1.104     raeburn  1688:     my ($now,$datatable,%dompersonnel,@domcoord,@currapproval,$rows);
1.102     raeburn  1689:     $now = time;
                   1690:     $rows = 0;
                   1691:     %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
                   1692:     foreach my $server (keys(%dompersonnel)) {
                   1693:         foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
                   1694:             my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
                   1695:             if (!grep(/^$uname:$udom$/,@domcoord)) {
                   1696:                 push(@domcoord,$uname.':'.$udom);
                   1697:             }
                   1698:         }
                   1699:     }
                   1700:     if (ref($settings) eq 'HASH') {
                   1701:         if (ref($settings->{'notify'}) eq 'HASH') {
                   1702:             if ($settings->{'notify'}{'approval'} ne '') {
1.104     raeburn  1703:                @currapproval = split(',',$settings->{'notify'}{'approval'});
1.102     raeburn  1704:             }
                   1705:         }
                   1706:     }
1.104     raeburn  1707:     if (@currapproval) {
                   1708:         foreach my $dc (@currapproval) {
1.102     raeburn  1709:             unless (grep(/^\Q$dc\E$/,@domcoord)) {
                   1710:                 push(@domcoord,$dc);
                   1711:             }
                   1712:         }
                   1713:     }
                   1714:     @domcoord = sort(@domcoord);
                   1715:     my $numinrow = 4;
                   1716:     my $numdc = @domcoord;
                   1717:     my $css_class = 'class="LC_odd_row"';
                   1718:     $datatable = '<tr'.$css_class.'>'.
                   1719:                  ' <td>'.&mt('Receive notification of course requests requiring approval.').
                   1720:                  ' </td>'.
                   1721:                  ' <td class="LC_left_item">';
                   1722:     if (@domcoord > 0) {
                   1723:         $datatable .= '<table>';
                   1724:         for (my $i=0; $i<$numdc; $i++) {
                   1725:             my $rem = $i%($numinrow);
                   1726:             if ($rem == 0) {
                   1727:                 if ($i > 0) {
                   1728:                     $datatable .= '</tr>';
                   1729:                 }
                   1730:                 $datatable .= '<tr>';
                   1731:                 $rows ++;
                   1732:             }
                   1733:             my $check = ' ';
1.104     raeburn  1734:             if (grep(/^\Q$domcoord[$i]\E$/,@currapproval)) {
1.102     raeburn  1735:                 $check = ' checked="checked" ';
                   1736:             }
                   1737:             my ($uname,$udom) = split(':',$domcoord[$i]);
                   1738:             my $fullname = &Apache::loncommon::plainname($uname,$udom);
                   1739:             if ($i == $numdc-1) {
                   1740:                 my $colsleft = $numinrow-$rem;
                   1741:                 if ($colsleft > 1) {
                   1742:                     $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
                   1743:                 } else {
                   1744:                     $datatable .= '<td class="LC_left_item">';
                   1745:                 }
                   1746:             } else {
                   1747:                 $datatable .= '<td class="LC_left_item">';
                   1748:             }
                   1749:             $datatable .= '<span class="LC_nobreak"><label>'.
                   1750:                           '<input type="checkbox" name="reqapprovalnotify" '.
                   1751:                           'value="'.$domcoord[$i].'"'.$check.'/>'.
                   1752:                           $fullname.'</label></span></td>';
                   1753:         }
                   1754:         $datatable .= '</tr></table>';
                   1755:     } else {
                   1756:         $datatable .= &mt('There are no active Domain Coordinators');
                   1757:         $rows ++;
                   1758:     }
                   1759:     $datatable .='</td></tr>';
                   1760:     $$rowtotal += $rows;
                   1761:     return $datatable;
                   1762: }
                   1763: 
1.3       raeburn  1764: sub print_autoenroll {
1.30      raeburn  1765:     my ($dom,$settings,$rowtotal) = @_;
1.3       raeburn  1766:     my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.129     raeburn  1767:     my ($defdom,$runon,$runoff,$coownerson,$coownersoff);
1.3       raeburn  1768:     if (ref($settings) eq 'HASH') {
                   1769:         if (exists($settings->{'run'})) {
                   1770:             if ($settings->{'run'} eq '0') {
                   1771:                 $runoff = ' checked="checked" ';
                   1772:                 $runon = ' ';
                   1773:             } else {
                   1774:                 $runon = ' checked="checked" ';
                   1775:                 $runoff = ' ';
                   1776:             }
                   1777:         } else {
                   1778:             if ($autorun) {
                   1779:                 $runon = ' checked="checked" ';
                   1780:                 $runoff = ' ';
                   1781:             } else {
                   1782:                 $runoff = ' checked="checked" ';
                   1783:                 $runon = ' ';
                   1784:             }
                   1785:         }
1.129     raeburn  1786:         if (exists($settings->{'co-owners'})) {
                   1787:             if ($settings->{'co-owners'} eq '0') {
                   1788:                 $coownersoff = ' checked="checked" ';
                   1789:                 $coownerson = ' ';
                   1790:             } else {
                   1791:                 $coownerson = ' checked="checked" ';
                   1792:                 $coownersoff = ' ';
                   1793:             }
                   1794:         } else {
                   1795:             $coownersoff = ' checked="checked" ';
                   1796:             $coownerson = ' ';
                   1797:         }
1.3       raeburn  1798:         if (exists($settings->{'sender_domain'})) {
                   1799:             $defdom = $settings->{'sender_domain'};
                   1800:         }
1.14      raeburn  1801:     } else {
                   1802:         if ($autorun) {
                   1803:             $runon = ' checked="checked" ';
                   1804:             $runoff = ' ';
                   1805:         } else {
                   1806:             $runoff = ' checked="checked" ';
                   1807:             $runon = ' ';
                   1808:         }
1.3       raeburn  1809:     }
                   1810:     my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39      raeburn  1811:     my $notif_sender;
                   1812:     if (ref($settings) eq 'HASH') {
                   1813:         $notif_sender = $settings->{'sender_uname'};
                   1814:     }
1.3       raeburn  1815:     my $datatable='<tr class="LC_odd_row">'.
                   1816:                   '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8       raeburn  1817:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3       raeburn  1818:                   '<input type="radio" name="autoenroll_run"'.
1.8       raeburn  1819:                   $runon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   1820:                   '<label><input type="radio" name="autoenroll_run"'.
1.14      raeburn  1821:                   $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3       raeburn  1822:                   '</tr><tr>'.
                   1823:                   '<td>'.&mt('Notification messages - sender').
1.8       raeburn  1824:                   '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3       raeburn  1825:                   &mt('username').':&nbsp;'.
                   1826:                   '<input type="text" name="sender_uname" value="'.
1.39      raeburn  1827:                   $notif_sender.'" size="10" />&nbsp;&nbsp;'.&mt('domain').
1.129     raeburn  1828:                   ':&nbsp;'.$domform.'</span></td></tr>'.
                   1829:                   '<tr class="LC_odd_row">'.
                   1830:                   '<td>'.&mt('Automatically assign co-ownership').'</td>'.
                   1831:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   1832:                   '<input type="radio" name="autoassign_coowners"'.
                   1833:                   $coownerson.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   1834:                   '<label><input type="radio" name="autoassign_coowners"'.
                   1835:                   $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
                   1836:                   '</tr>';
                   1837:     $$rowtotal += 3;
1.3       raeburn  1838:     return $datatable;
                   1839: }
                   1840: 
                   1841: sub print_autoupdate {
1.30      raeburn  1842:     my ($position,$dom,$settings,$rowtotal) = @_;
1.3       raeburn  1843:     my $datatable;
                   1844:     if ($position eq 'top') {
                   1845:         my $updateon = ' ';
                   1846:         my $updateoff = ' checked="checked" ';
                   1847:         my $classlistson = ' ';
                   1848:         my $classlistsoff = ' checked="checked" ';
                   1849:         if (ref($settings) eq 'HASH') {
                   1850:             if ($settings->{'run'} eq '1') {
                   1851:                 $updateon = $updateoff;
                   1852:                 $updateoff = ' ';
                   1853:             }
                   1854:             if ($settings->{'classlists'} eq '1') {
                   1855:                 $classlistson = $classlistsoff;
                   1856:                 $classlistsoff = ' ';
                   1857:             }
                   1858:         }
                   1859:         my %title = (
                   1860:                    run => 'Auto-update active?',
                   1861:                    classlists => 'Update information in classlists?',
                   1862:                     );
                   1863:         $datatable = '<tr class="LC_odd_row">'. 
                   1864:                   '<td>'.&mt($title{'run'}).'</td>'.
1.8       raeburn  1865:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3       raeburn  1866:                   '<input type="radio" name="autoupdate_run"'.
1.8       raeburn  1867:                   $updateon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   1868:                   '<label><input type="radio" name="autoupdate_run"'.
                   1869:                   $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3       raeburn  1870:                   '</tr><tr>'.
                   1871:                   '<td>'.&mt($title{'classlists'}).'</td>'.
1.8       raeburn  1872:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
                   1873:                   '<label><input type="radio" name="classlists"'.
                   1874:                   $classlistson.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   1875:                   '<label><input type="radio" name="classlists"'.
                   1876:                   $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3       raeburn  1877:                   '</tr>';
1.30      raeburn  1878:         $$rowtotal += 2;
1.131     raeburn  1879:     } elsif ($position eq 'middle') {
                   1880:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   1881:         my $numinrow = 3;
                   1882:         my $locknamesettings;
                   1883:         $datatable .= &insttypes_row($settings,$types,$usertypes,
                   1884:                                      $dom,$numinrow,$othertitle,
                   1885:                                     'lockablenames');
                   1886:         $$rowtotal ++;
1.3       raeburn  1887:     } else {
1.44      raeburn  1888:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132     raeburn  1889:         my @fields = ('lastname','firstname','middlename','generation',
1.20      raeburn  1890:                       'permanentemail','id');
1.33      raeburn  1891:         my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3       raeburn  1892:         my $numrows = 0;
1.26      raeburn  1893:         if (ref($types) eq 'ARRAY') {
                   1894:             if (@{$types} > 0) {
                   1895:                 $datatable = 
                   1896:                     &usertype_update_row($settings,$usertypes,\%fieldtitles,
                   1897:                                          \@fields,$types,\$numrows);
1.30      raeburn  1898:                     $$rowtotal += @{$types}; 
1.26      raeburn  1899:             }
1.3       raeburn  1900:         }
                   1901:         $datatable .= 
                   1902:             &usertype_update_row($settings,{'default' => $othertitle},
                   1903:                                  \%fieldtitles,\@fields,['default'],
                   1904:                                  \$numrows);
1.30      raeburn  1905:         $$rowtotal ++;     
1.3       raeburn  1906:     }
                   1907:     return $datatable;
                   1908: }
                   1909: 
1.125     raeburn  1910: sub print_autocreate {
                   1911:     my ($dom,$settings,$rowtotal) = @_;
                   1912:     my (%createon,%createoff);
                   1913:     my $curr_dc;
                   1914:     my @types = ('xml','req');
                   1915:     if (ref($settings) eq 'HASH') {
                   1916:         foreach my $item (@types) {
                   1917:             $createoff{$item} = ' checked="checked" ';
                   1918:             $createon{$item} = ' ';
                   1919:             if (exists($settings->{$item})) {
                   1920:                 if ($settings->{$item}) {
                   1921:                     $createon{$item} = ' checked="checked" ';
                   1922:                     $createoff{$item} = ' ';
                   1923:                 }
                   1924:             }
                   1925:         }
                   1926:         $curr_dc = $settings->{'xmldc'};
                   1927:     } else {
                   1928:         foreach my $item (@types) {
                   1929:             $createoff{$item} = ' checked="checked" ';
                   1930:             $createon{$item} = ' ';
                   1931:         }
                   1932:     }
                   1933:     $$rowtotal += 2;
                   1934:     my $datatable='<tr class="LC_odd_row">'.
                   1935:                   '<td>'.&mt('Create pending official courses from XML files').'</td>'.
                   1936:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   1937:                   '<input type="radio" name="autocreate_xml"'.
                   1938:                   $createon{'xml'}.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   1939:                   '<label><input type="radio" name="autocreate_xml"'.
1.143     raeburn  1940:                   $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
                   1941:                   '</td></tr><tr>'.
                   1942:                   '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
                   1943:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   1944:                   '<input type="radio" name="autocreate_req"'.
                   1945:                   $createon{'req'}.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   1946:                   '<label><input type="radio" name="autocreate_req"'.
                   1947:                   $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.125     raeburn  1948:     my ($numdc,$dctable) = &active_dc_picker($dom,$curr_dc);
                   1949:     if ($numdc > 1) {
1.143     raeburn  1950:         $datatable .= '</td></tr><tr class="LC_odd_row"><td>'.
                   1951:                       &mt('Course creation processed as: (choose Dom. Coord.)').
                   1952:                       '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.125     raeburn  1953:         $$rowtotal ++ ;
                   1954:     } else {
1.143     raeburn  1955:         $datatable .= $dctable.'</td></tr>';
1.125     raeburn  1956:     }
                   1957:     return $datatable;
                   1958: }
                   1959: 
1.23      raeburn  1960: sub print_directorysrch {
1.30      raeburn  1961:     my ($dom,$settings,$rowtotal) = @_;
1.23      raeburn  1962:     my $srchon = ' ';
                   1963:     my $srchoff = ' checked="checked" ';
1.25      raeburn  1964:     my ($exacton,$containson,$beginson);
1.24      raeburn  1965:     my $localon = ' ';
                   1966:     my $localoff = ' checked="checked" ';
1.23      raeburn  1967:     if (ref($settings) eq 'HASH') {
                   1968:         if ($settings->{'available'} eq '1') {
                   1969:             $srchon = $srchoff;
                   1970:             $srchoff = ' ';
                   1971:         }
1.24      raeburn  1972:         if ($settings->{'localonly'} eq '1') {
                   1973:             $localon = $localoff;
                   1974:             $localoff = ' ';
                   1975:         }
1.25      raeburn  1976:         if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
                   1977:             foreach my $type (@{$settings->{'searchtypes'}}) {
                   1978:                 if ($type eq 'exact') {
                   1979:                     $exacton = ' checked="checked" ';
                   1980:                 } elsif ($type eq 'contains') {
                   1981:                     $containson = ' checked="checked" ';
                   1982:                 } elsif ($type eq 'begins') {
                   1983:                     $beginson = ' checked="checked" ';
                   1984:                 }
                   1985:             }
                   1986:         } else {
                   1987:             if ($settings->{'searchtypes'} eq 'exact') {
                   1988:                 $exacton = ' checked="checked" ';
                   1989:             } elsif ($settings->{'searchtypes'} eq 'contains') {
                   1990:                 $containson = ' checked="checked" ';
                   1991:             } elsif ($settings->{'searchtypes'} eq 'specify') {
                   1992:                 $exacton = ' checked="checked" ';
                   1993:                 $containson = ' checked="checked" ';
                   1994:             }
1.23      raeburn  1995:         }
                   1996:     }
                   1997:     my ($searchtitles,$titleorder) = &sorted_searchtitles();
1.45      raeburn  1998:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23      raeburn  1999: 
                   2000:     my $numinrow = 4;
1.26      raeburn  2001:     my $cansrchrow = 0;
1.23      raeburn  2002:     my $datatable='<tr class="LC_odd_row">'.
1.30      raeburn  2003:                   '<td colspan="2"><span class ="LC_nobreak">'.&mt('Directory search available?').'</span></td>'.
1.23      raeburn  2004:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   2005:                   '<input type="radio" name="dirsrch_available"'.
                   2006:                   $srchon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   2007:                   '<label><input type="radio" name="dirsrch_available"'.
                   2008:                   $srchoff.' value="0" />'.&mt('No').'</label></span></td>'.
                   2009:                   '</tr><tr>'.
1.30      raeburn  2010:                   '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search?').'</span></td>'.
1.24      raeburn  2011:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   2012:                   '<input type="radio" name="dirsrch_localonly"'.
                   2013:                   $localoff.' value="0" />'.&mt('Yes').'</label>&nbsp;'.
                   2014:                   '<label><input type="radio" name="dirsrch_localonly"'.
                   2015:                   $localon.' value="1" />'.&mt('No').'</label></span></td>'.
1.25      raeburn  2016:                   '</tr>';
1.30      raeburn  2017:     $$rowtotal += 2;
1.26      raeburn  2018:     if (ref($usertypes) eq 'HASH') {
                   2019:         if (keys(%{$usertypes}) > 0) {
1.93      raeburn  2020:             $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
                   2021:                                          $numinrow,$othertitle,'cansearch');
1.26      raeburn  2022:             $cansrchrow = 1;
                   2023:         }
                   2024:     }
                   2025:     if ($cansrchrow) {
1.30      raeburn  2026:         $$rowtotal ++;
1.26      raeburn  2027:         $datatable .= '<tr>';
                   2028:     } else {
                   2029:         $datatable .= '<tr class="LC_odd_row">';
                   2030:     }
1.30      raeburn  2031:     $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
                   2032:                   '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
1.25      raeburn  2033:     foreach my $title (@{$titleorder}) {
                   2034:         if (defined($searchtitles->{$title})) {
                   2035:             my $check = ' ';
1.93      raeburn  2036:             if (ref($settings) eq 'HASH') {
1.39      raeburn  2037:                 if (ref($settings->{'searchby'}) eq 'ARRAY') {
                   2038:                     if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
                   2039:                         $check = ' checked="checked" ';
                   2040:                     }
1.25      raeburn  2041:                 }
                   2042:             }
                   2043:             $datatable .= '<td class="LC_left_item">'.
                   2044:                           '<span class="LC_nobreak"><label>'.
                   2045:                           '<input type="checkbox" name="searchby" '.
                   2046:                           'value="'.$title.'"'.$check.'/>'.
                   2047:                           $searchtitles->{$title}.'</label></span></td>';
                   2048:         }
                   2049:     }
1.26      raeburn  2050:     $datatable .= '</tr></table></td></tr>';
1.30      raeburn  2051:     $$rowtotal ++;
1.26      raeburn  2052:     if ($cansrchrow) {
                   2053:         $datatable .= '<tr class="LC_odd_row">';
                   2054:     } else {
                   2055:         $datatable .= '<tr>';
                   2056:     }
1.30      raeburn  2057:     $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.   
1.26      raeburn  2058:                   '<td class="LC_left_item" colspan="2">'.
1.25      raeburn  2059:                   '<span class="LC_nobreak"><label>'.
                   2060:                   '<input type="checkbox" name="searchtypes" '.
                   2061:                   $exacton.' value="exact" />'.&mt('Exact match').
                   2062:                   '</label>&nbsp;'.
                   2063:                   '<label><input type="checkbox" name="searchtypes" '.
                   2064:                   $beginson.' value="begins" />'.&mt('Begins with').
                   2065:                   '</label>&nbsp;'.
                   2066:                   '<label><input type="checkbox" name="searchtypes" '.
                   2067:                   $containson.' value="contains" />'.&mt('Contains').
                   2068:                   '</label></span></td></tr>';
1.30      raeburn  2069:     $$rowtotal ++;
1.25      raeburn  2070:     return $datatable;
                   2071: }
                   2072: 
1.28      raeburn  2073: sub print_contacts {
1.30      raeburn  2074:     my ($dom,$settings,$rowtotal) = @_;
1.28      raeburn  2075:     my $datatable;
                   2076:     my @contacts = ('adminemail','supportemail');
1.134     raeburn  2077:     my (%checked,%to,%otheremails,%bccemails);
1.102     raeburn  2078:     my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail',
                   2079:                     'requestsmail');
1.28      raeburn  2080:     foreach my $type (@mailings) {
                   2081:         $otheremails{$type} = '';
                   2082:     }
1.134     raeburn  2083:     $bccemails{'helpdeskmail'} = '';
1.28      raeburn  2084:     if (ref($settings) eq 'HASH') {
                   2085:         foreach my $item (@contacts) {
                   2086:             if (exists($settings->{$item})) {
                   2087:                 $to{$item} = $settings->{$item};
                   2088:             }
                   2089:         }
                   2090:         foreach my $type (@mailings) {
                   2091:             if (exists($settings->{$type})) {
                   2092:                 if (ref($settings->{$type}) eq 'HASH') {
                   2093:                     foreach my $item (@contacts) {
                   2094:                         if ($settings->{$type}{$item}) {
                   2095:                             $checked{$type}{$item} = ' checked="checked" ';
                   2096:                         }
                   2097:                     }
                   2098:                     $otheremails{$type} = $settings->{$type}{'others'};
1.134     raeburn  2099:                     if ($type eq 'helpdeskmail') {
                   2100:                         $bccemails{$type} = $settings->{$type}{'bcc'};
                   2101:                     }
1.28      raeburn  2102:                 }
1.89      raeburn  2103:             } elsif ($type eq 'lonstatusmail') {
                   2104:                 $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.28      raeburn  2105:             }
                   2106:         }
                   2107:     } else {
                   2108:         $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
                   2109:         $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
                   2110:         $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
                   2111:         $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.89      raeburn  2112:         $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
                   2113:         $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" '; 
1.102     raeburn  2114:         $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
1.28      raeburn  2115:     }
                   2116:     my ($titles,$short_titles) = &contact_titles();
                   2117:     my $rownum = 0;
                   2118:     my $css_class;
                   2119:     foreach my $item (@contacts) {
1.69      raeburn  2120:         $rownum ++;
                   2121:         $css_class = $rownum%2?' class="LC_odd_row"':'';
1.30      raeburn  2122:         $datatable .= '<tr'.$css_class.'>'. 
                   2123:                   '<td><span class="LC_nobreak">'.$titles->{$item}.
                   2124:                   '</span></td><td class="LC_right_item">'.
1.28      raeburn  2125:                   '<input type="text" name="'.$item.'" value="'.
                   2126:                   $to{$item}.'" /></td></tr>';
                   2127:     }
                   2128:     foreach my $type (@mailings) {
1.69      raeburn  2129:         $rownum ++;
                   2130:         $css_class = $rownum%2?' class="LC_odd_row"':'';
1.28      raeburn  2131:         $datatable .= '<tr'.$css_class.'>'.
1.30      raeburn  2132:                       '<td><span class="LC_nobreak">'.
                   2133:                       $titles->{$type}.': </span></td>'.
1.28      raeburn  2134:                       '<td class="LC_left_item">'.
                   2135:                       '<span class="LC_nobreak">';
                   2136:         foreach my $item (@contacts) {
                   2137:             $datatable .= '<label>'.
                   2138:                           '<input type="checkbox" name="'.$type.'"'.
                   2139:                           $checked{$type}{$item}.
                   2140:                           ' value="'.$item.'" />'.$short_titles->{$item}.
                   2141:                           '</label>&nbsp;';
                   2142:         }
                   2143:         $datatable .= '</span><br />'.&mt('Others').':&nbsp;&nbsp;'.
                   2144:                       '<input type="text" name="'.$type.'_others" '.
1.134     raeburn  2145:                       'value="'.$otheremails{$type}.'"  />';
                   2146:         if ($type eq 'helpdeskmail') {
1.136     raeburn  2147:             $datatable .= '<br />'.&mt('Bcc:').('&nbsp;'x6).
1.134     raeburn  2148:                           '<input type="text" name="'.$type.'_bcc" '.
                   2149:                           'value="'.$bccemails{$type}.'"  />';
                   2150:         }
                   2151:         $datatable .= '</td></tr>'."\n";
1.28      raeburn  2152:     }
1.30      raeburn  2153:     $$rowtotal += $rownum;
1.28      raeburn  2154:     return $datatable;
                   2155: }
                   2156: 
1.118     jms      2157: sub print_helpsettings {
1.122     jms      2158: 
                   2159: 	my ($position,$dom,$confname,$settings,$rowtotal) = @_;
                   2160: 	my ($css_class,$datatable);
                   2161: 	
                   2162: 	my $switchserver = &check_switchserver($dom,$confname);
                   2163: 	
                   2164: 	my $itemcount = 1;
                   2165: 	
                   2166: 	if ($position eq 'top') {
                   2167: 		
                   2168: 		my (%checkedon,%checkedoff,%choices,%defaultchecked,@toggles);
                   2169: 		
                   2170: 		%choices =
                   2171: 			&Apache::lonlocal::texthash (
                   2172: 				submitbugs => 'Display &quot;Submit a bug&quot; link?',
                   2173: 		);
                   2174: 		
                   2175: 		%defaultchecked = ('submitbugs' => 'on');
                   2176: 		
                   2177: 		@toggles = ('submitbugs',);
                   2178: 		
                   2179: 		foreach my $item (@toggles) {
                   2180: 			if ($defaultchecked{$item} eq 'on') { 
                   2181: 				$checkedon{$item} = ' checked="checked" ';
                   2182: 				$checkedoff{$item} = ' ';
                   2183: 			} elsif ($defaultchecked{$item} eq 'off') {
                   2184: 				$checkedoff{$item} = ' checked="checked" ';
                   2185: 				$checkedon{$item} = ' ';
                   2186: 			}
                   2187: 		}
                   2188: 		
                   2189: 		if (ref($settings) eq 'HASH') {
                   2190: 			foreach my $item (@toggles) {
                   2191: 				if ($settings->{$item} eq '1') {
                   2192: 					$checkedon{$item} =  ' checked="checked" ';
                   2193: 					$checkedoff{$item} = ' ';
                   2194: 				} elsif ($settings->{$item} eq '0') {
                   2195: 					$checkedoff{$item} =  ' checked="checked" ';
                   2196: 					$checkedon{$item} = ' ';
                   2197: 				}
                   2198: 			}
                   2199: 		 }
                   2200: 		
                   2201: 		 foreach my $item (@toggles) {
                   2202: 			$css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   2203: 			$datatable .=  
                   2204: 				'<tr'.$css_class.'>
                   2205: 				<td><span class="LC_nobreak">'.$choices{$item}.'</span></td>
                   2206: 				<td><span class="LC_nobreak">&nbsp;</span></td>
                   2207: 				<td class="LC_right_item"><span class="LC_nobreak">
                   2208: 				<label><input type="radio" name="'.$item.'" '.$checkedon{$item}.' value="1" />'.&mt('Yes').'</label>&nbsp;
                   2209: 				<label><input type="radio" name="'.$item.'" '.$checkedoff{$item}.' value="0" />'.&mt('No').'</label>'.
                   2210: 				'</span></td>'.
                   2211: 				'</tr>';
                   2212: 			$itemcount ++;
                   2213: 		 }
                   2214:      
                   2215:      } else {
                   2216:      
                   2217:      	$css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   2218:      	
                   2219:      	$datatable .= '<tr'.$css_class.'>';
                   2220:      	
                   2221:      	if (ref($settings) eq 'HASH') {
                   2222: 			if ($settings->{'loginhelpurl'} ne '') {
                   2223: 				my($directory, $filename) = $settings->{'loginhelpurl'} =~ m/(.*\/)(.*)$/;
                   2224: 				$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>';
                   2225: 				$datatable .= '<td width="33%"><span class="LC_right_item"><label><input type="checkbox" name="loginhelpurl_del" value="1" />'.&mt('Delete?').'</label></span></td>'
                   2226: 			} else {
                   2227: 				$datatable .= '<td width="33%"><span class="LC_left_item"><label>'.&mt('Default Login Page Help File In Use').'</label></span></td>';
                   2228: 				$datatable .= '<td width="33%"><span class="LC_right_item">&nbsp;</span></td>';
                   2229: 			}
                   2230: 		} else {
                   2231: 			$datatable .= '<td><span class="LC_left_item">&nbsp;</span></td>';
                   2232: 			$datatable .= '<td><span class="LC_right_item">&nbsp;</span></td>';
                   2233: 		}
                   2234:     	
                   2235:      	$datatable .= '<td width="33%"><span class="LC_right_item">';
                   2236:      	if ($switchserver) {
                   2237:             $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   2238:         } else {
                   2239:         	$datatable .= &mt('Upload Custom Login Page Help File:');
                   2240:             $datatable .='<input type="file" name="loginhelpurl" />';
                   2241:         }
                   2242:         $datatable .= '</span></td></tr>';
                   2243:         
                   2244:      }
                   2245:      
                   2246:      return $datatable;
                   2247: 	
1.121     raeburn  2248: }
                   2249: 
1.122     jms      2250: 
1.121     raeburn  2251: sub radiobutton_prefs {
                   2252:     my ($settings,$toggles,$defaultchecked,$choices,$itemcount) = @_;
                   2253:     return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
                   2254:                    (ref($choices) eq 'HASH'));
                   2255: 
                   2256:     my (%checkedon,%checkedoff,$datatable,$css_class);
                   2257: 
                   2258:     foreach my $item (@{$toggles}) {
                   2259:         if ($defaultchecked->{$item} eq 'on') {
1.118     jms      2260:             $checkedon{$item} = ' checked="checked" ';
                   2261:             $checkedoff{$item} = ' ';
1.121     raeburn  2262:         } elsif ($defaultchecked->{$item} eq 'off') {
1.118     jms      2263:             $checkedoff{$item} = ' checked="checked" ';
                   2264:             $checkedon{$item} = ' ';
                   2265:         }
                   2266:     }
                   2267:     if (ref($settings) eq 'HASH') {
1.121     raeburn  2268:         foreach my $item (@{$toggles}) {
1.118     jms      2269:             if ($settings->{$item} eq '1') {
                   2270:                 $checkedon{$item} =  ' checked="checked" ';
                   2271:                 $checkedoff{$item} = ' ';
                   2272:             } elsif ($settings->{$item} eq '0') {
                   2273:                 $checkedoff{$item} =  ' checked="checked" ';
                   2274:                 $checkedon{$item} = ' ';
                   2275:             }
                   2276:         }
1.121     raeburn  2277:     }
                   2278:     foreach my $item (@{$toggles}) {
1.118     jms      2279:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121     raeburn  2280:         $datatable .=
                   2281:             '<tr'.$css_class.'><td><span class="LC_nobreak">'.$choices->{$item}.
1.118     jms      2282:             '</span></td>'.
                   2283:             '<td class="LC_right_item"><span class="LC_nobreak">'.
                   2284:             '<label><input type="radio" name="'.
                   2285:             $item.'" '.$checkedon{$item}.' value="1" />'.&mt('Yes').
                   2286:             '</label>&nbsp;<label><input type="radio" name="'.$item.'" '.
                   2287:             $checkedoff{$item}.' value="0" />'.&mt('No').'</label>'.
                   2288:             '</span></td>'.
                   2289:             '</tr>';
                   2290:         $itemcount ++;
1.121     raeburn  2291:     }
                   2292:     return ($datatable,$itemcount);
                   2293: }
                   2294: 
                   2295: sub print_coursedefaults {
1.139     raeburn  2296:     my ($position,$dom,$settings,$rowtotal) = @_;
1.121     raeburn  2297:     my ($css_class,$datatable);
                   2298:     my $itemcount = 1;
1.139     raeburn  2299:     if ($position eq 'top') {
                   2300:         my (%checkedon,%checkedoff,%choices,%defaultchecked,@toggles);
                   2301:         %choices =
                   2302:             &Apache::lonlocal::texthash (
                   2303:                 canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
                   2304:         );
                   2305:         %defaultchecked = ('canuse_pdfforms' => 'off');
                   2306:         @toggles = ('canuse_pdfforms',);
                   2307:         ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.121     raeburn  2308:                                                  \%choices,$itemcount);
1.139     raeburn  2309:         $$rowtotal += $itemcount;
                   2310:     } else {
                   2311:         $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   2312:         my %choices =
                   2313:             &Apache::lonlocal::texthash (
                   2314:                 anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
                   2315:         );
                   2316:         my $currdefresponder;
                   2317:         if (ref($settings) eq 'HASH') {
                   2318:             $currdefresponder = $settings->{'anonsurvey_threshold'};
                   2319:         }
                   2320:         if (!$currdefresponder) {
                   2321:             $currdefresponder = 10;
                   2322:         } elsif ($currdefresponder < 1) {
                   2323:             $currdefresponder = 1;
                   2324:         }
                   2325:         $datatable .=
                   2326:                '<tr'.$css_class.'><td><span class="LC_nobreak">'.$choices{'anonsurvey_threshold'}.
                   2327:                 '</span></td>'.
                   2328:                 '<td class="LC_right_item"><span class="LC_nobreak">'.
                   2329:                 '<input type="text" name="anonsurvey_threshold"'.
                   2330:                 ' value="'.$currdefresponder.'" size="5" /></span>'.
                   2331:                 '</td></tr>';
                   2332:     }
1.121     raeburn  2333:     return $datatable;
1.118     jms      2334: }
                   2335: 
1.137     raeburn  2336: sub print_usersessions {
                   2337:     my ($position,$dom,$settings,$rowtotal) = @_;
                   2338:     my ($css_class,$datatable,%checked,%choices);
1.140     raeburn  2339:     my (%by_ip,%by_location,@intdoms);
                   2340:     &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145     raeburn  2341: 
                   2342:     my @alldoms = &Apache::lonnet::all_domains();
1.152     raeburn  2343:     my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149     raeburn  2344:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152     raeburn  2345:     my %altids = &id_for_thisdom(%servers);
1.145     raeburn  2346:     my $itemcount = 1;
                   2347:     if ($position eq 'top') {
1.152     raeburn  2348:         if (keys(%serverhomes) > 1) {
1.145     raeburn  2349:             my %spareid = &current_offloads_to($dom,$settings,\%servers);
1.152     raeburn  2350:             $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$rowtotal);
1.145     raeburn  2351:         } else {
1.140     raeburn  2352:             $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150     raeburn  2353:                           &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140     raeburn  2354:         }
1.137     raeburn  2355:     } else {
1.145     raeburn  2356:         if (keys(%by_location) == 0) {
                   2357:             $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150     raeburn  2358:                           &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145     raeburn  2359:         } else {
                   2360:             my %lt = &usersession_titles();
                   2361:             my $numinrow = 5;
                   2362:             my $prefix;
                   2363:             my @types;
                   2364:             if ($position eq 'bottom') {
                   2365:                 $prefix = 'remote';
                   2366:                 @types = ('version','excludedomain','includedomain');
                   2367:             } else {
                   2368:                 $prefix = 'hosted';
                   2369:                 @types = ('excludedomain','includedomain');
                   2370:             }
                   2371:             my (%current,%checkedon,%checkedoff);
                   2372:             my @lcversions = &Apache::lonnet::all_loncaparevs();
                   2373:             my @locations = sort(keys(%by_location));
                   2374:             foreach my $type (@types) {
                   2375:                 $checkedon{$type} = '';
                   2376:                 $checkedoff{$type} = ' checked="checked"';
                   2377:             }
                   2378:             if (ref($settings) eq 'HASH') {
                   2379:                 if (ref($settings->{$prefix}) eq 'HASH') {
                   2380:                     foreach my $key (keys(%{$settings->{$prefix}})) {
                   2381:                         $current{$key} = $settings->{$prefix}{$key};
                   2382:                         if ($key eq 'version') {
                   2383:                             if ($current{$key} ne '') {
                   2384:                                 $checkedon{$key} = ' checked="checked"';
                   2385:                                 $checkedoff{$key} = '';
                   2386:                             }
                   2387:                         } elsif (ref($current{$key}) eq 'ARRAY') {
                   2388:                             $checkedon{$key} = ' checked="checked"';
                   2389:                             $checkedoff{$key} = '';
                   2390:                         }
1.137     raeburn  2391:                     }
                   2392:                 }
                   2393:             }
1.145     raeburn  2394:             foreach my $type (@types) {
                   2395:                 next if ($type ne 'version' && !@locations);
                   2396:                 $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   2397:                 $datatable .= '<tr'.$css_class.'>
                   2398:                                <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
                   2399:                                <span class="LC_nobreak">&nbsp;
                   2400:                                <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>&nbsp;
                   2401:                                <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
                   2402:                 if ($type eq 'version') {
                   2403:                     my $selector = '<select name="'.$prefix.'_version">';
                   2404:                     foreach my $version (@lcversions) {
                   2405:                         my $selected = '';
                   2406:                         if ($current{'version'} eq $version) {
                   2407:                             $selected = ' selected="selected"';
                   2408:                         }
                   2409:                         $selector .= ' <option value="'.$version.'"'.
                   2410:                                      $selected.'>'.$version.'</option>';
                   2411:                     }
                   2412:                     $selector .= '</select> ';
                   2413:                     $datatable .= &mt('remote server must be version: [_1] or later',$selector);
                   2414:                 } else {
                   2415:                     $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
                   2416:                                  'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
                   2417:                                  ' />'.('&nbsp;'x2).
                   2418:                                  '<input type="button" value="'.&mt('uncheck all').'" '.
                   2419:                                  'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
                   2420:                                  "\n".
                   2421:                                  '</div><div><table>';
                   2422:                     my $rem;
                   2423:                     for (my $i=0; $i<@locations; $i++) {
                   2424:                         my ($showloc,$value,$checkedtype);
                   2425:                         if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
                   2426:                             my $ip = $by_location{$locations[$i]}->[0];
                   2427:                             if (ref($by_ip{$ip}) eq 'ARRAY') {
                   2428:                                  $value = join(':',@{$by_ip{$ip}});
                   2429:                                 $showloc = join(', ',@{$by_ip{$ip}});
                   2430:                                 if (ref($current{$type}) eq 'ARRAY') {
                   2431:                                     foreach my $loc (@{$by_ip{$ip}}) {  
                   2432:                                         if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
                   2433:                                             $checkedtype = ' checked="checked"';
                   2434:                                             last;
                   2435:                                         }
                   2436:                                     }
1.138     raeburn  2437:                                 }
                   2438:                             }
                   2439:                         }
1.145     raeburn  2440:                         $rem = $i%($numinrow);
                   2441:                         if ($rem == 0) {
                   2442:                             if ($i > 0) {
                   2443:                                 $datatable .= '</tr>';
                   2444:                             }
                   2445:                             $datatable .= '<tr>';
                   2446:                         }
                   2447:                         $datatable .= '<td class="LC_left_item">'.
                   2448:                                       '<span class="LC_nobreak"><label>'.
                   2449:                                       '<input type="checkbox" name="'.$prefix.'_'.$type.
                   2450:                                       '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
                   2451:                                       '</label></span></td>';
1.137     raeburn  2452:                     }
1.145     raeburn  2453:                     $rem = @locations%($numinrow);
                   2454:                     my $colsleft = $numinrow - $rem;
                   2455:                     if ($colsleft > 1 ) {
                   2456:                         $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   2457:                                       '&nbsp;</td>';
                   2458:                     } elsif ($colsleft == 1) {
                   2459:                         $datatable .= '<td class="LC_left_item">&nbsp;</td>';
1.137     raeburn  2460:                     }
1.145     raeburn  2461:                     $datatable .= '</tr></table>';
1.137     raeburn  2462:                 }
1.145     raeburn  2463:                 $datatable .= '</td></tr>';
                   2464:                 $itemcount ++;
1.137     raeburn  2465:             }
                   2466:         }
                   2467:     }
                   2468:     $$rowtotal += $itemcount;
                   2469:     return $datatable;
                   2470: }
                   2471: 
1.138     raeburn  2472: sub build_location_hashes {
                   2473:     my ($intdoms,$by_ip,$by_location) = @_;
                   2474:     return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
                   2475:                   (ref($by_location) eq 'HASH')); 
                   2476:     my %iphost = &Apache::lonnet::get_iphost();
                   2477:     my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
                   2478:     my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
                   2479:     if (ref($iphost{$primary_ip}) eq 'ARRAY') {
                   2480:         foreach my $id (@{$iphost{$primary_ip}}) {
                   2481:             my $intdom = &Apache::lonnet::internet_dom($id);
                   2482:             unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
                   2483:                 push(@{$intdoms},$intdom);
                   2484:             }
                   2485:         }
                   2486:     }
                   2487:     foreach my $ip (keys(%iphost)) {
                   2488:         if (ref($iphost{$ip}) eq 'ARRAY') {
                   2489:             foreach my $id (@{$iphost{$ip}}) {
                   2490:                 my $location = &Apache::lonnet::internet_dom($id);
                   2491:                 if ($location) {
                   2492:                     next if (grep(/^\Q$location\E$/,@{$intdoms}));
                   2493:                     if (ref($by_ip->{$ip}) eq 'ARRAY') {
                   2494:                         unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
                   2495:                             push(@{$by_ip->{$ip}},$location);
                   2496:                         }
                   2497:                     } else {
                   2498:                         $by_ip->{$ip} = [$location];
                   2499:                     }
                   2500:                 }
                   2501:             }
                   2502:         }
                   2503:     }
                   2504:     foreach my $ip (sort(keys(%{$by_ip}))) {
                   2505:         if (ref($by_ip->{$ip}) eq 'ARRAY') {
                   2506:             @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
                   2507:             my $first = $by_ip->{$ip}->[0];
                   2508:             if (ref($by_location->{$first}) eq 'ARRAY') {
                   2509:                 unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
                   2510:                     push(@{$by_location->{$first}},$ip);
                   2511:                 }
                   2512:             } else {
                   2513:                 $by_location->{$first} = [$ip];
                   2514:             }
                   2515:         }
                   2516:     }
                   2517:     return;
                   2518: }
                   2519: 
1.145     raeburn  2520: sub current_offloads_to {
                   2521:     my ($dom,$settings,$servers) = @_;
                   2522:     my (%spareid,%otherdomconfigs);
1.152     raeburn  2523:     if (ref($servers) eq 'HASH') {
1.145     raeburn  2524:         foreach my $lonhost (sort(keys(%{$servers}))) {
                   2525:             my $gotspares;
1.152     raeburn  2526:             if (ref($settings) eq 'HASH') {
                   2527:                 if (ref($settings->{'spares'}) eq 'HASH') {
                   2528:                     if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
                   2529:                         $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
                   2530:                         $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
                   2531:                         $gotspares = 1;
                   2532:                     }
1.145     raeburn  2533:                 }
                   2534:             }
                   2535:             unless ($gotspares) {
                   2536:                 my $gotspares;
                   2537:                 my $serverhomeID =
                   2538:                     &Apache::lonnet::get_server_homeID($servers->{$lonhost});
                   2539:                 my $serverhomedom =
                   2540:                     &Apache::lonnet::host_domain($serverhomeID);
                   2541:                 if ($serverhomedom ne $dom) {
                   2542:                     if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
                   2543:                         if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
                   2544:                             if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
                   2545:                                 $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
                   2546:                                 $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
                   2547:                                 $gotspares = 1;
                   2548:                             }
                   2549:                         }
                   2550:                     } else {
                   2551:                         $otherdomconfigs{$serverhomedom} =
                   2552:                             &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
                   2553:                         if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
                   2554:                             if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
                   2555:                                 if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
                   2556:                                     if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
                   2557:                                         $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
                   2558:                                         $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
                   2559:                                         $gotspares = 1;
                   2560:                                     }
                   2561:                                 }
                   2562:                             }
                   2563:                         }
                   2564:                     }
                   2565:                 }
                   2566:             }
                   2567:             unless ($gotspares) {
                   2568:                 if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
                   2569:                     $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
                   2570:                     $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
                   2571:                } else {
                   2572:                     my $server_hostname = &Apache::lonnet::hostname($lonhost);
                   2573:                     my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
                   2574:                     if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
                   2575:                         $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
                   2576:                         $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
                   2577:                     } else {
1.150     raeburn  2578:                         my %what = (
                   2579:                              spareid => 1,
                   2580:                         );
                   2581:                         my ($result,$returnhash) = 
                   2582:                             &Apache::lonnet::get_remote_globals($lonhost,\%what);
                   2583:                         if ($result eq 'ok') { 
                   2584:                             if (ref($returnhash) eq 'HASH') {
                   2585:                                 if (ref($returnhash->{'spareid'}) eq 'HASH') {
                   2586:                                     $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
                   2587:                                     $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
                   2588:                                 }
                   2589:                             }
1.145     raeburn  2590:                         }
                   2591:                     }
                   2592:                 }
                   2593:             }
                   2594:         }
                   2595:     }
                   2596:     return %spareid;
                   2597: }
                   2598: 
                   2599: sub spares_row {
1.152     raeburn  2600:     my ($dom,$servers,$spareid,$serverhomes,$altids,$rowtotal) = @_;
1.145     raeburn  2601:     my $css_class;
                   2602:     my $numinrow = 4;
                   2603:     my $itemcount = 1;
                   2604:     my $datatable;
1.152     raeburn  2605:     my %typetitles = &sparestype_titles();
                   2606:     if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145     raeburn  2607:         foreach my $server (sort(keys(%{$servers}))) {
1.152     raeburn  2608:             my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
                   2609:             my ($othercontrol,$serverdom);
                   2610:             if ($serverhome ne $server) {
                   2611:                 $serverdom = &Apache::lonnet::host_domain($serverhome);
                   2612:                 $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
                   2613:             } else {
                   2614:                 $serverdom = &Apache::lonnet::host_domain($server);
                   2615:                 if ($serverdom ne $dom) {
                   2616:                     $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
                   2617:                 }
                   2618:             }
                   2619:             next unless (ref($spareid->{$server}) eq 'HASH');
1.145     raeburn  2620:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   2621:             $datatable .= '<tr'.$css_class.'>
                   2622:                            <td rowspan="2">
1.152     raeburn  2623:                             <span class="LC_nobreak"><b>'.$server.'</b> when busy, offloads to:</span></td>'."\n";
1.145     raeburn  2624:             my (%current,%canselect);
1.152     raeburn  2625:             my @choices = 
                   2626:                 &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
                   2627:             foreach my $type ('primary','default') {
                   2628:                 if (ref($spareid->{$server}) eq 'HASH') {
1.145     raeburn  2629:                     if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
                   2630:                         my @spares = @{$spareid->{$server}{$type}};
                   2631:                         if (@spares > 0) {
1.152     raeburn  2632:                             if ($othercontrol) {
                   2633:                                 $current{$type} = join(', ',@spares);
                   2634:                             } else {
                   2635:                                 $current{$type} .= '<table>';
                   2636:                                 my $numspares = scalar(@spares);
                   2637:                                 for (my $i=0;  $i<@spares; $i++) {
                   2638:                                     my $rem = $i%($numinrow);
                   2639:                                     if ($rem == 0) {
                   2640:                                         if ($i > 0) {
                   2641:                                             $current{$type} .= '</tr>';
                   2642:                                         }
                   2643:                                         $current{$type} .= '<tr>';
1.145     raeburn  2644:                                     }
1.152     raeburn  2645:                                     $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;'.
                   2646:                                                        $spareid->{$server}{$type}[$i].
                   2647:                                                        '</label></td>'."\n";
                   2648:                                 }
                   2649:                                 my $rem = @spares%($numinrow);
                   2650:                                 my $colsleft = $numinrow - $rem;
                   2651:                                 if ($colsleft > 1 ) {
                   2652:                                     $current{$type} .= '<td colspan="'.$colsleft.
                   2653:                                                        '" class="LC_left_item">'.
                   2654:                                                        '&nbsp;</td>';
                   2655:                                 } elsif ($colsleft == 1) {
                   2656:                                     $current{$type} .= '<td class="LC_left_item">&nbsp;</td>'."\n";
1.145     raeburn  2657:                                 }
1.152     raeburn  2658:                                 $current{$type} .= '</tr></table>';
1.150     raeburn  2659:                             }
1.145     raeburn  2660:                         }
                   2661:                     }
                   2662:                     if ($current{$type} eq '') {
                   2663:                         $current{$type} = &mt('None specified');
                   2664:                     }
1.152     raeburn  2665:                     if ($othercontrol) {
                   2666:                         if ($type eq 'primary') {
                   2667:                             $canselect{$type} = $othercontrol;
                   2668:                         }
                   2669:                     } else {
                   2670:                         $canselect{$type} = 
                   2671:                             &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').'&nbsp;'.
                   2672:                             '<select name="newspare_'.$type.'_'.$server.'" '.
                   2673:                             'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
                   2674:                             '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
                   2675:                         if (@choices > 0) {
                   2676:                             foreach my $lonhost (@choices) {
                   2677:                                 $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
                   2678:                             }
                   2679:                         }
                   2680:                         $canselect{$type} .= '</select>'."\n";
                   2681:                     }
                   2682:                 } else {
                   2683:                     $current{$type} = &mt('Could not be determined');
                   2684:                     if ($type eq 'primary') {
                   2685:                         $canselect{$type} =  $othercontrol;
                   2686:                     }
1.145     raeburn  2687:                 }
1.152     raeburn  2688:                 if ($type eq 'default') {
                   2689:                     $datatable .= '<tr'.$css_class.'>';
                   2690:                 }
                   2691:                 $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
                   2692:                               '<td>'.$current{$type}.'</td>'."\n".
                   2693:                               '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145     raeburn  2694:             }
                   2695:             $itemcount ++;
                   2696:         }
                   2697:     }
                   2698:     $$rowtotal += $itemcount;
                   2699:     return $datatable;
                   2700: }
                   2701: 
1.152     raeburn  2702: sub possible_newspares {
                   2703:     my ($server,$currspares,$serverhomes,$altids) = @_;
                   2704:     my $serverhostname = &Apache::lonnet::hostname($server);
                   2705:     my %excluded;
                   2706:     if ($serverhostname ne '') {
                   2707:         %excluded = (
                   2708:                        $serverhostname => 1,
                   2709:                     );
                   2710:     }
                   2711:     if (ref($currspares) eq 'HASH') {
                   2712:         foreach my $type (keys(%{$currspares})) {
                   2713:             if (ref($currspares->{$type}) eq 'ARRAY') {
                   2714:                 if (@{$currspares->{$type}} > 0) {
                   2715:                     foreach my $curr (@{$currspares->{$type}}) {
                   2716:                         my $hostname = &Apache::lonnet::hostname($curr);
                   2717:                         $excluded{$hostname} = 1;
                   2718:                     }
                   2719:                 }
                   2720:             }
                   2721:         }
                   2722:     }
                   2723:     my @choices;
                   2724:     if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
                   2725:         if (keys(%{$serverhomes}) > 1) {
                   2726:             foreach my $name (sort(keys(%{$serverhomes}))) {
                   2727:                 unless ($excluded{$name}) {
                   2728:                     if (exists($altids->{$serverhomes->{$name}})) {
                   2729:                         push(@choices,$altids->{$serverhomes->{$name}});
                   2730:                     } else {
                   2731:                         push(@choices,$serverhomes->{$name});
1.145     raeburn  2732:                     }
                   2733:                 }
                   2734:             }
                   2735:         }
                   2736:     }
1.152     raeburn  2737:     return sort(@choices);
1.145     raeburn  2738: }
                   2739: 
1.150     raeburn  2740: sub print_loadbalancing {
                   2741:     my ($dom,$settings,$rowtotal) = @_;
                   2742:     my $primary_id = &Apache::lonnet::domain($dom,'primary');
                   2743:     my $intdom = &Apache::lonnet::internet_dom($primary_id);
                   2744:     my $numinrow = 1;
                   2745:     my $datatable;
                   2746:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
                   2747:     my ($currbalancer,$currtargets,$currrules);
                   2748:     if (keys(%servers) > 1) {
                   2749:         if (ref($settings) eq 'HASH') {
                   2750:             $currbalancer = $settings->{'lonhost'};
                   2751:             $currtargets = $settings->{'targets'};
                   2752:             $currrules = $settings->{'rules'};
                   2753:         } else {
                   2754:             ($currbalancer,$currtargets) = 
                   2755:                 &Apache::lonnet::get_lonbalancer_config(\%servers);
                   2756:         }
                   2757:     } else {
                   2758:         return;
                   2759:     }
                   2760:     my ($othertitle,$usertypes,$types) =
                   2761:         &Apache::loncommon::sorted_inst_types($dom);
                   2762:     my $rownum = 6;
                   2763:     if (ref($types) eq 'ARRAY') {
                   2764:         $rownum += scalar(@{$types});
                   2765:     }
1.153   ! raeburn  2766:     my $css_class = ' class="LC_odd_row"';
1.150     raeburn  2767:     my $targets_div_style = 'display: none';
                   2768:     my $disabled_div_style = 'display: block';
                   2769:     my $homedom_div_style = 'display: none';
                   2770:     $datatable = '<tr'.$css_class.'>'.
                   2771:                  '<td rowspan="'.$rownum.'" valign="top">'.
                   2772:                  '<p><select name="loadbalancing_lonhost" onchange="toggleTargets();">'."\n".
                   2773:                  '<option value=""';
                   2774:     if (($currbalancer eq '') || (!grep(/^\Q$currbalancer\E$/,keys(%servers)))) {
                   2775:         $datatable .= ' selected="selected"';
                   2776:     } else {
                   2777:         $targets_div_style = 'display: block';
                   2778:         $disabled_div_style = 'display: none';
                   2779:         if ($dom eq &Apache::lonnet::host_domain($currbalancer)) {
                   2780:             $homedom_div_style = 'display: block'; 
                   2781:         }
                   2782:     }
                   2783:     $datatable .= '>'.&mt('None').'</option>'."\n";
                   2784:     foreach my $lonhost (sort(keys(%servers))) {
                   2785:         my $selected;
                   2786:         if ($lonhost eq $currbalancer) {
                   2787:             $selected .= ' selected="selected"';
                   2788:         }
                   2789:         $datatable .= '<option value="'.$lonhost.'"'.$selected.'>'.$lonhost.'</option>'."\n";
                   2790:     }
                   2791:     $datatable .= '</select></p></td><td rowspan="'.$rownum.'" valign="top">'.
                   2792:                   '<div id="loadbalancing_disabled" style="'.$disabled_div_style.'">'.&mt('No dedicated Load Balancer').'</div>'."\n".
                   2793:                   '<div id="loadbalancing_targets" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
                   2794:     my ($numspares,@spares) = &count_servers($currbalancer,%servers);
                   2795:     my @sparestypes = ('primary','default');
                   2796:     my %typetitles = &sparestype_titles();
                   2797:     foreach my $sparetype (@sparestypes) {
                   2798:         my $targettable;
                   2799:         for (my $i=0; $i<$numspares; $i++) {
                   2800:             my $checked;
                   2801:             if (ref($currtargets) eq 'HASH') {
                   2802:                 if (ref($currtargets->{$sparetype}) eq 'ARRAY') {
                   2803:                     if (grep(/^\Q$spares[$i]\E$/,@{$currtargets->{$sparetype}})) {
                   2804:                         $checked = ' checked="checked"';
                   2805:                     }
                   2806:                 }
                   2807:             }
                   2808:             my $chkboxval;
                   2809:             if (($currbalancer ne '') && (grep((/^\Q$currbalancer\E$/,keys(%servers))))) {
                   2810:                 $chkboxval = $spares[$i];
                   2811:             }
                   2812:             $targettable .= '<td><label><input type="checkbox" name="loadbalancing_target_'.$sparetype.'"'.
                   2813:                       $checked.' value="'.$chkboxval.'" id="loadbalancing_target_'.$sparetype.'_'.$i.'" onclick="checkOffloads('."this,'$sparetype'".');" /><span id="loadbalancing_targettxt_'.$sparetype.'_'.$i.'">&nbsp;'.$chkboxval.
                   2814:                       '</span></label></td>';
                   2815:             my $rem = $i%($numinrow);
                   2816:             if ($rem == 0) {
                   2817:                 if ($i > 0) {
                   2818:                     $targettable .= '</tr>';
                   2819:                 }
                   2820:                 $targettable .= '<tr>';
                   2821:             }
                   2822:         }
                   2823:         if ($targettable ne '') {
                   2824:             my $rem = $numspares%($numinrow);
                   2825:             my $colsleft = $numinrow - $rem;
                   2826:             if ($colsleft > 1 ) {
                   2827:                 $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   2828:                                 '&nbsp;</td>';
                   2829:             } elsif ($colsleft == 1) {
                   2830:                 $targettable .= '<td class="LC_left_item">&nbsp;</td>';
                   2831:             }
                   2832:             $datatable .=  '<i>'.$typetitles{$sparetype}.'</i><br />'.
                   2833:                            '<table><tr>'.$targettable.'</table><br />';
                   2834:         }
                   2835:     }
                   2836:     $datatable .= '</div></td></tr>'.
                   2837:                   &loadbalancing_rules($dom,$intdom,$currrules,$othertitle,
                   2838:                                        $usertypes,$types,\%servers,$currbalancer,
1.153   ! raeburn  2839:                                        $targets_div_style,$homedom_div_style,$css_class);
1.150     raeburn  2840:     $$rowtotal += $rownum;
                   2841:     return $datatable;
                   2842: }
                   2843: 
                   2844: sub loadbalancing_rules {
                   2845:     my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.153   ! raeburn  2846:         $currbalancer,$targets_div_style,$homedom_div_style,$css_class) = @_;
1.150     raeburn  2847:     my $output;
                   2848:     my ($alltypes,$othertypes,$titles) = 
                   2849:         &loadbalancing_titles($dom,$intdom,$usertypes,$types);
                   2850:     if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH'))  {
                   2851:         foreach my $type (@{$alltypes}) {
                   2852:             my $current;
                   2853:             if (ref($currrules) eq 'HASH') {
                   2854:                 $current = $currrules->{$type};
                   2855:             }
                   2856:             if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
                   2857:                 if ($dom ne &Apache::lonnet::host_domain($currbalancer)) {
                   2858:                     $current = '';
                   2859:                 }
                   2860:             }
                   2861:             $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
                   2862:                                              $servers,$currbalancer,$dom,
1.153   ! raeburn  2863:                                              $targets_div_style,$homedom_div_style,$css_class);
1.150     raeburn  2864:         }
                   2865:     }
                   2866:     return $output;
                   2867: }
                   2868: 
                   2869: sub loadbalancing_titles {
                   2870:     my ($dom,$intdom,$usertypes,$types) = @_;
                   2871:     my %othertypes = (
                   2872:            '_LC_adv'         => &mt('Advanced users from [_1]',$dom),
                   2873:            '_LC_author'      => &mt('Users from [_1] with author role',$dom),
                   2874:            '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
                   2875:            '_LC_external'    => &mt('Users not from [_1]',$intdom),
                   2876:                      );
                   2877:     my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external');
                   2878:     if (ref($types) eq 'ARRAY') {
                   2879:         unshift(@alltypes,@{$types},'default');
                   2880:     }
                   2881:     my %titles;
                   2882:     foreach my $type (@alltypes) {
                   2883:         if ($type =~ /^_LC_/) {
                   2884:             $titles{$type} = $othertypes{$type};
                   2885:         } elsif ($type eq 'default') {
                   2886:             $titles{$type} = &mt('All users from [_1]',$dom);
                   2887:             if (ref($types) eq 'ARRAY') {
                   2888:                 if (@{$types} > 0) {
                   2889:                     $titles{$type} = &mt('Other users from [_1]',$dom);
                   2890:                 }
                   2891:             }
                   2892:         } elsif (ref($usertypes) eq 'HASH') {
                   2893:             $titles{$type} = $usertypes->{$type};
                   2894:         }
                   2895:     }
                   2896:     return (\@alltypes,\%othertypes,\%titles);
                   2897: }
                   2898: 
                   2899: sub loadbalance_rule_row {
                   2900:     my ($type,$title,$current,$servers,$currbalancer,$dom,$targets_div_style,
1.153   ! raeburn  2901:         $homedom_div_style,$css_class) = @_;
1.150     raeburn  2902:     my @rulenames = ('default','homeserver');
                   2903:     my %ruletitles = &offloadtype_text();
                   2904:     if ($type eq '_LC_external') {
                   2905:         push(@rulenames,'externalbalancer');
                   2906:     } else {
                   2907:         push(@rulenames,'specific');
                   2908:     }
                   2909:     my $style = $targets_div_style;
                   2910:     if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
                   2911:         $style = $homedom_div_style;
                   2912:     }
                   2913:     my $output = 
1.153   ! raeburn  2914:         '<tr'.$css_class.'><td valign="top"><div id="balanceruletitle_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
1.150     raeburn  2915:         '<td><div id="balancerule_'.$type.'" style="'.$style.'">'."\n";
                   2916:     for (my $i=0; $i<@rulenames; $i++) {
                   2917:         my $rule = $rulenames[$i];
                   2918:         my ($checked,$extra);
                   2919:         if ($rulenames[$i] eq 'default') {
                   2920:             $rule = '';
                   2921:         }
                   2922:         if ($rulenames[$i] eq 'specific') {
                   2923:             if (ref($servers) eq 'HASH') {
                   2924:                 my $default;
                   2925:                 if (($current ne '') && (exists($servers->{$current}))) {
                   2926:                     $checked = ' checked="checked"';
                   2927:                 }
                   2928:                 unless ($checked) {
                   2929:                     $default = ' selected="selected"';
                   2930:                 }
                   2931:                 $extra = ':&nbsp;<select name="loadbalancing_singleserver_'.$type.
                   2932:                          '" id="loadbalancing_singleserver_'.$type.
                   2933:                          '" onchange="singleServerToggle('."'$type'".')">'."\n".
                   2934:                          '<option value=""'.$default.'></option>'."\n";
                   2935:                 foreach my $lonhost (sort(keys(%{$servers}))) {
                   2936:                     next if ($lonhost eq $currbalancer);
                   2937:                     my $selected;
                   2938:                     if ($lonhost eq $current) {
                   2939:                         $selected = ' selected="selected"';
                   2940:                     }
                   2941:                     $extra .= '<option value="'.$lonhost.'"'.$selected.'>'.$lonhost.'</option>';
                   2942:                 }
                   2943:                 $extra .= '</select>';
                   2944:             }
                   2945:         } elsif ($rule eq $current) {
                   2946:             $checked = ' checked="checked"';
                   2947:         }
                   2948:         $output .= '<span class="LC_nobreak"><label>'.
                   2949:                    '<input type="radio" name="loadbalancing_rules_'.$type.
                   2950:                    '" id="loadbalancing_rules_'.$type.'_'.$i.'" value="'.
                   2951:                    $rule.'" onclick="balanceruleChange('."this.form,'$type'".
                   2952:                    ')"'.$checked.' />&nbsp;'.$ruletitles{$rulenames[$i]}.
                   2953:                    '</label>'.$extra.'</span><br />'."\n";
                   2954:     }
                   2955:     $output .= '</div></td></tr>'."\n";
                   2956:     return $output;
                   2957: }
                   2958: 
                   2959: sub offloadtype_text {
                   2960:     my %ruletitles = &Apache::lonlocal::texthash (
                   2961:            'default'          => 'Offloads to default destinations',
                   2962:            'homeserver'       => "Offloads to user's home server",
                   2963:            'externalbalancer' => "Offloads to Load Balancer in user's domain",
                   2964:            'specific'         => 'Offloads to specific server',
                   2965:     );
                   2966:     return %ruletitles;
                   2967: }
                   2968: 
                   2969: sub sparestype_titles {
                   2970:     my %typestitles = &Apache::lonlocal::texthash (
                   2971:                           'primary' => 'primary',
                   2972:                           'default' => 'default',
                   2973:                       );
                   2974:     return %typestitles;
                   2975: }
                   2976: 
1.28      raeburn  2977: sub contact_titles {
                   2978:     my %titles = &Apache::lonlocal::texthash (
                   2979:                    'supportemail' => 'Support E-mail address',
1.69      raeburn  2980:                    'adminemail'   => 'Default Server Admin E-mail address',
1.28      raeburn  2981:                    'errormail'    => 'Error reports to be e-mailed to',
                   2982:                    'packagesmail' => 'Package update alerts to be e-mailed to',
1.89      raeburn  2983:                    'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
                   2984:                    'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
1.102     raeburn  2985:                    'requestsmail' => 'E-mail from course requests requiring approval',
1.28      raeburn  2986:                  );
                   2987:     my %short_titles = &Apache::lonlocal::texthash (
                   2988:                            adminemail   => 'Admin E-mail address',
                   2989:                            supportemail => 'Support E-mail',
                   2990:                        );   
                   2991:     return (\%titles,\%short_titles);
                   2992: }
                   2993: 
1.72      raeburn  2994: sub tool_titles {
                   2995:     my %titles = &Apache::lonlocal::texthash (
1.90      weissno  2996:                      aboutme    => 'Personal Information Page',
1.86      raeburn  2997:                      blog       => 'Blog',
                   2998:                      portfolio  => 'Portfolio',
1.88      bisitz   2999:                      official   => 'Official courses (with institutional codes)',
                   3000:                      unofficial => 'Unofficial courses',
1.98      raeburn  3001:                      community  => 'Communities',
1.86      raeburn  3002:                  );
1.72      raeburn  3003:     return %titles;
                   3004: }
                   3005: 
1.101     raeburn  3006: sub courserequest_titles {
                   3007:     my %titles = &Apache::lonlocal::texthash (
                   3008:                                    official   => 'Official',
                   3009:                                    unofficial => 'Unofficial',
                   3010:                                    community  => 'Communities',
                   3011:                                    norequest  => 'Not allowed',
1.104     raeburn  3012:                                    approval   => 'Approval by Dom. Coord.',
1.101     raeburn  3013:                                    validate   => 'With validation',
                   3014:                                    autolimit  => 'Numerical limit',
1.103     raeburn  3015:                                    unlimited  => '(blank for unlimited)',
1.101     raeburn  3016:                  );
                   3017:     return %titles;
                   3018: }
                   3019: 
                   3020: sub courserequest_conditions {
                   3021:     my %conditions = &Apache::lonlocal::texthash (
1.104     raeburn  3022:        approval    => '(Processing of request subject to approval by Domain Coordinator).',
1.101     raeburn  3023:        validate   => '(Processing of request subject to instittutional validation).',
                   3024:                  );
                   3025:     return %conditions;
                   3026: }
                   3027: 
                   3028: 
1.27      raeburn  3029: sub print_usercreation {
1.30      raeburn  3030:     my ($position,$dom,$settings,$rowtotal) = @_;
1.27      raeburn  3031:     my $numinrow = 4;
1.28      raeburn  3032:     my $datatable;
                   3033:     if ($position eq 'top') {
1.30      raeburn  3034:         $$rowtotal ++;
1.34      raeburn  3035:         my $rowcount = 0;
1.32      raeburn  3036:         my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28      raeburn  3037:         if (ref($rules) eq 'HASH') {
                   3038:             if (keys(%{$rules}) > 0) {
1.32      raeburn  3039:                 $datatable .= &user_formats_row('username',$settings,$rules,
                   3040:                                                 $ruleorder,$numinrow,$rowcount);
1.30      raeburn  3041:                 $$rowtotal ++;
1.32      raeburn  3042:                 $rowcount ++;
                   3043:             }
                   3044:         }
                   3045:         my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
                   3046:         if (ref($idrules) eq 'HASH') {
                   3047:             if (keys(%{$idrules}) > 0) {
                   3048:                 $datatable .= &user_formats_row('id',$settings,$idrules,
                   3049:                                                 $idruleorder,$numinrow,$rowcount);
                   3050:                 $$rowtotal ++;
                   3051:                 $rowcount ++;
1.28      raeburn  3052:             }
                   3053:         }
1.43      raeburn  3054:         my ($emailrules,$emailruleorder) = 
                   3055:             &Apache::lonnet::inst_userrules($dom,'email');
                   3056:         if (ref($emailrules) eq 'HASH') {
                   3057:             if (keys(%{$emailrules}) > 0) {
                   3058:                 $datatable .= &user_formats_row('email',$settings,$emailrules,
                   3059:                                                 $emailruleorder,$numinrow,$rowcount);
                   3060:                 $$rowtotal ++;
                   3061:                 $rowcount ++;
                   3062:             }
                   3063:         }
1.39      raeburn  3064:         if ($rowcount == 0) {
                   3065:             $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';  
                   3066:             $$rowtotal ++;
                   3067:             $rowcount ++;
                   3068:         }
1.34      raeburn  3069:     } elsif ($position eq 'middle') {
1.100     raeburn  3070:         my @creators = ('author','course','requestcrs','selfcreate');
1.37      raeburn  3071:         my ($rules,$ruleorder) =
                   3072:             &Apache::lonnet::inst_userrules($dom,'username');
1.34      raeburn  3073:         my %lt = &usercreation_types();
                   3074:         my %checked;
1.50      raeburn  3075:         my @selfcreate; 
1.34      raeburn  3076:         if (ref($settings) eq 'HASH') {
                   3077:             if (ref($settings->{'cancreate'}) eq 'HASH') {
                   3078:                 foreach my $item (@creators) {
                   3079:                     $checked{$item} = $settings->{'cancreate'}{$item};
                   3080:                 }
1.50      raeburn  3081:                 if (ref($settings->{'cancreate'}{'selfcreate'}) eq 'ARRAY') {
                   3082:                     @selfcreate = @{$settings->{'cancreate'}{'selfcreate'}};
                   3083:                 } elsif ($settings->{'cancreate'}{'selfcreate'} ne '') {
                   3084:                     if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
                   3085:                         @selfcreate = ('email','login','sso');
                   3086:                     } elsif ($settings->{'cancreate'}{'selfcreate'} ne 'none') {
                   3087:                         @selfcreate = ($settings->{'cancreate'}{'selfcreate'});
                   3088:                     }
                   3089:                 }
1.34      raeburn  3090:             } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
                   3091:                 foreach my $item (@creators) {
                   3092:                     if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
                   3093:                         $checked{$item} = 'none';
                   3094:                     }
                   3095:                 }
                   3096:             }
                   3097:         }
                   3098:         my $rownum = 0;
                   3099:         foreach my $item (@creators) {
                   3100:             $rownum ++;
1.50      raeburn  3101:             if ($item ne 'selfcreate') {  
                   3102:                 if ($checked{$item} eq '') {
1.43      raeburn  3103:                     $checked{$item} = 'any';
                   3104:                 }
1.34      raeburn  3105:             }
                   3106:             my $css_class;
                   3107:             if ($rownum%2) {
                   3108:                 $css_class = '';
                   3109:             } else {
                   3110:                 $css_class = ' class="LC_odd_row" ';
                   3111:             }
                   3112:             $datatable .= '<tr'.$css_class.'>'.
                   3113:                          '<td><span class="LC_nobreak">'.$lt{$item}.
                   3114:                          '</span></td><td align="right">';
1.50      raeburn  3115:             my @options;
1.45      raeburn  3116:             if ($item eq 'selfcreate') {
1.43      raeburn  3117:                 push(@options,('email','login','sso'));
                   3118:             } else {
1.50      raeburn  3119:                 @options = ('any');
1.43      raeburn  3120:                 if (ref($rules) eq 'HASH') {
                   3121:                     if (keys(%{$rules}) > 0) {
                   3122:                         push(@options,('official','unofficial'));
                   3123:                     }
1.37      raeburn  3124:                 }
1.50      raeburn  3125:                 push(@options,'none');
1.37      raeburn  3126:             }
                   3127:             foreach my $option (@options) {
1.50      raeburn  3128:                 my $type = 'radio';
1.34      raeburn  3129:                 my $check = ' ';
1.50      raeburn  3130:                 if ($item eq 'selfcreate') {
                   3131:                     $type = 'checkbox';
                   3132:                     if (grep(/^\Q$option\E$/,@selfcreate)) {
                   3133:                         $check = ' checked="checked" ';
                   3134:                     }
                   3135:                 } else {
                   3136:                     if ($checked{$item} eq $option) {
                   3137:                         $check = ' checked="checked" ';
                   3138:                     }
1.34      raeburn  3139:                 } 
                   3140:                 $datatable .= '<span class="LC_nobreak"><label>'.
1.50      raeburn  3141:                               '<input type="'.$type.'" name="can_createuser_'.
1.34      raeburn  3142:                               $item.'" value="'.$option.'"'.$check.'/>&nbsp;'.
                   3143:                               $lt{$option}.'</label>&nbsp;&nbsp;</span>';
                   3144:             }
                   3145:             $datatable .= '</td></tr>';
                   3146:         }
1.93      raeburn  3147:         my ($othertitle,$usertypes,$types) =
                   3148:             &Apache::loncommon::sorted_inst_types($dom);
                   3149:         if (ref($usertypes) eq 'HASH') {
                   3150:             if (keys(%{$usertypes}) > 0) {
1.99      raeburn  3151:                 my $createsettings;
                   3152:                 if (ref($settings) eq 'HASH') {
                   3153:                     $createsettings = $settings->{cancreate};
                   3154:                 }
                   3155:                 $datatable .= &insttypes_row($createsettings,$types,$usertypes,
1.93      raeburn  3156:                                              $dom,$numinrow,$othertitle,
                   3157:                                              'statustocreate');
                   3158:                 $$rowtotal ++;
                   3159:             }
                   3160:         }
1.28      raeburn  3161:     } else {
                   3162:         my @contexts = ('author','course','domain');
                   3163:         my @authtypes = ('int','krb4','krb5','loc');
                   3164:         my %checked;
                   3165:         if (ref($settings) eq 'HASH') {
                   3166:             if (ref($settings->{'authtypes'}) eq 'HASH') {
                   3167:                 foreach my $item (@contexts) {
                   3168:                     if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
                   3169:                         foreach my $auth (@authtypes) {
                   3170:                             if ($settings->{'authtypes'}{$item}{$auth}) {
                   3171:                                 $checked{$item}{$auth} = ' checked="checked" ';
                   3172:                             }
                   3173:                         }
                   3174:                     }
                   3175:                 }
1.27      raeburn  3176:             }
1.35      raeburn  3177:         } else {
                   3178:             foreach my $item (@contexts) {
1.36      raeburn  3179:                 foreach my $auth (@authtypes) {
1.35      raeburn  3180:                     $checked{$item}{$auth} = ' checked="checked" ';
                   3181:                 }
                   3182:             }
1.27      raeburn  3183:         }
1.28      raeburn  3184:         my %title = &context_names();
                   3185:         my %authname = &authtype_names();
                   3186:         my $rownum = 0;
                   3187:         my $css_class; 
                   3188:         foreach my $item (@contexts) {
                   3189:             if ($rownum%2) {
                   3190:                 $css_class = '';
                   3191:             } else {
                   3192:                 $css_class = ' class="LC_odd_row" ';
                   3193:             }
1.30      raeburn  3194:             $datatable .=   '<tr'.$css_class.'>'.
1.28      raeburn  3195:                             '<td>'.$title{$item}.
                   3196:                             '</td><td class="LC_left_item">'.
                   3197:                             '<span class="LC_nobreak">';
                   3198:             foreach my $auth (@authtypes) {
                   3199:                 $datatable .= '<label>'. 
                   3200:                               '<input type="checkbox" name="'.$item.'_auth" '.
                   3201:                               $checked{$item}{$auth}.' value="'.$auth.'" />'.
                   3202:                               $authname{$auth}.'</label>&nbsp;';
                   3203:             }
                   3204:             $datatable .= '</span></td></tr>';
                   3205:             $rownum ++;
1.27      raeburn  3206:         }
1.30      raeburn  3207:         $$rowtotal += $rownum;
1.27      raeburn  3208:     }
                   3209:     return $datatable;
                   3210: }
                   3211: 
1.32      raeburn  3212: sub user_formats_row {
                   3213:     my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
                   3214:     my $output;
                   3215:     my %text = (
                   3216:                    'username' => 'new usernames',
                   3217:                    'id'       => 'IDs',
1.45      raeburn  3218:                    'email'    => 'self-created accounts (e-mail)',
1.32      raeburn  3219:                );
                   3220:     my $css_class = $rowcount%2?' class="LC_odd_row"':'';
                   3221:     $output = '<tr '.$css_class.'>'.
1.63      raeburn  3222:               '<td><span class="LC_nobreak">';
                   3223:     if ($type eq 'email') {
                   3224:         $output .= &mt("Formats disallowed for $text{$type}: ");
                   3225:     } else {
                   3226:         $output .= &mt("Format rules to check for $text{$type}: ");
                   3227:     }
                   3228:     $output .= '</span></td>'.
                   3229:                '<td class="LC_left_item" colspan="2"><table>';
1.27      raeburn  3230:     my $rem;
                   3231:     if (ref($ruleorder) eq 'ARRAY') {
                   3232:         for (my $i=0; $i<@{$ruleorder}; $i++) {
                   3233:             if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
                   3234:                 my $rem = $i%($numinrow);
                   3235:                 if ($rem == 0) {
                   3236:                     if ($i > 0) {
                   3237:                         $output .= '</tr>';
                   3238:                     }
                   3239:                     $output .= '<tr>';
                   3240:                 }
                   3241:                 my $check = ' ';
1.39      raeburn  3242:                 if (ref($settings) eq 'HASH') {
                   3243:                     if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
                   3244:                         if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
                   3245:                             $check = ' checked="checked" ';
                   3246:                         }
1.27      raeburn  3247:                     }
                   3248:                 }
                   3249:                 $output .= '<td class="LC_left_item">'.
                   3250:                            '<span class="LC_nobreak"><label>'.
1.32      raeburn  3251:                            '<input type="checkbox" name="'.$type.'_rule" '.
1.27      raeburn  3252:                            'value="'.$ruleorder->[$i].'"'.$check.'/>'.
                   3253:                            $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
                   3254:             }
                   3255:         }
                   3256:         $rem = @{$ruleorder}%($numinrow);
                   3257:     }
                   3258:     my $colsleft = $numinrow - $rem;
                   3259:     if ($colsleft > 1 ) {
                   3260:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   3261:                    '&nbsp;</td>';
                   3262:     } elsif ($colsleft == 1) {
                   3263:         $output .= '<td class="LC_left_item">&nbsp;</td>';
                   3264:     }
                   3265:     $output .= '</tr></table></td></tr>';
                   3266:     return $output;
                   3267: }
                   3268: 
1.34      raeburn  3269: sub usercreation_types {
                   3270:     my %lt = &Apache::lonlocal::texthash (
                   3271:                     author     => 'When adding a co-author',
                   3272:                     course     => 'When adding a user to a course',
1.100     raeburn  3273:                     requestcrs => 'When requesting a course',
1.45      raeburn  3274:                     selfcreate => 'User creates own account', 
1.34      raeburn  3275:                     any        => 'Any',
                   3276:                     official   => 'Institutional only ',
                   3277:                     unofficial => 'Non-institutional only',
1.85      schafran 3278:                     email      => 'E-mail address',
1.43      raeburn  3279:                     login      => 'Institutional Login',
                   3280:                     sso        => 'SSO', 
1.34      raeburn  3281:                     none       => 'None',
                   3282:     );
                   3283:     return %lt;
1.48      raeburn  3284: }
1.34      raeburn  3285: 
1.28      raeburn  3286: sub authtype_names {
                   3287:     my %lt = &Apache::lonlocal::texthash(
                   3288:                       int    => 'Internal',
                   3289:                       krb4   => 'Kerberos 4',
                   3290:                       krb5   => 'Kerberos 5',
                   3291:                       loc    => 'Local',
                   3292:                   );
                   3293:     return %lt;
                   3294: }
                   3295: 
                   3296: sub context_names {
                   3297:     my %context_title = &Apache::lonlocal::texthash(
                   3298:        author => 'Creating users when an Author',
                   3299:        course => 'Creating users when in a course',
                   3300:        domain => 'Creating users when a Domain Coordinator',
                   3301:     );
                   3302:     return %context_title;
                   3303: }
                   3304: 
1.33      raeburn  3305: sub print_usermodification {
                   3306:     my ($position,$dom,$settings,$rowtotal) = @_;
                   3307:     my $numinrow = 4;
                   3308:     my ($context,$datatable,$rowcount);
                   3309:     if ($position eq 'top') {
                   3310:         $rowcount = 0;
                   3311:         $context = 'author'; 
                   3312:         foreach my $role ('ca','aa') {
                   3313:             $datatable .= &modifiable_userdata_row($context,$role,$settings,
                   3314:                                                    $numinrow,$rowcount);
                   3315:             $$rowtotal ++;
                   3316:             $rowcount ++;
                   3317:         }
1.63      raeburn  3318:     } elsif ($position eq 'middle') {
1.33      raeburn  3319:         $context = 'course';
                   3320:         $rowcount = 0;
                   3321:         foreach my $role ('st','ep','ta','in','cr') {
                   3322:             $datatable .= &modifiable_userdata_row($context,$role,$settings,
                   3323:                                                    $numinrow,$rowcount);
                   3324:             $$rowtotal ++;
                   3325:             $rowcount ++;
                   3326:         }
1.63      raeburn  3327:     } elsif ($position eq 'bottom') {
                   3328:         $context = 'selfcreate';
                   3329:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   3330:         $usertypes->{'default'} = $othertitle;
                   3331:         if (ref($types) eq 'ARRAY') {
                   3332:             push(@{$types},'default');
                   3333:             $usertypes->{'default'} = $othertitle;
                   3334:             foreach my $status (@{$types}) {
                   3335:                 $datatable .= &modifiable_userdata_row($context,$status,$settings,
                   3336:                                                        $numinrow,$rowcount,$usertypes);
                   3337:                 $$rowtotal ++;
                   3338:                 $rowcount ++;
                   3339:             }
                   3340:         }
1.33      raeburn  3341:     }
                   3342:     return $datatable;
                   3343: }
                   3344: 
1.43      raeburn  3345: sub print_defaults {
                   3346:     my ($dom,$rowtotal) = @_;
1.68      raeburn  3347:     my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
1.141     raeburn  3348:                  'datelocale_def','portal_def');
1.43      raeburn  3349:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.141     raeburn  3350:     my $titles = &defaults_titles($dom);
1.43      raeburn  3351:     my $rownum = 0;
                   3352:     my ($datatable,$css_class);
                   3353:     foreach my $item (@items) {
                   3354:         if ($rownum%2) {
                   3355:             $css_class = '';
                   3356:         } else {
                   3357:             $css_class = ' class="LC_odd_row" ';
                   3358:         }
                   3359:         $datatable .= '<tr'.$css_class.'>'.
                   3360:                   '<td><span class="LC_nobreak">'.$titles->{$item}.
                   3361:                   '</span></td><td class="LC_right_item">';
                   3362:         if ($item eq 'auth_def') {
                   3363:             my @authtypes = ('internal','krb4','krb5','localauth');
                   3364:             my %shortauth = (
                   3365:                              internal => 'int',
                   3366:                              krb4 => 'krb4',
                   3367:                              krb5 => 'krb5',
                   3368:                              localauth  => 'loc'
                   3369:                            );
                   3370:             my %authnames = &authtype_names();
                   3371:             foreach my $auth (@authtypes) {
                   3372:                 my $checked = ' ';
                   3373:                 if ($domdefaults{$item} eq $auth) {
                   3374:                     $checked = ' checked="checked" ';
                   3375:                 }
                   3376:                 $datatable .= '<label><input type="radio" name="'.$item.
                   3377:                               '" value="'.$auth.'"'.$checked.'/>'.
                   3378:                               $authnames{$shortauth{$auth}}.'</label>&nbsp;&nbsp;';
                   3379:             }
1.54      raeburn  3380:         } elsif ($item eq 'timezone_def') {
                   3381:             my $includeempty = 1;
                   3382:             $datatable .= &Apache::loncommon::select_timezone($item,$domdefaults{$item},undef,$includeempty);
1.68      raeburn  3383:         } elsif ($item eq 'datelocale_def') {
                   3384:             my $includeempty = 1;
                   3385:             $datatable .= &Apache::loncommon::select_datelocale($item,$domdefaults{$item},undef,$includeempty);
1.43      raeburn  3386:         } else {
1.141     raeburn  3387:             my $size;
                   3388:             if ($item eq 'portal_def') {
                   3389:                 $size = ' size="25"';
                   3390:             }
1.43      raeburn  3391:             $datatable .= '<input type="text" name="'.$item.'" value="'.
1.141     raeburn  3392:                           $domdefaults{$item}.'"'.$size.' />';
1.43      raeburn  3393:         }
                   3394:         $datatable .= '</td></tr>';
                   3395:         $rownum ++;
                   3396:     }
                   3397:     $$rowtotal += $rownum;
                   3398:     return $datatable;
                   3399: }
                   3400: 
                   3401: sub defaults_titles {
1.141     raeburn  3402:     my ($dom) = @_;
1.43      raeburn  3403:     my %titles = &Apache::lonlocal::texthash (
                   3404:                    'auth_def'      => 'Default authentication type',
                   3405:                    'auth_arg_def'  => 'Default authentication argument',
                   3406:                    'lang_def'      => 'Default language',
1.54      raeburn  3407:                    'timezone_def'  => 'Default timezone',
1.68      raeburn  3408:                    'datelocale_def' => 'Default locale for dates',
1.141     raeburn  3409:                    'portal_def'     => 'Portal/Default URL',
1.43      raeburn  3410:                  );
1.141     raeburn  3411:     if ($dom) {
                   3412:         my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
                   3413:         my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
                   3414:         my $protocol = $Apache::lonnet::protocol{$uprimary_id};
                   3415:         $protocol = 'http' if ($protocol ne 'https');
                   3416:         if ($uint_dom) {
                   3417:             $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
                   3418:                                          $uint_dom);
                   3419:         }
                   3420:     }
1.43      raeburn  3421:     return (\%titles);
                   3422: }
                   3423: 
1.46      raeburn  3424: sub print_scantronformat {
                   3425:     my ($r,$dom,$confname,$settings,$rowtotal) = @_;
                   3426:     my $itemcount = 1;
1.60      raeburn  3427:     my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
                   3428:         %confhash);
1.46      raeburn  3429:     my $switchserver = &check_switchserver($dom,$confname);
                   3430:     my %lt = &Apache::lonlocal::texthash (
1.95      www      3431:                 default => 'Default bubblesheet format file error',
                   3432:                 custom  => 'Custom bubblesheet format file error',
1.46      raeburn  3433:              );
                   3434:     my %scantronfiles = (
                   3435:         default => 'default.tab',
                   3436:         custom => 'custom.tab',
                   3437:     );
                   3438:     foreach my $key (keys(%scantronfiles)) {
                   3439:         $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
                   3440:                               .$scantronfiles{$key};
                   3441:     }
                   3442:     my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
                   3443:     if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
                   3444:         if (!$switchserver) {
                   3445:             my $servadm = $r->dir_config('lonAdmEMail');
                   3446:             my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
                   3447:             if ($configuserok eq 'ok') {
                   3448:                 if ($author_ok eq 'ok') {
                   3449:                     my %legacyfile = (
                   3450:  default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab', 
                   3451:  custom  => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab', 
                   3452:                     );
                   3453:                     my %md5chk;
                   3454:                     foreach my $type (keys(%legacyfile)) {
1.60      raeburn  3455:                         ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
                   3456:                         chomp($md5chk{$type});
1.46      raeburn  3457:                     }
                   3458:                     if ($md5chk{'default'} ne $md5chk{'custom'}) {
                   3459:                         foreach my $type (keys(%legacyfile)) {
1.60      raeburn  3460:                             ($scantronurls{$type},my $error) = 
1.46      raeburn  3461:                                 &legacy_scantronformat($r,$dom,$confname,
                   3462:                                                  $type,$legacyfile{$type},
                   3463:                                                  $scantronurls{$type},
                   3464:                                                  $scantronfiles{$type});
1.60      raeburn  3465:                             if ($error ne '') {
                   3466:                                 $error{$type} = $error;
                   3467:                             }
                   3468:                         }
                   3469:                         if (keys(%error) == 0) {
                   3470:                             $is_custom = 1;
                   3471:                             $confhash{'scantron'}{'scantronformat'} = 
                   3472:                                 $scantronurls{'custom'};
                   3473:                             my $putresult = 
                   3474:                                 &Apache::lonnet::put_dom('configuration',
                   3475:                                                          \%confhash,$dom);
                   3476:                             if ($putresult ne 'ok') {
                   3477:                                 $error{'custom'} = 
                   3478:                                     '<span class="LC_error">'.
                   3479:                                     &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
                   3480:                             }
1.46      raeburn  3481:                         }
                   3482:                     } else {
1.60      raeburn  3483:                         ($scantronurls{'default'},my $error) =
1.46      raeburn  3484:                             &legacy_scantronformat($r,$dom,$confname,
                   3485:                                           'default',$legacyfile{'default'},
                   3486:                                           $scantronurls{'default'},
                   3487:                                           $scantronfiles{'default'});
1.60      raeburn  3488:                         if ($error eq '') {
                   3489:                             $confhash{'scantron'}{'scantronformat'} = ''; 
                   3490:                             my $putresult =
                   3491:                                 &Apache::lonnet::put_dom('configuration',
                   3492:                                                          \%confhash,$dom);
                   3493:                             if ($putresult ne 'ok') {
                   3494:                                 $error{'default'} =
                   3495:                                     '<span class="LC_error">'.
                   3496:                                     &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
                   3497:                             }
                   3498:                         } else {
                   3499:                             $error{'default'} = $error;
                   3500:                         }
1.46      raeburn  3501:                     }
                   3502:                 }
                   3503:             }
                   3504:         } else {
1.95      www      3505:             $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46      raeburn  3506:         }
                   3507:     }
                   3508:     if (ref($settings) eq 'HASH') {
                   3509:         if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
                   3510:             my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
                   3511:             if ((!@info) || ($info[0] eq 'no_such_dir')) {
                   3512:                 $scantronurl = '';
                   3513:             } else {
                   3514:                 $scantronurl = $settings->{'scantronformat'};
                   3515:             }
                   3516:             $is_custom = 1;
                   3517:         } else {
                   3518:             $scantronurl = $scantronurls{'default'};
                   3519:         }
                   3520:     } else {
1.60      raeburn  3521:         if ($is_custom) {
                   3522:             $scantronurl = $scantronurls{'custom'};
                   3523:         } else {
                   3524:             $scantronurl = $scantronurls{'default'};
                   3525:         }
1.46      raeburn  3526:     }
                   3527:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   3528:     $datatable .= '<tr'.$css_class.'>';
                   3529:     if (!$is_custom) {
1.65      raeburn  3530:         $datatable .= '<td>'.&mt('Default in use:').'<br />'.
                   3531:                       '<span class="LC_nobreak">';
1.46      raeburn  3532:         if ($scantronurl) {
                   3533:             $datatable .= '<a href="'.$scantronurl.'" target="_blank">'.
1.130     raeburn  3534:                           &mt('Default bubblesheet format file').'</a>';
1.46      raeburn  3535:         } else {
                   3536:             $datatable = &mt('File unavailable for display');
                   3537:         }
1.65      raeburn  3538:         $datatable .= '</span></td>';
1.60      raeburn  3539:         if (keys(%error) == 0) { 
                   3540:             $datatable .= '<td valign="bottom">';
                   3541:             if (!$switchserver) {
                   3542:                 $datatable .= &mt('Upload:').'<br />';
                   3543:             }
                   3544:         } else {
                   3545:             my $errorstr;
                   3546:             foreach my $key (sort(keys(%error))) {
                   3547:                 $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
                   3548:             }
                   3549:             $datatable .= '<td>'.$errorstr;
                   3550:         }
1.46      raeburn  3551:     } else {
                   3552:         if (keys(%error) > 0) {
                   3553:             my $errorstr;
                   3554:             foreach my $key (sort(keys(%error))) {
                   3555:                 $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
                   3556:             } 
1.60      raeburn  3557:             $datatable .= '<td>'.$errorstr.'</td><td>&nbsp;';
1.46      raeburn  3558:         } elsif ($scantronurl) {
1.65      raeburn  3559:             $datatable .= '<td><span class="LC_nobreak">'.
                   3560:                           '<a href="'.$scantronurl.'" target="_blank">'.
1.130     raeburn  3561:                           &mt('Custom bubblesheet format file').'</a><label>'.
1.65      raeburn  3562:                           '<input type="checkbox" name="scantronformat_del"'.
                   3563:                           '" value="1" />'.&mt('Delete?').'</label></span></td>'.
                   3564:                           '<td><span class="LC_nobreak">&nbsp;'.
                   3565:                           &mt('Replace:').'</span><br />';
1.46      raeburn  3566:         }
                   3567:     }
                   3568:     if (keys(%error) == 0) {
                   3569:         if ($switchserver) {
                   3570:             $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   3571:         } else {
1.65      raeburn  3572:             $datatable .='<span class="LC_nobreak">&nbsp;'.
                   3573:                          '<input type="file" name="scantronformat" /></span>';
1.46      raeburn  3574:         }
                   3575:     }
                   3576:     $datatable .= '</td></tr>';
                   3577:     $$rowtotal ++;
                   3578:     return $datatable;
                   3579: }
                   3580: 
                   3581: sub legacy_scantronformat {
                   3582:     my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
                   3583:     my ($url,$error);
                   3584:     my @statinfo = &Apache::lonnet::stat_file($newurl);
                   3585:     if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
                   3586:         (my $result,$url) =
                   3587:             &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
                   3588:                          '','',$newfile);
                   3589:         if ($result ne 'ok') {
1.130     raeburn  3590:             $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46      raeburn  3591:         }
                   3592:     }
                   3593:     return ($url,$error);
                   3594: }
1.43      raeburn  3595: 
1.49      raeburn  3596: sub print_coursecategories {
1.57      raeburn  3597:     my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
                   3598:     my $datatable;
                   3599:     if ($position eq 'top') {
                   3600:         my $toggle_cats_crs = ' ';
                   3601:         my $toggle_cats_dom = ' checked="checked" ';
                   3602:         my $can_cat_crs = ' ';
                   3603:         my $can_cat_dom = ' checked="checked" ';
1.120     raeburn  3604:         my $toggle_catscomm_comm = ' ';
                   3605:         my $toggle_catscomm_dom = ' checked="checked" ';
                   3606:         my $can_catcomm_comm = ' ';
                   3607:         my $can_catcomm_dom = ' checked="checked" ';
                   3608: 
1.57      raeburn  3609:         if (ref($settings) eq 'HASH') {
                   3610:             if ($settings->{'togglecats'} eq 'crs') {
                   3611:                 $toggle_cats_crs = $toggle_cats_dom;
                   3612:                 $toggle_cats_dom = ' ';
                   3613:             }
                   3614:             if ($settings->{'categorize'} eq 'crs') {
                   3615:                 $can_cat_crs = $can_cat_dom;
                   3616:                 $can_cat_dom = ' ';
                   3617:             }
1.120     raeburn  3618:             if ($settings->{'togglecatscomm'} eq 'comm') {
                   3619:                 $toggle_catscomm_comm = $toggle_catscomm_dom;
                   3620:                 $toggle_catscomm_dom = ' ';
                   3621:             }
                   3622:             if ($settings->{'categorizecomm'} eq 'comm') {
                   3623:                 $can_catcomm_comm = $can_catcomm_dom;
                   3624:                 $can_catcomm_dom = ' ';
                   3625:             }
1.57      raeburn  3626:         }
                   3627:         my %title = &Apache::lonlocal::texthash (
1.120     raeburn  3628:                      togglecats     => 'Show/Hide a course in catalog',
                   3629:                      togglecatscomm => 'Show/Hide a community in catalog',
                   3630:                      categorize     => 'Assign a category to a course',
                   3631:                      categorizecomm => 'Assign a category to a community',
1.57      raeburn  3632:                     );
                   3633:         my %level = &Apache::lonlocal::texthash (
1.120     raeburn  3634:                      dom  => 'Set in Domain',
                   3635:                      crs  => 'Set in Course',
                   3636:                      comm => 'Set in Community',
1.57      raeburn  3637:                     );
                   3638:         $datatable = '<tr class="LC_odd_row">'.
                   3639:                   '<td>'.$title{'togglecats'}.'</td>'.
                   3640:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   3641:                   '<input type="radio" name="togglecats"'.
                   3642:                   $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   3643:                   '<label><input type="radio" name="togglecats"'.
                   3644:                   $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
                   3645:                   '</tr><tr>'.
                   3646:                   '<td>'.$title{'categorize'}.'</td>'.
                   3647:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
                   3648:                   '<label><input type="radio" name="categorize"'.
                   3649:                   $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   3650:                   '<label><input type="radio" name="categorize"'.
                   3651:                   $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120     raeburn  3652:                   '</tr><tr class="LC_odd_row">'.
                   3653:                   '<td>'.$title{'togglecatscomm'}.'</td>'.
                   3654:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   3655:                   '<input type="radio" name="togglecatscomm"'.
                   3656:                   $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   3657:                   '<label><input type="radio" name="togglecatscomm"'.
                   3658:                   $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
                   3659:                   '</tr><tr>'.
                   3660:                   '<td>'.$title{'categorizecomm'}.'</td>'.
                   3661:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
                   3662:                   '<label><input type="radio" name="categorizecomm"'.
                   3663:                   $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   3664:                   '<label><input type="radio" name="categorizecomm"'.
                   3665:                   $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57      raeburn  3666:                   '</tr>';
1.120     raeburn  3667:         $$rowtotal += 4;
1.57      raeburn  3668:     } else {
                   3669:         my $css_class;
                   3670:         my $itemcount = 1;
                   3671:         my $cathash; 
                   3672:         if (ref($settings) eq 'HASH') {
                   3673:             $cathash = $settings->{'cats'};
                   3674:         }
                   3675:         if (ref($cathash) eq 'HASH') {
                   3676:             my (@cats,@trails,%allitems,%idx,@jsarray);
                   3677:             &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
                   3678:                                                    \%allitems,\%idx,\@jsarray);
                   3679:             my $maxdepth = scalar(@cats);
                   3680:             my $colattrib = '';
                   3681:             if ($maxdepth > 2) {
                   3682:                 $colattrib = ' colspan="2" ';
                   3683:             }
                   3684:             my @path;
                   3685:             if (@cats > 0) {
                   3686:                 if (ref($cats[0]) eq 'ARRAY') {
                   3687:                     my $numtop = @{$cats[0]};
                   3688:                     my $maxnum = $numtop;
1.120     raeburn  3689:                     my %default_names = (
                   3690:                           instcode    => &mt('Official courses'),
                   3691:                           communities => &mt('Communities'),
                   3692:                     );
                   3693: 
                   3694:                     if ((!grep(/^instcode$/,@{$cats[0]})) || 
                   3695:                         ($cathash->{'instcode::0'} eq '') ||
                   3696:                         (!grep(/^communities$/,@{$cats[0]})) || 
                   3697:                         ($cathash->{'communities::0'} eq '')) {
1.57      raeburn  3698:                         $maxnum ++;
                   3699:                     }
                   3700:                     my $lastidx;
                   3701:                     for (my $i=0; $i<$numtop; $i++) {
                   3702:                         my $parent = $cats[0][$i];
                   3703:                         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   3704:                         my $item = &escape($parent).'::0';
                   3705:                         my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
                   3706:                         $lastidx = $idx{$item};
                   3707:                         $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
                   3708:                                       .'<select name="'.$item.'"'.$chgstr.'>';
                   3709:                         for (my $k=0; $k<=$maxnum; $k++) {
                   3710:                             my $vpos = $k+1;
                   3711:                             my $selstr;
                   3712:                             if ($k == $i) {
                   3713:                                 $selstr = ' selected="selected" ';
                   3714:                             }
                   3715:                             $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   3716:                         }
                   3717:                         $datatable .= '</select></td><td>';
1.120     raeburn  3718:                         if ($parent eq 'instcode' || $parent eq 'communities') {
                   3719:                             $datatable .=  '<span class="LC_nobreak">'
                   3720:                                            .$default_names{$parent}.'</span>';
                   3721:                             if ($parent eq 'instcode') {
                   3722:                                 $datatable .= '<br /><span class="LC_nobreak">('
                   3723:                                               .&mt('with institutional codes')
                   3724:                                               .')</span></td><td'.$colattrib.'>';
                   3725:                             } else {
                   3726:                                 $datatable .= '<table><tr><td>';
                   3727:                             }
                   3728:                             $datatable .= '<span class="LC_nobreak">'
                   3729:                                           .'<label><input type="radio" name="'
                   3730:                                           .$parent.'" value="1" checked="checked" />'
                   3731:                                           .&mt('Display').'</label>';
                   3732:                             if ($parent eq 'instcode') {
                   3733:                                 $datatable .= '&nbsp;';
                   3734:                             } else {
                   3735:                                 $datatable .= '</span></td></tr><tr><td>'
                   3736:                                               .'<span class="LC_nobreak">';
                   3737:                             }
                   3738:                             $datatable .= '<label><input type="radio" name="'
                   3739:                                           .$parent.'" value="0" />'
                   3740:                                           .&mt('Do not display').'</label></span>';
                   3741:                             if ($parent eq 'communities') {
                   3742:                                 $datatable .= '</td></tr></table>';
                   3743:                             }
                   3744:                             $datatable .= '</td>';
1.57      raeburn  3745:                         } else {
                   3746:                             $datatable .= $parent
                   3747:                                           .'&nbsp;<label><input type="checkbox" name="deletecategory" '
                   3748:                                           .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
                   3749:                         }
                   3750:                         my $depth = 1;
                   3751:                         push(@path,$parent);
                   3752:                         $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
                   3753:                         pop(@path);
                   3754:                         $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
                   3755:                         $itemcount ++;
                   3756:                     }
1.48      raeburn  3757:                     $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57      raeburn  3758:                     my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
                   3759:                     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48      raeburn  3760:                     for (my $k=0; $k<=$maxnum; $k++) {
                   3761:                         my $vpos = $k+1;
                   3762:                         my $selstr;
1.57      raeburn  3763:                         if ($k == $numtop) {
1.48      raeburn  3764:                             $selstr = ' selected="selected" ';
                   3765:                         }
                   3766:                         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   3767:                     }
1.59      bisitz   3768:                     $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').'&nbsp;'
1.57      raeburn  3769:                                   .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
                   3770:                                   .'</tr>'."\n";
1.48      raeburn  3771:                     $itemcount ++;
1.120     raeburn  3772:                     foreach my $default ('instcode','communities') {
                   3773:                         if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
                   3774:                             $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   3775:                             my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
                   3776:                             $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
                   3777:                                           '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
                   3778:                             for (my $k=0; $k<=$maxnum; $k++) {
                   3779:                                 my $vpos = $k+1;
                   3780:                                 my $selstr;
                   3781:                                 if ($k == $maxnum) {
                   3782:                                     $selstr = ' selected="selected" ';
                   3783:                                 }
                   3784:                                 $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57      raeburn  3785:                             }
1.120     raeburn  3786:                             $datatable .= '</select></span></td>'.
                   3787:                                           '<td><span class="LC_nobreak">'.
                   3788:                                           $default_names{$default}.'</span>';
                   3789:                             if ($default eq 'instcode') {
                   3790:                                 $datatable .= '<br /><span class="LC_nobreak">(' 
                   3791:                                               .&mt('with institutional codes').')</span>';
                   3792:                             }
                   3793:                             $datatable .= '</td>'
                   3794:                                           .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
                   3795:                                           .&mt('Display').'</label>&nbsp;'
                   3796:                                           .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
                   3797:                                           .&mt('Do not display').'</label></span></td></tr>';
1.48      raeburn  3798:                         }
                   3799:                     }
                   3800:                 }
1.57      raeburn  3801:             } else {
                   3802:                 $datatable .= &initialize_categories($itemcount);
1.48      raeburn  3803:             }
                   3804:         } else {
1.57      raeburn  3805:             $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[0]->{'col2'}.'</td>'
                   3806:                           .&initialize_categories($itemcount);
1.48      raeburn  3807:         }
1.57      raeburn  3808:         $$rowtotal += $itemcount;
1.48      raeburn  3809:     }
                   3810:     return $datatable;
                   3811: }
                   3812: 
1.69      raeburn  3813: sub print_serverstatuses {
                   3814:     my ($dom,$settings,$rowtotal) = @_;
                   3815:     my $datatable;
                   3816:     my @pages = &serverstatus_pages();
                   3817:     my (%namedaccess,%machineaccess);
                   3818:     foreach my $type (@pages) {
                   3819:         $namedaccess{$type} = '';
                   3820:         $machineaccess{$type}= '';
                   3821:     }
                   3822:     if (ref($settings) eq 'HASH') {
                   3823:         foreach my $type (@pages) {
                   3824:             if (exists($settings->{$type})) {
                   3825:                 if (ref($settings->{$type}) eq 'HASH') {
                   3826:                     foreach my $key (keys(%{$settings->{$type}})) {
                   3827:                         if ($key eq 'namedusers') {
                   3828:                             $namedaccess{$type} = $settings->{$type}->{$key};
                   3829:                         } elsif ($key eq 'machines') {
                   3830:                             $machineaccess{$type} = $settings->{$type}->{$key};
                   3831:                         }
                   3832:                     }
                   3833:                 }
                   3834:             }
                   3835:         }
                   3836:     }
1.81      raeburn  3837:     my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69      raeburn  3838:     my $rownum = 0;
                   3839:     my $css_class;
                   3840:     foreach my $type (@pages) {
                   3841:         $rownum ++;
                   3842:         $css_class = $rownum%2?' class="LC_odd_row"':'';
                   3843:         $datatable .= '<tr'.$css_class.'>'.
                   3844:                       '<td><span class="LC_nobreak">'.
                   3845:                       $titles->{$type}.'</span></td>'.
                   3846:                       '<td class="LC_left_item">'.
                   3847:                       '<input type="text" name="'.$type.'_namedusers" '.
                   3848:                       'value="'.$namedaccess{$type}.'" size="30" /></td>'.
                   3849:                       '<td class="LC_right_item">'.
                   3850:                       '<span class="LC_nobreak">'.
                   3851:                       '<input type="text" name="'.$type.'_machines" '.
                   3852:                       'value="'.$machineaccess{$type}.'" size="10" />'.
                   3853:                       '</td></tr>'."\n";
                   3854:     }
                   3855:     $$rowtotal += $rownum;
                   3856:     return $datatable;
                   3857: }
                   3858: 
                   3859: sub serverstatus_pages {
                   3860:     return ('userstatus','lonstatus','loncron','server-status','codeversions',
                   3861:             'clusterstatus','metadata_keywords','metadata_harvest',
1.113     raeburn  3862:             'takeoffline','takeonline','showenv','toggledebug');
1.69      raeburn  3863: }
                   3864: 
1.49      raeburn  3865: sub coursecategories_javascript {
                   3866:     my ($settings) = @_;
1.57      raeburn  3867:     my ($output,$jstext,$cathash);
1.49      raeburn  3868:     if (ref($settings) eq 'HASH') {
1.57      raeburn  3869:         $cathash = $settings->{'cats'};
                   3870:     }
                   3871:     if (ref($cathash) eq 'HASH') {
1.49      raeburn  3872:         my (@cats,@jsarray,%idx);
1.57      raeburn  3873:         &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49      raeburn  3874:         if (@jsarray > 0) {
                   3875:             $jstext = '    var categories = Array('.scalar(@jsarray).');'."\n";
                   3876:             for (my $i=0; $i<@jsarray; $i++) {
                   3877:                 if (ref($jsarray[$i]) eq 'ARRAY') {
                   3878:                     my $catstr = join('","',@{$jsarray[$i]});
                   3879:                     $jstext .= '    categories['.$i.'] = Array("'.$catstr.'");'."\n";
                   3880:                 }
                   3881:             }
                   3882:         }
                   3883:     } else {
                   3884:         $jstext  = '    var categories = Array(1);'."\n".
                   3885:                    '    categories[0] = Array("instcode_pos");'."\n"; 
                   3886:     }
1.120     raeburn  3887:     my $instcode_reserved = &mt('The name: "instcode" is a reserved category');
                   3888:     my $communities_reserved = &mt('The name: "communities" is a reserved category');
                   3889:     my $choose_again = '\\n'.&mt('Please use a different name for the new top level category'); 
1.49      raeburn  3890:     $output = <<"ENDSCRIPT";
                   3891: <script type="text/javascript">
1.109     raeburn  3892: // <![CDATA[
1.49      raeburn  3893: function reorderCats(form,parent,item,idx) {
                   3894:     var changedVal;
                   3895: $jstext
                   3896:     var newpos = 'addcategory_pos';
                   3897:     var current = new Array;
                   3898:     if (parent == '') {
                   3899:         var has_instcode = 0;
                   3900:         var maxtop = categories[idx].length;
                   3901:         for (var j=0; j<maxtop; j++) {
                   3902:             if (categories[idx][j] == 'instcode::0') {
                   3903:                 has_instcode == 1;
                   3904:             }
                   3905:         }
                   3906:         if (has_instcode == 0) {
                   3907:             categories[idx][maxtop] = 'instcode_pos';
                   3908:         }
                   3909:     } else {
                   3910:         newpos += '_'+parent;
                   3911:     }
                   3912:     var maxh = 1 + categories[idx].length;
                   3913:     var current = new Array;
                   3914:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
                   3915:     if (item == newpos) {
                   3916:         changedVal = newitemVal;
                   3917:     } else {
                   3918:         changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
                   3919:         current[newitemVal] = newpos;
                   3920:     }
                   3921:     for (var i=0; i<categories[idx].length; i++) {
                   3922:         var elementName = categories[idx][i];
                   3923:         if (elementName != item) {
                   3924:             if (form.elements[elementName]) {
                   3925:                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   3926:                 current[currVal] = elementName;
                   3927:             }
                   3928:         }
                   3929:     }
                   3930:     var oldVal;
                   3931:     for (var j=0; j<maxh; j++) {
                   3932:         if (current[j] == undefined) {
                   3933:             oldVal = j;
                   3934:         }
                   3935:     }
                   3936:     if (oldVal < changedVal) {
                   3937:         for (var k=oldVal+1; k<=changedVal ; k++) {
                   3938:            var elementName = current[k];
                   3939:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   3940:         }
                   3941:     } else {
                   3942:         for (var k=changedVal; k<oldVal; k++) {
                   3943:             var elementName = current[k];
                   3944:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   3945:         }
                   3946:     }
                   3947:     return;
                   3948: }
1.120     raeburn  3949: 
                   3950: function categoryCheck(form) {
                   3951:     if (form.elements['addcategory_name'].value == 'instcode') {
                   3952:         alert('$instcode_reserved\\n$choose_again');
                   3953:         return false;
                   3954:     }
                   3955:     if (form.elements['addcategory_name'].value == 'communities') {
                   3956:         alert('$communities_reserved\\n$choose_again');
                   3957:         return false;
                   3958:     }
                   3959:     return true;
                   3960: }
                   3961: 
1.109     raeburn  3962: // ]]>
1.49      raeburn  3963: </script>
                   3964: 
                   3965: ENDSCRIPT
                   3966:     return $output;
                   3967: }
                   3968: 
1.48      raeburn  3969: sub initialize_categories {
                   3970:     my ($itemcount) = @_;
1.120     raeburn  3971:     my ($datatable,$css_class,$chgstr);
                   3972:     my %default_names = (
                   3973:                       instcode    => 'Official courses (with institutional codes)',
                   3974:                       communities => 'Communities',
                   3975:                         );
                   3976:     my $select0 = ' selected="selected"';
                   3977:     my $select1 = '';
                   3978:     foreach my $default ('instcode','communities') {
                   3979:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   3980:         $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
                   3981:         if ($default eq 'communities') {
                   3982:             $select1 = $select0;
                   3983:             $select0 = '';
                   3984:         }
                   3985:         $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
                   3986:                      .'<select name="'.$default.'_pos">'
                   3987:                      .'<option value="0"'.$select0.'>1</option>'
                   3988:                      .'<option value="1"'.$select1.'>2</option>'
                   3989:                      .'<option value="2">3</option></select>&nbsp;'
                   3990:                      .$default_names{$default}
                   3991:                      .'</span></td><td><span class="LC_nobreak">'
                   3992:                      .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
                   3993:                      .&mt('Display').'</label>&nbsp;<label>'
                   3994:                      .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48      raeburn  3995:                  .'</label></span></td></tr>';
1.120     raeburn  3996:         $itemcount ++;
                   3997:     }
1.48      raeburn  3998:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49      raeburn  3999:     $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48      raeburn  4000:     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120     raeburn  4001:                   .'<select name="addcategory_pos"'.$chgstr.'>'
                   4002:                   .'<option value="0">1</option>'
                   4003:                   .'<option value="1">2</option>'
                   4004:                   .'<option value="2" selected="selected">3</option></select>&nbsp;'
1.48      raeburn  4005:                   .&mt('Add category').'</td><td>'.&mt('Name:')
                   4006:                   .'&nbsp;<input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
                   4007:     return $datatable;
                   4008: }
                   4009: 
                   4010: sub build_category_rows {
1.49      raeburn  4011:     my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
                   4012:     my ($text,$name,$item,$chgstr);
1.48      raeburn  4013:     if (ref($cats) eq 'ARRAY') {
                   4014:         my $maxdepth = scalar(@{$cats});
                   4015:         if (ref($cats->[$depth]) eq 'HASH') {
                   4016:             if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
                   4017:                 my $numchildren = @{$cats->[$depth]{$parent}};
                   4018:                 my $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   4019:                 $text .= '<td><table class="LC_datatable">';
1.49      raeburn  4020:                 my ($idxnum,$parent_name,$parent_item);
                   4021:                 my $higher = $depth - 1;
                   4022:                 if ($higher == 0) {
                   4023:                     $parent_name = &escape($parent).'::'.$higher;
                   4024:                 } else {
                   4025:                     if (ref($path) eq 'ARRAY') {
                   4026:                         $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
                   4027:                     }
                   4028:                 }
                   4029:                 $parent_item = 'addcategory_pos_'.$parent_name;
1.48      raeburn  4030:                 for (my $j=0; $j<=$numchildren; $j++) {
1.49      raeburn  4031:                     if ($j < $numchildren) {
1.48      raeburn  4032:                         $name = $cats->[$depth]{$parent}[$j];
                   4033:                         $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49      raeburn  4034:                         $idxnum = $idx->{$item};
                   4035:                     } else {
                   4036:                         $name = $parent_name;
                   4037:                         $item = $parent_item;
1.48      raeburn  4038:                     }
1.49      raeburn  4039:                     $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
                   4040:                     $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48      raeburn  4041:                     for (my $i=0; $i<=$numchildren; $i++) {
                   4042:                         my $vpos = $i+1;
                   4043:                         my $selstr;
                   4044:                         if ($j == $i) {
                   4045:                             $selstr = ' selected="selected" ';
                   4046:                         }
                   4047:                         $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
                   4048:                     }
                   4049:                     $text .= '</select>&nbsp;';
                   4050:                     if ($j < $numchildren) {
                   4051:                         my $deeper = $depth+1;
                   4052:                         $text .= $name.'&nbsp;'
                   4053:                                  .'<label><input type="checkbox" name="deletecategory" value="'
                   4054:                                  .$item.'" />'.&mt('Delete').'</label></span></td><td>';
                   4055:                         if(ref($path) eq 'ARRAY') {
                   4056:                             push(@{$path},$name);
1.49      raeburn  4057:                             $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48      raeburn  4058:                             pop(@{$path});
                   4059:                         }
                   4060:                     } else {
1.59      bisitz   4061:                         $text .= &mt('Add subcategory:').'&nbsp;</span><input type="textbox" size="20" name="addcategory_name_';
1.48      raeburn  4062:                         if ($j == $numchildren) {
                   4063:                             $text .= $name;
                   4064:                         } else {
                   4065:                             $text .= $item;
                   4066:                         }
                   4067:                         $text .= '" value="" />';
                   4068:                     }
                   4069:                     $text .= '</td></tr>';
                   4070:                 }
                   4071:                 $text .= '</table></td>';
                   4072:             } else {
                   4073:                 my $higher = $depth-1;
                   4074:                 if ($higher == 0) {
                   4075:                     $name = &escape($parent).'::'.$higher;
                   4076:                 } else {
                   4077:                     if (ref($path) eq 'ARRAY') {
                   4078:                         $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
                   4079:                     }
                   4080:                 }
                   4081:                 my $colspan;
                   4082:                 if ($parent ne 'instcode') {
                   4083:                     $colspan = $maxdepth - $depth - 1;
                   4084:                     $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
                   4085:                 }
                   4086:             }
                   4087:         }
                   4088:     }
                   4089:     return $text;
                   4090: }
                   4091: 
1.33      raeburn  4092: sub modifiable_userdata_row {
1.63      raeburn  4093:     my ($context,$role,$settings,$numinrow,$rowcount,$usertypes) = @_;
1.33      raeburn  4094:     my $rolename;
1.63      raeburn  4095:     if ($context eq 'selfcreate') {
                   4096:         if (ref($usertypes) eq 'HASH') {
                   4097:             $rolename = $usertypes->{$role};
                   4098:         } else {
                   4099:             $rolename = $role;
                   4100:         }
1.33      raeburn  4101:     } else {
1.63      raeburn  4102:         if ($role eq 'cr') {
                   4103:             $rolename = &mt('Custom role');
                   4104:         } else {
                   4105:             $rolename = &Apache::lonnet::plaintext($role);
                   4106:         }
1.33      raeburn  4107:     }
                   4108:     my @fields = ('lastname','firstname','middlename','generation',
                   4109:                   'permanentemail','id');
                   4110:     my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
                   4111:     my $output;
                   4112:     my $css_class = $rowcount%2?' class="LC_odd_row"':'';
                   4113:     $output = '<tr '.$css_class.'>'.
                   4114:               '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
                   4115:               '<td class="LC_left_item" colspan="2"><table>';
                   4116:     my $rem;
                   4117:     my %checks;
                   4118:     if (ref($settings) eq 'HASH') {
                   4119:         if (ref($settings->{$context}) eq 'HASH') {
                   4120:             if (ref($settings->{$context}->{$role}) eq 'HASH') {
                   4121:                 foreach my $field (@fields) {
                   4122:                     if ($settings->{$context}->{$role}->{$field}) {
                   4123:                         $checks{$field} = ' checked="checked" ';
                   4124:                     }
                   4125:                 }
                   4126:             }
                   4127:         }
                   4128:     }
                   4129:     for (my $i=0; $i<@fields; $i++) {
                   4130:         my $rem = $i%($numinrow);
                   4131:         if ($rem == 0) {
                   4132:             if ($i > 0) {
                   4133:                 $output .= '</tr>';
                   4134:             }
                   4135:             $output .= '<tr>';
                   4136:         }
                   4137:         my $check = ' ';
                   4138:         if (exists($checks{$fields[$i]})) {
                   4139:             $check = $checks{$fields[$i]}
                   4140:         } else {
                   4141:             if ($role eq 'st') {
                   4142:                 if (ref($settings) ne 'HASH') {
                   4143:                     $check = ' checked="checked" '; 
                   4144:                 }
                   4145:             }
                   4146:         }
                   4147:         $output .= '<td class="LC_left_item">'.
                   4148:                    '<span class="LC_nobreak"><label>'.
                   4149:                    '<input type="checkbox" name="canmodify_'.$role.'" '.
                   4150:                    'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
                   4151:                    '</label></span></td>';
                   4152:         $rem = @fields%($numinrow);
                   4153:     }
                   4154:     my $colsleft = $numinrow - $rem;
                   4155:     if ($colsleft > 1 ) {
                   4156:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   4157:                    '&nbsp;</td>';
                   4158:     } elsif ($colsleft == 1) {
                   4159:         $output .= '<td class="LC_left_item">&nbsp;</td>';
                   4160:     }
                   4161:     $output .= '</tr></table></td></tr>';
                   4162:     return $output;
                   4163: }
1.28      raeburn  4164: 
1.93      raeburn  4165: sub insttypes_row {
                   4166:     my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context) = @_;
                   4167:     my %lt = &Apache::lonlocal::texthash (
                   4168:                       cansearch => 'Users allowed to search',
                   4169:                       statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131     raeburn  4170:                       lockablenames => 'User preference to lock name',
1.93      raeburn  4171:              );
                   4172:     my $showdom;
                   4173:     if ($context eq 'cansearch') {
                   4174:         $showdom = ' ('.$dom.')';
                   4175:     }
1.25      raeburn  4176:     my $output =  '<tr class="LC_odd_row">'.
1.93      raeburn  4177:                   '<td>'.$lt{$context}.$showdom.
1.24      raeburn  4178:                   '</td><td class="LC_left_item" colspan="2"><table>';
1.26      raeburn  4179:     my $rem;
                   4180:     if (ref($types) eq 'ARRAY') {
                   4181:         for (my $i=0; $i<@{$types}; $i++) {
                   4182:             if (defined($usertypes->{$types->[$i]})) {
                   4183:                 my $rem = $i%($numinrow);
                   4184:                 if ($rem == 0) {
                   4185:                     if ($i > 0) {
                   4186:                         $output .= '</tr>';
                   4187:                     }
                   4188:                     $output .= '<tr>';
1.23      raeburn  4189:                 }
1.26      raeburn  4190:                 my $check = ' ';
1.99      raeburn  4191:                 if (ref($settings) eq 'HASH') {
                   4192:                     if (ref($settings->{$context}) eq 'ARRAY') {
                   4193:                         if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
                   4194:                             $check = ' checked="checked" ';
                   4195:                         }
                   4196:                     } elsif ($context eq 'statustocreate') {
1.26      raeburn  4197:                         $check = ' checked="checked" ';
                   4198:                     }
1.23      raeburn  4199:                 }
1.26      raeburn  4200:                 $output .= '<td class="LC_left_item">'.
                   4201:                            '<span class="LC_nobreak"><label>'.
1.93      raeburn  4202:                            '<input type="checkbox" name="'.$context.'" '.
1.26      raeburn  4203:                            'value="'.$types->[$i].'"'.$check.'/>'.
                   4204:                            $usertypes->{$types->[$i]}.'</label></span></td>';
1.23      raeburn  4205:             }
                   4206:         }
1.26      raeburn  4207:         $rem = @{$types}%($numinrow);
1.23      raeburn  4208:     }
                   4209:     my $colsleft = $numinrow - $rem;
1.131     raeburn  4210:     if (($rem == 0) && (@{$types} > 0)) {
                   4211:         $output .= '<tr>';
                   4212:     }
1.23      raeburn  4213:     if ($colsleft > 1) {
1.25      raeburn  4214:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23      raeburn  4215:     } else {
1.25      raeburn  4216:         $output .= '<td class="LC_left_item">';
1.23      raeburn  4217:     }
                   4218:     my $defcheck = ' ';
1.99      raeburn  4219:     if (ref($settings) eq 'HASH') {  
                   4220:         if (ref($settings->{$context}) eq 'ARRAY') {
                   4221:             if (grep(/^default$/,@{$settings->{$context}})) {
                   4222:                 $defcheck = ' checked="checked" ';
                   4223:             }
                   4224:         } elsif ($context eq 'statustocreate') {
1.26      raeburn  4225:             $defcheck = ' checked="checked" ';
                   4226:         }
1.23      raeburn  4227:     }
1.25      raeburn  4228:     $output .= '<span class="LC_nobreak"><label>'.
1.93      raeburn  4229:                '<input type="checkbox" name="'.$context.'" '.
1.25      raeburn  4230:                'value="default"'.$defcheck.'/>'.
                   4231:                $othertitle.'</label></span></td>'.
                   4232:                '</tr></table></td></tr>';
                   4233:     return $output;
1.23      raeburn  4234: }
                   4235: 
                   4236: sub sorted_searchtitles {
                   4237:     my %searchtitles = &Apache::lonlocal::texthash(
                   4238:                          'uname' => 'username',
                   4239:                          'lastname' => 'last name',
                   4240:                          'lastfirst' => 'last name, first name',
                   4241:                      );
                   4242:     my @titleorder = ('uname','lastname','lastfirst');
                   4243:     return (\%searchtitles,\@titleorder);
                   4244: }
                   4245: 
1.25      raeburn  4246: sub sorted_searchtypes {
                   4247:     my %srchtypes_desc = (
                   4248:                            exact    => 'is exact match',
                   4249:                            contains => 'contains ..',
                   4250:                            begins   => 'begins with ..',
                   4251:                          );
                   4252:     my @srchtypeorder = ('exact','begins','contains');
                   4253:     return (\%srchtypes_desc,\@srchtypeorder);
                   4254: }
                   4255: 
1.3       raeburn  4256: sub usertype_update_row {
                   4257:     my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
                   4258:     my $datatable;
                   4259:     my $numinrow = 4;
                   4260:     foreach my $type (@{$types}) {
                   4261:         if (defined($usertypes->{$type})) {
                   4262:             $$rownums ++;
                   4263:             my $css_class = $$rownums%2?' class="LC_odd_row"':'';
                   4264:             $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
                   4265:                           '</td><td class="LC_left_item"><table>';
                   4266:             for (my $i=0; $i<@{$fields}; $i++) {
                   4267:                 my $rem = $i%($numinrow);
                   4268:                 if ($rem == 0) {
                   4269:                     if ($i > 0) {
                   4270:                         $datatable .= '</tr>';
                   4271:                     }
                   4272:                     $datatable .= '<tr>';
                   4273:                 }
                   4274:                 my $check = ' ';
1.39      raeburn  4275:                 if (ref($settings) eq 'HASH') {
                   4276:                     if (ref($settings->{'fields'}) eq 'HASH') {
                   4277:                         if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
                   4278:                             if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
                   4279:                                 $check = ' checked="checked" ';
                   4280:                             }
1.3       raeburn  4281:                         }
                   4282:                     }
                   4283:                 }
                   4284: 
                   4285:                 if ($i == @{$fields}-1) {
                   4286:                     my $colsleft = $numinrow - $rem;
                   4287:                     if ($colsleft > 1) {
                   4288:                         $datatable .= '<td colspan="'.$colsleft.'">';
                   4289:                     } else {
                   4290:                         $datatable .= '<td>';
                   4291:                     }
                   4292:                 } else {
                   4293:                     $datatable .= '<td>';
                   4294:                 }
1.8       raeburn  4295:                 $datatable .= '<span class="LC_nobreak"><label>'.
                   4296:                               '<input type="checkbox" name="updateable_'.$type.
                   4297:                               '_'.$fields->[$i].'" value="1"'.$check.'/>'.
                   4298:                               $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3       raeburn  4299:             }
                   4300:             $datatable .= '</tr></table></td></tr>';
                   4301:         }
                   4302:     }
                   4303:     return $datatable;
1.1       raeburn  4304: }
                   4305: 
                   4306: sub modify_login {
1.9       raeburn  4307:     my ($r,$dom,$confname,%domconfig) = @_;
1.6       raeburn  4308:     my ($resulttext,$errors,$colchgtext,%changes,%colchanges);
1.1       raeburn  4309:     my %title = ( coursecatalog => 'Display course catalog',
1.41      raeburn  4310:                   adminmail => 'Display administrator E-mail address',
1.43      raeburn  4311:                   newuser => 'Link for visitors to create a user account',
1.41      raeburn  4312:                   loginheader => 'Log-in box header');
1.3       raeburn  4313:     my @offon = ('off','on');
1.112     raeburn  4314:     my %curr_loginvia;
                   4315:     if (ref($domconfig{login}) eq 'HASH') {
                   4316:         if (ref($domconfig{login}{loginvia}) eq 'HASH') {
                   4317:             foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
                   4318:                 $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
                   4319:             }
                   4320:         }
                   4321:     }
1.6       raeburn  4322:     my %loginhash;
1.9       raeburn  4323:     ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
                   4324:                                            \%domconfig,\%loginhash);
1.118     jms      4325:     my @toggles = ('coursecatalog','adminmail','newuser');
1.42      raeburn  4326:     foreach my $item (@toggles) {
                   4327:         $loginhash{login}{$item} = $env{'form.'.$item};
                   4328:     }
1.41      raeburn  4329:     $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6       raeburn  4330:     if (ref($colchanges{'login'}) eq 'HASH') {  
                   4331:         $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
                   4332:                                          \%loginhash);
                   4333:     }
1.110     raeburn  4334: 
1.149     raeburn  4335:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.128     raeburn  4336:     my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110     raeburn  4337:     if (keys(%servers) > 1) {
                   4338:         foreach my $lonhost (keys(%servers)) {
1.128     raeburn  4339:             next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
                   4340:             if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
                   4341:                 if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
                   4342:                     $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
                   4343:                 } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
                   4344:                     if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
                   4345:                         $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
                   4346:                         $changes{'loginvia'}{$lonhost} = 1;
                   4347:                     } else {
                   4348:                         $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
                   4349:                         $changes{'loginvia'}{$lonhost} = 1;
                   4350:                     }
                   4351:                 } else {
                   4352:                     if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
                   4353:                         $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
                   4354:                         $changes{'loginvia'}{$lonhost} = 1;
                   4355:                     }
                   4356:                 }
                   4357:                 if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
                   4358:                     foreach my $item (@loginvia_attribs) {
                   4359:                         $loginhash{login}{loginvia}{$lonhost}{$item} = '';
                   4360:                     }
                   4361:                 } else {
                   4362:                     foreach my $item (@loginvia_attribs) {
                   4363:                         my $new = $env{'form.'.$lonhost.'_'.$item};
                   4364:                         if (($item eq 'serverpath') && ($new eq 'custom')) {
                   4365:                             $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
                   4366:                             if ($env{'form.'.$lonhost.'_custompath'} eq '') {
                   4367:                                 $new = '/';
                   4368:                             }
                   4369:                         }
                   4370:                         if (($item eq 'custompath') && 
                   4371:                             ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
                   4372:                             $new = '';
                   4373:                         }
                   4374:                         if ($new ne $curr_loginvia{$lonhost}{$item}) {
                   4375:                             $changes{'loginvia'}{$lonhost} = 1;
                   4376:                         }
                   4377:                         if ($item eq 'exempt') {
                   4378:                             $new =~ s/^\s+//;
                   4379:                             $new =~ s/\s+$//;
                   4380:                             my @poss_ips = split(/\s*[,:]\s*/,$new);
                   4381:                             my @okips;
                   4382:                             foreach my $ip (@poss_ips) {
                   4383:                                 if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
                   4384:                                     if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
                   4385:                                         push(@okips,$ip); 
                   4386:                                     }
                   4387:                                 }
                   4388:                             }
                   4389:                             if (@okips > 0) {
                   4390:                                 $new = join(',',@okips); 
                   4391:                             } else {
                   4392:                                 $new = ''; 
                   4393:                             }
                   4394:                         }
                   4395: 
                   4396:                         $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
                   4397:                     }
                   4398:                 }
1.112     raeburn  4399:             } else {
1.128     raeburn  4400:                 if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
                   4401:                     $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112     raeburn  4402:                     $changes{'loginvia'}{$lonhost} = 1;
1.128     raeburn  4403:                     foreach my $item (@loginvia_attribs) {
                   4404:                         my $new = $env{'form.'.$lonhost.'_'.$item};
                   4405:                         if (($item eq 'serverpath') && ($new eq 'custom')) {
                   4406:                             if ($env{'form.'.$lonhost.'_custompath'} eq '') {
                   4407:                                 $new = '/';
                   4408:                             }
                   4409:                         }
                   4410:                         if (($item eq 'custompath') && 
                   4411:                             ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
                   4412:                             $new = '';
                   4413:                         }
                   4414:                         $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
                   4415:                     }
1.110     raeburn  4416:                 }
                   4417:             }
                   4418:         }
                   4419:     }
1.119     raeburn  4420: 
1.1       raeburn  4421:     my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
                   4422:                                              $dom);
                   4423:     if ($putresult eq 'ok') {
1.118     jms      4424:         my @toggles = ('coursecatalog','adminmail','newuser');
1.42      raeburn  4425:         my %defaultchecked = (
                   4426:                     'coursecatalog' => 'on',
                   4427:                     'adminmail'     => 'off',
1.43      raeburn  4428:                     'newuser'       => 'off',
1.42      raeburn  4429:         );
1.55      raeburn  4430:         if (ref($domconfig{'login'}) eq 'HASH') {
                   4431:             foreach my $item (@toggles) {
                   4432:                 if ($defaultchecked{$item} eq 'on') { 
                   4433:                     if (($domconfig{'login'}{$item} eq '0') &&
                   4434:                         ($env{'form.'.$item} eq '1')) {
                   4435:                         $changes{$item} = 1;
                   4436:                     } elsif (($domconfig{'login'}{$item} eq '' ||
                   4437:                               $domconfig{'login'}{$item} eq '1') &&
                   4438:                              ($env{'form.'.$item} eq '0')) {
                   4439:                         $changes{$item} = 1;
                   4440:                     }
                   4441:                 } elsif ($defaultchecked{$item} eq 'off') {
                   4442:                     if (($domconfig{'login'}{$item} eq '1') &&
                   4443:                         ($env{'form.'.$item} eq '0')) {
                   4444:                         $changes{$item} = 1;
                   4445:                     } elsif (($domconfig{'login'}{$item} eq '' ||
                   4446:                               $domconfig{'login'}{$item} eq '0') &&
                   4447:                              ($env{'form.'.$item} eq '1')) {
                   4448:                         $changes{$item} = 1;
                   4449:                     }
1.42      raeburn  4450:                 }
                   4451:             }
1.41      raeburn  4452:         }
1.6       raeburn  4453:         if (keys(%changes) > 0 || $colchgtext) {
1.41      raeburn  4454:             &Apache::loncommon::devalidate_domconfig_cache($dom);
1.1       raeburn  4455:             $resulttext = &mt('Changes made:').'<ul>';
                   4456:             foreach my $item (sort(keys(%changes))) {
1.135     bisitz   4457:                 if ($item eq 'loginvia') {
1.112     raeburn  4458:                     if (ref($changes{$item}) eq 'HASH') {
                   4459:                         $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
                   4460:                         foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128     raeburn  4461:                             if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
                   4462:                                 if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
                   4463:                                     my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
                   4464:                                     $protocol = 'http' if ($protocol ne 'https');
                   4465:                                     my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
                   4466: 
                   4467:                                     if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
                   4468:                                         $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
                   4469:                                     } else {
                   4470:                                         $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'}; 
                   4471:                                     }
                   4472:                                     $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
                   4473:                                     if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
                   4474:                                         $resulttext .= '&nbsp;'.&mt('No redirection for clients from following IPs:').'&nbsp;'.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
                   4475:                                     }
                   4476:                                     $resulttext .= '</li>';
                   4477:                                 } else {
                   4478:                                     $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
                   4479:                                 }
1.112     raeburn  4480:                             } else {
1.128     raeburn  4481:                                 $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112     raeburn  4482:                             }
                   4483:                         }
1.128     raeburn  4484:                         $resulttext .= '</ul></li>';
1.112     raeburn  4485:                     }
1.41      raeburn  4486:                 } else {
                   4487:                     $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
                   4488:                 }
1.1       raeburn  4489:             }
1.6       raeburn  4490:             $resulttext .= $colchgtext.'</ul>';
1.1       raeburn  4491:         } else {
                   4492:             $resulttext = &mt('No changes made to log-in page settings');
                   4493:         }
                   4494:     } else {
1.11      albertel 4495:         $resulttext = '<span class="LC_error">'.
                   4496: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  4497:     }
1.6       raeburn  4498:     if ($errors) {
1.9       raeburn  4499:         $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6       raeburn  4500:                        $errors.'</ul>';
                   4501:     }
                   4502:     return $resulttext;
                   4503: }
                   4504: 
                   4505: sub color_font_choices {
                   4506:     my %choices =
                   4507:         &Apache::lonlocal::texthash (
                   4508:             img => "Header",
                   4509:             bgs => "Background colors",
                   4510:             links => "Link colors",
1.55      raeburn  4511:             images => "Images",
1.6       raeburn  4512:             font => "Font color",
1.97      tempelho 4513:             fontmenu => "Font Menu",
1.76      raeburn  4514:             pgbg => "Page",
1.6       raeburn  4515:             tabbg => "Header",
                   4516:             sidebg => "Border",
                   4517:             link => "Link",
                   4518:             alink => "Active link",
                   4519:             vlink => "Visited link",
                   4520:         );
                   4521:     return %choices;
                   4522: }
                   4523: 
                   4524: sub modify_rolecolors {
1.9       raeburn  4525:     my ($r,$dom,$confname,$roles,%domconfig) = @_;
1.6       raeburn  4526:     my ($resulttext,%rolehash);
                   4527:     $rolehash{'rolecolors'} = {};
1.55      raeburn  4528:     if (ref($domconfig{'rolecolors'}) ne 'HASH') {
                   4529:         if ($domconfig{'rolecolors'} eq '') {
                   4530:             $domconfig{'rolecolors'} = {};
                   4531:         }
                   4532:     }
1.9       raeburn  4533:     my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6       raeburn  4534:                          $domconfig{'rolecolors'},$rolehash{'rolecolors'});
                   4535:     my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
                   4536:                                              $dom);
                   4537:     if ($putresult eq 'ok') {
                   4538:         if (keys(%changes) > 0) {
1.41      raeburn  4539:             &Apache::loncommon::devalidate_domconfig_cache($dom);
1.6       raeburn  4540:             $resulttext = &display_colorchgs($dom,\%changes,$roles,
                   4541:                                              $rolehash{'rolecolors'});
                   4542:         } else {
                   4543:             $resulttext = &mt('No changes made to default color schemes');
                   4544:         }
                   4545:     } else {
1.11      albertel 4546:         $resulttext = '<span class="LC_error">'.
                   4547: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.6       raeburn  4548:     }
                   4549:     if ($errors) {
                   4550:         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
                   4551:                        $errors.'</ul>';
                   4552:     }
                   4553:     return $resulttext;
                   4554: }
                   4555: 
                   4556: sub modify_colors {
1.9       raeburn  4557:     my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12      raeburn  4558:     my (%changes,%choices);
1.51      raeburn  4559:     my @bgs;
1.6       raeburn  4560:     my @links = ('link','alink','vlink');
1.41      raeburn  4561:     my @logintext;
1.6       raeburn  4562:     my @images;
                   4563:     my $servadm = $r->dir_config('lonAdmEMail');
                   4564:     my $errors;
                   4565:     foreach my $role (@{$roles}) {
                   4566:         if ($role eq 'login') {
1.12      raeburn  4567:             %choices = &login_choices();
1.41      raeburn  4568:             @logintext = ('textcol','bgcol');
1.12      raeburn  4569:         } else {
                   4570:             %choices = &color_font_choices();
1.107     raeburn  4571:             $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
1.12      raeburn  4572:         }
                   4573:         if ($role eq 'login') {
1.41      raeburn  4574:             @images = ('img','logo','domlogo','login');
1.51      raeburn  4575:             @bgs = ('pgbg','mainbg','sidebg');
1.6       raeburn  4576:         } else {
                   4577:             @images = ('img');
1.51      raeburn  4578:             @bgs = ('pgbg','tabbg','sidebg'); 
1.6       raeburn  4579:         }
                   4580:         $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
1.41      raeburn  4581:         foreach my $item (@bgs,@links,@logintext) {
1.6       raeburn  4582:             $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
                   4583:         }
1.46      raeburn  4584:         my ($configuserok,$author_ok,$switchserver) = 
                   4585:             &config_check($dom,$confname,$servadm);
1.9       raeburn  4586:         my ($width,$height) = &thumb_dimensions();
1.40      raeburn  4587:         if (ref($domconfig->{$role}) ne 'HASH') {
                   4588:             $domconfig->{$role} = {};
                   4589:         }
1.8       raeburn  4590:         foreach my $img (@images) {
1.70      raeburn  4591:             if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {  
                   4592:                 if (defined($env{'form.login_showlogo_'.$img})) {
                   4593:                     $confhash->{$role}{'showlogo'}{$img} = 1;
                   4594:                 } else { 
                   4595:                     $confhash->{$role}{'showlogo'}{$img} = 0;
                   4596:                 }
                   4597:             } 
1.18      albertel 4598: 	    if ( ! $env{'form.'.$role.'_'.$img.'.filename'} 
                   4599: 		 && !defined($domconfig->{$role}{$img})
                   4600: 		 && !$env{'form.'.$role.'_del_'.$img}
                   4601: 		 && $env{'form.'.$role.'_import_'.$img}) {
                   4602: 		# import the old configured image from the .tab setting
                   4603: 		# if they haven't provided a new one 
                   4604: 		$domconfig->{$role}{$img} = 
                   4605: 		    $env{'form.'.$role.'_import_'.$img};
                   4606: 	    }
1.6       raeburn  4607:             if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9       raeburn  4608:                 my $error;
1.6       raeburn  4609:                 if ($configuserok eq 'ok') {
1.9       raeburn  4610:                     if ($switchserver) {
1.12      raeburn  4611:                         $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9       raeburn  4612:                     } else {
                   4613:                         if ($author_ok eq 'ok') {
                   4614:                             my ($result,$logourl) = 
                   4615:                                 &publishlogo($r,'upload',$role.'_'.$img,
                   4616:                                            $dom,$confname,$img,$width,$height);
                   4617:                             if ($result eq 'ok') {
                   4618:                                 $confhash->{$role}{$img} = $logourl;
1.12      raeburn  4619:                                 $changes{$role}{'images'}{$img} = 1;
1.9       raeburn  4620:                             } else {
1.12      raeburn  4621:                                 $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  4622:                             }
                   4623:                         } else {
1.46      raeburn  4624:                             $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  4625:                         }
                   4626:                     }
                   4627:                 } else {
1.46      raeburn  4628:                     $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  4629:                 }
                   4630:                 if ($error) {
1.8       raeburn  4631:                     &Apache::lonnet::logthis($error);
1.11      albertel 4632:                     $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8       raeburn  4633:                 }
                   4634:             } elsif ($domconfig->{$role}{$img} ne '') {
1.9       raeburn  4635:                 if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
                   4636:                     my $error;
                   4637:                     if ($configuserok eq 'ok') {
                   4638: # is confname an author?
                   4639:                         if ($switchserver eq '') {
                   4640:                             if ($author_ok eq 'ok') {
                   4641:                                 my ($result,$logourl) = 
                   4642:                                &publishlogo($r,'copy',$domconfig->{$role}{$img},
                   4643:                                             $dom,$confname,$img,$width,$height);
                   4644:                                 if ($result eq 'ok') {
                   4645:                                     $confhash->{$role}{$img} = $logourl;
1.18      albertel 4646: 				    $changes{$role}{'images'}{$img} = 1;
1.9       raeburn  4647:                                 }
                   4648:                             }
                   4649:                         }
                   4650:                     }
1.6       raeburn  4651:                 }
                   4652:             }
                   4653:         }
                   4654:         if (ref($domconfig) eq 'HASH') {
                   4655:             if (ref($domconfig->{$role}) eq 'HASH') {
                   4656:                 foreach my $img (@images) {
                   4657:                     if ($domconfig->{$role}{$img} ne '') {
                   4658:                         if ($env{'form.'.$role.'_del_'.$img}) {
                   4659:                             $confhash->{$role}{$img} = '';
1.12      raeburn  4660:                             $changes{$role}{'images'}{$img} = 1;
1.6       raeburn  4661:                         } else {
1.9       raeburn  4662:                             if ($confhash->{$role}{$img} eq '') {
                   4663:                                 $confhash->{$role}{$img} = $domconfig->{$role}{$img};
                   4664:                             }
1.6       raeburn  4665:                         }
                   4666:                     } else {
                   4667:                         if ($env{'form.'.$role.'_del_'.$img}) {
                   4668:                             $confhash->{$role}{$img} = '';
1.12      raeburn  4669:                             $changes{$role}{'images'}{$img} = 1;
1.6       raeburn  4670:                         } 
                   4671:                     }
1.70      raeburn  4672:                     if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
                   4673:                         if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
                   4674:                             if ($confhash->{$role}{'showlogo'}{$img} ne 
                   4675:                                 $domconfig->{$role}{'showlogo'}{$img}) {
                   4676:                                 $changes{$role}{'showlogo'}{$img} = 1; 
                   4677:                             }
                   4678:                         } else {
                   4679:                             if ($confhash->{$role}{'showlogo'}{$img} == 0) {
                   4680:                                 $changes{$role}{'showlogo'}{$img} = 1;
                   4681:                             }
                   4682:                         }
                   4683:                     }
                   4684:                 }
1.6       raeburn  4685:                 if ($domconfig->{$role}{'font'} ne '') {
                   4686:                     if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
                   4687:                         $changes{$role}{'font'} = 1;
                   4688:                     }
                   4689:                 } else {
                   4690:                     if ($confhash->{$role}{'font'}) {
                   4691:                         $changes{$role}{'font'} = 1;
                   4692:                     }
                   4693:                 }
1.107     raeburn  4694:                 if ($role ne 'login') {
                   4695:                     if ($domconfig->{$role}{'fontmenu'} ne '') {
                   4696:                         if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
                   4697:                             $changes{$role}{'fontmenu'} = 1;
                   4698:                         }
                   4699:                     } else {
                   4700:                         if ($confhash->{$role}{'fontmenu'}) {
                   4701:                             $changes{$role}{'fontmenu'} = 1;
                   4702:                         }
1.97      tempelho 4703:                     }
                   4704:                 }
1.6       raeburn  4705:                 foreach my $item (@bgs) {
                   4706:                     if ($domconfig->{$role}{$item} ne '') {
                   4707:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
                   4708:                             $changes{$role}{'bgs'}{$item} = 1;
                   4709:                         } 
                   4710:                     } else {
                   4711:                         if ($confhash->{$role}{$item}) {
                   4712:                             $changes{$role}{'bgs'}{$item} = 1;
                   4713:                         }
                   4714:                     }
                   4715:                 }
                   4716:                 foreach my $item (@links) {
                   4717:                     if ($domconfig->{$role}{$item} ne '') {
                   4718:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
                   4719:                             $changes{$role}{'links'}{$item} = 1;
                   4720:                         }
                   4721:                     } else {
                   4722:                         if ($confhash->{$role}{$item}) {
                   4723:                             $changes{$role}{'links'}{$item} = 1;
                   4724:                         }
                   4725:                     }
                   4726:                 }
1.41      raeburn  4727:                 foreach my $item (@logintext) {
                   4728:                     if ($domconfig->{$role}{$item} ne '') {
                   4729:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
                   4730:                             $changes{$role}{'logintext'}{$item} = 1;
                   4731:                         }
                   4732:                     } else {
                   4733:                         if ($confhash->{$role}{$item}) {
                   4734:                             $changes{$role}{'logintext'}{$item} = 1;
                   4735:                         }
                   4736:                     }
                   4737:                 }
1.6       raeburn  4738:             } else {
                   4739:                 &default_change_checker($role,\@images,\@links,\@bgs,
1.41      raeburn  4740:                                         \@logintext,$confhash,\%changes); 
1.6       raeburn  4741:             }
                   4742:         } else {
                   4743:             &default_change_checker($role,\@images,\@links,\@bgs,
1.41      raeburn  4744:                                     \@logintext,$confhash,\%changes); 
1.6       raeburn  4745:         }
                   4746:     }
                   4747:     return ($errors,%changes);
                   4748: }
                   4749: 
1.46      raeburn  4750: sub config_check {
                   4751:     my ($dom,$confname,$servadm) = @_;
                   4752:     my ($configuserok,$author_ok,$switchserver,%currroles);
                   4753:     my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
                   4754:     ($configuserok,%currroles) = &check_configuser($uhome,$dom,
                   4755:                                                    $confname,$servadm);
                   4756:     if ($configuserok eq 'ok') {
                   4757:         $switchserver = &check_switchserver($dom,$confname);
                   4758:         if ($switchserver eq '') {
                   4759:             $author_ok = &check_authorstatus($dom,$confname,%currroles);
                   4760:         }
                   4761:     }
                   4762:     return ($configuserok,$author_ok,$switchserver);
                   4763: }
                   4764: 
1.6       raeburn  4765: sub default_change_checker {
1.41      raeburn  4766:     my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6       raeburn  4767:     foreach my $item (@{$links}) {
                   4768:         if ($confhash->{$role}{$item}) {
                   4769:             $changes->{$role}{'links'}{$item} = 1;
                   4770:         }
                   4771:     }
                   4772:     foreach my $item (@{$bgs}) {
                   4773:         if ($confhash->{$role}{$item}) {
                   4774:             $changes->{$role}{'bgs'}{$item} = 1;
                   4775:         }
                   4776:     }
1.41      raeburn  4777:     foreach my $item (@{$logintext}) {
                   4778:         if ($confhash->{$role}{$item}) {
                   4779:             $changes->{$role}{'logintext'}{$item} = 1;
                   4780:         }
                   4781:     }
1.6       raeburn  4782:     foreach my $img (@{$images}) {
                   4783:         if ($env{'form.'.$role.'_del_'.$img}) {
                   4784:             $confhash->{$role}{$img} = '';
1.12      raeburn  4785:             $changes->{$role}{'images'}{$img} = 1;
1.6       raeburn  4786:         }
1.70      raeburn  4787:         if ($role eq 'login') {
                   4788:             if ($confhash->{$role}{'showlogo'}{$img} == 0) {
                   4789:                 $changes->{$role}{'showlogo'}{$img} = 1;
                   4790:             }
                   4791:         }
1.6       raeburn  4792:     }
                   4793:     if ($confhash->{$role}{'font'}) {
                   4794:         $changes->{$role}{'font'} = 1;
                   4795:     }
1.48      raeburn  4796: }
1.6       raeburn  4797: 
                   4798: sub display_colorchgs {
                   4799:     my ($dom,$changes,$roles,$confhash) = @_;
                   4800:     my (%choices,$resulttext);
                   4801:     if (!grep(/^login$/,@{$roles})) {
                   4802:         $resulttext = &mt('Changes made:').'<br />';
                   4803:     }
                   4804:     foreach my $role (@{$roles}) {
                   4805:         if ($role eq 'login') {
                   4806:             %choices = &login_choices();
                   4807:         } else {
                   4808:             %choices = &color_font_choices();
                   4809:         }
                   4810:         if (ref($changes->{$role}) eq 'HASH') {
                   4811:             if ($role ne 'login') {
                   4812:                 $resulttext .= '<h4>'.&mt($role).'</h4>';
                   4813:             }
                   4814:             foreach my $key (sort(keys(%{$changes->{$role}}))) {
                   4815:                 if ($role ne 'login') {
                   4816:                     $resulttext .= '<ul>';
                   4817:                 }
                   4818:                 if (ref($changes->{$role}{$key}) eq 'HASH') {
                   4819:                     if ($role ne 'login') {
                   4820:                         $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
                   4821:                     }
                   4822:                     foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70      raeburn  4823:                         if (($role eq 'login') && ($key eq 'showlogo')) {
                   4824:                             if ($confhash->{$role}{$key}{$item}) {
                   4825:                                 $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
                   4826:                             } else {
                   4827:                                 $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
                   4828:                             }
                   4829:                         } elsif ($confhash->{$role}{$item} eq '') {
1.6       raeburn  4830:                             $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
                   4831:                         } else {
1.12      raeburn  4832:                             my $newitem = $confhash->{$role}{$item};
                   4833:                             if ($key eq 'images') {
                   4834:                                 $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
                   4835:                             }
                   4836:                             $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6       raeburn  4837:                         }
                   4838:                     }
                   4839:                     if ($role ne 'login') {
                   4840:                         $resulttext .= '</ul></li>';
                   4841:                     }
                   4842:                 } else {
                   4843:                     if ($confhash->{$role}{$key} eq '') {
                   4844:                         $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
                   4845:                     } else {
                   4846:                         $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
                   4847:                     }
                   4848:                 }
                   4849:                 if ($role ne 'login') {
                   4850:                     $resulttext .= '</ul>';
                   4851:                 }
                   4852:             }
                   4853:         }
                   4854:     }
1.3       raeburn  4855:     return $resulttext;
1.1       raeburn  4856: }
                   4857: 
1.9       raeburn  4858: sub thumb_dimensions {
                   4859:     return ('200','50');
                   4860: }
                   4861: 
1.16      raeburn  4862: sub check_dimensions {
                   4863:     my ($inputfile) = @_;
                   4864:     my ($fullwidth,$fullheight);
                   4865:     if ($inputfile =~ m|^[/\w.\-]+$|) {
                   4866:         if (open(PIPE,"identify $inputfile 2>&1 |")) {
                   4867:             my $imageinfo = <PIPE>;
                   4868:             if (!close(PIPE)) {
                   4869:                 &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
                   4870:             }
                   4871:             chomp($imageinfo);
                   4872:             my ($fullsize) = 
1.21      raeburn  4873:                 ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16      raeburn  4874:             if ($fullsize) {
                   4875:                 ($fullwidth,$fullheight) = split(/x/,$fullsize);
                   4876:             }
                   4877:         }
                   4878:     }
                   4879:     return ($fullwidth,$fullheight);
                   4880: }
                   4881: 
1.9       raeburn  4882: sub check_configuser {
                   4883:     my ($uhome,$dom,$confname,$servadm) = @_;
                   4884:     my ($configuserok,%currroles);
                   4885:     if ($uhome eq 'no_host') {
                   4886:         srand( time() ^ ($$ + ($$ << 15))  ); # Seed rand.
                   4887:         my $configpass = &LONCAPA::Enrollment::create_password();
                   4888:         $configuserok = 
                   4889:             &Apache::lonnet::modifyuser($dom,$confname,'','internal',
                   4890:                              $configpass,'','','','','',undef,$servadm);
                   4891:     } else {
                   4892:         $configuserok = 'ok';
                   4893:         %currroles = 
                   4894:             &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
                   4895:     }
                   4896:     return ($configuserok,%currroles);
                   4897: }
                   4898: 
                   4899: sub check_authorstatus {
                   4900:     my ($dom,$confname,%currroles) = @_;
                   4901:     my $author_ok;
1.40      raeburn  4902:     if (!$currroles{':'.$dom.':au'}) {
1.9       raeburn  4903:         my $start = time;
                   4904:         my $end = 0;
                   4905:         $author_ok = 
                   4906:             &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47      raeburn  4907:                                         'au',$end,$start,'','','domconfig');
1.9       raeburn  4908:     } else {
                   4909:         $author_ok = 'ok';
                   4910:     }
                   4911:     return $author_ok;
                   4912: }
                   4913: 
                   4914: sub publishlogo {
1.46      raeburn  4915:     my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9       raeburn  4916:     my ($output,$fname,$logourl);
                   4917:     if ($action eq 'upload') {
                   4918:         $fname=$env{'form.'.$formname.'.filename'};
                   4919:         chop($env{'form.'.$formname});
                   4920:     } else {
                   4921:         ($fname) = ($formname =~ /([^\/]+)$/);
                   4922:     }
1.46      raeburn  4923:     if ($savefileas ne '') {
                   4924:         $fname = $savefileas;
                   4925:     }
1.9       raeburn  4926:     $fname=&Apache::lonnet::clean_filename($fname);
                   4927: # See if there is anything left
                   4928:     unless ($fname) { return ('error: no uploaded file'); }
                   4929:     $fname="$subdir/$fname";
                   4930:     my $filepath='/home/'.$confname.'/public_html';
                   4931:     my ($fnamepath,$file,$fetchthumb);
                   4932:     $file=$fname;
                   4933:     if ($fname=~m|/|) {
                   4934:         ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
                   4935:     }
                   4936:     my @parts=split(/\//,$filepath.'/'.$fnamepath);
                   4937:     my $count;
                   4938:     for ($count=4;$count<=$#parts;$count++) {
                   4939:         $filepath.="/$parts[$count]";
                   4940:         if ((-e $filepath)!=1) {
                   4941:             mkdir($filepath,02770);
                   4942:         }
                   4943:     }
                   4944:     # Check for bad extension and disallow upload
                   4945:     if ($file=~/\.(\w+)$/ &&
                   4946:         (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
                   4947:         $output = 
                   4948:             &mt('Invalid file extension ([_1]) - reserved for LONCAPA use.',$1); 
                   4949:     } elsif ($file=~/\.(\w+)$/ &&
                   4950:         !defined(&Apache::loncommon::fileembstyle($1))) {
                   4951:         $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
                   4952:     } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.46      raeburn  4953:         $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  4954:     } elsif (-d "$filepath/$file") {
                   4955:         $output = &mt('File name is a directory name - rename the file and re-upload');
                   4956:     } else {
                   4957:         my $source = $filepath.'/'.$file;
                   4958:         my $logfile;
                   4959:         if (!open($logfile,">>$source".'.log')) {
                   4960:             return (&mt('No write permission to Construction Space'));
                   4961:         }
                   4962:         print $logfile
                   4963: "\n================= Publish ".localtime()." ================\n".
                   4964: $env{'user.name'}.':'.$env{'user.domain'}."\n";
                   4965: # Save the file
                   4966:         if (!open(FH,'>'.$source)) {
                   4967:             &Apache::lonnet::logthis('Failed to create '.$source);
                   4968:             return (&mt('Failed to create file'));
                   4969:         }
                   4970:         if ($action eq 'upload') {
                   4971:             if (!print FH ($env{'form.'.$formname})) {
                   4972:                 &Apache::lonnet::logthis('Failed to write to '.$source);
                   4973:                 return (&mt('Failed to write file'));
                   4974:             }
                   4975:         } else {
                   4976:             my $original = &Apache::lonnet::filelocation('',$formname);
                   4977:             if(!copy($original,$source)) {
                   4978:                 &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
                   4979:                 return (&mt('Failed to write file'));
                   4980:             }
                   4981:         }
                   4982:         close(FH);
                   4983:         chmod(0660, $source); # Permissions to rw-rw---.
                   4984: 
                   4985:         my $docroot=$r->dir_config('lonDocRoot');
                   4986:         my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
                   4987:         my $copyfile=$targetdir.'/'.$file;
                   4988: 
                   4989:         my @parts=split(/\//,$targetdir);
                   4990:         my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
                   4991:         for (my $count=5;$count<=$#parts;$count++) {
                   4992:             $path.="/$parts[$count]";
                   4993:             if (!-e $path) {
                   4994:                 print $logfile "\nCreating directory ".$path;
                   4995:                 mkdir($path,02770);
                   4996:             }
                   4997:         }
                   4998:         my $versionresult;
                   4999:         if (-e $copyfile) {
                   5000:             $versionresult = &logo_versioning($targetdir,$file,$logfile);
                   5001:         } else {
                   5002:             $versionresult = 'ok';
                   5003:         }
                   5004:         if ($versionresult eq 'ok') {
                   5005:             if (copy($source,$copyfile)) {
                   5006:                 print $logfile "\nCopied original source to ".$copyfile."\n";
                   5007:                 $output = 'ok';
                   5008:                 &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
                   5009:                 $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
                   5010:             } else {
                   5011:                 print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
                   5012:                 $output = &mt('Failed to copy file to RES space').", $!";
                   5013:             }
                   5014:             if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
                   5015:                 my $inputfile = $filepath.'/'.$file;
                   5016:                 my $outfile = $filepath.'/'.'tn-'.$file;
1.16      raeburn  5017:                 my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
                   5018:                 if ($fullwidth ne '' && $fullheight ne '') { 
                   5019:                     if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
                   5020:                         my $thumbsize = $thumbwidth.'x'.$thumbheight;
                   5021:                         system("convert -sample $thumbsize $inputfile $outfile");
                   5022:                         chmod(0660, $filepath.'/tn-'.$file);
                   5023:                         if (-e $outfile) {
                   5024:                             my $copyfile=$targetdir.'/tn-'.$file;
                   5025:                             if (copy($outfile,$copyfile)) {
                   5026:                                 print $logfile "\nCopied source to ".$copyfile."\n";
                   5027:                                 &write_metadata($dom,$confname,$formname,
                   5028:                                                 $targetdir,'tn-'.$file,$logfile);
                   5029:                             } else {
                   5030:                                 print $logfile "\nUnable to write ".$copyfile.
                   5031:                                                ':'.$!."\n";
                   5032:                             }
                   5033:                         }
1.9       raeburn  5034:                     }
                   5035:                 }
                   5036:             }
                   5037:         } else {
                   5038:             $output = $versionresult;
                   5039:         }
                   5040:     }
                   5041:     return ($output,$logourl);
                   5042: }
                   5043: 
                   5044: sub logo_versioning {
                   5045:     my ($targetdir,$file,$logfile) = @_;
                   5046:     my $target = $targetdir.'/'.$file;
                   5047:     my ($maxversion,$fn,$extn,$output);
                   5048:     $maxversion = 0;
                   5049:     if ($file =~ /^(.+)\.(\w+)$/) {
                   5050:         $fn=$1;
                   5051:         $extn=$2;
                   5052:     }
                   5053:     opendir(DIR,$targetdir);
                   5054:     while (my $filename=readdir(DIR)) {
                   5055:         if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
                   5056:             $maxversion=($1>$maxversion)?$1:$maxversion;
                   5057:         }
                   5058:     }
                   5059:     $maxversion++;
                   5060:     print $logfile "\nCreating old version ".$maxversion."\n";
                   5061:     my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
                   5062:     if (copy($target,$copyfile)) {
                   5063:         print $logfile "Copied old target to ".$copyfile."\n";
                   5064:         $copyfile=$copyfile.'.meta';
                   5065:         if (copy($target.'.meta',$copyfile)) {
                   5066:             print $logfile "Copied old target metadata to ".$copyfile."\n";
                   5067:             $output = 'ok';
                   5068:         } else {
                   5069:             print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
                   5070:             $output = &mt('Failed to copy old meta').", $!, ";
                   5071:         }
                   5072:     } else {
                   5073:         print $logfile "Unable to write ".$copyfile.':'.$!."\n";
                   5074:         $output = &mt('Failed to copy old target').", $!, ";
                   5075:     }
                   5076:     return $output;
                   5077: }
                   5078: 
                   5079: sub write_metadata {
                   5080:     my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
                   5081:     my (%metadatafields,%metadatakeys,$output);
                   5082:     $metadatafields{'title'}=$formname;
                   5083:     $metadatafields{'creationdate'}=time;
                   5084:     $metadatafields{'lastrevisiondate'}=time;
                   5085:     $metadatafields{'copyright'}='public';
                   5086:     $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
                   5087:                                          $env{'user.domain'};
                   5088:     $metadatafields{'authorspace'}=$confname.':'.$dom;
                   5089:     $metadatafields{'domain'}=$dom;
                   5090:     {
                   5091:         print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
                   5092:         my $mfh;
                   5093:         unless (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
                   5094:             $output = &mt('Could not write metadata');
                   5095:         }
                   5096:         foreach (sort keys %metadatafields) {
                   5097:             unless ($_=~/\./) {
                   5098:                 my $unikey=$_;
                   5099:                 $unikey=~/^([A-Za-z]+)/;
                   5100:                 my $tag=$1;
                   5101:                 $tag=~tr/A-Z/a-z/;
                   5102:                 print $mfh "\n\<$tag";
                   5103:                 foreach (split(/\,/,$metadatakeys{$unikey})) {
                   5104:                     my $value=$metadatafields{$unikey.'.'.$_};
                   5105:                     $value=~s/\"/\'\'/g;
                   5106:                     print $mfh ' '.$_.'="'.$value.'"';
                   5107:                 }
                   5108:                 print $mfh '>'.
                   5109:                     &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
                   5110:                         .'</'.$tag.'>';
                   5111:             }
                   5112:         }
                   5113:         $output = 'ok';
                   5114:         print $logfile "\nWrote metadata";
                   5115:         close($mfh);
                   5116:     }
                   5117: }
                   5118: 
                   5119: sub check_switchserver {
                   5120:     my ($dom,$confname) = @_;
                   5121:     my ($allowed,$switchserver);
                   5122:     my $home = &Apache::lonnet::homeserver($confname,$dom);
                   5123:     if ($home eq 'no_host') {
                   5124:         $home = &Apache::lonnet::domain($dom,'primary');
                   5125:     }
                   5126:     my @ids=&Apache::lonnet::current_machine_ids();
1.10      albertel 5127:     foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
                   5128:     if (!$allowed) {
                   5129: 	$switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/">'.&mt('Switch Server').'</a>';
1.9       raeburn  5130:     }
                   5131:     return $switchserver;
                   5132: }
                   5133: 
1.1       raeburn  5134: sub modify_quotas {
1.86      raeburn  5135:     my ($dom,$action,%domconfig) = @_;
1.101     raeburn  5136:     my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
                   5137:         %limithash,$toolregexp,%conditions,$resulttext,%changes);
1.86      raeburn  5138:     if ($action eq 'quotas') {
                   5139:         $context = 'tools'; 
                   5140:     } else { 
                   5141:         $context = $action;
                   5142:     }
                   5143:     if ($context eq 'requestcourses') {
1.98      raeburn  5144:         @usertools = ('official','unofficial','community');
1.106     raeburn  5145:         @options =('norequest','approval','validate','autolimit');
1.101     raeburn  5146:         %validations = &Apache::lonnet::auto_courserequest_checks($dom);
                   5147:         %titles = &courserequest_titles();
                   5148:         $toolregexp = join('|',@usertools);
                   5149:         %conditions = &courserequest_conditions();
1.86      raeburn  5150:     } else {
                   5151:         @usertools = ('aboutme','blog','portfolio');
1.101     raeburn  5152:         %titles = &tool_titles();
1.86      raeburn  5153:     }
1.72      raeburn  5154:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.44      raeburn  5155:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1       raeburn  5156:     foreach my $key (keys(%env)) {
1.101     raeburn  5157:         if ($context eq 'requestcourses') {
                   5158:             if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
                   5159:                 my $item = $1;
                   5160:                 my $type = $2;
                   5161:                 if ($type =~ /^limit_(.+)/) {
                   5162:                     $limithash{$item}{$1} = $env{$key};
                   5163:                 } else {
                   5164:                     $confhash{$item}{$type} = $env{$key};
                   5165:                 }
                   5166:             }
                   5167:         } else {
1.86      raeburn  5168:             if ($key =~ /^form\.quota_(.+)$/) {
                   5169:                 $confhash{'defaultquota'}{$1} = $env{$key};
                   5170:             }
1.101     raeburn  5171:             if ($key =~ /^form\.\Q$context\E_(.+)$/) {
                   5172:                 @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
                   5173:             }
1.72      raeburn  5174:         }
                   5175:     }
1.102     raeburn  5176:     if ($context eq 'requestcourses') {
                   5177:         my @approvalnotify = &Apache::loncommon::get_env_multiple('form.reqapprovalnotify');
                   5178:         @approvalnotify = sort(@approvalnotify);
                   5179:         $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
                   5180:         if (ref($domconfig{$action}) eq 'HASH') {
                   5181:             if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
                   5182:                 if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
                   5183:                     $changes{'notify'}{'approval'} = 1;
                   5184:                 }
                   5185:             } else {
1.144     raeburn  5186:                 if ($confhash{'notify'}{'approval'}) {
1.102     raeburn  5187:                     $changes{'notify'}{'approval'} = 1;
                   5188:                 }
                   5189:             }
                   5190:         } else {
1.144     raeburn  5191:             if ($confhash{'notify'}{'approval'}) {
1.102     raeburn  5192:                 $changes{'notify'}{'approval'} = 1;
                   5193:             }
                   5194:         }
                   5195:     } else {
1.86      raeburn  5196:         $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
                   5197:     }
1.72      raeburn  5198:     foreach my $item (@usertools) {
                   5199:         foreach my $type (@{$types},'default','_LC_adv') {
1.104     raeburn  5200:             my $unset; 
1.101     raeburn  5201:             if ($context eq 'requestcourses') {
1.104     raeburn  5202:                 $unset = '0';
                   5203:                 if ($type eq '_LC_adv') {
                   5204:                     $unset = '';
                   5205:                 }
1.101     raeburn  5206:                 if ($confhash{$item}{$type} eq 'autolimit') {
                   5207:                     $confhash{$item}{$type} .= '=';
                   5208:                     unless ($limithash{$item}{$type} =~ /\D/) {
                   5209:                         $confhash{$item}{$type} .= $limithash{$item}{$type};
                   5210:                     }
                   5211:                 }
1.72      raeburn  5212:             } else {
1.101     raeburn  5213:                 if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
                   5214:                     $confhash{$item}{$type} = 1;
                   5215:                 } else {
                   5216:                     $confhash{$item}{$type} = 0;
                   5217:                 }
1.72      raeburn  5218:             }
1.86      raeburn  5219:             if (ref($domconfig{$action}) eq 'HASH') {
                   5220:                 if (ref($domconfig{$action}{$item}) eq 'HASH') {
                   5221:                     if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
                   5222:                         $changes{$item}{$type} = 1;
                   5223:                     }
                   5224:                 } else {
                   5225:                     if ($context eq 'requestcourses') {
1.104     raeburn  5226:                         if ($confhash{$item}{$type} ne $unset) {
1.86      raeburn  5227:                             $changes{$item}{$type} = 1;
                   5228:                         }
                   5229:                     } else {
                   5230:                         if (!$confhash{$item}{$type}) {
                   5231:                             $changes{$item}{$type} = 1;
                   5232:                         }
                   5233:                     }
                   5234:                 }
                   5235:             } else {
                   5236:                 if ($context eq 'requestcourses') {
1.104     raeburn  5237:                     if ($confhash{$item}{$type} ne $unset) {
1.72      raeburn  5238:                         $changes{$item}{$type} = 1;
                   5239:                     }
                   5240:                 } else {
                   5241:                     if (!$confhash{$item}{$type}) {
                   5242:                         $changes{$item}{$type} = 1;
                   5243:                     }
                   5244:                 }
                   5245:             }
1.1       raeburn  5246:         }
                   5247:     }
1.86      raeburn  5248:     unless ($context eq 'requestcourses') {
                   5249:         if (ref($domconfig{'quotas'}) eq 'HASH') {
                   5250:             if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
                   5251:                 foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
                   5252:                     if (exists($confhash{'defaultquota'}{$key})) {
                   5253:                         if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
                   5254:                             $changes{'defaultquota'}{$key} = 1;
                   5255:                         }
                   5256:                     } else {
                   5257:                         $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72      raeburn  5258:                     }
                   5259:                 }
1.86      raeburn  5260:             } else {
                   5261:                 foreach my $key (keys(%{$domconfig{'quotas'}})) {
                   5262:                     if (exists($confhash{'defaultquota'}{$key})) {
                   5263:                         if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
                   5264:                             $changes{'defaultquota'}{$key} = 1;
                   5265:                         }
                   5266:                     } else {
                   5267:                         $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72      raeburn  5268:                     }
1.1       raeburn  5269:                 }
                   5270:             }
                   5271:         }
1.86      raeburn  5272:         if (ref($confhash{'defaultquota'}) eq 'HASH') {
                   5273:             foreach my $key (keys(%{$confhash{'defaultquota'}})) {
                   5274:                 if (ref($domconfig{'quotas'}) eq 'HASH') {
                   5275:                     if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
                   5276:                         if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
                   5277:                             $changes{'defaultquota'}{$key} = 1;
                   5278:                         }
                   5279:                     } else {
                   5280:                         if (!exists($domconfig{'quotas'}{$key})) {
                   5281:                             $changes{'defaultquota'}{$key} = 1;
                   5282:                         }
1.72      raeburn  5283:                     }
                   5284:                 } else {
1.86      raeburn  5285:                     $changes{'defaultquota'}{$key} = 1;
1.55      raeburn  5286:                 }
1.1       raeburn  5287:             }
                   5288:         }
                   5289:     }
1.72      raeburn  5290: 
                   5291:     foreach my $key (keys(%confhash)) {
                   5292:         $domdefaults{$key} = $confhash{$key};
                   5293:     }
                   5294:    
1.1       raeburn  5295:     my %quotahash = (
1.86      raeburn  5296:                       $action => { %confhash }
1.1       raeburn  5297:                     );
                   5298:     my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
                   5299:                                              $dom);
                   5300:     if ($putresult eq 'ok') {
                   5301:         if (keys(%changes) > 0) {
1.72      raeburn  5302:             my $cachetime = 24*60*60;
                   5303:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
                   5304: 
1.1       raeburn  5305:             $resulttext = &mt('Changes made:').'<ul>';
1.86      raeburn  5306:             unless ($context eq 'requestcourses') {
                   5307:                 if (ref($changes{'defaultquota'}) eq 'HASH') {
                   5308:                     $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
                   5309:                     foreach my $type (@{$types},'default') {
                   5310:                         if (defined($changes{'defaultquota'}{$type})) {
                   5311:                             my $typetitle = $usertypes->{$type};
                   5312:                             if ($type eq 'default') {
                   5313:                                 $typetitle = $othertitle;
                   5314:                             }
                   5315:                             $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72      raeburn  5316:                         }
                   5317:                     }
1.86      raeburn  5318:                     $resulttext .= '</ul></li>';
1.72      raeburn  5319:                 }
                   5320:             }
1.80      raeburn  5321:             my %newenv;
1.72      raeburn  5322:             foreach my $item (@usertools) {
                   5323:                 if (ref($changes{$item}) eq 'HASH') {
1.80      raeburn  5324:                     my $newacc = 
                   5325:                         &Apache::lonnet::usertools_access($env{'user.name'},
                   5326:                                                           $env{'user.domain'},
1.86      raeburn  5327:                                                           $item,'reload',$context);
                   5328:                     if ($context eq 'requestcourses') {
1.108     raeburn  5329:                         if ($env{'environment.canrequest.'.$item} ne $newacc) {
                   5330:                             $newenv{'environment.canrequest.'.$item} = $newacc;
1.86      raeburn  5331:                         }
                   5332:                     } else {
                   5333:                         if ($env{'environment.availabletools.'.$item} ne $newacc) { 
                   5334:                             $newenv{'environment.availabletools.'.$item} = $newacc;
                   5335:                         }
1.80      raeburn  5336:                     }
1.72      raeburn  5337:                     $resulttext .= '<li>'.$titles{$item}.'<ul>';
                   5338:                     foreach my $type (@{$types},'default','_LC_adv') {
                   5339:                         if ($changes{$item}{$type}) {
                   5340:                             my $typetitle = $usertypes->{$type};
                   5341:                             if ($type eq 'default') {
                   5342:                                 $typetitle = $othertitle;
                   5343:                             } elsif ($type eq '_LC_adv') {
                   5344:                                 $typetitle = 'LON-CAPA Advanced Users'; 
                   5345:                             }
                   5346:                             if ($confhash{$item}{$type}) {
1.101     raeburn  5347:                                 if ($context eq 'requestcourses') {
                   5348:                                     my $cond;
                   5349:                                     if ($confhash{$item}{$type} =~ /^autolimit=(\d*)$/) {
                   5350:                                         if ($1 eq '') {
                   5351:                                             $cond = &mt('(Automatic processing of any request).');
                   5352:                                         } else {
                   5353:                                             $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
                   5354:                                         }
                   5355:                                     } else { 
                   5356:                                         $cond = $conditions{$confhash{$item}{$type}};
                   5357:                                     }
                   5358:                                     $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
                   5359:                                 } else {
                   5360:                                     $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
                   5361:                                 }
1.72      raeburn  5362:                             } else {
1.104     raeburn  5363:                                 if ($type eq '_LC_adv') {
                   5364:                                     if ($confhash{$item}{$type} eq '0') {
                   5365:                                         $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
                   5366:                                     } else { 
                   5367:                                         $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
                   5368:                                     }
                   5369:                                 } else {
                   5370:                                     $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
                   5371:                                 }
1.72      raeburn  5372:                             }
                   5373:                         }
1.26      raeburn  5374:                     }
1.72      raeburn  5375:                     $resulttext .= '</ul></li>';
1.26      raeburn  5376:                 }
1.1       raeburn  5377:             }
1.102     raeburn  5378:             if ($action eq 'requestcourses') {
                   5379:                 if (ref($changes{'notify'}) eq 'HASH') {
                   5380:                     if ($changes{'notify'}{'approval'}) {
                   5381:                         if (ref($confhash{'notify'}) eq 'HASH') {
                   5382:                             if ($confhash{'notify'}{'approval'}) {
                   5383:                                 $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
                   5384:                             } else {
                   5385:                                 $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of course requests requiring approval.').'</li>';
                   5386:                             }
                   5387:                         }
                   5388:                     }
                   5389:                 }
                   5390:             }
1.1       raeburn  5391:             $resulttext .= '</ul>';
1.80      raeburn  5392:             if (keys(%newenv)) {
                   5393:                 &Apache::lonnet::appenv(\%newenv);
                   5394:             }
1.1       raeburn  5395:         } else {
1.86      raeburn  5396:             if ($context eq 'requestcourses') {
                   5397:                 $resulttext = &mt('No changes made to rights to request creation of courses.');
                   5398:             } else {
1.90      weissno  5399:                 $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86      raeburn  5400:             }
1.1       raeburn  5401:         }
                   5402:     } else {
1.11      albertel 5403:         $resulttext = '<span class="LC_error">'.
                   5404: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  5405:     }
1.3       raeburn  5406:     return $resulttext;
1.1       raeburn  5407: }
                   5408: 
1.3       raeburn  5409: sub modify_autoenroll {
                   5410:     my ($dom,%domconfig) = @_;
1.1       raeburn  5411:     my ($resulttext,%changes);
                   5412:     my %currautoenroll;
                   5413:     if (ref($domconfig{'autoenroll'}) eq 'HASH') {
                   5414:         foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
                   5415:             $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
                   5416:         }
                   5417:     }
                   5418:     my $autorun = &Apache::lonnet::auto_run(undef,$dom),
                   5419:     my %title = ( run => 'Auto-enrollment active',
1.129     raeburn  5420:                   sender => 'Sender for notification messages',
                   5421:                   coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)');
1.1       raeburn  5422:     my @offon = ('off','on');
1.17      raeburn  5423:     my $sender_uname = $env{'form.sender_uname'};
                   5424:     my $sender_domain = $env{'form.sender_domain'};
                   5425:     if ($sender_domain eq '') {
                   5426:         $sender_uname = '';
                   5427:     } elsif ($sender_uname eq '') {
                   5428:         $sender_domain = '';
                   5429:     }
1.129     raeburn  5430:     my $coowners = $env{'form.autoassign_coowners'};
1.1       raeburn  5431:     my %autoenrollhash =  (
1.129     raeburn  5432:                        autoenroll => { 'run' => $env{'form.autoenroll_run'},
                   5433:                                        'sender_uname' => $sender_uname,
                   5434:                                        'sender_domain' => $sender_domain,
                   5435:                                        'co-owners' => $coowners,
1.1       raeburn  5436:                                 }
                   5437:                      );
1.4       raeburn  5438:     my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
                   5439:                                              $dom);
1.1       raeburn  5440:     if ($putresult eq 'ok') {
                   5441:         if (exists($currautoenroll{'run'})) {
                   5442:              if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
                   5443:                  $changes{'run'} = 1;
                   5444:              }
                   5445:         } elsif ($autorun) {
                   5446:             if ($env{'form.autoenroll_run'} ne '1') {
1.23      raeburn  5447:                  $changes{'run'} = 1;
1.1       raeburn  5448:             }
                   5449:         }
1.17      raeburn  5450:         if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1       raeburn  5451:             $changes{'sender'} = 1;
                   5452:         }
1.17      raeburn  5453:         if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1       raeburn  5454:             $changes{'sender'} = 1;
                   5455:         }
1.129     raeburn  5456:         if ($currautoenroll{'co-owners'} ne '') {
                   5457:             if ($currautoenroll{'co-owners'} ne $coowners) {
                   5458:                 $changes{'coowners'} = 1;
                   5459:             }
                   5460:         } elsif ($coowners) {
                   5461:             $changes{'coowners'} = 1;
                   5462:         }      
1.1       raeburn  5463:         if (keys(%changes) > 0) {
                   5464:             $resulttext = &mt('Changes made:').'<ul>';
1.3       raeburn  5465:             if ($changes{'run'}) {
1.1       raeburn  5466:                 $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
                   5467:             }
                   5468:             if ($changes{'sender'}) {
1.17      raeburn  5469:                 if ($sender_uname eq '' || $sender_domain eq '') {
                   5470:                     $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
                   5471:                 } else {
                   5472:                     $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
                   5473:                 }
1.1       raeburn  5474:             }
1.129     raeburn  5475:             if ($changes{'coowners'}) {
                   5476:                 $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
                   5477:                 &Apache::loncommon::devalidate_domconfig_cache($dom);
                   5478:             }
1.1       raeburn  5479:             $resulttext .= '</ul>';
                   5480:         } else {
                   5481:             $resulttext = &mt('No changes made to auto-enrollment settings');
                   5482:         }
                   5483:     } else {
1.11      albertel 5484:         $resulttext = '<span class="LC_error">'.
                   5485: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  5486:     }
1.3       raeburn  5487:     return $resulttext;
1.1       raeburn  5488: }
                   5489: 
                   5490: sub modify_autoupdate {
1.3       raeburn  5491:     my ($dom,%domconfig) = @_;
1.1       raeburn  5492:     my ($resulttext,%currautoupdate,%fields,%changes);
                   5493:     if (ref($domconfig{'autoupdate'}) eq 'HASH') {
                   5494:         foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
                   5495:             $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
                   5496:         }
                   5497:     }
                   5498:     my @offon = ('off','on');
                   5499:     my %title = &Apache::lonlocal::texthash (
                   5500:                    run => 'Auto-update:',
                   5501:                    classlists => 'Updates to user information in classlists?'
                   5502:                 );
1.44      raeburn  5503:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1       raeburn  5504:     my %fieldtitles = &Apache::lonlocal::texthash (
                   5505:                         id => 'Student/Employee ID',
1.20      raeburn  5506:                         permanentemail => 'E-mail address',
1.1       raeburn  5507:                         lastname => 'Last Name',
                   5508:                         firstname => 'First Name',
                   5509:                         middlename => 'Middle Name',
1.132     raeburn  5510:                         generation => 'Generation',
1.1       raeburn  5511:                       );
1.142     raeburn  5512:     $othertitle = &mt('All users');
1.1       raeburn  5513:     if (keys(%{$usertypes}) >  0) {
1.26      raeburn  5514:         $othertitle = &mt('Other users');
1.1       raeburn  5515:     }
                   5516:     foreach my $key (keys(%env)) {
                   5517:         if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132     raeburn  5518:             my ($usertype,$item) = ($1,$2);
                   5519:             if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
                   5520:                 if ($usertype eq 'default') {   
                   5521:                     push(@{$fields{$1}},$2);
                   5522:                 } elsif (ref($types) eq 'ARRAY') {
                   5523:                     if (grep(/^\Q$usertype\E$/,@{$types})) {
                   5524:                         push(@{$fields{$1}},$2);
                   5525:                     }
                   5526:                 }
                   5527:             }
1.1       raeburn  5528:         }
                   5529:     }
1.131     raeburn  5530:     my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
                   5531:     @lockablenames = sort(@lockablenames);
                   5532:     if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
                   5533:         my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
                   5534:         if (@changed) {
                   5535:             $changes{'lockablenames'} = 1;
                   5536:         }
                   5537:     } else {
                   5538:         if (@lockablenames) {
                   5539:             $changes{'lockablenames'} = 1;
                   5540:         }
                   5541:     }
1.1       raeburn  5542:     my %updatehash = (
                   5543:                       autoupdate => { run => $env{'form.autoupdate_run'},
                   5544:                                       classlists => $env{'form.classlists'},
                   5545:                                       fields => {%fields},
1.131     raeburn  5546:                                       lockablenames => \@lockablenames,
1.1       raeburn  5547:                                     }
                   5548:                      );
                   5549:     foreach my $key (keys(%currautoupdate)) {
                   5550:         if (($key eq 'run') || ($key eq 'classlists')) {
                   5551:             if (exists($updatehash{autoupdate}{$key})) {
                   5552:                 if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
                   5553:                     $changes{$key} = 1;
                   5554:                 }
                   5555:             }
                   5556:         } elsif ($key eq 'fields') {
                   5557:             if (ref($currautoupdate{$key}) eq 'HASH') {
1.26      raeburn  5558:                 foreach my $item (@{$types},'default') {
1.1       raeburn  5559:                     if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
                   5560:                         my $change = 0;
                   5561:                         foreach my $type (@{$currautoupdate{$key}{$item}}) {
                   5562:                             if (!exists($fields{$item})) {
                   5563:                                 $change = 1;
1.132     raeburn  5564:                                 last;
1.1       raeburn  5565:                             } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26      raeburn  5566:                                 if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1       raeburn  5567:                                     $change = 1;
1.132     raeburn  5568:                                     last;
1.1       raeburn  5569:                                 }
                   5570:                             }
                   5571:                         }
                   5572:                         if ($change) {
                   5573:                             push(@{$changes{$key}},$item);
                   5574:                         }
1.26      raeburn  5575:                     } 
1.1       raeburn  5576:                 }
                   5577:             }
1.131     raeburn  5578:         } elsif ($key eq 'lockablenames') {
                   5579:             if (ref($currautoupdate{$key}) eq 'ARRAY') {
                   5580:                 my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
                   5581:                 if (@changed) {
                   5582:                     $changes{'lockablenames'} = 1;
                   5583:                 }
                   5584:             } else {
                   5585:                 if (@lockablenames) {
                   5586:                     $changes{'lockablenames'} = 1;
                   5587:                 }
                   5588:             }
                   5589:         }
                   5590:     }
                   5591:     unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
                   5592:         if (@lockablenames) {
                   5593:             $changes{'lockablenames'} = 1;
1.1       raeburn  5594:         }
                   5595:     }
1.26      raeburn  5596:     foreach my $item (@{$types},'default') {
                   5597:         if (defined($fields{$item})) {
                   5598:             if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132     raeburn  5599:                 if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
                   5600:                     my $change = 0;
                   5601:                     if (ref($fields{$item}) eq 'ARRAY') {
                   5602:                         foreach my $type (@{$fields{$item}}) {
                   5603:                             if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
                   5604:                                 $change = 1;
                   5605:                                 last;
                   5606:                             }
                   5607:                         }
                   5608:                     }
                   5609:                     if ($change) {
                   5610:                         push(@{$changes{'fields'}},$item);
                   5611:                     }
                   5612:                 } else {
1.26      raeburn  5613:                     push(@{$changes{'fields'}},$item);
                   5614:                 }
                   5615:             } else {
                   5616:                 push(@{$changes{'fields'}},$item);
1.1       raeburn  5617:             }
                   5618:         }
                   5619:     }
                   5620:     my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
                   5621:                                              $dom);
                   5622:     if ($putresult eq 'ok') {
                   5623:         if (keys(%changes) > 0) {
                   5624:             $resulttext = &mt('Changes made:').'<ul>';
                   5625:             foreach my $key (sort(keys(%changes))) {
1.131     raeburn  5626:                 if ($key eq 'lockablenames') {
                   5627:                     $resulttext .= '<li>';
                   5628:                     if (@lockablenames) {
                   5629:                         $usertypes->{'default'} = $othertitle;
                   5630:                         $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
                   5631:                                    join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
                   5632:                     } else {
                   5633:                         $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
                   5634:                     }
                   5635:                     $resulttext .= '</li>';
                   5636:                 } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1       raeburn  5637:                     foreach my $item (@{$changes{$key}}) {
                   5638:                         my @newvalues;
                   5639:                         foreach my $type (@{$fields{$item}}) {
                   5640:                             push(@newvalues,$fieldtitles{$type});
                   5641:                         }
1.3       raeburn  5642:                         my $newvaluestr;
                   5643:                         if (@newvalues > 0) {
                   5644:                             $newvaluestr = join(', ',@newvalues);
                   5645:                         } else {
                   5646:                             $newvaluestr = &mt('none');
1.6       raeburn  5647:                         }
1.1       raeburn  5648:                         if ($item eq 'default') {
1.26      raeburn  5649:                             $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1       raeburn  5650:                         } else {
1.26      raeburn  5651:                             $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1       raeburn  5652:                         }
                   5653:                     }
                   5654:                 } else {
                   5655:                     my $newvalue;
                   5656:                     if ($key eq 'run') {
                   5657:                         $newvalue = $offon[$env{'form.autoupdate_run'}];
                   5658:                     } else {
                   5659:                         $newvalue = $offon[$env{'form.'.$key}];
1.3       raeburn  5660:                     }
1.1       raeburn  5661:                     $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
                   5662:                 }
                   5663:             }
                   5664:             $resulttext .= '</ul>';
                   5665:         } else {
1.3       raeburn  5666:             $resulttext = &mt('No changes made to autoupdates');
1.1       raeburn  5667:         }
                   5668:     } else {
1.11      albertel 5669:         $resulttext = '<span class="LC_error">'.
                   5670: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  5671:     }
1.3       raeburn  5672:     return $resulttext;
1.1       raeburn  5673: }
                   5674: 
1.125     raeburn  5675: sub modify_autocreate {
                   5676:     my ($dom,%domconfig) = @_;
                   5677:     my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
                   5678:     if (ref($domconfig{'autocreate'}) eq 'HASH') {
                   5679:         foreach my $key (keys(%{$domconfig{'autocreate'}})) {
                   5680:             $currautocreate{$key} = $domconfig{'autocreate'}{$key};
                   5681:         }
                   5682:     }
                   5683:     my %title= ( xml => 'Auto-creation of courses in XML course description files',
                   5684:                  req => 'Auto-creation of validated requests for official courses',
                   5685:                  xmldc => 'Identity of course creator of courses from XML files',
                   5686:                );
                   5687:     my @types = ('xml','req');
                   5688:     foreach my $item (@types) {
                   5689:         $newvals{$item} = $env{'form.autocreate_'.$item};
                   5690:         $newvals{$item} =~ s/\D//g;
                   5691:         $newvals{$item} = 0 if ($newvals{$item} eq '');
                   5692:     }
                   5693:     $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
                   5694:     my %domcoords = &get_active_dcs($dom);
                   5695:     unless (exists($domcoords{$newvals{'xmldc'}})) {
                   5696:         $newvals{'xmldc'} = '';
                   5697:     } 
                   5698:     %autocreatehash =  (
                   5699:                         autocreate => { xml => $newvals{'xml'},
                   5700:                                         req => $newvals{'req'},
                   5701:                                       }
                   5702:                        );
                   5703:     if ($newvals{'xmldc'} ne '') {
                   5704:         $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
                   5705:     }
                   5706:     my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
                   5707:                                              $dom);
                   5708:     if ($putresult eq 'ok') {
                   5709:         my @items = @types;
                   5710:         if ($newvals{'xml'}) {
                   5711:             push(@items,'xmldc');
                   5712:         }
                   5713:         foreach my $item (@items) {
                   5714:             if (exists($currautocreate{$item})) {
                   5715:                 if ($currautocreate{$item} ne $newvals{$item}) {
                   5716:                     $changes{$item} = 1;
                   5717:                 }
                   5718:             } elsif ($newvals{$item}) {
                   5719:                 $changes{$item} = 1;
                   5720:             }
                   5721:         }
                   5722:         if (keys(%changes) > 0) {
                   5723:             my @offon = ('off','on'); 
                   5724:             $resulttext = &mt('Changes made:').'<ul>';
                   5725:             foreach my $item (@types) {
                   5726:                 if ($changes{$item}) {
                   5727:                     my $newtxt = $offon[$newvals{$item}];
                   5728:                     $resulttext .= '<li>'.&mt("$title{$item} set to [_1]$newtxt [_2]",'<b>','</b>').'</li>';
                   5729:                 }
                   5730:             }
                   5731:             if ($changes{'xmldc'}) {
                   5732:                 my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
                   5733:                 my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
                   5734:                 $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]$newtxt [_2]",'<b>','</b>').'</li>'; 
                   5735:             }
                   5736:             $resulttext .= '</ul>';
                   5737:         } else {
                   5738:             $resulttext = &mt('No changes made to auto-creation settings');
                   5739:         }
                   5740:     } else {
                   5741:         $resulttext = '<span class="LC_error">'.
                   5742:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   5743:     }
                   5744:     return $resulttext;
                   5745: }
                   5746: 
1.23      raeburn  5747: sub modify_directorysrch {
                   5748:     my ($dom,%domconfig) = @_;
                   5749:     my ($resulttext,%changes);
                   5750:     my %currdirsrch;
                   5751:     if (ref($domconfig{'directorysrch'}) eq 'HASH') {
                   5752:         foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
                   5753:             $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
                   5754:         }
                   5755:     }
                   5756:     my %title = ( available => 'Directory search available',
1.24      raeburn  5757:                   localonly => 'Other domains can search',
1.23      raeburn  5758:                   searchby => 'Search types',
                   5759:                   searchtypes => 'Search latitude');
                   5760:     my @offon = ('off','on');
1.24      raeburn  5761:     my @otherdoms = ('Yes','No');
1.23      raeburn  5762: 
1.25      raeburn  5763:     my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');  
1.23      raeburn  5764:     my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
                   5765:     my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
                   5766: 
1.44      raeburn  5767:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26      raeburn  5768:     if (keys(%{$usertypes}) == 0) {
                   5769:         @cansearch = ('default');
                   5770:     } else {
                   5771:         if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
                   5772:             foreach my $type (@{$currdirsrch{'cansearch'}}) {
                   5773:                 if (!grep(/^\Q$type\E$/,@cansearch)) {
                   5774:                     push(@{$changes{'cansearch'}},$type);
                   5775:                 }
1.23      raeburn  5776:             }
1.26      raeburn  5777:             foreach my $type (@cansearch) {
                   5778:                 if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
                   5779:                     push(@{$changes{'cansearch'}},$type);
                   5780:                 }
1.23      raeburn  5781:             }
1.26      raeburn  5782:         } else {
                   5783:             push(@{$changes{'cansearch'}},@cansearch);
1.23      raeburn  5784:         }
                   5785:     }
                   5786: 
                   5787:     if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
                   5788:         foreach my $by (@{$currdirsrch{'searchby'}}) {
                   5789:             if (!grep(/^\Q$by\E$/,@searchby)) {
                   5790:                 push(@{$changes{'searchby'}},$by);
                   5791:             }
                   5792:         }
                   5793:         foreach my $by (@searchby) {
                   5794:             if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
                   5795:                 push(@{$changes{'searchby'}},$by);
                   5796:             }
                   5797:         }
                   5798:     } else {
                   5799:         push(@{$changes{'searchby'}},@searchby);
                   5800:     }
1.25      raeburn  5801: 
                   5802:     if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
                   5803:         foreach my $type (@{$currdirsrch{'searchtypes'}}) {
                   5804:             if (!grep(/^\Q$type\E$/,@searchtypes)) {
                   5805:                 push(@{$changes{'searchtypes'}},$type);
                   5806:             }
                   5807:         }
                   5808:         foreach my $type (@searchtypes) {
                   5809:             if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
                   5810:                 push(@{$changes{'searchtypes'}},$type);
                   5811:             }
                   5812:         }
                   5813:     } else {
                   5814:         if (exists($currdirsrch{'searchtypes'})) {
                   5815:             foreach my $type (@searchtypes) {  
                   5816:                 if ($type ne $currdirsrch{'searchtypes'}) { 
                   5817:                     push(@{$changes{'searchtypes'}},$type);
                   5818:                 }
                   5819:             }
                   5820:             if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
                   5821:                 push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
                   5822:             }   
                   5823:         } else {
                   5824:             push(@{$changes{'searchtypes'}},@searchtypes); 
                   5825:         }
                   5826:     }
                   5827: 
1.23      raeburn  5828:     my %dirsrch_hash =  (
                   5829:             directorysrch => { available => $env{'form.dirsrch_available'},
                   5830:                                cansearch => \@cansearch,
1.24      raeburn  5831:                                localonly => $env{'form.dirsrch_localonly'},
1.23      raeburn  5832:                                searchby => \@searchby,
1.25      raeburn  5833:                                searchtypes => \@searchtypes,
1.23      raeburn  5834:                              }
                   5835:             );
                   5836:     my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
                   5837:                                              $dom);
                   5838:     if ($putresult eq 'ok') {
                   5839:         if (exists($currdirsrch{'available'})) {
                   5840:              if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
                   5841:                  $changes{'available'} = 1;
                   5842:              }
                   5843:         } else {
                   5844:             if ($env{'form.dirsrch_available'} eq '1') {
                   5845:                 $changes{'available'} = 1;
                   5846:             }
                   5847:         }
1.24      raeburn  5848:         if (exists($currdirsrch{'localonly'})) {
                   5849:              if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
                   5850:                  $changes{'localonly'} = 1;
                   5851:              }
                   5852:         } else {
                   5853:             if ($env{'form.dirsrch_localonly'} eq '1') {
                   5854:                 $changes{'localonly'} = 1;
                   5855:             }
                   5856:         }
1.23      raeburn  5857:         if (keys(%changes) > 0) {
                   5858:             $resulttext = &mt('Changes made:').'<ul>';
                   5859:             if ($changes{'available'}) {
                   5860:                 $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
                   5861:             }
1.24      raeburn  5862:             if ($changes{'localonly'}) {
                   5863:                 $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
                   5864:             }
                   5865: 
1.23      raeburn  5866:             if (ref($changes{'cansearch'}) eq 'ARRAY') {
                   5867:                 my $chgtext;
1.26      raeburn  5868:                 if (ref($usertypes) eq 'HASH') {
                   5869:                     if (keys(%{$usertypes}) > 0) {
                   5870:                         foreach my $type (@{$types}) {
                   5871:                             if (grep(/^\Q$type\E$/,@cansearch)) {
                   5872:                                 $chgtext .= $usertypes->{$type}.'; ';
                   5873:                             }
                   5874:                         }
                   5875:                         if (grep(/^default$/,@cansearch)) {
                   5876:                             $chgtext .= $othertitle;
                   5877:                         } else {
                   5878:                             $chgtext =~ s/\; $//;
                   5879:                         }
                   5880:                         $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  5881:                     }
                   5882:                 }
                   5883:             }
                   5884:             if (ref($changes{'searchby'}) eq 'ARRAY') {
                   5885:                 my ($searchtitles,$titleorder) = &sorted_searchtitles();
                   5886:                 my $chgtext;
                   5887:                 foreach my $type (@{$titleorder}) {
                   5888:                     if (grep(/^\Q$type\E$/,@searchby)) {
                   5889:                         if (defined($searchtitles->{$type})) {
                   5890:                             $chgtext .= $searchtitles->{$type}.'; ';
                   5891:                         }
                   5892:                     }
                   5893:                 }
                   5894:                 $chgtext =~ s/\; $//;
                   5895:                 $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
                   5896:             }
1.25      raeburn  5897:             if (ref($changes{'searchtypes'}) eq 'ARRAY') {
                   5898:                 my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes(); 
                   5899:                 my $chgtext;
                   5900:                 foreach my $type (@{$srchtypeorder}) {
                   5901:                     if (grep(/^\Q$type\E$/,@searchtypes)) {
                   5902:                         if (defined($srchtypes_desc->{$type})) {
                   5903:                             $chgtext .= $srchtypes_desc->{$type}.'; ';
                   5904:                         }
                   5905:                     }
                   5906:                 }
                   5907:                 $chgtext =~ s/\; $//;
                   5908:                 $resulttext .= '<li>'.&mt("$title{'searchtypes'} set to: \"[_1]\"",$chgtext).'</li>';
1.23      raeburn  5909:             }
                   5910:             $resulttext .= '</ul>';
                   5911:         } else {
                   5912:             $resulttext = &mt('No changes made to institution directory search settings');
                   5913:         }
                   5914:     } else {
                   5915:         $resulttext = '<span class="LC_error">'.
1.27      raeburn  5916:                       &mt('An error occurred: [_1]',$putresult).'</span>';
                   5917:     }
                   5918:     return $resulttext;
                   5919: }
                   5920: 
1.28      raeburn  5921: sub modify_contacts {
                   5922:     my ($dom,%domconfig) = @_;
                   5923:     my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
                   5924:     if (ref($domconfig{'contacts'}) eq 'HASH') {
                   5925:         foreach my $key (keys(%{$domconfig{'contacts'}})) {
                   5926:             $currsetting{$key} = $domconfig{'contacts'}{$key};
                   5927:         }
                   5928:     }
1.134     raeburn  5929:     my (%others,%to,%bcc);
1.28      raeburn  5930:     my @contacts = ('supportemail','adminemail');
1.102     raeburn  5931:     my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
                   5932:                     'requestsmail');
1.28      raeburn  5933:     foreach my $type (@mailings) {
                   5934:         @{$newsetting{$type}} = 
                   5935:             &Apache::loncommon::get_env_multiple('form.'.$type);
                   5936:         foreach my $item (@contacts) {
                   5937:             if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
                   5938:                 $contacts_hash{contacts}{$type}{$item} = 1;
                   5939:             } else {
                   5940:                 $contacts_hash{contacts}{$type}{$item} = 0;
                   5941:             }
                   5942:         }  
                   5943:         $others{$type} = $env{'form.'.$type.'_others'};
                   5944:         $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.134     raeburn  5945:         if ($type eq 'helpdeskmail') {
                   5946:             $bcc{$type} = $env{'form.'.$type.'_bcc'};
                   5947:             $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
                   5948:         }
1.28      raeburn  5949:     }
                   5950:     foreach my $item (@contacts) {
                   5951:         $to{$item} = $env{'form.'.$item};
                   5952:         $contacts_hash{'contacts'}{$item} = $to{$item};
                   5953:     }
                   5954:     if (keys(%currsetting) > 0) {
                   5955:         foreach my $item (@contacts) {
                   5956:             if ($to{$item} ne $currsetting{$item}) {
                   5957:                 $changes{$item} = 1;
                   5958:             }
                   5959:         }
                   5960:         foreach my $type (@mailings) {
                   5961:             foreach my $item (@contacts) {
                   5962:                 if (ref($currsetting{$type}) eq 'HASH') {
                   5963:                     if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
                   5964:                         push(@{$changes{$type}},$item);
                   5965:                     }
                   5966:                 } else {
                   5967:                     push(@{$changes{$type}},@{$newsetting{$type}});
                   5968:                 }
                   5969:             }
                   5970:             if ($others{$type} ne $currsetting{$type}{'others'}) {
                   5971:                 push(@{$changes{$type}},'others');
                   5972:             }
1.134     raeburn  5973:             if ($type eq 'helpdeskmail') {   
                   5974:                 if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
                   5975:                     push(@{$changes{$type}},'bcc'); 
                   5976:                 }
                   5977:             }
1.28      raeburn  5978:         }
                   5979:     } else {
                   5980:         my %default;
                   5981:         $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
                   5982:         $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
                   5983:         $default{'errormail'} = 'adminemail';
                   5984:         $default{'packagesmail'} = 'adminemail';
                   5985:         $default{'helpdeskmail'} = 'supportemail';
1.89      raeburn  5986:         $default{'lonstatusmail'} = 'adminemail';
1.102     raeburn  5987:         $default{'requestsmail'} = 'adminemail';
1.28      raeburn  5988:         foreach my $item (@contacts) {
                   5989:            if ($to{$item} ne $default{$item}) {
                   5990:               $changes{$item} = 1;
                   5991:            } 
                   5992:         }
                   5993:         foreach my $type (@mailings) {
                   5994:             if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
                   5995:                
                   5996:                 push(@{$changes{$type}},@{$newsetting{$type}});
                   5997:             }
                   5998:             if ($others{$type} ne '') {
                   5999:                 push(@{$changes{$type}},'others');
1.134     raeburn  6000:             }
                   6001:             if ($type eq 'helpdeskmail') {
                   6002:                 if ($bcc{$type} ne '') {
                   6003:                     push(@{$changes{$type}},'bcc');
                   6004:                 }
                   6005:             }
1.28      raeburn  6006:         }
                   6007:     }
                   6008:     my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
                   6009:                                              $dom);
                   6010:     if ($putresult eq 'ok') {
                   6011:         if (keys(%changes) > 0) {
                   6012:             my ($titles,$short_titles)  = &contact_titles();
                   6013:             $resulttext = &mt('Changes made:').'<ul>';
                   6014:             foreach my $item (@contacts) {
                   6015:                 if ($changes{$item}) {
                   6016:                     $resulttext .= '<li>'.$titles->{$item}.
                   6017:                                     &mt(' set to: ').
                   6018:                                     '<span class="LC_cusr_emph">'.
                   6019:                                     $to{$item}.'</span></li>';
                   6020:                 }
                   6021:             }
                   6022:             foreach my $type (@mailings) {
                   6023:                 if (ref($changes{$type}) eq 'ARRAY') {
                   6024:                     $resulttext .= '<li>'.$titles->{$type}.': ';
                   6025:                     my @text;
                   6026:                     foreach my $item (@{$newsetting{$type}}) {
                   6027:                         push(@text,$short_titles->{$item});
                   6028:                     }
                   6029:                     if ($others{$type} ne '') {
                   6030:                         push(@text,$others{$type});
                   6031:                     }
                   6032:                     $resulttext .= '<span class="LC_cusr_emph">'.
1.134     raeburn  6033:                                    join(', ',@text).'</span>';
                   6034:                     if ($type eq 'helpdeskmail') {
                   6035:                         if ($bcc{$type} ne '') {
                   6036:                             $resulttext .= '&nbsp;'.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
                   6037:                         }
                   6038:                     }
                   6039:                     $resulttext .= '</li>';
1.28      raeburn  6040:                 }
                   6041:             }
                   6042:             $resulttext .= '</ul>';
                   6043:         } else {
1.34      raeburn  6044:             $resulttext = &mt('No changes made to contact information');
1.28      raeburn  6045:         }
                   6046:     } else {
                   6047:         $resulttext = '<span class="LC_error">'.
                   6048:             &mt('An error occurred: [_1].',$putresult).'</span>';
                   6049:     }
                   6050:     return $resulttext;
                   6051: }
                   6052: 
                   6053: sub modify_usercreation {
1.27      raeburn  6054:     my ($dom,%domconfig) = @_;
1.34      raeburn  6055:     my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate);
1.43      raeburn  6056:     my $warningmsg;
1.27      raeburn  6057:     if (ref($domconfig{'usercreation'}) eq 'HASH') {
                   6058:         foreach my $key (keys(%{$domconfig{'usercreation'}})) {
                   6059:             $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
                   6060:         }
                   6061:     }
                   6062:     my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32      raeburn  6063:     my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.43      raeburn  6064:     my @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
1.100     raeburn  6065:     my @contexts = ('author','course','requestcrs','selfcreate');
1.34      raeburn  6066:     foreach my $item(@contexts) {
1.45      raeburn  6067:         if ($item eq 'selfcreate') {
1.50      raeburn  6068:             @{$cancreate{$item}} = &Apache::loncommon::get_env_multiple('form.can_createuser_'.$item);
1.43      raeburn  6069:             my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
                   6070:             if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) || ($domdefaults{'auth_def'} eq 'localauth'))) {
1.50      raeburn  6071:                 if (ref($cancreate{$item}) eq 'ARRAY') { 
                   6072:                     if (grep(/^login$/,@{$cancreate{$item}})) {
                   6073:                         $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.');   
                   6074:                     }
1.43      raeburn  6075:                 }
                   6076:             }
1.50      raeburn  6077:         } else {
                   6078:             $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.43      raeburn  6079:         }
1.34      raeburn  6080:     }
1.93      raeburn  6081:     my ($othertitle,$usertypes,$types) = 
                   6082:         &Apache::loncommon::sorted_inst_types($dom);
                   6083:     if (ref($types) eq 'ARRAY') {
                   6084:         if (@{$types} > 0) {
                   6085:             @{$cancreate{'statustocreate'}} = 
                   6086:                 &Apache::loncommon::get_env_multiple('form.statustocreate');
1.103     raeburn  6087:         } else {
                   6088:             @{$cancreate{'statustocreate'}} = ();
1.93      raeburn  6089:         }
                   6090:         push(@contexts,'statustocreate');
                   6091:     }
1.34      raeburn  6092:     if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
                   6093:         foreach my $item (@contexts) {
1.93      raeburn  6094:             if (($item eq 'selfcreate') || ($item eq 'statustocreate')) {
                   6095:                 if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
1.50      raeburn  6096:                     foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
1.103     raeburn  6097:                         if (ref($cancreate{$item}) eq 'ARRAY') {
                   6098:                             if (!grep(/^$curr$/,@{$cancreate{$item}})) {
                   6099:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   6100:                                     push(@{$changes{'cancreate'}},$item);
                   6101:                                 }
1.50      raeburn  6102:                             }
                   6103:                         }
                   6104:                     }
                   6105:                 } else {
                   6106:                     if ($curr_usercreation{'cancreate'}{$item} eq '') {
                   6107:                         if (@{$cancreate{$item}} > 0) {
                   6108:                             if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   6109:                                 push(@{$changes{'cancreate'}},$item);
                   6110:                             }
                   6111:                         }
                   6112:                     } else {
                   6113:                         if ($curr_usercreation{'cancreate'}{$item} eq 'any') {
                   6114:                             if (@{$cancreate{$item}} < 3) {
                   6115:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   6116:                                     push(@{$changes{'cancreate'}},$item);
                   6117:                                 }
                   6118:                             }
                   6119:                         } elsif ($curr_usercreation{'cancreate'}{$item} eq 'none') {
                   6120:                             if (@{$cancreate{$item}} > 0) {
                   6121:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   6122:                                     push(@{$changes{'cancreate'}},$item);
                   6123:                                 }
                   6124:                             }
                   6125:                         } elsif (!grep(/^$curr_usercreation{'cancreate'}{$item}$/,@{$cancreate{$item}})) {
                   6126:                             if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   6127:                                 push(@{$changes{'cancreate'}},$item);
                   6128:                             }
                   6129:                         }
                   6130:                     }
                   6131:                 }
                   6132:                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   6133:                     foreach my $type (@{$cancreate{$item}}) {
                   6134:                         if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
                   6135:                             if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
                   6136:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   6137:                                     push(@{$changes{'cancreate'}},$item);
                   6138:                                 }
                   6139:                             }
                   6140:                         } elsif (($curr_usercreation{'cancreate'}{$item} ne 'any') &&
                   6141:                                  ($curr_usercreation{'cancreate'}{$item} ne 'none')) {
                   6142:                             if ($curr_usercreation{'cancreate'}{$item} ne $type) {
                   6143:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   6144:                                     push(@{$changes{'cancreate'}},$item);
                   6145:                                 }
                   6146:                             }
                   6147:                         }
                   6148:                     }
                   6149:                 }
                   6150:             } else {
                   6151:                 if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
                   6152:                     push(@{$changes{'cancreate'}},$item);
                   6153:                 }
                   6154:             }
1.27      raeburn  6155:         }
1.34      raeburn  6156:     } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
                   6157:         foreach my $item (@contexts) {
1.43      raeburn  6158:             if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34      raeburn  6159:                 if ($cancreate{$item} ne 'any') {
                   6160:                     push(@{$changes{'cancreate'}},$item);
                   6161:                 }
                   6162:             } else {
                   6163:                 if ($cancreate{$item} ne 'none') {
                   6164:                     push(@{$changes{'cancreate'}},$item);
                   6165:                 }
1.27      raeburn  6166:             }
                   6167:         }
                   6168:     } else {
1.43      raeburn  6169:         foreach my $item (@contexts)  {
1.34      raeburn  6170:             push(@{$changes{'cancreate'}},$item);
                   6171:         }
1.27      raeburn  6172:     }
1.34      raeburn  6173: 
1.27      raeburn  6174:     if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
                   6175:         foreach my $type (@{$curr_usercreation{'username_rule'}}) {
                   6176:             if (!grep(/^\Q$type\E$/,@username_rule)) {
                   6177:                 push(@{$changes{'username_rule'}},$type);
                   6178:             }
                   6179:         }
                   6180:         foreach my $type (@username_rule) {
                   6181:             if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
                   6182:                 push(@{$changes{'username_rule'}},$type);
                   6183:             }
                   6184:         }
                   6185:     } else {
                   6186:         push(@{$changes{'username_rule'}},@username_rule);
                   6187:     }
                   6188: 
1.32      raeburn  6189:     if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
                   6190:         foreach my $type (@{$curr_usercreation{'id_rule'}}) {
                   6191:             if (!grep(/^\Q$type\E$/,@id_rule)) {
                   6192:                 push(@{$changes{'id_rule'}},$type);
                   6193:             }
                   6194:         }
                   6195:         foreach my $type (@id_rule) {
                   6196:             if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
                   6197:                 push(@{$changes{'id_rule'}},$type);
                   6198:             }
                   6199:         }
                   6200:     } else {
                   6201:         push(@{$changes{'id_rule'}},@id_rule);
                   6202:     }
                   6203: 
1.43      raeburn  6204:     if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
                   6205:         foreach my $type (@{$curr_usercreation{'email_rule'}}) {
                   6206:             if (!grep(/^\Q$type\E$/,@email_rule)) {
                   6207:                 push(@{$changes{'email_rule'}},$type);
                   6208:             }
                   6209:         }
                   6210:         foreach my $type (@email_rule) {
                   6211:             if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
                   6212:                 push(@{$changes{'email_rule'}},$type);
                   6213:             }
                   6214:         }
                   6215:     } else {
                   6216:         push(@{$changes{'email_rule'}},@email_rule);
                   6217:     }
                   6218: 
                   6219:     my @authen_contexts = ('author','course','domain');
1.28      raeburn  6220:     my @authtypes = ('int','krb4','krb5','loc');
                   6221:     my %authhash;
1.43      raeburn  6222:     foreach my $item (@authen_contexts) {
1.28      raeburn  6223:         my @authallowed =  &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
                   6224:         foreach my $auth (@authtypes) {
                   6225:             if (grep(/^\Q$auth\E$/,@authallowed)) {
                   6226:                 $authhash{$item}{$auth} = 1;
                   6227:             } else {
                   6228:                 $authhash{$item}{$auth} = 0;
                   6229:             }
                   6230:         }
                   6231:     }
                   6232:     if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43      raeburn  6233:         foreach my $item (@authen_contexts) {
1.28      raeburn  6234:             if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
                   6235:                 foreach my $auth (@authtypes) {
                   6236:                     if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
                   6237:                         push(@{$changes{'authtypes'}},$item);
                   6238:                         last;
                   6239:                     }
                   6240:                 }
                   6241:             }
                   6242:         }
                   6243:     } else {
1.43      raeburn  6244:         foreach my $item (@authen_contexts) {
1.28      raeburn  6245:             push(@{$changes{'authtypes'}},$item);
                   6246:         }
                   6247:     }
                   6248: 
1.27      raeburn  6249:     my %usercreation_hash =  (
1.28      raeburn  6250:             usercreation => {
1.34      raeburn  6251:                               cancreate     => \%cancreate,
1.27      raeburn  6252:                               username_rule => \@username_rule,
1.32      raeburn  6253:                               id_rule       => \@id_rule,
1.43      raeburn  6254:                               email_rule    => \@email_rule,
1.32      raeburn  6255:                               authtypes     => \%authhash,
1.27      raeburn  6256:                             }
                   6257:             );
                   6258: 
                   6259:     my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
                   6260:                                              $dom);
1.50      raeburn  6261: 
                   6262:     my %selfcreatetypes = (
                   6263:                              sso   => 'users authenticated by institutional single sign on',
                   6264:                              login => 'users authenticated by institutional log-in',
                   6265:                              email => 'users who provide a valid e-mail address for use as the username',
                   6266:                           );
1.27      raeburn  6267:     if ($putresult eq 'ok') {
                   6268:         if (keys(%changes) > 0) {
                   6269:             $resulttext = &mt('Changes made:').'<ul>';
                   6270:             if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.34      raeburn  6271:                 my %lt = &usercreation_types();
                   6272:                 foreach my $type (@{$changes{'cancreate'}}) {
1.100     raeburn  6273:                     my $chgtext;
                   6274:                     unless ($type eq 'statustocreate') {
                   6275:                         $chgtext = $lt{$type}.', ';
                   6276:                     }
1.45      raeburn  6277:                     if ($type eq 'selfcreate') {
1.50      raeburn  6278:                         if (@{$cancreate{$type}} == 0) {
1.43      raeburn  6279:                             $chgtext .= &mt('creation of a new user account is not permitted.');
1.50      raeburn  6280:                         } else {
1.100     raeburn  6281:                             $chgtext .= &mt('creation of a new account is permitted for:').'<ul>';
1.50      raeburn  6282:                             foreach my $case (@{$cancreate{$type}}) {
                   6283:                                 $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
                   6284:                             }
                   6285:                             $chgtext .= '</ul>';
1.100     raeburn  6286:                             if (ref($cancreate{$type}) eq 'ARRAY') {
                   6287:                                 if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
                   6288:                                     if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
                   6289:                                         if (@{$cancreate{'statustocreate'}} == 0) {
                   6290:                                             $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
                   6291:                                         }
                   6292:                                     }
                   6293:                                 }
                   6294:                             }
1.43      raeburn  6295:                         }
1.93      raeburn  6296:                     } elsif ($type eq 'statustocreate') {
1.96      raeburn  6297:                         if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
                   6298:                             (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
                   6299:                             if (@{$cancreate{'selfcreate'}} > 0) {
                   6300:                                 if (@{$cancreate{'statustocreate'}} == 0) {
1.100     raeburn  6301: 
                   6302:                                     $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96      raeburn  6303:                                     if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.100     raeburn  6304:                                         $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
                   6305:                                     } 
1.96      raeburn  6306:                                 } elsif (ref($usertypes) eq 'HASH') {
                   6307:                                     if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100     raeburn  6308:                                         $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
                   6309:                                     } else {
                   6310:                                         $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
                   6311:                                     }
                   6312:                                     $chgtext .= '<ul>';
                   6313:                                     foreach my $case (@{$cancreate{$type}}) {
                   6314:                                         if ($case eq 'default') {
                   6315:                                             $chgtext .= '<li>'.$othertitle.'</li>';
                   6316:                                         } else {
                   6317:                                             $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93      raeburn  6318:                                         }
                   6319:                                     }
1.100     raeburn  6320:                                     $chgtext .= '</ul>';
                   6321:                                     if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
                   6322:                                         $chgtext .= '<br /><span class="LC_warning">'.&mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').'</span>';
                   6323:                                     }
                   6324:                                 }
                   6325:                             } else {
                   6326:                                 if (@{$cancreate{$type}} == 0) {
                   6327:                                     $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
                   6328:                                 } else {
                   6329:                                     $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  6330:                                 }
                   6331:                             }
                   6332:                         }
1.43      raeburn  6333:                     } else {
                   6334:                         if ($cancreate{$type} eq 'none') {
                   6335:                             $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
                   6336:                         } elsif ($cancreate{$type} eq 'any') {
                   6337:                             $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
                   6338:                         } elsif ($cancreate{$type} eq 'official') {
                   6339:                             $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
                   6340:                         } elsif ($cancreate{$type} eq 'unofficial') {
                   6341:                             $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
                   6342:                         }
1.34      raeburn  6343:                     }
                   6344:                     $resulttext .= '<li>'.$chgtext.'</li>';
1.27      raeburn  6345:                 }
                   6346:             }
                   6347:             if (ref($changes{'username_rule'}) eq 'ARRAY') {
1.32      raeburn  6348:                 my ($rules,$ruleorder) = 
                   6349:                     &Apache::lonnet::inst_userrules($dom,'username');
1.27      raeburn  6350:                 my $chgtext = '<ul>';
                   6351:                 foreach my $type (@username_rule) {
                   6352:                     if (ref($rules->{$type}) eq 'HASH') {
                   6353:                         $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
                   6354:                     }
                   6355:                 }
                   6356:                 $chgtext .= '</ul>';
                   6357:                 if (@username_rule > 0) {
                   6358:                     $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';     
                   6359:                 } else {
1.28      raeburn  6360:                     $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>'; 
1.27      raeburn  6361:                 }
                   6362:             }
1.32      raeburn  6363:             if (ref($changes{'id_rule'}) eq 'ARRAY') {
                   6364:                 my ($idrules,$idruleorder) = 
                   6365:                     &Apache::lonnet::inst_userrules($dom,'id');
                   6366:                 my $chgtext = '<ul>';
                   6367:                 foreach my $type (@id_rule) {
                   6368:                     if (ref($idrules->{$type}) eq 'HASH') {
                   6369:                         $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
                   6370:                     }
                   6371:                 }
                   6372:                 $chgtext .= '</ul>';
                   6373:                 if (@id_rule > 0) {
                   6374:                     $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
                   6375:                 } else {
                   6376:                     $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
                   6377:                 }
                   6378:             }
1.43      raeburn  6379:             if (ref($changes{'email_rule'}) eq 'ARRAY') {
                   6380:                 my ($emailrules,$emailruleorder) =
                   6381:                     &Apache::lonnet::inst_userrules($dom,'email');
                   6382:                 my $chgtext = '<ul>';
                   6383:                 foreach my $type (@email_rule) {
                   6384:                     if (ref($emailrules->{$type}) eq 'HASH') {
                   6385:                         $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
                   6386:                     }
                   6387:                 }
                   6388:                 $chgtext .= '</ul>';
                   6389:                 if (@email_rule > 0) {
                   6390:                     $resulttext .= '<li>'.&mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').$chgtext.'</li>';
                   6391:                 } else {
                   6392:                     $resulttext .= '<li>'.&mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').'</li>';
                   6393:                 }
                   6394:             }
                   6395: 
1.28      raeburn  6396:             my %authname = &authtype_names();
                   6397:             my %context_title = &context_names();
                   6398:             if (ref($changes{'authtypes'}) eq 'ARRAY') {
                   6399:                 my $chgtext = '<ul>';
                   6400:                 foreach my $type (@{$changes{'authtypes'}}) {
                   6401:                     my @allowed;
                   6402:                     $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
                   6403:                     foreach my $auth (@authtypes) {
                   6404:                         if ($authhash{$type}{$auth}) {
                   6405:                             push(@allowed,$authname{$auth});
                   6406:                         }
                   6407:                     }
1.43      raeburn  6408:                     if (@allowed > 0) {
                   6409:                         $chgtext .= join(', ',@allowed).'</li>';
                   6410:                     } else {
                   6411:                         $chgtext .= &mt('none').'</li>';
                   6412:                     }
1.28      raeburn  6413:                 }
                   6414:                 $chgtext .= '</ul>';
                   6415:                 $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
                   6416:                 $resulttext .= '</li>';
                   6417:             }
1.27      raeburn  6418:             $resulttext .= '</ul>';
                   6419:         } else {
1.28      raeburn  6420:             $resulttext = &mt('No changes made to user creation settings');
1.27      raeburn  6421:         }
                   6422:     } else {
                   6423:         $resulttext = '<span class="LC_error">'.
1.23      raeburn  6424:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   6425:     }
1.43      raeburn  6426:     if ($warningmsg ne '') {
                   6427:         $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
                   6428:     }
1.23      raeburn  6429:     return $resulttext;
                   6430: }
                   6431: 
1.33      raeburn  6432: sub modify_usermodification {
                   6433:     my ($dom,%domconfig) = @_;
                   6434:     my ($resulttext,%curr_usermodification,%changes);
                   6435:     if (ref($domconfig{'usermodification'}) eq 'HASH') {
                   6436:         foreach my $key (keys(%{$domconfig{'usermodification'}})) {
                   6437:             $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
                   6438:         }
                   6439:     }
1.63      raeburn  6440:     my @contexts = ('author','course','selfcreate');
1.33      raeburn  6441:     my %context_title = (
                   6442:                            author => 'In author context',
                   6443:                            course => 'In course context',
1.63      raeburn  6444:                            selfcreate => 'When self creating account', 
1.33      raeburn  6445:                         );
                   6446:     my @fields = ('lastname','firstname','middlename','generation',
                   6447:                   'permanentemail','id');
                   6448:     my %roles = (
                   6449:                   author => ['ca','aa'],
                   6450:                   course => ['st','ep','ta','in','cr'],
                   6451:                 );
1.63      raeburn  6452:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   6453:     if (ref($types) eq 'ARRAY') {
                   6454:         push(@{$types},'default');
                   6455:         $usertypes->{'default'} = $othertitle;
                   6456:     }
                   6457:     $roles{'selfcreate'} = $types;  
1.33      raeburn  6458:     my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
                   6459:     my %modifyhash;
                   6460:     foreach my $context (@contexts) {
                   6461:         foreach my $role (@{$roles{$context}}) {
                   6462:             my @modifiable =  &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
                   6463:             foreach my $item (@fields) {
                   6464:                 if (grep(/^\Q$item\E$/,@modifiable)) {
                   6465:                     $modifyhash{$context}{$role}{$item} = 1;
                   6466:                 } else {
                   6467:                     $modifyhash{$context}{$role}{$item} = 0;
                   6468:                 }
                   6469:             }
                   6470:         }
                   6471:         if (ref($curr_usermodification{$context}) eq 'HASH') {
                   6472:             foreach my $role (@{$roles{$context}}) {
                   6473:                 if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
                   6474:                     foreach my $field (@fields) {
                   6475:                         if ($modifyhash{$context}{$role}{$field} ne 
                   6476:                                 $curr_usermodification{$context}{$role}{$field}) {
                   6477:                             push(@{$changes{$context}},$role);
                   6478:                             last;
                   6479:                         }
                   6480:                     }
                   6481:                 }
                   6482:             }
                   6483:         } else {
                   6484:             foreach my $context (@contexts) {
                   6485:                 foreach my $role (@{$roles{$context}}) {
                   6486:                     push(@{$changes{$context}},$role);
                   6487:                 }
                   6488:             }
                   6489:         }
                   6490:     }
                   6491:     my %usermodification_hash =  (
                   6492:                                    usermodification => \%modifyhash,
                   6493:                                  );
                   6494:     my $putresult = &Apache::lonnet::put_dom('configuration',
                   6495:                                              \%usermodification_hash,$dom);
                   6496:     if ($putresult eq 'ok') {
                   6497:         if (keys(%changes) > 0) {
                   6498:             $resulttext = &mt('Changes made: ').'<ul>';
                   6499:             foreach my $context (@contexts) {
                   6500:                 if (ref($changes{$context}) eq 'ARRAY') {
                   6501:                     $resulttext .= '<li>'.$context_title{$context}.':<ul>';
                   6502:                     if (ref($changes{$context}) eq 'ARRAY') {
                   6503:                         foreach my $role (@{$changes{$context}}) {
                   6504:                             my $rolename;
1.63      raeburn  6505:                             if ($context eq 'selfcreate') {
                   6506:                                 $rolename = $role;
                   6507:                                 if (ref($usertypes) eq 'HASH') {
                   6508:                                     if ($usertypes->{$role} ne '') {
                   6509:                                         $rolename = $usertypes->{$role};
                   6510:                                     }
                   6511:                                 }
1.33      raeburn  6512:                             } else {
1.63      raeburn  6513:                                 if ($role eq 'cr') {
                   6514:                                     $rolename = &mt('Custom');
                   6515:                                 } else {
                   6516:                                     $rolename = &Apache::lonnet::plaintext($role);
                   6517:                                 }
1.33      raeburn  6518:                             }
                   6519:                             my @modifiable;
1.63      raeburn  6520:                             if ($context eq 'selfcreate') {
1.126     bisitz   6521:                                 $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  6522:                             } else {
                   6523:                                 $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
                   6524:                             }
1.33      raeburn  6525:                             foreach my $field (@fields) {
                   6526:                                 if ($modifyhash{$context}{$role}{$field}) {
                   6527:                                     push(@modifiable,$fieldtitles{$field});
                   6528:                                 }
                   6529:                             }
                   6530:                             if (@modifiable > 0) {
                   6531:                                 $resulttext .= join(', ',@modifiable);
                   6532:                             } else {
                   6533:                                 $resulttext .= &mt('none'); 
                   6534:                             }
                   6535:                             $resulttext .= '</li>';
                   6536:                         }
                   6537:                         $resulttext .= '</ul></li>';
                   6538:                     }
                   6539:                 }
                   6540:             }
                   6541:             $resulttext .= '</ul>';
                   6542:         } else {
                   6543:             $resulttext = &mt('No changes made to user modification settings');
                   6544:         }
                   6545:     } else {
                   6546:         $resulttext = '<span class="LC_error">'.
                   6547:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   6548:     }
                   6549:     return $resulttext;
                   6550: }
                   6551: 
1.43      raeburn  6552: sub modify_defaults {
                   6553:     my ($dom,$r) = @_;
                   6554:     my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
                   6555:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.141     raeburn  6556:     my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
1.43      raeburn  6557:     my @authtypes = ('internal','krb4','krb5','localauth');
                   6558:     foreach my $item (@items) {
                   6559:         $newvalues{$item} = $env{'form.'.$item};
                   6560:         if ($item eq 'auth_def') {
                   6561:             if ($newvalues{$item} ne '') {
                   6562:                 if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
                   6563:                     push(@errors,$item);
                   6564:                 }
                   6565:             }
                   6566:         } elsif ($item eq 'lang_def') {
                   6567:             if ($newvalues{$item} ne '') {
                   6568:                 if ($newvalues{$item} =~ /^(\w+)/) {
                   6569:                     my $langcode = $1;
1.103     raeburn  6570:                     if ($langcode ne 'x_chef') {
                   6571:                         if (code2language($langcode) eq '') {
                   6572:                             push(@errors,$item);
                   6573:                         }
1.43      raeburn  6574:                     }
                   6575:                 } else {
                   6576:                     push(@errors,$item);
                   6577:                 }
                   6578:             }
1.54      raeburn  6579:         } elsif ($item eq 'timezone_def') {
                   6580:             if ($newvalues{$item} ne '') {
1.62      raeburn  6581:                 if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54      raeburn  6582:                     push(@errors,$item);   
                   6583:                 }
                   6584:             }
1.68      raeburn  6585:         } elsif ($item eq 'datelocale_def') {
                   6586:             if ($newvalues{$item} ne '') {
                   6587:                 my @datelocale_ids = DateTime::Locale->ids();
                   6588:                 if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
                   6589:                     push(@errors,$item);
                   6590:                 }
                   6591:             }
1.141     raeburn  6592:         } elsif ($item eq 'portal_def') {
                   6593:             if ($newvalues{$item} ne '') {
                   6594:                 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])\/?$/) {
                   6595:                     push(@errors,$item);
                   6596:                 }
                   6597:             }
1.43      raeburn  6598:         }
                   6599:         if (grep(/^\Q$item\E$/,@errors)) {
                   6600:             $newvalues{$item} = $domdefaults{$item};
                   6601:         } elsif ($domdefaults{$item} ne $newvalues{$item}) {
                   6602:             $changes{$item} = 1;
                   6603:         }
1.72      raeburn  6604:         $domdefaults{$item} = $newvalues{$item};
1.43      raeburn  6605:     }
                   6606:     my %defaults_hash = (
1.72      raeburn  6607:                          defaults => \%newvalues,
                   6608:                         );
1.43      raeburn  6609:     my $title = &defaults_titles();
                   6610:     my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
                   6611:                                              $dom);
                   6612:     if ($putresult eq 'ok') {
                   6613:         if (keys(%changes) > 0) {
                   6614:             $resulttext = &mt('Changes made:').'<ul>';
                   6615:             my $version = $r->dir_config('lonVersion');
                   6616:             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";
                   6617:             foreach my $item (sort(keys(%changes))) {
                   6618:                 my $value = $env{'form.'.$item};
                   6619:                 if ($value eq '') {
                   6620:                     $value = &mt('none');
                   6621:                 } elsif ($item eq 'auth_def') {
                   6622:                     my %authnames = &authtype_names();
                   6623:                     my %shortauth = (
                   6624:                              internal => 'int',
                   6625:                              krb4 => 'krb4',
                   6626:                              krb5 => 'krb5',
                   6627:                              localauth  => 'loc',
                   6628:                     );
                   6629:                     $value = $authnames{$shortauth{$value}};
                   6630:                 }
                   6631:                 $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
                   6632:                 $mailmsgtext .= "$title->{$item} set to $value\n";  
                   6633:             }
                   6634:             $resulttext .= '</ul>';
                   6635:             $mailmsgtext .= "\n";
                   6636:             my $cachetime = 24*60*60;
1.72      raeburn  6637:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.68      raeburn  6638:             if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.54      raeburn  6639:                 my $sysmail = $r->dir_config('lonSysEMail');
                   6640:                 &Apache::lonmsg::sendemail($sysmail,"LON-CAPA Domain Settings Change - $dom",$mailmsgtext);
                   6641:             }
1.43      raeburn  6642:         } else {
1.54      raeburn  6643:             $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43      raeburn  6644:         }
                   6645:     } else {
                   6646:         $resulttext = '<span class="LC_error">'.
                   6647:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   6648:     }
                   6649:     if (@errors > 0) {
                   6650:         $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
                   6651:         foreach my $item (@errors) {
                   6652:             $resulttext .= ' "'.$title->{$item}.'",';
                   6653:         }
                   6654:         $resulttext =~ s/,$//;
                   6655:     }
                   6656:     return $resulttext;
                   6657: }
                   6658: 
1.46      raeburn  6659: sub modify_scantron {
1.48      raeburn  6660:     my ($r,$dom,$confname,%domconfig) = @_;
1.46      raeburn  6661:     my ($resulttext,%confhash,%changes,$errors);
                   6662:     my $custom = 'custom.tab';
                   6663:     my $default = 'default.tab';
                   6664:     my $servadm = $r->dir_config('lonAdmEMail');
                   6665:     my ($configuserok,$author_ok,$switchserver) = 
                   6666:         &config_check($dom,$confname,$servadm);
                   6667:     if ($env{'form.scantronformat.filename'} ne '') {
                   6668:         my $error;
                   6669:         if ($configuserok eq 'ok') {
                   6670:             if ($switchserver) {
1.130     raeburn  6671:                 $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46      raeburn  6672:             } else {
                   6673:                 if ($author_ok eq 'ok') {
                   6674:                     my ($result,$scantronurl) =
                   6675:                         &publishlogo($r,'upload','scantronformat',$dom,
                   6676:                                      $confname,'scantron','','',$custom);
                   6677:                     if ($result eq 'ok') {
                   6678:                         $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48      raeburn  6679:                         $changes{'scantronformat'} = 1;
1.46      raeburn  6680:                     } else {
                   6681:                         $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
                   6682:                     }
                   6683:                 } else {
                   6684:                     $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);
                   6685:                 }
                   6686:             }
                   6687:         } else {
                   6688:             $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);
                   6689:         }
                   6690:         if ($error) {
                   6691:             &Apache::lonnet::logthis($error);
                   6692:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   6693:         }
                   6694:     }
1.48      raeburn  6695:     if (ref($domconfig{'scantron'}) eq 'HASH') {
                   6696:         if ($domconfig{'scantron'}{'scantronformat'} ne '') {
                   6697:             if ($env{'form.scantronformat_del'}) {
                   6698:                 $confhash{'scantron'}{'scantronformat'} = '';
                   6699:                 $changes{'scantronformat'} = 1;
1.46      raeburn  6700:             }
                   6701:         }
                   6702:     }
                   6703:     if (keys(%confhash) > 0) {
                   6704:         my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
                   6705:                                                  $dom);
                   6706:         if ($putresult eq 'ok') {
                   6707:             if (keys(%changes) > 0) {
1.48      raeburn  6708:                 if (ref($confhash{'scantron'}) eq 'HASH') {
                   6709:                     $resulttext = &mt('Changes made:').'<ul>';
                   6710:                     if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130     raeburn  6711:                         $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48      raeburn  6712:                     } else {
1.130     raeburn  6713:                         $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46      raeburn  6714:                     }
1.48      raeburn  6715:                     $resulttext .= '</ul>';
                   6716:                 } else {
1.130     raeburn  6717:                     $resulttext = &mt('Changes made to bubblesheet format file.');
1.46      raeburn  6718:                 }
                   6719:                 $resulttext .= '</ul>';
                   6720:                 &Apache::loncommon::devalidate_domconfig_cache($dom);
                   6721:             } else {
1.130     raeburn  6722:                 $resulttext = &mt('No changes made to bubblesheet format file');
1.46      raeburn  6723:             }
                   6724:         } else {
                   6725:             $resulttext = '<span class="LC_error">'.
                   6726:                 &mt('An error occurred: [_1]',$putresult).'</span>';
                   6727:         }
                   6728:     } else {
1.130     raeburn  6729:         $resulttext = &mt('No changes made to bubblesheet format file'); 
1.46      raeburn  6730:     }
                   6731:     if ($errors) {
                   6732:         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
                   6733:                        $errors.'</ul>';
                   6734:     }
                   6735:     return $resulttext;
                   6736: }
                   6737: 
1.48      raeburn  6738: sub modify_coursecategories {
                   6739:     my ($dom,%domconfig) = @_;
1.57      raeburn  6740:     my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
                   6741:         $cathash);
1.48      raeburn  6742:     my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.55      raeburn  6743:     if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57      raeburn  6744:         $cathash = $domconfig{'coursecategories'}{'cats'};
                   6745:         if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
                   6746:             $changes{'togglecats'} = 1;
                   6747:             $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
                   6748:         }
                   6749:         if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
                   6750:             $changes{'categorize'} = 1;
                   6751:             $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
                   6752:         }
1.120     raeburn  6753:         if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
                   6754:             $changes{'togglecatscomm'} = 1;
                   6755:             $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
                   6756:         }
                   6757:         if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
                   6758:             $changes{'categorizecomm'} = 1;
                   6759:             $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
                   6760:         }
1.57      raeburn  6761:     } else {
                   6762:         $changes{'togglecats'} = 1;
                   6763:         $changes{'categorize'} = 1;
1.124     raeburn  6764:         $changes{'togglecatscomm'} = 1;
                   6765:         $changes{'categorizecomm'} = 1;
1.87      raeburn  6766:         $domconfig{'coursecategories'} = {
                   6767:                                              togglecats => $env{'form.togglecats'},
                   6768:                                              categorize => $env{'form.categorize'},
1.124     raeburn  6769:                                              togglecatscomm => $env{'form.togglecatscomm'},
                   6770:                                              categorizecomm => $env{'form.categorizecomm'},
1.120     raeburn  6771:                                          };
1.57      raeburn  6772:     }
                   6773:     if (ref($cathash) eq 'HASH') {
                   6774:         if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '')  && ($env{'form.instcode'} == 0)) {
1.55      raeburn  6775:             push (@deletecategory,'instcode::0');
                   6776:         }
1.120     raeburn  6777:         if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '')  && ($env{'form.communities'} == 0)) {
                   6778:             push(@deletecategory,'communities::0');
                   6779:         }
1.48      raeburn  6780:     }
1.57      raeburn  6781:     my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
                   6782:     if (ref($cathash) eq 'HASH') {
1.48      raeburn  6783:         if (@deletecategory > 0) {
                   6784:             #FIXME Need to remove category from all courses using a deleted category 
1.57      raeburn  6785:             &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48      raeburn  6786:             foreach my $item (@deletecategory) {
1.57      raeburn  6787:                 if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
                   6788:                     delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48      raeburn  6789:                     $deletions{$item} = 1;
1.57      raeburn  6790:                     &recurse_cat_deletes($item,$cathash,\%deletions);
1.48      raeburn  6791:                 }
                   6792:             }
                   6793:         }
1.57      raeburn  6794:         foreach my $item (keys(%{$cathash})) {
1.48      raeburn  6795:             my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57      raeburn  6796:             if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48      raeburn  6797:                 $reorderings{$item} = 1;
1.57      raeburn  6798:                 $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48      raeburn  6799:             }
                   6800:             if ($env{'form.addcategory_name_'.$item} ne '') {
                   6801:                 my $newcat = $env{'form.addcategory_name_'.$item};
                   6802:                 my $newdepth = $depth+1;
                   6803:                 my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57      raeburn  6804:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48      raeburn  6805:                 $adds{$newitem} = 1; 
                   6806:             }
                   6807:             if ($env{'form.subcat_'.$item} ne '') {
                   6808:                 my $newcat = $env{'form.subcat_'.$item};
                   6809:                 my $newdepth = $depth+1;
                   6810:                 my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57      raeburn  6811:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48      raeburn  6812:                 $adds{$newitem} = 1;
                   6813:             }
                   6814:         }
                   6815:     }
                   6816:     if ($env{'form.instcode'} eq '1') {
1.57      raeburn  6817:         if (ref($cathash) eq 'HASH') {
1.48      raeburn  6818:             my $newitem = 'instcode::0';
1.57      raeburn  6819:             if ($cathash->{$newitem} eq '') {  
                   6820:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48      raeburn  6821:                 $adds{$newitem} = 1;
                   6822:             }
                   6823:         } else {
                   6824:             my $newitem = 'instcode::0';
1.57      raeburn  6825:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48      raeburn  6826:             $adds{$newitem} = 1;
                   6827:         }
                   6828:     }
1.120     raeburn  6829:     if ($env{'form.communities'} eq '1') {
                   6830:         if (ref($cathash) eq 'HASH') {
                   6831:             my $newitem = 'communities::0';
                   6832:             if ($cathash->{$newitem} eq '') {
                   6833:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
                   6834:                 $adds{$newitem} = 1;
                   6835:             }
                   6836:         } else {
                   6837:             my $newitem = 'communities::0';
                   6838:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
                   6839:             $adds{$newitem} = 1;
                   6840:         }
                   6841:     }
1.48      raeburn  6842:     if ($env{'form.addcategory_name'} ne '') {
1.120     raeburn  6843:         if (($env{'form.addcategory_name'} ne 'instcode') &&
                   6844:             ($env{'form.addcategory_name'} ne 'communities')) {
                   6845:             my $newitem = &escape($env{'form.addcategory_name'}).'::0';
                   6846:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
                   6847:             $adds{$newitem} = 1;
                   6848:         }
1.48      raeburn  6849:     }
1.57      raeburn  6850:     my $putresult;
1.48      raeburn  6851:     if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
                   6852:         if (keys(%deletions) > 0) {
                   6853:             foreach my $key (keys(%deletions)) {
                   6854:                 if ($predelallitems{$key} ne '') {
                   6855:                     $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
                   6856:                 }
                   6857:             }
                   6858:         }
                   6859:         my (@chkcats,@chktrails,%chkallitems);
1.57      raeburn  6860:         &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48      raeburn  6861:         if (ref($chkcats[0]) eq 'ARRAY') {
                   6862:             my $depth = 0;
                   6863:             my $chg = 0;
                   6864:             for (my $i=0; $i<@{$chkcats[0]}; $i++) {
                   6865:                 my $name = $chkcats[0][$i];
                   6866:                 my $item;
                   6867:                 if ($name eq '') {
                   6868:                     $chg ++;
                   6869:                 } else {
                   6870:                     $item = &escape($name).'::0';
                   6871:                     if ($chg) {
1.57      raeburn  6872:                         $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48      raeburn  6873:                     }
                   6874:                     $depth ++; 
1.57      raeburn  6875:                     &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48      raeburn  6876:                     $depth --;
                   6877:                 }
                   6878:             }
                   6879:         }
1.57      raeburn  6880:     }
                   6881:     if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
                   6882:         $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48      raeburn  6883:         if ($putresult eq 'ok') {
1.57      raeburn  6884:             my %title = (
1.120     raeburn  6885:                          togglecats     => 'Show/Hide a course in catalog',
                   6886:                          categorize     => 'Assign a category to a course',
                   6887:                          togglecatscomm => 'Show/Hide a community in catalog',
                   6888:                          categorizecomm => 'Assign a category to a community',
1.57      raeburn  6889:                         );
                   6890:             my %level = (
1.120     raeburn  6891:                          dom  => 'set in Domain ("Modify Course/Community")',
                   6892:                          crs  => 'set in Course ("Course Configuration")',
                   6893:                          comm => 'set in Community ("Community Configuration")',
1.57      raeburn  6894:                         );
1.48      raeburn  6895:             $resulttext = &mt('Changes made:').'<ul>';
1.57      raeburn  6896:             if ($changes{'togglecats'}) {
                   6897:                 $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>'; 
                   6898:             }
                   6899:             if ($changes{'categorize'}) {
                   6900:                 $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48      raeburn  6901:             }
1.120     raeburn  6902:             if ($changes{'togglecatscomm'}) {
                   6903:                 $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
                   6904:             }
                   6905:             if ($changes{'categorizecomm'}) {
                   6906:                 $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
                   6907:             }
1.57      raeburn  6908:             if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
                   6909:                 my $cathash;
                   6910:                 if (ref($domconfig{'coursecategories'}) eq 'HASH') {
                   6911:                     $cathash = $domconfig{'coursecategories'}{'cats'};
                   6912:                 } else {
                   6913:                     $cathash = {};
                   6914:                 } 
                   6915:                 my (@cats,@trails,%allitems);
                   6916:                     &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
                   6917:                 if (keys(%deletions) > 0) {
                   6918:                     $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
                   6919:                     foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) { 
                   6920:                         $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
                   6921:                     }
                   6922:                     $resulttext .= '</ul></li>';
                   6923:                 }
                   6924:                 if (keys(%reorderings) > 0) {
                   6925:                     my %sort_by_trail;
                   6926:                     $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
                   6927:                     foreach my $key (keys(%reorderings)) {
                   6928:                         if ($allitems{$key} ne '') {
                   6929:                             $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
                   6930:                         }
1.48      raeburn  6931:                     }
1.57      raeburn  6932:                     foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
                   6933:                         $resulttext .= '<li>'.$trails[$trail].'</li>';
                   6934:                     }
                   6935:                     $resulttext .= '</ul></li>';
1.48      raeburn  6936:                 }
1.57      raeburn  6937:                 if (keys(%adds) > 0) {
                   6938:                     my %sort_by_trail;
                   6939:                     $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
                   6940:                     foreach my $key (keys(%adds)) {
                   6941:                         if ($allitems{$key} ne '') {
                   6942:                             $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
                   6943:                         }
                   6944:                     }
                   6945:                     foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
                   6946:                         $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48      raeburn  6947:                     }
1.57      raeburn  6948:                     $resulttext .= '</ul></li>';
1.48      raeburn  6949:                 }
                   6950:             }
                   6951:             $resulttext .= '</ul>';
                   6952:         } else {
                   6953:             $resulttext = '<span class="LC_error">'.
1.57      raeburn  6954:                           &mt('An error occurred: [_1]',$putresult).'</span>';
1.48      raeburn  6955:         }
                   6956:     } else {
1.120     raeburn  6957:         $resulttext = &mt('No changes made to course and community categories');
1.48      raeburn  6958:     }
                   6959:     return $resulttext;
                   6960: }
                   6961: 
1.69      raeburn  6962: sub modify_serverstatuses {
                   6963:     my ($dom,%domconfig) = @_;
                   6964:     my ($resulttext,%changes,%currserverstatus,%newserverstatus);
                   6965:     if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
                   6966:         %currserverstatus = %{$domconfig{'serverstatuses'}};
                   6967:     }
                   6968:     my @pages = &serverstatus_pages();
                   6969:     foreach my $type (@pages) {
                   6970:         $newserverstatus{$type}{'namedusers'} = '';
                   6971:         $newserverstatus{$type}{'machines'} = '';
                   6972:         if (defined($env{'form.'.$type.'_namedusers'})) {
                   6973:             my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
                   6974:             my @okusers;
                   6975:             foreach my $user (@users) {
                   6976:                 my ($uname,$udom) = split(/:/,$user);
                   6977:                 if (($udom =~ /^$match_domain$/) &&   
                   6978:                     (&Apache::lonnet::domain($udom)) &&
                   6979:                     ($uname =~ /^$match_username$/)) {
                   6980:                     if (!grep(/^\Q$user\E/,@okusers)) {
                   6981:                         push(@okusers,$user);
                   6982:                     }
                   6983:                 }
                   6984:             }
                   6985:             if (@okusers > 0) {
                   6986:                  @okusers = sort(@okusers);
                   6987:                  $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
                   6988:             }
                   6989:         }
                   6990:         if (defined($env{'form.'.$type.'_machines'})) {
                   6991:             my @machines = split(/,/,$env{'form.'.$type.'_machines'});
                   6992:             my @okmachines;
                   6993:             foreach my $ip (@machines) {
                   6994:                 my @parts = split(/\./,$ip);
                   6995:                 next if (@parts < 4);
                   6996:                 my $badip = 0;
                   6997:                 for (my $i=0; $i<4; $i++) {
                   6998:                     if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
                   6999:                         $badip = 1;
                   7000:                         last;
                   7001:                     }
                   7002:                 }
                   7003:                 if (!$badip) {
                   7004:                     push(@okmachines,$ip);     
                   7005:                 }
                   7006:             }
                   7007:             @okmachines = sort(@okmachines);
                   7008:             $newserverstatus{$type}{'machines'} = join(',',@okmachines);
                   7009:         }
                   7010:     }
                   7011:     my %serverstatushash =  (
                   7012:                                 serverstatuses => \%newserverstatus,
                   7013:                             );
                   7014:     foreach my $type (@pages) {
1.83      raeburn  7015:         foreach my $setting ('namedusers','machines') {
1.84      raeburn  7016:             my (@current,@new);
1.83      raeburn  7017:             if (ref($currserverstatus{$type}) eq 'HASH') {
1.84      raeburn  7018:                 if ($currserverstatus{$type}{$setting} ne '') { 
                   7019:                     @current = split(/,/,$currserverstatus{$type}{$setting});
                   7020:                 }
                   7021:             }
                   7022:             if ($newserverstatus{$type}{$setting} ne '') {
                   7023:                 @new = split(/,/,$newserverstatus{$type}{$setting});
1.83      raeburn  7024:             }
                   7025:             if (@current > 0) {
                   7026:                 if (@new > 0) {
                   7027:                     foreach my $item (@current) {
                   7028:                         if (!grep(/^\Q$item\E$/,@new)) {
                   7029:                             $changes{$type}{$setting} = 1;
1.82      raeburn  7030:                             last;
                   7031:                         }
                   7032:                     }
1.84      raeburn  7033:                     foreach my $item (@new) {
                   7034:                         if (!grep(/^\Q$item\E$/,@current)) {
                   7035:                             $changes{$type}{$setting} = 1;
                   7036:                             last;
1.82      raeburn  7037:                         }
                   7038:                     }
                   7039:                 } else {
1.83      raeburn  7040:                     $changes{$type}{$setting} = 1;
1.69      raeburn  7041:                 }
1.83      raeburn  7042:             } elsif (@new > 0) {
                   7043:                 $changes{$type}{$setting} = 1;
1.69      raeburn  7044:             }
                   7045:         }
                   7046:     }
                   7047:     if (keys(%changes) > 0) {
1.81      raeburn  7048:         my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69      raeburn  7049:         my $putresult = &Apache::lonnet::put_dom('configuration',
                   7050:                                                  \%serverstatushash,$dom);
                   7051:         if ($putresult eq 'ok') {
                   7052:             $resulttext .= &mt('Changes made:').'<ul>';
                   7053:             foreach my $type (@pages) {
1.84      raeburn  7054:                 if (ref($changes{$type}) eq 'HASH') {
1.69      raeburn  7055:                     $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84      raeburn  7056:                     if ($changes{$type}{'namedusers'}) {
1.69      raeburn  7057:                         if ($newserverstatus{$type}{'namedusers'} eq '') {
                   7058:                             $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
                   7059:                         } else {
                   7060:                             $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
                   7061:                         }
1.84      raeburn  7062:                     }
                   7063:                     if ($changes{$type}{'machines'}) {
1.69      raeburn  7064:                         if ($newserverstatus{$type}{'machines'} eq '') {
                   7065:                             $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
                   7066:                         } else {
                   7067:                             $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
                   7068:                         }
                   7069: 
                   7070:                     }
                   7071:                     $resulttext .= '</ul></li>';
                   7072:                 }
                   7073:             }
                   7074:             $resulttext .= '</ul>';
                   7075:         } else {
                   7076:             $resulttext = '<span class="LC_error">'.
                   7077:                           &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
                   7078: 
                   7079:         }
                   7080:     } else {
                   7081:         $resulttext = &mt('No changes made to access to server status pages');
                   7082:     }
                   7083:     return $resulttext;
                   7084: }
                   7085: 
1.118     jms      7086: sub modify_helpsettings {
1.122     jms      7087:     my ($r,$dom,$confname,%domconfig) = @_;
1.118     jms      7088:  	my ($resulttext,$errors,%changes,%helphash);
                   7089:  	
1.122     jms      7090:  	my $customhelpfile  = $env{'form.loginhelpurl.filename'};
                   7091:     my $defaulthelpfile = 'defaulthelp.html';
                   7092:  	my $servadm = $r->dir_config('lonAdmEMail');
                   7093:     my ($configuserok,$author_ok,$switchserver) = 
                   7094:         &config_check($dom,$confname,$servadm);
                   7095:  	
1.118     jms      7096:  	my %defaultchecked = ('submitbugs'	=> 'on');
                   7097:  	my @offon = ('off','on');
1.122     jms      7098:     my %title = ( submitbugs     => 'Display link for users to submit a bug', 
                   7099:     			  loginhelpurl  => 'Unauthenticated login help page set to custom file');
                   7100:     			  
1.118     jms      7101:     my @toggles = ('submitbugs');
                   7102: 
                   7103:     $helphash{'helpsettings'} = {};
                   7104:     
                   7105:     if (ref($domconfig{'helpsettings'}) ne 'HASH') {
                   7106:         if ($domconfig{'helpsettings'} eq '') {
                   7107:             $domconfig{'helpsettings'} = {};
                   7108:         }
                   7109:     }
                   7110:     
                   7111:     if (ref($domconfig{'helpsettings'}) eq 'HASH') {
                   7112:     	
                   7113:         foreach my $item (@toggles) {
                   7114:         	
                   7115: 			if ($defaultchecked{$item} eq 'on') { 
                   7116: 				if (($domconfig{'helpsettings'}{$item} eq '') &&
                   7117: 					 ($env{'form.'.$item} eq '0')) {
                   7118: 					$changes{$item} = 1;
                   7119: 				} elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
                   7120: 					$changes{$item} = 1;
                   7121: 				}
                   7122: 			} elsif ($defaultchecked{$item} eq 'off') {
                   7123: 				if (($domconfig{'helpsettings'}{$item} eq '') &&
                   7124: 					 ($env{'form.'.$item} eq '1')) {
                   7125: 					$changes{$item} = 1;
                   7126: 				} elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
                   7127: 					$changes{$item} = 1;
                   7128: 				}
                   7129: 			}
                   7130: 			$helphash{'helpsettings'}{$item} = $env{'form.'.$item};
1.122     jms      7131: 		}
                   7132: 		
                   7133: 		if ($customhelpfile ne '') {
                   7134: 			my $error;
                   7135: 			if ($configuserok eq 'ok') {
                   7136: 				if ($switchserver) {
                   7137: 					$error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
                   7138: 				} else {
                   7139: 					if ($author_ok eq 'ok') {
                   7140: 						my ($result,$loginhelpurl) =
                   7141: 							&publishlogo($r,'upload','loginhelpurl',$dom,
                   7142: 										 $confname,'help','','',$customhelpfile);
                   7143: 						if ($result eq 'ok') {
                   7144: 							$helphash{'helpsettings'}{'loginhelpurl'} = $loginhelpurl;
                   7145: 							$changes{'loginhelpurl'} = 1;
                   7146: 						} else {
                   7147: 							$error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customhelpfile,$result);
                   7148: 						}
                   7149: 					} else {
                   7150: 						$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);
                   7151: 					}
                   7152: 				}
                   7153: 			} else {
                   7154: 				$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);
                   7155: 			}
                   7156: 			if ($error) {
                   7157: 				&Apache::lonnet::logthis($error);
                   7158: 				$errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   7159: 			}
                   7160: 		}
                   7161: 		
                   7162:         if ($domconfig{'helpsettings'}{'loginhelpurl'} ne '') {
                   7163:             if ($env{'form.loginhelpurl_del'}) {
                   7164:                 $helphash{'helpsettings'}{'loginhelpurl'} = '';
                   7165:                 $changes{'loginhelpurl'} = 1;
                   7166:             }
                   7167:         }
1.118     jms      7168:     }
                   7169:     
1.123     jms      7170:     
                   7171:     my $putresult;
                   7172:     
                   7173:     if (keys(%changes) > 0) {
                   7174:     	$putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
                   7175:     } else {
                   7176:     	$putresult = 'ok';
                   7177:     }
1.118     jms      7178:                                              
                   7179:     if ($putresult eq 'ok') {
                   7180:         if (keys(%changes) > 0) {
                   7181: 			$resulttext = &mt('Changes made:').'<ul>';
                   7182: 			foreach my $item (sort(keys(%changes))) {
                   7183: 				if ($item eq 'submitbugs') {
                   7184: 					$resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
                   7185: 				}
1.122     jms      7186: 				if ($item eq 'loginhelpurl') {
                   7187: 					if ($helphash{'helpsettings'}{'loginhelpurl'} eq '') {
                   7188:                         $resulttext .= '<li>'.&mt('[_1] help file removed; [_2] file will be used for the unathorized help page in this domain.',$customhelpfile,$defaulthelpfile).'</li>';
                   7189:                     } else {
                   7190:                         $resulttext .= '<li>'.&mt("$title{$item} [_1]",$customhelpfile).'</li>';
                   7191:                     }
                   7192: 				}
1.118     jms      7193: 			}
                   7194: 			$resulttext .= '</ul>';
                   7195: 		} else {
                   7196: 			$resulttext = &mt('No changes made to help settings');
                   7197: 		}
                   7198:     } else {
                   7199:         $resulttext = '<span class="LC_error">'.
                   7200: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
                   7201:     }
                   7202:     if ($errors) {
                   7203:         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
                   7204:                        $errors.'</ul>';
                   7205:     }
                   7206:     return $resulttext;
                   7207: }
                   7208: 
1.121     raeburn  7209: sub modify_coursedefaults {
                   7210:     my ($dom,%domconfig) = @_;
                   7211:     my ($resulttext,$errors,%changes,%defaultshash);
                   7212:     my %defaultchecked = ('canuse_pdfforms' => 'off');
                   7213:     my @offon = ('off','on');
                   7214:     my @toggles = ('canuse_pdfforms');
                   7215: 
                   7216:     $defaultshash{'coursedefaults'} = {};
                   7217: 
                   7218:     if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
                   7219:         if ($domconfig{'coursedefaults'} eq '') {
                   7220:             $domconfig{'coursedefaults'} = {};
                   7221:         }
                   7222:     }
                   7223: 
                   7224:     if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
                   7225:         foreach my $item (@toggles) {
                   7226:             if ($defaultchecked{$item} eq 'on') {
                   7227:                 if (($domconfig{'coursedefaults'}{$item} eq '') &&
                   7228:                     ($env{'form.'.$item} eq '0')) {
                   7229:                     $changes{$item} = 1;
                   7230:                 } elsif ($domconfig{'coursdefaults'}{$item} ne $env{'form.'.$item}) {
                   7231:                     $changes{$item} = 1;
                   7232:                 }
                   7233:             } elsif ($defaultchecked{$item} eq 'off') {
                   7234:                 if (($domconfig{'coursedefaults'}{$item} eq '') &&
                   7235:                     ($env{'form.'.$item} eq '1')) {
                   7236:                     $changes{$item} = 1;
                   7237:                 } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
                   7238:                     $changes{$item} = 1;
                   7239:                 }
                   7240:             }
                   7241:             $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
                   7242:         }
1.139     raeburn  7243:         my $currdefresponder = $domconfig{'coursedefaults'}{'anonsurvey_threshold'};
                   7244:         my $newdefresponder = $env{'form.anonsurvey_threshold'};
                   7245:         $newdefresponder =~ s/\D//g;
                   7246:         if ($newdefresponder eq '' || $newdefresponder < 1) {
                   7247:             $newdefresponder = 1;
                   7248:         }
                   7249:         $defaultshash{'coursedefaults'}{'anonsurvey_threshold'} = $newdefresponder;
                   7250:         if ($currdefresponder ne $newdefresponder) {
                   7251:             unless ($currdefresponder eq '' && $newdefresponder == 10) {
                   7252:                 $changes{'anonsurvey_threshold'} = 1;
                   7253:             }
                   7254:         }
1.121     raeburn  7255:     }
                   7256:     my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
                   7257:                                              $dom);
                   7258:     if ($putresult eq 'ok') {
                   7259:         if (keys(%changes) > 0) {
                   7260:             if ($changes{'canuse_pdfforms'}) {
                   7261:                 my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
                   7262:                 $domdefaults{'canuse_pdfforms'}=$defaultshash{'coursedefaults'}{'canuse_pdfforms'};
                   7263:                 my $cachetime = 24*60*60;
                   7264:                 &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
                   7265:             }
                   7266:             $resulttext = &mt('Changes made:').'<ul>';
                   7267:             foreach my $item (sort(keys(%changes))) {
                   7268:                 if ($item eq 'canuse_pdfforms') {
                   7269:                     if ($env{'form.'.$item} eq '1') {
                   7270:                         $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
                   7271:                     } else {
                   7272:                         $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
                   7273:                     }
1.139     raeburn  7274:                 } elsif ($item eq 'anonsurvey_threshold') {
                   7275:                         $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.140     raeburn  7276:                 }
1.121     raeburn  7277:             }
                   7278:             $resulttext .= '</ul>';
                   7279:         } else {
                   7280:             $resulttext = &mt('No changes made to course defaults');
                   7281:         }
                   7282:     } else {
                   7283:         $resulttext = '<span class="LC_error">'.
                   7284:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   7285:     }
                   7286:     return $resulttext;
                   7287: }
                   7288: 
1.137     raeburn  7289: sub modify_usersessions {
                   7290:     my ($dom,%domconfig) = @_;
1.145     raeburn  7291:     my @hostingtypes = ('version','excludedomain','includedomain');
                   7292:     my @offloadtypes = ('primary','default');
                   7293:     my %types = (
                   7294:                   remote => \@hostingtypes,
                   7295:                   hosted => \@hostingtypes,
                   7296:                   spares => \@offloadtypes,
                   7297:                 );
                   7298:     my @prefixes = ('remote','hosted','spares');
1.137     raeburn  7299:     my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138     raeburn  7300:     my (%by_ip,%by_location,@intdoms);
                   7301:     &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
                   7302:     my @locations = sort(keys(%by_location));
1.137     raeburn  7303:     my (%defaultshash,%changes);
                   7304:     foreach my $prefix (@prefixes) {
                   7305:         $defaultshash{'usersessions'}{$prefix} = {};
                   7306:     }
                   7307:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
                   7308:     my $resulttext;
1.138     raeburn  7309:     my %iphost = &Apache::lonnet::get_iphost();
1.137     raeburn  7310:     foreach my $prefix (@prefixes) {
1.145     raeburn  7311:         next if ($prefix eq 'spares');
                   7312:         foreach my $type (@{$types{$prefix}}) {
1.137     raeburn  7313:             my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
                   7314:             if ($type eq 'version') {
                   7315:                 my $value = $env{'form.'.$prefix.'_'.$type};
                   7316:                 my $okvalue;
                   7317:                 if ($value ne '') {
                   7318:                     if (grep(/^\Q$value\E$/,@lcversions)) {
                   7319:                         $okvalue = $value;
                   7320:                     }
                   7321:                 }
                   7322:                 if (ref($domconfig{'usersessions'}) eq 'HASH') {
                   7323:                     if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
                   7324:                         if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
                   7325:                             if ($inuse == 0) {
                   7326:                                 $changes{$prefix}{$type} = 1;
                   7327:                             } else {
                   7328:                                 if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
                   7329:                                     $changes{$prefix}{$type} = 1;
                   7330:                                 }
                   7331:                                 if ($okvalue ne '') {
                   7332:                                     $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
                   7333:                                 } 
                   7334:                             }
                   7335:                         } else {
                   7336:                             if (($inuse == 1) && ($okvalue ne '')) {
                   7337:                                 $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
                   7338:                                 $changes{$prefix}{$type} = 1;
                   7339:                             }
                   7340:                         }
                   7341:                     } else {
                   7342:                         if (($inuse == 1) && ($okvalue ne '')) {
                   7343:                             $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
                   7344:                             $changes{$prefix}{$type} = 1;
                   7345:                         }
                   7346:                     }
                   7347:                 } else {
                   7348:                     if (($inuse == 1) && ($okvalue ne '')) {
                   7349:                         $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
                   7350:                         $changes{$prefix}{$type} = 1;
                   7351:                     }
                   7352:                 }
                   7353:             } else {
                   7354:                 my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
                   7355:                 my @okvals;
                   7356:                 foreach my $val (@vals) {
1.138     raeburn  7357:                     if ($val =~ /:/) {
                   7358:                         my @items = split(/:/,$val);
                   7359:                         foreach my $item (@items) {
                   7360:                             if (ref($by_location{$item}) eq 'ARRAY') {
                   7361:                                 push(@okvals,$item);
                   7362:                             }
                   7363:                         }
                   7364:                     } else {
                   7365:                         if (ref($by_location{$val}) eq 'ARRAY') {
                   7366:                             push(@okvals,$val);
                   7367:                         }
1.137     raeburn  7368:                     }
                   7369:                 }
                   7370:                 @okvals = sort(@okvals);
                   7371:                 if (ref($domconfig{'usersessions'}) eq 'HASH') {
                   7372:                     if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
                   7373:                         if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
                   7374:                             if ($inuse == 0) {
                   7375:                                 $changes{$prefix}{$type} = 1; 
                   7376:                             } else {
                   7377:                                 $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
                   7378:                                 my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
                   7379:                                 if (@changed > 0) {
                   7380:                                     $changes{$prefix}{$type} = 1;
                   7381:                                 }
                   7382:                             }
                   7383:                         } else {
                   7384:                             if ($inuse == 1) {
                   7385:                                 $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
                   7386:                                 $changes{$prefix}{$type} = 1;
                   7387:                             }
                   7388:                         } 
                   7389:                     } else {
                   7390:                         if ($inuse == 1) {
                   7391:                             $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
                   7392:                             $changes{$prefix}{$type} = 1;
                   7393:                         }
                   7394:                     }
                   7395:                 } else {
                   7396:                     if ($inuse == 1) {
                   7397:                         $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
                   7398:                         $changes{$prefix}{$type} = 1;
                   7399:                     }
                   7400:                 }
                   7401:             }
                   7402:         }
                   7403:     }
1.145     raeburn  7404: 
                   7405:     my @alldoms = &Apache::lonnet::all_domains();
1.149     raeburn  7406:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145     raeburn  7407:     my %spareid = &current_offloads_to($dom,$domconfig{'usersessions'},\%servers);
                   7408:     my $savespares;
                   7409: 
                   7410:     foreach my $lonhost (sort(keys(%servers))) {
                   7411:         my $serverhomeID =
                   7412:             &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152     raeburn  7413:         my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145     raeburn  7414:         $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
                   7415:         my %spareschg;
                   7416:         foreach my $type (@{$types{'spares'}}) {
                   7417:             my @okspares;
                   7418:             my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
                   7419:             foreach my $server (@checked) {
1.152     raeburn  7420:                 if (&Apache::lonnet::hostname($server) ne '') {
                   7421:                     unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
                   7422:                         unless (grep(/^\Q$server\E$/,@okspares)) {
                   7423:                             push(@okspares,$server);
                   7424:                         }
1.145     raeburn  7425:                     }
                   7426:                 }
                   7427:             }
                   7428:             my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
                   7429:             my $newspare;
1.152     raeburn  7430:             if (($new ne '') && (&Apache::lonnet::hostname($new))) {
                   7431:                 unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145     raeburn  7432:                     $newspare = $new;
                   7433:                 }
                   7434:             }
1.152     raeburn  7435:             my @spares;
                   7436:             if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
                   7437:                 @spares = sort(@okspares,$newspare);
                   7438:             } else {
                   7439:                 @spares = sort(@okspares);
                   7440:             }
                   7441:             $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145     raeburn  7442:             if (ref($spareid{$lonhost}) eq 'HASH') {
                   7443:                 if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152     raeburn  7444:                     my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145     raeburn  7445:                     if (@diffs > 0) {
                   7446:                         $spareschg{$type} = 1;
                   7447:                     }
                   7448:                 }
                   7449:             }
                   7450:         }
                   7451:         if (keys(%spareschg) > 0) {
                   7452:             $changes{'spares'}{$lonhost} = \%spareschg;
                   7453:         }
                   7454:     }
                   7455: 
                   7456:     if (ref($domconfig{'usersessions'}) eq 'HASH') {
                   7457:         if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
                   7458:             if (ref($changes{'spares'}) eq 'HASH') {
                   7459:                 if (keys(%{$changes{'spares'}}) > 0) {
                   7460:                     $savespares = 1;
                   7461:                 }
                   7462:             }
                   7463:         } else {
                   7464:             $savespares = 1;
                   7465:         }
                   7466:     }
                   7467: 
1.147     raeburn  7468:     my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
                   7469:     if ((keys(%changes) > 0) || ($savespares)) {
1.137     raeburn  7470:         my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
                   7471:                                                  $dom);
                   7472:         if ($putresult eq 'ok') {
                   7473:             if (ref($defaultshash{'usersessions'}) eq 'HASH') {
                   7474:                 if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
                   7475:                     $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
                   7476:                 }
                   7477:                 if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
                   7478:                     $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
                   7479:                 }
                   7480:             }
                   7481:             my $cachetime = 24*60*60;
                   7482:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.147     raeburn  7483:             if (keys(%changes) > 0) {
                   7484:                 my %lt = &usersession_titles();
                   7485:                 $resulttext = &mt('Changes made:').'<ul>';
                   7486:                 foreach my $prefix (@prefixes) {
                   7487:                     if (ref($changes{$prefix}) eq 'HASH') {
                   7488:                         $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
                   7489:                         if ($prefix eq 'spares') {
                   7490:                             if (ref($changes{$prefix}) eq 'HASH') {
                   7491:                                 foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
                   7492:                                     $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148     raeburn  7493:                                     my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
                   7494:                                     &Apache::lonnet::remote_devalidate_cache($lonhost,'spares',$lonhostdom);
1.147     raeburn  7495:                                     if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
                   7496:                                         foreach my $type (@{$types{$prefix}}) {
                   7497:                                             if ($changes{$prefix}{$lonhost}{$type}) {
                   7498:                                                 my $offloadto = &mt('None');
                   7499:                                                 if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
                   7500:                                                     if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {   
                   7501:                                                         $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
                   7502:                                                     }
1.145     raeburn  7503:                                                 }
1.147     raeburn  7504:                                                 $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).('&nbsp;'x3);
1.145     raeburn  7505:                                             }
1.137     raeburn  7506:                                         }
                   7507:                                     }
1.147     raeburn  7508:                                     $resulttext .= '</li>';
1.137     raeburn  7509:                                 }
                   7510:                             }
1.147     raeburn  7511:                         } else {
                   7512:                             foreach my $type (@{$types{$prefix}}) {
                   7513:                                 if (defined($changes{$prefix}{$type})) {
                   7514:                                     my $newvalue;
                   7515:                                     if (ref($defaultshash{'usersessions'}) eq 'HASH') {
                   7516:                                         if (ref($defaultshash{'usersessions'}{$prefix})) {
                   7517:                                             if ($type eq 'version') {
                   7518:                                                 $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
                   7519:                                             } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
                   7520:                                                 if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
                   7521:                                                     $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
                   7522:                                                 }
1.145     raeburn  7523:                                             }
                   7524:                                         }
                   7525:                                     }
1.147     raeburn  7526:                                     if ($newvalue eq '') {
                   7527:                                         if ($type eq 'version') {
                   7528:                                             $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
                   7529:                                         } else {
                   7530:                                             $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
                   7531:                                         }
1.145     raeburn  7532:                                     } else {
1.147     raeburn  7533:                                         if ($type eq 'version') {
                   7534:                                             $newvalue .= ' '.&mt('(or later)'); 
                   7535:                                         }
                   7536:                                         $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145     raeburn  7537:                                     }
1.137     raeburn  7538:                                 }
                   7539:                             }
                   7540:                         }
1.147     raeburn  7541:                         $resulttext .= '</ul>';
1.137     raeburn  7542:                     }
                   7543:                 }
1.147     raeburn  7544:                 $resulttext .= '</ul>';
                   7545:             } else {
                   7546:                 $resulttext = $nochgmsg;
1.137     raeburn  7547:             }
                   7548:         } else {
                   7549:             $resulttext = '<span class="LC_error">'.
                   7550:                           &mt('An error occurred: [_1]',$putresult).'</span>';
                   7551:         }
                   7552:     } else {
1.147     raeburn  7553:         $resulttext = $nochgmsg;
1.137     raeburn  7554:     }
                   7555:     return $resulttext;
                   7556: }
                   7557: 
1.150     raeburn  7558: sub modify_loadbalancing {
                   7559:     my ($dom,%domconfig) = @_;
                   7560:     my $primary_id = &Apache::lonnet::domain($dom,'primary');
                   7561:     my $intdom = &Apache::lonnet::internet_dom($primary_id);
                   7562:     my ($othertitle,$usertypes,$types) =
                   7563:         &Apache::loncommon::sorted_inst_types($dom);
                   7564:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
                   7565:     my @sparestypes = ('primary','default');
                   7566:     my %typetitles = &sparestype_titles();
                   7567:     my $resulttext;
                   7568:     if (keys(%servers) > 1) {
                   7569:         my ($currbalancer,$currtargets,$currrules);
                   7570:         if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
                   7571:             $currbalancer = $domconfig{'loadbalancing'}{'lonhost'};
                   7572:             $currtargets = $domconfig{'loadbalancing'}{'targets'};
                   7573:             $currrules = $domconfig{'loadbalancing'}{'rules'};
                   7574:         } else {
                   7575:             ($currbalancer,$currtargets) = 
                   7576:                 &Apache::lonnet::get_lonbalancer_config(\%servers);
                   7577:         }
                   7578:         my ($saveloadbalancing,%defaultshash,%changes);
                   7579:         my ($alltypes,$othertypes,$titles) =
                   7580:             &loadbalancing_titles($dom,$intdom,$usertypes,$types);
                   7581:         my %ruletitles = &offloadtype_text();
                   7582:         my $balancer = $env{'form.loadbalancing_lonhost'};
                   7583:         if (!$servers{$balancer}) {
                   7584:             undef($balancer);
                   7585:         }
                   7586:         if ($currbalancer ne $balancer) {
                   7587:             $changes{'lonhost'} = 1;
                   7588:         }
                   7589:         $defaultshash{'loadbalancing'}{'lonhost'} = $balancer;
                   7590:         if ($balancer ne '') {
                   7591:             unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
                   7592:                 $saveloadbalancing = 1;
                   7593:             }
                   7594:             foreach my $sparetype (@sparestypes) {
                   7595:                 my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$sparetype);
1.151     raeburn  7596:                 my @offloadto;
1.150     raeburn  7597:                 foreach my $target (@targets) {
                   7598:                     if (($servers{$target}) && ($target ne $balancer)) {
                   7599:                         if ($sparetype eq 'default') {
                   7600:                             if (ref($defaultshash{'loadbalancing'}{'targets'}{'primary'}) eq 'ARRAY') {
                   7601:                                 next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{'targets'}{'primary'}}));
                   7602:                             }
                   7603:                         }
                   7604:                         unless(grep(/^\Q$target\E$/,@offloadto)) {
                   7605:                             push(@offloadto,$target);
                   7606:                         }
                   7607:                     }
                   7608:                     $defaultshash{'loadbalancing'}{'targets'}{$sparetype} = \@offloadto;
                   7609:                 }
                   7610:             }
                   7611:         } else {
                   7612:             foreach my $sparetype (@sparestypes) {
                   7613:                 $defaultshash{'loadbalancing'}{'targets'}{$sparetype} = [];
                   7614:             }
                   7615:         }
                   7616:         if (ref($currtargets) eq 'HASH') {
                   7617:             foreach my $sparetype (@sparestypes) {
                   7618:                 if (ref($currtargets->{$sparetype}) eq 'ARRAY') {
                   7619:                     my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets->{$sparetype},$defaultshash{'loadbalancing'}{'targets'}{$sparetype});
                   7620:                     if (@targetdiffs > 0) {
                   7621:                         $changes{'targets'} = 1;
                   7622:                     }
                   7623:                 } elsif (ref($defaultshash{'loadbalancing'}{'targets'}{$sparetype}) eq 'ARRAY') {
                   7624:                     if (@{$defaultshash{'loadbalancing'}{'targets'}{$sparetype}} > 0) {
                   7625:                         $changes{'targets'} = 1;
                   7626:                     }
                   7627:                 }
                   7628:             }
                   7629:         } else {
                   7630:             foreach my $sparetype (@sparestypes) {
                   7631:                 if (ref($defaultshash{'loadbalancing'}{'targets'}{$sparetype}) eq 'ARRAY') {
                   7632:                     if (@{$defaultshash{'loadbalancing'}{'targets'}{$sparetype}} > 0) {
                   7633:                         $changes{'targets'} = 1;  
                   7634:                     }
                   7635:                 }
                   7636:             }  
                   7637:         }
                   7638:         my $ishomedom;
                   7639:         if ($balancer ne '') {
                   7640:             if (&Apache::lonnet::host_domain($balancer) eq $dom) {
                   7641:                 $ishomedom = 1;
                   7642:             }
                   7643:         }
                   7644:         if (ref($alltypes) eq 'ARRAY') {
                   7645:             foreach my $type (@{$alltypes}) {
                   7646:                 my $rule;
                   7647:                 if ($balancer ne '') {
                   7648:                     unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) && 
                   7649:                          (!$ishomedom)) {
                   7650:                         $rule = $env{'form.loadbalancing_rules_'.$type};
                   7651:                     }
                   7652:                     if ($rule eq 'specific') {
                   7653:                         $rule = $env{'form.loadbalancing_singleserver_'.$type};
                   7654:                     }
                   7655:                 }
                   7656:                 $defaultshash{'loadbalancing'}{'rules'}{$type} = $rule;
                   7657:                 if (ref($currrules) eq 'HASH') {
                   7658:                     if ($rule ne $currrules->{$type}) {
                   7659:                         $changes{'rules'}{$type} = 1;
                   7660:                     }
                   7661:                 } elsif ($rule ne '') {
                   7662:                     $changes{'rules'}{$type} = 1;
                   7663:                 }
                   7664:             }
                   7665:         }
                   7666:         my $nochgmsg = &mt('No changes made to Load Balancer settings.');
                   7667:         if ((keys(%changes) > 0) || ($saveloadbalancing)) {
                   7668:             my $putresult = &Apache::lonnet::put_dom('configuration',
                   7669:                                                      \%defaultshash,$dom);
                   7670:             if ($putresult eq 'ok') {
                   7671:                 if (keys(%changes) > 0) {
                   7672:                     if ($changes{'lonhost'}) {
                   7673:                         if ($currbalancer ne '') {
                   7674:                             &Apache::lonnet::remote_devalidate_cache($currbalancer,'loadbalancing',$dom);
                   7675:                         }
                   7676:                         if ($balancer eq '') {
                   7677:                             $resulttext .= '<li>'.&mt('Load Balancing with dedicated server discontinued').'</li>'; 
                   7678:                         } else {
                   7679:                             &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
                   7680:                             $resulttext .= '<li>'.&mt('Dedicated Load Balancer server set to [_1]',$balancer);
                   7681:                         }
                   7682:                     } else {
                   7683:                         &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
                   7684:                     }
                   7685:                     if (($changes{'targets'}) && ($balancer ne '')) {
                   7686:                         my %offloadstr;
                   7687:                         foreach my $sparetype (@sparestypes) {
                   7688:                             if (ref($defaultshash{'loadbalancing'}{'targets'}{$sparetype}) eq 'ARRAY') {
                   7689:                                 if (@{$defaultshash{'loadbalancing'}{'targets'}{$sparetype}} > 0) {
                   7690:                                     $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{'targets'}{$sparetype}});
                   7691:                                 }
                   7692:                             }
                   7693:                         }
                   7694:                         if (keys(%offloadstr) == 0) {
                   7695:                             $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
                   7696:                         } else {
                   7697:                             my $showoffload;
                   7698:                             foreach my $sparetype (@sparestypes) {
                   7699:                                 $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>:&nbsp;';
                   7700:                                 if (defined($offloadstr{$sparetype})) {
                   7701:                                     $showoffload .= $offloadstr{$sparetype};
                   7702:                                 } else {
                   7703:                                     $showoffload .= &mt('None');
                   7704:                                 }
                   7705:                                 $showoffload .= ('&nbsp;'x3);
                   7706:                             }
                   7707:                             $resulttext .= '<li>'.&mt('By default, Load Balancer server set to offload to: [_1]',$showoffload).'</li>';
                   7708:                         }
                   7709:                     }
                   7710:                     if ((ref($changes{'rules'}) eq 'HASH') && ($balancer ne '')) {
                   7711:                         if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
                   7712:                             foreach my $type (@{$alltypes}) {
                   7713:                                 if ($changes{'rules'}{$type}) {
                   7714:                                     my $rule = $defaultshash{'loadbalancing'}{'rules'}{$type};
                   7715:                                     my $balancetext;
                   7716:                                     if ($rule eq '') {
                   7717:                                         $balancetext =  $ruletitles{'default'};
                   7718:                                     } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer')) {
                   7719:                                         $balancetext =  $ruletitles{$rule};
                   7720:                                     } else {
                   7721:                                         $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{'rules'}{$type});
                   7722:                                     }
                   7723:                                     $resulttext .= '<li>'.&mt('Load Balancing for [_1] set to: [_2]',$titles->{$type},$balancetext).'</li>';     
                   7724:                                 }
                   7725:                             }
                   7726:                         }
                   7727:                     }
                   7728:                     if ($resulttext ne '') {
                   7729:                         $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
                   7730:                     } else {
                   7731:                         $resulttext = $nochgmsg;
                   7732:                     }
                   7733:                 } else {
                   7734:                     $resulttext = $nochgmsg;
                   7735:                     if ($balancer ne '') {
                   7736:                         &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
                   7737:                     }
                   7738:                 }
                   7739:             } else {
                   7740:                 $resulttext = '<span class="LC_error">'.
                   7741:                               &mt('An error occurred: [_1]',$putresult).'</span>';
                   7742:             }
                   7743:         } else {
                   7744:             $resulttext = $nochgmsg;
                   7745:         }
                   7746:     } else {
                   7747:         $resulttext =  &mt('Load Balancing unavailable as this domain only has one server.');
                   7748:     }
                   7749:     return $resulttext;
                   7750: }
                   7751: 
1.48      raeburn  7752: sub recurse_check {
                   7753:     my ($chkcats,$categories,$depth,$name) = @_;
                   7754:     if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
                   7755:         my $chg = 0;
                   7756:         for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
                   7757:             my $category = $chkcats->[$depth]{$name}[$j];
                   7758:             my $item;
                   7759:             if ($category eq '') {
                   7760:                 $chg ++;
                   7761:             } else {
                   7762:                 my $deeper = $depth + 1;
                   7763:                 $item = &escape($category).':'.&escape($name).':'.$depth;
                   7764:                 if ($chg) {
                   7765:                     $categories->{$item} -= $chg;
                   7766:                 }
                   7767:                 &recurse_check($chkcats,$categories,$deeper,$category);
                   7768:                 $deeper --;
                   7769:             }
                   7770:         }
                   7771:     }
                   7772:     return;
                   7773: }
                   7774: 
                   7775: sub recurse_cat_deletes {
                   7776:     my ($item,$coursecategories,$deletions) = @_;
                   7777:     my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
                   7778:     my $subdepth = $depth + 1;
                   7779:     if (ref($coursecategories) eq 'HASH') {
                   7780:         foreach my $subitem (keys(%{$coursecategories})) {
                   7781:             my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
                   7782:             if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
                   7783:                 delete($coursecategories->{$subitem});
                   7784:                 $deletions->{$subitem} = 1;
                   7785:                 &recurse_cat_deletes($subitem,$coursecategories,$deletions);
                   7786:             }  
                   7787:         }
                   7788:     }
                   7789:     return;
                   7790: }
                   7791: 
1.125     raeburn  7792: sub get_active_dcs {
                   7793:     my ($dom) = @_;
                   7794:     my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc']);
                   7795:     my %domcoords;
                   7796:     my $numdcs = 0;
                   7797:     my $now = time;
                   7798:     foreach my $server (keys(%dompersonnel)) {
                   7799:         foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
                   7800:             my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
                   7801:             my ($end,$start) = split(':',$dompersonnel{$server}{$user});
                   7802:             if (($end eq '') || ($end == 0) || ($end > $now)) {
                   7803:                 if ($start <= $now) {
                   7804:                     $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
                   7805:                 }
                   7806:             }
                   7807:         }
                   7808:     }
                   7809:     return %domcoords;
                   7810: }
                   7811: 
                   7812: sub active_dc_picker {
                   7813:     my ($dom,$curr_dc) = @_;
                   7814:     my %domcoords = &get_active_dcs($dom); 
                   7815:     my @dcs = sort(keys(%domcoords));
                   7816:     my $numdcs = scalar(@dcs); 
                   7817:     my $datatable;
                   7818:     my $numinrow = 2;
                   7819:     if ($numdcs > 1) {
                   7820:         $datatable = '<table>';
                   7821:         for (my $i=0; $i<@dcs; $i++) {
                   7822:             my $rem = $i%($numinrow);
                   7823:             if ($rem == 0) {
                   7824:                 if ($i > 0) {
                   7825:                     $datatable .= '</tr>';
                   7826:                 }
                   7827:                 $datatable .= '<tr>';
                   7828:             }
                   7829:             my $check = ' ';
                   7830:             if ($curr_dc eq '') {
                   7831:                 if (!$i) { 
                   7832:                     $check = ' checked="checked" ';
                   7833:                 }
                   7834:             } elsif ($dcs[$i] eq $curr_dc) {
                   7835:                 $check = ' checked="checked" ';
                   7836:             }
                   7837:             if ($i == @dcs - 1) {
                   7838:                 my $colsleft = $numinrow - $rem;
                   7839:                 if ($colsleft > 1) {
                   7840:                     $datatable .= '<td colspan="'.$colsleft.'">';
                   7841:                 } else {
                   7842:                     $datatable .= '<td>';
                   7843:                 }
                   7844:             } else {
                   7845:                 $datatable .= '<td>';
                   7846:             }
                   7847:             my ($dcname,$dcdom) = split(':',$dcs[$i]);
                   7848:             $datatable .= '<span class="LC_nobreak"><label>'.
                   7849:                           '<input type="radio" name="autocreate_xmldc"'.
                   7850:                           ' value="'.$dcs[$i].'"'.$check.'/>'.
                   7851:                           &Apache::loncommon::plainname($dcname,$dcdom).
                   7852:                           '</label></span></td>';
                   7853:         }
                   7854:         $datatable .= '</tr></table>';
                   7855:     } elsif (@dcs) {
                   7856:         $datatable .= '<input type="hidden" name="autocreate_dc" value="'.
                   7857:                       $dcs[0].'" />';
                   7858:     }
                   7859:     return ($numdcs,$datatable);
                   7860: }
                   7861: 
1.137     raeburn  7862: sub usersession_titles {
                   7863:     return &Apache::lonlocal::texthash(
                   7864:                hosted => 'Hosting of sessions for users from other domains on servers in this domain',
                   7865: 
                   7866:                remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145     raeburn  7867:                spares => 'Servers offloaded to, when busy',
1.137     raeburn  7868:                version => 'LON-CAPA version requirement',
1.138     raeburn  7869:                excludedomain => 'Allow all, but exclude specific domains',
                   7870:                includedomain => 'Deny all, but include specific domains',
1.145     raeburn  7871:                primary => 'Primary (checked first)',
                   7872:                default => 'Default', 
1.137     raeburn  7873:            );
                   7874: }
                   7875: 
1.152     raeburn  7876: sub id_for_thisdom {
                   7877:     my (%servers) = @_;
                   7878:     my %altids;
                   7879:     foreach my $server (keys(%servers)) {
                   7880:         my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
                   7881:         if ($serverhome ne $server) {
                   7882:             $altids{$serverhome} = $server;
                   7883:         }
                   7884:     }
                   7885:     return %altids;
                   7886: }
                   7887: 
1.150     raeburn  7888: sub count_servers {
                   7889:     my ($currbalancer,%servers) = @_;
                   7890:     my (@spares,$numspares);
                   7891:     foreach my $lonhost (sort(keys(%servers))) {
                   7892:         next if ($currbalancer eq $lonhost);
                   7893:         push(@spares,$lonhost);
                   7894:     }
                   7895:     if ($currbalancer) {
                   7896:         $numspares = scalar(@spares);
                   7897:     } else {
                   7898:         $numspares = scalar(@spares) - 1;
                   7899:     }
                   7900:     return ($numspares,@spares);
                   7901: }
                   7902: 
                   7903: sub lonbalance_targets_js {
                   7904:     my ($dom,$types,$servers) = @_;
                   7905:     my $select = &mt('Select');
                   7906:     my ($alltargets,$allishome,$allinsttypes,@alltypes);
                   7907:     if (ref($servers) eq 'HASH') {
                   7908:         $alltargets = join("','",sort(keys(%{$servers})));
                   7909:         my @homedoms;
                   7910:         foreach my $server (sort(keys(%{$servers}))) {
                   7911:             if (&Apache::lonnet::host_domain($server) eq $dom) {
                   7912:                 push(@homedoms,'1');
                   7913:             } else {
                   7914:                 push(@homedoms,'0');
                   7915:             }
                   7916:         }
                   7917:         $allishome = join("','",@homedoms);
                   7918:     }
                   7919:     if (ref($types) eq 'ARRAY') {
                   7920:         if (@{$types} > 0) {
                   7921:             @alltypes = @{$types};
                   7922:         }
                   7923:     }
                   7924:     push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
                   7925:     $allinsttypes = join("','",@alltypes);
                   7926:     return <<"END";
                   7927: 
                   7928: <script type="text/javascript">
                   7929: // <![CDATA[
                   7930: 
                   7931: function toggleTargets() {
                   7932:     var balancer = document.display.loadbalancing_lonhost.options[document.display.loadbalancing_lonhost.selectedIndex].value;
                   7933:     if (balancer == '') {
                   7934:         hideSpares();
                   7935:     } else {
                   7936:         var homedoms = new Array('$allishome');
                   7937:         var ishomedom = homedoms[document.display.loadbalancing_lonhost.selectedIndex];
                   7938:         showSpares(balancer,ishomedom);
                   7939:     }
                   7940:     return;
                   7941: }
                   7942: 
                   7943: function showSpares(balancer,ishomedom) {
                   7944:     var alltargets = new Array('$alltargets');
                   7945:     var insttypes = new Array('$allinsttypes');
1.151     raeburn  7946:     var offloadtypes = new Array('primary','default');
                   7947: 
1.150     raeburn  7948:     document.getElementById('loadbalancing_targets').style.display='block';
                   7949:     document.getElementById('loadbalancing_disabled').style.display='none';
1.152     raeburn  7950:  
1.151     raeburn  7951:     for (var i=0; i<offloadtypes.length; i++) {
                   7952:         var count = 0;
                   7953:         for (var j=0; j<alltargets.length; j++) {
                   7954:             if (alltargets[j] != balancer) {
                   7955:                 document.getElementById('loadbalancing_target_'+offloadtypes[i]+'_'+count).value = alltargets[j];
                   7956:                 document.getElementById('loadbalancing_targettxt_'+offloadtypes[i]+'_'+count).style.textAlign='left';
                   7957:                 document.getElementById('loadbalancing_targettxt_'+offloadtypes[i]+'_'+count).style.textFace='normal';
                   7958:                 document.getElementById('loadbalancing_targettxt_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
                   7959:                 count ++;
                   7960:             }
1.150     raeburn  7961:         }
                   7962:     }
1.151     raeburn  7963:     for (var k=0; k<insttypes.length; k++) {
                   7964:         if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150     raeburn  7965:             if (ishomedom == 1) {
1.151     raeburn  7966:                 document.getElementById('balanceruletitle_'+insttypes[k]).style.display='block';
                   7967:                 document.getElementById('balancerule_'+insttypes[k]).style.display='block';
1.150     raeburn  7968:             } else {
1.151     raeburn  7969:                 document.getElementById('balanceruletitle_'+insttypes[k]).style.display='none';
                   7970:                 document.getElementById('balancerule_'+insttypes[k]).style.display='none';
1.150     raeburn  7971: 
                   7972:             }
                   7973:         } else {
1.151     raeburn  7974:             document.getElementById('balanceruletitle_'+insttypes[k]).style.display='block';
                   7975:             document.getElementById('balancerule_'+insttypes[k]).style.display='block';
1.150     raeburn  7976:         }
1.151     raeburn  7977:         if ((insttypes[k] != '_LC_external') && 
                   7978:             ((insttypes[k] != '_LC_internetdom') ||
                   7979:              ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
                   7980:             document.getElementById('loadbalancing_singleserver_'+insttypes[k]).options[0] = new Option("","",true,true);
                   7981:             for (var m=0; m<alltargets.length; m++) {
                   7982:                 var idx = m+1;
                   7983:                 if (alltargets[m] != balancer) {
                   7984:                     document.getElementById('loadbalancing_singleserver_'+insttypes[k]).options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150     raeburn  7985:                 }
                   7986:             }
                   7987:         }
                   7988:     }
                   7989:     return;
                   7990: }
                   7991: 
                   7992: function hideSpares() {
                   7993:     var alltargets = new Array('$alltargets');
                   7994:     var insttypes = new Array('$allinsttypes');
                   7995:     var offloadtypes = new Array('primary','default');
                   7996: 
                   7997:     document.getElementById('loadbalancing_targets').style.display='none';
                   7998:     document.getElementById('loadbalancing_disabled').style.display='block';
                   7999: 
                   8000:     var total = alltargets.length - 1;
                   8001:     for (var i=0; i<offloadtypes; i++) {
                   8002:         for (var j=0; j<total; j++) {
                   8003:            document.getElementById('loadbalancing_target_'+offloadtypes[i]+'_'+j).checked = false;
                   8004:            document.getElementById('loadbalancing_target_'+offloadtypes[i]+'_'+j).value = '';
                   8005:            document.getElementById('loadbalancing_targettxt_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151     raeburn  8006:         }
1.150     raeburn  8007:     }
                   8008:     for (var k=0; k<insttypes.length; k++) {
1.151     raeburn  8009:         document.getElementById('balanceruletitle_'+insttypes[k]).style.display='none';
                   8010:         document.getElementById('balancerule_'+insttypes[k]).style.display='none';
                   8011:         if (insttypes[k] != '_LC_external') {
                   8012:             document.getElementById('loadbalancing_singleserver_'+insttypes[k]).length = 0;
                   8013:             document.getElementById('loadbalancing_singleserver_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150     raeburn  8014:         }
                   8015:     }
                   8016:     return;
                   8017: }
                   8018: 
                   8019: function checkOffloads(item,type) {
                   8020:     var alltargets = new Array('$alltargets');
                   8021:     var offloadtypes = new Array('primary','default');
                   8022:     if (item.checked) {
                   8023:         var total = alltargets.length - 1;
                   8024:         var other;
                   8025:         if (type == offloadtypes[0]) {
1.151     raeburn  8026:             other = offloadtypes[1];
1.150     raeburn  8027:         } else {
1.151     raeburn  8028:             other = offloadtypes[0];
1.150     raeburn  8029:         }
                   8030:         for (var i=0; i<total; i++) {
                   8031:             var server = document.getElementById('loadbalancing_target_'+other+'_'+i).value;
                   8032:             if (server == item.value) {
                   8033:                 if (document.getElementById('loadbalancing_target_'+other+'_'+i).checked) {
                   8034:                     document.getElementById('loadbalancing_target_'+other+'_'+i).checked = false;
                   8035:                 }
                   8036:             }
                   8037:         }
                   8038:     }
                   8039:     return;
                   8040: }
                   8041: 
                   8042: function singleServerToggle(type) {
                   8043:     var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+type).selectedIndex;
                   8044:     if (offloadtoSelIdx == 0) {
                   8045:         document.getElementById('loadbalancing_rules_'+type+'_0').checked = true;
                   8046:         document.getElementById('loadbalancing_singleserver_'+type).options[0].text = '';
                   8047: 
                   8048:     } else {
                   8049:         document.getElementById('loadbalancing_rules_'+type+'_2').checked = true;
                   8050:         document.getElementById('loadbalancing_singleserver_'+type).options[0].text = '$select';
                   8051:     }
                   8052:     return;
                   8053: }
                   8054: 
                   8055: function balanceruleChange(formname,type) {
                   8056:     if (type == '_LC_external') {
                   8057:         return; 
                   8058:     }
                   8059:     var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+type);
                   8060:     for (var i=0; i<typesRules.length; i++) {
                   8061:         if (formname.elements[typesRules[i]].checked) {
                   8062:             if (formname.elements[typesRules[i]].value != 'specific') {
                   8063:                 document.getElementById('loadbalancing_singleserver_'+type).selectedIndex = 0;
                   8064:                 document.getElementById('loadbalancing_singleserver_'+type).options[0].text = '';
                   8065:             } else {
                   8066:                 document.getElementById('loadbalancing_singleserver_'+type).options[0].text = '$select';
                   8067:             }
                   8068:         }
                   8069:     }
                   8070:     return;
                   8071: }
                   8072: 
1.152     raeburn  8073: // ]]>
                   8074: </script>
                   8075: 
                   8076: END
                   8077: }
                   8078: 
                   8079: sub new_spares_js {
                   8080:     my @sparestypes = ('primary','default');
                   8081:     my $types = join("','",@sparestypes);
                   8082:     my $select = &mt('Select');
                   8083:     return <<"END";
                   8084: 
                   8085: <script type="text/javascript">
                   8086: // <![CDATA[
                   8087: 
                   8088: function updateNewSpares(formname,lonhost) {
                   8089:     var types = new Array('$types');
                   8090:     var include = new Array();
                   8091:     var exclude = new Array();
                   8092:     for (var i=0; i<types.length; i++) {
                   8093:         var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
                   8094:         for (var j=0; j<spareboxes.length; j++) {
                   8095:             if (formname.elements[spareboxes[j]].checked) {
                   8096:                 exclude.push(formname.elements[spareboxes[j]].value);
                   8097:             } else {
                   8098:                 include.push(formname.elements[spareboxes[j]].value);
                   8099:             }
                   8100:         }
                   8101:     }
                   8102:     for (var i=0; i<types.length; i++) {
                   8103:         var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
                   8104:         var selIdx = newSpare.selectedIndex;
                   8105:         var currnew = newSpare.options[selIdx].value;
                   8106:         var okSpares = new Array();
                   8107:         for (var j=0; j<newSpare.options.length; j++) {
                   8108:             var possible = newSpare.options[j].value;
                   8109:             if (possible != '') {
                   8110:                 if (exclude.indexOf(possible) == -1) {
                   8111:                     okSpares.push(possible);
                   8112:                 } else {
                   8113:                     if (currnew == possible) {
                   8114:                         selIdx = 0;
                   8115:                     }
                   8116:                 }
                   8117:             }
                   8118:         }
                   8119:         for (var k=0; k<include.length; k++) {
                   8120:             if (okSpares.indexOf(include[k]) == -1) {
                   8121:                 okSpares.push(include[k]);
                   8122:             }
                   8123:         }
                   8124:         okSpares.sort();
                   8125:         newSpare.options.length = 0;
                   8126:         if (selIdx == 0) {
                   8127:             newSpare.options[0] = new Option("$select","",true,true);
                   8128:         } else {
                   8129:             newSpare.options[0] = new Option("$select","",false,false);
                   8130:         }
                   8131:         for (var m=0; m<okSpares.length; m++) {
                   8132:             var idx = m+1;
                   8133:             var selThis = 0;
                   8134:             if (selIdx != 0) {
                   8135:                 if (okSpares[m] == currnew) {
                   8136:                     selThis = 1;
                   8137:                 }
                   8138:             }
                   8139:             if (selThis == 1) {
                   8140:                 newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
                   8141:             } else {
                   8142:                 newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
                   8143:             }
                   8144:         }
                   8145:     }
                   8146:     return;
                   8147: }
                   8148: 
                   8149: function checkNewSpares(lonhost,type) {
                   8150:     var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
                   8151:     var chosen =  newSpare.options[newSpare.selectedIndex].value;
                   8152:     if (chosen != '') { 
                   8153:         var othertype;
                   8154:         var othernewSpare;
                   8155:         if (type == 'primary') {
                   8156:             othernewSpare = document.getElementById('newspare_default_'+lonhost);
                   8157:         }
                   8158:         if (type == 'default') {
                   8159:             othernewSpare = document.getElementById('newspare_primary_'+lonhost);
                   8160:         }
                   8161:         if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
                   8162:             othernewSpare.selectedIndex = 0;
                   8163:         }
                   8164:     }
                   8165:     return;
                   8166: }
                   8167: 
                   8168: // ]]>
                   8169: </script>
                   8170: 
                   8171: END
                   8172: 
                   8173: }
                   8174: 
                   8175: sub common_domprefs_js {
                   8176:     return <<"END";
                   8177: 
                   8178: <script type="text/javascript">
                   8179: // <![CDATA[
                   8180: 
1.150     raeburn  8181: function getIndicesByName(formname,item) {
1.152     raeburn  8182:     var group = new Array();
1.150     raeburn  8183:     for (var i=0;i<formname.elements.length;i++) {
                   8184:         if (formname.elements[i].name == item) {
1.152     raeburn  8185:             group.push(formname.elements[i].id);
1.150     raeburn  8186:         }
                   8187:     }
1.152     raeburn  8188:     return group;
1.150     raeburn  8189: }
                   8190: 
                   8191: // ]]>
                   8192: </script>
                   8193: 
                   8194: END
1.152     raeburn  8195: 
1.150     raeburn  8196: }
                   8197: 
1.3       raeburn  8198: 1;

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