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

1.1       raeburn     1: # The LearningOnline Network with CAPA
                      2: # Handler to set domain-wide configuration settings
                      3: #
1.176   ! raeburn     4: # $Id: domainprefs.pm,v 1.175 2012/12/07 16:16:30 bisitz 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 
1.163     raeburn    89: number of rows displayed on the page, and $action is the context (quotas,  
                     90: requestcourses or requestauthor).
1.101     raeburn    91: 
                     92: The print_quotas routine was orginally created to display/store information
                     93: about default quota sizes for portfolio spaces for the different types of 
                     94: institutional affiliation in the domain (e.g., Faculty, Staff, Student etc.), 
                     95: but is now also used to manage availability of user tools: 
                     96: i.e., blogs, aboutme page, and portfolios, and the course request tool,
                     97: used by course owners to request creation of a course.
                     98: 
                     99: Outputs: 1
                    100: 
                    101: $datatable  - HTML containing form elements which allow settings to be changed. 
                    102: 
                    103: In the case of course requests, radio buttons are displayed for each institutional
                    104: affiliate type (and also default, and _LC_adv) for each of the course types 
                    105: (official, unofficial and community).  In each case the radio buttons allow the 
                    106: selection of one of four values:
                    107: 
1.104     raeburn   108: 0, approval, validate, autolimit=N (where N is blank, or a positive integer).
1.101     raeburn   109: which have the following effects:
                    110: 
                    111: 0
                    112: 
                    113: =over
                    114: 
                    115: - course requests are not allowed for this course types/affiliation
                    116: 
                    117: =back
                    118: 
1.104     raeburn   119: approval 
1.101     raeburn   120: 
                    121: =over 
                    122: 
                    123: - course requests must be approved by a Doman Coordinator in the 
                    124: course's domain
                    125: 
                    126: =back
                    127: 
                    128: validate 
                    129: 
                    130: =over
                    131: 
                    132: - an institutional validation (e.g., check requestor is instructor
                    133: of record) needs to be passed before the course will be created.  The required
                    134: validation is in localenroll.pm on the primary library server for the course 
                    135: domain.
                    136: 
                    137: =back
                    138: 
                    139: autolimit 
                    140: 
                    141: =over
                    142:  
1.143     raeburn   143: - course requests will be processed automatically up to a limit of
1.101     raeburn   144: N requests for the course type for the particular requestor.
                    145: If N is undefined, there is no limit to the number of course requests
                    146: which a course owner may submit and have processed automatically. 
                    147: 
                    148: =back
                    149: 
                    150: =item modify_quotas() 
                    151: 
                    152: =back
                    153: 
                    154: =cut
                    155: 
1.1       raeburn   156: package Apache::domainprefs;
                    157: 
                    158: use strict;
                    159: use Apache::Constants qw(:common :http);
                    160: use Apache::lonnet;
                    161: use Apache::loncommon();
                    162: use Apache::lonhtmlcommon();
                    163: use Apache::lonlocal;
1.43      raeburn   164: use Apache::lonmsg();
1.91      raeburn   165: use Apache::lonconfigsettings;
1.69      raeburn   166: use LONCAPA qw(:DEFAULT :match);
1.6       raeburn   167: use LONCAPA::Enrollment;
1.81      raeburn   168: use LONCAPA::lonauthcgi();
1.9       raeburn   169: use File::Copy;
1.43      raeburn   170: use Locale::Language;
1.62      raeburn   171: use DateTime::TimeZone;
1.68      raeburn   172: use DateTime::Locale;
1.1       raeburn   173: 
1.155     raeburn   174: my $registered_cleanup;
                    175: my $modified_urls;
                    176: 
1.1       raeburn   177: sub handler {
                    178:     my $r=shift;
                    179:     if ($r->header_only) {
                    180:         &Apache::loncommon::content_type($r,'text/html');
                    181:         $r->send_http_header;
                    182:         return OK;
                    183:     }
                    184: 
1.91      raeburn   185:     my $context = 'domain';
1.1       raeburn   186:     my $dom = $env{'request.role.domain'};
1.5       albertel  187:     my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1       raeburn   188:     if (&Apache::lonnet::allowed('mau',$dom)) {
                    189:         &Apache::loncommon::content_type($r,'text/html');
                    190:         $r->send_http_header;
                    191:     } else {
                    192:         $env{'user.error.msg'}=
                    193:         "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
                    194:         return HTTP_NOT_ACCEPTABLE;
                    195:     }
1.155     raeburn   196: 
                    197:     $registered_cleanup=0;
                    198:     @{$modified_urls}=();
                    199: 
1.1       raeburn   200:     &Apache::lonhtmlcommon::clear_breadcrumbs();
                    201:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.58      raeburn   202:                                             ['phase','actions']);
1.30      raeburn   203:     my $phase = 'pickactions';
1.3       raeburn   204:     if ( exists($env{'form.phase'}) ) {
                    205:         $phase = $env{'form.phase'};
                    206:     }
1.150     raeburn   207:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.3       raeburn   208:     my %domconfig =
1.6       raeburn   209:       &Apache::lonnet::get_dom('configuration',['login','rolecolors',
1.125     raeburn   210:                 'quotas','autoenroll','autoupdate','autocreate',
                    211:                 'directorysrch','usercreation','usermodification',
                    212:                 'contacts','defaults','scantron','coursecategories',
                    213:                 'serverstatuses','requestcourses','helpsettings',
1.163     raeburn   214:                 'coursedefaults','usersessions','loadbalancing',
                    215:                 'requestauthor'],$dom);
1.43      raeburn   216:     my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll',
1.125     raeburn   217:                        'autoupdate','autocreate','directorysrch','contacts',
1.48      raeburn   218:                        'usercreation','usermodification','scantron',
1.163     raeburn   219:                        'requestcourses','requestauthor','coursecategories',
                    220:                        'serverstatuses','helpsettings',
1.137     raeburn   221:                        'coursedefaults','usersessions');
1.171     raeburn   222:     my %existing;
                    223:     if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
                    224:         %existing = %{$domconfig{'loadbalancing'}};
                    225:     }
                    226:     if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.150     raeburn   227:         push(@prefs_order,'loadbalancing');
                    228:     }
1.30      raeburn   229:     my %prefs = (
                    230:         'rolecolors' =>
                    231:                    { text => 'Default color schemes',
1.67      raeburn   232:                      help => 'Domain_Configuration_Color_Schemes',
1.30      raeburn   233:                      header => [{col1 => 'Student Settings',
                    234:                                  col2 => '',},
                    235:                                 {col1 => 'Coordinator Settings',
                    236:                                  col2 => '',},
                    237:                                 {col1 => 'Author Settings',
                    238:                                  col2 => '',},
                    239:                                 {col1 => 'Administrator Settings',
                    240:                                  col2 => '',}],
                    241:                     },
1.110     raeburn   242:         'login' =>
1.30      raeburn   243:                     { text => 'Log-in page options',
1.67      raeburn   244:                       help => 'Domain_Configuration_Login_Page',
1.168     raeburn   245:                       header => [{col1 => 'Log-in Page Items',
                    246:                                   col2 => '',},
                    247:                                  {col1 => 'Log-in Help',
                    248:                                   col2 => 'Value'}],
1.30      raeburn   249:                     },
1.43      raeburn   250:         'defaults' => 
1.141     raeburn   251:                     { text => 'Default authentication/language/timezone/portal',
1.67      raeburn   252:                       help => 'Domain_Configuration_LangTZAuth',
1.43      raeburn   253:                       header => [{col1 => 'Setting',
                    254:                                   col2 => 'Value'}],
                    255:                     },
1.30      raeburn   256:         'quotas' => 
1.162     raeburn   257:                     { text => 'Blogs, personal web pages, webDAV, portfolios',
1.67      raeburn   258:                       help => 'Domain_Configuration_Quotas',
1.77      raeburn   259:                       header => [{col1 => 'User affiliation',
1.72      raeburn   260:                                   col2 => 'Available tools',
                    261:                                   col3 => 'Portfolio quota',}],
1.30      raeburn   262:                     },
                    263:         'autoenroll' =>
                    264:                    { text => 'Auto-enrollment settings',
1.67      raeburn   265:                      help => 'Domain_Configuration_Auto_Enrollment',
1.30      raeburn   266:                      header => [{col1 => 'Configuration setting',
                    267:                                  col2 => 'Value(s)'}],
                    268:                    },
                    269:         'autoupdate' => 
                    270:                    { text => 'Auto-update settings',
1.67      raeburn   271:                      help => 'Domain_Configuration_Auto_Updates',
1.30      raeburn   272:                      header => [{col1 => 'Setting',
                    273:                                  col2 => 'Value',},
1.131     raeburn   274:                                 {col1 => 'Setting',
                    275:                                  col2 => 'Affiliation'},
1.43      raeburn   276:                                 {col1 => 'User population',
1.131     raeburn   277:                                  col2 => 'Updateable user data'}],
1.30      raeburn   278:                   },
1.125     raeburn   279:         'autocreate' => 
                    280:                   { text => 'Auto-course creation settings',
                    281:                      help => 'Domain_Configuration_Auto_Creation',
                    282:                      header => [{col1 => 'Configuration Setting',
                    283:                                  col2 => 'Value',}],
                    284:                   },
1.30      raeburn   285:         'directorysrch' => 
                    286:                   { text => 'Institutional directory searches',
1.67      raeburn   287:                     help => 'Domain_Configuration_InstDirectory_Search',
1.30      raeburn   288:                     header => [{col1 => 'Setting',
                    289:                                 col2 => 'Value',}],
                    290:                   },
                    291:         'contacts' =>
                    292:                   { text => 'Contact Information',
1.67      raeburn   293:                     help => 'Domain_Configuration_Contact_Info',
1.30      raeburn   294:                     header => [{col1 => 'Setting',
                    295:                                 col2 => 'Value',}],
                    296:                   },
                    297: 
                    298:         'usercreation' => 
                    299:                   { text => 'User creation',
1.67      raeburn   300:                     help => 'Domain_Configuration_User_Creation',
1.43      raeburn   301:                     header => [{col1 => 'Format rule type',
                    302:                                 col2 => 'Format rules in force'},
1.34      raeburn   303:                                {col1 => 'User account creation',
                    304:                                 col2 => 'Usernames which may be created',},
1.30      raeburn   305:                                {col1 => 'Context',
1.43      raeburn   306:                                 col2 => 'Assignable authentication types'}],
1.30      raeburn   307:                   },
1.69      raeburn   308:         'usermodification' =>
1.33      raeburn   309:                   { text => 'User modification',
1.67      raeburn   310:                     help => 'Domain_Configuration_User_Modification',
1.33      raeburn   311:                     header => [{col1 => 'Target user has role',
                    312:                                 col2 => 'User information updateable in author context'},
                    313:                                {col1 => 'Target user has role',
1.63      raeburn   314:                                 col2 => 'User information updateable in course context'},
                    315:                                {col1 => "Status of user",
                    316:                                 col2 => 'Information settable when self-creating account (if directory data blank)'}],
1.33      raeburn   317:                   },
1.69      raeburn   318:         'scantron' =>
1.95      www       319:                   { text => 'Bubblesheet format file',
1.67      raeburn   320:                     help => 'Domain_Configuration_Scantron_Format',
1.46      raeburn   321:                     header => [ {col1 => 'Item',
                    322:                                  col2 => '',
                    323:                               }],
                    324:                   },
1.86      raeburn   325:         'requestcourses' => 
                    326:                  {text => 'Request creation of courses',
                    327:                   help => 'Domain_Configuration_Request_Courses',
                    328:                   header => [{col1 => 'User affiliation',
1.102     raeburn   329:                               col2 => 'Availability/Processing of requests',},
                    330:                              {col1 => 'Setting',
                    331:                               col2 => 'Value'}],
1.86      raeburn   332:                  },
1.163     raeburn   333:         'requestauthor' =>
                    334:                  {text => 'Request authoring space',
                    335:                   help => 'Domain_Configuration_Request_Author',
                    336:                   header => [{col1 => 'User affiliation',
                    337:                               col2 => 'Availability/Processing of requests',},
                    338:                              {col1 => 'Setting',
                    339:                               col2 => 'Value'}],
                    340:                  },
1.69      raeburn   341:         'coursecategories' =>
1.120     raeburn   342:                   { text => 'Cataloging of courses/communities',
1.67      raeburn   343:                     help => 'Domain_Configuration_Cataloging_Courses',
1.69      raeburn   344:                     header => [{col1 => 'Category settings',
1.57      raeburn   345:                                 col2 => '',},
                    346:                                {col1 => 'Categories',
                    347:                                 col2 => '',
                    348:                                }],
1.69      raeburn   349:                   },
                    350:         'serverstatuses' =>
1.77      raeburn   351:                  {text   => 'Access to server status pages',
1.69      raeburn   352:                   help   => 'Domain_Configuration_Server_Status',
                    353:                   header => [{col1 => 'Status Page',
                    354:                               col2 => 'Other named users',
                    355:                               col3 => 'Specific IPs',
                    356:                             }],
                    357:                  },
1.118     jms       358:         'helpsettings' =>
                    359:                  {text   => 'Help page settings',
                    360:                   help   => 'Domain_Configuration_Help_Settings',
1.166     raeburn   361:                   header => [{col1 => 'Help Settings (logged-in users)',
                    362:                               col2 => 'Value'}],
1.118     jms       363:                  },
1.121     raeburn   364:         'coursedefaults' => 
                    365:                  {text => 'Course/Community defaults',
                    366:                   help => 'Domain_Configuration_Course_Defaults',
1.139     raeburn   367:                   header => [{col1 => 'Defaults which can be overridden in each course by a CC',
                    368:                               col2 => 'Value',},
                    369:                              {col1 => 'Defaults which can be overridden for each course by a DC',
                    370:                               col2 => 'Value',},],
1.121     raeburn   371:                  },
1.120     raeburn   372:         'privacy' => 
                    373:                  {text   => 'User Privacy',
                    374:                   help   => 'Domain_Configuration_User_Privacy',
                    375:                   header => [{col1 => 'Setting',
                    376:                               col2 => 'Value',}],
                    377:                  },
1.141     raeburn   378:         'usersessions' =>
1.145     raeburn   379:                  {text  => 'User session hosting/offloading',
1.137     raeburn   380:                   help  => 'Domain_Configuration_User_Sessions',
1.145     raeburn   381:                   header => [{col1 => 'Domain server',
                    382:                               col2 => 'Servers to offload sessions to when busy'},
                    383:                              {col1 => 'Hosting of users from other domains',
1.137     raeburn   384:                               col2 => 'Rules'},
                    385:                              {col1 => "Hosting domain's own users elsewhere",
                    386:                               col2 => 'Rules'}],
                    387:                  },
1.150     raeburn   388:          'loadbalancing' =>
                    389:                  {text  => 'Dedicated Load Balancer',
                    390:                   help  => 'Domain_Configuration_Load_Balancing',
1.171     raeburn   391:                   header => [{col1 => 'Balancers',
1.150     raeburn   392:                               col2 => 'Default destinations',
                    393:                               col3 => 'User affliation',
                    394:                               col4 => 'Overrides'},
                    395:                             ],
                    396:                  },
1.3       raeburn   397:     );
1.110     raeburn   398:     if (keys(%servers) > 1) {
                    399:         $prefs{'login'}  = { text   => 'Log-in page options',
                    400:                              help   => 'Domain_Configuration_Login_Page',
                    401:                             header => [{col1 => 'Log-in Service',
                    402:                                         col2 => 'Server Setting',},
                    403:                                        {col1 => 'Log-in Page Items',
1.168     raeburn   404:                                         col2 => ''},
                    405:                                        {col1 => 'Log-in Help',
                    406:                                         col2 => 'Value'}],
1.110     raeburn   407:                            };
                    408:     }
1.174     foxr      409: 
                    410: 
                    411: 
1.6       raeburn   412:     my @roles = ('student','coordinator','author','admin');
1.30      raeburn   413:     my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3       raeburn   414:     &Apache::lonhtmlcommon::add_breadcrumb
1.30      raeburn   415:     ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133     raeburn   416:       text=>"Settings to display/modify"});
1.9       raeburn   417:     my $confname = $dom.'-domainconfig';
1.174     foxr      418: 
1.3       raeburn   419:     if ($phase eq 'process') {
1.91      raeburn   420:         &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,\@roles);
1.30      raeburn   421:     } elsif ($phase eq 'display') {
1.165     raeburn   422:         my $js = &recaptcha_js();
1.171     raeburn   423:         if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152     raeburn   424:             my ($othertitle,$usertypes,$types) =
                    425:                 &Apache::loncommon::sorted_inst_types($dom);
1.171     raeburn   426:             $js .= &lonbalance_targets_js($dom,$types,\%servers,
                    427:                                           $domconfig{'loadbalancing'}).
1.170     raeburn   428:                    &new_spares_js().
                    429:                    &common_domprefs_js().
                    430:                    &Apache::loncommon::javascript_array_indexof();
1.152     raeburn   431:         }
1.150     raeburn   432:         &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1       raeburn   433:     } else {
1.21      raeburn   434:         if (keys(%domconfig) == 0) {
                    435:             my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29      raeburn   436:             my @ids=&Apache::lonnet::current_machine_ids();
                    437:             if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21      raeburn   438:                 my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41      raeburn   439:                 my @loginimages = ('img','logo','domlogo','login');
1.21      raeburn   440:                 my $custom_img_count = 0;
                    441:                 foreach my $img (@loginimages) {
                    442:                     if ($designhash{$dom.'.login.'.$img} ne '') {
                    443:                         $custom_img_count ++;
                    444:                     }
                    445:                 }
                    446:                 foreach my $role (@roles) {
                    447:                     if ($designhash{$dom.'.'.$role.'.img'} ne '') {
                    448:                         $custom_img_count ++;
                    449:                     }
                    450:                 }
                    451:                 if ($custom_img_count > 0) {
1.94      raeburn   452:                     &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21      raeburn   453:                     my $switch_server = &check_switchserver($dom,$confname);
1.29      raeburn   454:                     $r->print(
                    455:     &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
                    456:     &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
                    457:     &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 />'.
                    458:     &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
                    459:                     if ($switch_server) {
1.30      raeburn   460:                         $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29      raeburn   461:                     }
1.91      raeburn   462:                     $r->print(&Apache::loncommon::end_page());
1.21      raeburn   463:                     return OK;
                    464:                 }
                    465:             }
                    466:         }
1.174     foxr      467: 
1.91      raeburn   468:         &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3       raeburn   469:     }
                    470:     return OK;
                    471: }
                    472: 
                    473: sub process_changes {
1.92      raeburn   474:     my ($r,$dom,$confname,$action,$roles,$values) = @_;
                    475:     my %domconfig;
                    476:     if (ref($values) eq 'HASH') {
                    477:         %domconfig = %{$values};
                    478:     }
1.3       raeburn   479:     my $output;
                    480:     if ($action eq 'login') {
1.9       raeburn   481:         $output = &modify_login($r,$dom,$confname,%domconfig);
1.6       raeburn   482:     } elsif ($action eq 'rolecolors') {
1.9       raeburn   483:         $output = &modify_rolecolors($r,$dom,$confname,$roles,
                    484:                                      %domconfig);
1.3       raeburn   485:     } elsif ($action eq 'quotas') {
1.86      raeburn   486:         $output = &modify_quotas($dom,$action,%domconfig);
1.3       raeburn   487:     } elsif ($action eq 'autoenroll') {
                    488:         $output = &modify_autoenroll($dom,%domconfig);
                    489:     } elsif ($action eq 'autoupdate') {
                    490:         $output = &modify_autoupdate($dom,%domconfig);
1.125     raeburn   491:     } elsif ($action eq 'autocreate') {
                    492:         $output = &modify_autocreate($dom,%domconfig);
1.23      raeburn   493:     } elsif ($action eq 'directorysrch') {
                    494:         $output = &modify_directorysrch($dom,%domconfig);
1.27      raeburn   495:     } elsif ($action eq 'usercreation') {
1.28      raeburn   496:         $output = &modify_usercreation($dom,%domconfig);
1.33      raeburn   497:     } elsif ($action eq 'usermodification') {
                    498:         $output = &modify_usermodification($dom,%domconfig);
1.28      raeburn   499:     } elsif ($action eq 'contacts') {
                    500:         $output = &modify_contacts($dom,%domconfig);
1.43      raeburn   501:     } elsif ($action eq 'defaults') {
                    502:         $output = &modify_defaults($dom,$r);
1.46      raeburn   503:     } elsif ($action eq 'scantron') {
1.48      raeburn   504:         $output = &modify_scantron($r,$dom,$confname,%domconfig);
                    505:     } elsif ($action eq 'coursecategories') {
                    506:         $output = &modify_coursecategories($dom,%domconfig);
1.69      raeburn   507:     } elsif ($action eq 'serverstatuses') {
                    508:         $output = &modify_serverstatuses($dom,%domconfig);
1.86      raeburn   509:     } elsif ($action eq 'requestcourses') {
                    510:         $output = &modify_quotas($dom,$action,%domconfig);
1.163     raeburn   511:     } elsif ($action eq 'requestauthor') {
                    512:         $output = &modify_quotas($dom,$action,%domconfig);
1.118     jms       513:     } elsif ($action eq 'helpsettings') {
1.122     jms       514:         $output = &modify_helpsettings($r,$dom,$confname,%domconfig);
1.121     raeburn   515:     } elsif ($action eq 'coursedefaults') {
                    516:         $output = &modify_coursedefaults($dom,%domconfig);
1.137     raeburn   517:     } elsif ($action eq 'usersessions') {
                    518:         $output = &modify_usersessions($dom,%domconfig);
1.150     raeburn   519:     } elsif ($action eq 'loadbalancing') {
                    520:         $output = &modify_loadbalancing($dom,%domconfig);
1.3       raeburn   521:     }
                    522:     return $output;
                    523: }
                    524: 
                    525: sub print_config_box {
1.9       raeburn   526:     my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30      raeburn   527:     my $rowtotal = 0;
1.49      raeburn   528:     my $output;
1.174     foxr      529: 
1.49      raeburn   530:     if ($action eq 'coursecategories') {
                    531:         $output = &coursecategories_javascript($settings);
1.91      raeburn   532:     }
1.49      raeburn   533:     $output .= 
1.30      raeburn   534:          '<table class="LC_nested_outer">
1.3       raeburn   535:           <tr>
1.66      raeburn   536:            <th align="left" valign="middle"><span class="LC_nobreak">'.
                    537:            &mt($item->{text}).'&nbsp;'.
                    538:            &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
                    539:           '</tr>';
1.30      raeburn   540:     $rowtotal ++;
1.110     raeburn   541:     my $numheaders = 1;
                    542:     if (ref($item->{'header'}) eq 'ARRAY') {
                    543:         $numheaders = scalar(@{$item->{'header'}});
                    544:     }
                    545:     if ($numheaders > 1) {
1.64      raeburn   546:         my $colspan = '';
1.145     raeburn   547:         my $rightcolspan = '';
1.168     raeburn   548:         if (($action eq 'rolecolors') || ($action eq 'coursecategories') || 
                    549:             (($action eq 'login') && ($numheaders < 3))) {
1.64      raeburn   550:             $colspan = ' colspan="2"';
                    551:         }
1.145     raeburn   552:         if ($action eq 'usersessions') {
                    553:             $rightcolspan = ' colspan="3"'; 
                    554:         }
1.30      raeburn   555:         $output .= '
1.3       raeburn   556:           <tr>
                    557:            <td>
                    558:             <table class="LC_nested">
                    559:              <tr class="LC_info_row">
1.59      bisitz    560:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145     raeburn   561:               <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30      raeburn   562:              </tr>';
1.69      raeburn   563:         $rowtotal ++;
1.6       raeburn   564:         if ($action eq 'autoupdate') {
1.30      raeburn   565:             $output .= &print_autoupdate('top',$dom,$settings,\$rowtotal);
1.28      raeburn   566:         } elsif ($action eq 'usercreation') {
1.33      raeburn   567:             $output .= &print_usercreation('top',$dom,$settings,\$rowtotal);
                    568:         } elsif ($action eq 'usermodification') {
                    569:             $output .= &print_usermodification('top',$dom,$settings,\$rowtotal);
1.57      raeburn   570:         } elsif ($action eq 'coursecategories') {
                    571:             $output .= &print_coursecategories('top',$dom,$item,$settings,\$rowtotal);
1.110     raeburn   572:         } elsif ($action eq 'login') {
1.168     raeburn   573:             if ($numheaders == 3) {
                    574:                 $colspan = ' colspan="2"';
                    575:                 $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
                    576:             } else {
                    577:                 $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
                    578:             }
1.102     raeburn   579:         } elsif ($action eq 'requestcourses') {
                    580:             $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.163     raeburn   581:         } elsif ($action eq 'requestauthor') {
                    582:             $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.137     raeburn   583:         } elsif ($action eq 'usersessions') {
                    584:             $output .= &print_usersessions('top',$dom,$settings,\$rowtotal); 
1.122     jms       585:         } elsif ($action eq 'rolecolors') {
1.30      raeburn   586:             $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.139     raeburn   587:         } elsif ($action eq 'coursedefaults') {
                    588:             $output .= &print_coursedefaults('top',$dom,$settings,\$rowtotal);
1.6       raeburn   589:         }
1.30      raeburn   590:         $output .= '
1.6       raeburn   591:            </table>
                    592:           </td>
                    593:          </tr>
                    594:          <tr>
                    595:            <td>
                    596:             <table class="LC_nested">
                    597:              <tr class="LC_info_row">
1.59      bisitz    598:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>';
1.57      raeburn   599:         $output .= '
1.59      bisitz    600:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30      raeburn   601:              </tr>';
                    602:             $rowtotal ++;
1.6       raeburn   603:         if ($action eq 'autoupdate') {
1.131     raeburn   604:             $output .= &print_autoupdate('middle',$dom,$settings,\$rowtotal).'
                    605:            </table>
                    606:           </td>
                    607:          </tr>
                    608:          <tr>
                    609:            <td>
                    610:             <table class="LC_nested">
                    611:              <tr class="LC_info_row">
                    612:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
                    613:               <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>      </tr>'.
                    614:             &print_autoupdate('bottom',$dom,$settings,\$rowtotal);
                    615:             $rowtotal ++;
1.28      raeburn   616:         } elsif ($action eq 'usercreation') {
1.34      raeburn   617:             $output .= &print_usercreation('middle',$dom,$settings,\$rowtotal).'
                    618:            </table>
                    619:           </td>
                    620:          </tr>
                    621:          <tr>
                    622:            <td>
                    623:             <table class="LC_nested">
                    624:              <tr class="LC_info_row">
1.59      bisitz    625:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
                    626:               <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>             </tr>'.
1.34      raeburn   627:             &print_usercreation('bottom',$dom,$settings,\$rowtotal);
                    628:             $rowtotal ++;
1.33      raeburn   629:         } elsif ($action eq 'usermodification') {
1.63      raeburn   630:             $output .= &print_usermodification('middle',$dom,$settings,\$rowtotal).'
                    631:            </table>
                    632:           </td>
                    633:          </tr>
                    634:          <tr>
                    635:            <td>
                    636:             <table class="LC_nested">
                    637:              <tr class="LC_info_row">
                    638:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
                    639:               <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>      </tr>'.
                    640:                        &print_usermodification('bottom',$dom,$settings,\$rowtotal);
                    641:             $rowtotal ++;
1.57      raeburn   642:         } elsif ($action eq 'coursecategories') {
                    643:             $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.110     raeburn   644:         } elsif ($action eq 'login') {
1.168     raeburn   645:             if ($numheaders == 3) {
                    646:                 $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
                    647:            </table>
                    648:           </td>
                    649:          </tr>
                    650:          <tr>
                    651:            <td>
                    652:             <table class="LC_nested">
                    653:              <tr class="LC_info_row">
                    654:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
                    655:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>      </tr>'.
                    656:                        &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
                    657:                 $rowtotal ++;
                    658:             } else {
                    659:                 $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
                    660:             }
1.102     raeburn   661:         } elsif ($action eq 'requestcourses') {
1.163     raeburn   662:             $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
                    663:         } elsif ($action eq 'requestauthor') {
                    664:             $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.137     raeburn   665:         } elsif ($action eq 'usersessions') {
1.145     raeburn   666:             $output .= &print_usersessions('middle',$dom,$settings,\$rowtotal).'
                    667:            </table>
                    668:           </td>
                    669:          </tr>
                    670:          <tr>
                    671:            <td>
                    672:             <table class="LC_nested">
                    673:              <tr class="LC_info_row">
                    674:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
                    675:               <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>      </tr>'.
                    676:                        &print_usersessions('bottom',$dom,$settings,\$rowtotal);
                    677:             $rowtotal ++;
1.139     raeburn   678:         } elsif ($action eq 'coursedefaults') {
                    679:             $output .= &print_coursedefaults('bottom',$dom,$settings,\$rowtotal);
1.122     jms       680:         } elsif ($action eq 'rolecolors') {
1.30      raeburn   681:             $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6       raeburn   682:            </table>
                    683:           </td>
                    684:          </tr>
                    685:          <tr>
                    686:            <td>
                    687:             <table class="LC_nested">
                    688:              <tr class="LC_info_row">
1.69      raeburn   689:               <td class="LC_left_item"'.$colspan.' valign="top">'.
                    690:                &mt($item->{'header'}->[2]->{'col1'}).'</td>
                    691:               <td class="LC_right_item" valign="top">'.
                    692:                &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3       raeburn   693:              </tr>'.
1.30      raeburn   694:             &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3       raeburn   695:            </table>
                    696:           </td>
                    697:          </tr>
                    698:          <tr>
                    699:            <td>
                    700:             <table class="LC_nested">
                    701:              <tr class="LC_info_row">
1.59      bisitz    702:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
                    703:               <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3       raeburn   704:              </tr>'.
1.30      raeburn   705:             &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
                    706:             $rowtotal += 2;
1.6       raeburn   707:         }
1.3       raeburn   708:     } else {
1.30      raeburn   709:         $output .= '
1.3       raeburn   710:           <tr>
                    711:            <td>
                    712:             <table class="LC_nested">
1.30      raeburn   713:              <tr class="LC_info_row">';
1.24      raeburn   714:         if (($action eq 'login') || ($action eq 'directorysrch')) {
1.30      raeburn   715:             $output .= '  
1.59      bisitz    716:               <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69      raeburn   717:         } elsif ($action eq 'serverstatuses') {
                    718:             $output .= '
                    719:               <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
                    720:               '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
                    721: 
1.6       raeburn   722:         } else {
1.30      raeburn   723:             $output .= '
1.69      raeburn   724:               <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
                    725:         }
1.72      raeburn   726:         if (defined($item->{'header'}->[0]->{'col3'})) {
                    727:             $output .= '<td class="LC_left_item" valign="top">'.
                    728:                        &mt($item->{'header'}->[0]->{'col2'});
                    729:             if ($action eq 'serverstatuses') {
                    730:                 $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
                    731:             } 
1.69      raeburn   732:         } else {
                    733:             $output .= '<td class="LC_right_item" valign="top">'.
                    734:                        &mt($item->{'header'}->[0]->{'col2'});
                    735:         }
                    736:         $output .= '</td>';
                    737:         if ($item->{'header'}->[0]->{'col3'}) {
1.150     raeburn   738:             if (defined($item->{'header'}->[0]->{'col4'})) {
                    739:                 $output .= '<td class="LC_left_item" valign="top">'.
                    740:                             &mt($item->{'header'}->[0]->{'col3'});
                    741:             } else {
                    742:                 $output .= '<td class="LC_right_item" valign="top">'.
                    743:                            &mt($item->{'header'}->[0]->{'col3'});
                    744:             }
1.69      raeburn   745:             if ($action eq 'serverstatuses') {
                    746:                 $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
                    747:             }
                    748:             $output .= '</td>';
1.6       raeburn   749:         }
1.150     raeburn   750:         if ($item->{'header'}->[0]->{'col4'}) {
                    751:             $output .= '<td class="LC_right_item" valign="top">'.
                    752:                        &mt($item->{'header'}->[0]->{'col4'});
                    753:         }
1.69      raeburn   754:         $output .= '</tr>';
1.48      raeburn   755:         $rowtotal ++;
1.168     raeburn   756:         if ($action eq 'quotas') {
1.86      raeburn   757:             $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.3       raeburn   758:         } elsif ($action eq 'autoenroll') {
1.30      raeburn   759:             $output .= &print_autoenroll($dom,$settings,\$rowtotal);
1.125     raeburn   760:         } elsif ($action eq 'autocreate') {
                    761:             $output .= &print_autocreate($dom,$settings,\$rowtotal);
1.23      raeburn   762:         } elsif ($action eq 'directorysrch') {
1.30      raeburn   763:             $output .= &print_directorysrch($dom,$settings,\$rowtotal);
1.28      raeburn   764:         } elsif ($action eq 'contacts') {
1.30      raeburn   765:             $output .= &print_contacts($dom,$settings,\$rowtotal);
1.43      raeburn   766:         } elsif ($action eq 'defaults') {
                    767:             $output .= &print_defaults($dom,\$rowtotal);
1.46      raeburn   768:         } elsif ($action eq 'scantron') {
                    769:             $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
1.69      raeburn   770:         } elsif ($action eq 'serverstatuses') {
                    771:             $output .= &print_serverstatuses($dom,$settings,\$rowtotal);
1.118     jms       772:         } elsif ($action eq 'helpsettings') {
1.168     raeburn   773:             $output .= &print_helpsettings($dom,$confname,$settings,\$rowtotal);
1.150     raeburn   774:         } elsif ($action eq 'loadbalancing') {
                    775:             $output .= &print_loadbalancing($dom,$settings,\$rowtotal);
1.121     raeburn   776:         }
1.3       raeburn   777:     }
1.30      raeburn   778:     $output .= '
1.3       raeburn   779:    </table>
                    780:   </td>
                    781:  </tr>
1.30      raeburn   782: </table><br />';
                    783:     return ($output,$rowtotal);
1.1       raeburn   784: }
                    785: 
1.3       raeburn   786: sub print_login {
1.168     raeburn   787:     my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110     raeburn   788:     my ($css_class,$datatable);
1.6       raeburn   789:     my %choices = &login_choices();
1.110     raeburn   790: 
1.168     raeburn   791:     if ($caller eq 'service') {
1.149     raeburn   792:         my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110     raeburn   793:         my $choice = $choices{'disallowlogin'};
                    794:         $css_class = ' class="LC_odd_row"';
1.128     raeburn   795:         $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110     raeburn   796:                       '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128     raeburn   797:                       '<th>'.$choices{'server'}.'</th>'.
                    798:                       '<th>'.$choices{'serverpath'}.'</th>'.
                    799:                       '<th>'.$choices{'custompath'}.'</th>'.
                    800:                       '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110     raeburn   801:         my %disallowed;
                    802:         if (ref($settings) eq 'HASH') {
                    803:             if (ref($settings->{'loginvia'}) eq 'HASH') {
                    804:                %disallowed = %{$settings->{'loginvia'}};
                    805:             }
                    806:         }
                    807:         foreach my $lonhost (sort(keys(%servers))) {
                    808:             my $direct = 'selected="selected"';
1.128     raeburn   809:             if (ref($disallowed{$lonhost}) eq 'HASH') {
                    810:                 if ($disallowed{$lonhost}{'server'} ne '') {
                    811:                     $direct = '';
                    812:                 }
1.110     raeburn   813:             }
1.115     raeburn   814:             $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128     raeburn   815:                           '<td><select name="'.$lonhost.'_server">'.
1.110     raeburn   816:                           '<option value=""'.$direct.'>'.$choices{'directlogin'}.
                    817:                           '</option>';
                    818:             foreach my $hostid (keys(%servers)) {
1.115     raeburn   819:                 next if ($servers{$hostid} eq $servers{$lonhost});
1.110     raeburn   820:                 my $selected = '';
1.128     raeburn   821:                 if (ref($disallowed{$lonhost}) eq 'HASH') {
                    822:                     if ($hostid eq $disallowed{$lonhost}{'server'}) {
                    823:                         $selected = 'selected="selected"';
                    824:                     }
1.110     raeburn   825:                 }
                    826:                 $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
                    827:                               $servers{$hostid}.'</option>';
                    828:             }
1.128     raeburn   829:             $datatable .= '</select></td>'.
                    830:                           '<td><select name="'.$lonhost.'_serverpath">';
                    831:             foreach my $path ('','/','/adm/login','/adm/roles','custom') {
                    832:                 my $pathname = $path;
                    833:                 if ($path eq 'custom') {
                    834:                     $pathname = &mt('Custom Path').' ->';
                    835:                 }
                    836:                 my $selected = '';
                    837:                 if (ref($disallowed{$lonhost}) eq 'HASH') {
                    838:                     if ($path eq $disallowed{$lonhost}{'serverpath'}) {
                    839:                         $selected = 'selected="selected"';
                    840:                     }
                    841:                 } elsif ($path eq '') {
                    842:                     $selected = 'selected="selected"';
                    843:                 }
                    844:                 $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
                    845:             }
                    846:             $datatable .= '</select></td>';
                    847:             my ($custom,$exempt);
                    848:             if (ref($disallowed{$lonhost}) eq 'HASH') {
                    849:                 $custom = $disallowed{$lonhost}{'custompath'};
                    850:                 $exempt = $disallowed{$lonhost}{'exempt'};
                    851:             }
                    852:             $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
                    853:                           '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
                    854:                           '</tr>';
1.110     raeburn   855:         }
                    856:         $datatable .= '</table></td></tr>';
                    857:         return $datatable;
1.168     raeburn   858:     } elsif ($caller eq 'page') {
                    859:         my %defaultchecked = ( 
                    860:                                'coursecatalog' => 'on',
                    861:                                'adminmail'     => 'off',
                    862:                                'newuser'       => 'off',
                    863:                              );
                    864:         my @toggles = ('coursecatalog','adminmail','newuser');
                    865:         my (%checkedon,%checkedoff);
1.42      raeburn   866:         foreach my $item (@toggles) {
1.168     raeburn   867:             if ($defaultchecked{$item} eq 'on') { 
                    868:                 $checkedon{$item} = ' checked="checked" ';
1.42      raeburn   869:                 $checkedoff{$item} = ' ';
1.168     raeburn   870:             } elsif ($defaultchecked{$item} eq 'off') {
                    871:                 $checkedoff{$item} = ' checked="checked" ';
1.42      raeburn   872:                 $checkedon{$item} = ' ';
                    873:             }
1.1       raeburn   874:         }
1.168     raeburn   875:         my @images = ('img','logo','domlogo','login');
                    876:         my @logintext = ('textcol','bgcol');
                    877:         my @bgs = ('pgbg','mainbg','sidebg');
                    878:         my @links = ('link','alink','vlink');
                    879:         my %designhash = &Apache::loncommon::get_domainconf($dom);
                    880:         my %defaultdesign = %Apache::loncommon::defaultdesign;
                    881:         my (%is_custom,%designs);
                    882:         my %defaults = (
                    883:                        font => $defaultdesign{'login.font'},
                    884:                        );
1.6       raeburn   885:         foreach my $item (@images) {
1.168     raeburn   886:             $defaults{$item} = $defaultdesign{'login.'.$item};
                    887:             $defaults{'showlogo'}{$item} = 1;
                    888:         }
                    889:         foreach my $item (@bgs) {
                    890:             $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6       raeburn   891:         }
1.41      raeburn   892:         foreach my $item (@logintext) {
1.168     raeburn   893:             $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41      raeburn   894:         }
1.168     raeburn   895:         foreach my $item (@links) {
                    896:             $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6       raeburn   897:         }
1.168     raeburn   898:         if (ref($settings) eq 'HASH') {
                    899:             foreach my $item (@toggles) {
                    900:                 if ($settings->{$item} eq '1') {
                    901:                     $checkedon{$item} =  ' checked="checked" ';
                    902:                     $checkedoff{$item} = ' ';
                    903:                 } elsif ($settings->{$item} eq '0') {
                    904:                     $checkedoff{$item} =  ' checked="checked" ';
                    905:                     $checkedon{$item} = ' ';
                    906:                 }
                    907:             }
                    908:             foreach my $item (@images) {
                    909:                 if (defined($settings->{$item})) {
                    910:                     $designs{$item} = $settings->{$item};
                    911:                     $is_custom{$item} = 1;
                    912:                 }
                    913:                 if (defined($settings->{'showlogo'}{$item})) {
                    914:                     $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
                    915:                 }
                    916:             }
                    917:             foreach my $item (@logintext) {
                    918:                 if ($settings->{$item} ne '') {
                    919:                     $designs{'logintext'}{$item} = $settings->{$item};
                    920:                     $is_custom{$item} = 1;
                    921:                 }
                    922:             }
                    923:             if ($settings->{'font'} ne '') {
                    924:                 $designs{'font'} = $settings->{'font'};
                    925:                 $is_custom{'font'} = 1;
                    926:             }
                    927:             foreach my $item (@bgs) {
                    928:                 if ($settings->{$item} ne '') {
                    929:                     $designs{'bgs'}{$item} = $settings->{$item};
                    930:                     $is_custom{$item} = 1;
                    931:                 }
                    932:             }
                    933:             foreach my $item (@links) {
                    934:                 if ($settings->{$item} ne '') {
                    935:                     $designs{'links'}{$item} = $settings->{$item};
                    936:                     $is_custom{$item} = 1;
                    937:                 }
                    938:             }
                    939:         } else {
                    940:             if ($designhash{$dom.'.login.font'} ne '') {
                    941:                 $designs{'font'} = $designhash{$dom.'.login.font'};
                    942:                 $is_custom{'font'} = 1;
                    943:             }
                    944:             foreach my $item (@images) {
                    945:                 if ($designhash{$dom.'.login.'.$item} ne '') {
                    946:                     $designs{$item} = $designhash{$dom.'.login.'.$item};
                    947:                     $is_custom{$item} = 1;
                    948:                 }
                    949:             }
                    950:             foreach my $item (@bgs) {
                    951:                 if ($designhash{$dom.'.login.'.$item} ne '') {
                    952:                     $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
                    953:                     $is_custom{$item} = 1;
                    954:                 }
1.6       raeburn   955:             }
1.168     raeburn   956:             foreach my $item (@links) {
                    957:                 if ($designhash{$dom.'.login.'.$item} ne '') {
                    958:                     $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
                    959:                     $is_custom{$item} = 1;
                    960:                 }
1.6       raeburn   961:             }
                    962:         }
1.168     raeburn   963:         my %alt_text = &Apache::lonlocal::texthash  ( img => 'Log-in banner',
                    964:                                                       logo => 'Institution Logo',
                    965:                                                       domlogo => 'Domain Logo',
                    966:                                                       login => 'Login box');
                    967:         my $itemcount = 1;
                    968:         foreach my $item (@toggles) {
                    969:             $css_class = $itemcount%2?' class="LC_odd_row"':'';
                    970:             $datatable .=  
                    971:                 '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
                    972:                 '</td><td>'.
                    973:                 '<span class="LC_nobreak"><label><input type="radio" name="'.
                    974:                 $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
                    975:                 '</label>&nbsp;<label><input type="radio" name="'.$item.'"'.
                    976:                 $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
                    977:                 '</tr>';
                    978:             $itemcount ++;
1.6       raeburn   979:         }
1.168     raeburn   980:         $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
                    981:         $datatable .= '</tr></table></td></tr>';
                    982:     } elsif ($caller eq 'help') {
                    983:         my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
                    984:         my $switchserver = &check_switchserver($dom,$confname);
                    985:         my $itemcount = 1;
                    986:         $defaulturl = '/adm/loginproblems.html';
                    987:         $defaulttype = 'default';
                    988:         %lt = &Apache::lonlocal::texthash (
                    989:                      del     => 'Delete?',
                    990:                      rep     => 'Replace:',
                    991:                      upl     => 'Upload:',
                    992:                      default => 'Default',
                    993:                      custom  => 'Custom',
                    994:                                              );
                    995:         %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
                    996:         my @currlangs;
                    997:         if (ref($settings) eq 'HASH') {
                    998:             if (ref($settings->{'helpurl'}) eq 'HASH') {
                    999:                 foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
                   1000:                     next if ($settings->{'helpurl'}{$key} eq '');
                   1001:                     $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
                   1002:                     $type{$key} = 'custom';
                   1003:                     unless ($key eq 'nolang') {
                   1004:                         push(@currlangs,$key);
                   1005:                     }
                   1006:                 }
                   1007:             } elsif ($settings->{'helpurl'} ne '') {
                   1008:                 $type{'nolang'} = 'custom';
                   1009:                 $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8       raeburn  1010:             }
                   1011:         }
1.168     raeburn  1012:         foreach my $lang ('nolang',sort(@currlangs)) {
                   1013:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   1014:             $datatable .= '<tr'.$css_class.'>';
                   1015:             if ($url{$lang} eq '') {
                   1016:                 $url{$lang} = $defaulturl;
                   1017:             }
                   1018:             if ($type{$lang} eq '') {
                   1019:                 $type{$lang} = $defaulttype;
                   1020:             }
                   1021:             $datatable .= '<td colspan="2"><span class="LC_nobreak">';
                   1022:             if ($lang eq 'nolang') {
                   1023:                 $datatable .= &mt('Log-in help page if no specific language file: [_1]',
                   1024:                                   &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
                   1025:             } else {
                   1026:                 $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
                   1027:                                   $langchoices{$lang},
                   1028:                                   &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
                   1029:             }
                   1030:             $datatable .= '</span></td>'."\n".
                   1031:                           '<td class="LC_left_item">';
                   1032:             if ($type{$lang} eq 'custom') {
                   1033:                 $datatable .= '<span class="LC_nobreak"><label>'.
                   1034:                               '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
                   1035:                               $lt{'del'}.'</label>&nbsp;'.$lt{'rep'}.'</span>';
                   1036:             } else {
                   1037:                 $datatable .= $lt{'upl'};
                   1038:             }
                   1039:             $datatable .='<br />';
                   1040:             if ($switchserver) {
                   1041:                 $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   1042:             } else {
                   1043:                 $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6       raeburn  1044:             }
1.168     raeburn  1045:             $datatable .= '</td></tr>';
                   1046:             $itemcount ++;
1.6       raeburn  1047:         }
1.168     raeburn  1048:         my @addlangs;
                   1049:         foreach my $lang (sort(keys(%langchoices))) {
                   1050:             next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
                   1051:             push(@addlangs,$lang);
                   1052:         }
                   1053:         if (@addlangs > 0) {
                   1054:             my %toadd;
                   1055:             map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
                   1056:             $toadd{''} = &mt('Select');
                   1057:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   1058:             $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
                   1059:                           &mt('Add log-in help page for a specific language:').'&nbsp;'.
                   1060:                           &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
                   1061:                           '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
                   1062:             if ($switchserver) {
                   1063:                 $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   1064:             } else {
                   1065:                 $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6       raeburn  1066:             }
1.168     raeburn  1067:             $datatable .= '</td></tr>';
1.169     raeburn  1068:             $itemcount ++;
1.6       raeburn  1069:         }
1.169     raeburn  1070:         $datatable .= &captcha_choice('login',$settings,$itemcount);
1.1       raeburn  1071:     }
1.6       raeburn  1072:     return $datatable;
                   1073: }
                   1074: 
                   1075: sub login_choices {
                   1076:     my %choices =
                   1077:         &Apache::lonlocal::texthash (
1.116     bisitz   1078:             coursecatalog => 'Display Course/Community Catalog link?',
1.110     raeburn  1079:             adminmail     => "Display Administrator's E-mail Address?",
                   1080:             disallowlogin => "Login page requests redirected",
                   1081:             hostid        => "Server",
1.128     raeburn  1082:             server        => "Redirect to:",
                   1083:             serverpath    => "Path",
                   1084:             custompath    => "Custom", 
                   1085:             exempt        => "Exempt IP(s)",
1.110     raeburn  1086:             directlogin   => "No redirect",
                   1087:             newuser       => "Link to create a user account",
                   1088:             img           => "Header",
                   1089:             logo          => "Main Logo",
                   1090:             domlogo       => "Domain Logo",
                   1091:             login         => "Log-in Header", 
                   1092:             textcol       => "Text color",
                   1093:             bgcol         => "Box color",
                   1094:             bgs           => "Background colors",
                   1095:             links         => "Link colors",
                   1096:             font          => "Font color",
                   1097:             pgbg          => "Header",
                   1098:             mainbg        => "Page",
                   1099:             sidebg        => "Login box",
                   1100:             link          => "Link",
                   1101:             alink         => "Active link",
                   1102:             vlink         => "Visited link",
1.6       raeburn  1103:         );
                   1104:     return %choices;
                   1105: }
                   1106: 
                   1107: sub print_rolecolors {
1.30      raeburn  1108:     my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6       raeburn  1109:     my %choices = &color_font_choices();
                   1110:     my @bgs = ('pgbg','tabbg','sidebg');
                   1111:     my @links = ('link','alink','vlink');
                   1112:     my @images = ('img');
                   1113:     my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7       albertel 1114:     my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6       raeburn  1115:     my %defaultdesign = %Apache::loncommon::defaultdesign;
                   1116:     my (%is_custom,%designs);
                   1117:     my %defaults = (
                   1118:                    img => $defaultdesign{$role.'.img'},
                   1119:                    font => $defaultdesign{$role.'.font'},
1.97      tempelho 1120: 		   fontmenu => $defaultdesign{$role.'.fontmenu'},
1.6       raeburn  1121:                    );
                   1122:     foreach my $item (@bgs) {
                   1123:         $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
                   1124:     }
                   1125:     foreach my $item (@links) {
                   1126:         $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
                   1127:     }
                   1128:     if (ref($settings) eq 'HASH') {
                   1129:         if (ref($settings->{$role}) eq 'HASH') {
                   1130:             if ($settings->{$role}->{'img'} ne '') {
                   1131:                 $designs{'img'} = $settings->{$role}->{'img'};
                   1132:                 $is_custom{'img'} = 1;
                   1133:             }
                   1134:             if ($settings->{$role}->{'font'} ne '') {
                   1135:                 $designs{'font'} = $settings->{$role}->{'font'};
                   1136:                 $is_custom{'font'} = 1;
                   1137:             }
1.97      tempelho 1138:             if ($settings->{$role}->{'fontmenu'} ne '') {
                   1139:                 $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
                   1140:                 $is_custom{'fontmenu'} = 1;
                   1141:             }
1.6       raeburn  1142:             foreach my $item (@bgs) {
                   1143:                 if ($settings->{$role}->{$item} ne '') {
                   1144:                     $designs{'bgs'}{$item} = $settings->{$role}->{$item};
                   1145:                     $is_custom{$item} = 1;
                   1146:                 }
                   1147:             }
                   1148:             foreach my $item (@links) {
                   1149:                 if ($settings->{$role}->{$item} ne '') {
                   1150:                     $designs{'links'}{$item} = $settings->{$role}->{$item};
                   1151:                     $is_custom{$item} = 1;
                   1152:                 }
                   1153:             }
                   1154:         }
                   1155:     } else {
                   1156:         if ($designhash{$dom.'.'.$role.'.img'} ne '') {
                   1157:             $designs{img} = $designhash{$dom.'.'.$role.'.img'};
                   1158:             $is_custom{'img'} = 1;
                   1159:         }
1.97      tempelho 1160:         if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
                   1161:             $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
                   1162:             $is_custom{'fontmenu'} = 1; 
                   1163:         }
1.6       raeburn  1164:         if ($designhash{$dom.'.'.$role.'.font'} ne '') {
                   1165:             $designs{font} = $designhash{$dom.'.'.$role.'.font'};
                   1166:             $is_custom{'font'} = 1;
                   1167:         }
                   1168:         foreach my $item (@bgs) {
                   1169:             if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
                   1170:                 $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
                   1171:                 $is_custom{$item} = 1;
                   1172:             
                   1173:             }
                   1174:         }
                   1175:         foreach my $item (@links) {
                   1176:             if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
                   1177:                 $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
                   1178:                 $is_custom{$item} = 1;
                   1179:             }
                   1180:         }
                   1181:     }
                   1182:     my $itemcount = 1;
1.30      raeburn  1183:     my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6       raeburn  1184:     $datatable .= '</tr></table></td></tr>';
                   1185:     return $datatable;
                   1186: }
                   1187: 
                   1188: sub display_color_options {
1.9       raeburn  1189:     my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135     bisitz   1190:         $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159     raeburn  1191:     my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6       raeburn  1192:     my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.176   ! raeburn  1193:     my $datatable = '<tr'.$css_class.'>'.
1.6       raeburn  1194:         '<td>'.$choices->{'font'}.'</td>';
                   1195:     if (!$is_custom->{'font'}) {
1.30      raeburn  1196:         $datatable .=  '<td>'.&mt('Default in use:').'&nbsp;<span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6       raeburn  1197:     } else {
                   1198:         $datatable .= '<td>&nbsp;</td>';
                   1199:     }
1.174     foxr     1200:     my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
                   1201: 
1.8       raeburn  1202:     $datatable .= '<td><span class="LC_nobreak">'.
1.174     foxr     1203:                   '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
                   1204:                   ' value="'.$current_color.'" />&nbsp;'. 
                   1205:                   '&nbsp;</td></tr>';
1.107     raeburn  1206:     unless ($role eq 'login') { 
                   1207:         $datatable .= '<tr'.$css_class.'>'.
                   1208:                       '<td>'.$choices->{'fontmenu'}.'</td>';
                   1209:         if (!$is_custom->{'fontmenu'}) {
                   1210:             $datatable .=  '<td>'.&mt('Default in use:').'&nbsp;<span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
                   1211:         } else {
                   1212:             $datatable .= '<td>&nbsp;</td>';
                   1213:         }
1.174     foxr     1214: 	$current_color = $designs->{'fontmenu'} ? 
                   1215: 	    $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107     raeburn  1216:         $datatable .= '<td><span class="LC_nobreak">'.
1.174     foxr     1217:                       '<input class="colorchooser" type="text" size="10" name="'
                   1218: 		      .$role.'_fontmenu"'.
                   1219:                       ' value="'.$current_color.'" />&nbsp;'.
                   1220:                       '&nbsp;</td></tr>';
1.97      tempelho 1221:     }
1.9       raeburn  1222:     my $switchserver = &check_switchserver($dom,$confname);
1.6       raeburn  1223:     foreach my $img (@{$images}) {
1.18      albertel 1224: 	$itemcount ++;
1.6       raeburn  1225:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8       raeburn  1226:         $datatable .= '<tr'.$css_class.'>'.
1.70      raeburn  1227:                       '<td>'.$choices->{$img};
1.41      raeburn  1228:         my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70      raeburn  1229:         if ($role eq 'login') {
                   1230:             if ($img eq 'login') {
                   1231:                 $login_hdr_pick =
1.135     bisitz   1232:                     &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70      raeburn  1233:                 $logincolors =
                   1234:                     &login_text_colors($img,$role,$logintext,$phase,$choices,
                   1235:                                             $designs);
                   1236:             } elsif ($img ne 'domlogo') {
                   1237:                 $datatable.= &logo_display_options($img,$defaults,$designs);
                   1238:             }
                   1239:         }
                   1240:         $datatable .= '</td>';
1.6       raeburn  1241:         if ($designs->{$img} ne '') {
                   1242:             $imgfile = $designs->{$img};
1.18      albertel 1243: 	    $img_import = ($imgfile =~ m{^/adm/});
1.6       raeburn  1244:         } else {
                   1245:             $imgfile = $defaults->{$img};
                   1246:         }
                   1247:         if ($imgfile) {
1.9       raeburn  1248:             my ($showfile,$fullsize);
                   1249:             if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6       raeburn  1250:                 my $urldir = $1;
                   1251:                 my $filename = $2;
                   1252:                 my @info = &Apache::lonnet::stat_file($designs->{$img});
                   1253:                 if (@info) {
                   1254:                     my $thumbfile = 'tn-'.$filename;
                   1255:                     my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
                   1256:                     if (@thumb) {
                   1257:                         $showfile = $urldir.'/'.$thumbfile;
                   1258:                     } else {
                   1259:                         $showfile = $imgfile;
                   1260:                     }
                   1261:                 } else {
                   1262:                     $showfile = '';
                   1263:                 }
                   1264:             } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16      raeburn  1265:                 $showfile = $imgfile;
1.6       raeburn  1266:                 my $imgdir = $1;
                   1267:                 my $filename = $2;
1.159     raeburn  1268:                 if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6       raeburn  1269:                     $showfile = "/$imgdir/tn-".$filename;
                   1270:                 } else {
1.159     raeburn  1271:                     my $input = $londocroot.$imgfile;
                   1272:                     my $output = "$londocroot/$imgdir/tn-".$filename;
1.6       raeburn  1273:                     if (!-e $output) {
1.9       raeburn  1274:                         my ($width,$height) = &thumb_dimensions();
1.16      raeburn  1275:                         my ($fullwidth,$fullheight) = &check_dimensions($input);
                   1276:                         if ($fullwidth ne '' && $fullheight ne '') {
                   1277:                             if ($fullwidth > $width && $fullheight > $height) { 
                   1278:                                 my $size = $width.'x'.$height;
                   1279:                                 system("convert -sample $size $input $output");
1.159     raeburn  1280:                                 $showfile = "/$imgdir/tn-".$filename;
1.16      raeburn  1281:                             }
                   1282:                         }
1.6       raeburn  1283:                     }
                   1284:                 }
1.16      raeburn  1285:             }
1.6       raeburn  1286:             if ($showfile) {
1.40      raeburn  1287:                 if ($showfile =~ m{^/(adm|res)/}) {
                   1288:                     if ($showfile =~ m{^/res/}) {
                   1289:                         my $local_showfile =
                   1290:                             &Apache::lonnet::filelocation('',$showfile);
                   1291:                         &Apache::lonnet::repcopy($local_showfile);
                   1292:                     }
                   1293:                     $showfile = &Apache::loncommon::lonhttpdurl($showfile);
                   1294:                 }
                   1295:                 if ($imgfile) {
                   1296:                     if ($imgfile  =~ m{^/(adm|res)/}) {
                   1297:                         if ($imgfile =~ m{^/res/}) {
                   1298:                             my $local_imgfile =
                   1299:                                 &Apache::lonnet::filelocation('',$imgfile);
                   1300:                             &Apache::lonnet::repcopy($local_imgfile);
                   1301:                         }
                   1302:                         $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
                   1303:                     } else {
                   1304:                         $fullsize = $imgfile;
                   1305:                     }
                   1306:                 }
1.41      raeburn  1307:                 $datatable .= '<td>';
                   1308:                 if ($img eq 'login') {
1.135     bisitz   1309:                     $datatable .= $login_hdr_pick;
                   1310:                 } 
1.41      raeburn  1311:                 $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
                   1312:                                              $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6       raeburn  1313:             } else {
                   1314:                 $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
                   1315:                               &mt('Upload:');
                   1316:             }
                   1317:         } else {
                   1318:             $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
                   1319:                           &mt('Upload:');
                   1320:         }
1.9       raeburn  1321:         if ($switchserver) {
                   1322:             $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   1323:         } else {
1.135     bisitz   1324:             if ($img ne 'login') { # suppress file selection for Log-in header
                   1325:                 $datatable .='&nbsp;<input type="file" name="'.$role.'_'.$img.'" />';
                   1326:             }
1.9       raeburn  1327:         }
                   1328:         $datatable .= '</td></tr>';
1.6       raeburn  1329:     }
                   1330:     $itemcount ++;
                   1331:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   1332:     $datatable .= '<tr'.$css_class.'>'.
                   1333:                   '<td>'.$choices->{'bgs'}.'</td>';
                   1334:     my $bgs_def;
                   1335:     foreach my $item (@{$bgs}) {
                   1336:         if (!$is_custom->{$item}) {
1.70      raeburn  1337:             $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  1338:         }
                   1339:     }
                   1340:     if ($bgs_def) {
1.8       raeburn  1341:         $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6       raeburn  1342:     } else {
                   1343:         $datatable .= '<td>&nbsp;</td>';
                   1344:     }
                   1345:     $datatable .= '<td class="LC_right_item">'.
                   1346:                   '<table border="0"><tr>';
1.174     foxr     1347: 
                   1348: 
1.6       raeburn  1349:     foreach my $item (@{$bgs}) {
1.174     foxr     1350: #        my $link = &color_pick($phase,$role,$item,$choices->{$item},$designs->{'bgs'}{$item});
                   1351:         $datatable .= '<td align="center">';
                   1352: 	my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6       raeburn  1353:         if ($designs->{'bgs'}{$item}) {
1.174     foxr     1354:             $datatable .= '&nbsp;';
1.6       raeburn  1355:         }
1.174     foxr     1356:         $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41      raeburn  1357:                       '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6       raeburn  1358:     }
                   1359:     $datatable .= '</tr></table></td></tr>';
                   1360:     $itemcount ++;
                   1361:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   1362:     $datatable .= '<tr'.$css_class.'>'.
                   1363:                   '<td>'.$choices->{'links'}.'</td>';
                   1364:     my $links_def;
                   1365:     foreach my $item (@{$links}) {
                   1366:         if (!$is_custom->{$item}) {
1.30      raeburn  1367:             $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  1368:         }
                   1369:     }
                   1370:     if ($links_def) {
1.8       raeburn  1371:         $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6       raeburn  1372:     } else {
                   1373:         $datatable .= '<td>&nbsp;</td>';
                   1374:     }
                   1375:     $datatable .= '<td class="LC_right_item">'.
                   1376:                   '<table border="0"><tr>';
                   1377:     foreach my $item (@{$links}) {
1.174     foxr     1378: 	my $color = $designs->{'link'}{$item} ? $designs->{'link'}{$item} : $defaults->{'links'}{$item};
                   1379:         $datatable .= '<td align="center">'."\n";
                   1380: 
1.6       raeburn  1381:         if ($designs->{'links'}{$item}) {
1.174     foxr     1382:             $datatable.='&nbsp;';
1.6       raeburn  1383:         }
1.174     foxr     1384:         $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6       raeburn  1385:                       '" /></td>';
                   1386:     }
1.30      raeburn  1387:     $$rowtotal += $itemcount;
1.3       raeburn  1388:     return $datatable;
                   1389: }
                   1390: 
1.70      raeburn  1391: sub logo_display_options {
                   1392:     my ($img,$defaults,$designs) = @_;
                   1393:     my $checkedon;
                   1394:     if (ref($defaults) eq 'HASH') {
                   1395:         if (ref($defaults->{'showlogo'}) eq 'HASH') {
                   1396:             if ($defaults->{'showlogo'}{$img}) {
                   1397:                 $checkedon = 'checked="checked" ';     
                   1398:             }
                   1399:         } 
                   1400:     }
                   1401:     if (ref($designs) eq 'HASH') {
                   1402:         if (ref($designs->{'showlogo'}) eq 'HASH') {
                   1403:             if (defined($designs->{'showlogo'}{$img})) {
                   1404:                 if ($designs->{'showlogo'}{$img} == 0) {
                   1405:                     $checkedon = '';
                   1406:                 } elsif ($designs->{'showlogo'}{$img} == 1) {
                   1407:                     $checkedon = 'checked="checked" ';
                   1408:                 }
                   1409:             }
                   1410:         }
                   1411:     }
                   1412:     return '<br /><label>&nbsp;&nbsp;<input type="checkbox" name="'.
                   1413:            'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
                   1414:            &mt('show').'</label>'."\n";
                   1415: }
                   1416: 
1.41      raeburn  1417: sub login_header_options  {
1.135     bisitz   1418:     my ($img,$role,$defaults,$is_custom,$choices) = @_;
                   1419:     my $output = '';
1.41      raeburn  1420:     if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135     bisitz   1421:         $output .= &mt('Text default(s):').'<br />';
1.41      raeburn  1422:         if (!$is_custom->{'textcol'}) {
                   1423:             $output .= $choices->{'textcol'}.':&nbsp;'.$defaults->{'logintext'}{'textcol'}.
                   1424:                        '&nbsp;&nbsp;&nbsp;';
                   1425:         }
                   1426:         if (!$is_custom->{'bgcol'}) {
                   1427:             $output .= $choices->{'bgcol'}.':&nbsp;'.
                   1428:                        '<span id="css_'.$role.'_font" style="background-color: '.
                   1429:                        $defaults->{'logintext'}{'bgcol'}.';">&nbsp;&nbsp;&nbsp;</span>';
                   1430:         }
                   1431:         $output .= '<br />';
                   1432:     }
                   1433:     $output .='<br />';
                   1434:     return $output;
                   1435: }
                   1436: 
                   1437: sub login_text_colors {
                   1438:     my ($img,$role,$logintext,$phase,$choices,$designs) = @_;
                   1439:     my $color_menu = '<table border="0"><tr>';
                   1440:     foreach my $item (@{$logintext}) {
                   1441:         my $link = &color_pick($phase,$role,$item,$choices->{$item},$designs->{'logintext'}{$item});
                   1442:         $color_menu .= '<td align="center">'.$link;
                   1443:         if ($designs->{'logintext'}{$item}) {
                   1444:             $color_menu .= '&nbsp;<span id="css_'.$role.'_'.$item.'" style="background-color: '.$designs->{'logintext'}{$item}.';">&nbsp;&nbsp;&nbsp;</span>';
                   1445:         }
                   1446:         $color_menu .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.
                   1447:                        $designs->{'logintext'}{$item}.'" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>'.
                   1448:                        '<td>&nbsp;</td>';
                   1449:     }
                   1450:     $color_menu .= '</tr></table><br />';
                   1451:     return $color_menu;
                   1452: }
                   1453: 
                   1454: sub image_changes {
                   1455:     my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
                   1456:     my $output;
1.135     bisitz   1457:     if ($img eq 'login') {
                   1458:             # suppress image for Log-in header
                   1459:     } elsif (!$is_custom) {
1.70      raeburn  1460:         if ($img ne 'domlogo') {
1.41      raeburn  1461:             $output .= &mt('Default image:').'<br />';
                   1462:         } else {
                   1463:             $output .= &mt('Default in use:').'<br />';
                   1464:         }
                   1465:     }
1.135     bisitz   1466:     if ($img eq 'login') { # suppress image for Log-in header
                   1467:         $output .= '<td>'.$logincolors;
1.41      raeburn  1468:     } else {
1.135     bisitz   1469:         if ($img_import) {
                   1470:             $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
                   1471:         }
                   1472:         $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
                   1473:                    $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
                   1474:         if ($is_custom) {
                   1475:             $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
                   1476:                        '<input type="checkbox" name="'.
                   1477:                        $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
                   1478:                        '</label>&nbsp;'.&mt('Replace:').'</span><br />';
                   1479:         } else {
                   1480:             $output .= '<td valign="bottom">'.$logincolors.&mt('Upload:').'<br />';
                   1481:         }
1.41      raeburn  1482:     }
                   1483:     return $output;
                   1484: }
                   1485: 
1.6       raeburn  1486: sub color_pick {
                   1487:     my ($phase,$role,$item,$desc,$curcol) = @_;
                   1488:     my $link = '<a href="javascript:pjump('."'color_custom','".$desc.
                   1489:                "','".$curcol."','".$role.'_'.$item."','parmform.pres','psub'".
                   1490:                ');">'.$desc.'</a>';
                   1491:     return $link;
                   1492: }
                   1493: 
1.3       raeburn  1494: sub print_quotas {
1.86      raeburn  1495:     my ($dom,$settings,$rowtotal,$action) = @_;
                   1496:     my $context;
                   1497:     if ($action eq 'quotas') {
                   1498:         $context = 'tools';
                   1499:     } else {
                   1500:         $context = $action;
                   1501:     }
1.101     raeburn  1502:     my ($datatable,$defaultquota,@usertools,@options,%validations);
1.44      raeburn  1503:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3       raeburn  1504:     my $typecount = 0;
1.101     raeburn  1505:     my ($css_class,%titles);
1.86      raeburn  1506:     if ($context eq 'requestcourses') {
1.98      raeburn  1507:         @usertools = ('official','unofficial','community');
1.106     raeburn  1508:         @options =('norequest','approval','validate','autolimit');
1.101     raeburn  1509:         %validations = &Apache::lonnet::auto_courserequest_checks($dom);
                   1510:         %titles = &courserequest_titles();
1.163     raeburn  1511:     } elsif ($context eq 'requestauthor') {
                   1512:         @usertools = ('author');
                   1513:         @options = ('norequest','approval','automatic');
                   1514:         %titles = &authorrequest_titles(); 
1.86      raeburn  1515:     } else {
1.162     raeburn  1516:         @usertools = ('aboutme','blog','webdav','portfolio');
1.101     raeburn  1517:         %titles = &tool_titles();
1.86      raeburn  1518:     }
1.26      raeburn  1519:     if (ref($types) eq 'ARRAY') {
1.23      raeburn  1520:         foreach my $type (@{$types}) {
1.72      raeburn  1521:             my $currdefquota;
1.163     raeburn  1522:             unless (($context eq 'requestcourses') ||
                   1523:                     ($context eq 'requestauthor')) {
1.86      raeburn  1524:                 if (ref($settings) eq 'HASH') {
                   1525:                     if (ref($settings->{defaultquota}) eq 'HASH') {
                   1526:                         $currdefquota = $settings->{defaultquota}->{$type}; 
                   1527:                     } else {
                   1528:                         $currdefquota = $settings->{$type};
                   1529:                     }
1.78      raeburn  1530:                 }
1.72      raeburn  1531:             }
1.3       raeburn  1532:             if (defined($usertypes->{$type})) {
                   1533:                 $typecount ++;
                   1534:                 $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72      raeburn  1535:                 $datatable .= '<tr'.$css_class.'>'.
1.3       raeburn  1536:                               '<td>'.$usertypes->{$type}.'</td>'.
1.72      raeburn  1537:                               '<td class="LC_left_item">';
1.101     raeburn  1538:                 if ($context eq 'requestcourses') {
                   1539:                     $datatable .= '<table><tr>';
                   1540:                 }
                   1541:                 my %cell;  
1.72      raeburn  1542:                 foreach my $item (@usertools) {
1.101     raeburn  1543:                     if ($context eq 'requestcourses') {
                   1544:                         my ($curroption,$currlimit);
                   1545:                         if (ref($settings) eq 'HASH') {
                   1546:                             if (ref($settings->{$item}) eq 'HASH') {
                   1547:                                 $curroption = $settings->{$item}->{$type};
                   1548:                                 if ($curroption =~ /^autolimit=(\d*)$/) {
                   1549:                                     $currlimit = $1; 
                   1550:                                 }
                   1551:                             }
                   1552:                         }
                   1553:                         if (!$curroption) {
                   1554:                             $curroption = 'norequest';
                   1555:                         }
                   1556:                         $datatable .= '<th>'.$titles{$item}.'</th>';
                   1557:                         foreach my $option (@options) {
                   1558:                             my $val = $option;
                   1559:                             if ($option eq 'norequest') {
                   1560:                                 $val = 0;  
                   1561:                             }
                   1562:                             if ($option eq 'validate') {
                   1563:                                 my $canvalidate = 0;
                   1564:                                 if (ref($validations{$item}) eq 'HASH') { 
                   1565:                                     if ($validations{$item}{$type}) {
                   1566:                                         $canvalidate = 1;
                   1567:                                     }
                   1568:                                 }
                   1569:                                 next if (!$canvalidate);
                   1570:                             }
                   1571:                             my $checked = '';
                   1572:                             if ($option eq $curroption) {
                   1573:                                 $checked = ' checked="checked"';
                   1574:                             } elsif ($option eq 'autolimit') {
                   1575:                                 if ($curroption =~ /^autolimit/) {
                   1576:                                     $checked = ' checked="checked"';
                   1577:                                 }                       
                   1578:                             } 
                   1579:                             $cell{$item} .= '<span class="LC_nobreak"><label>'.
                   1580:                                   '<input type="radio" name="crsreq_'.$item.
                   1581:                                   '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127     raeburn  1582:                                   $titles{$option}.'</label>';
1.101     raeburn  1583:                             if ($option eq 'autolimit') {
1.127     raeburn  1584:                                 $cell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
1.101     raeburn  1585:                                                 $item.'_limit_'.$type.'" size="1" '.
1.103     raeburn  1586:                                                 'value="'.$currlimit.'" />';
1.101     raeburn  1587:                             }
1.127     raeburn  1588:                             $cell{$item} .= '</span> ';
1.103     raeburn  1589:                             if ($option eq 'autolimit') {
1.127     raeburn  1590:                                 $cell{$item} .= $titles{'unlimited'};
1.103     raeburn  1591:                             }
1.101     raeburn  1592:                         }
1.163     raeburn  1593:                     } elsif ($context eq 'requestauthor') {
                   1594:                         my $curroption;
                   1595:                         if (ref($settings) eq 'HASH') {
                   1596:                             $curroption = $settings->{$type};
                   1597:                         }
                   1598:                         if (!$curroption) {
                   1599:                             $curroption = 'norequest';
                   1600:                         }
                   1601:                         foreach my $option (@options) {
                   1602:                             my $val = $option;
                   1603:                             if ($option eq 'norequest') {
                   1604:                                 $val = 0;
                   1605:                             }
                   1606:                             my $checked = '';
                   1607:                             if ($option eq $curroption) {
                   1608:                                 $checked = ' checked="checked"';
                   1609:                             }
                   1610:                             $datatable .= '<span class="LC_nobreak"><label>'.
                   1611:                                   '<input type="radio" name="authorreq_'.$type.
                   1612:                                   '" value="'.$val.'"'.$checked.' />'.
                   1613:                                   $titles{$option}.'</label></span>&nbsp; ';
                   1614:                         }
1.101     raeburn  1615:                     } else {
                   1616:                         my $checked = 'checked="checked" ';
                   1617:                         if (ref($settings) eq 'HASH') {
                   1618:                             if (ref($settings->{$item}) eq 'HASH') {
                   1619:                                 if ($settings->{$item}->{$type} == 0) {
                   1620:                                     $checked = '';
                   1621:                                 } elsif ($settings->{$item}->{$type} == 1) {
                   1622:                                     $checked =  'checked="checked" ';
                   1623:                                 }
1.78      raeburn  1624:                             }
1.72      raeburn  1625:                         }
1.101     raeburn  1626:                         $datatable .= '<span class="LC_nobreak"><label>'.
                   1627:                                       '<input type="checkbox" name="'.$context.'_'.$item.
                   1628:                                       '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
                   1629:                                       '</label></span>&nbsp; ';
1.72      raeburn  1630:                     }
1.101     raeburn  1631:                 }
                   1632:                 if ($context eq 'requestcourses') {
                   1633:                     $datatable .= '</tr><tr>';
                   1634:                     foreach my $item (@usertools) {
1.106     raeburn  1635:                         $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';  
1.101     raeburn  1636:                     }
                   1637:                     $datatable .= '</tr></table>';
1.72      raeburn  1638:                 }
1.86      raeburn  1639:                 $datatable .= '</td>';
1.163     raeburn  1640:                 unless (($context eq 'requestcourses') ||
                   1641:                         ($context eq 'requestauthor')) {
1.86      raeburn  1642:                     $datatable .= 
                   1643:                               '<td class="LC_right_item"><span class="LC_nobreak">'.
1.3       raeburn  1644:                               '<input type="text" name="quota_'.$type.
1.72      raeburn  1645:                               '" value="'.$currdefquota.
1.86      raeburn  1646:                               '" size="5" /> Mb</span></td>';
                   1647:                 }
                   1648:                 $datatable .= '</tr>';
1.3       raeburn  1649:             }
                   1650:         }
                   1651:     }
1.163     raeburn  1652:     unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86      raeburn  1653:         $defaultquota = '20';
                   1654:         if (ref($settings) eq 'HASH') {
                   1655:             if (ref($settings->{'defaultquota'}) eq 'HASH') {
                   1656:                 $defaultquota = $settings->{'defaultquota'}->{'default'};
                   1657:             } elsif (defined($settings->{'default'})) {
                   1658:                 $defaultquota = $settings->{'default'};
                   1659:             }
1.3       raeburn  1660:         }
                   1661:     }
                   1662:     $typecount ++;
                   1663:     $css_class = $typecount%2?' class="LC_odd_row"':'';
                   1664:     $datatable .= '<tr'.$css_class.'>'.
1.26      raeburn  1665:                   '<td>'.$othertitle.'</td>'.
1.72      raeburn  1666:                   '<td class="LC_left_item">';
1.101     raeburn  1667:     if ($context eq 'requestcourses') {
                   1668:         $datatable .= '<table><tr>';
                   1669:     }
                   1670:     my %defcell;
1.72      raeburn  1671:     foreach my $item (@usertools) {
1.101     raeburn  1672:         if ($context eq 'requestcourses') {
                   1673:             my ($curroption,$currlimit);
                   1674:             if (ref($settings) eq 'HASH') {
                   1675:                 if (ref($settings->{$item}) eq 'HASH') {
                   1676:                     $curroption = $settings->{$item}->{'default'};
                   1677:                     if ($curroption =~ /^autolimit=(\d*)$/) {
                   1678:                         $currlimit = $1;
                   1679:                     }
                   1680:                 }
                   1681:             }
                   1682:             if (!$curroption) {
                   1683:                 $curroption = 'norequest';
                   1684:             }
                   1685:             $datatable .= '<th>'.$titles{$item}.'</th>';
                   1686:             foreach my $option (@options) {
                   1687:                 my $val = $option;
                   1688:                 if ($option eq 'norequest') {
                   1689:                     $val = 0;
                   1690:                 }
                   1691:                 if ($option eq 'validate') {
                   1692:                     my $canvalidate = 0;
                   1693:                     if (ref($validations{$item}) eq 'HASH') {
                   1694:                         if ($validations{$item}{'default'}) {
                   1695:                             $canvalidate = 1;
                   1696:                         }
                   1697:                     }
                   1698:                     next if (!$canvalidate);
                   1699:                 }
                   1700:                 my $checked = '';
                   1701:                 if ($option eq $curroption) {
                   1702:                     $checked = ' checked="checked"';
                   1703:                 } elsif ($option eq 'autolimit') {
                   1704:                     if ($curroption =~ /^autolimit/) {
                   1705:                         $checked = ' checked="checked"';
                   1706:                     }
                   1707:                 }
                   1708:                 $defcell{$item} .= '<span class="LC_nobreak"><label>'.
                   1709:                                   '<input type="radio" name="crsreq_'.$item.
                   1710:                                   '_default" value="'.$val.'"'.$checked.' />'.
                   1711:                                   $titles{$option}.'</label>';
                   1712:                 if ($option eq 'autolimit') {
1.127     raeburn  1713:                     $defcell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
1.101     raeburn  1714:                                        $item.'_limit_default" size="1" '.
                   1715:                                        'value="'.$currlimit.'" />';
                   1716:                 }
1.127     raeburn  1717:                 $defcell{$item} .= '</span> ';
1.104     raeburn  1718:                 if ($option eq 'autolimit') {
1.127     raeburn  1719:                     $defcell{$item} .= $titles{'unlimited'};
1.104     raeburn  1720:                 }
1.101     raeburn  1721:             }
1.163     raeburn  1722:         } elsif ($context eq 'requestauthor') {
                   1723:             my $curroption;
                   1724:             if (ref($settings) eq 'HASH') {
1.172     raeburn  1725:                 $curroption = $settings->{'default'};
1.163     raeburn  1726:             }
                   1727:             if (!$curroption) {
                   1728:                 $curroption = 'norequest';
                   1729:             }
                   1730:             foreach my $option (@options) {
                   1731:                 my $val = $option;
                   1732:                 if ($option eq 'norequest') {
                   1733:                     $val = 0;
                   1734:                 }
                   1735:                 my $checked = '';
                   1736:                 if ($option eq $curroption) {
                   1737:                     $checked = ' checked="checked"';
                   1738:                 }
                   1739:                 $datatable .= '<span class="LC_nobreak"><label>'.
                   1740:                               '<input type="radio" name="authorreq_default"'.
                   1741:                               ' value="'.$val.'"'.$checked.' />'.
                   1742:                               $titles{$option}.'</label></span>&nbsp; ';
                   1743:             }
1.101     raeburn  1744:         } else {
                   1745:             my $checked = 'checked="checked" ';
                   1746:             if (ref($settings) eq 'HASH') {
                   1747:                 if (ref($settings->{$item}) eq 'HASH') {
                   1748:                     if ($settings->{$item}->{'default'} == 0) {
                   1749:                         $checked = '';
                   1750:                     } elsif ($settings->{$item}->{'default'} == 1) {
                   1751:                         $checked = 'checked="checked" ';
                   1752:                     }
1.78      raeburn  1753:                 }
1.72      raeburn  1754:             }
1.101     raeburn  1755:             $datatable .= '<span class="LC_nobreak"><label>'.
                   1756:                           '<input type="checkbox" name="'.$context.'_'.$item.
                   1757:                           '" value="default" '.$checked.'/>'.$titles{$item}.
                   1758:                           '</label></span>&nbsp; ';
                   1759:         }
                   1760:     }
                   1761:     if ($context eq 'requestcourses') {
                   1762:         $datatable .= '</tr><tr>';
                   1763:         foreach my $item (@usertools) {
1.106     raeburn  1764:             $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72      raeburn  1765:         }
1.101     raeburn  1766:         $datatable .= '</tr></table>';
1.72      raeburn  1767:     }
1.86      raeburn  1768:     $datatable .= '</td>';
1.163     raeburn  1769:     unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86      raeburn  1770:         $datatable .= '<td class="LC_right_item"><span class="LC_nobreak">'.
                   1771:                       '<input type="text" name="defaultquota" value="'.
                   1772:                       $defaultquota.'" size="5" /> Mb</span></td>';
                   1773:     }
                   1774:     $datatable .= '</tr>';
1.72      raeburn  1775:     $typecount ++;
                   1776:     $css_class = $typecount%2?' class="LC_odd_row"':'';
                   1777:     $datatable .= '<tr'.$css_class.'>'.
1.104     raeburn  1778:                   '<td>'.&mt('LON-CAPA Advanced Users').' ';
                   1779:     if ($context eq 'requestcourses') {
1.109     raeburn  1780:         $datatable .= &mt('(overrides affiliation, if set)').
                   1781:                       '</td>'.
                   1782:                       '<td class="LC_left_item">'.
                   1783:                       '<table><tr>';
1.101     raeburn  1784:     } else {
1.109     raeburn  1785:         $datatable .= &mt('(overrides affiliation, if checked)').
                   1786:                       '</td>'.
                   1787:                       '<td class="LC_left_item" colspan="2">'.
                   1788:                       '<br />';
1.101     raeburn  1789:     }
                   1790:     my %advcell;
1.72      raeburn  1791:     foreach my $item (@usertools) {
1.101     raeburn  1792:         if ($context eq 'requestcourses') {
                   1793:             my ($curroption,$currlimit);
                   1794:             if (ref($settings) eq 'HASH') {
                   1795:                 if (ref($settings->{$item}) eq 'HASH') {
                   1796:                     $curroption = $settings->{$item}->{'_LC_adv'};
                   1797:                     if ($curroption =~ /^autolimit=(\d*)$/) {
                   1798:                         $currlimit = $1;
                   1799:                     }
                   1800:                 }
                   1801:             }
                   1802:             $datatable .= '<th>'.$titles{$item}.'</th>';
1.104     raeburn  1803:             my $checked = '';
                   1804:             if ($curroption eq '') {
                   1805:                 $checked = ' checked="checked"';
                   1806:             }
                   1807:             $advcell{$item} .= '<span class="LC_nobreak"><label>'.
                   1808:                                '<input type="radio" name="crsreq_'.$item.
                   1809:                                '__LC_adv" value=""'.$checked.' />'.
                   1810:                                &mt('No override set').'</label></span>&nbsp; ';
1.101     raeburn  1811:             foreach my $option (@options) {
                   1812:                 my $val = $option;
                   1813:                 if ($option eq 'norequest') {
                   1814:                     $val = 0;
                   1815:                 }
                   1816:                 if ($option eq 'validate') {
                   1817:                     my $canvalidate = 0;
                   1818:                     if (ref($validations{$item}) eq 'HASH') {
                   1819:                         if ($validations{$item}{'_LC_adv'}) {
                   1820:                             $canvalidate = 1;
                   1821:                         }
                   1822:                     }
                   1823:                     next if (!$canvalidate);
                   1824:                 }
                   1825:                 my $checked = '';
1.104     raeburn  1826:                 if ($val eq $curroption) {
1.101     raeburn  1827:                     $checked = ' checked="checked"';
                   1828:                 } elsif ($option eq 'autolimit') {
                   1829:                     if ($curroption =~ /^autolimit/) {
                   1830:                         $checked = ' checked="checked"';
                   1831:                     }
                   1832:                 }
                   1833:                 $advcell{$item} .= '<span class="LC_nobreak"><label>'.
                   1834:                                   '<input type="radio" name="crsreq_'.$item.
                   1835:                                   '__LC_adv" value="'.$val.'"'.$checked.' />'.
                   1836:                                   $titles{$option}.'</label>';
                   1837:                 if ($option eq 'autolimit') {
1.127     raeburn  1838:                     $advcell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
1.101     raeburn  1839:                                        $item.'_limit__LC_adv" size="1" '.
                   1840:                                        'value="'.$currlimit.'" />';
                   1841:                 }
1.127     raeburn  1842:                 $advcell{$item} .= '</span> ';
1.104     raeburn  1843:                 if ($option eq 'autolimit') {
1.127     raeburn  1844:                     $advcell{$item} .= $titles{'unlimited'};
1.104     raeburn  1845:                 }
1.101     raeburn  1846:             }
1.163     raeburn  1847:         } elsif ($context eq 'requestauthor') {
                   1848:             my $curroption;
                   1849:             if (ref($settings) eq 'HASH') {
                   1850:                 $curroption = $settings->{'_LC_adv'};
                   1851:             }
                   1852:             my $checked = '';
                   1853:             if ($curroption eq '') {
                   1854:                 $checked = ' checked="checked"';
                   1855:             }
                   1856:             $datatable .= '<span class="LC_nobreak"><label>'.
                   1857:                           '<input type="radio" name="authorreq__LC_adv"'.
                   1858:                           ' value=""'.$checked.' />'.
                   1859:                           &mt('No override set').'</label></span>&nbsp; ';
                   1860:             foreach my $option (@options) {
                   1861:                 my $val = $option;
                   1862:                 if ($option eq 'norequest') {
                   1863:                     $val = 0;
                   1864:                 }
                   1865:                 my $checked = '';
                   1866:                 if ($val eq $curroption) {
                   1867:                     $checked = ' checked="checked"';
                   1868:                 }
                   1869:                 $datatable .= '<span class="LC_nobreak"><label>'.
1.173     raeburn  1870:                               '<input type="radio" name="authorreq__LC_adv"'.
                   1871:                               ' value="'.$val.'"'.$checked.' />'.
1.163     raeburn  1872:                               $titles{$option}.'</label></span>&nbsp; ';
                   1873:             }
1.101     raeburn  1874:         } else {
                   1875:             my $checked = 'checked="checked" ';
                   1876:             if (ref($settings) eq 'HASH') {
                   1877:                 if (ref($settings->{$item}) eq 'HASH') {
                   1878:                     if ($settings->{$item}->{'_LC_adv'} == 0) {
                   1879:                         $checked = '';
                   1880:                     } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
                   1881:                         $checked = 'checked="checked" ';
                   1882:                     }
1.79      raeburn  1883:                 }
1.72      raeburn  1884:             }
1.101     raeburn  1885:             $datatable .= '<span class="LC_nobreak"><label>'.
                   1886:                           '<input type="checkbox" name="'.$context.'_'.$item.
                   1887:                           '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
                   1888:                           '</label></span>&nbsp; ';
                   1889:         }
                   1890:     }
                   1891:     if ($context eq 'requestcourses') {
                   1892:         $datatable .= '</tr><tr>';
                   1893:         foreach my $item (@usertools) {
1.106     raeburn  1894:             $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72      raeburn  1895:         }
1.101     raeburn  1896:         $datatable .= '</tr></table>';
1.72      raeburn  1897:     }
1.98      raeburn  1898:     $datatable .= '</td></tr>';
1.30      raeburn  1899:     $$rowtotal += $typecount;
1.3       raeburn  1900:     return $datatable;
                   1901: }
                   1902: 
1.163     raeburn  1903: sub print_requestmail {
                   1904:     my ($dom,$action,$settings,$rowtotal) = @_;
1.104     raeburn  1905:     my ($now,$datatable,%dompersonnel,@domcoord,@currapproval,$rows);
1.102     raeburn  1906:     $now = time;
                   1907:     $rows = 0;
                   1908:     %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
                   1909:     foreach my $server (keys(%dompersonnel)) {
                   1910:         foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
                   1911:             my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
                   1912:             if (!grep(/^$uname:$udom$/,@domcoord)) {
                   1913:                 push(@domcoord,$uname.':'.$udom);
                   1914:             }
                   1915:         }
                   1916:     }
                   1917:     if (ref($settings) eq 'HASH') {
                   1918:         if (ref($settings->{'notify'}) eq 'HASH') {
                   1919:             if ($settings->{'notify'}{'approval'} ne '') {
1.104     raeburn  1920:                @currapproval = split(',',$settings->{'notify'}{'approval'});
1.102     raeburn  1921:             }
                   1922:         }
                   1923:     }
1.104     raeburn  1924:     if (@currapproval) {
                   1925:         foreach my $dc (@currapproval) {
1.102     raeburn  1926:             unless (grep(/^\Q$dc\E$/,@domcoord)) {
                   1927:                 push(@domcoord,$dc);
                   1928:             }
                   1929:         }
                   1930:     }
                   1931:     @domcoord = sort(@domcoord);
                   1932:     my $numinrow = 4;
                   1933:     my $numdc = @domcoord;
                   1934:     my $css_class = 'class="LC_odd_row"';
1.163     raeburn  1935:     my $text;
                   1936:     if ($action eq 'requestcourses') {
                   1937:         $text = &mt('Receive notification of course requests requiring approval');
                   1938:     } else {
                   1939:         $text = &mt('Receive notification of authoring space requests requiring approval')
                   1940:     }
                   1941:     $datatable = '<tr '.$css_class.'>'.
                   1942:                  ' <td>'.$text.'</td>'.
1.102     raeburn  1943:                  ' <td class="LC_left_item">';
                   1944:     if (@domcoord > 0) {
                   1945:         $datatable .= '<table>';
                   1946:         for (my $i=0; $i<$numdc; $i++) {
                   1947:             my $rem = $i%($numinrow);
                   1948:             if ($rem == 0) {
                   1949:                 if ($i > 0) {
                   1950:                     $datatable .= '</tr>';
                   1951:                 }
                   1952:                 $datatable .= '<tr>';
                   1953:                 $rows ++;
                   1954:             }
                   1955:             my $check = ' ';
1.104     raeburn  1956:             if (grep(/^\Q$domcoord[$i]\E$/,@currapproval)) {
1.102     raeburn  1957:                 $check = ' checked="checked" ';
                   1958:             }
                   1959:             my ($uname,$udom) = split(':',$domcoord[$i]);
                   1960:             my $fullname = &Apache::loncommon::plainname($uname,$udom);
                   1961:             if ($i == $numdc-1) {
                   1962:                 my $colsleft = $numinrow-$rem;
                   1963:                 if ($colsleft > 1) {
                   1964:                     $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
                   1965:                 } else {
                   1966:                     $datatable .= '<td class="LC_left_item">';
                   1967:                 }
                   1968:             } else {
                   1969:                 $datatable .= '<td class="LC_left_item">';
                   1970:             }
                   1971:             $datatable .= '<span class="LC_nobreak"><label>'.
                   1972:                           '<input type="checkbox" name="reqapprovalnotify" '.
                   1973:                           'value="'.$domcoord[$i].'"'.$check.'/>'.
1.175     bisitz   1974:                           $fullname.' ('.$uname.':'.$udom.')</label></span></td>';
1.102     raeburn  1975:         }
                   1976:         $datatable .= '</tr></table>';
                   1977:     } else {
                   1978:         $datatable .= &mt('There are no active Domain Coordinators');
                   1979:         $rows ++;
                   1980:     }
                   1981:     $datatable .='</td></tr>';
                   1982:     $$rowtotal += $rows;
                   1983:     return $datatable;
                   1984: }
                   1985: 
1.3       raeburn  1986: sub print_autoenroll {
1.30      raeburn  1987:     my ($dom,$settings,$rowtotal) = @_;
1.3       raeburn  1988:     my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.129     raeburn  1989:     my ($defdom,$runon,$runoff,$coownerson,$coownersoff);
1.3       raeburn  1990:     if (ref($settings) eq 'HASH') {
                   1991:         if (exists($settings->{'run'})) {
                   1992:             if ($settings->{'run'} eq '0') {
                   1993:                 $runoff = ' checked="checked" ';
                   1994:                 $runon = ' ';
                   1995:             } else {
                   1996:                 $runon = ' checked="checked" ';
                   1997:                 $runoff = ' ';
                   1998:             }
                   1999:         } else {
                   2000:             if ($autorun) {
                   2001:                 $runon = ' checked="checked" ';
                   2002:                 $runoff = ' ';
                   2003:             } else {
                   2004:                 $runoff = ' checked="checked" ';
                   2005:                 $runon = ' ';
                   2006:             }
                   2007:         }
1.129     raeburn  2008:         if (exists($settings->{'co-owners'})) {
                   2009:             if ($settings->{'co-owners'} eq '0') {
                   2010:                 $coownersoff = ' checked="checked" ';
                   2011:                 $coownerson = ' ';
                   2012:             } else {
                   2013:                 $coownerson = ' checked="checked" ';
                   2014:                 $coownersoff = ' ';
                   2015:             }
                   2016:         } else {
                   2017:             $coownersoff = ' checked="checked" ';
                   2018:             $coownerson = ' ';
                   2019:         }
1.3       raeburn  2020:         if (exists($settings->{'sender_domain'})) {
                   2021:             $defdom = $settings->{'sender_domain'};
                   2022:         }
1.14      raeburn  2023:     } else {
                   2024:         if ($autorun) {
                   2025:             $runon = ' checked="checked" ';
                   2026:             $runoff = ' ';
                   2027:         } else {
                   2028:             $runoff = ' checked="checked" ';
                   2029:             $runon = ' ';
                   2030:         }
1.3       raeburn  2031:     }
                   2032:     my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39      raeburn  2033:     my $notif_sender;
                   2034:     if (ref($settings) eq 'HASH') {
                   2035:         $notif_sender = $settings->{'sender_uname'};
                   2036:     }
1.3       raeburn  2037:     my $datatable='<tr class="LC_odd_row">'.
                   2038:                   '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8       raeburn  2039:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3       raeburn  2040:                   '<input type="radio" name="autoenroll_run"'.
1.8       raeburn  2041:                   $runon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   2042:                   '<label><input type="radio" name="autoenroll_run"'.
1.14      raeburn  2043:                   $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3       raeburn  2044:                   '</tr><tr>'.
                   2045:                   '<td>'.&mt('Notification messages - sender').
1.8       raeburn  2046:                   '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3       raeburn  2047:                   &mt('username').':&nbsp;'.
                   2048:                   '<input type="text" name="sender_uname" value="'.
1.39      raeburn  2049:                   $notif_sender.'" size="10" />&nbsp;&nbsp;'.&mt('domain').
1.129     raeburn  2050:                   ':&nbsp;'.$domform.'</span></td></tr>'.
                   2051:                   '<tr class="LC_odd_row">'.
                   2052:                   '<td>'.&mt('Automatically assign co-ownership').'</td>'.
                   2053:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   2054:                   '<input type="radio" name="autoassign_coowners"'.
                   2055:                   $coownerson.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   2056:                   '<label><input type="radio" name="autoassign_coowners"'.
                   2057:                   $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
                   2058:                   '</tr>';
                   2059:     $$rowtotal += 3;
1.3       raeburn  2060:     return $datatable;
                   2061: }
                   2062: 
                   2063: sub print_autoupdate {
1.30      raeburn  2064:     my ($position,$dom,$settings,$rowtotal) = @_;
1.3       raeburn  2065:     my $datatable;
                   2066:     if ($position eq 'top') {
                   2067:         my $updateon = ' ';
                   2068:         my $updateoff = ' checked="checked" ';
                   2069:         my $classlistson = ' ';
                   2070:         my $classlistsoff = ' checked="checked" ';
                   2071:         if (ref($settings) eq 'HASH') {
                   2072:             if ($settings->{'run'} eq '1') {
                   2073:                 $updateon = $updateoff;
                   2074:                 $updateoff = ' ';
                   2075:             }
                   2076:             if ($settings->{'classlists'} eq '1') {
                   2077:                 $classlistson = $classlistsoff;
                   2078:                 $classlistsoff = ' ';
                   2079:             }
                   2080:         }
                   2081:         my %title = (
                   2082:                    run => 'Auto-update active?',
                   2083:                    classlists => 'Update information in classlists?',
                   2084:                     );
                   2085:         $datatable = '<tr class="LC_odd_row">'. 
                   2086:                   '<td>'.&mt($title{'run'}).'</td>'.
1.8       raeburn  2087:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3       raeburn  2088:                   '<input type="radio" name="autoupdate_run"'.
1.8       raeburn  2089:                   $updateon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   2090:                   '<label><input type="radio" name="autoupdate_run"'.
                   2091:                   $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3       raeburn  2092:                   '</tr><tr>'.
                   2093:                   '<td>'.&mt($title{'classlists'}).'</td>'.
1.8       raeburn  2094:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
                   2095:                   '<label><input type="radio" name="classlists"'.
                   2096:                   $classlistson.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   2097:                   '<label><input type="radio" name="classlists"'.
                   2098:                   $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3       raeburn  2099:                   '</tr>';
1.30      raeburn  2100:         $$rowtotal += 2;
1.131     raeburn  2101:     } elsif ($position eq 'middle') {
                   2102:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   2103:         my $numinrow = 3;
                   2104:         my $locknamesettings;
                   2105:         $datatable .= &insttypes_row($settings,$types,$usertypes,
                   2106:                                      $dom,$numinrow,$othertitle,
                   2107:                                     'lockablenames');
                   2108:         $$rowtotal ++;
1.3       raeburn  2109:     } else {
1.44      raeburn  2110:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132     raeburn  2111:         my @fields = ('lastname','firstname','middlename','generation',
1.20      raeburn  2112:                       'permanentemail','id');
1.33      raeburn  2113:         my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3       raeburn  2114:         my $numrows = 0;
1.26      raeburn  2115:         if (ref($types) eq 'ARRAY') {
                   2116:             if (@{$types} > 0) {
                   2117:                 $datatable = 
                   2118:                     &usertype_update_row($settings,$usertypes,\%fieldtitles,
                   2119:                                          \@fields,$types,\$numrows);
1.30      raeburn  2120:                     $$rowtotal += @{$types}; 
1.26      raeburn  2121:             }
1.3       raeburn  2122:         }
                   2123:         $datatable .= 
                   2124:             &usertype_update_row($settings,{'default' => $othertitle},
                   2125:                                  \%fieldtitles,\@fields,['default'],
                   2126:                                  \$numrows);
1.30      raeburn  2127:         $$rowtotal ++;     
1.3       raeburn  2128:     }
                   2129:     return $datatable;
                   2130: }
                   2131: 
1.125     raeburn  2132: sub print_autocreate {
                   2133:     my ($dom,$settings,$rowtotal) = @_;
                   2134:     my (%createon,%createoff);
                   2135:     my $curr_dc;
                   2136:     my @types = ('xml','req');
                   2137:     if (ref($settings) eq 'HASH') {
                   2138:         foreach my $item (@types) {
                   2139:             $createoff{$item} = ' checked="checked" ';
                   2140:             $createon{$item} = ' ';
                   2141:             if (exists($settings->{$item})) {
                   2142:                 if ($settings->{$item}) {
                   2143:                     $createon{$item} = ' checked="checked" ';
                   2144:                     $createoff{$item} = ' ';
                   2145:                 }
                   2146:             }
                   2147:         }
                   2148:         $curr_dc = $settings->{'xmldc'};
                   2149:     } else {
                   2150:         foreach my $item (@types) {
                   2151:             $createoff{$item} = ' checked="checked" ';
                   2152:             $createon{$item} = ' ';
                   2153:         }
                   2154:     }
                   2155:     $$rowtotal += 2;
                   2156:     my $datatable='<tr class="LC_odd_row">'.
                   2157:                   '<td>'.&mt('Create pending official courses from XML files').'</td>'.
                   2158:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   2159:                   '<input type="radio" name="autocreate_xml"'.
                   2160:                   $createon{'xml'}.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   2161:                   '<label><input type="radio" name="autocreate_xml"'.
1.143     raeburn  2162:                   $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
                   2163:                   '</td></tr><tr>'.
                   2164:                   '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
                   2165:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   2166:                   '<input type="radio" name="autocreate_req"'.
                   2167:                   $createon{'req'}.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   2168:                   '<label><input type="radio" name="autocreate_req"'.
                   2169:                   $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.125     raeburn  2170:     my ($numdc,$dctable) = &active_dc_picker($dom,$curr_dc);
                   2171:     if ($numdc > 1) {
1.143     raeburn  2172:         $datatable .= '</td></tr><tr class="LC_odd_row"><td>'.
                   2173:                       &mt('Course creation processed as: (choose Dom. Coord.)').
                   2174:                       '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.125     raeburn  2175:         $$rowtotal ++ ;
                   2176:     } else {
1.143     raeburn  2177:         $datatable .= $dctable.'</td></tr>';
1.125     raeburn  2178:     }
                   2179:     return $datatable;
                   2180: }
                   2181: 
1.23      raeburn  2182: sub print_directorysrch {
1.30      raeburn  2183:     my ($dom,$settings,$rowtotal) = @_;
1.23      raeburn  2184:     my $srchon = ' ';
                   2185:     my $srchoff = ' checked="checked" ';
1.25      raeburn  2186:     my ($exacton,$containson,$beginson);
1.24      raeburn  2187:     my $localon = ' ';
                   2188:     my $localoff = ' checked="checked" ';
1.23      raeburn  2189:     if (ref($settings) eq 'HASH') {
                   2190:         if ($settings->{'available'} eq '1') {
                   2191:             $srchon = $srchoff;
                   2192:             $srchoff = ' ';
                   2193:         }
1.24      raeburn  2194:         if ($settings->{'localonly'} eq '1') {
                   2195:             $localon = $localoff;
                   2196:             $localoff = ' ';
                   2197:         }
1.25      raeburn  2198:         if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
                   2199:             foreach my $type (@{$settings->{'searchtypes'}}) {
                   2200:                 if ($type eq 'exact') {
                   2201:                     $exacton = ' checked="checked" ';
                   2202:                 } elsif ($type eq 'contains') {
                   2203:                     $containson = ' checked="checked" ';
                   2204:                 } elsif ($type eq 'begins') {
                   2205:                     $beginson = ' checked="checked" ';
                   2206:                 }
                   2207:             }
                   2208:         } else {
                   2209:             if ($settings->{'searchtypes'} eq 'exact') {
                   2210:                 $exacton = ' checked="checked" ';
                   2211:             } elsif ($settings->{'searchtypes'} eq 'contains') {
                   2212:                 $containson = ' checked="checked" ';
                   2213:             } elsif ($settings->{'searchtypes'} eq 'specify') {
                   2214:                 $exacton = ' checked="checked" ';
                   2215:                 $containson = ' checked="checked" ';
                   2216:             }
1.23      raeburn  2217:         }
                   2218:     }
                   2219:     my ($searchtitles,$titleorder) = &sorted_searchtitles();
1.45      raeburn  2220:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23      raeburn  2221: 
                   2222:     my $numinrow = 4;
1.26      raeburn  2223:     my $cansrchrow = 0;
1.23      raeburn  2224:     my $datatable='<tr class="LC_odd_row">'.
1.30      raeburn  2225:                   '<td colspan="2"><span class ="LC_nobreak">'.&mt('Directory search available?').'</span></td>'.
1.23      raeburn  2226:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   2227:                   '<input type="radio" name="dirsrch_available"'.
                   2228:                   $srchon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   2229:                   '<label><input type="radio" name="dirsrch_available"'.
                   2230:                   $srchoff.' value="0" />'.&mt('No').'</label></span></td>'.
                   2231:                   '</tr><tr>'.
1.30      raeburn  2232:                   '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search?').'</span></td>'.
1.24      raeburn  2233:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   2234:                   '<input type="radio" name="dirsrch_localonly"'.
                   2235:                   $localoff.' value="0" />'.&mt('Yes').'</label>&nbsp;'.
                   2236:                   '<label><input type="radio" name="dirsrch_localonly"'.
                   2237:                   $localon.' value="1" />'.&mt('No').'</label></span></td>'.
1.25      raeburn  2238:                   '</tr>';
1.30      raeburn  2239:     $$rowtotal += 2;
1.26      raeburn  2240:     if (ref($usertypes) eq 'HASH') {
                   2241:         if (keys(%{$usertypes}) > 0) {
1.93      raeburn  2242:             $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
                   2243:                                          $numinrow,$othertitle,'cansearch');
1.26      raeburn  2244:             $cansrchrow = 1;
                   2245:         }
                   2246:     }
                   2247:     if ($cansrchrow) {
1.30      raeburn  2248:         $$rowtotal ++;
1.26      raeburn  2249:         $datatable .= '<tr>';
                   2250:     } else {
                   2251:         $datatable .= '<tr class="LC_odd_row">';
                   2252:     }
1.30      raeburn  2253:     $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
                   2254:                   '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
1.25      raeburn  2255:     foreach my $title (@{$titleorder}) {
                   2256:         if (defined($searchtitles->{$title})) {
                   2257:             my $check = ' ';
1.93      raeburn  2258:             if (ref($settings) eq 'HASH') {
1.39      raeburn  2259:                 if (ref($settings->{'searchby'}) eq 'ARRAY') {
                   2260:                     if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
                   2261:                         $check = ' checked="checked" ';
                   2262:                     }
1.25      raeburn  2263:                 }
                   2264:             }
                   2265:             $datatable .= '<td class="LC_left_item">'.
                   2266:                           '<span class="LC_nobreak"><label>'.
                   2267:                           '<input type="checkbox" name="searchby" '.
                   2268:                           'value="'.$title.'"'.$check.'/>'.
                   2269:                           $searchtitles->{$title}.'</label></span></td>';
                   2270:         }
                   2271:     }
1.26      raeburn  2272:     $datatable .= '</tr></table></td></tr>';
1.30      raeburn  2273:     $$rowtotal ++;
1.26      raeburn  2274:     if ($cansrchrow) {
                   2275:         $datatable .= '<tr class="LC_odd_row">';
                   2276:     } else {
                   2277:         $datatable .= '<tr>';
                   2278:     }
1.30      raeburn  2279:     $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.   
1.26      raeburn  2280:                   '<td class="LC_left_item" colspan="2">'.
1.25      raeburn  2281:                   '<span class="LC_nobreak"><label>'.
                   2282:                   '<input type="checkbox" name="searchtypes" '.
                   2283:                   $exacton.' value="exact" />'.&mt('Exact match').
                   2284:                   '</label>&nbsp;'.
                   2285:                   '<label><input type="checkbox" name="searchtypes" '.
                   2286:                   $beginson.' value="begins" />'.&mt('Begins with').
                   2287:                   '</label>&nbsp;'.
                   2288:                   '<label><input type="checkbox" name="searchtypes" '.
                   2289:                   $containson.' value="contains" />'.&mt('Contains').
                   2290:                   '</label></span></td></tr>';
1.30      raeburn  2291:     $$rowtotal ++;
1.25      raeburn  2292:     return $datatable;
                   2293: }
                   2294: 
1.28      raeburn  2295: sub print_contacts {
1.30      raeburn  2296:     my ($dom,$settings,$rowtotal) = @_;
1.28      raeburn  2297:     my $datatable;
                   2298:     my @contacts = ('adminemail','supportemail');
1.134     raeburn  2299:     my (%checked,%to,%otheremails,%bccemails);
1.102     raeburn  2300:     my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail',
                   2301:                     'requestsmail');
1.28      raeburn  2302:     foreach my $type (@mailings) {
                   2303:         $otheremails{$type} = '';
                   2304:     }
1.134     raeburn  2305:     $bccemails{'helpdeskmail'} = '';
1.28      raeburn  2306:     if (ref($settings) eq 'HASH') {
                   2307:         foreach my $item (@contacts) {
                   2308:             if (exists($settings->{$item})) {
                   2309:                 $to{$item} = $settings->{$item};
                   2310:             }
                   2311:         }
                   2312:         foreach my $type (@mailings) {
                   2313:             if (exists($settings->{$type})) {
                   2314:                 if (ref($settings->{$type}) eq 'HASH') {
                   2315:                     foreach my $item (@contacts) {
                   2316:                         if ($settings->{$type}{$item}) {
                   2317:                             $checked{$type}{$item} = ' checked="checked" ';
                   2318:                         }
                   2319:                     }
                   2320:                     $otheremails{$type} = $settings->{$type}{'others'};
1.134     raeburn  2321:                     if ($type eq 'helpdeskmail') {
                   2322:                         $bccemails{$type} = $settings->{$type}{'bcc'};
                   2323:                     }
1.28      raeburn  2324:                 }
1.89      raeburn  2325:             } elsif ($type eq 'lonstatusmail') {
                   2326:                 $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.28      raeburn  2327:             }
                   2328:         }
                   2329:     } else {
                   2330:         $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
                   2331:         $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
                   2332:         $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
                   2333:         $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.89      raeburn  2334:         $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
                   2335:         $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" '; 
1.102     raeburn  2336:         $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
1.28      raeburn  2337:     }
                   2338:     my ($titles,$short_titles) = &contact_titles();
                   2339:     my $rownum = 0;
                   2340:     my $css_class;
                   2341:     foreach my $item (@contacts) {
1.69      raeburn  2342:         $rownum ++;
                   2343:         $css_class = $rownum%2?' class="LC_odd_row"':'';
1.30      raeburn  2344:         $datatable .= '<tr'.$css_class.'>'. 
                   2345:                   '<td><span class="LC_nobreak">'.$titles->{$item}.
                   2346:                   '</span></td><td class="LC_right_item">'.
1.28      raeburn  2347:                   '<input type="text" name="'.$item.'" value="'.
                   2348:                   $to{$item}.'" /></td></tr>';
                   2349:     }
                   2350:     foreach my $type (@mailings) {
1.69      raeburn  2351:         $rownum ++;
                   2352:         $css_class = $rownum%2?' class="LC_odd_row"':'';
1.28      raeburn  2353:         $datatable .= '<tr'.$css_class.'>'.
1.30      raeburn  2354:                       '<td><span class="LC_nobreak">'.
                   2355:                       $titles->{$type}.': </span></td>'.
1.28      raeburn  2356:                       '<td class="LC_left_item">'.
                   2357:                       '<span class="LC_nobreak">';
                   2358:         foreach my $item (@contacts) {
                   2359:             $datatable .= '<label>'.
                   2360:                           '<input type="checkbox" name="'.$type.'"'.
                   2361:                           $checked{$type}{$item}.
                   2362:                           ' value="'.$item.'" />'.$short_titles->{$item}.
                   2363:                           '</label>&nbsp;';
                   2364:         }
                   2365:         $datatable .= '</span><br />'.&mt('Others').':&nbsp;&nbsp;'.
                   2366:                       '<input type="text" name="'.$type.'_others" '.
1.134     raeburn  2367:                       'value="'.$otheremails{$type}.'"  />';
                   2368:         if ($type eq 'helpdeskmail') {
1.136     raeburn  2369:             $datatable .= '<br />'.&mt('Bcc:').('&nbsp;'x6).
1.134     raeburn  2370:                           '<input type="text" name="'.$type.'_bcc" '.
                   2371:                           'value="'.$bccemails{$type}.'"  />';
                   2372:         }
                   2373:         $datatable .= '</td></tr>'."\n";
1.28      raeburn  2374:     }
1.30      raeburn  2375:     $$rowtotal += $rownum;
1.28      raeburn  2376:     return $datatable;
                   2377: }
                   2378: 
1.118     jms      2379: sub print_helpsettings {
1.168     raeburn  2380:     my ($dom,$confname,$settings,$rowtotal) = @_;
                   2381:     my ($datatable,$itemcount);
1.166     raeburn  2382:     $itemcount = 1;
1.168     raeburn  2383:     my (%choices,%defaultchecked,@toggles);
                   2384:     $choices{'submitbugs'} = &mt('Display link to: [_1]?',
                   2385:                                  &Apache::loncommon::modal_link('http://bugs.loncapa.org',
                   2386:                                  &mt('LON-CAPA bug tracker'),600,500));
                   2387:     %defaultchecked = ('submitbugs' => 'on');
                   2388:     @toggles = ('submitbugs',);
1.166     raeburn  2389: 
1.168     raeburn  2390:     ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
                   2391:                                                  \%choices,$itemcount);
1.166     raeburn  2392:     return $datatable;
1.121     raeburn  2393: }
                   2394: 
                   2395: sub radiobutton_prefs {
                   2396:     my ($settings,$toggles,$defaultchecked,$choices,$itemcount) = @_;
                   2397:     return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
                   2398:                    (ref($choices) eq 'HASH'));
                   2399: 
1.170     raeburn  2400:     my (%checkedon,%checkedoff,$datatable,$css_class);
1.121     raeburn  2401: 
                   2402:     foreach my $item (@{$toggles}) {
                   2403:         if ($defaultchecked->{$item} eq 'on') {
1.118     jms      2404:             $checkedon{$item} = ' checked="checked" ';
                   2405:             $checkedoff{$item} = ' ';
1.121     raeburn  2406:         } elsif ($defaultchecked->{$item} eq 'off') {
1.118     jms      2407:             $checkedoff{$item} = ' checked="checked" ';
                   2408:             $checkedon{$item} = ' ';
                   2409:         }
                   2410:     }
                   2411:     if (ref($settings) eq 'HASH') {
1.121     raeburn  2412:         foreach my $item (@{$toggles}) {
1.118     jms      2413:             if ($settings->{$item} eq '1') {
                   2414:                 $checkedon{$item} =  ' checked="checked" ';
                   2415:                 $checkedoff{$item} = ' ';
                   2416:             } elsif ($settings->{$item} eq '0') {
                   2417:                 $checkedoff{$item} =  ' checked="checked" ';
                   2418:                 $checkedon{$item} = ' ';
                   2419:             }
                   2420:         }
1.121     raeburn  2421:     }
                   2422:     foreach my $item (@{$toggles}) {
1.118     jms      2423:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121     raeburn  2424:         $datatable .=
                   2425:             '<tr'.$css_class.'><td><span class="LC_nobreak">'.$choices->{$item}.
1.118     jms      2426:             '</span></td>'.
                   2427:             '<td class="LC_right_item"><span class="LC_nobreak">'.
                   2428:             '<label><input type="radio" name="'.
                   2429:             $item.'" '.$checkedon{$item}.' value="1" />'.&mt('Yes').
                   2430:             '</label>&nbsp;<label><input type="radio" name="'.$item.'" '.
                   2431:             $checkedoff{$item}.' value="0" />'.&mt('No').'</label>'.
                   2432:             '</span></td>'.
                   2433:             '</tr>';
                   2434:         $itemcount ++;
1.121     raeburn  2435:     }
                   2436:     return ($datatable,$itemcount);
                   2437: }
                   2438: 
                   2439: sub print_coursedefaults {
1.139     raeburn  2440:     my ($position,$dom,$settings,$rowtotal) = @_;
1.121     raeburn  2441:     my ($css_class,$datatable);
                   2442:     my $itemcount = 1;
1.139     raeburn  2443:     if ($position eq 'top') {
                   2444:         my (%checkedon,%checkedoff,%choices,%defaultchecked,@toggles);
                   2445:         %choices =
                   2446:             &Apache::lonlocal::texthash (
                   2447:                 canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
                   2448:         );
                   2449:         %defaultchecked = ('canuse_pdfforms' => 'off');
                   2450:         @toggles = ('canuse_pdfforms',);
                   2451:         ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.121     raeburn  2452:                                                  \%choices,$itemcount);
1.139     raeburn  2453:         $$rowtotal += $itemcount;
                   2454:     } else {
                   2455:         $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   2456:         my %choices =
                   2457:             &Apache::lonlocal::texthash (
                   2458:                 anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
                   2459:         );
                   2460:         my $currdefresponder;
                   2461:         if (ref($settings) eq 'HASH') {
                   2462:             $currdefresponder = $settings->{'anonsurvey_threshold'};
                   2463:         }
                   2464:         if (!$currdefresponder) {
                   2465:             $currdefresponder = 10;
                   2466:         } elsif ($currdefresponder < 1) {
                   2467:             $currdefresponder = 1;
                   2468:         }
                   2469:         $datatable .=
                   2470:                '<tr'.$css_class.'><td><span class="LC_nobreak">'.$choices{'anonsurvey_threshold'}.
                   2471:                 '</span></td>'.
                   2472:                 '<td class="LC_right_item"><span class="LC_nobreak">'.
                   2473:                 '<input type="text" name="anonsurvey_threshold"'.
                   2474:                 ' value="'.$currdefresponder.'" size="5" /></span>'.
                   2475:                 '</td></tr>';
                   2476:     }
1.121     raeburn  2477:     return $datatable;
1.118     jms      2478: }
                   2479: 
1.137     raeburn  2480: sub print_usersessions {
                   2481:     my ($position,$dom,$settings,$rowtotal) = @_;
                   2482:     my ($css_class,$datatable,%checked,%choices);
1.140     raeburn  2483:     my (%by_ip,%by_location,@intdoms);
                   2484:     &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145     raeburn  2485: 
                   2486:     my @alldoms = &Apache::lonnet::all_domains();
1.152     raeburn  2487:     my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149     raeburn  2488:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152     raeburn  2489:     my %altids = &id_for_thisdom(%servers);
1.145     raeburn  2490:     my $itemcount = 1;
                   2491:     if ($position eq 'top') {
1.152     raeburn  2492:         if (keys(%serverhomes) > 1) {
1.145     raeburn  2493:             my %spareid = &current_offloads_to($dom,$settings,\%servers);
1.152     raeburn  2494:             $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$rowtotal);
1.145     raeburn  2495:         } else {
1.140     raeburn  2496:             $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150     raeburn  2497:                           &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140     raeburn  2498:         }
1.137     raeburn  2499:     } else {
1.145     raeburn  2500:         if (keys(%by_location) == 0) {
                   2501:             $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150     raeburn  2502:                           &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145     raeburn  2503:         } else {
                   2504:             my %lt = &usersession_titles();
                   2505:             my $numinrow = 5;
                   2506:             my $prefix;
                   2507:             my @types;
                   2508:             if ($position eq 'bottom') {
                   2509:                 $prefix = 'remote';
                   2510:                 @types = ('version','excludedomain','includedomain');
                   2511:             } else {
                   2512:                 $prefix = 'hosted';
                   2513:                 @types = ('excludedomain','includedomain');
                   2514:             }
                   2515:             my (%current,%checkedon,%checkedoff);
                   2516:             my @lcversions = &Apache::lonnet::all_loncaparevs();
                   2517:             my @locations = sort(keys(%by_location));
                   2518:             foreach my $type (@types) {
                   2519:                 $checkedon{$type} = '';
                   2520:                 $checkedoff{$type} = ' checked="checked"';
                   2521:             }
                   2522:             if (ref($settings) eq 'HASH') {
                   2523:                 if (ref($settings->{$prefix}) eq 'HASH') {
                   2524:                     foreach my $key (keys(%{$settings->{$prefix}})) {
                   2525:                         $current{$key} = $settings->{$prefix}{$key};
                   2526:                         if ($key eq 'version') {
                   2527:                             if ($current{$key} ne '') {
                   2528:                                 $checkedon{$key} = ' checked="checked"';
                   2529:                                 $checkedoff{$key} = '';
                   2530:                             }
                   2531:                         } elsif (ref($current{$key}) eq 'ARRAY') {
                   2532:                             $checkedon{$key} = ' checked="checked"';
                   2533:                             $checkedoff{$key} = '';
                   2534:                         }
1.137     raeburn  2535:                     }
                   2536:                 }
                   2537:             }
1.145     raeburn  2538:             foreach my $type (@types) {
                   2539:                 next if ($type ne 'version' && !@locations);
                   2540:                 $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   2541:                 $datatable .= '<tr'.$css_class.'>
                   2542:                                <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
                   2543:                                <span class="LC_nobreak">&nbsp;
                   2544:                                <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>&nbsp;
                   2545:                                <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
                   2546:                 if ($type eq 'version') {
                   2547:                     my $selector = '<select name="'.$prefix.'_version">';
                   2548:                     foreach my $version (@lcversions) {
                   2549:                         my $selected = '';
                   2550:                         if ($current{'version'} eq $version) {
                   2551:                             $selected = ' selected="selected"';
                   2552:                         }
                   2553:                         $selector .= ' <option value="'.$version.'"'.
                   2554:                                      $selected.'>'.$version.'</option>';
                   2555:                     }
                   2556:                     $selector .= '</select> ';
                   2557:                     $datatable .= &mt('remote server must be version: [_1] or later',$selector);
                   2558:                 } else {
                   2559:                     $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
                   2560:                                  'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
                   2561:                                  ' />'.('&nbsp;'x2).
                   2562:                                  '<input type="button" value="'.&mt('uncheck all').'" '.
                   2563:                                  'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
                   2564:                                  "\n".
                   2565:                                  '</div><div><table>';
                   2566:                     my $rem;
                   2567:                     for (my $i=0; $i<@locations; $i++) {
                   2568:                         my ($showloc,$value,$checkedtype);
                   2569:                         if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
                   2570:                             my $ip = $by_location{$locations[$i]}->[0];
                   2571:                             if (ref($by_ip{$ip}) eq 'ARRAY') {
                   2572:                                  $value = join(':',@{$by_ip{$ip}});
                   2573:                                 $showloc = join(', ',@{$by_ip{$ip}});
                   2574:                                 if (ref($current{$type}) eq 'ARRAY') {
                   2575:                                     foreach my $loc (@{$by_ip{$ip}}) {  
                   2576:                                         if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
                   2577:                                             $checkedtype = ' checked="checked"';
                   2578:                                             last;
                   2579:                                         }
                   2580:                                     }
1.138     raeburn  2581:                                 }
                   2582:                             }
                   2583:                         }
1.145     raeburn  2584:                         $rem = $i%($numinrow);
                   2585:                         if ($rem == 0) {
                   2586:                             if ($i > 0) {
                   2587:                                 $datatable .= '</tr>';
                   2588:                             }
                   2589:                             $datatable .= '<tr>';
                   2590:                         }
                   2591:                         $datatable .= '<td class="LC_left_item">'.
                   2592:                                       '<span class="LC_nobreak"><label>'.
                   2593:                                       '<input type="checkbox" name="'.$prefix.'_'.$type.
                   2594:                                       '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
                   2595:                                       '</label></span></td>';
1.137     raeburn  2596:                     }
1.145     raeburn  2597:                     $rem = @locations%($numinrow);
                   2598:                     my $colsleft = $numinrow - $rem;
                   2599:                     if ($colsleft > 1 ) {
                   2600:                         $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   2601:                                       '&nbsp;</td>';
                   2602:                     } elsif ($colsleft == 1) {
                   2603:                         $datatable .= '<td class="LC_left_item">&nbsp;</td>';
1.137     raeburn  2604:                     }
1.145     raeburn  2605:                     $datatable .= '</tr></table>';
1.137     raeburn  2606:                 }
1.145     raeburn  2607:                 $datatable .= '</td></tr>';
                   2608:                 $itemcount ++;
1.137     raeburn  2609:             }
                   2610:         }
                   2611:     }
                   2612:     $$rowtotal += $itemcount;
                   2613:     return $datatable;
                   2614: }
                   2615: 
1.138     raeburn  2616: sub build_location_hashes {
                   2617:     my ($intdoms,$by_ip,$by_location) = @_;
                   2618:     return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
                   2619:                   (ref($by_location) eq 'HASH')); 
                   2620:     my %iphost = &Apache::lonnet::get_iphost();
                   2621:     my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
                   2622:     my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
                   2623:     if (ref($iphost{$primary_ip}) eq 'ARRAY') {
                   2624:         foreach my $id (@{$iphost{$primary_ip}}) {
                   2625:             my $intdom = &Apache::lonnet::internet_dom($id);
                   2626:             unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
                   2627:                 push(@{$intdoms},$intdom);
                   2628:             }
                   2629:         }
                   2630:     }
                   2631:     foreach my $ip (keys(%iphost)) {
                   2632:         if (ref($iphost{$ip}) eq 'ARRAY') {
                   2633:             foreach my $id (@{$iphost{$ip}}) {
                   2634:                 my $location = &Apache::lonnet::internet_dom($id);
                   2635:                 if ($location) {
                   2636:                     next if (grep(/^\Q$location\E$/,@{$intdoms}));
                   2637:                     if (ref($by_ip->{$ip}) eq 'ARRAY') {
                   2638:                         unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
                   2639:                             push(@{$by_ip->{$ip}},$location);
                   2640:                         }
                   2641:                     } else {
                   2642:                         $by_ip->{$ip} = [$location];
                   2643:                     }
                   2644:                 }
                   2645:             }
                   2646:         }
                   2647:     }
                   2648:     foreach my $ip (sort(keys(%{$by_ip}))) {
                   2649:         if (ref($by_ip->{$ip}) eq 'ARRAY') {
                   2650:             @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
                   2651:             my $first = $by_ip->{$ip}->[0];
                   2652:             if (ref($by_location->{$first}) eq 'ARRAY') {
                   2653:                 unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
                   2654:                     push(@{$by_location->{$first}},$ip);
                   2655:                 }
                   2656:             } else {
                   2657:                 $by_location->{$first} = [$ip];
                   2658:             }
                   2659:         }
                   2660:     }
                   2661:     return;
                   2662: }
                   2663: 
1.145     raeburn  2664: sub current_offloads_to {
                   2665:     my ($dom,$settings,$servers) = @_;
                   2666:     my (%spareid,%otherdomconfigs);
1.152     raeburn  2667:     if (ref($servers) eq 'HASH') {
1.145     raeburn  2668:         foreach my $lonhost (sort(keys(%{$servers}))) {
                   2669:             my $gotspares;
1.152     raeburn  2670:             if (ref($settings) eq 'HASH') {
                   2671:                 if (ref($settings->{'spares'}) eq 'HASH') {
                   2672:                     if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
                   2673:                         $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
                   2674:                         $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
                   2675:                         $gotspares = 1;
                   2676:                     }
1.145     raeburn  2677:                 }
                   2678:             }
                   2679:             unless ($gotspares) {
                   2680:                 my $gotspares;
                   2681:                 my $serverhomeID =
                   2682:                     &Apache::lonnet::get_server_homeID($servers->{$lonhost});
                   2683:                 my $serverhomedom =
                   2684:                     &Apache::lonnet::host_domain($serverhomeID);
                   2685:                 if ($serverhomedom ne $dom) {
                   2686:                     if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
                   2687:                         if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
                   2688:                             if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
                   2689:                                 $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
                   2690:                                 $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
                   2691:                                 $gotspares = 1;
                   2692:                             }
                   2693:                         }
                   2694:                     } else {
                   2695:                         $otherdomconfigs{$serverhomedom} =
                   2696:                             &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
                   2697:                         if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
                   2698:                             if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
                   2699:                                 if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
                   2700:                                     if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
                   2701:                                         $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
                   2702:                                         $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
                   2703:                                         $gotspares = 1;
                   2704:                                     }
                   2705:                                 }
                   2706:                             }
                   2707:                         }
                   2708:                     }
                   2709:                 }
                   2710:             }
                   2711:             unless ($gotspares) {
                   2712:                 if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
                   2713:                     $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
                   2714:                     $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
                   2715:                } else {
                   2716:                     my $server_hostname = &Apache::lonnet::hostname($lonhost);
                   2717:                     my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
                   2718:                     if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
                   2719:                         $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
                   2720:                         $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
                   2721:                     } else {
1.150     raeburn  2722:                         my %what = (
                   2723:                              spareid => 1,
                   2724:                         );
                   2725:                         my ($result,$returnhash) = 
                   2726:                             &Apache::lonnet::get_remote_globals($lonhost,\%what);
                   2727:                         if ($result eq 'ok') { 
                   2728:                             if (ref($returnhash) eq 'HASH') {
                   2729:                                 if (ref($returnhash->{'spareid'}) eq 'HASH') {
                   2730:                                     $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
                   2731:                                     $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
                   2732:                                 }
                   2733:                             }
1.145     raeburn  2734:                         }
                   2735:                     }
                   2736:                 }
                   2737:             }
                   2738:         }
                   2739:     }
                   2740:     return %spareid;
                   2741: }
                   2742: 
                   2743: sub spares_row {
1.152     raeburn  2744:     my ($dom,$servers,$spareid,$serverhomes,$altids,$rowtotal) = @_;
1.145     raeburn  2745:     my $css_class;
                   2746:     my $numinrow = 4;
                   2747:     my $itemcount = 1;
                   2748:     my $datatable;
1.152     raeburn  2749:     my %typetitles = &sparestype_titles();
                   2750:     if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145     raeburn  2751:         foreach my $server (sort(keys(%{$servers}))) {
1.152     raeburn  2752:             my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
                   2753:             my ($othercontrol,$serverdom);
                   2754:             if ($serverhome ne $server) {
                   2755:                 $serverdom = &Apache::lonnet::host_domain($serverhome);
                   2756:                 $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
                   2757:             } else {
                   2758:                 $serverdom = &Apache::lonnet::host_domain($server);
                   2759:                 if ($serverdom ne $dom) {
                   2760:                     $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
                   2761:                 }
                   2762:             }
                   2763:             next unless (ref($spareid->{$server}) eq 'HASH');
1.145     raeburn  2764:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   2765:             $datatable .= '<tr'.$css_class.'>
                   2766:                            <td rowspan="2">
1.152     raeburn  2767:                             <span class="LC_nobreak"><b>'.$server.'</b> when busy, offloads to:</span></td>'."\n";
1.145     raeburn  2768:             my (%current,%canselect);
1.152     raeburn  2769:             my @choices = 
                   2770:                 &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
                   2771:             foreach my $type ('primary','default') {
                   2772:                 if (ref($spareid->{$server}) eq 'HASH') {
1.145     raeburn  2773:                     if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
                   2774:                         my @spares = @{$spareid->{$server}{$type}};
                   2775:                         if (@spares > 0) {
1.152     raeburn  2776:                             if ($othercontrol) {
                   2777:                                 $current{$type} = join(', ',@spares);
                   2778:                             } else {
                   2779:                                 $current{$type} .= '<table>';
                   2780:                                 my $numspares = scalar(@spares);
                   2781:                                 for (my $i=0;  $i<@spares; $i++) {
                   2782:                                     my $rem = $i%($numinrow);
                   2783:                                     if ($rem == 0) {
                   2784:                                         if ($i > 0) {
                   2785:                                             $current{$type} .= '</tr>';
                   2786:                                         }
                   2787:                                         $current{$type} .= '<tr>';
1.145     raeburn  2788:                                     }
1.152     raeburn  2789:                                     $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;'.
                   2790:                                                        $spareid->{$server}{$type}[$i].
                   2791:                                                        '</label></td>'."\n";
                   2792:                                 }
                   2793:                                 my $rem = @spares%($numinrow);
                   2794:                                 my $colsleft = $numinrow - $rem;
                   2795:                                 if ($colsleft > 1 ) {
                   2796:                                     $current{$type} .= '<td colspan="'.$colsleft.
                   2797:                                                        '" class="LC_left_item">'.
                   2798:                                                        '&nbsp;</td>';
                   2799:                                 } elsif ($colsleft == 1) {
                   2800:                                     $current{$type} .= '<td class="LC_left_item">&nbsp;</td>'."\n";
1.145     raeburn  2801:                                 }
1.152     raeburn  2802:                                 $current{$type} .= '</tr></table>';
1.150     raeburn  2803:                             }
1.145     raeburn  2804:                         }
                   2805:                     }
                   2806:                     if ($current{$type} eq '') {
                   2807:                         $current{$type} = &mt('None specified');
                   2808:                     }
1.152     raeburn  2809:                     if ($othercontrol) {
                   2810:                         if ($type eq 'primary') {
                   2811:                             $canselect{$type} = $othercontrol;
                   2812:                         }
                   2813:                     } else {
                   2814:                         $canselect{$type} = 
                   2815:                             &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').'&nbsp;'.
                   2816:                             '<select name="newspare_'.$type.'_'.$server.'" '.
                   2817:                             'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
                   2818:                             '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
                   2819:                         if (@choices > 0) {
                   2820:                             foreach my $lonhost (@choices) {
                   2821:                                 $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
                   2822:                             }
                   2823:                         }
                   2824:                         $canselect{$type} .= '</select>'."\n";
                   2825:                     }
                   2826:                 } else {
                   2827:                     $current{$type} = &mt('Could not be determined');
                   2828:                     if ($type eq 'primary') {
                   2829:                         $canselect{$type} =  $othercontrol;
                   2830:                     }
1.145     raeburn  2831:                 }
1.152     raeburn  2832:                 if ($type eq 'default') {
                   2833:                     $datatable .= '<tr'.$css_class.'>';
                   2834:                 }
                   2835:                 $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
                   2836:                               '<td>'.$current{$type}.'</td>'."\n".
                   2837:                               '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145     raeburn  2838:             }
                   2839:             $itemcount ++;
                   2840:         }
                   2841:     }
                   2842:     $$rowtotal += $itemcount;
                   2843:     return $datatable;
                   2844: }
                   2845: 
1.152     raeburn  2846: sub possible_newspares {
                   2847:     my ($server,$currspares,$serverhomes,$altids) = @_;
                   2848:     my $serverhostname = &Apache::lonnet::hostname($server);
                   2849:     my %excluded;
                   2850:     if ($serverhostname ne '') {
                   2851:         %excluded = (
                   2852:                        $serverhostname => 1,
                   2853:                     );
                   2854:     }
                   2855:     if (ref($currspares) eq 'HASH') {
                   2856:         foreach my $type (keys(%{$currspares})) {
                   2857:             if (ref($currspares->{$type}) eq 'ARRAY') {
                   2858:                 if (@{$currspares->{$type}} > 0) {
                   2859:                     foreach my $curr (@{$currspares->{$type}}) {
                   2860:                         my $hostname = &Apache::lonnet::hostname($curr);
                   2861:                         $excluded{$hostname} = 1;
                   2862:                     }
                   2863:                 }
                   2864:             }
                   2865:         }
                   2866:     }
                   2867:     my @choices;
                   2868:     if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
                   2869:         if (keys(%{$serverhomes}) > 1) {
                   2870:             foreach my $name (sort(keys(%{$serverhomes}))) {
                   2871:                 unless ($excluded{$name}) {
                   2872:                     if (exists($altids->{$serverhomes->{$name}})) {
                   2873:                         push(@choices,$altids->{$serverhomes->{$name}});
                   2874:                     } else {
                   2875:                         push(@choices,$serverhomes->{$name});
1.145     raeburn  2876:                     }
                   2877:                 }
                   2878:             }
                   2879:         }
                   2880:     }
1.152     raeburn  2881:     return sort(@choices);
1.145     raeburn  2882: }
                   2883: 
1.150     raeburn  2884: sub print_loadbalancing {
                   2885:     my ($dom,$settings,$rowtotal) = @_;
                   2886:     my $primary_id = &Apache::lonnet::domain($dom,'primary');
                   2887:     my $intdom = &Apache::lonnet::internet_dom($primary_id);
                   2888:     my $numinrow = 1;
                   2889:     my $datatable;
                   2890:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.171     raeburn  2891:     my (%currbalancer,%currtargets,%currrules,%existing);
                   2892:     if (ref($settings) eq 'HASH') {
                   2893:         %existing = %{$settings};
                   2894:     }
                   2895:     if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
                   2896:         &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
                   2897:                                   \%currtargets,\%currrules);
1.150     raeburn  2898:     } else {
                   2899:         return;
                   2900:     }
                   2901:     my ($othertitle,$usertypes,$types) =
                   2902:         &Apache::loncommon::sorted_inst_types($dom);
                   2903:     my $rownum = 6;
                   2904:     if (ref($types) eq 'ARRAY') {
                   2905:         $rownum += scalar(@{$types});
                   2906:     }
1.171     raeburn  2907:     my @css_class = ('LC_odd_row','LC_even_row');
                   2908:     my $balnum = 0;
                   2909:     my $islast;
                   2910:     my (@toshow,$disabledtext);
                   2911:     if (keys(%currbalancer) > 0) {
                   2912:         @toshow = sort(keys(%currbalancer));
                   2913:         if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
                   2914:             push(@toshow,'');
                   2915:         }
                   2916:     } else {
                   2917:         @toshow = ('');
                   2918:         $disabledtext = &mt('No existing load balancer');
                   2919:     }
                   2920:     foreach my $lonhost (@toshow) {
                   2921:         if ($balnum == scalar(@toshow)-1) {
                   2922:             $islast = 1;
                   2923:         } else {
                   2924:             $islast = 0;
                   2925:         }
                   2926:         my $cssidx = $balnum%2;
                   2927:         my $targets_div_style = 'display: none';
                   2928:         my $disabled_div_style = 'display: block';
                   2929:         my $homedom_div_style = 'display: none';
                   2930:         $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
                   2931:                       '<td rowspan="'.$rownum.'" valign="top">'.
                   2932:                       '<p>';
                   2933:         if ($lonhost eq '') {
                   2934:             $datatable .= '<span class="LC_nobreak">'; 
                   2935:             if (keys(%currbalancer) > 0) {
                   2936:                 $datatable .= &mt('Add balancer:');
                   2937:             } else {
                   2938:                 $datatable .= &mt('Enable balancer:');
                   2939:             }
                   2940:             $datatable .= '&nbsp;'.
                   2941:                           '<select name="loadbalancing_lonhost_'.$balnum.'"'.
                   2942:                           ' id="loadbalancing_lonhost_'.$balnum.'"'.
                   2943:                           ' onchange="toggleTargets('."'$balnum'".');">'."\n".
                   2944:                           '<option value="" selected="selected">'.&mt('None').
                   2945:                           '</option>'."\n";
                   2946:             foreach my $server (sort(keys(%servers))) {
                   2947:                 next if ($currbalancer{$server});
                   2948:                 $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
                   2949:             }
                   2950:             $datatable .= 
                   2951:                 '</select>'."\n".
                   2952:                 '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" />&nbsp;</span>'."\n";
                   2953:         } else {
                   2954:             $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
                   2955:                           '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" />&nbsp;'.
                   2956:                            &mt('Stop balancing').'</label>'.
                   2957:                            '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
                   2958:             $targets_div_style = 'display: block';
                   2959:             $disabled_div_style = 'display: none';
                   2960:             if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
                   2961:                 $homedom_div_style = 'display: block';
                   2962:             }
                   2963:         }
                   2964:         $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
                   2965:                   '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
                   2966:                   $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
                   2967:                   '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
                   2968:         my ($numspares,@spares) = &count_servers($lonhost,%servers);
                   2969:         my @sparestypes = ('primary','default');
                   2970:         my %typetitles = &sparestype_titles();
                   2971:         foreach my $sparetype (@sparestypes) {
                   2972:             my $targettable;
                   2973:             for (my $i=0; $i<$numspares; $i++) {
                   2974:                 my $checked;
                   2975:                 if (ref($currtargets{$lonhost}) eq 'HASH') {
                   2976:                     if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
                   2977:                         if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
                   2978:                             $checked = ' checked="checked"';
                   2979:                         }
                   2980:                     }
                   2981:                 }
                   2982:                 my ($chkboxval,$disabled);
                   2983:                 if (($lonhost ne '') && (exists($servers{$lonhost}))) {
                   2984:                     $chkboxval = $spares[$i];
                   2985:                 }
                   2986:                 if (exists($currbalancer{$spares[$i]})) {
                   2987:                     $disabled = ' disabled="disabled"';
                   2988:                 }
                   2989:                 $targettable .= 
                   2990:                     '<td><label><input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
                   2991:                     $checked.$disabled.' value="'.$chkboxval.'" id="loadbalancing_target_'.$balnum.'_'.$sparetype.'_'.$i.'" onclick="checkOffloads('."this,'$balnum','$sparetype'".');" /><span id="loadbalancing_targettxt_'.$balnum.'_'.$sparetype.'_'.$i.'">&nbsp;'.$chkboxval.
                   2992:                     '</span></label></td>';
                   2993:                 my $rem = $i%($numinrow);
                   2994:                 if ($rem == 0) {
                   2995:                     if (($i > 0) && ($i < $numspares-1)) {
                   2996:                         $targettable .= '</tr>';
                   2997:                     }
                   2998:                     if ($i < $numspares-1) {
                   2999:                         $targettable .= '<tr>';
1.150     raeburn  3000:                     }
                   3001:                 }
                   3002:             }
1.171     raeburn  3003:             if ($targettable ne '') {
                   3004:                 my $rem = $numspares%($numinrow);
                   3005:                 my $colsleft = $numinrow - $rem;
                   3006:                 if ($colsleft > 1 ) {
                   3007:                     $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   3008:                                     '&nbsp;</td>';
                   3009:                 } elsif ($colsleft == 1) {
                   3010:                     $targettable .= '<td class="LC_left_item">&nbsp;</td>';
                   3011:                 }
                   3012:                 $datatable .=  '<i>'.$typetitles{$sparetype}.'</i><br />'.
                   3013:                                '<table><tr>'.$targettable.'</tr></table><br />';
                   3014:             }
                   3015:         }
                   3016:         my $cssidx = $balnum%2; 
                   3017:         $datatable .= '</div></td></tr>'.
                   3018:                       &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
                   3019:                                            $othertitle,$usertypes,$types,\%servers,
                   3020:                                            \%currbalancer,$lonhost,
                   3021:                                            $targets_div_style,$homedom_div_style,
                   3022:                                            $css_class[$cssidx],$balnum,$islast);
                   3023:         $$rowtotal += $rownum;
                   3024:         $balnum ++;
                   3025:     }
                   3026:     $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
                   3027:     return $datatable;
                   3028: }
                   3029: 
                   3030: sub get_loadbalancers_config {
                   3031:     my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
                   3032:     return unless ((ref($servers) eq 'HASH') &&
                   3033:                    (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
                   3034:                    (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
                   3035:     if (keys(%{$existing}) > 0) {
                   3036:         my $oldlonhost;
                   3037:         foreach my $key (sort(keys(%{$existing}))) {
                   3038:             if ($key eq 'lonhost') {
                   3039:                 $oldlonhost = $existing->{'lonhost'};
                   3040:                 $currbalancer->{$oldlonhost} = 1;
                   3041:             } elsif ($key eq 'targets') {
                   3042:                 if ($oldlonhost) {
                   3043:                     $currtargets->{$oldlonhost} = $existing->{'targets'};
                   3044:                 }
                   3045:             } elsif ($key eq 'rules') {
                   3046:                 if ($oldlonhost) {
                   3047:                     $currrules->{$oldlonhost} = $existing->{'rules'};
                   3048:                 }
                   3049:             } elsif (ref($existing->{$key}) eq 'HASH') {
                   3050:                 $currbalancer->{$key} = 1;
                   3051:                 $currtargets->{$key} = $existing->{$key}{'targets'};
                   3052:                 $currrules->{$key} = $existing->{$key}{'rules'};
1.150     raeburn  3053:             }
                   3054:         }
1.171     raeburn  3055:     } else {
                   3056:         my ($balancerref,$targetsref) =
                   3057:                 &Apache::lonnet::get_lonbalancer_config($servers);
                   3058:         if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
                   3059:             foreach my $server (sort(keys(%{$balancerref}))) {
                   3060:                 $currbalancer->{$server} = 1;
                   3061:                 $currtargets->{$server} = $targetsref->{$server};
1.150     raeburn  3062:             }
                   3063:         }
                   3064:     }
1.171     raeburn  3065:     return;
1.150     raeburn  3066: }
                   3067: 
                   3068: sub loadbalancing_rules {
                   3069:     my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171     raeburn  3070:         $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
                   3071:         $css_class,$balnum,$islast) = @_;
1.150     raeburn  3072:     my $output;
1.171     raeburn  3073:     my $num = 0;
1.150     raeburn  3074:     my ($alltypes,$othertypes,$titles) = 
                   3075:         &loadbalancing_titles($dom,$intdom,$usertypes,$types);
                   3076:     if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH'))  {
                   3077:         foreach my $type (@{$alltypes}) {
1.171     raeburn  3078:             $num ++;
1.150     raeburn  3079:             my $current;
                   3080:             if (ref($currrules) eq 'HASH') {
                   3081:                 $current = $currrules->{$type};
                   3082:             }
                   3083:             if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.171     raeburn  3084:                 if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150     raeburn  3085:                     $current = '';
                   3086:                 }
                   3087:             }
                   3088:             $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171     raeburn  3089:                                              $servers,$currbalancer,$lonhost,$dom,
                   3090:                                              $targets_div_style,$homedom_div_style,
                   3091:                                              $css_class,$balnum,$num,$islast);
1.150     raeburn  3092:         }
                   3093:     }
                   3094:     return $output;
                   3095: }
                   3096: 
                   3097: sub loadbalancing_titles {
                   3098:     my ($dom,$intdom,$usertypes,$types) = @_;
                   3099:     my %othertypes = (
                   3100:            '_LC_adv'         => &mt('Advanced users from [_1]',$dom),
                   3101:            '_LC_author'      => &mt('Users from [_1] with author role',$dom),
                   3102:            '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
                   3103:            '_LC_external'    => &mt('Users not from [_1]',$intdom),
                   3104:                      );
                   3105:     my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external');
                   3106:     if (ref($types) eq 'ARRAY') {
                   3107:         unshift(@alltypes,@{$types},'default');
                   3108:     }
                   3109:     my %titles;
                   3110:     foreach my $type (@alltypes) {
                   3111:         if ($type =~ /^_LC_/) {
                   3112:             $titles{$type} = $othertypes{$type};
                   3113:         } elsif ($type eq 'default') {
                   3114:             $titles{$type} = &mt('All users from [_1]',$dom);
                   3115:             if (ref($types) eq 'ARRAY') {
                   3116:                 if (@{$types} > 0) {
                   3117:                     $titles{$type} = &mt('Other users from [_1]',$dom);
                   3118:                 }
                   3119:             }
                   3120:         } elsif (ref($usertypes) eq 'HASH') {
                   3121:             $titles{$type} = $usertypes->{$type};
                   3122:         }
                   3123:     }
                   3124:     return (\@alltypes,\%othertypes,\%titles);
                   3125: }
                   3126: 
                   3127: sub loadbalance_rule_row {
1.171     raeburn  3128:     my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
                   3129:         $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.150     raeburn  3130:     my @rulenames = ('default','homeserver');
                   3131:     my %ruletitles = &offloadtype_text();
                   3132:     if ($type eq '_LC_external') {
                   3133:         push(@rulenames,'externalbalancer');
                   3134:     } else {
                   3135:         push(@rulenames,'specific');
                   3136:     }
1.161     raeburn  3137:     push(@rulenames,'none');
1.150     raeburn  3138:     my $style = $targets_div_style;
                   3139:     if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
                   3140:         $style = $homedom_div_style;
                   3141:     }
1.171     raeburn  3142:     my $space;
                   3143:     if ($islast && $num == 1) {
                   3144:         $space = '<div display="inline-block">&nbsp;</div>';
                   3145:     }
1.150     raeburn  3146:     my $output = 
1.171     raeburn  3147:         '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
                   3148:         '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
                   3149:         '<td valaign="top">'.$space.
                   3150:         '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150     raeburn  3151:     for (my $i=0; $i<@rulenames; $i++) {
                   3152:         my $rule = $rulenames[$i];
                   3153:         my ($checked,$extra);
                   3154:         if ($rulenames[$i] eq 'default') {
                   3155:             $rule = '';
                   3156:         }
                   3157:         if ($rulenames[$i] eq 'specific') {
                   3158:             if (ref($servers) eq 'HASH') {
                   3159:                 my $default;
                   3160:                 if (($current ne '') && (exists($servers->{$current}))) {
                   3161:                     $checked = ' checked="checked"';
                   3162:                 }
                   3163:                 unless ($checked) {
                   3164:                     $default = ' selected="selected"';
                   3165:                 }
1.171     raeburn  3166:                 $extra = 
                   3167:                     ':&nbsp;<select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
                   3168:                     '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
                   3169:                     '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
                   3170:                     '<option value=""'.$default.'></option>'."\n";
                   3171:                 foreach my $server (sort(keys(%{$servers}))) {
                   3172:                     if (ref($currbalancer) eq 'HASH') {
                   3173:                         next if (exists($currbalancer->{$server}));
                   3174:                     }
1.150     raeburn  3175:                     my $selected;
1.171     raeburn  3176:                     if ($server eq $current) {
1.150     raeburn  3177:                         $selected = ' selected="selected"';
                   3178:                     }
1.171     raeburn  3179:                     $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150     raeburn  3180:                 }
                   3181:                 $extra .= '</select>';
                   3182:             }
                   3183:         } elsif ($rule eq $current) {
                   3184:             $checked = ' checked="checked"';
                   3185:         }
                   3186:         $output .= '<span class="LC_nobreak"><label>'.
1.171     raeburn  3187:                    '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
                   3188:                    '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
                   3189:                    $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.150     raeburn  3190:                    ')"'.$checked.' />&nbsp;'.$ruletitles{$rulenames[$i]}.
                   3191:                    '</label>'.$extra.'</span><br />'."\n";
                   3192:     }
                   3193:     $output .= '</div></td></tr>'."\n";
                   3194:     return $output;
                   3195: }
                   3196: 
                   3197: sub offloadtype_text {
                   3198:     my %ruletitles = &Apache::lonlocal::texthash (
                   3199:            'default'          => 'Offloads to default destinations',
                   3200:            'homeserver'       => "Offloads to user's home server",
                   3201:            'externalbalancer' => "Offloads to Load Balancer in user's domain",
                   3202:            'specific'         => 'Offloads to specific server',
1.161     raeburn  3203:            'none'             => 'No offload',
1.150     raeburn  3204:     );
                   3205:     return %ruletitles;
                   3206: }
                   3207: 
                   3208: sub sparestype_titles {
                   3209:     my %typestitles = &Apache::lonlocal::texthash (
                   3210:                           'primary' => 'primary',
                   3211:                           'default' => 'default',
                   3212:                       );
                   3213:     return %typestitles;
                   3214: }
                   3215: 
1.28      raeburn  3216: sub contact_titles {
                   3217:     my %titles = &Apache::lonlocal::texthash (
                   3218:                    'supportemail' => 'Support E-mail address',
1.69      raeburn  3219:                    'adminemail'   => 'Default Server Admin E-mail address',
1.28      raeburn  3220:                    'errormail'    => 'Error reports to be e-mailed to',
                   3221:                    'packagesmail' => 'Package update alerts to be e-mailed to',
1.89      raeburn  3222:                    'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
                   3223:                    'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
1.102     raeburn  3224:                    'requestsmail' => 'E-mail from course requests requiring approval',
1.28      raeburn  3225:                  );
                   3226:     my %short_titles = &Apache::lonlocal::texthash (
                   3227:                            adminemail   => 'Admin E-mail address',
                   3228:                            supportemail => 'Support E-mail',
                   3229:                        );   
                   3230:     return (\%titles,\%short_titles);
                   3231: }
                   3232: 
1.72      raeburn  3233: sub tool_titles {
                   3234:     my %titles = &Apache::lonlocal::texthash (
1.162     raeburn  3235:                      aboutme    => 'Personal web page',
1.86      raeburn  3236:                      blog       => 'Blog',
1.162     raeburn  3237:                      webdav     => 'WebDAV',
1.86      raeburn  3238:                      portfolio  => 'Portfolio',
1.88      bisitz   3239:                      official   => 'Official courses (with institutional codes)',
                   3240:                      unofficial => 'Unofficial courses',
1.98      raeburn  3241:                      community  => 'Communities',
1.86      raeburn  3242:                  );
1.72      raeburn  3243:     return %titles;
                   3244: }
                   3245: 
1.101     raeburn  3246: sub courserequest_titles {
                   3247:     my %titles = &Apache::lonlocal::texthash (
                   3248:                                    official   => 'Official',
                   3249:                                    unofficial => 'Unofficial',
                   3250:                                    community  => 'Communities',
                   3251:                                    norequest  => 'Not allowed',
1.104     raeburn  3252:                                    approval   => 'Approval by Dom. Coord.',
1.101     raeburn  3253:                                    validate   => 'With validation',
                   3254:                                    autolimit  => 'Numerical limit',
1.103     raeburn  3255:                                    unlimited  => '(blank for unlimited)',
1.101     raeburn  3256:                  );
                   3257:     return %titles;
                   3258: }
                   3259: 
1.163     raeburn  3260: sub authorrequest_titles {
                   3261:     my %titles = &Apache::lonlocal::texthash (
                   3262:                                    norequest  => 'Not allowed',
                   3263:                                    approval   => 'Approval by Dom. Coord.',
                   3264:                                    automatic  => 'Automatic approval',
                   3265:                  );
                   3266:     return %titles;
                   3267: } 
                   3268: 
1.101     raeburn  3269: sub courserequest_conditions {
                   3270:     my %conditions = &Apache::lonlocal::texthash (
1.104     raeburn  3271:        approval    => '(Processing of request subject to approval by Domain Coordinator).',
1.101     raeburn  3272:        validate   => '(Processing of request subject to instittutional validation).',
                   3273:                  );
                   3274:     return %conditions;
                   3275: }
                   3276: 
                   3277: 
1.27      raeburn  3278: sub print_usercreation {
1.30      raeburn  3279:     my ($position,$dom,$settings,$rowtotal) = @_;
1.27      raeburn  3280:     my $numinrow = 4;
1.28      raeburn  3281:     my $datatable;
                   3282:     if ($position eq 'top') {
1.30      raeburn  3283:         $$rowtotal ++;
1.34      raeburn  3284:         my $rowcount = 0;
1.32      raeburn  3285:         my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28      raeburn  3286:         if (ref($rules) eq 'HASH') {
                   3287:             if (keys(%{$rules}) > 0) {
1.32      raeburn  3288:                 $datatable .= &user_formats_row('username',$settings,$rules,
                   3289:                                                 $ruleorder,$numinrow,$rowcount);
1.30      raeburn  3290:                 $$rowtotal ++;
1.32      raeburn  3291:                 $rowcount ++;
                   3292:             }
                   3293:         }
                   3294:         my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
                   3295:         if (ref($idrules) eq 'HASH') {
                   3296:             if (keys(%{$idrules}) > 0) {
                   3297:                 $datatable .= &user_formats_row('id',$settings,$idrules,
                   3298:                                                 $idruleorder,$numinrow,$rowcount);
                   3299:                 $$rowtotal ++;
                   3300:                 $rowcount ++;
1.28      raeburn  3301:             }
                   3302:         }
1.43      raeburn  3303:         my ($emailrules,$emailruleorder) = 
                   3304:             &Apache::lonnet::inst_userrules($dom,'email');
                   3305:         if (ref($emailrules) eq 'HASH') {
                   3306:             if (keys(%{$emailrules}) > 0) {
                   3307:                 $datatable .= &user_formats_row('email',$settings,$emailrules,
                   3308:                                                 $emailruleorder,$numinrow,$rowcount);
                   3309:                 $$rowtotal ++;
                   3310:                 $rowcount ++;
                   3311:             }
                   3312:         }
1.39      raeburn  3313:         if ($rowcount == 0) {
                   3314:             $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';  
                   3315:             $$rowtotal ++;
                   3316:             $rowcount ++;
                   3317:         }
1.34      raeburn  3318:     } elsif ($position eq 'middle') {
1.100     raeburn  3319:         my @creators = ('author','course','requestcrs','selfcreate');
1.37      raeburn  3320:         my ($rules,$ruleorder) =
                   3321:             &Apache::lonnet::inst_userrules($dom,'username');
1.34      raeburn  3322:         my %lt = &usercreation_types();
                   3323:         my %checked;
1.50      raeburn  3324:         my @selfcreate; 
1.34      raeburn  3325:         if (ref($settings) eq 'HASH') {
                   3326:             if (ref($settings->{'cancreate'}) eq 'HASH') {
                   3327:                 foreach my $item (@creators) {
                   3328:                     $checked{$item} = $settings->{'cancreate'}{$item};
                   3329:                 }
1.50      raeburn  3330:                 if (ref($settings->{'cancreate'}{'selfcreate'}) eq 'ARRAY') {
                   3331:                     @selfcreate = @{$settings->{'cancreate'}{'selfcreate'}};
                   3332:                 } elsif ($settings->{'cancreate'}{'selfcreate'} ne '') {
                   3333:                     if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
                   3334:                         @selfcreate = ('email','login','sso');
                   3335:                     } elsif ($settings->{'cancreate'}{'selfcreate'} ne 'none') {
                   3336:                         @selfcreate = ($settings->{'cancreate'}{'selfcreate'});
                   3337:                     }
                   3338:                 }
1.34      raeburn  3339:             } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
                   3340:                 foreach my $item (@creators) {
                   3341:                     if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
                   3342:                         $checked{$item} = 'none';
                   3343:                     }
                   3344:                 }
                   3345:             }
                   3346:         }
                   3347:         my $rownum = 0;
                   3348:         foreach my $item (@creators) {
                   3349:             $rownum ++;
1.50      raeburn  3350:             if ($item ne 'selfcreate') {  
                   3351:                 if ($checked{$item} eq '') {
1.43      raeburn  3352:                     $checked{$item} = 'any';
                   3353:                 }
1.34      raeburn  3354:             }
                   3355:             my $css_class;
                   3356:             if ($rownum%2) {
                   3357:                 $css_class = '';
                   3358:             } else {
                   3359:                 $css_class = ' class="LC_odd_row" ';
                   3360:             }
                   3361:             $datatable .= '<tr'.$css_class.'>'.
                   3362:                          '<td><span class="LC_nobreak">'.$lt{$item}.
                   3363:                          '</span></td><td align="right">';
1.50      raeburn  3364:             my @options;
1.45      raeburn  3365:             if ($item eq 'selfcreate') {
1.43      raeburn  3366:                 push(@options,('email','login','sso'));
                   3367:             } else {
1.50      raeburn  3368:                 @options = ('any');
1.43      raeburn  3369:                 if (ref($rules) eq 'HASH') {
                   3370:                     if (keys(%{$rules}) > 0) {
                   3371:                         push(@options,('official','unofficial'));
                   3372:                     }
1.37      raeburn  3373:                 }
1.50      raeburn  3374:                 push(@options,'none');
1.37      raeburn  3375:             }
                   3376:             foreach my $option (@options) {
1.50      raeburn  3377:                 my $type = 'radio';
1.34      raeburn  3378:                 my $check = ' ';
1.50      raeburn  3379:                 if ($item eq 'selfcreate') {
                   3380:                     $type = 'checkbox';
                   3381:                     if (grep(/^\Q$option\E$/,@selfcreate)) {
                   3382:                         $check = ' checked="checked" ';
                   3383:                     }
                   3384:                 } else {
                   3385:                     if ($checked{$item} eq $option) {
                   3386:                         $check = ' checked="checked" ';
                   3387:                     }
1.34      raeburn  3388:                 } 
                   3389:                 $datatable .= '<span class="LC_nobreak"><label>'.
1.50      raeburn  3390:                               '<input type="'.$type.'" name="can_createuser_'.
1.34      raeburn  3391:                               $item.'" value="'.$option.'"'.$check.'/>&nbsp;'.
                   3392:                               $lt{$option}.'</label>&nbsp;&nbsp;</span>';
                   3393:             }
                   3394:             $datatable .= '</td></tr>';
                   3395:         }
1.93      raeburn  3396:         my ($othertitle,$usertypes,$types) =
                   3397:             &Apache::loncommon::sorted_inst_types($dom);
1.165     raeburn  3398:         my $createsettings;
                   3399:         if (ref($settings) eq 'HASH') {
                   3400:             $createsettings = $settings->{cancreate};
                   3401:         }
1.93      raeburn  3402:         if (ref($usertypes) eq 'HASH') {
                   3403:             if (keys(%{$usertypes}) > 0) {
1.99      raeburn  3404:                 $datatable .= &insttypes_row($createsettings,$types,$usertypes,
1.93      raeburn  3405:                                              $dom,$numinrow,$othertitle,
                   3406:                                              'statustocreate');
                   3407:                 $$rowtotal ++;
1.169     raeburn  3408:                 $rownum ++;
1.93      raeburn  3409:             }
                   3410:         }
1.169     raeburn  3411:         $datatable .= &captcha_choice('cancreate',$createsettings,$rownum);
1.28      raeburn  3412:     } else {
                   3413:         my @contexts = ('author','course','domain');
                   3414:         my @authtypes = ('int','krb4','krb5','loc');
                   3415:         my %checked;
                   3416:         if (ref($settings) eq 'HASH') {
                   3417:             if (ref($settings->{'authtypes'}) eq 'HASH') {
                   3418:                 foreach my $item (@contexts) {
                   3419:                     if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
                   3420:                         foreach my $auth (@authtypes) {
                   3421:                             if ($settings->{'authtypes'}{$item}{$auth}) {
                   3422:                                 $checked{$item}{$auth} = ' checked="checked" ';
                   3423:                             }
                   3424:                         }
                   3425:                     }
                   3426:                 }
1.27      raeburn  3427:             }
1.35      raeburn  3428:         } else {
                   3429:             foreach my $item (@contexts) {
1.36      raeburn  3430:                 foreach my $auth (@authtypes) {
1.35      raeburn  3431:                     $checked{$item}{$auth} = ' checked="checked" ';
                   3432:                 }
                   3433:             }
1.27      raeburn  3434:         }
1.28      raeburn  3435:         my %title = &context_names();
                   3436:         my %authname = &authtype_names();
                   3437:         my $rownum = 0;
                   3438:         my $css_class; 
                   3439:         foreach my $item (@contexts) {
                   3440:             if ($rownum%2) {
                   3441:                 $css_class = '';
                   3442:             } else {
                   3443:                 $css_class = ' class="LC_odd_row" ';
                   3444:             }
1.30      raeburn  3445:             $datatable .=   '<tr'.$css_class.'>'.
1.28      raeburn  3446:                             '<td>'.$title{$item}.
                   3447:                             '</td><td class="LC_left_item">'.
                   3448:                             '<span class="LC_nobreak">';
                   3449:             foreach my $auth (@authtypes) {
                   3450:                 $datatable .= '<label>'. 
                   3451:                               '<input type="checkbox" name="'.$item.'_auth" '.
                   3452:                               $checked{$item}{$auth}.' value="'.$auth.'" />'.
                   3453:                               $authname{$auth}.'</label>&nbsp;';
                   3454:             }
                   3455:             $datatable .= '</span></td></tr>';
                   3456:             $rownum ++;
1.27      raeburn  3457:         }
1.30      raeburn  3458:         $$rowtotal += $rownum;
1.27      raeburn  3459:     }
                   3460:     return $datatable;
                   3461: }
                   3462: 
1.165     raeburn  3463: sub captcha_choice {
1.169     raeburn  3464:     my ($context,$settings,$itemcount) = @_;
1.165     raeburn  3465:     my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext);
                   3466:     my %lt = &captcha_phrases();
                   3467:     $keyentry = 'hidden';
                   3468:     if ($context eq 'cancreate') {
                   3469:         $rowname = &mt('CAPTCHA validation (e-mail as username)');
1.169     raeburn  3470:     } elsif ($context eq 'login') {
                   3471:         $rowname =  &mt('"Contact helpdesk" CAPTCHA validation');
1.165     raeburn  3472:     }
                   3473:     if (ref($settings) eq 'HASH') {
                   3474:         if ($settings->{'captcha'}) {
                   3475:             $checked{$settings->{'captcha'}} = ' checked="checked"';
                   3476:         } else {
                   3477:             $checked{'original'} = ' checked="checked"';
                   3478:         }
                   3479:         if ($settings->{'captcha'} eq 'recaptcha') {
                   3480:             $pubtext = $lt{'pub'};
                   3481:             $privtext = $lt{'priv'};
                   3482:             $keyentry = 'text';
                   3483:         }
                   3484:         if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
                   3485:             $currpub = $settings->{'recaptchakeys'}{'public'};
                   3486:             $currpriv = $settings->{'recaptchakeys'}{'private'};
                   3487:         }
                   3488:     } else {
                   3489:         $checked{'original'} = ' checked="checked"';
                   3490:     }
1.169     raeburn  3491:     my $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   3492:     my $output = '<tr'.$css_class.'>'.
                   3493:                  '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
1.165     raeburn  3494:                  '<table><tr><td>'."\n";
                   3495:     foreach my $option ('original','recaptcha','notused') {
                   3496:         $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
                   3497:                    $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
                   3498:                    $lt{$option}.'</label></span>';
                   3499:         unless ($option eq 'notused') {
                   3500:             $output .= ('&nbsp;'x2)."\n";
                   3501:         }
                   3502:     }
                   3503: #
                   3504: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
                   3505: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
                   3506: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu) 
                   3507: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
                   3508: #  
                   3509:     $output .= '</td></tr>'."\n".
                   3510:                '<tr><td>'."\n".
                   3511:                '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span>&nbsp;'."\n".
                   3512:                '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
                   3513:                $currpub.'" size="40" /></span><br />'."\n".
                   3514:                '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span>&nbsp;'."\n".
                   3515:                '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
                   3516:                $currpriv.'" size="40" /></span></td></tr></table>'."\n".
                   3517:                '</td></tr>';
                   3518:     return $output;
                   3519: }
                   3520: 
1.32      raeburn  3521: sub user_formats_row {
                   3522:     my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
                   3523:     my $output;
                   3524:     my %text = (
                   3525:                    'username' => 'new usernames',
                   3526:                    'id'       => 'IDs',
1.45      raeburn  3527:                    'email'    => 'self-created accounts (e-mail)',
1.32      raeburn  3528:                );
                   3529:     my $css_class = $rowcount%2?' class="LC_odd_row"':'';
                   3530:     $output = '<tr '.$css_class.'>'.
1.63      raeburn  3531:               '<td><span class="LC_nobreak">';
                   3532:     if ($type eq 'email') {
                   3533:         $output .= &mt("Formats disallowed for $text{$type}: ");
                   3534:     } else {
                   3535:         $output .= &mt("Format rules to check for $text{$type}: ");
                   3536:     }
                   3537:     $output .= '</span></td>'.
                   3538:                '<td class="LC_left_item" colspan="2"><table>';
1.27      raeburn  3539:     my $rem;
                   3540:     if (ref($ruleorder) eq 'ARRAY') {
                   3541:         for (my $i=0; $i<@{$ruleorder}; $i++) {
                   3542:             if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
                   3543:                 my $rem = $i%($numinrow);
                   3544:                 if ($rem == 0) {
                   3545:                     if ($i > 0) {
                   3546:                         $output .= '</tr>';
                   3547:                     }
                   3548:                     $output .= '<tr>';
                   3549:                 }
                   3550:                 my $check = ' ';
1.39      raeburn  3551:                 if (ref($settings) eq 'HASH') {
                   3552:                     if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
                   3553:                         if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
                   3554:                             $check = ' checked="checked" ';
                   3555:                         }
1.27      raeburn  3556:                     }
                   3557:                 }
                   3558:                 $output .= '<td class="LC_left_item">'.
                   3559:                            '<span class="LC_nobreak"><label>'.
1.32      raeburn  3560:                            '<input type="checkbox" name="'.$type.'_rule" '.
1.27      raeburn  3561:                            'value="'.$ruleorder->[$i].'"'.$check.'/>'.
                   3562:                            $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
                   3563:             }
                   3564:         }
                   3565:         $rem = @{$ruleorder}%($numinrow);
                   3566:     }
                   3567:     my $colsleft = $numinrow - $rem;
                   3568:     if ($colsleft > 1 ) {
                   3569:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   3570:                    '&nbsp;</td>';
                   3571:     } elsif ($colsleft == 1) {
                   3572:         $output .= '<td class="LC_left_item">&nbsp;</td>';
                   3573:     }
                   3574:     $output .= '</tr></table></td></tr>';
                   3575:     return $output;
                   3576: }
                   3577: 
1.34      raeburn  3578: sub usercreation_types {
                   3579:     my %lt = &Apache::lonlocal::texthash (
                   3580:                     author     => 'When adding a co-author',
                   3581:                     course     => 'When adding a user to a course',
1.100     raeburn  3582:                     requestcrs => 'When requesting a course',
1.45      raeburn  3583:                     selfcreate => 'User creates own account', 
1.34      raeburn  3584:                     any        => 'Any',
                   3585:                     official   => 'Institutional only ',
                   3586:                     unofficial => 'Non-institutional only',
1.85      schafran 3587:                     email      => 'E-mail address',
1.43      raeburn  3588:                     login      => 'Institutional Login',
                   3589:                     sso        => 'SSO', 
1.34      raeburn  3590:                     none       => 'None',
                   3591:     );
                   3592:     return %lt;
1.48      raeburn  3593: }
1.34      raeburn  3594: 
1.28      raeburn  3595: sub authtype_names {
                   3596:     my %lt = &Apache::lonlocal::texthash(
                   3597:                       int    => 'Internal',
                   3598:                       krb4   => 'Kerberos 4',
                   3599:                       krb5   => 'Kerberos 5',
                   3600:                       loc    => 'Local',
                   3601:                   );
                   3602:     return %lt;
                   3603: }
                   3604: 
                   3605: sub context_names {
                   3606:     my %context_title = &Apache::lonlocal::texthash(
                   3607:        author => 'Creating users when an Author',
                   3608:        course => 'Creating users when in a course',
                   3609:        domain => 'Creating users when a Domain Coordinator',
                   3610:     );
                   3611:     return %context_title;
                   3612: }
                   3613: 
1.33      raeburn  3614: sub print_usermodification {
                   3615:     my ($position,$dom,$settings,$rowtotal) = @_;
                   3616:     my $numinrow = 4;
                   3617:     my ($context,$datatable,$rowcount);
                   3618:     if ($position eq 'top') {
                   3619:         $rowcount = 0;
                   3620:         $context = 'author'; 
                   3621:         foreach my $role ('ca','aa') {
                   3622:             $datatable .= &modifiable_userdata_row($context,$role,$settings,
                   3623:                                                    $numinrow,$rowcount);
                   3624:             $$rowtotal ++;
                   3625:             $rowcount ++;
                   3626:         }
1.63      raeburn  3627:     } elsif ($position eq 'middle') {
1.33      raeburn  3628:         $context = 'course';
                   3629:         $rowcount = 0;
                   3630:         foreach my $role ('st','ep','ta','in','cr') {
                   3631:             $datatable .= &modifiable_userdata_row($context,$role,$settings,
                   3632:                                                    $numinrow,$rowcount);
                   3633:             $$rowtotal ++;
                   3634:             $rowcount ++;
                   3635:         }
1.63      raeburn  3636:     } elsif ($position eq 'bottom') {
                   3637:         $context = 'selfcreate';
                   3638:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   3639:         $usertypes->{'default'} = $othertitle;
                   3640:         if (ref($types) eq 'ARRAY') {
                   3641:             push(@{$types},'default');
                   3642:             $usertypes->{'default'} = $othertitle;
                   3643:             foreach my $status (@{$types}) {
                   3644:                 $datatable .= &modifiable_userdata_row($context,$status,$settings,
                   3645:                                                        $numinrow,$rowcount,$usertypes);
                   3646:                 $$rowtotal ++;
                   3647:                 $rowcount ++;
                   3648:             }
                   3649:         }
1.33      raeburn  3650:     }
                   3651:     return $datatable;
                   3652: }
                   3653: 
1.43      raeburn  3654: sub print_defaults {
                   3655:     my ($dom,$rowtotal) = @_;
1.68      raeburn  3656:     my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
1.141     raeburn  3657:                  'datelocale_def','portal_def');
1.43      raeburn  3658:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.141     raeburn  3659:     my $titles = &defaults_titles($dom);
1.43      raeburn  3660:     my $rownum = 0;
                   3661:     my ($datatable,$css_class);
                   3662:     foreach my $item (@items) {
                   3663:         if ($rownum%2) {
                   3664:             $css_class = '';
                   3665:         } else {
                   3666:             $css_class = ' class="LC_odd_row" ';
                   3667:         }
                   3668:         $datatable .= '<tr'.$css_class.'>'.
                   3669:                   '<td><span class="LC_nobreak">'.$titles->{$item}.
                   3670:                   '</span></td><td class="LC_right_item">';
                   3671:         if ($item eq 'auth_def') {
                   3672:             my @authtypes = ('internal','krb4','krb5','localauth');
                   3673:             my %shortauth = (
                   3674:                              internal => 'int',
                   3675:                              krb4 => 'krb4',
                   3676:                              krb5 => 'krb5',
                   3677:                              localauth  => 'loc'
                   3678:                            );
                   3679:             my %authnames = &authtype_names();
                   3680:             foreach my $auth (@authtypes) {
                   3681:                 my $checked = ' ';
                   3682:                 if ($domdefaults{$item} eq $auth) {
                   3683:                     $checked = ' checked="checked" ';
                   3684:                 }
                   3685:                 $datatable .= '<label><input type="radio" name="'.$item.
                   3686:                               '" value="'.$auth.'"'.$checked.'/>'.
                   3687:                               $authnames{$shortauth{$auth}}.'</label>&nbsp;&nbsp;';
                   3688:             }
1.54      raeburn  3689:         } elsif ($item eq 'timezone_def') {
                   3690:             my $includeempty = 1;
                   3691:             $datatable .= &Apache::loncommon::select_timezone($item,$domdefaults{$item},undef,$includeempty);
1.68      raeburn  3692:         } elsif ($item eq 'datelocale_def') {
                   3693:             my $includeempty = 1;
                   3694:             $datatable .= &Apache::loncommon::select_datelocale($item,$domdefaults{$item},undef,$includeempty);
1.167     raeburn  3695:         } elsif ($item eq 'lang_def') {
1.168     raeburn  3696:             my %langchoices = &get_languages_hash();
                   3697:             $langchoices{''} = 'No language preference';
1.167     raeburn  3698:             %langchoices = &Apache::lonlocal::texthash(%langchoices);
                   3699:             $datatable .= &Apache::loncommon::select_form($domdefaults{$item},$item,
                   3700:                                                           \%langchoices);
1.43      raeburn  3701:         } else {
1.141     raeburn  3702:             my $size;
                   3703:             if ($item eq 'portal_def') {
                   3704:                 $size = ' size="25"';
                   3705:             }
1.43      raeburn  3706:             $datatable .= '<input type="text" name="'.$item.'" value="'.
1.141     raeburn  3707:                           $domdefaults{$item}.'"'.$size.' />';
1.43      raeburn  3708:         }
                   3709:         $datatable .= '</td></tr>';
                   3710:         $rownum ++;
                   3711:     }
                   3712:     $$rowtotal += $rownum;
                   3713:     return $datatable;
                   3714: }
                   3715: 
1.168     raeburn  3716: sub get_languages_hash {
                   3717:     my %langchoices;
                   3718:     foreach my $id (&Apache::loncommon::languageids()) {
                   3719:         my $code = &Apache::loncommon::supportedlanguagecode($id);
                   3720:         if ($code ne '') {
                   3721:             $langchoices{$code} =  &Apache::loncommon::plainlanguagedescription($id);
                   3722:         }
                   3723:     }
                   3724:     return %langchoices;
                   3725: }
                   3726: 
1.43      raeburn  3727: sub defaults_titles {
1.141     raeburn  3728:     my ($dom) = @_;
1.43      raeburn  3729:     my %titles = &Apache::lonlocal::texthash (
                   3730:                    'auth_def'      => 'Default authentication type',
                   3731:                    'auth_arg_def'  => 'Default authentication argument',
                   3732:                    'lang_def'      => 'Default language',
1.54      raeburn  3733:                    'timezone_def'  => 'Default timezone',
1.68      raeburn  3734:                    'datelocale_def' => 'Default locale for dates',
1.141     raeburn  3735:                    'portal_def'     => 'Portal/Default URL',
1.43      raeburn  3736:                  );
1.141     raeburn  3737:     if ($dom) {
                   3738:         my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
                   3739:         my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
                   3740:         my $protocol = $Apache::lonnet::protocol{$uprimary_id};
                   3741:         $protocol = 'http' if ($protocol ne 'https');
                   3742:         if ($uint_dom) {
                   3743:             $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
                   3744:                                          $uint_dom);
                   3745:         }
                   3746:     }
1.43      raeburn  3747:     return (\%titles);
                   3748: }
                   3749: 
1.46      raeburn  3750: sub print_scantronformat {
                   3751:     my ($r,$dom,$confname,$settings,$rowtotal) = @_;
                   3752:     my $itemcount = 1;
1.60      raeburn  3753:     my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
                   3754:         %confhash);
1.46      raeburn  3755:     my $switchserver = &check_switchserver($dom,$confname);
                   3756:     my %lt = &Apache::lonlocal::texthash (
1.95      www      3757:                 default => 'Default bubblesheet format file error',
                   3758:                 custom  => 'Custom bubblesheet format file error',
1.46      raeburn  3759:              );
                   3760:     my %scantronfiles = (
                   3761:         default => 'default.tab',
                   3762:         custom => 'custom.tab',
                   3763:     );
                   3764:     foreach my $key (keys(%scantronfiles)) {
                   3765:         $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
                   3766:                               .$scantronfiles{$key};
                   3767:     }
                   3768:     my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
                   3769:     if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
                   3770:         if (!$switchserver) {
                   3771:             my $servadm = $r->dir_config('lonAdmEMail');
                   3772:             my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
                   3773:             if ($configuserok eq 'ok') {
                   3774:                 if ($author_ok eq 'ok') {
                   3775:                     my %legacyfile = (
                   3776:  default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab', 
                   3777:  custom  => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab', 
                   3778:                     );
                   3779:                     my %md5chk;
                   3780:                     foreach my $type (keys(%legacyfile)) {
1.60      raeburn  3781:                         ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
                   3782:                         chomp($md5chk{$type});
1.46      raeburn  3783:                     }
                   3784:                     if ($md5chk{'default'} ne $md5chk{'custom'}) {
                   3785:                         foreach my $type (keys(%legacyfile)) {
1.60      raeburn  3786:                             ($scantronurls{$type},my $error) = 
1.46      raeburn  3787:                                 &legacy_scantronformat($r,$dom,$confname,
                   3788:                                                  $type,$legacyfile{$type},
                   3789:                                                  $scantronurls{$type},
                   3790:                                                  $scantronfiles{$type});
1.60      raeburn  3791:                             if ($error ne '') {
                   3792:                                 $error{$type} = $error;
                   3793:                             }
                   3794:                         }
                   3795:                         if (keys(%error) == 0) {
                   3796:                             $is_custom = 1;
                   3797:                             $confhash{'scantron'}{'scantronformat'} = 
                   3798:                                 $scantronurls{'custom'};
                   3799:                             my $putresult = 
                   3800:                                 &Apache::lonnet::put_dom('configuration',
                   3801:                                                          \%confhash,$dom);
                   3802:                             if ($putresult ne 'ok') {
                   3803:                                 $error{'custom'} = 
                   3804:                                     '<span class="LC_error">'.
                   3805:                                     &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
                   3806:                             }
1.46      raeburn  3807:                         }
                   3808:                     } else {
1.60      raeburn  3809:                         ($scantronurls{'default'},my $error) =
1.46      raeburn  3810:                             &legacy_scantronformat($r,$dom,$confname,
                   3811:                                           'default',$legacyfile{'default'},
                   3812:                                           $scantronurls{'default'},
                   3813:                                           $scantronfiles{'default'});
1.60      raeburn  3814:                         if ($error eq '') {
                   3815:                             $confhash{'scantron'}{'scantronformat'} = ''; 
                   3816:                             my $putresult =
                   3817:                                 &Apache::lonnet::put_dom('configuration',
                   3818:                                                          \%confhash,$dom);
                   3819:                             if ($putresult ne 'ok') {
                   3820:                                 $error{'default'} =
                   3821:                                     '<span class="LC_error">'.
                   3822:                                     &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
                   3823:                             }
                   3824:                         } else {
                   3825:                             $error{'default'} = $error;
                   3826:                         }
1.46      raeburn  3827:                     }
                   3828:                 }
                   3829:             }
                   3830:         } else {
1.95      www      3831:             $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46      raeburn  3832:         }
                   3833:     }
                   3834:     if (ref($settings) eq 'HASH') {
                   3835:         if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
                   3836:             my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
                   3837:             if ((!@info) || ($info[0] eq 'no_such_dir')) {
                   3838:                 $scantronurl = '';
                   3839:             } else {
                   3840:                 $scantronurl = $settings->{'scantronformat'};
                   3841:             }
                   3842:             $is_custom = 1;
                   3843:         } else {
                   3844:             $scantronurl = $scantronurls{'default'};
                   3845:         }
                   3846:     } else {
1.60      raeburn  3847:         if ($is_custom) {
                   3848:             $scantronurl = $scantronurls{'custom'};
                   3849:         } else {
                   3850:             $scantronurl = $scantronurls{'default'};
                   3851:         }
1.46      raeburn  3852:     }
                   3853:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   3854:     $datatable .= '<tr'.$css_class.'>';
                   3855:     if (!$is_custom) {
1.65      raeburn  3856:         $datatable .= '<td>'.&mt('Default in use:').'<br />'.
                   3857:                       '<span class="LC_nobreak">';
1.46      raeburn  3858:         if ($scantronurl) {
                   3859:             $datatable .= '<a href="'.$scantronurl.'" target="_blank">'.
1.130     raeburn  3860:                           &mt('Default bubblesheet format file').'</a>';
1.46      raeburn  3861:         } else {
                   3862:             $datatable = &mt('File unavailable for display');
                   3863:         }
1.65      raeburn  3864:         $datatable .= '</span></td>';
1.60      raeburn  3865:         if (keys(%error) == 0) { 
                   3866:             $datatable .= '<td valign="bottom">';
                   3867:             if (!$switchserver) {
                   3868:                 $datatable .= &mt('Upload:').'<br />';
                   3869:             }
                   3870:         } else {
                   3871:             my $errorstr;
                   3872:             foreach my $key (sort(keys(%error))) {
                   3873:                 $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
                   3874:             }
                   3875:             $datatable .= '<td>'.$errorstr;
                   3876:         }
1.46      raeburn  3877:     } else {
                   3878:         if (keys(%error) > 0) {
                   3879:             my $errorstr;
                   3880:             foreach my $key (sort(keys(%error))) {
                   3881:                 $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
                   3882:             } 
1.60      raeburn  3883:             $datatable .= '<td>'.$errorstr.'</td><td>&nbsp;';
1.46      raeburn  3884:         } elsif ($scantronurl) {
1.65      raeburn  3885:             $datatable .= '<td><span class="LC_nobreak">'.
                   3886:                           '<a href="'.$scantronurl.'" target="_blank">'.
1.130     raeburn  3887:                           &mt('Custom bubblesheet format file').'</a><label>'.
1.65      raeburn  3888:                           '<input type="checkbox" name="scantronformat_del"'.
                   3889:                           '" value="1" />'.&mt('Delete?').'</label></span></td>'.
                   3890:                           '<td><span class="LC_nobreak">&nbsp;'.
                   3891:                           &mt('Replace:').'</span><br />';
1.46      raeburn  3892:         }
                   3893:     }
                   3894:     if (keys(%error) == 0) {
                   3895:         if ($switchserver) {
                   3896:             $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   3897:         } else {
1.65      raeburn  3898:             $datatable .='<span class="LC_nobreak">&nbsp;'.
                   3899:                          '<input type="file" name="scantronformat" /></span>';
1.46      raeburn  3900:         }
                   3901:     }
                   3902:     $datatable .= '</td></tr>';
                   3903:     $$rowtotal ++;
                   3904:     return $datatable;
                   3905: }
                   3906: 
                   3907: sub legacy_scantronformat {
                   3908:     my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
                   3909:     my ($url,$error);
                   3910:     my @statinfo = &Apache::lonnet::stat_file($newurl);
                   3911:     if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
                   3912:         (my $result,$url) =
                   3913:             &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
                   3914:                          '','',$newfile);
                   3915:         if ($result ne 'ok') {
1.130     raeburn  3916:             $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46      raeburn  3917:         }
                   3918:     }
                   3919:     return ($url,$error);
                   3920: }
1.43      raeburn  3921: 
1.49      raeburn  3922: sub print_coursecategories {
1.57      raeburn  3923:     my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
                   3924:     my $datatable;
                   3925:     if ($position eq 'top') {
                   3926:         my $toggle_cats_crs = ' ';
                   3927:         my $toggle_cats_dom = ' checked="checked" ';
                   3928:         my $can_cat_crs = ' ';
                   3929:         my $can_cat_dom = ' checked="checked" ';
1.120     raeburn  3930:         my $toggle_catscomm_comm = ' ';
                   3931:         my $toggle_catscomm_dom = ' checked="checked" ';
                   3932:         my $can_catcomm_comm = ' ';
                   3933:         my $can_catcomm_dom = ' checked="checked" ';
                   3934: 
1.57      raeburn  3935:         if (ref($settings) eq 'HASH') {
                   3936:             if ($settings->{'togglecats'} eq 'crs') {
                   3937:                 $toggle_cats_crs = $toggle_cats_dom;
                   3938:                 $toggle_cats_dom = ' ';
                   3939:             }
                   3940:             if ($settings->{'categorize'} eq 'crs') {
                   3941:                 $can_cat_crs = $can_cat_dom;
                   3942:                 $can_cat_dom = ' ';
                   3943:             }
1.120     raeburn  3944:             if ($settings->{'togglecatscomm'} eq 'comm') {
                   3945:                 $toggle_catscomm_comm = $toggle_catscomm_dom;
                   3946:                 $toggle_catscomm_dom = ' ';
                   3947:             }
                   3948:             if ($settings->{'categorizecomm'} eq 'comm') {
                   3949:                 $can_catcomm_comm = $can_catcomm_dom;
                   3950:                 $can_catcomm_dom = ' ';
                   3951:             }
1.57      raeburn  3952:         }
                   3953:         my %title = &Apache::lonlocal::texthash (
1.120     raeburn  3954:                      togglecats     => 'Show/Hide a course in catalog',
                   3955:                      togglecatscomm => 'Show/Hide a community in catalog',
                   3956:                      categorize     => 'Assign a category to a course',
                   3957:                      categorizecomm => 'Assign a category to a community',
1.57      raeburn  3958:                     );
                   3959:         my %level = &Apache::lonlocal::texthash (
1.120     raeburn  3960:                      dom  => 'Set in Domain',
                   3961:                      crs  => 'Set in Course',
                   3962:                      comm => 'Set in Community',
1.57      raeburn  3963:                     );
                   3964:         $datatable = '<tr class="LC_odd_row">'.
                   3965:                   '<td>'.$title{'togglecats'}.'</td>'.
                   3966:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   3967:                   '<input type="radio" name="togglecats"'.
                   3968:                   $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   3969:                   '<label><input type="radio" name="togglecats"'.
                   3970:                   $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
                   3971:                   '</tr><tr>'.
                   3972:                   '<td>'.$title{'categorize'}.'</td>'.
                   3973:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
                   3974:                   '<label><input type="radio" name="categorize"'.
                   3975:                   $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   3976:                   '<label><input type="radio" name="categorize"'.
                   3977:                   $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120     raeburn  3978:                   '</tr><tr class="LC_odd_row">'.
                   3979:                   '<td>'.$title{'togglecatscomm'}.'</td>'.
                   3980:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   3981:                   '<input type="radio" name="togglecatscomm"'.
                   3982:                   $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   3983:                   '<label><input type="radio" name="togglecatscomm"'.
                   3984:                   $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
                   3985:                   '</tr><tr>'.
                   3986:                   '<td>'.$title{'categorizecomm'}.'</td>'.
                   3987:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
                   3988:                   '<label><input type="radio" name="categorizecomm"'.
                   3989:                   $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   3990:                   '<label><input type="radio" name="categorizecomm"'.
                   3991:                   $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57      raeburn  3992:                   '</tr>';
1.120     raeburn  3993:         $$rowtotal += 4;
1.57      raeburn  3994:     } else {
                   3995:         my $css_class;
                   3996:         my $itemcount = 1;
                   3997:         my $cathash; 
                   3998:         if (ref($settings) eq 'HASH') {
                   3999:             $cathash = $settings->{'cats'};
                   4000:         }
                   4001:         if (ref($cathash) eq 'HASH') {
                   4002:             my (@cats,@trails,%allitems,%idx,@jsarray);
                   4003:             &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
                   4004:                                                    \%allitems,\%idx,\@jsarray);
                   4005:             my $maxdepth = scalar(@cats);
                   4006:             my $colattrib = '';
                   4007:             if ($maxdepth > 2) {
                   4008:                 $colattrib = ' colspan="2" ';
                   4009:             }
                   4010:             my @path;
                   4011:             if (@cats > 0) {
                   4012:                 if (ref($cats[0]) eq 'ARRAY') {
                   4013:                     my $numtop = @{$cats[0]};
                   4014:                     my $maxnum = $numtop;
1.120     raeburn  4015:                     my %default_names = (
                   4016:                           instcode    => &mt('Official courses'),
                   4017:                           communities => &mt('Communities'),
                   4018:                     );
                   4019: 
                   4020:                     if ((!grep(/^instcode$/,@{$cats[0]})) || 
                   4021:                         ($cathash->{'instcode::0'} eq '') ||
                   4022:                         (!grep(/^communities$/,@{$cats[0]})) || 
                   4023:                         ($cathash->{'communities::0'} eq '')) {
1.57      raeburn  4024:                         $maxnum ++;
                   4025:                     }
                   4026:                     my $lastidx;
                   4027:                     for (my $i=0; $i<$numtop; $i++) {
                   4028:                         my $parent = $cats[0][$i];
                   4029:                         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   4030:                         my $item = &escape($parent).'::0';
                   4031:                         my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
                   4032:                         $lastidx = $idx{$item};
                   4033:                         $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
                   4034:                                       .'<select name="'.$item.'"'.$chgstr.'>';
                   4035:                         for (my $k=0; $k<=$maxnum; $k++) {
                   4036:                             my $vpos = $k+1;
                   4037:                             my $selstr;
                   4038:                             if ($k == $i) {
                   4039:                                 $selstr = ' selected="selected" ';
                   4040:                             }
                   4041:                             $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   4042:                         }
                   4043:                         $datatable .= '</select></td><td>';
1.120     raeburn  4044:                         if ($parent eq 'instcode' || $parent eq 'communities') {
                   4045:                             $datatable .=  '<span class="LC_nobreak">'
                   4046:                                            .$default_names{$parent}.'</span>';
                   4047:                             if ($parent eq 'instcode') {
                   4048:                                 $datatable .= '<br /><span class="LC_nobreak">('
                   4049:                                               .&mt('with institutional codes')
                   4050:                                               .')</span></td><td'.$colattrib.'>';
                   4051:                             } else {
                   4052:                                 $datatable .= '<table><tr><td>';
                   4053:                             }
                   4054:                             $datatable .= '<span class="LC_nobreak">'
                   4055:                                           .'<label><input type="radio" name="'
                   4056:                                           .$parent.'" value="1" checked="checked" />'
                   4057:                                           .&mt('Display').'</label>';
                   4058:                             if ($parent eq 'instcode') {
                   4059:                                 $datatable .= '&nbsp;';
                   4060:                             } else {
                   4061:                                 $datatable .= '</span></td></tr><tr><td>'
                   4062:                                               .'<span class="LC_nobreak">';
                   4063:                             }
                   4064:                             $datatable .= '<label><input type="radio" name="'
                   4065:                                           .$parent.'" value="0" />'
                   4066:                                           .&mt('Do not display').'</label></span>';
                   4067:                             if ($parent eq 'communities') {
                   4068:                                 $datatable .= '</td></tr></table>';
                   4069:                             }
                   4070:                             $datatable .= '</td>';
1.57      raeburn  4071:                         } else {
                   4072:                             $datatable .= $parent
                   4073:                                           .'&nbsp;<label><input type="checkbox" name="deletecategory" '
                   4074:                                           .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
                   4075:                         }
                   4076:                         my $depth = 1;
                   4077:                         push(@path,$parent);
                   4078:                         $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
                   4079:                         pop(@path);
                   4080:                         $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
                   4081:                         $itemcount ++;
                   4082:                     }
1.48      raeburn  4083:                     $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57      raeburn  4084:                     my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
                   4085:                     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48      raeburn  4086:                     for (my $k=0; $k<=$maxnum; $k++) {
                   4087:                         my $vpos = $k+1;
                   4088:                         my $selstr;
1.57      raeburn  4089:                         if ($k == $numtop) {
1.48      raeburn  4090:                             $selstr = ' selected="selected" ';
                   4091:                         }
                   4092:                         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   4093:                     }
1.59      bisitz   4094:                     $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').'&nbsp;'
1.57      raeburn  4095:                                   .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
                   4096:                                   .'</tr>'."\n";
1.48      raeburn  4097:                     $itemcount ++;
1.120     raeburn  4098:                     foreach my $default ('instcode','communities') {
                   4099:                         if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
                   4100:                             $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   4101:                             my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
                   4102:                             $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
                   4103:                                           '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
                   4104:                             for (my $k=0; $k<=$maxnum; $k++) {
                   4105:                                 my $vpos = $k+1;
                   4106:                                 my $selstr;
                   4107:                                 if ($k == $maxnum) {
                   4108:                                     $selstr = ' selected="selected" ';
                   4109:                                 }
                   4110:                                 $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57      raeburn  4111:                             }
1.120     raeburn  4112:                             $datatable .= '</select></span></td>'.
                   4113:                                           '<td><span class="LC_nobreak">'.
                   4114:                                           $default_names{$default}.'</span>';
                   4115:                             if ($default eq 'instcode') {
                   4116:                                 $datatable .= '<br /><span class="LC_nobreak">(' 
                   4117:                                               .&mt('with institutional codes').')</span>';
                   4118:                             }
                   4119:                             $datatable .= '</td>'
                   4120:                                           .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
                   4121:                                           .&mt('Display').'</label>&nbsp;'
                   4122:                                           .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
                   4123:                                           .&mt('Do not display').'</label></span></td></tr>';
1.48      raeburn  4124:                         }
                   4125:                     }
                   4126:                 }
1.57      raeburn  4127:             } else {
                   4128:                 $datatable .= &initialize_categories($itemcount);
1.48      raeburn  4129:             }
                   4130:         } else {
1.57      raeburn  4131:             $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[0]->{'col2'}.'</td>'
                   4132:                           .&initialize_categories($itemcount);
1.48      raeburn  4133:         }
1.57      raeburn  4134:         $$rowtotal += $itemcount;
1.48      raeburn  4135:     }
                   4136:     return $datatable;
                   4137: }
                   4138: 
1.69      raeburn  4139: sub print_serverstatuses {
                   4140:     my ($dom,$settings,$rowtotal) = @_;
                   4141:     my $datatable;
                   4142:     my @pages = &serverstatus_pages();
                   4143:     my (%namedaccess,%machineaccess);
                   4144:     foreach my $type (@pages) {
                   4145:         $namedaccess{$type} = '';
                   4146:         $machineaccess{$type}= '';
                   4147:     }
                   4148:     if (ref($settings) eq 'HASH') {
                   4149:         foreach my $type (@pages) {
                   4150:             if (exists($settings->{$type})) {
                   4151:                 if (ref($settings->{$type}) eq 'HASH') {
                   4152:                     foreach my $key (keys(%{$settings->{$type}})) {
                   4153:                         if ($key eq 'namedusers') {
                   4154:                             $namedaccess{$type} = $settings->{$type}->{$key};
                   4155:                         } elsif ($key eq 'machines') {
                   4156:                             $machineaccess{$type} = $settings->{$type}->{$key};
                   4157:                         }
                   4158:                     }
                   4159:                 }
                   4160:             }
                   4161:         }
                   4162:     }
1.81      raeburn  4163:     my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69      raeburn  4164:     my $rownum = 0;
                   4165:     my $css_class;
                   4166:     foreach my $type (@pages) {
                   4167:         $rownum ++;
                   4168:         $css_class = $rownum%2?' class="LC_odd_row"':'';
                   4169:         $datatable .= '<tr'.$css_class.'>'.
                   4170:                       '<td><span class="LC_nobreak">'.
                   4171:                       $titles->{$type}.'</span></td>'.
                   4172:                       '<td class="LC_left_item">'.
                   4173:                       '<input type="text" name="'.$type.'_namedusers" '.
                   4174:                       'value="'.$namedaccess{$type}.'" size="30" /></td>'.
                   4175:                       '<td class="LC_right_item">'.
                   4176:                       '<span class="LC_nobreak">'.
                   4177:                       '<input type="text" name="'.$type.'_machines" '.
                   4178:                       'value="'.$machineaccess{$type}.'" size="10" />'.
                   4179:                       '</td></tr>'."\n";
                   4180:     }
                   4181:     $$rowtotal += $rownum;
                   4182:     return $datatable;
                   4183: }
                   4184: 
                   4185: sub serverstatus_pages {
                   4186:     return ('userstatus','lonstatus','loncron','server-status','codeversions',
                   4187:             'clusterstatus','metadata_keywords','metadata_harvest',
1.156     raeburn  4188:             'takeoffline','takeonline','showenv','toggledebug','ping','domconf');
1.69      raeburn  4189: }
                   4190: 
1.49      raeburn  4191: sub coursecategories_javascript {
                   4192:     my ($settings) = @_;
1.57      raeburn  4193:     my ($output,$jstext,$cathash);
1.49      raeburn  4194:     if (ref($settings) eq 'HASH') {
1.57      raeburn  4195:         $cathash = $settings->{'cats'};
                   4196:     }
                   4197:     if (ref($cathash) eq 'HASH') {
1.49      raeburn  4198:         my (@cats,@jsarray,%idx);
1.57      raeburn  4199:         &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49      raeburn  4200:         if (@jsarray > 0) {
                   4201:             $jstext = '    var categories = Array('.scalar(@jsarray).');'."\n";
                   4202:             for (my $i=0; $i<@jsarray; $i++) {
                   4203:                 if (ref($jsarray[$i]) eq 'ARRAY') {
                   4204:                     my $catstr = join('","',@{$jsarray[$i]});
                   4205:                     $jstext .= '    categories['.$i.'] = Array("'.$catstr.'");'."\n";
                   4206:                 }
                   4207:             }
                   4208:         }
                   4209:     } else {
                   4210:         $jstext  = '    var categories = Array(1);'."\n".
                   4211:                    '    categories[0] = Array("instcode_pos");'."\n"; 
                   4212:     }
1.120     raeburn  4213:     my $instcode_reserved = &mt('The name: "instcode" is a reserved category');
                   4214:     my $communities_reserved = &mt('The name: "communities" is a reserved category');
                   4215:     my $choose_again = '\\n'.&mt('Please use a different name for the new top level category'); 
1.49      raeburn  4216:     $output = <<"ENDSCRIPT";
                   4217: <script type="text/javascript">
1.109     raeburn  4218: // <![CDATA[
1.49      raeburn  4219: function reorderCats(form,parent,item,idx) {
                   4220:     var changedVal;
                   4221: $jstext
                   4222:     var newpos = 'addcategory_pos';
                   4223:     var current = new Array;
                   4224:     if (parent == '') {
                   4225:         var has_instcode = 0;
                   4226:         var maxtop = categories[idx].length;
                   4227:         for (var j=0; j<maxtop; j++) {
                   4228:             if (categories[idx][j] == 'instcode::0') {
                   4229:                 has_instcode == 1;
                   4230:             }
                   4231:         }
                   4232:         if (has_instcode == 0) {
                   4233:             categories[idx][maxtop] = 'instcode_pos';
                   4234:         }
                   4235:     } else {
                   4236:         newpos += '_'+parent;
                   4237:     }
                   4238:     var maxh = 1 + categories[idx].length;
                   4239:     var current = new Array;
                   4240:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
                   4241:     if (item == newpos) {
                   4242:         changedVal = newitemVal;
                   4243:     } else {
                   4244:         changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
                   4245:         current[newitemVal] = newpos;
                   4246:     }
                   4247:     for (var i=0; i<categories[idx].length; i++) {
                   4248:         var elementName = categories[idx][i];
                   4249:         if (elementName != item) {
                   4250:             if (form.elements[elementName]) {
                   4251:                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   4252:                 current[currVal] = elementName;
                   4253:             }
                   4254:         }
                   4255:     }
                   4256:     var oldVal;
                   4257:     for (var j=0; j<maxh; j++) {
                   4258:         if (current[j] == undefined) {
                   4259:             oldVal = j;
                   4260:         }
                   4261:     }
                   4262:     if (oldVal < changedVal) {
                   4263:         for (var k=oldVal+1; k<=changedVal ; k++) {
                   4264:            var elementName = current[k];
                   4265:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   4266:         }
                   4267:     } else {
                   4268:         for (var k=changedVal; k<oldVal; k++) {
                   4269:             var elementName = current[k];
                   4270:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   4271:         }
                   4272:     }
                   4273:     return;
                   4274: }
1.120     raeburn  4275: 
                   4276: function categoryCheck(form) {
                   4277:     if (form.elements['addcategory_name'].value == 'instcode') {
                   4278:         alert('$instcode_reserved\\n$choose_again');
                   4279:         return false;
                   4280:     }
                   4281:     if (form.elements['addcategory_name'].value == 'communities') {
                   4282:         alert('$communities_reserved\\n$choose_again');
                   4283:         return false;
                   4284:     }
                   4285:     return true;
                   4286: }
                   4287: 
1.109     raeburn  4288: // ]]>
1.49      raeburn  4289: </script>
                   4290: 
                   4291: ENDSCRIPT
                   4292:     return $output;
                   4293: }
                   4294: 
1.48      raeburn  4295: sub initialize_categories {
                   4296:     my ($itemcount) = @_;
1.120     raeburn  4297:     my ($datatable,$css_class,$chgstr);
                   4298:     my %default_names = (
                   4299:                       instcode    => 'Official courses (with institutional codes)',
                   4300:                       communities => 'Communities',
                   4301:                         );
                   4302:     my $select0 = ' selected="selected"';
                   4303:     my $select1 = '';
                   4304:     foreach my $default ('instcode','communities') {
                   4305:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   4306:         $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
                   4307:         if ($default eq 'communities') {
                   4308:             $select1 = $select0;
                   4309:             $select0 = '';
                   4310:         }
                   4311:         $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
                   4312:                      .'<select name="'.$default.'_pos">'
                   4313:                      .'<option value="0"'.$select0.'>1</option>'
                   4314:                      .'<option value="1"'.$select1.'>2</option>'
                   4315:                      .'<option value="2">3</option></select>&nbsp;'
                   4316:                      .$default_names{$default}
                   4317:                      .'</span></td><td><span class="LC_nobreak">'
                   4318:                      .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
                   4319:                      .&mt('Display').'</label>&nbsp;<label>'
                   4320:                      .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48      raeburn  4321:                  .'</label></span></td></tr>';
1.120     raeburn  4322:         $itemcount ++;
                   4323:     }
1.48      raeburn  4324:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49      raeburn  4325:     $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48      raeburn  4326:     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120     raeburn  4327:                   .'<select name="addcategory_pos"'.$chgstr.'>'
                   4328:                   .'<option value="0">1</option>'
                   4329:                   .'<option value="1">2</option>'
                   4330:                   .'<option value="2" selected="selected">3</option></select>&nbsp;'
1.48      raeburn  4331:                   .&mt('Add category').'</td><td>'.&mt('Name:')
                   4332:                   .'&nbsp;<input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
                   4333:     return $datatable;
                   4334: }
                   4335: 
                   4336: sub build_category_rows {
1.49      raeburn  4337:     my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
                   4338:     my ($text,$name,$item,$chgstr);
1.48      raeburn  4339:     if (ref($cats) eq 'ARRAY') {
                   4340:         my $maxdepth = scalar(@{$cats});
                   4341:         if (ref($cats->[$depth]) eq 'HASH') {
                   4342:             if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
                   4343:                 my $numchildren = @{$cats->[$depth]{$parent}};
                   4344:                 my $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   4345:                 $text .= '<td><table class="LC_datatable">';
1.49      raeburn  4346:                 my ($idxnum,$parent_name,$parent_item);
                   4347:                 my $higher = $depth - 1;
                   4348:                 if ($higher == 0) {
                   4349:                     $parent_name = &escape($parent).'::'.$higher;
                   4350:                 } else {
                   4351:                     if (ref($path) eq 'ARRAY') {
                   4352:                         $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
                   4353:                     }
                   4354:                 }
                   4355:                 $parent_item = 'addcategory_pos_'.$parent_name;
1.48      raeburn  4356:                 for (my $j=0; $j<=$numchildren; $j++) {
1.49      raeburn  4357:                     if ($j < $numchildren) {
1.48      raeburn  4358:                         $name = $cats->[$depth]{$parent}[$j];
                   4359:                         $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49      raeburn  4360:                         $idxnum = $idx->{$item};
                   4361:                     } else {
                   4362:                         $name = $parent_name;
                   4363:                         $item = $parent_item;
1.48      raeburn  4364:                     }
1.49      raeburn  4365:                     $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
                   4366:                     $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48      raeburn  4367:                     for (my $i=0; $i<=$numchildren; $i++) {
                   4368:                         my $vpos = $i+1;
                   4369:                         my $selstr;
                   4370:                         if ($j == $i) {
                   4371:                             $selstr = ' selected="selected" ';
                   4372:                         }
                   4373:                         $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
                   4374:                     }
                   4375:                     $text .= '</select>&nbsp;';
                   4376:                     if ($j < $numchildren) {
                   4377:                         my $deeper = $depth+1;
                   4378:                         $text .= $name.'&nbsp;'
                   4379:                                  .'<label><input type="checkbox" name="deletecategory" value="'
                   4380:                                  .$item.'" />'.&mt('Delete').'</label></span></td><td>';
                   4381:                         if(ref($path) eq 'ARRAY') {
                   4382:                             push(@{$path},$name);
1.49      raeburn  4383:                             $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48      raeburn  4384:                             pop(@{$path});
                   4385:                         }
                   4386:                     } else {
1.59      bisitz   4387:                         $text .= &mt('Add subcategory:').'&nbsp;</span><input type="textbox" size="20" name="addcategory_name_';
1.48      raeburn  4388:                         if ($j == $numchildren) {
                   4389:                             $text .= $name;
                   4390:                         } else {
                   4391:                             $text .= $item;
                   4392:                         }
                   4393:                         $text .= '" value="" />';
                   4394:                     }
                   4395:                     $text .= '</td></tr>';
                   4396:                 }
                   4397:                 $text .= '</table></td>';
                   4398:             } else {
                   4399:                 my $higher = $depth-1;
                   4400:                 if ($higher == 0) {
                   4401:                     $name = &escape($parent).'::'.$higher;
                   4402:                 } else {
                   4403:                     if (ref($path) eq 'ARRAY') {
                   4404:                         $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
                   4405:                     }
                   4406:                 }
                   4407:                 my $colspan;
                   4408:                 if ($parent ne 'instcode') {
                   4409:                     $colspan = $maxdepth - $depth - 1;
                   4410:                     $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
                   4411:                 }
                   4412:             }
                   4413:         }
                   4414:     }
                   4415:     return $text;
                   4416: }
                   4417: 
1.33      raeburn  4418: sub modifiable_userdata_row {
1.63      raeburn  4419:     my ($context,$role,$settings,$numinrow,$rowcount,$usertypes) = @_;
1.33      raeburn  4420:     my $rolename;
1.63      raeburn  4421:     if ($context eq 'selfcreate') {
                   4422:         if (ref($usertypes) eq 'HASH') {
                   4423:             $rolename = $usertypes->{$role};
                   4424:         } else {
                   4425:             $rolename = $role;
                   4426:         }
1.33      raeburn  4427:     } else {
1.63      raeburn  4428:         if ($role eq 'cr') {
                   4429:             $rolename = &mt('Custom role');
                   4430:         } else {
                   4431:             $rolename = &Apache::lonnet::plaintext($role);
                   4432:         }
1.33      raeburn  4433:     }
                   4434:     my @fields = ('lastname','firstname','middlename','generation',
                   4435:                   'permanentemail','id');
                   4436:     my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
                   4437:     my $output;
                   4438:     my $css_class = $rowcount%2?' class="LC_odd_row"':'';
                   4439:     $output = '<tr '.$css_class.'>'.
                   4440:               '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
                   4441:               '<td class="LC_left_item" colspan="2"><table>';
                   4442:     my $rem;
                   4443:     my %checks;
                   4444:     if (ref($settings) eq 'HASH') {
                   4445:         if (ref($settings->{$context}) eq 'HASH') {
                   4446:             if (ref($settings->{$context}->{$role}) eq 'HASH') {
                   4447:                 foreach my $field (@fields) {
                   4448:                     if ($settings->{$context}->{$role}->{$field}) {
                   4449:                         $checks{$field} = ' checked="checked" ';
                   4450:                     }
                   4451:                 }
                   4452:             }
                   4453:         }
                   4454:     }
                   4455:     for (my $i=0; $i<@fields; $i++) {
                   4456:         my $rem = $i%($numinrow);
                   4457:         if ($rem == 0) {
                   4458:             if ($i > 0) {
                   4459:                 $output .= '</tr>';
                   4460:             }
                   4461:             $output .= '<tr>';
                   4462:         }
                   4463:         my $check = ' ';
                   4464:         if (exists($checks{$fields[$i]})) {
                   4465:             $check = $checks{$fields[$i]}
                   4466:         } else {
                   4467:             if ($role eq 'st') {
                   4468:                 if (ref($settings) ne 'HASH') {
                   4469:                     $check = ' checked="checked" '; 
                   4470:                 }
                   4471:             }
                   4472:         }
                   4473:         $output .= '<td class="LC_left_item">'.
                   4474:                    '<span class="LC_nobreak"><label>'.
                   4475:                    '<input type="checkbox" name="canmodify_'.$role.'" '.
                   4476:                    'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
                   4477:                    '</label></span></td>';
                   4478:         $rem = @fields%($numinrow);
                   4479:     }
                   4480:     my $colsleft = $numinrow - $rem;
                   4481:     if ($colsleft > 1 ) {
                   4482:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   4483:                    '&nbsp;</td>';
                   4484:     } elsif ($colsleft == 1) {
                   4485:         $output .= '<td class="LC_left_item">&nbsp;</td>';
                   4486:     }
                   4487:     $output .= '</tr></table></td></tr>';
                   4488:     return $output;
                   4489: }
1.28      raeburn  4490: 
1.93      raeburn  4491: sub insttypes_row {
                   4492:     my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context) = @_;
                   4493:     my %lt = &Apache::lonlocal::texthash (
                   4494:                       cansearch => 'Users allowed to search',
                   4495:                       statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131     raeburn  4496:                       lockablenames => 'User preference to lock name',
1.93      raeburn  4497:              );
                   4498:     my $showdom;
                   4499:     if ($context eq 'cansearch') {
                   4500:         $showdom = ' ('.$dom.')';
                   4501:     }
1.165     raeburn  4502:     my $class = 'LC_left_item';
                   4503:     if ($context eq 'statustocreate') {
                   4504:         $class = 'LC_right_item';
                   4505:     }
1.25      raeburn  4506:     my $output =  '<tr class="LC_odd_row">'.
1.93      raeburn  4507:                   '<td>'.$lt{$context}.$showdom.
1.165     raeburn  4508:                   '</td><td class="'.$class.'" colspan="2"><table>';
1.26      raeburn  4509:     my $rem;
                   4510:     if (ref($types) eq 'ARRAY') {
                   4511:         for (my $i=0; $i<@{$types}; $i++) {
                   4512:             if (defined($usertypes->{$types->[$i]})) {
                   4513:                 my $rem = $i%($numinrow);
                   4514:                 if ($rem == 0) {
                   4515:                     if ($i > 0) {
                   4516:                         $output .= '</tr>';
                   4517:                     }
                   4518:                     $output .= '<tr>';
1.23      raeburn  4519:                 }
1.26      raeburn  4520:                 my $check = ' ';
1.99      raeburn  4521:                 if (ref($settings) eq 'HASH') {
                   4522:                     if (ref($settings->{$context}) eq 'ARRAY') {
                   4523:                         if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
                   4524:                             $check = ' checked="checked" ';
                   4525:                         }
                   4526:                     } elsif ($context eq 'statustocreate') {
1.26      raeburn  4527:                         $check = ' checked="checked" ';
                   4528:                     }
1.23      raeburn  4529:                 }
1.26      raeburn  4530:                 $output .= '<td class="LC_left_item">'.
                   4531:                            '<span class="LC_nobreak"><label>'.
1.93      raeburn  4532:                            '<input type="checkbox" name="'.$context.'" '.
1.26      raeburn  4533:                            'value="'.$types->[$i].'"'.$check.'/>'.
                   4534:                            $usertypes->{$types->[$i]}.'</label></span></td>';
1.23      raeburn  4535:             }
                   4536:         }
1.26      raeburn  4537:         $rem = @{$types}%($numinrow);
1.23      raeburn  4538:     }
                   4539:     my $colsleft = $numinrow - $rem;
1.131     raeburn  4540:     if (($rem == 0) && (@{$types} > 0)) {
                   4541:         $output .= '<tr>';
                   4542:     }
1.23      raeburn  4543:     if ($colsleft > 1) {
1.25      raeburn  4544:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23      raeburn  4545:     } else {
1.25      raeburn  4546:         $output .= '<td class="LC_left_item">';
1.23      raeburn  4547:     }
                   4548:     my $defcheck = ' ';
1.99      raeburn  4549:     if (ref($settings) eq 'HASH') {  
                   4550:         if (ref($settings->{$context}) eq 'ARRAY') {
                   4551:             if (grep(/^default$/,@{$settings->{$context}})) {
                   4552:                 $defcheck = ' checked="checked" ';
                   4553:             }
                   4554:         } elsif ($context eq 'statustocreate') {
1.26      raeburn  4555:             $defcheck = ' checked="checked" ';
                   4556:         }
1.23      raeburn  4557:     }
1.25      raeburn  4558:     $output .= '<span class="LC_nobreak"><label>'.
1.93      raeburn  4559:                '<input type="checkbox" name="'.$context.'" '.
1.25      raeburn  4560:                'value="default"'.$defcheck.'/>'.
                   4561:                $othertitle.'</label></span></td>'.
                   4562:                '</tr></table></td></tr>';
                   4563:     return $output;
1.23      raeburn  4564: }
                   4565: 
                   4566: sub sorted_searchtitles {
                   4567:     my %searchtitles = &Apache::lonlocal::texthash(
                   4568:                          'uname' => 'username',
                   4569:                          'lastname' => 'last name',
                   4570:                          'lastfirst' => 'last name, first name',
                   4571:                      );
                   4572:     my @titleorder = ('uname','lastname','lastfirst');
                   4573:     return (\%searchtitles,\@titleorder);
                   4574: }
                   4575: 
1.25      raeburn  4576: sub sorted_searchtypes {
                   4577:     my %srchtypes_desc = (
                   4578:                            exact    => 'is exact match',
                   4579:                            contains => 'contains ..',
                   4580:                            begins   => 'begins with ..',
                   4581:                          );
                   4582:     my @srchtypeorder = ('exact','begins','contains');
                   4583:     return (\%srchtypes_desc,\@srchtypeorder);
                   4584: }
                   4585: 
1.3       raeburn  4586: sub usertype_update_row {
                   4587:     my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
                   4588:     my $datatable;
                   4589:     my $numinrow = 4;
                   4590:     foreach my $type (@{$types}) {
                   4591:         if (defined($usertypes->{$type})) {
                   4592:             $$rownums ++;
                   4593:             my $css_class = $$rownums%2?' class="LC_odd_row"':'';
                   4594:             $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
                   4595:                           '</td><td class="LC_left_item"><table>';
                   4596:             for (my $i=0; $i<@{$fields}; $i++) {
                   4597:                 my $rem = $i%($numinrow);
                   4598:                 if ($rem == 0) {
                   4599:                     if ($i > 0) {
                   4600:                         $datatable .= '</tr>';
                   4601:                     }
                   4602:                     $datatable .= '<tr>';
                   4603:                 }
                   4604:                 my $check = ' ';
1.39      raeburn  4605:                 if (ref($settings) eq 'HASH') {
                   4606:                     if (ref($settings->{'fields'}) eq 'HASH') {
                   4607:                         if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
                   4608:                             if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
                   4609:                                 $check = ' checked="checked" ';
                   4610:                             }
1.3       raeburn  4611:                         }
                   4612:                     }
                   4613:                 }
                   4614: 
                   4615:                 if ($i == @{$fields}-1) {
                   4616:                     my $colsleft = $numinrow - $rem;
                   4617:                     if ($colsleft > 1) {
                   4618:                         $datatable .= '<td colspan="'.$colsleft.'">';
                   4619:                     } else {
                   4620:                         $datatable .= '<td>';
                   4621:                     }
                   4622:                 } else {
                   4623:                     $datatable .= '<td>';
                   4624:                 }
1.8       raeburn  4625:                 $datatable .= '<span class="LC_nobreak"><label>'.
                   4626:                               '<input type="checkbox" name="updateable_'.$type.
                   4627:                               '_'.$fields->[$i].'" value="1"'.$check.'/>'.
                   4628:                               $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3       raeburn  4629:             }
                   4630:             $datatable .= '</tr></table></td></tr>';
                   4631:         }
                   4632:     }
                   4633:     return $datatable;
1.1       raeburn  4634: }
                   4635: 
                   4636: sub modify_login {
1.9       raeburn  4637:     my ($r,$dom,$confname,%domconfig) = @_;
1.168     raeburn  4638:     my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
                   4639:         %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
                   4640:     %title = ( coursecatalog => 'Display course catalog',
                   4641:                adminmail => 'Display administrator E-mail address',
                   4642:                newuser => 'Link for visitors to create a user account',
                   4643:                loginheader => 'Log-in box header');
                   4644:     @offon = ('off','on');
1.112     raeburn  4645:     if (ref($domconfig{login}) eq 'HASH') {
                   4646:         if (ref($domconfig{login}{loginvia}) eq 'HASH') {
                   4647:             foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
                   4648:                 $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
                   4649:             }
                   4650:         }
                   4651:     }
1.9       raeburn  4652:     ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
                   4653:                                            \%domconfig,\%loginhash);
1.118     jms      4654:     my @toggles = ('coursecatalog','adminmail','newuser');
1.42      raeburn  4655:     foreach my $item (@toggles) {
                   4656:         $loginhash{login}{$item} = $env{'form.'.$item};
                   4657:     }
1.41      raeburn  4658:     $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6       raeburn  4659:     if (ref($colchanges{'login'}) eq 'HASH') {  
                   4660:         $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
                   4661:                                          \%loginhash);
                   4662:     }
1.110     raeburn  4663: 
1.149     raeburn  4664:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.128     raeburn  4665:     my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110     raeburn  4666:     if (keys(%servers) > 1) {
                   4667:         foreach my $lonhost (keys(%servers)) {
1.128     raeburn  4668:             next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
                   4669:             if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
                   4670:                 if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
                   4671:                     $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
                   4672:                 } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
                   4673:                     if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
                   4674:                         $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
                   4675:                         $changes{'loginvia'}{$lonhost} = 1;
                   4676:                     } else {
                   4677:                         $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
                   4678:                         $changes{'loginvia'}{$lonhost} = 1;
                   4679:                     }
                   4680:                 } else {
                   4681:                     if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
                   4682:                         $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
                   4683:                         $changes{'loginvia'}{$lonhost} = 1;
                   4684:                     }
                   4685:                 }
                   4686:                 if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
                   4687:                     foreach my $item (@loginvia_attribs) {
                   4688:                         $loginhash{login}{loginvia}{$lonhost}{$item} = '';
                   4689:                     }
                   4690:                 } else {
                   4691:                     foreach my $item (@loginvia_attribs) {
                   4692:                         my $new = $env{'form.'.$lonhost.'_'.$item};
                   4693:                         if (($item eq 'serverpath') && ($new eq 'custom')) {
                   4694:                             $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
                   4695:                             if ($env{'form.'.$lonhost.'_custompath'} eq '') {
                   4696:                                 $new = '/';
                   4697:                             }
                   4698:                         }
                   4699:                         if (($item eq 'custompath') && 
                   4700:                             ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
                   4701:                             $new = '';
                   4702:                         }
                   4703:                         if ($new ne $curr_loginvia{$lonhost}{$item}) {
                   4704:                             $changes{'loginvia'}{$lonhost} = 1;
                   4705:                         }
                   4706:                         if ($item eq 'exempt') {
                   4707:                             $new =~ s/^\s+//;
                   4708:                             $new =~ s/\s+$//;
                   4709:                             my @poss_ips = split(/\s*[,:]\s*/,$new);
                   4710:                             my @okips;
                   4711:                             foreach my $ip (@poss_ips) {
                   4712:                                 if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
                   4713:                                     if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
                   4714:                                         push(@okips,$ip); 
                   4715:                                     }
                   4716:                                 }
                   4717:                             }
                   4718:                             if (@okips > 0) {
                   4719:                                 $new = join(',',@okips); 
                   4720:                             } else {
                   4721:                                 $new = ''; 
                   4722:                             }
                   4723:                         }
                   4724:                         $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
                   4725:                     }
                   4726:                 }
1.112     raeburn  4727:             } else {
1.128     raeburn  4728:                 if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
                   4729:                     $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112     raeburn  4730:                     $changes{'loginvia'}{$lonhost} = 1;
1.128     raeburn  4731:                     foreach my $item (@loginvia_attribs) {
                   4732:                         my $new = $env{'form.'.$lonhost.'_'.$item};
                   4733:                         if (($item eq 'serverpath') && ($new eq 'custom')) {
                   4734:                             if ($env{'form.'.$lonhost.'_custompath'} eq '') {
                   4735:                                 $new = '/';
                   4736:                             }
                   4737:                         }
                   4738:                         if (($item eq 'custompath') && 
                   4739:                             ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
                   4740:                             $new = '';
                   4741:                         }
                   4742:                         $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
                   4743:                     }
1.110     raeburn  4744:                 }
                   4745:             }
                   4746:         }
                   4747:     }
1.119     raeburn  4748: 
1.168     raeburn  4749:     my $servadm = $r->dir_config('lonAdmEMail');
                   4750:     my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
                   4751:     if (ref($domconfig{'login'}) eq 'HASH') {
                   4752:         if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
                   4753:             foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
                   4754:                 if ($lang eq 'nolang') {
                   4755:                     push(@currlangs,$lang);
                   4756:                 } elsif (defined($langchoices{$lang})) {
                   4757:                     push(@currlangs,$lang);
                   4758:                 } else {
                   4759:                     next;
                   4760:                 }
                   4761:             }
                   4762:         }
                   4763:     }
                   4764:     my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
                   4765:     if (@currlangs > 0) {
                   4766:         foreach my $lang (@currlangs) {
                   4767:             if (grep(/^\Q$lang\E$/,@delurls)) {
                   4768:                 $changes{'helpurl'}{$lang} = 1;
                   4769:             } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
                   4770:                 $changes{'helpurl'}{$lang} = 1;
                   4771:                 $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
                   4772:                 push(@newlangs,$lang);
                   4773:             } else {
                   4774:                 $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
                   4775:             }
                   4776:         }
                   4777:     }
                   4778:     unless (grep(/^nolang$/,@currlangs)) {
                   4779:         if ($env{'form.loginhelpurl_nolang.filename'}) {
                   4780:             $changes{'helpurl'}{'nolang'} = 1;
                   4781:             $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
                   4782:             push(@newlangs,'nolang');
                   4783:         }
                   4784:     }
                   4785:     if ($env{'form.loginhelpurl_add_lang'}) {
                   4786:         if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
                   4787:             ($env{'form.loginhelpurl_add_file.filename'})) {
                   4788:             $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
                   4789:             $addedfile = $env{'form.loginhelpurl_add_lang'};
                   4790:         }
                   4791:     }
                   4792:     if ((@newlangs > 0) || ($addedfile)) {
                   4793:         my $error;
                   4794:         my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
                   4795:         if ($configuserok eq 'ok') {
                   4796:             if ($switchserver) {
                   4797:                 $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
                   4798:             } elsif ($author_ok eq 'ok') {
                   4799:                 my @allnew = @newlangs;
                   4800:                 if ($addedfile ne '') {
                   4801:                     push(@allnew,$addedfile);
                   4802:                 }
                   4803:                 foreach my $lang (@allnew) {
                   4804:                     my $formelem = 'loginhelpurl_'.$lang;
                   4805:                     if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
                   4806:                         $formelem = 'loginhelpurl_add_file';
                   4807:                     }
                   4808:                     (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
                   4809:                                                                "help/$lang",'','',$newfile{$lang});
                   4810:                     if ($result eq 'ok') {
                   4811:                         $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
                   4812:                         $changes{'helpurl'}{$lang} = 1;
                   4813:                     } else {
                   4814:                         my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
                   4815:                         $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
                   4816:                         if ((grep(/^\Q$lang\E$/,@currlangs)) && 
                   4817:                             (!grep(/^\Q$lang\E$/,@delurls))) {
                   4818: 
                   4819:                             $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
                   4820:                         }
                   4821:                     }
                   4822:                 }
                   4823:             } else {
                   4824:                 $error = &mt("Upload of custom log-in help file(s) failed because an author role could not be assigned to a Domain Configuration user ([_1]) in domain: [_2].  Error was: [_3].",$confname,$dom,$author_ok);
                   4825:             }
                   4826:         } else {
                   4827:             $error = &mt("Upload of custom log-in help file(s) failed because a Domain Configuration user ([_1]) could not be created in domain: [_2].  Error was: [_3].",$confname,$dom,$configuserok);
                   4828:         }
                   4829:         if ($error) {
                   4830:             &Apache::lonnet::logthis($error);
                   4831:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   4832:         }
                   4833:     }
1.169     raeburn  4834:     &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168     raeburn  4835: 
                   4836:     my $defaulthelpfile = '/adm/loginproblems.html';
                   4837:     my $defaulttext = &mt('Default in use');
                   4838: 
1.1       raeburn  4839:     my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
                   4840:                                              $dom);
                   4841:     if ($putresult eq 'ok') {
1.118     jms      4842:         my @toggles = ('coursecatalog','adminmail','newuser');
1.42      raeburn  4843:         my %defaultchecked = (
                   4844:                     'coursecatalog' => 'on',
                   4845:                     'adminmail'     => 'off',
1.43      raeburn  4846:                     'newuser'       => 'off',
1.42      raeburn  4847:         );
1.55      raeburn  4848:         if (ref($domconfig{'login'}) eq 'HASH') {
                   4849:             foreach my $item (@toggles) {
                   4850:                 if ($defaultchecked{$item} eq 'on') { 
                   4851:                     if (($domconfig{'login'}{$item} eq '0') &&
                   4852:                         ($env{'form.'.$item} eq '1')) {
                   4853:                         $changes{$item} = 1;
                   4854:                     } elsif (($domconfig{'login'}{$item} eq '' ||
                   4855:                               $domconfig{'login'}{$item} eq '1') &&
                   4856:                              ($env{'form.'.$item} eq '0')) {
                   4857:                         $changes{$item} = 1;
                   4858:                     }
                   4859:                 } elsif ($defaultchecked{$item} eq 'off') {
                   4860:                     if (($domconfig{'login'}{$item} eq '1') &&
                   4861:                         ($env{'form.'.$item} eq '0')) {
                   4862:                         $changes{$item} = 1;
                   4863:                     } elsif (($domconfig{'login'}{$item} eq '' ||
                   4864:                               $domconfig{'login'}{$item} eq '0') &&
                   4865:                              ($env{'form.'.$item} eq '1')) {
                   4866:                         $changes{$item} = 1;
                   4867:                     }
1.42      raeburn  4868:                 }
                   4869:             }
1.41      raeburn  4870:         }
1.6       raeburn  4871:         if (keys(%changes) > 0 || $colchgtext) {
1.41      raeburn  4872:             &Apache::loncommon::devalidate_domconfig_cache($dom);
1.1       raeburn  4873:             $resulttext = &mt('Changes made:').'<ul>';
                   4874:             foreach my $item (sort(keys(%changes))) {
1.135     bisitz   4875:                 if ($item eq 'loginvia') {
1.112     raeburn  4876:                     if (ref($changes{$item}) eq 'HASH') {
                   4877:                         $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
                   4878:                         foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128     raeburn  4879:                             if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
                   4880:                                 if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
                   4881:                                     my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
                   4882:                                     $protocol = 'http' if ($protocol ne 'https');
                   4883:                                     my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
                   4884: 
                   4885:                                     if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
                   4886:                                         $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
                   4887:                                     } else {
                   4888:                                         $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'}; 
                   4889:                                     }
                   4890:                                     $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
                   4891:                                     if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
                   4892:                                         $resulttext .= '&nbsp;'.&mt('No redirection for clients from following IPs:').'&nbsp;'.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
                   4893:                                     }
                   4894:                                     $resulttext .= '</li>';
                   4895:                                 } else {
                   4896:                                     $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
                   4897:                                 }
1.112     raeburn  4898:                             } else {
1.128     raeburn  4899:                                 $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112     raeburn  4900:                             }
                   4901:                         }
1.128     raeburn  4902:                         $resulttext .= '</ul></li>';
1.112     raeburn  4903:                     }
1.168     raeburn  4904:                 } elsif ($item eq 'helpurl') {
                   4905:                     if (ref($changes{$item}) eq 'HASH') {
                   4906:                         foreach my $lang (sort(keys(%{$changes{$item}}))) {
                   4907:                             if (grep(/^\Q$lang\E$/,@delurls)) {
                   4908:                                 my ($chg,$link);
                   4909:                                 $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
                   4910:                                 if ($lang eq 'nolang') {
                   4911:                                     $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
                   4912:                                 } else {
                   4913:                                     $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
                   4914:                                 }
                   4915:                                 $resulttext .= '<li>'.$chg.'</li>';
                   4916:                             } else {
                   4917:                                 my $chg;
                   4918:                                 if ($lang eq 'nolang') {
                   4919:                                     $chg = &mt('custom log-in help file for no preferred language');
                   4920:                                 } else {
                   4921:                                     $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
                   4922:                                 }
                   4923:                                 $resulttext .= '<li>'.&Apache::loncommon::modal_link(
                   4924:                                                       $loginhash{'login'}{'helpurl'}{$lang}.
                   4925:                                                       '?inhibitmenu=yes',$chg,600,500).
                   4926:                                                '</li>';
                   4927:                             }
                   4928:                         }
                   4929:                     }
1.169     raeburn  4930:                 } elsif ($item eq 'captcha') {
                   4931:                     if (ref($loginhash{'login'}) eq 'HASH') {
                   4932:                         my $chgtxt; 
                   4933:                         if ($loginhash{'login'}{$item} eq 'notused') {
                   4934:                             $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
                   4935:                         } else {
                   4936:                             my %captchas = &captcha_phrases();
                   4937:                             if ($captchas{$loginhash{'login'}{$item}}) {
                   4938:                                 $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
                   4939:                             } else {
                   4940:                                 $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
                   4941:                             }
                   4942:                         }
                   4943:                         $resulttext .= '<li>'.$chgtxt.'</li>';
                   4944:                     }
                   4945:                 } elsif ($item eq 'recaptchakeys') {
                   4946:                     if (ref($loginhash{'login'}) eq 'HASH') {
                   4947:                         my ($privkey,$pubkey);
                   4948:                         if (ref($loginhash{'login'}{$item}) eq 'HASH') {
                   4949:                             $pubkey = $loginhash{'login'}{$item}{'public'};
                   4950:                             $privkey = $loginhash{'login'}{$item}{'private'};
                   4951:                         }
                   4952:                         my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
                   4953:                         if (!$pubkey) {
                   4954:                             $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
                   4955:                         } else {
                   4956:                             $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
                   4957:                         }
                   4958:                         if (!$privkey) {
                   4959:                             $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
                   4960:                         } else {
                   4961:                             $chgtxt .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
                   4962:                         }
                   4963:                         $chgtxt .= '</ul>';
                   4964:                         $resulttext .= '<li>'.$chgtxt.'</li>';
                   4965:                     }
1.41      raeburn  4966:                 } else {
                   4967:                     $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
                   4968:                 }
1.1       raeburn  4969:             }
1.6       raeburn  4970:             $resulttext .= $colchgtext.'</ul>';
1.1       raeburn  4971:         } else {
                   4972:             $resulttext = &mt('No changes made to log-in page settings');
                   4973:         }
                   4974:     } else {
1.11      albertel 4975:         $resulttext = '<span class="LC_error">'.
                   4976: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  4977:     }
1.6       raeburn  4978:     if ($errors) {
1.9       raeburn  4979:         $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6       raeburn  4980:                        $errors.'</ul>';
                   4981:     }
                   4982:     return $resulttext;
                   4983: }
                   4984: 
                   4985: sub color_font_choices {
                   4986:     my %choices =
                   4987:         &Apache::lonlocal::texthash (
                   4988:             img => "Header",
                   4989:             bgs => "Background colors",
                   4990:             links => "Link colors",
1.55      raeburn  4991:             images => "Images",
1.6       raeburn  4992:             font => "Font color",
1.97      tempelho 4993:             fontmenu => "Font Menu",
1.76      raeburn  4994:             pgbg => "Page",
1.6       raeburn  4995:             tabbg => "Header",
                   4996:             sidebg => "Border",
                   4997:             link => "Link",
                   4998:             alink => "Active link",
                   4999:             vlink => "Visited link",
                   5000:         );
                   5001:     return %choices;
                   5002: }
                   5003: 
                   5004: sub modify_rolecolors {
1.9       raeburn  5005:     my ($r,$dom,$confname,$roles,%domconfig) = @_;
1.6       raeburn  5006:     my ($resulttext,%rolehash);
                   5007:     $rolehash{'rolecolors'} = {};
1.55      raeburn  5008:     if (ref($domconfig{'rolecolors'}) ne 'HASH') {
                   5009:         if ($domconfig{'rolecolors'} eq '') {
                   5010:             $domconfig{'rolecolors'} = {};
                   5011:         }
                   5012:     }
1.9       raeburn  5013:     my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6       raeburn  5014:                          $domconfig{'rolecolors'},$rolehash{'rolecolors'});
                   5015:     my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
                   5016:                                              $dom);
                   5017:     if ($putresult eq 'ok') {
                   5018:         if (keys(%changes) > 0) {
1.41      raeburn  5019:             &Apache::loncommon::devalidate_domconfig_cache($dom);
1.6       raeburn  5020:             $resulttext = &display_colorchgs($dom,\%changes,$roles,
                   5021:                                              $rolehash{'rolecolors'});
                   5022:         } else {
                   5023:             $resulttext = &mt('No changes made to default color schemes');
                   5024:         }
                   5025:     } else {
1.11      albertel 5026:         $resulttext = '<span class="LC_error">'.
                   5027: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.6       raeburn  5028:     }
                   5029:     if ($errors) {
                   5030:         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
                   5031:                        $errors.'</ul>';
                   5032:     }
                   5033:     return $resulttext;
                   5034: }
                   5035: 
                   5036: sub modify_colors {
1.9       raeburn  5037:     my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12      raeburn  5038:     my (%changes,%choices);
1.51      raeburn  5039:     my @bgs;
1.6       raeburn  5040:     my @links = ('link','alink','vlink');
1.41      raeburn  5041:     my @logintext;
1.6       raeburn  5042:     my @images;
                   5043:     my $servadm = $r->dir_config('lonAdmEMail');
                   5044:     my $errors;
                   5045:     foreach my $role (@{$roles}) {
                   5046:         if ($role eq 'login') {
1.12      raeburn  5047:             %choices = &login_choices();
1.41      raeburn  5048:             @logintext = ('textcol','bgcol');
1.12      raeburn  5049:         } else {
                   5050:             %choices = &color_font_choices();
1.107     raeburn  5051:             $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
1.12      raeburn  5052:         }
                   5053:         if ($role eq 'login') {
1.41      raeburn  5054:             @images = ('img','logo','domlogo','login');
1.51      raeburn  5055:             @bgs = ('pgbg','mainbg','sidebg');
1.6       raeburn  5056:         } else {
                   5057:             @images = ('img');
1.51      raeburn  5058:             @bgs = ('pgbg','tabbg','sidebg'); 
1.6       raeburn  5059:         }
                   5060:         $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
1.41      raeburn  5061:         foreach my $item (@bgs,@links,@logintext) {
1.6       raeburn  5062:             $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
                   5063:         }
1.46      raeburn  5064:         my ($configuserok,$author_ok,$switchserver) = 
                   5065:             &config_check($dom,$confname,$servadm);
1.9       raeburn  5066:         my ($width,$height) = &thumb_dimensions();
1.40      raeburn  5067:         if (ref($domconfig->{$role}) ne 'HASH') {
                   5068:             $domconfig->{$role} = {};
                   5069:         }
1.8       raeburn  5070:         foreach my $img (@images) {
1.70      raeburn  5071:             if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {  
                   5072:                 if (defined($env{'form.login_showlogo_'.$img})) {
                   5073:                     $confhash->{$role}{'showlogo'}{$img} = 1;
                   5074:                 } else { 
                   5075:                     $confhash->{$role}{'showlogo'}{$img} = 0;
                   5076:                 }
                   5077:             } 
1.18      albertel 5078: 	    if ( ! $env{'form.'.$role.'_'.$img.'.filename'} 
                   5079: 		 && !defined($domconfig->{$role}{$img})
                   5080: 		 && !$env{'form.'.$role.'_del_'.$img}
                   5081: 		 && $env{'form.'.$role.'_import_'.$img}) {
                   5082: 		# import the old configured image from the .tab setting
                   5083: 		# if they haven't provided a new one 
                   5084: 		$domconfig->{$role}{$img} = 
                   5085: 		    $env{'form.'.$role.'_import_'.$img};
                   5086: 	    }
1.6       raeburn  5087:             if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9       raeburn  5088:                 my $error;
1.6       raeburn  5089:                 if ($configuserok eq 'ok') {
1.9       raeburn  5090:                     if ($switchserver) {
1.12      raeburn  5091:                         $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9       raeburn  5092:                     } else {
                   5093:                         if ($author_ok eq 'ok') {
                   5094:                             my ($result,$logourl) = 
                   5095:                                 &publishlogo($r,'upload',$role.'_'.$img,
                   5096:                                            $dom,$confname,$img,$width,$height);
                   5097:                             if ($result eq 'ok') {
                   5098:                                 $confhash->{$role}{$img} = $logourl;
1.12      raeburn  5099:                                 $changes{$role}{'images'}{$img} = 1;
1.9       raeburn  5100:                             } else {
1.12      raeburn  5101:                                 $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  5102:                             }
                   5103:                         } else {
1.46      raeburn  5104:                             $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  5105:                         }
                   5106:                     }
                   5107:                 } else {
1.46      raeburn  5108:                     $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  5109:                 }
                   5110:                 if ($error) {
1.8       raeburn  5111:                     &Apache::lonnet::logthis($error);
1.11      albertel 5112:                     $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8       raeburn  5113:                 }
                   5114:             } elsif ($domconfig->{$role}{$img} ne '') {
1.9       raeburn  5115:                 if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
                   5116:                     my $error;
                   5117:                     if ($configuserok eq 'ok') {
                   5118: # is confname an author?
                   5119:                         if ($switchserver eq '') {
                   5120:                             if ($author_ok eq 'ok') {
                   5121:                                 my ($result,$logourl) = 
                   5122:                                &publishlogo($r,'copy',$domconfig->{$role}{$img},
                   5123:                                             $dom,$confname,$img,$width,$height);
                   5124:                                 if ($result eq 'ok') {
                   5125:                                     $confhash->{$role}{$img} = $logourl;
1.18      albertel 5126: 				    $changes{$role}{'images'}{$img} = 1;
1.9       raeburn  5127:                                 }
                   5128:                             }
                   5129:                         }
                   5130:                     }
1.6       raeburn  5131:                 }
                   5132:             }
                   5133:         }
                   5134:         if (ref($domconfig) eq 'HASH') {
                   5135:             if (ref($domconfig->{$role}) eq 'HASH') {
                   5136:                 foreach my $img (@images) {
                   5137:                     if ($domconfig->{$role}{$img} ne '') {
                   5138:                         if ($env{'form.'.$role.'_del_'.$img}) {
                   5139:                             $confhash->{$role}{$img} = '';
1.12      raeburn  5140:                             $changes{$role}{'images'}{$img} = 1;
1.6       raeburn  5141:                         } else {
1.9       raeburn  5142:                             if ($confhash->{$role}{$img} eq '') {
                   5143:                                 $confhash->{$role}{$img} = $domconfig->{$role}{$img};
                   5144:                             }
1.6       raeburn  5145:                         }
                   5146:                     } else {
                   5147:                         if ($env{'form.'.$role.'_del_'.$img}) {
                   5148:                             $confhash->{$role}{$img} = '';
1.12      raeburn  5149:                             $changes{$role}{'images'}{$img} = 1;
1.6       raeburn  5150:                         } 
                   5151:                     }
1.70      raeburn  5152:                     if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
                   5153:                         if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
                   5154:                             if ($confhash->{$role}{'showlogo'}{$img} ne 
                   5155:                                 $domconfig->{$role}{'showlogo'}{$img}) {
                   5156:                                 $changes{$role}{'showlogo'}{$img} = 1; 
                   5157:                             }
                   5158:                         } else {
                   5159:                             if ($confhash->{$role}{'showlogo'}{$img} == 0) {
                   5160:                                 $changes{$role}{'showlogo'}{$img} = 1;
                   5161:                             }
                   5162:                         }
                   5163:                     }
                   5164:                 }
1.6       raeburn  5165:                 if ($domconfig->{$role}{'font'} ne '') {
                   5166:                     if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
                   5167:                         $changes{$role}{'font'} = 1;
                   5168:                     }
                   5169:                 } else {
                   5170:                     if ($confhash->{$role}{'font'}) {
                   5171:                         $changes{$role}{'font'} = 1;
                   5172:                     }
                   5173:                 }
1.107     raeburn  5174:                 if ($role ne 'login') {
                   5175:                     if ($domconfig->{$role}{'fontmenu'} ne '') {
                   5176:                         if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
                   5177:                             $changes{$role}{'fontmenu'} = 1;
                   5178:                         }
                   5179:                     } else {
                   5180:                         if ($confhash->{$role}{'fontmenu'}) {
                   5181:                             $changes{$role}{'fontmenu'} = 1;
                   5182:                         }
1.97      tempelho 5183:                     }
                   5184:                 }
1.6       raeburn  5185:                 foreach my $item (@bgs) {
                   5186:                     if ($domconfig->{$role}{$item} ne '') {
                   5187:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
                   5188:                             $changes{$role}{'bgs'}{$item} = 1;
                   5189:                         } 
                   5190:                     } else {
                   5191:                         if ($confhash->{$role}{$item}) {
                   5192:                             $changes{$role}{'bgs'}{$item} = 1;
                   5193:                         }
                   5194:                     }
                   5195:                 }
                   5196:                 foreach my $item (@links) {
                   5197:                     if ($domconfig->{$role}{$item} ne '') {
                   5198:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
                   5199:                             $changes{$role}{'links'}{$item} = 1;
                   5200:                         }
                   5201:                     } else {
                   5202:                         if ($confhash->{$role}{$item}) {
                   5203:                             $changes{$role}{'links'}{$item} = 1;
                   5204:                         }
                   5205:                     }
                   5206:                 }
1.41      raeburn  5207:                 foreach my $item (@logintext) {
                   5208:                     if ($domconfig->{$role}{$item} ne '') {
                   5209:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
                   5210:                             $changes{$role}{'logintext'}{$item} = 1;
                   5211:                         }
                   5212:                     } else {
                   5213:                         if ($confhash->{$role}{$item}) {
                   5214:                             $changes{$role}{'logintext'}{$item} = 1;
                   5215:                         }
                   5216:                     }
                   5217:                 }
1.6       raeburn  5218:             } else {
                   5219:                 &default_change_checker($role,\@images,\@links,\@bgs,
1.41      raeburn  5220:                                         \@logintext,$confhash,\%changes); 
1.6       raeburn  5221:             }
                   5222:         } else {
                   5223:             &default_change_checker($role,\@images,\@links,\@bgs,
1.41      raeburn  5224:                                     \@logintext,$confhash,\%changes); 
1.6       raeburn  5225:         }
                   5226:     }
                   5227:     return ($errors,%changes);
                   5228: }
                   5229: 
1.46      raeburn  5230: sub config_check {
                   5231:     my ($dom,$confname,$servadm) = @_;
                   5232:     my ($configuserok,$author_ok,$switchserver,%currroles);
                   5233:     my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
                   5234:     ($configuserok,%currroles) = &check_configuser($uhome,$dom,
                   5235:                                                    $confname,$servadm);
                   5236:     if ($configuserok eq 'ok') {
                   5237:         $switchserver = &check_switchserver($dom,$confname);
                   5238:         if ($switchserver eq '') {
                   5239:             $author_ok = &check_authorstatus($dom,$confname,%currroles);
                   5240:         }
                   5241:     }
                   5242:     return ($configuserok,$author_ok,$switchserver);
                   5243: }
                   5244: 
1.6       raeburn  5245: sub default_change_checker {
1.41      raeburn  5246:     my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6       raeburn  5247:     foreach my $item (@{$links}) {
                   5248:         if ($confhash->{$role}{$item}) {
                   5249:             $changes->{$role}{'links'}{$item} = 1;
                   5250:         }
                   5251:     }
                   5252:     foreach my $item (@{$bgs}) {
                   5253:         if ($confhash->{$role}{$item}) {
                   5254:             $changes->{$role}{'bgs'}{$item} = 1;
                   5255:         }
                   5256:     }
1.41      raeburn  5257:     foreach my $item (@{$logintext}) {
                   5258:         if ($confhash->{$role}{$item}) {
                   5259:             $changes->{$role}{'logintext'}{$item} = 1;
                   5260:         }
                   5261:     }
1.6       raeburn  5262:     foreach my $img (@{$images}) {
                   5263:         if ($env{'form.'.$role.'_del_'.$img}) {
                   5264:             $confhash->{$role}{$img} = '';
1.12      raeburn  5265:             $changes->{$role}{'images'}{$img} = 1;
1.6       raeburn  5266:         }
1.70      raeburn  5267:         if ($role eq 'login') {
                   5268:             if ($confhash->{$role}{'showlogo'}{$img} == 0) {
                   5269:                 $changes->{$role}{'showlogo'}{$img} = 1;
                   5270:             }
                   5271:         }
1.6       raeburn  5272:     }
                   5273:     if ($confhash->{$role}{'font'}) {
                   5274:         $changes->{$role}{'font'} = 1;
                   5275:     }
1.48      raeburn  5276: }
1.6       raeburn  5277: 
                   5278: sub display_colorchgs {
                   5279:     my ($dom,$changes,$roles,$confhash) = @_;
                   5280:     my (%choices,$resulttext);
                   5281:     if (!grep(/^login$/,@{$roles})) {
                   5282:         $resulttext = &mt('Changes made:').'<br />';
                   5283:     }
                   5284:     foreach my $role (@{$roles}) {
                   5285:         if ($role eq 'login') {
                   5286:             %choices = &login_choices();
                   5287:         } else {
                   5288:             %choices = &color_font_choices();
                   5289:         }
                   5290:         if (ref($changes->{$role}) eq 'HASH') {
                   5291:             if ($role ne 'login') {
                   5292:                 $resulttext .= '<h4>'.&mt($role).'</h4>';
                   5293:             }
                   5294:             foreach my $key (sort(keys(%{$changes->{$role}}))) {
                   5295:                 if ($role ne 'login') {
                   5296:                     $resulttext .= '<ul>';
                   5297:                 }
                   5298:                 if (ref($changes->{$role}{$key}) eq 'HASH') {
                   5299:                     if ($role ne 'login') {
                   5300:                         $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
                   5301:                     }
                   5302:                     foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70      raeburn  5303:                         if (($role eq 'login') && ($key eq 'showlogo')) {
                   5304:                             if ($confhash->{$role}{$key}{$item}) {
                   5305:                                 $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
                   5306:                             } else {
                   5307:                                 $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
                   5308:                             }
                   5309:                         } elsif ($confhash->{$role}{$item} eq '') {
1.6       raeburn  5310:                             $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
                   5311:                         } else {
1.12      raeburn  5312:                             my $newitem = $confhash->{$role}{$item};
                   5313:                             if ($key eq 'images') {
                   5314:                                 $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
                   5315:                             }
                   5316:                             $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6       raeburn  5317:                         }
                   5318:                     }
                   5319:                     if ($role ne 'login') {
                   5320:                         $resulttext .= '</ul></li>';
                   5321:                     }
                   5322:                 } else {
                   5323:                     if ($confhash->{$role}{$key} eq '') {
                   5324:                         $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
                   5325:                     } else {
                   5326:                         $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
                   5327:                     }
                   5328:                 }
                   5329:                 if ($role ne 'login') {
                   5330:                     $resulttext .= '</ul>';
                   5331:                 }
                   5332:             }
                   5333:         }
                   5334:     }
1.3       raeburn  5335:     return $resulttext;
1.1       raeburn  5336: }
                   5337: 
1.9       raeburn  5338: sub thumb_dimensions {
                   5339:     return ('200','50');
                   5340: }
                   5341: 
1.16      raeburn  5342: sub check_dimensions {
                   5343:     my ($inputfile) = @_;
                   5344:     my ($fullwidth,$fullheight);
                   5345:     if ($inputfile =~ m|^[/\w.\-]+$|) {
                   5346:         if (open(PIPE,"identify $inputfile 2>&1 |")) {
                   5347:             my $imageinfo = <PIPE>;
                   5348:             if (!close(PIPE)) {
                   5349:                 &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
                   5350:             }
                   5351:             chomp($imageinfo);
                   5352:             my ($fullsize) = 
1.21      raeburn  5353:                 ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16      raeburn  5354:             if ($fullsize) {
                   5355:                 ($fullwidth,$fullheight) = split(/x/,$fullsize);
                   5356:             }
                   5357:         }
                   5358:     }
                   5359:     return ($fullwidth,$fullheight);
                   5360: }
                   5361: 
1.9       raeburn  5362: sub check_configuser {
                   5363:     my ($uhome,$dom,$confname,$servadm) = @_;
                   5364:     my ($configuserok,%currroles);
                   5365:     if ($uhome eq 'no_host') {
                   5366:         srand( time() ^ ($$ + ($$ << 15))  ); # Seed rand.
                   5367:         my $configpass = &LONCAPA::Enrollment::create_password();
                   5368:         $configuserok = 
                   5369:             &Apache::lonnet::modifyuser($dom,$confname,'','internal',
                   5370:                              $configpass,'','','','','',undef,$servadm);
                   5371:     } else {
                   5372:         $configuserok = 'ok';
                   5373:         %currroles = 
                   5374:             &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
                   5375:     }
                   5376:     return ($configuserok,%currroles);
                   5377: }
                   5378: 
                   5379: sub check_authorstatus {
                   5380:     my ($dom,$confname,%currroles) = @_;
                   5381:     my $author_ok;
1.40      raeburn  5382:     if (!$currroles{':'.$dom.':au'}) {
1.9       raeburn  5383:         my $start = time;
                   5384:         my $end = 0;
                   5385:         $author_ok = 
                   5386:             &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47      raeburn  5387:                                         'au',$end,$start,'','','domconfig');
1.9       raeburn  5388:     } else {
                   5389:         $author_ok = 'ok';
                   5390:     }
                   5391:     return $author_ok;
                   5392: }
                   5393: 
                   5394: sub publishlogo {
1.46      raeburn  5395:     my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9       raeburn  5396:     my ($output,$fname,$logourl);
                   5397:     if ($action eq 'upload') {
                   5398:         $fname=$env{'form.'.$formname.'.filename'};
                   5399:         chop($env{'form.'.$formname});
                   5400:     } else {
                   5401:         ($fname) = ($formname =~ /([^\/]+)$/);
                   5402:     }
1.46      raeburn  5403:     if ($savefileas ne '') {
                   5404:         $fname = $savefileas;
                   5405:     }
1.9       raeburn  5406:     $fname=&Apache::lonnet::clean_filename($fname);
                   5407: # See if there is anything left
                   5408:     unless ($fname) { return ('error: no uploaded file'); }
                   5409:     $fname="$subdir/$fname";
1.164     raeburn  5410:     my $docroot=$r->dir_config('lonDocRoot'); 
                   5411:     my $filepath="$docroot/priv";
                   5412:     my $relpath = "$dom/$confname";
1.9       raeburn  5413:     my ($fnamepath,$file,$fetchthumb);
                   5414:     $file=$fname;
                   5415:     if ($fname=~m|/|) {
                   5416:         ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
                   5417:     }
1.164     raeburn  5418:     my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9       raeburn  5419:     my $count;
1.164     raeburn  5420:     for ($count=5;$count<=$#parts;$count++) {
1.9       raeburn  5421:         $filepath.="/$parts[$count]";
                   5422:         if ((-e $filepath)!=1) {
                   5423:             mkdir($filepath,02770);
                   5424:         }
                   5425:     }
                   5426:     # Check for bad extension and disallow upload
                   5427:     if ($file=~/\.(\w+)$/ &&
                   5428:         (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
                   5429:         $output = 
                   5430:             &mt('Invalid file extension ([_1]) - reserved for LONCAPA use.',$1); 
                   5431:     } elsif ($file=~/\.(\w+)$/ &&
                   5432:         !defined(&Apache::loncommon::fileembstyle($1))) {
                   5433:         $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
                   5434:     } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.46      raeburn  5435:         $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  5436:     } elsif (-d "$filepath/$file") {
                   5437:         $output = &mt('File name is a directory name - rename the file and re-upload');
                   5438:     } else {
                   5439:         my $source = $filepath.'/'.$file;
                   5440:         my $logfile;
                   5441:         if (!open($logfile,">>$source".'.log')) {
                   5442:             return (&mt('No write permission to Construction Space'));
                   5443:         }
                   5444:         print $logfile
                   5445: "\n================= Publish ".localtime()." ================\n".
                   5446: $env{'user.name'}.':'.$env{'user.domain'}."\n";
                   5447: # Save the file
                   5448:         if (!open(FH,'>'.$source)) {
                   5449:             &Apache::lonnet::logthis('Failed to create '.$source);
                   5450:             return (&mt('Failed to create file'));
                   5451:         }
                   5452:         if ($action eq 'upload') {
                   5453:             if (!print FH ($env{'form.'.$formname})) {
                   5454:                 &Apache::lonnet::logthis('Failed to write to '.$source);
                   5455:                 return (&mt('Failed to write file'));
                   5456:             }
                   5457:         } else {
                   5458:             my $original = &Apache::lonnet::filelocation('',$formname);
                   5459:             if(!copy($original,$source)) {
                   5460:                 &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
                   5461:                 return (&mt('Failed to write file'));
                   5462:             }
                   5463:         }
                   5464:         close(FH);
                   5465:         chmod(0660, $source); # Permissions to rw-rw---.
                   5466: 
                   5467:         my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
                   5468:         my $copyfile=$targetdir.'/'.$file;
                   5469: 
                   5470:         my @parts=split(/\//,$targetdir);
                   5471:         my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
                   5472:         for (my $count=5;$count<=$#parts;$count++) {
                   5473:             $path.="/$parts[$count]";
                   5474:             if (!-e $path) {
                   5475:                 print $logfile "\nCreating directory ".$path;
                   5476:                 mkdir($path,02770);
                   5477:             }
                   5478:         }
                   5479:         my $versionresult;
                   5480:         if (-e $copyfile) {
                   5481:             $versionresult = &logo_versioning($targetdir,$file,$logfile);
                   5482:         } else {
                   5483:             $versionresult = 'ok';
                   5484:         }
                   5485:         if ($versionresult eq 'ok') {
                   5486:             if (copy($source,$copyfile)) {
                   5487:                 print $logfile "\nCopied original source to ".$copyfile."\n";
                   5488:                 $output = 'ok';
                   5489:                 $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155     raeburn  5490:                 push(@{$modified_urls},[$copyfile,$source]);
                   5491:                 my $metaoutput = 
                   5492:                     &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
                   5493:                 unless ($registered_cleanup) {
                   5494:                     my $handlers = $r->get_handlers('PerlCleanupHandler');
                   5495:                     $r->set_handlers('PerlCleanupHandler' => [\&notifysubscribed,@{$handlers}]);
                   5496:                     $registered_cleanup=1;
                   5497:                 }
1.9       raeburn  5498:             } else {
                   5499:                 print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
                   5500:                 $output = &mt('Failed to copy file to RES space').", $!";
                   5501:             }
                   5502:             if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
                   5503:                 my $inputfile = $filepath.'/'.$file;
                   5504:                 my $outfile = $filepath.'/'.'tn-'.$file;
1.16      raeburn  5505:                 my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
                   5506:                 if ($fullwidth ne '' && $fullheight ne '') { 
                   5507:                     if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
                   5508:                         my $thumbsize = $thumbwidth.'x'.$thumbheight;
                   5509:                         system("convert -sample $thumbsize $inputfile $outfile");
                   5510:                         chmod(0660, $filepath.'/tn-'.$file);
                   5511:                         if (-e $outfile) {
                   5512:                             my $copyfile=$targetdir.'/tn-'.$file;
                   5513:                             if (copy($outfile,$copyfile)) {
                   5514:                                 print $logfile "\nCopied source to ".$copyfile."\n";
1.155     raeburn  5515:                                 my $thumb_metaoutput = 
                   5516:                                     &write_metadata($dom,$confname,$formname,
                   5517:                                                     $targetdir,'tn-'.$file,$logfile);
                   5518:                                 push(@{$modified_urls},[$copyfile,$outfile]);
                   5519:                                 unless ($registered_cleanup) {
                   5520:                                     my $handlers = $r->get_handlers('PerlCleanupHandler');
                   5521:                                     $r->set_handlers('PerlCleanupHandler' => [\&notifysubscribed,@{$handlers}]);
                   5522:                                     $registered_cleanup=1;
                   5523:                                 }
1.16      raeburn  5524:                             } else {
                   5525:                                 print $logfile "\nUnable to write ".$copyfile.
                   5526:                                                ':'.$!."\n";
                   5527:                             }
                   5528:                         }
1.9       raeburn  5529:                     }
                   5530:                 }
                   5531:             }
                   5532:         } else {
                   5533:             $output = $versionresult;
                   5534:         }
                   5535:     }
                   5536:     return ($output,$logourl);
                   5537: }
                   5538: 
                   5539: sub logo_versioning {
                   5540:     my ($targetdir,$file,$logfile) = @_;
                   5541:     my $target = $targetdir.'/'.$file;
                   5542:     my ($maxversion,$fn,$extn,$output);
                   5543:     $maxversion = 0;
                   5544:     if ($file =~ /^(.+)\.(\w+)$/) {
                   5545:         $fn=$1;
                   5546:         $extn=$2;
                   5547:     }
                   5548:     opendir(DIR,$targetdir);
                   5549:     while (my $filename=readdir(DIR)) {
                   5550:         if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
                   5551:             $maxversion=($1>$maxversion)?$1:$maxversion;
                   5552:         }
                   5553:     }
                   5554:     $maxversion++;
                   5555:     print $logfile "\nCreating old version ".$maxversion."\n";
                   5556:     my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
                   5557:     if (copy($target,$copyfile)) {
                   5558:         print $logfile "Copied old target to ".$copyfile."\n";
                   5559:         $copyfile=$copyfile.'.meta';
                   5560:         if (copy($target.'.meta',$copyfile)) {
                   5561:             print $logfile "Copied old target metadata to ".$copyfile."\n";
                   5562:             $output = 'ok';
                   5563:         } else {
                   5564:             print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
                   5565:             $output = &mt('Failed to copy old meta').", $!, ";
                   5566:         }
                   5567:     } else {
                   5568:         print $logfile "Unable to write ".$copyfile.':'.$!."\n";
                   5569:         $output = &mt('Failed to copy old target').", $!, ";
                   5570:     }
                   5571:     return $output;
                   5572: }
                   5573: 
                   5574: sub write_metadata {
                   5575:     my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
                   5576:     my (%metadatafields,%metadatakeys,$output);
                   5577:     $metadatafields{'title'}=$formname;
                   5578:     $metadatafields{'creationdate'}=time;
                   5579:     $metadatafields{'lastrevisiondate'}=time;
                   5580:     $metadatafields{'copyright'}='public';
                   5581:     $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
                   5582:                                          $env{'user.domain'};
                   5583:     $metadatafields{'authorspace'}=$confname.':'.$dom;
                   5584:     $metadatafields{'domain'}=$dom;
                   5585:     {
                   5586:         print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
                   5587:         my $mfh;
1.155     raeburn  5588:         if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
                   5589:             foreach (sort keys %metadatafields) {
                   5590:                 unless ($_=~/\./) {
                   5591:                     my $unikey=$_;
                   5592:                     $unikey=~/^([A-Za-z]+)/;
                   5593:                     my $tag=$1;
                   5594:                     $tag=~tr/A-Z/a-z/;
                   5595:                     print $mfh "\n\<$tag";
                   5596:                     foreach (split(/\,/,$metadatakeys{$unikey})) {
                   5597:                         my $value=$metadatafields{$unikey.'.'.$_};
                   5598:                         $value=~s/\"/\'\'/g;
                   5599:                         print $mfh ' '.$_.'="'.$value.'"';
                   5600:                     }
                   5601:                     print $mfh '>'.
                   5602:                         &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
                   5603:                             .'</'.$tag.'>';
                   5604:                 }
                   5605:             }
                   5606:             $output = 'ok';
                   5607:             print $logfile "\nWrote metadata";
                   5608:             close($mfh);
                   5609:         } else {
                   5610:             print $logfile "\nFailed to open metadata file";
1.9       raeburn  5611:             $output = &mt('Could not write metadata');
                   5612:         }
                   5613:     }
1.155     raeburn  5614:     return $output;
                   5615: }
                   5616: 
                   5617: sub notifysubscribed {
                   5618:     foreach my $targetsource (@{$modified_urls}){
                   5619:         next unless (ref($targetsource) eq 'ARRAY');
                   5620:         my ($target,$source)=@{$targetsource};
                   5621:         if ($source ne '') {
                   5622:             if (open(my $logfh,'>>'.$source.'.log')) {
                   5623:                 print $logfh "\nCleanup phase: Notifications\n";
                   5624:                 my @subscribed=&subscribed_hosts($target);
                   5625:                 foreach my $subhost (@subscribed) {
                   5626:                     print $logfh "\nNotifying host ".$subhost.':';
                   5627:                     my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
                   5628:                     print $logfh $reply;
                   5629:                 }
                   5630:                 my @subscribedmeta=&subscribed_hosts("$target.meta");
                   5631:                 foreach my $subhost (@subscribedmeta) {
                   5632:                     print $logfh "\nNotifying host for metadata only ".$subhost.':';
                   5633:                     my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
                   5634:                                                         $subhost);
                   5635:                     print $logfh $reply;
                   5636:                 }
                   5637:                 print $logfh "\n============ Done ============\n";
1.160     raeburn  5638:                 close($logfh);
1.155     raeburn  5639:             }
                   5640:         }
                   5641:     }
                   5642:     return OK;
                   5643: }
                   5644: 
                   5645: sub subscribed_hosts {
                   5646:     my ($target) = @_;
                   5647:     my @subscribed;
                   5648:     if (open(my $fh,"<$target.subscription")) {
                   5649:         while (my $subline=<$fh>) {
                   5650:             if ($subline =~ /^($match_lonid):/) {
                   5651:                 my $host = $1;
                   5652:                 if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
                   5653:                     unless (grep(/^\Q$host\E$/,@subscribed)) {
                   5654:                         push(@subscribed,$host);
                   5655:                     }
                   5656:                 }
                   5657:             }
                   5658:         }
                   5659:     }
                   5660:     return @subscribed;
1.9       raeburn  5661: }
                   5662: 
                   5663: sub check_switchserver {
                   5664:     my ($dom,$confname) = @_;
                   5665:     my ($allowed,$switchserver);
                   5666:     my $home = &Apache::lonnet::homeserver($confname,$dom);
                   5667:     if ($home eq 'no_host') {
                   5668:         $home = &Apache::lonnet::domain($dom,'primary');
                   5669:     }
                   5670:     my @ids=&Apache::lonnet::current_machine_ids();
1.10      albertel 5671:     foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
                   5672:     if (!$allowed) {
                   5673: 	$switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/">'.&mt('Switch Server').'</a>';
1.9       raeburn  5674:     }
                   5675:     return $switchserver;
                   5676: }
                   5677: 
1.1       raeburn  5678: sub modify_quotas {
1.86      raeburn  5679:     my ($dom,$action,%domconfig) = @_;
1.101     raeburn  5680:     my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
                   5681:         %limithash,$toolregexp,%conditions,$resulttext,%changes);
1.86      raeburn  5682:     if ($action eq 'quotas') {
                   5683:         $context = 'tools'; 
1.163     raeburn  5684:     } else {
1.86      raeburn  5685:         $context = $action;
                   5686:     }
                   5687:     if ($context eq 'requestcourses') {
1.98      raeburn  5688:         @usertools = ('official','unofficial','community');
1.106     raeburn  5689:         @options =('norequest','approval','validate','autolimit');
1.101     raeburn  5690:         %validations = &Apache::lonnet::auto_courserequest_checks($dom);
                   5691:         %titles = &courserequest_titles();
                   5692:         $toolregexp = join('|',@usertools);
                   5693:         %conditions = &courserequest_conditions();
1.163     raeburn  5694:     } elsif ($context eq 'requestauthor') {
                   5695:         @usertools = ('author');
                   5696:         %titles = &authorrequest_titles();
1.86      raeburn  5697:     } else {
1.162     raeburn  5698:         @usertools = ('aboutme','blog','webdav','portfolio');
1.101     raeburn  5699:         %titles = &tool_titles();
1.86      raeburn  5700:     }
1.72      raeburn  5701:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.44      raeburn  5702:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1       raeburn  5703:     foreach my $key (keys(%env)) {
1.101     raeburn  5704:         if ($context eq 'requestcourses') {
                   5705:             if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
                   5706:                 my $item = $1;
                   5707:                 my $type = $2;
                   5708:                 if ($type =~ /^limit_(.+)/) {
                   5709:                     $limithash{$item}{$1} = $env{$key};
                   5710:                 } else {
                   5711:                     $confhash{$item}{$type} = $env{$key};
                   5712:                 }
                   5713:             }
1.163     raeburn  5714:         } elsif ($context eq 'requestauthor') {
                   5715:             if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
                   5716:                 $confhash{$1} = $env{$key};
                   5717:             }
1.101     raeburn  5718:         } else {
1.86      raeburn  5719:             if ($key =~ /^form\.quota_(.+)$/) {
                   5720:                 $confhash{'defaultquota'}{$1} = $env{$key};
                   5721:             }
1.101     raeburn  5722:             if ($key =~ /^form\.\Q$context\E_(.+)$/) {
                   5723:                 @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
                   5724:             }
1.72      raeburn  5725:         }
                   5726:     }
1.163     raeburn  5727:     if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.102     raeburn  5728:         my @approvalnotify = &Apache::loncommon::get_env_multiple('form.reqapprovalnotify');
                   5729:         @approvalnotify = sort(@approvalnotify);
                   5730:         $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
                   5731:         if (ref($domconfig{$action}) eq 'HASH') {
                   5732:             if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
                   5733:                 if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
                   5734:                     $changes{'notify'}{'approval'} = 1;
                   5735:                 }
                   5736:             } else {
1.144     raeburn  5737:                 if ($confhash{'notify'}{'approval'}) {
1.102     raeburn  5738:                     $changes{'notify'}{'approval'} = 1;
                   5739:                 }
                   5740:             }
                   5741:         } else {
1.144     raeburn  5742:             if ($confhash{'notify'}{'approval'}) {
1.102     raeburn  5743:                 $changes{'notify'}{'approval'} = 1;
                   5744:             }
                   5745:         }
                   5746:     } else {
1.86      raeburn  5747:         $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
                   5748:     }
1.72      raeburn  5749:     foreach my $item (@usertools) {
                   5750:         foreach my $type (@{$types},'default','_LC_adv') {
1.104     raeburn  5751:             my $unset; 
1.101     raeburn  5752:             if ($context eq 'requestcourses') {
1.104     raeburn  5753:                 $unset = '0';
                   5754:                 if ($type eq '_LC_adv') {
                   5755:                     $unset = '';
                   5756:                 }
1.101     raeburn  5757:                 if ($confhash{$item}{$type} eq 'autolimit') {
                   5758:                     $confhash{$item}{$type} .= '=';
                   5759:                     unless ($limithash{$item}{$type} =~ /\D/) {
                   5760:                         $confhash{$item}{$type} .= $limithash{$item}{$type};
                   5761:                     }
                   5762:                 }
1.163     raeburn  5763:             } elsif ($context eq 'requestauthor') {
                   5764:                 $unset = '0';
                   5765:                 if ($type eq '_LC_adv') {
                   5766:                     $unset = '';
                   5767:                 }
1.72      raeburn  5768:             } else {
1.101     raeburn  5769:                 if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
                   5770:                     $confhash{$item}{$type} = 1;
                   5771:                 } else {
                   5772:                     $confhash{$item}{$type} = 0;
                   5773:                 }
1.72      raeburn  5774:             }
1.86      raeburn  5775:             if (ref($domconfig{$action}) eq 'HASH') {
1.163     raeburn  5776:                 if ($action eq 'requestauthor') {
                   5777:                     if ($domconfig{$action}{$type} ne $confhash{$type}) {
                   5778:                         $changes{$type} = 1;
                   5779:                     }
                   5780:                 } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86      raeburn  5781:                     if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
                   5782:                         $changes{$item}{$type} = 1;
                   5783:                     }
                   5784:                 } else {
                   5785:                     if ($context eq 'requestcourses') {
1.104     raeburn  5786:                         if ($confhash{$item}{$type} ne $unset) {
1.86      raeburn  5787:                             $changes{$item}{$type} = 1;
                   5788:                         }
                   5789:                     } else {
                   5790:                         if (!$confhash{$item}{$type}) {
                   5791:                             $changes{$item}{$type} = 1;
                   5792:                         }
                   5793:                     }
                   5794:                 }
                   5795:             } else {
                   5796:                 if ($context eq 'requestcourses') {
1.104     raeburn  5797:                     if ($confhash{$item}{$type} ne $unset) {
1.72      raeburn  5798:                         $changes{$item}{$type} = 1;
                   5799:                     }
1.163     raeburn  5800:                 } elsif ($context eq 'requestauthor') {
                   5801:                     if ($confhash{$type} ne $unset) {
                   5802:                         $changes{$type} = 1;
                   5803:                     }
1.72      raeburn  5804:                 } else {
                   5805:                     if (!$confhash{$item}{$type}) {
                   5806:                         $changes{$item}{$type} = 1;
                   5807:                     }
                   5808:                 }
                   5809:             }
1.1       raeburn  5810:         }
                   5811:     }
1.163     raeburn  5812:     unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86      raeburn  5813:         if (ref($domconfig{'quotas'}) eq 'HASH') {
                   5814:             if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
                   5815:                 foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
                   5816:                     if (exists($confhash{'defaultquota'}{$key})) {
                   5817:                         if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
                   5818:                             $changes{'defaultquota'}{$key} = 1;
                   5819:                         }
                   5820:                     } else {
                   5821:                         $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72      raeburn  5822:                     }
                   5823:                 }
1.86      raeburn  5824:             } else {
                   5825:                 foreach my $key (keys(%{$domconfig{'quotas'}})) {
                   5826:                     if (exists($confhash{'defaultquota'}{$key})) {
                   5827:                         if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
                   5828:                             $changes{'defaultquota'}{$key} = 1;
                   5829:                         }
                   5830:                     } else {
                   5831:                         $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72      raeburn  5832:                     }
1.1       raeburn  5833:                 }
                   5834:             }
                   5835:         }
1.86      raeburn  5836:         if (ref($confhash{'defaultquota'}) eq 'HASH') {
                   5837:             foreach my $key (keys(%{$confhash{'defaultquota'}})) {
                   5838:                 if (ref($domconfig{'quotas'}) eq 'HASH') {
                   5839:                     if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
                   5840:                         if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
                   5841:                             $changes{'defaultquota'}{$key} = 1;
                   5842:                         }
                   5843:                     } else {
                   5844:                         if (!exists($domconfig{'quotas'}{$key})) {
                   5845:                             $changes{'defaultquota'}{$key} = 1;
                   5846:                         }
1.72      raeburn  5847:                     }
                   5848:                 } else {
1.86      raeburn  5849:                     $changes{'defaultquota'}{$key} = 1;
1.55      raeburn  5850:                 }
1.1       raeburn  5851:             }
                   5852:         }
                   5853:     }
1.72      raeburn  5854: 
1.163     raeburn  5855:     if ($context eq 'requestauthor') {
                   5856:         $domdefaults{'requestauthor'} = \%confhash;
                   5857:     } else {
                   5858:         foreach my $key (keys(%confhash)) {
                   5859:             $domdefaults{$key} = $confhash{$key};
                   5860:         }
1.72      raeburn  5861:     }
1.163     raeburn  5862: 
1.1       raeburn  5863:     my %quotahash = (
1.86      raeburn  5864:                       $action => { %confhash }
1.1       raeburn  5865:                     );
                   5866:     my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
                   5867:                                              $dom);
                   5868:     if ($putresult eq 'ok') {
                   5869:         if (keys(%changes) > 0) {
1.72      raeburn  5870:             my $cachetime = 24*60*60;
                   5871:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
                   5872: 
1.1       raeburn  5873:             $resulttext = &mt('Changes made:').'<ul>';
1.163     raeburn  5874:             unless (($context eq 'requestcourses') || 
                   5875:                     ($context eq 'requestauthor')) {
1.86      raeburn  5876:                 if (ref($changes{'defaultquota'}) eq 'HASH') {
                   5877:                     $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
                   5878:                     foreach my $type (@{$types},'default') {
                   5879:                         if (defined($changes{'defaultquota'}{$type})) {
                   5880:                             my $typetitle = $usertypes->{$type};
                   5881:                             if ($type eq 'default') {
                   5882:                                 $typetitle = $othertitle;
                   5883:                             }
                   5884:                             $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72      raeburn  5885:                         }
                   5886:                     }
1.86      raeburn  5887:                     $resulttext .= '</ul></li>';
1.72      raeburn  5888:                 }
                   5889:             }
1.80      raeburn  5890:             my %newenv;
1.72      raeburn  5891:             foreach my $item (@usertools) {
1.163     raeburn  5892:                 my (%haschgs,%inconf);
                   5893:                 if ($context eq 'requestauthor') {
                   5894:                     %haschgs = %changes;
                   5895:                     %inconf = %confhash; 
                   5896:                 } else {
                   5897:                     if (ref($changes{$item}) eq 'HASH') {
                   5898:                         %haschgs = %{$changes{$item}};
                   5899:                     }
                   5900:                     if (ref($confhash{$item}) eq 'HASH') {
                   5901:                         %inconf = %{$confhash{$item}};
                   5902:                     }
                   5903:                 }
                   5904:                 if (keys(%haschgs) > 0) {
1.80      raeburn  5905:                     my $newacc = 
                   5906:                         &Apache::lonnet::usertools_access($env{'user.name'},
                   5907:                                                           $env{'user.domain'},
1.86      raeburn  5908:                                                           $item,'reload',$context);
1.163     raeburn  5909:                     if (($context eq 'requestcourses') || 
                   5910:                         ($context eq 'requestauthor')) {
1.108     raeburn  5911:                         if ($env{'environment.canrequest.'.$item} ne $newacc) {
                   5912:                             $newenv{'environment.canrequest.'.$item} = $newacc;
1.86      raeburn  5913:                         }
                   5914:                     } else {
                   5915:                         if ($env{'environment.availabletools.'.$item} ne $newacc) { 
                   5916:                             $newenv{'environment.availabletools.'.$item} = $newacc;
                   5917:                         }
1.80      raeburn  5918:                     }
1.163     raeburn  5919:                     unless ($context eq 'requestauthor') {
                   5920:                         $resulttext .= '<li>'.$titles{$item}.'<ul>';
                   5921:                     }
1.72      raeburn  5922:                     foreach my $type (@{$types},'default','_LC_adv') {
1.163     raeburn  5923:                         if ($haschgs{$type}) {
1.72      raeburn  5924:                             my $typetitle = $usertypes->{$type};
                   5925:                             if ($type eq 'default') {
                   5926:                                 $typetitle = $othertitle;
                   5927:                             } elsif ($type eq '_LC_adv') {
                   5928:                                 $typetitle = 'LON-CAPA Advanced Users'; 
                   5929:                             }
1.163     raeburn  5930:                             if ($inconf{$type}) {
1.101     raeburn  5931:                                 if ($context eq 'requestcourses') {
                   5932:                                     my $cond;
1.163     raeburn  5933:                                     if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101     raeburn  5934:                                         if ($1 eq '') {
                   5935:                                             $cond = &mt('(Automatic processing of any request).');
                   5936:                                         } else {
                   5937:                                             $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
                   5938:                                         }
                   5939:                                     } else { 
1.163     raeburn  5940:                                         $cond = $conditions{$inconf{$type}};
1.101     raeburn  5941:                                     }
                   5942:                                     $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172     raeburn  5943:                                 } elsif ($context eq 'requestauthor') {
                   5944:                                     $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
                   5945:                                                              $titles{$inconf{$type}},$typetitle);
                   5946: 
1.101     raeburn  5947:                                 } else {
                   5948:                                     $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
                   5949:                                 }
1.72      raeburn  5950:                             } else {
1.104     raeburn  5951:                                 if ($type eq '_LC_adv') {
1.163     raeburn  5952:                                     if ($inconf{$type} eq '0') {
1.104     raeburn  5953:                                         $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
                   5954:                                     } else { 
                   5955:                                         $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
                   5956:                                     }
                   5957:                                 } else {
                   5958:                                     $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
                   5959:                                 }
1.72      raeburn  5960:                             }
                   5961:                         }
1.26      raeburn  5962:                     }
1.163     raeburn  5963:                     unless ($context eq 'requestauthor') {
                   5964:                         $resulttext .= '</ul></li>';
                   5965:                     }
1.26      raeburn  5966:                 }
1.1       raeburn  5967:             }
1.163     raeburn  5968:             if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102     raeburn  5969:                 if (ref($changes{'notify'}) eq 'HASH') {
                   5970:                     if ($changes{'notify'}{'approval'}) {
                   5971:                         if (ref($confhash{'notify'}) eq 'HASH') {
                   5972:                             if ($confhash{'notify'}{'approval'}) {
                   5973:                                 $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
                   5974:                             } else {
1.163     raeburn  5975:                                 $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102     raeburn  5976:                             }
                   5977:                         }
                   5978:                     }
                   5979:                 }
                   5980:             }
1.1       raeburn  5981:             $resulttext .= '</ul>';
1.80      raeburn  5982:             if (keys(%newenv)) {
                   5983:                 &Apache::lonnet::appenv(\%newenv);
                   5984:             }
1.1       raeburn  5985:         } else {
1.86      raeburn  5986:             if ($context eq 'requestcourses') {
                   5987:                 $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163     raeburn  5988:             } elsif ($context eq 'requestauthor') {
                   5989:                 $resulttext = &mt('No changes made to rights to request author space.');
1.86      raeburn  5990:             } else {
1.90      weissno  5991:                 $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86      raeburn  5992:             }
1.1       raeburn  5993:         }
                   5994:     } else {
1.11      albertel 5995:         $resulttext = '<span class="LC_error">'.
                   5996: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  5997:     }
1.3       raeburn  5998:     return $resulttext;
1.1       raeburn  5999: }
                   6000: 
1.3       raeburn  6001: sub modify_autoenroll {
                   6002:     my ($dom,%domconfig) = @_;
1.1       raeburn  6003:     my ($resulttext,%changes);
                   6004:     my %currautoenroll;
                   6005:     if (ref($domconfig{'autoenroll'}) eq 'HASH') {
                   6006:         foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
                   6007:             $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
                   6008:         }
                   6009:     }
                   6010:     my $autorun = &Apache::lonnet::auto_run(undef,$dom),
                   6011:     my %title = ( run => 'Auto-enrollment active',
1.129     raeburn  6012:                   sender => 'Sender for notification messages',
                   6013:                   coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)');
1.1       raeburn  6014:     my @offon = ('off','on');
1.17      raeburn  6015:     my $sender_uname = $env{'form.sender_uname'};
                   6016:     my $sender_domain = $env{'form.sender_domain'};
                   6017:     if ($sender_domain eq '') {
                   6018:         $sender_uname = '';
                   6019:     } elsif ($sender_uname eq '') {
                   6020:         $sender_domain = '';
                   6021:     }
1.129     raeburn  6022:     my $coowners = $env{'form.autoassign_coowners'};
1.1       raeburn  6023:     my %autoenrollhash =  (
1.129     raeburn  6024:                        autoenroll => { 'run' => $env{'form.autoenroll_run'},
                   6025:                                        'sender_uname' => $sender_uname,
                   6026:                                        'sender_domain' => $sender_domain,
                   6027:                                        'co-owners' => $coowners,
1.1       raeburn  6028:                                 }
                   6029:                      );
1.4       raeburn  6030:     my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
                   6031:                                              $dom);
1.1       raeburn  6032:     if ($putresult eq 'ok') {
                   6033:         if (exists($currautoenroll{'run'})) {
                   6034:              if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
                   6035:                  $changes{'run'} = 1;
                   6036:              }
                   6037:         } elsif ($autorun) {
                   6038:             if ($env{'form.autoenroll_run'} ne '1') {
1.23      raeburn  6039:                  $changes{'run'} = 1;
1.1       raeburn  6040:             }
                   6041:         }
1.17      raeburn  6042:         if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1       raeburn  6043:             $changes{'sender'} = 1;
                   6044:         }
1.17      raeburn  6045:         if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1       raeburn  6046:             $changes{'sender'} = 1;
                   6047:         }
1.129     raeburn  6048:         if ($currautoenroll{'co-owners'} ne '') {
                   6049:             if ($currautoenroll{'co-owners'} ne $coowners) {
                   6050:                 $changes{'coowners'} = 1;
                   6051:             }
                   6052:         } elsif ($coowners) {
                   6053:             $changes{'coowners'} = 1;
                   6054:         }      
1.1       raeburn  6055:         if (keys(%changes) > 0) {
                   6056:             $resulttext = &mt('Changes made:').'<ul>';
1.3       raeburn  6057:             if ($changes{'run'}) {
1.1       raeburn  6058:                 $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
                   6059:             }
                   6060:             if ($changes{'sender'}) {
1.17      raeburn  6061:                 if ($sender_uname eq '' || $sender_domain eq '') {
                   6062:                     $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
                   6063:                 } else {
                   6064:                     $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
                   6065:                 }
1.1       raeburn  6066:             }
1.129     raeburn  6067:             if ($changes{'coowners'}) {
                   6068:                 $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
                   6069:                 &Apache::loncommon::devalidate_domconfig_cache($dom);
                   6070:             }
1.1       raeburn  6071:             $resulttext .= '</ul>';
                   6072:         } else {
                   6073:             $resulttext = &mt('No changes made to auto-enrollment settings');
                   6074:         }
                   6075:     } else {
1.11      albertel 6076:         $resulttext = '<span class="LC_error">'.
                   6077: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  6078:     }
1.3       raeburn  6079:     return $resulttext;
1.1       raeburn  6080: }
                   6081: 
                   6082: sub modify_autoupdate {
1.3       raeburn  6083:     my ($dom,%domconfig) = @_;
1.1       raeburn  6084:     my ($resulttext,%currautoupdate,%fields,%changes);
                   6085:     if (ref($domconfig{'autoupdate'}) eq 'HASH') {
                   6086:         foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
                   6087:             $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
                   6088:         }
                   6089:     }
                   6090:     my @offon = ('off','on');
                   6091:     my %title = &Apache::lonlocal::texthash (
                   6092:                    run => 'Auto-update:',
                   6093:                    classlists => 'Updates to user information in classlists?'
                   6094:                 );
1.44      raeburn  6095:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1       raeburn  6096:     my %fieldtitles = &Apache::lonlocal::texthash (
                   6097:                         id => 'Student/Employee ID',
1.20      raeburn  6098:                         permanentemail => 'E-mail address',
1.1       raeburn  6099:                         lastname => 'Last Name',
                   6100:                         firstname => 'First Name',
                   6101:                         middlename => 'Middle Name',
1.132     raeburn  6102:                         generation => 'Generation',
1.1       raeburn  6103:                       );
1.142     raeburn  6104:     $othertitle = &mt('All users');
1.1       raeburn  6105:     if (keys(%{$usertypes}) >  0) {
1.26      raeburn  6106:         $othertitle = &mt('Other users');
1.1       raeburn  6107:     }
                   6108:     foreach my $key (keys(%env)) {
                   6109:         if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132     raeburn  6110:             my ($usertype,$item) = ($1,$2);
                   6111:             if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
                   6112:                 if ($usertype eq 'default') {   
                   6113:                     push(@{$fields{$1}},$2);
                   6114:                 } elsif (ref($types) eq 'ARRAY') {
                   6115:                     if (grep(/^\Q$usertype\E$/,@{$types})) {
                   6116:                         push(@{$fields{$1}},$2);
                   6117:                     }
                   6118:                 }
                   6119:             }
1.1       raeburn  6120:         }
                   6121:     }
1.131     raeburn  6122:     my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
                   6123:     @lockablenames = sort(@lockablenames);
                   6124:     if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
                   6125:         my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
                   6126:         if (@changed) {
                   6127:             $changes{'lockablenames'} = 1;
                   6128:         }
                   6129:     } else {
                   6130:         if (@lockablenames) {
                   6131:             $changes{'lockablenames'} = 1;
                   6132:         }
                   6133:     }
1.1       raeburn  6134:     my %updatehash = (
                   6135:                       autoupdate => { run => $env{'form.autoupdate_run'},
                   6136:                                       classlists => $env{'form.classlists'},
                   6137:                                       fields => {%fields},
1.131     raeburn  6138:                                       lockablenames => \@lockablenames,
1.1       raeburn  6139:                                     }
                   6140:                      );
                   6141:     foreach my $key (keys(%currautoupdate)) {
                   6142:         if (($key eq 'run') || ($key eq 'classlists')) {
                   6143:             if (exists($updatehash{autoupdate}{$key})) {
                   6144:                 if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
                   6145:                     $changes{$key} = 1;
                   6146:                 }
                   6147:             }
                   6148:         } elsif ($key eq 'fields') {
                   6149:             if (ref($currautoupdate{$key}) eq 'HASH') {
1.26      raeburn  6150:                 foreach my $item (@{$types},'default') {
1.1       raeburn  6151:                     if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
                   6152:                         my $change = 0;
                   6153:                         foreach my $type (@{$currautoupdate{$key}{$item}}) {
                   6154:                             if (!exists($fields{$item})) {
                   6155:                                 $change = 1;
1.132     raeburn  6156:                                 last;
1.1       raeburn  6157:                             } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26      raeburn  6158:                                 if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1       raeburn  6159:                                     $change = 1;
1.132     raeburn  6160:                                     last;
1.1       raeburn  6161:                                 }
                   6162:                             }
                   6163:                         }
                   6164:                         if ($change) {
                   6165:                             push(@{$changes{$key}},$item);
                   6166:                         }
1.26      raeburn  6167:                     } 
1.1       raeburn  6168:                 }
                   6169:             }
1.131     raeburn  6170:         } elsif ($key eq 'lockablenames') {
                   6171:             if (ref($currautoupdate{$key}) eq 'ARRAY') {
                   6172:                 my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
                   6173:                 if (@changed) {
                   6174:                     $changes{'lockablenames'} = 1;
                   6175:                 }
                   6176:             } else {
                   6177:                 if (@lockablenames) {
                   6178:                     $changes{'lockablenames'} = 1;
                   6179:                 }
                   6180:             }
                   6181:         }
                   6182:     }
                   6183:     unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
                   6184:         if (@lockablenames) {
                   6185:             $changes{'lockablenames'} = 1;
1.1       raeburn  6186:         }
                   6187:     }
1.26      raeburn  6188:     foreach my $item (@{$types},'default') {
                   6189:         if (defined($fields{$item})) {
                   6190:             if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132     raeburn  6191:                 if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
                   6192:                     my $change = 0;
                   6193:                     if (ref($fields{$item}) eq 'ARRAY') {
                   6194:                         foreach my $type (@{$fields{$item}}) {
                   6195:                             if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
                   6196:                                 $change = 1;
                   6197:                                 last;
                   6198:                             }
                   6199:                         }
                   6200:                     }
                   6201:                     if ($change) {
                   6202:                         push(@{$changes{'fields'}},$item);
                   6203:                     }
                   6204:                 } else {
1.26      raeburn  6205:                     push(@{$changes{'fields'}},$item);
                   6206:                 }
                   6207:             } else {
                   6208:                 push(@{$changes{'fields'}},$item);
1.1       raeburn  6209:             }
                   6210:         }
                   6211:     }
                   6212:     my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
                   6213:                                              $dom);
                   6214:     if ($putresult eq 'ok') {
                   6215:         if (keys(%changes) > 0) {
                   6216:             $resulttext = &mt('Changes made:').'<ul>';
                   6217:             foreach my $key (sort(keys(%changes))) {
1.131     raeburn  6218:                 if ($key eq 'lockablenames') {
                   6219:                     $resulttext .= '<li>';
                   6220:                     if (@lockablenames) {
                   6221:                         $usertypes->{'default'} = $othertitle;
                   6222:                         $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
                   6223:                                    join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
                   6224:                     } else {
                   6225:                         $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
                   6226:                     }
                   6227:                     $resulttext .= '</li>';
                   6228:                 } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1       raeburn  6229:                     foreach my $item (@{$changes{$key}}) {
                   6230:                         my @newvalues;
                   6231:                         foreach my $type (@{$fields{$item}}) {
                   6232:                             push(@newvalues,$fieldtitles{$type});
                   6233:                         }
1.3       raeburn  6234:                         my $newvaluestr;
                   6235:                         if (@newvalues > 0) {
                   6236:                             $newvaluestr = join(', ',@newvalues);
                   6237:                         } else {
                   6238:                             $newvaluestr = &mt('none');
1.6       raeburn  6239:                         }
1.1       raeburn  6240:                         if ($item eq 'default') {
1.26      raeburn  6241:                             $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1       raeburn  6242:                         } else {
1.26      raeburn  6243:                             $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1       raeburn  6244:                         }
                   6245:                     }
                   6246:                 } else {
                   6247:                     my $newvalue;
                   6248:                     if ($key eq 'run') {
                   6249:                         $newvalue = $offon[$env{'form.autoupdate_run'}];
                   6250:                     } else {
                   6251:                         $newvalue = $offon[$env{'form.'.$key}];
1.3       raeburn  6252:                     }
1.1       raeburn  6253:                     $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
                   6254:                 }
                   6255:             }
                   6256:             $resulttext .= '</ul>';
                   6257:         } else {
1.3       raeburn  6258:             $resulttext = &mt('No changes made to autoupdates');
1.1       raeburn  6259:         }
                   6260:     } else {
1.11      albertel 6261:         $resulttext = '<span class="LC_error">'.
                   6262: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  6263:     }
1.3       raeburn  6264:     return $resulttext;
1.1       raeburn  6265: }
                   6266: 
1.125     raeburn  6267: sub modify_autocreate {
                   6268:     my ($dom,%domconfig) = @_;
                   6269:     my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
                   6270:     if (ref($domconfig{'autocreate'}) eq 'HASH') {
                   6271:         foreach my $key (keys(%{$domconfig{'autocreate'}})) {
                   6272:             $currautocreate{$key} = $domconfig{'autocreate'}{$key};
                   6273:         }
                   6274:     }
                   6275:     my %title= ( xml => 'Auto-creation of courses in XML course description files',
                   6276:                  req => 'Auto-creation of validated requests for official courses',
                   6277:                  xmldc => 'Identity of course creator of courses from XML files',
                   6278:                );
                   6279:     my @types = ('xml','req');
                   6280:     foreach my $item (@types) {
                   6281:         $newvals{$item} = $env{'form.autocreate_'.$item};
                   6282:         $newvals{$item} =~ s/\D//g;
                   6283:         $newvals{$item} = 0 if ($newvals{$item} eq '');
                   6284:     }
                   6285:     $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
                   6286:     my %domcoords = &get_active_dcs($dom);
                   6287:     unless (exists($domcoords{$newvals{'xmldc'}})) {
                   6288:         $newvals{'xmldc'} = '';
                   6289:     } 
                   6290:     %autocreatehash =  (
                   6291:                         autocreate => { xml => $newvals{'xml'},
                   6292:                                         req => $newvals{'req'},
                   6293:                                       }
                   6294:                        );
                   6295:     if ($newvals{'xmldc'} ne '') {
                   6296:         $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
                   6297:     }
                   6298:     my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
                   6299:                                              $dom);
                   6300:     if ($putresult eq 'ok') {
                   6301:         my @items = @types;
                   6302:         if ($newvals{'xml'}) {
                   6303:             push(@items,'xmldc');
                   6304:         }
                   6305:         foreach my $item (@items) {
                   6306:             if (exists($currautocreate{$item})) {
                   6307:                 if ($currautocreate{$item} ne $newvals{$item}) {
                   6308:                     $changes{$item} = 1;
                   6309:                 }
                   6310:             } elsif ($newvals{$item}) {
                   6311:                 $changes{$item} = 1;
                   6312:             }
                   6313:         }
                   6314:         if (keys(%changes) > 0) {
                   6315:             my @offon = ('off','on'); 
                   6316:             $resulttext = &mt('Changes made:').'<ul>';
                   6317:             foreach my $item (@types) {
                   6318:                 if ($changes{$item}) {
                   6319:                     my $newtxt = $offon[$newvals{$item}];
                   6320:                     $resulttext .= '<li>'.&mt("$title{$item} set to [_1]$newtxt [_2]",'<b>','</b>').'</li>';
                   6321:                 }
                   6322:             }
                   6323:             if ($changes{'xmldc'}) {
                   6324:                 my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
                   6325:                 my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
                   6326:                 $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]$newtxt [_2]",'<b>','</b>').'</li>'; 
                   6327:             }
                   6328:             $resulttext .= '</ul>';
                   6329:         } else {
                   6330:             $resulttext = &mt('No changes made to auto-creation settings');
                   6331:         }
                   6332:     } else {
                   6333:         $resulttext = '<span class="LC_error">'.
                   6334:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   6335:     }
                   6336:     return $resulttext;
                   6337: }
                   6338: 
1.23      raeburn  6339: sub modify_directorysrch {
                   6340:     my ($dom,%domconfig) = @_;
                   6341:     my ($resulttext,%changes);
                   6342:     my %currdirsrch;
                   6343:     if (ref($domconfig{'directorysrch'}) eq 'HASH') {
                   6344:         foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
                   6345:             $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
                   6346:         }
                   6347:     }
                   6348:     my %title = ( available => 'Directory search available',
1.24      raeburn  6349:                   localonly => 'Other domains can search',
1.23      raeburn  6350:                   searchby => 'Search types',
                   6351:                   searchtypes => 'Search latitude');
                   6352:     my @offon = ('off','on');
1.24      raeburn  6353:     my @otherdoms = ('Yes','No');
1.23      raeburn  6354: 
1.25      raeburn  6355:     my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');  
1.23      raeburn  6356:     my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
                   6357:     my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
                   6358: 
1.44      raeburn  6359:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26      raeburn  6360:     if (keys(%{$usertypes}) == 0) {
                   6361:         @cansearch = ('default');
                   6362:     } else {
                   6363:         if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
                   6364:             foreach my $type (@{$currdirsrch{'cansearch'}}) {
                   6365:                 if (!grep(/^\Q$type\E$/,@cansearch)) {
                   6366:                     push(@{$changes{'cansearch'}},$type);
                   6367:                 }
1.23      raeburn  6368:             }
1.26      raeburn  6369:             foreach my $type (@cansearch) {
                   6370:                 if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
                   6371:                     push(@{$changes{'cansearch'}},$type);
                   6372:                 }
1.23      raeburn  6373:             }
1.26      raeburn  6374:         } else {
                   6375:             push(@{$changes{'cansearch'}},@cansearch);
1.23      raeburn  6376:         }
                   6377:     }
                   6378: 
                   6379:     if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
                   6380:         foreach my $by (@{$currdirsrch{'searchby'}}) {
                   6381:             if (!grep(/^\Q$by\E$/,@searchby)) {
                   6382:                 push(@{$changes{'searchby'}},$by);
                   6383:             }
                   6384:         }
                   6385:         foreach my $by (@searchby) {
                   6386:             if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
                   6387:                 push(@{$changes{'searchby'}},$by);
                   6388:             }
                   6389:         }
                   6390:     } else {
                   6391:         push(@{$changes{'searchby'}},@searchby);
                   6392:     }
1.25      raeburn  6393: 
                   6394:     if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
                   6395:         foreach my $type (@{$currdirsrch{'searchtypes'}}) {
                   6396:             if (!grep(/^\Q$type\E$/,@searchtypes)) {
                   6397:                 push(@{$changes{'searchtypes'}},$type);
                   6398:             }
                   6399:         }
                   6400:         foreach my $type (@searchtypes) {
                   6401:             if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
                   6402:                 push(@{$changes{'searchtypes'}},$type);
                   6403:             }
                   6404:         }
                   6405:     } else {
                   6406:         if (exists($currdirsrch{'searchtypes'})) {
                   6407:             foreach my $type (@searchtypes) {  
                   6408:                 if ($type ne $currdirsrch{'searchtypes'}) { 
                   6409:                     push(@{$changes{'searchtypes'}},$type);
                   6410:                 }
                   6411:             }
                   6412:             if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
                   6413:                 push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
                   6414:             }   
                   6415:         } else {
                   6416:             push(@{$changes{'searchtypes'}},@searchtypes); 
                   6417:         }
                   6418:     }
                   6419: 
1.23      raeburn  6420:     my %dirsrch_hash =  (
                   6421:             directorysrch => { available => $env{'form.dirsrch_available'},
                   6422:                                cansearch => \@cansearch,
1.24      raeburn  6423:                                localonly => $env{'form.dirsrch_localonly'},
1.23      raeburn  6424:                                searchby => \@searchby,
1.25      raeburn  6425:                                searchtypes => \@searchtypes,
1.23      raeburn  6426:                              }
                   6427:             );
                   6428:     my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
                   6429:                                              $dom);
                   6430:     if ($putresult eq 'ok') {
                   6431:         if (exists($currdirsrch{'available'})) {
                   6432:              if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
                   6433:                  $changes{'available'} = 1;
                   6434:              }
                   6435:         } else {
                   6436:             if ($env{'form.dirsrch_available'} eq '1') {
                   6437:                 $changes{'available'} = 1;
                   6438:             }
                   6439:         }
1.24      raeburn  6440:         if (exists($currdirsrch{'localonly'})) {
                   6441:              if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
                   6442:                  $changes{'localonly'} = 1;
                   6443:              }
                   6444:         } else {
                   6445:             if ($env{'form.dirsrch_localonly'} eq '1') {
                   6446:                 $changes{'localonly'} = 1;
                   6447:             }
                   6448:         }
1.23      raeburn  6449:         if (keys(%changes) > 0) {
                   6450:             $resulttext = &mt('Changes made:').'<ul>';
                   6451:             if ($changes{'available'}) {
                   6452:                 $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
                   6453:             }
1.24      raeburn  6454:             if ($changes{'localonly'}) {
                   6455:                 $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
                   6456:             }
                   6457: 
1.23      raeburn  6458:             if (ref($changes{'cansearch'}) eq 'ARRAY') {
                   6459:                 my $chgtext;
1.26      raeburn  6460:                 if (ref($usertypes) eq 'HASH') {
                   6461:                     if (keys(%{$usertypes}) > 0) {
                   6462:                         foreach my $type (@{$types}) {
                   6463:                             if (grep(/^\Q$type\E$/,@cansearch)) {
                   6464:                                 $chgtext .= $usertypes->{$type}.'; ';
                   6465:                             }
                   6466:                         }
                   6467:                         if (grep(/^default$/,@cansearch)) {
                   6468:                             $chgtext .= $othertitle;
                   6469:                         } else {
                   6470:                             $chgtext =~ s/\; $//;
                   6471:                         }
                   6472:                         $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  6473:                     }
                   6474:                 }
                   6475:             }
                   6476:             if (ref($changes{'searchby'}) eq 'ARRAY') {
                   6477:                 my ($searchtitles,$titleorder) = &sorted_searchtitles();
                   6478:                 my $chgtext;
                   6479:                 foreach my $type (@{$titleorder}) {
                   6480:                     if (grep(/^\Q$type\E$/,@searchby)) {
                   6481:                         if (defined($searchtitles->{$type})) {
                   6482:                             $chgtext .= $searchtitles->{$type}.'; ';
                   6483:                         }
                   6484:                     }
                   6485:                 }
                   6486:                 $chgtext =~ s/\; $//;
                   6487:                 $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
                   6488:             }
1.25      raeburn  6489:             if (ref($changes{'searchtypes'}) eq 'ARRAY') {
                   6490:                 my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes(); 
                   6491:                 my $chgtext;
                   6492:                 foreach my $type (@{$srchtypeorder}) {
                   6493:                     if (grep(/^\Q$type\E$/,@searchtypes)) {
                   6494:                         if (defined($srchtypes_desc->{$type})) {
                   6495:                             $chgtext .= $srchtypes_desc->{$type}.'; ';
                   6496:                         }
                   6497:                     }
                   6498:                 }
                   6499:                 $chgtext =~ s/\; $//;
                   6500:                 $resulttext .= '<li>'.&mt("$title{'searchtypes'} set to: \"[_1]\"",$chgtext).'</li>';
1.23      raeburn  6501:             }
                   6502:             $resulttext .= '</ul>';
                   6503:         } else {
                   6504:             $resulttext = &mt('No changes made to institution directory search settings');
                   6505:         }
                   6506:     } else {
                   6507:         $resulttext = '<span class="LC_error">'.
1.27      raeburn  6508:                       &mt('An error occurred: [_1]',$putresult).'</span>';
                   6509:     }
                   6510:     return $resulttext;
                   6511: }
                   6512: 
1.28      raeburn  6513: sub modify_contacts {
                   6514:     my ($dom,%domconfig) = @_;
                   6515:     my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
                   6516:     if (ref($domconfig{'contacts'}) eq 'HASH') {
                   6517:         foreach my $key (keys(%{$domconfig{'contacts'}})) {
                   6518:             $currsetting{$key} = $domconfig{'contacts'}{$key};
                   6519:         }
                   6520:     }
1.134     raeburn  6521:     my (%others,%to,%bcc);
1.28      raeburn  6522:     my @contacts = ('supportemail','adminemail');
1.102     raeburn  6523:     my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
                   6524:                     'requestsmail');
1.28      raeburn  6525:     foreach my $type (@mailings) {
                   6526:         @{$newsetting{$type}} = 
                   6527:             &Apache::loncommon::get_env_multiple('form.'.$type);
                   6528:         foreach my $item (@contacts) {
                   6529:             if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
                   6530:                 $contacts_hash{contacts}{$type}{$item} = 1;
                   6531:             } else {
                   6532:                 $contacts_hash{contacts}{$type}{$item} = 0;
                   6533:             }
                   6534:         }  
                   6535:         $others{$type} = $env{'form.'.$type.'_others'};
                   6536:         $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.134     raeburn  6537:         if ($type eq 'helpdeskmail') {
                   6538:             $bcc{$type} = $env{'form.'.$type.'_bcc'};
                   6539:             $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
                   6540:         }
1.28      raeburn  6541:     }
                   6542:     foreach my $item (@contacts) {
                   6543:         $to{$item} = $env{'form.'.$item};
                   6544:         $contacts_hash{'contacts'}{$item} = $to{$item};
                   6545:     }
                   6546:     if (keys(%currsetting) > 0) {
                   6547:         foreach my $item (@contacts) {
                   6548:             if ($to{$item} ne $currsetting{$item}) {
                   6549:                 $changes{$item} = 1;
                   6550:             }
                   6551:         }
                   6552:         foreach my $type (@mailings) {
                   6553:             foreach my $item (@contacts) {
                   6554:                 if (ref($currsetting{$type}) eq 'HASH') {
                   6555:                     if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
                   6556:                         push(@{$changes{$type}},$item);
                   6557:                     }
                   6558:                 } else {
                   6559:                     push(@{$changes{$type}},@{$newsetting{$type}});
                   6560:                 }
                   6561:             }
                   6562:             if ($others{$type} ne $currsetting{$type}{'others'}) {
                   6563:                 push(@{$changes{$type}},'others');
                   6564:             }
1.134     raeburn  6565:             if ($type eq 'helpdeskmail') {   
                   6566:                 if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
                   6567:                     push(@{$changes{$type}},'bcc'); 
                   6568:                 }
                   6569:             }
1.28      raeburn  6570:         }
                   6571:     } else {
                   6572:         my %default;
                   6573:         $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
                   6574:         $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
                   6575:         $default{'errormail'} = 'adminemail';
                   6576:         $default{'packagesmail'} = 'adminemail';
                   6577:         $default{'helpdeskmail'} = 'supportemail';
1.89      raeburn  6578:         $default{'lonstatusmail'} = 'adminemail';
1.102     raeburn  6579:         $default{'requestsmail'} = 'adminemail';
1.28      raeburn  6580:         foreach my $item (@contacts) {
                   6581:            if ($to{$item} ne $default{$item}) {
                   6582:               $changes{$item} = 1;
                   6583:            } 
                   6584:         }
                   6585:         foreach my $type (@mailings) {
                   6586:             if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
                   6587:                
                   6588:                 push(@{$changes{$type}},@{$newsetting{$type}});
                   6589:             }
                   6590:             if ($others{$type} ne '') {
                   6591:                 push(@{$changes{$type}},'others');
1.134     raeburn  6592:             }
                   6593:             if ($type eq 'helpdeskmail') {
                   6594:                 if ($bcc{$type} ne '') {
                   6595:                     push(@{$changes{$type}},'bcc');
                   6596:                 }
                   6597:             }
1.28      raeburn  6598:         }
                   6599:     }
                   6600:     my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
                   6601:                                              $dom);
                   6602:     if ($putresult eq 'ok') {
                   6603:         if (keys(%changes) > 0) {
                   6604:             my ($titles,$short_titles)  = &contact_titles();
                   6605:             $resulttext = &mt('Changes made:').'<ul>';
                   6606:             foreach my $item (@contacts) {
                   6607:                 if ($changes{$item}) {
                   6608:                     $resulttext .= '<li>'.$titles->{$item}.
                   6609:                                     &mt(' set to: ').
                   6610:                                     '<span class="LC_cusr_emph">'.
                   6611:                                     $to{$item}.'</span></li>';
                   6612:                 }
                   6613:             }
                   6614:             foreach my $type (@mailings) {
                   6615:                 if (ref($changes{$type}) eq 'ARRAY') {
                   6616:                     $resulttext .= '<li>'.$titles->{$type}.': ';
                   6617:                     my @text;
                   6618:                     foreach my $item (@{$newsetting{$type}}) {
                   6619:                         push(@text,$short_titles->{$item});
                   6620:                     }
                   6621:                     if ($others{$type} ne '') {
                   6622:                         push(@text,$others{$type});
                   6623:                     }
                   6624:                     $resulttext .= '<span class="LC_cusr_emph">'.
1.134     raeburn  6625:                                    join(', ',@text).'</span>';
                   6626:                     if ($type eq 'helpdeskmail') {
                   6627:                         if ($bcc{$type} ne '') {
                   6628:                             $resulttext .= '&nbsp;'.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
                   6629:                         }
                   6630:                     }
                   6631:                     $resulttext .= '</li>';
1.28      raeburn  6632:                 }
                   6633:             }
                   6634:             $resulttext .= '</ul>';
                   6635:         } else {
1.34      raeburn  6636:             $resulttext = &mt('No changes made to contact information');
1.28      raeburn  6637:         }
                   6638:     } else {
                   6639:         $resulttext = '<span class="LC_error">'.
                   6640:             &mt('An error occurred: [_1].',$putresult).'</span>';
                   6641:     }
                   6642:     return $resulttext;
                   6643: }
                   6644: 
                   6645: sub modify_usercreation {
1.27      raeburn  6646:     my ($dom,%domconfig) = @_;
1.34      raeburn  6647:     my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate);
1.43      raeburn  6648:     my $warningmsg;
1.27      raeburn  6649:     if (ref($domconfig{'usercreation'}) eq 'HASH') {
                   6650:         foreach my $key (keys(%{$domconfig{'usercreation'}})) {
                   6651:             $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
                   6652:         }
                   6653:     }
                   6654:     my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32      raeburn  6655:     my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.43      raeburn  6656:     my @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
1.100     raeburn  6657:     my @contexts = ('author','course','requestcrs','selfcreate');
1.34      raeburn  6658:     foreach my $item(@contexts) {
1.45      raeburn  6659:         if ($item eq 'selfcreate') {
1.50      raeburn  6660:             @{$cancreate{$item}} = &Apache::loncommon::get_env_multiple('form.can_createuser_'.$item);
1.43      raeburn  6661:             my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
                   6662:             if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) || ($domdefaults{'auth_def'} eq 'localauth'))) {
1.50      raeburn  6663:                 if (ref($cancreate{$item}) eq 'ARRAY') { 
                   6664:                     if (grep(/^login$/,@{$cancreate{$item}})) {
                   6665:                         $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.');   
                   6666:                     }
1.43      raeburn  6667:                 }
                   6668:             }
1.50      raeburn  6669:         } else {
                   6670:             $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.43      raeburn  6671:         }
1.34      raeburn  6672:     }
1.93      raeburn  6673:     my ($othertitle,$usertypes,$types) = 
                   6674:         &Apache::loncommon::sorted_inst_types($dom);
                   6675:     if (ref($types) eq 'ARRAY') {
                   6676:         if (@{$types} > 0) {
                   6677:             @{$cancreate{'statustocreate'}} = 
                   6678:                 &Apache::loncommon::get_env_multiple('form.statustocreate');
1.103     raeburn  6679:         } else {
                   6680:             @{$cancreate{'statustocreate'}} = ();
1.93      raeburn  6681:         }
                   6682:         push(@contexts,'statustocreate');
                   6683:     }
1.165     raeburn  6684:     &process_captcha('cancreate',\%changes,\%cancreate,\%curr_usercreation);
1.34      raeburn  6685:     if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
                   6686:         foreach my $item (@contexts) {
1.93      raeburn  6687:             if (($item eq 'selfcreate') || ($item eq 'statustocreate')) {
                   6688:                 if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
1.50      raeburn  6689:                     foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
1.103     raeburn  6690:                         if (ref($cancreate{$item}) eq 'ARRAY') {
                   6691:                             if (!grep(/^$curr$/,@{$cancreate{$item}})) {
                   6692:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   6693:                                     push(@{$changes{'cancreate'}},$item);
                   6694:                                 }
1.50      raeburn  6695:                             }
                   6696:                         }
                   6697:                     }
                   6698:                 } else {
                   6699:                     if ($curr_usercreation{'cancreate'}{$item} eq '') {
                   6700:                         if (@{$cancreate{$item}} > 0) {
                   6701:                             if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   6702:                                 push(@{$changes{'cancreate'}},$item);
                   6703:                             }
                   6704:                         }
                   6705:                     } else {
                   6706:                         if ($curr_usercreation{'cancreate'}{$item} eq 'any') {
                   6707:                             if (@{$cancreate{$item}} < 3) {
                   6708:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   6709:                                     push(@{$changes{'cancreate'}},$item);
                   6710:                                 }
                   6711:                             }
                   6712:                         } elsif ($curr_usercreation{'cancreate'}{$item} eq 'none') {
                   6713:                             if (@{$cancreate{$item}} > 0) {
                   6714:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   6715:                                     push(@{$changes{'cancreate'}},$item);
                   6716:                                 }
                   6717:                             }
                   6718:                         } elsif (!grep(/^$curr_usercreation{'cancreate'}{$item}$/,@{$cancreate{$item}})) {
                   6719:                             if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   6720:                                 push(@{$changes{'cancreate'}},$item);
                   6721:                             }
                   6722:                         }
                   6723:                     }
                   6724:                 }
                   6725:                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   6726:                     foreach my $type (@{$cancreate{$item}}) {
                   6727:                         if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
                   6728:                             if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
                   6729:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   6730:                                     push(@{$changes{'cancreate'}},$item);
                   6731:                                 }
                   6732:                             }
                   6733:                         } elsif (($curr_usercreation{'cancreate'}{$item} ne 'any') &&
                   6734:                                  ($curr_usercreation{'cancreate'}{$item} ne 'none')) {
                   6735:                             if ($curr_usercreation{'cancreate'}{$item} ne $type) {
                   6736:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   6737:                                     push(@{$changes{'cancreate'}},$item);
                   6738:                                 }
                   6739:                             }
                   6740:                         }
                   6741:                     }
                   6742:                 }
                   6743:             } else {
                   6744:                 if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
                   6745:                     push(@{$changes{'cancreate'}},$item);
                   6746:                 }
                   6747:             }
1.27      raeburn  6748:         }
1.34      raeburn  6749:     } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
                   6750:         foreach my $item (@contexts) {
1.43      raeburn  6751:             if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34      raeburn  6752:                 if ($cancreate{$item} ne 'any') {
                   6753:                     push(@{$changes{'cancreate'}},$item);
                   6754:                 }
                   6755:             } else {
                   6756:                 if ($cancreate{$item} ne 'none') {
                   6757:                     push(@{$changes{'cancreate'}},$item);
                   6758:                 }
1.27      raeburn  6759:             }
                   6760:         }
                   6761:     } else {
1.43      raeburn  6762:         foreach my $item (@contexts)  {
1.34      raeburn  6763:             push(@{$changes{'cancreate'}},$item);
                   6764:         }
1.27      raeburn  6765:     }
1.34      raeburn  6766: 
1.27      raeburn  6767:     if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
                   6768:         foreach my $type (@{$curr_usercreation{'username_rule'}}) {
                   6769:             if (!grep(/^\Q$type\E$/,@username_rule)) {
                   6770:                 push(@{$changes{'username_rule'}},$type);
                   6771:             }
                   6772:         }
                   6773:         foreach my $type (@username_rule) {
                   6774:             if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
                   6775:                 push(@{$changes{'username_rule'}},$type);
                   6776:             }
                   6777:         }
                   6778:     } else {
                   6779:         push(@{$changes{'username_rule'}},@username_rule);
                   6780:     }
                   6781: 
1.32      raeburn  6782:     if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
                   6783:         foreach my $type (@{$curr_usercreation{'id_rule'}}) {
                   6784:             if (!grep(/^\Q$type\E$/,@id_rule)) {
                   6785:                 push(@{$changes{'id_rule'}},$type);
                   6786:             }
                   6787:         }
                   6788:         foreach my $type (@id_rule) {
                   6789:             if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
                   6790:                 push(@{$changes{'id_rule'}},$type);
                   6791:             }
                   6792:         }
                   6793:     } else {
                   6794:         push(@{$changes{'id_rule'}},@id_rule);
                   6795:     }
                   6796: 
1.43      raeburn  6797:     if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
                   6798:         foreach my $type (@{$curr_usercreation{'email_rule'}}) {
                   6799:             if (!grep(/^\Q$type\E$/,@email_rule)) {
                   6800:                 push(@{$changes{'email_rule'}},$type);
                   6801:             }
                   6802:         }
                   6803:         foreach my $type (@email_rule) {
                   6804:             if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
                   6805:                 push(@{$changes{'email_rule'}},$type);
                   6806:             }
                   6807:         }
                   6808:     } else {
                   6809:         push(@{$changes{'email_rule'}},@email_rule);
                   6810:     }
                   6811: 
                   6812:     my @authen_contexts = ('author','course','domain');
1.28      raeburn  6813:     my @authtypes = ('int','krb4','krb5','loc');
                   6814:     my %authhash;
1.43      raeburn  6815:     foreach my $item (@authen_contexts) {
1.28      raeburn  6816:         my @authallowed =  &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
                   6817:         foreach my $auth (@authtypes) {
                   6818:             if (grep(/^\Q$auth\E$/,@authallowed)) {
                   6819:                 $authhash{$item}{$auth} = 1;
                   6820:             } else {
                   6821:                 $authhash{$item}{$auth} = 0;
                   6822:             }
                   6823:         }
                   6824:     }
                   6825:     if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43      raeburn  6826:         foreach my $item (@authen_contexts) {
1.28      raeburn  6827:             if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
                   6828:                 foreach my $auth (@authtypes) {
                   6829:                     if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
                   6830:                         push(@{$changes{'authtypes'}},$item);
                   6831:                         last;
                   6832:                     }
                   6833:                 }
                   6834:             }
                   6835:         }
                   6836:     } else {
1.43      raeburn  6837:         foreach my $item (@authen_contexts) {
1.28      raeburn  6838:             push(@{$changes{'authtypes'}},$item);
                   6839:         }
                   6840:     }
                   6841: 
1.27      raeburn  6842:     my %usercreation_hash =  (
1.28      raeburn  6843:             usercreation => {
1.34      raeburn  6844:                               cancreate     => \%cancreate,
1.27      raeburn  6845:                               username_rule => \@username_rule,
1.32      raeburn  6846:                               id_rule       => \@id_rule,
1.43      raeburn  6847:                               email_rule    => \@email_rule,
1.32      raeburn  6848:                               authtypes     => \%authhash,
1.27      raeburn  6849:                             }
                   6850:             );
                   6851: 
                   6852:     my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
                   6853:                                              $dom);
1.50      raeburn  6854: 
                   6855:     my %selfcreatetypes = (
                   6856:                              sso   => 'users authenticated by institutional single sign on',
                   6857:                              login => 'users authenticated by institutional log-in',
                   6858:                              email => 'users who provide a valid e-mail address for use as the username',
                   6859:                           );
1.27      raeburn  6860:     if ($putresult eq 'ok') {
                   6861:         if (keys(%changes) > 0) {
                   6862:             $resulttext = &mt('Changes made:').'<ul>';
                   6863:             if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.34      raeburn  6864:                 my %lt = &usercreation_types();
                   6865:                 foreach my $type (@{$changes{'cancreate'}}) {
1.100     raeburn  6866:                     my $chgtext;
1.165     raeburn  6867:                     unless (($type eq 'statustocreate') || ($type eq 'captcha') || ($type eq 'recaptchakeys')) {
1.100     raeburn  6868:                         $chgtext = $lt{$type}.', ';
                   6869:                     }
1.45      raeburn  6870:                     if ($type eq 'selfcreate') {
1.50      raeburn  6871:                         if (@{$cancreate{$type}} == 0) {
1.43      raeburn  6872:                             $chgtext .= &mt('creation of a new user account is not permitted.');
1.50      raeburn  6873:                         } else {
1.100     raeburn  6874:                             $chgtext .= &mt('creation of a new account is permitted for:').'<ul>';
1.50      raeburn  6875:                             foreach my $case (@{$cancreate{$type}}) {
                   6876:                                 $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
                   6877:                             }
                   6878:                             $chgtext .= '</ul>';
1.100     raeburn  6879:                             if (ref($cancreate{$type}) eq 'ARRAY') {
                   6880:                                 if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
                   6881:                                     if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
                   6882:                                         if (@{$cancreate{'statustocreate'}} == 0) {
                   6883:                                             $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
                   6884:                                         }
                   6885:                                     }
                   6886:                                 }
                   6887:                             }
1.43      raeburn  6888:                         }
1.93      raeburn  6889:                     } elsif ($type eq 'statustocreate') {
1.96      raeburn  6890:                         if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
                   6891:                             (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
                   6892:                             if (@{$cancreate{'selfcreate'}} > 0) {
                   6893:                                 if (@{$cancreate{'statustocreate'}} == 0) {
1.100     raeburn  6894: 
                   6895:                                     $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96      raeburn  6896:                                     if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.100     raeburn  6897:                                         $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
                   6898:                                     } 
1.96      raeburn  6899:                                 } elsif (ref($usertypes) eq 'HASH') {
                   6900:                                     if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100     raeburn  6901:                                         $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
                   6902:                                     } else {
                   6903:                                         $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
                   6904:                                     }
                   6905:                                     $chgtext .= '<ul>';
                   6906:                                     foreach my $case (@{$cancreate{$type}}) {
                   6907:                                         if ($case eq 'default') {
                   6908:                                             $chgtext .= '<li>'.$othertitle.'</li>';
                   6909:                                         } else {
                   6910:                                             $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93      raeburn  6911:                                         }
                   6912:                                     }
1.100     raeburn  6913:                                     $chgtext .= '</ul>';
                   6914:                                     if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
                   6915:                                         $chgtext .= '<br /><span class="LC_warning">'.&mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').'</span>';
                   6916:                                     }
                   6917:                                 }
                   6918:                             } else {
                   6919:                                 if (@{$cancreate{$type}} == 0) {
                   6920:                                     $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
                   6921:                                 } else {
                   6922:                                     $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  6923:                                 }
                   6924:                             }
                   6925:                         }
1.165     raeburn  6926:                     } elsif ($type eq 'captcha') {
                   6927:                         if ($cancreate{$type} eq 'notused') {
                   6928:                             $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
                   6929:                         } else {
                   6930:                             my %captchas = &captcha_phrases();
                   6931:                             if ($captchas{$cancreate{$type}}) {
                   6932:                                 $chgtext .= &mt("Validation for self-creation screen set to $captchas{$cancreate{$type}}.");
                   6933:                             } else {
                   6934:                                 $chgtext .= &mt('Validation for self-creation screen set to unknown type.'); 
                   6935:                             }
                   6936:                         }
                   6937:                     } elsif ($type eq 'recaptchakeys') {
                   6938:                         my ($privkey,$pubkey);
                   6939:                         if (ref($cancreate{$type}) eq 'HASH') {
                   6940:                             $pubkey = $cancreate{$type}{'public'};
                   6941:                             $privkey = $cancreate{$type}{'private'};
                   6942:                         }
                   6943:                         $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
                   6944:                         if (!$pubkey) {
                   6945:                             $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
                   6946:                         } else {
                   6947:                             $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
                   6948:                         }
                   6949:                         if (!$privkey) {
                   6950:                             $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
                   6951:                         } else {
                   6952:                             $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
                   6953:                         }
                   6954:                         $chgtext .= '</ul>';
1.43      raeburn  6955:                     } else {
                   6956:                         if ($cancreate{$type} eq 'none') {
                   6957:                             $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
                   6958:                         } elsif ($cancreate{$type} eq 'any') {
                   6959:                             $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
                   6960:                         } elsif ($cancreate{$type} eq 'official') {
                   6961:                             $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
                   6962:                         } elsif ($cancreate{$type} eq 'unofficial') {
                   6963:                             $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
                   6964:                         }
1.34      raeburn  6965:                     }
                   6966:                     $resulttext .= '<li>'.$chgtext.'</li>';
1.27      raeburn  6967:                 }
                   6968:             }
                   6969:             if (ref($changes{'username_rule'}) eq 'ARRAY') {
1.32      raeburn  6970:                 my ($rules,$ruleorder) = 
                   6971:                     &Apache::lonnet::inst_userrules($dom,'username');
1.27      raeburn  6972:                 my $chgtext = '<ul>';
                   6973:                 foreach my $type (@username_rule) {
                   6974:                     if (ref($rules->{$type}) eq 'HASH') {
                   6975:                         $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
                   6976:                     }
                   6977:                 }
                   6978:                 $chgtext .= '</ul>';
                   6979:                 if (@username_rule > 0) {
                   6980:                     $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';     
                   6981:                 } else {
1.28      raeburn  6982:                     $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>'; 
1.27      raeburn  6983:                 }
                   6984:             }
1.32      raeburn  6985:             if (ref($changes{'id_rule'}) eq 'ARRAY') {
                   6986:                 my ($idrules,$idruleorder) = 
                   6987:                     &Apache::lonnet::inst_userrules($dom,'id');
                   6988:                 my $chgtext = '<ul>';
                   6989:                 foreach my $type (@id_rule) {
                   6990:                     if (ref($idrules->{$type}) eq 'HASH') {
                   6991:                         $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
                   6992:                     }
                   6993:                 }
                   6994:                 $chgtext .= '</ul>';
                   6995:                 if (@id_rule > 0) {
                   6996:                     $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
                   6997:                 } else {
                   6998:                     $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
                   6999:                 }
                   7000:             }
1.43      raeburn  7001:             if (ref($changes{'email_rule'}) eq 'ARRAY') {
                   7002:                 my ($emailrules,$emailruleorder) =
                   7003:                     &Apache::lonnet::inst_userrules($dom,'email');
                   7004:                 my $chgtext = '<ul>';
                   7005:                 foreach my $type (@email_rule) {
                   7006:                     if (ref($emailrules->{$type}) eq 'HASH') {
                   7007:                         $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
                   7008:                     }
                   7009:                 }
                   7010:                 $chgtext .= '</ul>';
                   7011:                 if (@email_rule > 0) {
                   7012:                     $resulttext .= '<li>'.&mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').$chgtext.'</li>';
                   7013:                 } else {
                   7014:                     $resulttext .= '<li>'.&mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').'</li>';
                   7015:                 }
                   7016:             }
                   7017: 
1.28      raeburn  7018:             my %authname = &authtype_names();
                   7019:             my %context_title = &context_names();
                   7020:             if (ref($changes{'authtypes'}) eq 'ARRAY') {
                   7021:                 my $chgtext = '<ul>';
                   7022:                 foreach my $type (@{$changes{'authtypes'}}) {
                   7023:                     my @allowed;
                   7024:                     $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
                   7025:                     foreach my $auth (@authtypes) {
                   7026:                         if ($authhash{$type}{$auth}) {
                   7027:                             push(@allowed,$authname{$auth});
                   7028:                         }
                   7029:                     }
1.43      raeburn  7030:                     if (@allowed > 0) {
                   7031:                         $chgtext .= join(', ',@allowed).'</li>';
                   7032:                     } else {
                   7033:                         $chgtext .= &mt('none').'</li>';
                   7034:                     }
1.28      raeburn  7035:                 }
                   7036:                 $chgtext .= '</ul>';
                   7037:                 $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
                   7038:                 $resulttext .= '</li>';
                   7039:             }
1.27      raeburn  7040:             $resulttext .= '</ul>';
                   7041:         } else {
1.28      raeburn  7042:             $resulttext = &mt('No changes made to user creation settings');
1.27      raeburn  7043:         }
                   7044:     } else {
                   7045:         $resulttext = '<span class="LC_error">'.
1.23      raeburn  7046:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   7047:     }
1.43      raeburn  7048:     if ($warningmsg ne '') {
                   7049:         $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
                   7050:     }
1.23      raeburn  7051:     return $resulttext;
                   7052: }
                   7053: 
1.165     raeburn  7054: sub process_captcha {
                   7055:     my ($container,$changes,$newsettings,$current) = @_;
                   7056:     return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
                   7057:     $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
                   7058:     unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
                   7059:         $newsettings->{'captcha'} = 'original';
                   7060:     }
                   7061:     if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
1.169     raeburn  7062:         if ($container eq 'cancreate') { 
                   7063:             if (ref($changes->{'cancreate'}) eq 'ARRAY') {
                   7064:                 push(@{$changes->{'cancreate'}},'captcha');
                   7065:             } elsif (!defined($changes->{'cancreate'})) {
                   7066:                 $changes->{'cancreate'} = ['captcha'];
                   7067:             }
                   7068:         } else {
                   7069:             $changes->{'captcha'} = 1;
1.165     raeburn  7070:         }
                   7071:     }
                   7072:     my ($newpub,$newpriv,$currpub,$currpriv);
                   7073:     if ($newsettings->{'captcha'} eq 'recaptcha') {
                   7074:         $newpub = $env{'form.'.$container.'_recaptchapub'};
                   7075:         $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.169     raeburn  7076:         $newpub =~ s/\W//g;
                   7077:         $newpriv =~ s/\W//g;
                   7078:         $newsettings->{'recaptchakeys'} = {
                   7079:                                              public  => $newpub,
                   7080:                                              private => $newpriv,
                   7081:                                           };
1.165     raeburn  7082:     }
                   7083:     if (ref($current->{'recaptchakeys'}) eq 'HASH') {
                   7084:         $currpub = $current->{'recaptchakeys'}{'public'};
                   7085:         $currpriv = $current->{'recaptchakeys'}{'private'};
1.169     raeburn  7086:         $newsettings->{'recaptchakeys'} = {
                   7087:                                              public  => '',
                   7088:                                              private => '',
                   7089:                                           }
1.165     raeburn  7090:     }
                   7091:     if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169     raeburn  7092:         if ($container eq 'cancreate') {
                   7093:             if (ref($changes->{'cancreate'}) eq 'ARRAY') {
                   7094:                 push(@{$changes->{'cancreate'}},'recaptchakeys');
                   7095:             } elsif (!defined($changes->{'cancreate'})) {
                   7096:                 $changes->{'cancreate'} = ['recaptchakeys'];
                   7097:             }
                   7098:         } else {
                   7099:             $changes->{'recaptchakeys'} = 1; 
1.165     raeburn  7100:         }
                   7101:     }
                   7102:     return;
                   7103: }
                   7104: 
1.33      raeburn  7105: sub modify_usermodification {
                   7106:     my ($dom,%domconfig) = @_;
                   7107:     my ($resulttext,%curr_usermodification,%changes);
                   7108:     if (ref($domconfig{'usermodification'}) eq 'HASH') {
                   7109:         foreach my $key (keys(%{$domconfig{'usermodification'}})) {
                   7110:             $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
                   7111:         }
                   7112:     }
1.63      raeburn  7113:     my @contexts = ('author','course','selfcreate');
1.33      raeburn  7114:     my %context_title = (
                   7115:                            author => 'In author context',
                   7116:                            course => 'In course context',
1.63      raeburn  7117:                            selfcreate => 'When self creating account', 
1.33      raeburn  7118:                         );
                   7119:     my @fields = ('lastname','firstname','middlename','generation',
                   7120:                   'permanentemail','id');
                   7121:     my %roles = (
                   7122:                   author => ['ca','aa'],
                   7123:                   course => ['st','ep','ta','in','cr'],
                   7124:                 );
1.63      raeburn  7125:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   7126:     if (ref($types) eq 'ARRAY') {
                   7127:         push(@{$types},'default');
                   7128:         $usertypes->{'default'} = $othertitle;
                   7129:     }
                   7130:     $roles{'selfcreate'} = $types;  
1.33      raeburn  7131:     my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
                   7132:     my %modifyhash;
                   7133:     foreach my $context (@contexts) {
                   7134:         foreach my $role (@{$roles{$context}}) {
                   7135:             my @modifiable =  &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
                   7136:             foreach my $item (@fields) {
                   7137:                 if (grep(/^\Q$item\E$/,@modifiable)) {
                   7138:                     $modifyhash{$context}{$role}{$item} = 1;
                   7139:                 } else {
                   7140:                     $modifyhash{$context}{$role}{$item} = 0;
                   7141:                 }
                   7142:             }
                   7143:         }
                   7144:         if (ref($curr_usermodification{$context}) eq 'HASH') {
                   7145:             foreach my $role (@{$roles{$context}}) {
                   7146:                 if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
                   7147:                     foreach my $field (@fields) {
                   7148:                         if ($modifyhash{$context}{$role}{$field} ne 
                   7149:                                 $curr_usermodification{$context}{$role}{$field}) {
                   7150:                             push(@{$changes{$context}},$role);
                   7151:                             last;
                   7152:                         }
                   7153:                     }
                   7154:                 }
                   7155:             }
                   7156:         } else {
                   7157:             foreach my $context (@contexts) {
                   7158:                 foreach my $role (@{$roles{$context}}) {
                   7159:                     push(@{$changes{$context}},$role);
                   7160:                 }
                   7161:             }
                   7162:         }
                   7163:     }
                   7164:     my %usermodification_hash =  (
                   7165:                                    usermodification => \%modifyhash,
                   7166:                                  );
                   7167:     my $putresult = &Apache::lonnet::put_dom('configuration',
                   7168:                                              \%usermodification_hash,$dom);
                   7169:     if ($putresult eq 'ok') {
                   7170:         if (keys(%changes) > 0) {
                   7171:             $resulttext = &mt('Changes made: ').'<ul>';
                   7172:             foreach my $context (@contexts) {
                   7173:                 if (ref($changes{$context}) eq 'ARRAY') {
                   7174:                     $resulttext .= '<li>'.$context_title{$context}.':<ul>';
                   7175:                     if (ref($changes{$context}) eq 'ARRAY') {
                   7176:                         foreach my $role (@{$changes{$context}}) {
                   7177:                             my $rolename;
1.63      raeburn  7178:                             if ($context eq 'selfcreate') {
                   7179:                                 $rolename = $role;
                   7180:                                 if (ref($usertypes) eq 'HASH') {
                   7181:                                     if ($usertypes->{$role} ne '') {
                   7182:                                         $rolename = $usertypes->{$role};
                   7183:                                     }
                   7184:                                 }
1.33      raeburn  7185:                             } else {
1.63      raeburn  7186:                                 if ($role eq 'cr') {
                   7187:                                     $rolename = &mt('Custom');
                   7188:                                 } else {
                   7189:                                     $rolename = &Apache::lonnet::plaintext($role);
                   7190:                                 }
1.33      raeburn  7191:                             }
                   7192:                             my @modifiable;
1.63      raeburn  7193:                             if ($context eq 'selfcreate') {
1.126     bisitz   7194:                                 $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  7195:                             } else {
                   7196:                                 $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
                   7197:                             }
1.33      raeburn  7198:                             foreach my $field (@fields) {
                   7199:                                 if ($modifyhash{$context}{$role}{$field}) {
                   7200:                                     push(@modifiable,$fieldtitles{$field});
                   7201:                                 }
                   7202:                             }
                   7203:                             if (@modifiable > 0) {
                   7204:                                 $resulttext .= join(', ',@modifiable);
                   7205:                             } else {
                   7206:                                 $resulttext .= &mt('none'); 
                   7207:                             }
                   7208:                             $resulttext .= '</li>';
                   7209:                         }
                   7210:                         $resulttext .= '</ul></li>';
                   7211:                     }
                   7212:                 }
                   7213:             }
                   7214:             $resulttext .= '</ul>';
                   7215:         } else {
                   7216:             $resulttext = &mt('No changes made to user modification settings');
                   7217:         }
                   7218:     } else {
                   7219:         $resulttext = '<span class="LC_error">'.
                   7220:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   7221:     }
                   7222:     return $resulttext;
                   7223: }
                   7224: 
1.43      raeburn  7225: sub modify_defaults {
                   7226:     my ($dom,$r) = @_;
                   7227:     my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
                   7228:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.141     raeburn  7229:     my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
1.43      raeburn  7230:     my @authtypes = ('internal','krb4','krb5','localauth');
                   7231:     foreach my $item (@items) {
                   7232:         $newvalues{$item} = $env{'form.'.$item};
                   7233:         if ($item eq 'auth_def') {
                   7234:             if ($newvalues{$item} ne '') {
                   7235:                 if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
                   7236:                     push(@errors,$item);
                   7237:                 }
                   7238:             }
                   7239:         } elsif ($item eq 'lang_def') {
                   7240:             if ($newvalues{$item} ne '') {
                   7241:                 if ($newvalues{$item} =~ /^(\w+)/) {
                   7242:                     my $langcode = $1;
1.103     raeburn  7243:                     if ($langcode ne 'x_chef') {
                   7244:                         if (code2language($langcode) eq '') {
                   7245:                             push(@errors,$item);
                   7246:                         }
1.43      raeburn  7247:                     }
                   7248:                 } else {
                   7249:                     push(@errors,$item);
                   7250:                 }
                   7251:             }
1.54      raeburn  7252:         } elsif ($item eq 'timezone_def') {
                   7253:             if ($newvalues{$item} ne '') {
1.62      raeburn  7254:                 if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54      raeburn  7255:                     push(@errors,$item);   
                   7256:                 }
                   7257:             }
1.68      raeburn  7258:         } elsif ($item eq 'datelocale_def') {
                   7259:             if ($newvalues{$item} ne '') {
                   7260:                 my @datelocale_ids = DateTime::Locale->ids();
                   7261:                 if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
                   7262:                     push(@errors,$item);
                   7263:                 }
                   7264:             }
1.141     raeburn  7265:         } elsif ($item eq 'portal_def') {
                   7266:             if ($newvalues{$item} ne '') {
                   7267:                 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])\/?$/) {
                   7268:                     push(@errors,$item);
                   7269:                 }
                   7270:             }
1.43      raeburn  7271:         }
                   7272:         if (grep(/^\Q$item\E$/,@errors)) {
                   7273:             $newvalues{$item} = $domdefaults{$item};
                   7274:         } elsif ($domdefaults{$item} ne $newvalues{$item}) {
                   7275:             $changes{$item} = 1;
                   7276:         }
1.72      raeburn  7277:         $domdefaults{$item} = $newvalues{$item};
1.43      raeburn  7278:     }
                   7279:     my %defaults_hash = (
1.72      raeburn  7280:                          defaults => \%newvalues,
                   7281:                         );
1.43      raeburn  7282:     my $title = &defaults_titles();
                   7283:     my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
                   7284:                                              $dom);
                   7285:     if ($putresult eq 'ok') {
                   7286:         if (keys(%changes) > 0) {
                   7287:             $resulttext = &mt('Changes made:').'<ul>';
                   7288:             my $version = $r->dir_config('lonVersion');
                   7289:             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";
                   7290:             foreach my $item (sort(keys(%changes))) {
                   7291:                 my $value = $env{'form.'.$item};
                   7292:                 if ($value eq '') {
                   7293:                     $value = &mt('none');
                   7294:                 } elsif ($item eq 'auth_def') {
                   7295:                     my %authnames = &authtype_names();
                   7296:                     my %shortauth = (
                   7297:                              internal => 'int',
                   7298:                              krb4 => 'krb4',
                   7299:                              krb5 => 'krb5',
                   7300:                              localauth  => 'loc',
                   7301:                     );
                   7302:                     $value = $authnames{$shortauth{$value}};
                   7303:                 }
                   7304:                 $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
                   7305:                 $mailmsgtext .= "$title->{$item} set to $value\n";  
                   7306:             }
                   7307:             $resulttext .= '</ul>';
                   7308:             $mailmsgtext .= "\n";
                   7309:             my $cachetime = 24*60*60;
1.72      raeburn  7310:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.68      raeburn  7311:             if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.54      raeburn  7312:                 my $sysmail = $r->dir_config('lonSysEMail');
                   7313:                 &Apache::lonmsg::sendemail($sysmail,"LON-CAPA Domain Settings Change - $dom",$mailmsgtext);
                   7314:             }
1.43      raeburn  7315:         } else {
1.54      raeburn  7316:             $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43      raeburn  7317:         }
                   7318:     } else {
                   7319:         $resulttext = '<span class="LC_error">'.
                   7320:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   7321:     }
                   7322:     if (@errors > 0) {
                   7323:         $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
                   7324:         foreach my $item (@errors) {
                   7325:             $resulttext .= ' "'.$title->{$item}.'",';
                   7326:         }
                   7327:         $resulttext =~ s/,$//;
                   7328:     }
                   7329:     return $resulttext;
                   7330: }
                   7331: 
1.46      raeburn  7332: sub modify_scantron {
1.48      raeburn  7333:     my ($r,$dom,$confname,%domconfig) = @_;
1.46      raeburn  7334:     my ($resulttext,%confhash,%changes,$errors);
                   7335:     my $custom = 'custom.tab';
                   7336:     my $default = 'default.tab';
                   7337:     my $servadm = $r->dir_config('lonAdmEMail');
                   7338:     my ($configuserok,$author_ok,$switchserver) = 
                   7339:         &config_check($dom,$confname,$servadm);
                   7340:     if ($env{'form.scantronformat.filename'} ne '') {
                   7341:         my $error;
                   7342:         if ($configuserok eq 'ok') {
                   7343:             if ($switchserver) {
1.130     raeburn  7344:                 $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46      raeburn  7345:             } else {
                   7346:                 if ($author_ok eq 'ok') {
                   7347:                     my ($result,$scantronurl) =
                   7348:                         &publishlogo($r,'upload','scantronformat',$dom,
                   7349:                                      $confname,'scantron','','',$custom);
                   7350:                     if ($result eq 'ok') {
                   7351:                         $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48      raeburn  7352:                         $changes{'scantronformat'} = 1;
1.46      raeburn  7353:                     } else {
                   7354:                         $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
                   7355:                     }
                   7356:                 } else {
                   7357:                     $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);
                   7358:                 }
                   7359:             }
                   7360:         } else {
                   7361:             $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);
                   7362:         }
                   7363:         if ($error) {
                   7364:             &Apache::lonnet::logthis($error);
                   7365:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   7366:         }
                   7367:     }
1.48      raeburn  7368:     if (ref($domconfig{'scantron'}) eq 'HASH') {
                   7369:         if ($domconfig{'scantron'}{'scantronformat'} ne '') {
                   7370:             if ($env{'form.scantronformat_del'}) {
                   7371:                 $confhash{'scantron'}{'scantronformat'} = '';
                   7372:                 $changes{'scantronformat'} = 1;
1.46      raeburn  7373:             }
                   7374:         }
                   7375:     }
                   7376:     if (keys(%confhash) > 0) {
                   7377:         my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
                   7378:                                                  $dom);
                   7379:         if ($putresult eq 'ok') {
                   7380:             if (keys(%changes) > 0) {
1.48      raeburn  7381:                 if (ref($confhash{'scantron'}) eq 'HASH') {
                   7382:                     $resulttext = &mt('Changes made:').'<ul>';
                   7383:                     if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130     raeburn  7384:                         $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48      raeburn  7385:                     } else {
1.130     raeburn  7386:                         $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46      raeburn  7387:                     }
1.48      raeburn  7388:                     $resulttext .= '</ul>';
                   7389:                 } else {
1.130     raeburn  7390:                     $resulttext = &mt('Changes made to bubblesheet format file.');
1.46      raeburn  7391:                 }
                   7392:                 $resulttext .= '</ul>';
                   7393:                 &Apache::loncommon::devalidate_domconfig_cache($dom);
                   7394:             } else {
1.130     raeburn  7395:                 $resulttext = &mt('No changes made to bubblesheet format file');
1.46      raeburn  7396:             }
                   7397:         } else {
                   7398:             $resulttext = '<span class="LC_error">'.
                   7399:                 &mt('An error occurred: [_1]',$putresult).'</span>';
                   7400:         }
                   7401:     } else {
1.130     raeburn  7402:         $resulttext = &mt('No changes made to bubblesheet format file'); 
1.46      raeburn  7403:     }
                   7404:     if ($errors) {
                   7405:         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
                   7406:                        $errors.'</ul>';
                   7407:     }
                   7408:     return $resulttext;
                   7409: }
                   7410: 
1.48      raeburn  7411: sub modify_coursecategories {
                   7412:     my ($dom,%domconfig) = @_;
1.57      raeburn  7413:     my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
                   7414:         $cathash);
1.48      raeburn  7415:     my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.55      raeburn  7416:     if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57      raeburn  7417:         $cathash = $domconfig{'coursecategories'}{'cats'};
                   7418:         if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
                   7419:             $changes{'togglecats'} = 1;
                   7420:             $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
                   7421:         }
                   7422:         if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
                   7423:             $changes{'categorize'} = 1;
                   7424:             $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
                   7425:         }
1.120     raeburn  7426:         if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
                   7427:             $changes{'togglecatscomm'} = 1;
                   7428:             $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
                   7429:         }
                   7430:         if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
                   7431:             $changes{'categorizecomm'} = 1;
                   7432:             $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
                   7433:         }
1.57      raeburn  7434:     } else {
                   7435:         $changes{'togglecats'} = 1;
                   7436:         $changes{'categorize'} = 1;
1.124     raeburn  7437:         $changes{'togglecatscomm'} = 1;
                   7438:         $changes{'categorizecomm'} = 1;
1.87      raeburn  7439:         $domconfig{'coursecategories'} = {
                   7440:                                              togglecats => $env{'form.togglecats'},
                   7441:                                              categorize => $env{'form.categorize'},
1.124     raeburn  7442:                                              togglecatscomm => $env{'form.togglecatscomm'},
                   7443:                                              categorizecomm => $env{'form.categorizecomm'},
1.120     raeburn  7444:                                          };
1.57      raeburn  7445:     }
                   7446:     if (ref($cathash) eq 'HASH') {
                   7447:         if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '')  && ($env{'form.instcode'} == 0)) {
1.55      raeburn  7448:             push (@deletecategory,'instcode::0');
                   7449:         }
1.120     raeburn  7450:         if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '')  && ($env{'form.communities'} == 0)) {
                   7451:             push(@deletecategory,'communities::0');
                   7452:         }
1.48      raeburn  7453:     }
1.57      raeburn  7454:     my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
                   7455:     if (ref($cathash) eq 'HASH') {
1.48      raeburn  7456:         if (@deletecategory > 0) {
                   7457:             #FIXME Need to remove category from all courses using a deleted category 
1.57      raeburn  7458:             &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48      raeburn  7459:             foreach my $item (@deletecategory) {
1.57      raeburn  7460:                 if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
                   7461:                     delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48      raeburn  7462:                     $deletions{$item} = 1;
1.57      raeburn  7463:                     &recurse_cat_deletes($item,$cathash,\%deletions);
1.48      raeburn  7464:                 }
                   7465:             }
                   7466:         }
1.57      raeburn  7467:         foreach my $item (keys(%{$cathash})) {
1.48      raeburn  7468:             my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57      raeburn  7469:             if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48      raeburn  7470:                 $reorderings{$item} = 1;
1.57      raeburn  7471:                 $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48      raeburn  7472:             }
                   7473:             if ($env{'form.addcategory_name_'.$item} ne '') {
                   7474:                 my $newcat = $env{'form.addcategory_name_'.$item};
                   7475:                 my $newdepth = $depth+1;
                   7476:                 my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57      raeburn  7477:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48      raeburn  7478:                 $adds{$newitem} = 1; 
                   7479:             }
                   7480:             if ($env{'form.subcat_'.$item} ne '') {
                   7481:                 my $newcat = $env{'form.subcat_'.$item};
                   7482:                 my $newdepth = $depth+1;
                   7483:                 my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57      raeburn  7484:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48      raeburn  7485:                 $adds{$newitem} = 1;
                   7486:             }
                   7487:         }
                   7488:     }
                   7489:     if ($env{'form.instcode'} eq '1') {
1.57      raeburn  7490:         if (ref($cathash) eq 'HASH') {
1.48      raeburn  7491:             my $newitem = 'instcode::0';
1.57      raeburn  7492:             if ($cathash->{$newitem} eq '') {  
                   7493:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48      raeburn  7494:                 $adds{$newitem} = 1;
                   7495:             }
                   7496:         } else {
                   7497:             my $newitem = 'instcode::0';
1.57      raeburn  7498:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48      raeburn  7499:             $adds{$newitem} = 1;
                   7500:         }
                   7501:     }
1.120     raeburn  7502:     if ($env{'form.communities'} eq '1') {
                   7503:         if (ref($cathash) eq 'HASH') {
                   7504:             my $newitem = 'communities::0';
                   7505:             if ($cathash->{$newitem} eq '') {
                   7506:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
                   7507:                 $adds{$newitem} = 1;
                   7508:             }
                   7509:         } else {
                   7510:             my $newitem = 'communities::0';
                   7511:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
                   7512:             $adds{$newitem} = 1;
                   7513:         }
                   7514:     }
1.48      raeburn  7515:     if ($env{'form.addcategory_name'} ne '') {
1.120     raeburn  7516:         if (($env{'form.addcategory_name'} ne 'instcode') &&
                   7517:             ($env{'form.addcategory_name'} ne 'communities')) {
                   7518:             my $newitem = &escape($env{'form.addcategory_name'}).'::0';
                   7519:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
                   7520:             $adds{$newitem} = 1;
                   7521:         }
1.48      raeburn  7522:     }
1.57      raeburn  7523:     my $putresult;
1.48      raeburn  7524:     if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
                   7525:         if (keys(%deletions) > 0) {
                   7526:             foreach my $key (keys(%deletions)) {
                   7527:                 if ($predelallitems{$key} ne '') {
                   7528:                     $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
                   7529:                 }
                   7530:             }
                   7531:         }
                   7532:         my (@chkcats,@chktrails,%chkallitems);
1.57      raeburn  7533:         &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48      raeburn  7534:         if (ref($chkcats[0]) eq 'ARRAY') {
                   7535:             my $depth = 0;
                   7536:             my $chg = 0;
                   7537:             for (my $i=0; $i<@{$chkcats[0]}; $i++) {
                   7538:                 my $name = $chkcats[0][$i];
                   7539:                 my $item;
                   7540:                 if ($name eq '') {
                   7541:                     $chg ++;
                   7542:                 } else {
                   7543:                     $item = &escape($name).'::0';
                   7544:                     if ($chg) {
1.57      raeburn  7545:                         $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48      raeburn  7546:                     }
                   7547:                     $depth ++; 
1.57      raeburn  7548:                     &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48      raeburn  7549:                     $depth --;
                   7550:                 }
                   7551:             }
                   7552:         }
1.57      raeburn  7553:     }
                   7554:     if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
                   7555:         $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48      raeburn  7556:         if ($putresult eq 'ok') {
1.57      raeburn  7557:             my %title = (
1.120     raeburn  7558:                          togglecats     => 'Show/Hide a course in catalog',
                   7559:                          categorize     => 'Assign a category to a course',
                   7560:                          togglecatscomm => 'Show/Hide a community in catalog',
                   7561:                          categorizecomm => 'Assign a category to a community',
1.57      raeburn  7562:                         );
                   7563:             my %level = (
1.120     raeburn  7564:                          dom  => 'set in Domain ("Modify Course/Community")',
                   7565:                          crs  => 'set in Course ("Course Configuration")',
                   7566:                          comm => 'set in Community ("Community Configuration")',
1.57      raeburn  7567:                         );
1.48      raeburn  7568:             $resulttext = &mt('Changes made:').'<ul>';
1.57      raeburn  7569:             if ($changes{'togglecats'}) {
                   7570:                 $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>'; 
                   7571:             }
                   7572:             if ($changes{'categorize'}) {
                   7573:                 $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48      raeburn  7574:             }
1.120     raeburn  7575:             if ($changes{'togglecatscomm'}) {
                   7576:                 $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
                   7577:             }
                   7578:             if ($changes{'categorizecomm'}) {
                   7579:                 $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
                   7580:             }
1.57      raeburn  7581:             if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
                   7582:                 my $cathash;
                   7583:                 if (ref($domconfig{'coursecategories'}) eq 'HASH') {
                   7584:                     $cathash = $domconfig{'coursecategories'}{'cats'};
                   7585:                 } else {
                   7586:                     $cathash = {};
                   7587:                 } 
                   7588:                 my (@cats,@trails,%allitems);
                   7589:                     &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
                   7590:                 if (keys(%deletions) > 0) {
                   7591:                     $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
                   7592:                     foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) { 
                   7593:                         $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
                   7594:                     }
                   7595:                     $resulttext .= '</ul></li>';
                   7596:                 }
                   7597:                 if (keys(%reorderings) > 0) {
                   7598:                     my %sort_by_trail;
                   7599:                     $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
                   7600:                     foreach my $key (keys(%reorderings)) {
                   7601:                         if ($allitems{$key} ne '') {
                   7602:                             $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
                   7603:                         }
1.48      raeburn  7604:                     }
1.57      raeburn  7605:                     foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
                   7606:                         $resulttext .= '<li>'.$trails[$trail].'</li>';
                   7607:                     }
                   7608:                     $resulttext .= '</ul></li>';
1.48      raeburn  7609:                 }
1.57      raeburn  7610:                 if (keys(%adds) > 0) {
                   7611:                     my %sort_by_trail;
                   7612:                     $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
                   7613:                     foreach my $key (keys(%adds)) {
                   7614:                         if ($allitems{$key} ne '') {
                   7615:                             $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
                   7616:                         }
                   7617:                     }
                   7618:                     foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
                   7619:                         $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48      raeburn  7620:                     }
1.57      raeburn  7621:                     $resulttext .= '</ul></li>';
1.48      raeburn  7622:                 }
                   7623:             }
                   7624:             $resulttext .= '</ul>';
                   7625:         } else {
                   7626:             $resulttext = '<span class="LC_error">'.
1.57      raeburn  7627:                           &mt('An error occurred: [_1]',$putresult).'</span>';
1.48      raeburn  7628:         }
                   7629:     } else {
1.120     raeburn  7630:         $resulttext = &mt('No changes made to course and community categories');
1.48      raeburn  7631:     }
                   7632:     return $resulttext;
                   7633: }
                   7634: 
1.69      raeburn  7635: sub modify_serverstatuses {
                   7636:     my ($dom,%domconfig) = @_;
                   7637:     my ($resulttext,%changes,%currserverstatus,%newserverstatus);
                   7638:     if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
                   7639:         %currserverstatus = %{$domconfig{'serverstatuses'}};
                   7640:     }
                   7641:     my @pages = &serverstatus_pages();
                   7642:     foreach my $type (@pages) {
                   7643:         $newserverstatus{$type}{'namedusers'} = '';
                   7644:         $newserverstatus{$type}{'machines'} = '';
                   7645:         if (defined($env{'form.'.$type.'_namedusers'})) {
                   7646:             my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
                   7647:             my @okusers;
                   7648:             foreach my $user (@users) {
                   7649:                 my ($uname,$udom) = split(/:/,$user);
                   7650:                 if (($udom =~ /^$match_domain$/) &&   
                   7651:                     (&Apache::lonnet::domain($udom)) &&
                   7652:                     ($uname =~ /^$match_username$/)) {
                   7653:                     if (!grep(/^\Q$user\E/,@okusers)) {
                   7654:                         push(@okusers,$user);
                   7655:                     }
                   7656:                 }
                   7657:             }
                   7658:             if (@okusers > 0) {
                   7659:                  @okusers = sort(@okusers);
                   7660:                  $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
                   7661:             }
                   7662:         }
                   7663:         if (defined($env{'form.'.$type.'_machines'})) {
                   7664:             my @machines = split(/,/,$env{'form.'.$type.'_machines'});
                   7665:             my @okmachines;
                   7666:             foreach my $ip (@machines) {
                   7667:                 my @parts = split(/\./,$ip);
                   7668:                 next if (@parts < 4);
                   7669:                 my $badip = 0;
                   7670:                 for (my $i=0; $i<4; $i++) {
                   7671:                     if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
                   7672:                         $badip = 1;
                   7673:                         last;
                   7674:                     }
                   7675:                 }
                   7676:                 if (!$badip) {
                   7677:                     push(@okmachines,$ip);     
                   7678:                 }
                   7679:             }
                   7680:             @okmachines = sort(@okmachines);
                   7681:             $newserverstatus{$type}{'machines'} = join(',',@okmachines);
                   7682:         }
                   7683:     }
                   7684:     my %serverstatushash =  (
                   7685:                                 serverstatuses => \%newserverstatus,
                   7686:                             );
                   7687:     foreach my $type (@pages) {
1.83      raeburn  7688:         foreach my $setting ('namedusers','machines') {
1.84      raeburn  7689:             my (@current,@new);
1.83      raeburn  7690:             if (ref($currserverstatus{$type}) eq 'HASH') {
1.84      raeburn  7691:                 if ($currserverstatus{$type}{$setting} ne '') { 
                   7692:                     @current = split(/,/,$currserverstatus{$type}{$setting});
                   7693:                 }
                   7694:             }
                   7695:             if ($newserverstatus{$type}{$setting} ne '') {
                   7696:                 @new = split(/,/,$newserverstatus{$type}{$setting});
1.83      raeburn  7697:             }
                   7698:             if (@current > 0) {
                   7699:                 if (@new > 0) {
                   7700:                     foreach my $item (@current) {
                   7701:                         if (!grep(/^\Q$item\E$/,@new)) {
                   7702:                             $changes{$type}{$setting} = 1;
1.82      raeburn  7703:                             last;
                   7704:                         }
                   7705:                     }
1.84      raeburn  7706:                     foreach my $item (@new) {
                   7707:                         if (!grep(/^\Q$item\E$/,@current)) {
                   7708:                             $changes{$type}{$setting} = 1;
                   7709:                             last;
1.82      raeburn  7710:                         }
                   7711:                     }
                   7712:                 } else {
1.83      raeburn  7713:                     $changes{$type}{$setting} = 1;
1.69      raeburn  7714:                 }
1.83      raeburn  7715:             } elsif (@new > 0) {
                   7716:                 $changes{$type}{$setting} = 1;
1.69      raeburn  7717:             }
                   7718:         }
                   7719:     }
                   7720:     if (keys(%changes) > 0) {
1.81      raeburn  7721:         my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69      raeburn  7722:         my $putresult = &Apache::lonnet::put_dom('configuration',
                   7723:                                                  \%serverstatushash,$dom);
                   7724:         if ($putresult eq 'ok') {
                   7725:             $resulttext .= &mt('Changes made:').'<ul>';
                   7726:             foreach my $type (@pages) {
1.84      raeburn  7727:                 if (ref($changes{$type}) eq 'HASH') {
1.69      raeburn  7728:                     $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84      raeburn  7729:                     if ($changes{$type}{'namedusers'}) {
1.69      raeburn  7730:                         if ($newserverstatus{$type}{'namedusers'} eq '') {
                   7731:                             $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
                   7732:                         } else {
                   7733:                             $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
                   7734:                         }
1.84      raeburn  7735:                     }
                   7736:                     if ($changes{$type}{'machines'}) {
1.69      raeburn  7737:                         if ($newserverstatus{$type}{'machines'} eq '') {
                   7738:                             $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
                   7739:                         } else {
                   7740:                             $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
                   7741:                         }
                   7742: 
                   7743:                     }
                   7744:                     $resulttext .= '</ul></li>';
                   7745:                 }
                   7746:             }
                   7747:             $resulttext .= '</ul>';
                   7748:         } else {
                   7749:             $resulttext = '<span class="LC_error">'.
                   7750:                           &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
                   7751: 
                   7752:         }
                   7753:     } else {
                   7754:         $resulttext = &mt('No changes made to access to server status pages');
                   7755:     }
                   7756:     return $resulttext;
                   7757: }
                   7758: 
1.118     jms      7759: sub modify_helpsettings {
1.122     jms      7760:     my ($r,$dom,$confname,%domconfig) = @_;
1.166     raeburn  7761:     my ($resulttext,$errors,%changes,%helphash);
                   7762:     my %defaultchecked = ('submitbugs' => 'on');
                   7763:     my @offon = ('off','on');
1.118     jms      7764:     my @toggles = ('submitbugs');
                   7765:     if (ref($domconfig{'helpsettings'}) eq 'HASH') {
                   7766:         foreach my $item (@toggles) {
1.166     raeburn  7767:             if ($defaultchecked{$item} eq 'on') { 
                   7768:                 if ($domconfig{'helpsettings'}{$item} eq '') {
                   7769:                     if ($env{'form.'.$item} eq '0') {
                   7770:                         $changes{$item} = 1;
                   7771:                     }
                   7772:                 } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
                   7773:                     $changes{$item} = 1;
                   7774:                 }
                   7775:             } elsif ($defaultchecked{$item} eq 'off') {
                   7776:                 if ($domconfig{'helpsettings'}{$item} eq '') {
                   7777:                     if ($env{'form.'.$item} eq '1') {
                   7778:                         $changes{$item} = 1;
                   7779:                     }
                   7780:                 } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
                   7781:                     $changes{$item} = 1;
                   7782:                 }
                   7783:             }
                   7784:             if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) { 
                   7785:                 $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
                   7786:             }
                   7787:         }
1.118     jms      7788:     }
1.123     jms      7789:     my $putresult;
                   7790:     if (keys(%changes) > 0) {
1.166     raeburn  7791:         $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168     raeburn  7792:         if ($putresult eq 'ok') {
1.166     raeburn  7793:             $resulttext = &mt('Changes made:').'<ul>';
                   7794:             foreach my $item (sort(keys(%changes))) {
                   7795:                 if ($item eq 'submitbugs') {
                   7796:                     $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
                   7797:                                               &Apache::loncommon::modal_link('http://bugs.loncapa.org',
                   7798:                                               &mt('LON-CAPA bug tracker'),600,500)).'</li>';
                   7799:                 }
                   7800:             }
                   7801:             $resulttext .= '</ul>';
                   7802:         } else {
                   7803:             $resulttext = &mt('No changes made to help settings');
1.168     raeburn  7804:             $errors .= '<li><span class="LC_error">'.
                   7805:                        &mt('An error occurred storing the settings: [_1]',
                   7806:                            $putresult).'</span></li>';
1.166     raeburn  7807:         }
1.118     jms      7808:     }
                   7809:     if ($errors) {
1.168     raeburn  7810:         $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.118     jms      7811:                        $errors.'</ul>';
                   7812:     }
                   7813:     return $resulttext;
                   7814: }
                   7815: 
1.121     raeburn  7816: sub modify_coursedefaults {
                   7817:     my ($dom,%domconfig) = @_;
                   7818:     my ($resulttext,$errors,%changes,%defaultshash);
                   7819:     my %defaultchecked = ('canuse_pdfforms' => 'off');
                   7820:     my @offon = ('off','on');
                   7821:     my @toggles = ('canuse_pdfforms');
                   7822: 
                   7823:     $defaultshash{'coursedefaults'} = {};
                   7824: 
                   7825:     if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
                   7826:         if ($domconfig{'coursedefaults'} eq '') {
                   7827:             $domconfig{'coursedefaults'} = {};
                   7828:         }
                   7829:     }
                   7830: 
                   7831:     if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
                   7832:         foreach my $item (@toggles) {
                   7833:             if ($defaultchecked{$item} eq 'on') {
                   7834:                 if (($domconfig{'coursedefaults'}{$item} eq '') &&
                   7835:                     ($env{'form.'.$item} eq '0')) {
                   7836:                     $changes{$item} = 1;
                   7837:                 } elsif ($domconfig{'coursdefaults'}{$item} ne $env{'form.'.$item}) {
                   7838:                     $changes{$item} = 1;
                   7839:                 }
                   7840:             } elsif ($defaultchecked{$item} eq 'off') {
                   7841:                 if (($domconfig{'coursedefaults'}{$item} eq '') &&
                   7842:                     ($env{'form.'.$item} eq '1')) {
                   7843:                     $changes{$item} = 1;
                   7844:                 } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
                   7845:                     $changes{$item} = 1;
                   7846:                 }
                   7847:             }
                   7848:             $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
                   7849:         }
1.139     raeburn  7850:         my $currdefresponder = $domconfig{'coursedefaults'}{'anonsurvey_threshold'};
                   7851:         my $newdefresponder = $env{'form.anonsurvey_threshold'};
                   7852:         $newdefresponder =~ s/\D//g;
                   7853:         if ($newdefresponder eq '' || $newdefresponder < 1) {
                   7854:             $newdefresponder = 1;
                   7855:         }
                   7856:         $defaultshash{'coursedefaults'}{'anonsurvey_threshold'} = $newdefresponder;
                   7857:         if ($currdefresponder ne $newdefresponder) {
                   7858:             unless ($currdefresponder eq '' && $newdefresponder == 10) {
                   7859:                 $changes{'anonsurvey_threshold'} = 1;
                   7860:             }
                   7861:         }
1.121     raeburn  7862:     }
                   7863:     my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
                   7864:                                              $dom);
                   7865:     if ($putresult eq 'ok') {
                   7866:         if (keys(%changes) > 0) {
                   7867:             if ($changes{'canuse_pdfforms'}) {
                   7868:                 my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
                   7869:                 $domdefaults{'canuse_pdfforms'}=$defaultshash{'coursedefaults'}{'canuse_pdfforms'};
                   7870:                 my $cachetime = 24*60*60;
                   7871:                 &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
                   7872:             }
                   7873:             $resulttext = &mt('Changes made:').'<ul>';
                   7874:             foreach my $item (sort(keys(%changes))) {
                   7875:                 if ($item eq 'canuse_pdfforms') {
                   7876:                     if ($env{'form.'.$item} eq '1') {
                   7877:                         $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
                   7878:                     } else {
                   7879:                         $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
                   7880:                     }
1.139     raeburn  7881:                 } elsif ($item eq 'anonsurvey_threshold') {
                   7882:                         $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.140     raeburn  7883:                 }
1.121     raeburn  7884:             }
                   7885:             $resulttext .= '</ul>';
                   7886:         } else {
                   7887:             $resulttext = &mt('No changes made to course defaults');
                   7888:         }
                   7889:     } else {
                   7890:         $resulttext = '<span class="LC_error">'.
                   7891:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   7892:     }
                   7893:     return $resulttext;
                   7894: }
                   7895: 
1.137     raeburn  7896: sub modify_usersessions {
                   7897:     my ($dom,%domconfig) = @_;
1.145     raeburn  7898:     my @hostingtypes = ('version','excludedomain','includedomain');
                   7899:     my @offloadtypes = ('primary','default');
                   7900:     my %types = (
                   7901:                   remote => \@hostingtypes,
                   7902:                   hosted => \@hostingtypes,
                   7903:                   spares => \@offloadtypes,
                   7904:                 );
                   7905:     my @prefixes = ('remote','hosted','spares');
1.137     raeburn  7906:     my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138     raeburn  7907:     my (%by_ip,%by_location,@intdoms);
                   7908:     &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
                   7909:     my @locations = sort(keys(%by_location));
1.137     raeburn  7910:     my (%defaultshash,%changes);
                   7911:     foreach my $prefix (@prefixes) {
                   7912:         $defaultshash{'usersessions'}{$prefix} = {};
                   7913:     }
                   7914:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
                   7915:     my $resulttext;
1.138     raeburn  7916:     my %iphost = &Apache::lonnet::get_iphost();
1.137     raeburn  7917:     foreach my $prefix (@prefixes) {
1.145     raeburn  7918:         next if ($prefix eq 'spares');
                   7919:         foreach my $type (@{$types{$prefix}}) {
1.137     raeburn  7920:             my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
                   7921:             if ($type eq 'version') {
                   7922:                 my $value = $env{'form.'.$prefix.'_'.$type};
                   7923:                 my $okvalue;
                   7924:                 if ($value ne '') {
                   7925:                     if (grep(/^\Q$value\E$/,@lcversions)) {
                   7926:                         $okvalue = $value;
                   7927:                     }
                   7928:                 }
                   7929:                 if (ref($domconfig{'usersessions'}) eq 'HASH') {
                   7930:                     if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
                   7931:                         if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
                   7932:                             if ($inuse == 0) {
                   7933:                                 $changes{$prefix}{$type} = 1;
                   7934:                             } else {
                   7935:                                 if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
                   7936:                                     $changes{$prefix}{$type} = 1;
                   7937:                                 }
                   7938:                                 if ($okvalue ne '') {
                   7939:                                     $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
                   7940:                                 } 
                   7941:                             }
                   7942:                         } else {
                   7943:                             if (($inuse == 1) && ($okvalue ne '')) {
                   7944:                                 $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
                   7945:                                 $changes{$prefix}{$type} = 1;
                   7946:                             }
                   7947:                         }
                   7948:                     } else {
                   7949:                         if (($inuse == 1) && ($okvalue ne '')) {
                   7950:                             $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
                   7951:                             $changes{$prefix}{$type} = 1;
                   7952:                         }
                   7953:                     }
                   7954:                 } else {
                   7955:                     if (($inuse == 1) && ($okvalue ne '')) {
                   7956:                         $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
                   7957:                         $changes{$prefix}{$type} = 1;
                   7958:                     }
                   7959:                 }
                   7960:             } else {
                   7961:                 my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
                   7962:                 my @okvals;
                   7963:                 foreach my $val (@vals) {
1.138     raeburn  7964:                     if ($val =~ /:/) {
                   7965:                         my @items = split(/:/,$val);
                   7966:                         foreach my $item (@items) {
                   7967:                             if (ref($by_location{$item}) eq 'ARRAY') {
                   7968:                                 push(@okvals,$item);
                   7969:                             }
                   7970:                         }
                   7971:                     } else {
                   7972:                         if (ref($by_location{$val}) eq 'ARRAY') {
                   7973:                             push(@okvals,$val);
                   7974:                         }
1.137     raeburn  7975:                     }
                   7976:                 }
                   7977:                 @okvals = sort(@okvals);
                   7978:                 if (ref($domconfig{'usersessions'}) eq 'HASH') {
                   7979:                     if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
                   7980:                         if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
                   7981:                             if ($inuse == 0) {
                   7982:                                 $changes{$prefix}{$type} = 1; 
                   7983:                             } else {
                   7984:                                 $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
                   7985:                                 my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
                   7986:                                 if (@changed > 0) {
                   7987:                                     $changes{$prefix}{$type} = 1;
                   7988:                                 }
                   7989:                             }
                   7990:                         } else {
                   7991:                             if ($inuse == 1) {
                   7992:                                 $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
                   7993:                                 $changes{$prefix}{$type} = 1;
                   7994:                             }
                   7995:                         } 
                   7996:                     } else {
                   7997:                         if ($inuse == 1) {
                   7998:                             $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
                   7999:                             $changes{$prefix}{$type} = 1;
                   8000:                         }
                   8001:                     }
                   8002:                 } else {
                   8003:                     if ($inuse == 1) {
                   8004:                         $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
                   8005:                         $changes{$prefix}{$type} = 1;
                   8006:                     }
                   8007:                 }
                   8008:             }
                   8009:         }
                   8010:     }
1.145     raeburn  8011: 
                   8012:     my @alldoms = &Apache::lonnet::all_domains();
1.149     raeburn  8013:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145     raeburn  8014:     my %spareid = &current_offloads_to($dom,$domconfig{'usersessions'},\%servers);
                   8015:     my $savespares;
                   8016: 
                   8017:     foreach my $lonhost (sort(keys(%servers))) {
                   8018:         my $serverhomeID =
                   8019:             &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152     raeburn  8020:         my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145     raeburn  8021:         $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
                   8022:         my %spareschg;
                   8023:         foreach my $type (@{$types{'spares'}}) {
                   8024:             my @okspares;
                   8025:             my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
                   8026:             foreach my $server (@checked) {
1.152     raeburn  8027:                 if (&Apache::lonnet::hostname($server) ne '') {
                   8028:                     unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
                   8029:                         unless (grep(/^\Q$server\E$/,@okspares)) {
                   8030:                             push(@okspares,$server);
                   8031:                         }
1.145     raeburn  8032:                     }
                   8033:                 }
                   8034:             }
                   8035:             my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
                   8036:             my $newspare;
1.152     raeburn  8037:             if (($new ne '') && (&Apache::lonnet::hostname($new))) {
                   8038:                 unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145     raeburn  8039:                     $newspare = $new;
                   8040:                 }
                   8041:             }
1.152     raeburn  8042:             my @spares;
                   8043:             if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
                   8044:                 @spares = sort(@okspares,$newspare);
                   8045:             } else {
                   8046:                 @spares = sort(@okspares);
                   8047:             }
                   8048:             $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145     raeburn  8049:             if (ref($spareid{$lonhost}) eq 'HASH') {
                   8050:                 if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152     raeburn  8051:                     my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145     raeburn  8052:                     if (@diffs > 0) {
                   8053:                         $spareschg{$type} = 1;
                   8054:                     }
                   8055:                 }
                   8056:             }
                   8057:         }
                   8058:         if (keys(%spareschg) > 0) {
                   8059:             $changes{'spares'}{$lonhost} = \%spareschg;
                   8060:         }
                   8061:     }
                   8062: 
                   8063:     if (ref($domconfig{'usersessions'}) eq 'HASH') {
                   8064:         if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
                   8065:             if (ref($changes{'spares'}) eq 'HASH') {
                   8066:                 if (keys(%{$changes{'spares'}}) > 0) {
                   8067:                     $savespares = 1;
                   8068:                 }
                   8069:             }
                   8070:         } else {
                   8071:             $savespares = 1;
                   8072:         }
                   8073:     }
                   8074: 
1.147     raeburn  8075:     my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
                   8076:     if ((keys(%changes) > 0) || ($savespares)) {
1.137     raeburn  8077:         my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
                   8078:                                                  $dom);
                   8079:         if ($putresult eq 'ok') {
                   8080:             if (ref($defaultshash{'usersessions'}) eq 'HASH') {
                   8081:                 if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
                   8082:                     $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
                   8083:                 }
                   8084:                 if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
                   8085:                     $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
                   8086:                 }
                   8087:             }
                   8088:             my $cachetime = 24*60*60;
                   8089:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.147     raeburn  8090:             if (keys(%changes) > 0) {
                   8091:                 my %lt = &usersession_titles();
                   8092:                 $resulttext = &mt('Changes made:').'<ul>';
                   8093:                 foreach my $prefix (@prefixes) {
                   8094:                     if (ref($changes{$prefix}) eq 'HASH') {
                   8095:                         $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
                   8096:                         if ($prefix eq 'spares') {
                   8097:                             if (ref($changes{$prefix}) eq 'HASH') {
                   8098:                                 foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
                   8099:                                     $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148     raeburn  8100:                                     my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
                   8101:                                     &Apache::lonnet::remote_devalidate_cache($lonhost,'spares',$lonhostdom);
1.147     raeburn  8102:                                     if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
                   8103:                                         foreach my $type (@{$types{$prefix}}) {
                   8104:                                             if ($changes{$prefix}{$lonhost}{$type}) {
                   8105:                                                 my $offloadto = &mt('None');
                   8106:                                                 if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
                   8107:                                                     if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {   
                   8108:                                                         $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
                   8109:                                                     }
1.145     raeburn  8110:                                                 }
1.147     raeburn  8111:                                                 $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).('&nbsp;'x3);
1.145     raeburn  8112:                                             }
1.137     raeburn  8113:                                         }
                   8114:                                     }
1.147     raeburn  8115:                                     $resulttext .= '</li>';
1.137     raeburn  8116:                                 }
                   8117:                             }
1.147     raeburn  8118:                         } else {
                   8119:                             foreach my $type (@{$types{$prefix}}) {
                   8120:                                 if (defined($changes{$prefix}{$type})) {
                   8121:                                     my $newvalue;
                   8122:                                     if (ref($defaultshash{'usersessions'}) eq 'HASH') {
                   8123:                                         if (ref($defaultshash{'usersessions'}{$prefix})) {
                   8124:                                             if ($type eq 'version') {
                   8125:                                                 $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
                   8126:                                             } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
                   8127:                                                 if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
                   8128:                                                     $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
                   8129:                                                 }
1.145     raeburn  8130:                                             }
                   8131:                                         }
                   8132:                                     }
1.147     raeburn  8133:                                     if ($newvalue eq '') {
                   8134:                                         if ($type eq 'version') {
                   8135:                                             $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
                   8136:                                         } else {
                   8137:                                             $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
                   8138:                                         }
1.145     raeburn  8139:                                     } else {
1.147     raeburn  8140:                                         if ($type eq 'version') {
                   8141:                                             $newvalue .= ' '.&mt('(or later)'); 
                   8142:                                         }
                   8143:                                         $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145     raeburn  8144:                                     }
1.137     raeburn  8145:                                 }
                   8146:                             }
                   8147:                         }
1.147     raeburn  8148:                         $resulttext .= '</ul>';
1.137     raeburn  8149:                     }
                   8150:                 }
1.147     raeburn  8151:                 $resulttext .= '</ul>';
                   8152:             } else {
                   8153:                 $resulttext = $nochgmsg;
1.137     raeburn  8154:             }
                   8155:         } else {
                   8156:             $resulttext = '<span class="LC_error">'.
                   8157:                           &mt('An error occurred: [_1]',$putresult).'</span>';
                   8158:         }
                   8159:     } else {
1.147     raeburn  8160:         $resulttext = $nochgmsg;
1.137     raeburn  8161:     }
                   8162:     return $resulttext;
                   8163: }
                   8164: 
1.150     raeburn  8165: sub modify_loadbalancing {
                   8166:     my ($dom,%domconfig) = @_;
                   8167:     my $primary_id = &Apache::lonnet::domain($dom,'primary');
                   8168:     my $intdom = &Apache::lonnet::internet_dom($primary_id);
                   8169:     my ($othertitle,$usertypes,$types) =
                   8170:         &Apache::loncommon::sorted_inst_types($dom);
                   8171:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
                   8172:     my @sparestypes = ('primary','default');
                   8173:     my %typetitles = &sparestype_titles();
                   8174:     my $resulttext;
1.171     raeburn  8175:     my (%currbalancer,%currtargets,%currrules,%existing);
                   8176:     if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
                   8177:         %existing = %{$domconfig{'loadbalancing'}};
                   8178:     }
                   8179:     &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
                   8180:                               \%currtargets,\%currrules);
                   8181:     my ($saveloadbalancing,%defaultshash,%changes);
                   8182:     my ($alltypes,$othertypes,$titles) =
                   8183:         &loadbalancing_titles($dom,$intdom,$usertypes,$types);
                   8184:     my %ruletitles = &offloadtype_text();
                   8185:     my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
                   8186:     for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
                   8187:         my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
                   8188:         if ($balancer eq '') {
                   8189:             next;
                   8190:         }
                   8191:         if (!exists($servers{$balancer})) { 
                   8192:             if (exists($currbalancer{$balancer})) {
                   8193:                 push(@{$changes{'delete'}},$balancer);
1.150     raeburn  8194:             }
1.171     raeburn  8195:             next;
                   8196:         }
                   8197:         if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
                   8198:             push(@{$changes{'delete'}},$balancer);
                   8199:             next;
                   8200:         }
                   8201:         if (!exists($currbalancer{$balancer})) {
                   8202:             push(@{$changes{'add'}},$balancer);
                   8203:         }
                   8204:         $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
                   8205:         $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
                   8206:         $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
                   8207:         unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
                   8208:             $saveloadbalancing = 1;
                   8209:         }
                   8210:         foreach my $sparetype (@sparestypes) {
                   8211:             my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
                   8212:             my @offloadto;
                   8213:             foreach my $target (@targets) {
                   8214:                 if (($servers{$target}) && ($target ne $balancer)) {
                   8215:                     if ($sparetype eq 'default') {
                   8216:                         if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
                   8217:                             next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150     raeburn  8218:                         }
                   8219:                     }
1.171     raeburn  8220:                     unless(grep(/^\Q$target\E$/,@offloadto)) {
                   8221:                         push(@offloadto,$target);
                   8222:                     }
1.150     raeburn  8223:                 }
1.171     raeburn  8224:                 $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150     raeburn  8225:             }
                   8226:         }
1.171     raeburn  8227:         if (ref($currtargets{$balancer}) eq 'HASH') {
1.150     raeburn  8228:             foreach my $sparetype (@sparestypes) {
1.171     raeburn  8229:                 if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
                   8230:                     my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150     raeburn  8231:                     if (@targetdiffs > 0) {
1.171     raeburn  8232:                         $changes{'curr'}{$balancer}{'targets'} = 1;
1.150     raeburn  8233:                     }
1.171     raeburn  8234:                 } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
                   8235:                     if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
                   8236:                         $changes{'curr'}{$balancer}{'targets'} = 1;
1.150     raeburn  8237:                     }
                   8238:                 }
                   8239:             }
                   8240:         } else {
1.171     raeburn  8241:             if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
                   8242:                 foreach my $sparetype (@sparestypes) { 
                   8243:                     if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
                   8244:                         if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
                   8245:                             $changes{'curr'}{$balancer}{'targets'} = 1;
                   8246:                         }
1.150     raeburn  8247:                     }
                   8248:                 }
                   8249:             }  
                   8250:         }
                   8251:         my $ishomedom;
1.171     raeburn  8252:         if (&Apache::lonnet::host_domain($balancer) eq $dom) {
                   8253:             $ishomedom = 1;
1.150     raeburn  8254:         }
                   8255:         if (ref($alltypes) eq 'ARRAY') {
                   8256:             foreach my $type (@{$alltypes}) {
                   8257:                 my $rule;
1.171     raeburn  8258:                 unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) && 
1.150     raeburn  8259:                          (!$ishomedom)) {
1.171     raeburn  8260:                     $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
                   8261:                 }
                   8262:                 if ($rule eq 'specific') {
                   8263:                     $rule = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.150     raeburn  8264:                 }
1.171     raeburn  8265:                 $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
                   8266:                 if (ref($currrules{$balancer}) eq 'HASH') {
                   8267:                     if ($rule ne $currrules{$balancer}{$type}) {
                   8268:                         $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150     raeburn  8269:                     }
                   8270:                 } elsif ($rule ne '') {
1.171     raeburn  8271:                     $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150     raeburn  8272:                 }
                   8273:             }
                   8274:         }
1.171     raeburn  8275:     }
                   8276:     my $nochgmsg = &mt('No changes made to Load Balancer settings.');
                   8277:     if ((keys(%changes) > 0) || ($saveloadbalancing)) {
                   8278:         unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
                   8279:             $defaultshash{'loadbalancing'} = {};
                   8280:         }
                   8281:         my $putresult = &Apache::lonnet::put_dom('configuration',
                   8282:                                                  \%defaultshash,$dom);
                   8283:  
                   8284:         if ($putresult eq 'ok') {
                   8285:             if (keys(%changes) > 0) {
                   8286:                 if (ref($changes{'delete'}) eq 'ARRAY') {
                   8287:                     foreach my $balancer (sort(@{$changes{'delete'}})) {
                   8288:                         $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.150     raeburn  8289:                         &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
                   8290:                     }
1.171     raeburn  8291:                 }
                   8292:                 if (ref($changes{'add'}) eq 'ARRAY') {
                   8293:                     foreach my $balancer (sort(@{$changes{'add'}})) {   
                   8294:                         $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
                   8295:                     }
                   8296:                 }
                   8297:                 if (ref($changes{'curr'}) eq 'HASH') {
                   8298:                     foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
                   8299:                         if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
                   8300:                             if ($changes{'curr'}{$balancer}{'targets'}) {
                   8301:                                 my %offloadstr;
                   8302:                                 foreach my $sparetype (@sparestypes) {
                   8303:                                     if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
                   8304:                                         if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
                   8305:                                             $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
                   8306:                                         }
                   8307:                                     }
1.150     raeburn  8308:                                 }
1.171     raeburn  8309:                                 if (keys(%offloadstr) == 0) {
                   8310:                                     $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150     raeburn  8311:                                 } else {
1.171     raeburn  8312:                                     my $showoffload;
                   8313:                                     foreach my $sparetype (@sparestypes) {
                   8314:                                         $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>:&nbsp;';
                   8315:                                         if (defined($offloadstr{$sparetype})) {
                   8316:                                             $showoffload .= $offloadstr{$sparetype};
                   8317:                                         } else {
                   8318:                                             $showoffload .= &mt('None');
                   8319:                                         }
                   8320:                                         $showoffload .= ('&nbsp;'x3);
                   8321:                                     }
                   8322:                                     $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150     raeburn  8323:                                 }
                   8324:                             }
                   8325:                         }
1.171     raeburn  8326:                         if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
                   8327:                             if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
                   8328:                                 foreach my $type (@{$alltypes}) {
                   8329:                                     if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
                   8330:                                         my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
                   8331:                                         my $balancetext;
                   8332:                                         if ($rule eq '') {
                   8333:                                             $balancetext =  $ruletitles{'default'};
                   8334:                                         } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer')) {
                   8335:                                             $balancetext =  $ruletitles{$rule};
                   8336:                                         } else {
                   8337:                                             $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
                   8338:                                         }
                   8339:                                         $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';     
1.150     raeburn  8340:                                     }
                   8341:                                 }
                   8342:                             }
                   8343:                         }
1.171     raeburn  8344:                         &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
1.150     raeburn  8345:                     }
1.171     raeburn  8346:                 }
                   8347:                 if ($resulttext ne '') {
                   8348:                     $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150     raeburn  8349:                 } else {
                   8350:                     $resulttext = $nochgmsg;
                   8351:                 }
                   8352:             } else {
1.171     raeburn  8353:                 $resulttext = $nochgmsg;
1.150     raeburn  8354:             }
                   8355:         } else {
1.171     raeburn  8356:             $resulttext = '<span class="LC_error">'.
                   8357:                           &mt('An error occurred: [_1]',$putresult).'</span>';
1.150     raeburn  8358:         }
                   8359:     } else {
1.171     raeburn  8360:         $resulttext = $nochgmsg;
1.150     raeburn  8361:     }
                   8362:     return $resulttext;
                   8363: }
                   8364: 
1.48      raeburn  8365: sub recurse_check {
                   8366:     my ($chkcats,$categories,$depth,$name) = @_;
                   8367:     if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
                   8368:         my $chg = 0;
                   8369:         for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
                   8370:             my $category = $chkcats->[$depth]{$name}[$j];
                   8371:             my $item;
                   8372:             if ($category eq '') {
                   8373:                 $chg ++;
                   8374:             } else {
                   8375:                 my $deeper = $depth + 1;
                   8376:                 $item = &escape($category).':'.&escape($name).':'.$depth;
                   8377:                 if ($chg) {
                   8378:                     $categories->{$item} -= $chg;
                   8379:                 }
                   8380:                 &recurse_check($chkcats,$categories,$deeper,$category);
                   8381:                 $deeper --;
                   8382:             }
                   8383:         }
                   8384:     }
                   8385:     return;
                   8386: }
                   8387: 
                   8388: sub recurse_cat_deletes {
                   8389:     my ($item,$coursecategories,$deletions) = @_;
                   8390:     my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
                   8391:     my $subdepth = $depth + 1;
                   8392:     if (ref($coursecategories) eq 'HASH') {
                   8393:         foreach my $subitem (keys(%{$coursecategories})) {
                   8394:             my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
                   8395:             if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
                   8396:                 delete($coursecategories->{$subitem});
                   8397:                 $deletions->{$subitem} = 1;
                   8398:                 &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168     raeburn  8399:             }
1.48      raeburn  8400:         }
                   8401:     }
                   8402:     return;
                   8403: }
                   8404: 
1.125     raeburn  8405: sub get_active_dcs {
                   8406:     my ($dom) = @_;
                   8407:     my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc']);
                   8408:     my %domcoords;
                   8409:     my $numdcs = 0;
                   8410:     my $now = time;
                   8411:     foreach my $server (keys(%dompersonnel)) {
                   8412:         foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
                   8413:             my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
                   8414:             my ($end,$start) = split(':',$dompersonnel{$server}{$user});
                   8415:             if (($end eq '') || ($end == 0) || ($end > $now)) {
                   8416:                 if ($start <= $now) {
                   8417:                     $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
                   8418:                 }
                   8419:             }
                   8420:         }
                   8421:     }
                   8422:     return %domcoords;
                   8423: }
                   8424: 
                   8425: sub active_dc_picker {
                   8426:     my ($dom,$curr_dc) = @_;
                   8427:     my %domcoords = &get_active_dcs($dom); 
                   8428:     my @dcs = sort(keys(%domcoords));
                   8429:     my $numdcs = scalar(@dcs); 
                   8430:     my $datatable;
                   8431:     my $numinrow = 2;
                   8432:     if ($numdcs > 1) {
                   8433:         $datatable = '<table>';
                   8434:         for (my $i=0; $i<@dcs; $i++) {
                   8435:             my $rem = $i%($numinrow);
                   8436:             if ($rem == 0) {
                   8437:                 if ($i > 0) {
                   8438:                     $datatable .= '</tr>';
                   8439:                 }
                   8440:                 $datatable .= '<tr>';
                   8441:             }
                   8442:             my $check = ' ';
                   8443:             if ($curr_dc eq '') {
                   8444:                 if (!$i) { 
                   8445:                     $check = ' checked="checked" ';
                   8446:                 }
                   8447:             } elsif ($dcs[$i] eq $curr_dc) {
                   8448:                 $check = ' checked="checked" ';
                   8449:             }
                   8450:             if ($i == @dcs - 1) {
                   8451:                 my $colsleft = $numinrow - $rem;
                   8452:                 if ($colsleft > 1) {
                   8453:                     $datatable .= '<td colspan="'.$colsleft.'">';
                   8454:                 } else {
                   8455:                     $datatable .= '<td>';
                   8456:                 }
                   8457:             } else {
                   8458:                 $datatable .= '<td>';
                   8459:             }
                   8460:             my ($dcname,$dcdom) = split(':',$dcs[$i]);
                   8461:             $datatable .= '<span class="LC_nobreak"><label>'.
                   8462:                           '<input type="radio" name="autocreate_xmldc"'.
                   8463:                           ' value="'.$dcs[$i].'"'.$check.'/>'.
                   8464:                           &Apache::loncommon::plainname($dcname,$dcdom).
                   8465:                           '</label></span></td>';
                   8466:         }
                   8467:         $datatable .= '</tr></table>';
                   8468:     } elsif (@dcs) {
                   8469:         $datatable .= '<input type="hidden" name="autocreate_dc" value="'.
                   8470:                       $dcs[0].'" />';
                   8471:     }
                   8472:     return ($numdcs,$datatable);
                   8473: }
                   8474: 
1.137     raeburn  8475: sub usersession_titles {
                   8476:     return &Apache::lonlocal::texthash(
                   8477:                hosted => 'Hosting of sessions for users from other domains on servers in this domain',
                   8478:                remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145     raeburn  8479:                spares => 'Servers offloaded to, when busy',
1.137     raeburn  8480:                version => 'LON-CAPA version requirement',
1.138     raeburn  8481:                excludedomain => 'Allow all, but exclude specific domains',
                   8482:                includedomain => 'Deny all, but include specific domains',
1.145     raeburn  8483:                primary => 'Primary (checked first)',
1.154     raeburn  8484:                default => 'Default',
1.137     raeburn  8485:            );
                   8486: }
                   8487: 
1.152     raeburn  8488: sub id_for_thisdom {
                   8489:     my (%servers) = @_;
                   8490:     my %altids;
                   8491:     foreach my $server (keys(%servers)) {
                   8492:         my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
                   8493:         if ($serverhome ne $server) {
                   8494:             $altids{$serverhome} = $server;
                   8495:         }
                   8496:     }
                   8497:     return %altids;
                   8498: }
                   8499: 
1.150     raeburn  8500: sub count_servers {
                   8501:     my ($currbalancer,%servers) = @_;
                   8502:     my (@spares,$numspares);
                   8503:     foreach my $lonhost (sort(keys(%servers))) {
                   8504:         next if ($currbalancer eq $lonhost);
                   8505:         push(@spares,$lonhost);
                   8506:     }
                   8507:     if ($currbalancer) {
                   8508:         $numspares = scalar(@spares);
                   8509:     } else {
                   8510:         $numspares = scalar(@spares) - 1;
                   8511:     }
                   8512:     return ($numspares,@spares);
                   8513: }
                   8514: 
                   8515: sub lonbalance_targets_js {
1.171     raeburn  8516:     my ($dom,$types,$servers,$settings) = @_;
1.150     raeburn  8517:     my $select = &mt('Select');
                   8518:     my ($alltargets,$allishome,$allinsttypes,@alltypes);
                   8519:     if (ref($servers) eq 'HASH') {
                   8520:         $alltargets = join("','",sort(keys(%{$servers})));
                   8521:         my @homedoms;
                   8522:         foreach my $server (sort(keys(%{$servers}))) {
                   8523:             if (&Apache::lonnet::host_domain($server) eq $dom) {
                   8524:                 push(@homedoms,'1');
                   8525:             } else {
                   8526:                 push(@homedoms,'0');
                   8527:             }
                   8528:         }
                   8529:         $allishome = join("','",@homedoms);
                   8530:     }
                   8531:     if (ref($types) eq 'ARRAY') {
                   8532:         if (@{$types} > 0) {
                   8533:             @alltypes = @{$types};
                   8534:         }
                   8535:     }
                   8536:     push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
                   8537:     $allinsttypes = join("','",@alltypes);
1.171     raeburn  8538:     my (%currbalancer,%currtargets,%currrules,%existing);
                   8539:     if (ref($settings) eq 'HASH') {
                   8540:         %existing = %{$settings};
                   8541:     }
                   8542:     &get_loadbalancers_config($servers,\%existing,\%currbalancer,
                   8543:                               \%currtargets,\%currrules);
                   8544:     my $balancers = join("','",sort(keys(%currbalancer))); 
1.150     raeburn  8545:     return <<"END";
                   8546: 
                   8547: <script type="text/javascript">
                   8548: // <![CDATA[
                   8549: 
1.171     raeburn  8550: currBalancers = new Array('$balancers');
                   8551: 
                   8552: function toggleTargets(balnum) {
                   8553:     var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
                   8554:     var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
                   8555:     var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
                   8556:     var prevbalancer = prevhostitem.value;
                   8557:     var baltotal = document.getElementById('loadbalancing_total').value;
                   8558:     prevhostitem.value = balancer;
                   8559:     if (prevbalancer != '') {
                   8560:         var prevIdx = currBalancers.indexOf(prevbalancer);
                   8561:         if (prevIdx != -1) {
                   8562:             currBalancers.splice(prevIdx,1);
                   8563:         }
                   8564:     }
1.150     raeburn  8565:     if (balancer == '') {
1.171     raeburn  8566:         hideSpares(balnum);
1.150     raeburn  8567:     } else {
1.171     raeburn  8568:         var currIdx = currBalancers.indexOf(balancer);
                   8569:         if (currIdx == -1) {
                   8570:             currBalancers.push(balancer);
                   8571:         }
1.150     raeburn  8572:         var homedoms = new Array('$allishome');
1.171     raeburn  8573:         var ishomedom = homedoms[lonhostitem.selectedIndex];
                   8574:         showSpares(balancer,ishomedom,balnum);
1.150     raeburn  8575:     }
1.171     raeburn  8576:     balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150     raeburn  8577:     return;
                   8578: }
                   8579: 
1.171     raeburn  8580: function showSpares(balancer,ishomedom,balnum) {
1.150     raeburn  8581:     var alltargets = new Array('$alltargets');
                   8582:     var insttypes = new Array('$allinsttypes');
1.151     raeburn  8583:     var offloadtypes = new Array('primary','default');
                   8584: 
1.171     raeburn  8585:     document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
                   8586:     document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152     raeburn  8587:  
1.151     raeburn  8588:     for (var i=0; i<offloadtypes.length; i++) {
                   8589:         var count = 0;
                   8590:         for (var j=0; j<alltargets.length; j++) {
                   8591:             if (alltargets[j] != balancer) {
1.171     raeburn  8592:                 var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
                   8593:                 item.value = alltargets[j];
                   8594:                 item.style.textAlign='left';
                   8595:                 item.style.textFace='normal';
                   8596:                 document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
                   8597:                 if (currBalancers.indexOf(alltargets[j]) == -1) {
                   8598:                     item.disabled = '';
                   8599:                 } else {
                   8600:                     item.disabled = 'disabled';
                   8601:                     item.checked = false;
                   8602:                 }
1.151     raeburn  8603:                 count ++;
                   8604:             }
1.150     raeburn  8605:         }
                   8606:     }
1.151     raeburn  8607:     for (var k=0; k<insttypes.length; k++) {
                   8608:         if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150     raeburn  8609:             if (ishomedom == 1) {
1.171     raeburn  8610:                 document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
                   8611:                 document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150     raeburn  8612:             } else {
1.171     raeburn  8613:                 document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
                   8614:                 document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150     raeburn  8615: 
                   8616:             }
                   8617:         } else {
1.171     raeburn  8618:             document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
                   8619:             document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150     raeburn  8620:         }
1.151     raeburn  8621:         if ((insttypes[k] != '_LC_external') && 
                   8622:             ((insttypes[k] != '_LC_internetdom') ||
                   8623:              ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171     raeburn  8624:             var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
                   8625:             item.options.length = 0;
                   8626:             item.options[0] = new Option("","",true,true);
                   8627:             var idx = 0;  
1.151     raeburn  8628:             for (var m=0; m<alltargets.length; m++) {
1.171     raeburn  8629:                 if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
                   8630:                     idx ++;
                   8631:                     item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
                   8632:                     
1.150     raeburn  8633:                 }
                   8634:             }
                   8635:         }
                   8636:     }
                   8637:     return;
                   8638: }
                   8639: 
1.171     raeburn  8640: function hideSpares(balnum) {
1.150     raeburn  8641:     var alltargets = new Array('$alltargets');
                   8642:     var insttypes = new Array('$allinsttypes');
                   8643:     var offloadtypes = new Array('primary','default');
                   8644: 
1.171     raeburn  8645:     document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
                   8646:     document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150     raeburn  8647: 
                   8648:     var total = alltargets.length - 1;
                   8649:     for (var i=0; i<offloadtypes; i++) {
                   8650:         for (var j=0; j<total; j++) {
1.171     raeburn  8651:            document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
                   8652:            document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
                   8653:            document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151     raeburn  8654:         }
1.150     raeburn  8655:     }
                   8656:     for (var k=0; k<insttypes.length; k++) {
1.171     raeburn  8657:         document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
                   8658:         document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151     raeburn  8659:         if (insttypes[k] != '_LC_external') {
1.171     raeburn  8660:             document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
                   8661:             document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150     raeburn  8662:         }
                   8663:     }
                   8664:     return;
                   8665: }
                   8666: 
1.171     raeburn  8667: function checkOffloads(item,balnum,type) {
1.150     raeburn  8668:     var alltargets = new Array('$alltargets');
                   8669:     var offloadtypes = new Array('primary','default');
                   8670:     if (item.checked) {
                   8671:         var total = alltargets.length - 1;
                   8672:         var other;
                   8673:         if (type == offloadtypes[0]) {
1.151     raeburn  8674:             other = offloadtypes[1];
1.150     raeburn  8675:         } else {
1.151     raeburn  8676:             other = offloadtypes[0];
1.150     raeburn  8677:         }
                   8678:         for (var i=0; i<total; i++) {
1.171     raeburn  8679:             var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150     raeburn  8680:             if (server == item.value) {
1.171     raeburn  8681:                 if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
                   8682:                     document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150     raeburn  8683:                 }
                   8684:             }
                   8685:         }
                   8686:     }
                   8687:     return;
                   8688: }
                   8689: 
1.171     raeburn  8690: function singleServerToggle(balnum,type) {
                   8691:     var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150     raeburn  8692:     if (offloadtoSelIdx == 0) {
1.171     raeburn  8693:         document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
                   8694:         document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150     raeburn  8695: 
                   8696:     } else {
1.171     raeburn  8697:         document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
                   8698:         document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150     raeburn  8699:     }
                   8700:     return;
                   8701: }
                   8702: 
1.171     raeburn  8703: function balanceruleChange(formname,balnum,type) {
1.150     raeburn  8704:     if (type == '_LC_external') {
1.171     raeburn  8705:         return;
1.150     raeburn  8706:     }
1.171     raeburn  8707:     var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150     raeburn  8708:     for (var i=0; i<typesRules.length; i++) {
                   8709:         if (formname.elements[typesRules[i]].checked) {
                   8710:             if (formname.elements[typesRules[i]].value != 'specific') {
1.171     raeburn  8711:                 document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
                   8712:                 document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150     raeburn  8713:             } else {
1.171     raeburn  8714:                 document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
                   8715:             }
                   8716:         }
                   8717:     }
                   8718:     return;
                   8719: }
                   8720: 
                   8721: function balancerDeleteChange(balnum) {
                   8722:     var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
                   8723:     var baltotal = document.getElementById('loadbalancing_total').value;
                   8724:     var addtarget;
                   8725:     var removetarget;
                   8726:     var action = 'delete';
                   8727:     if (document.getElementById('loadbalancing_delete_'+balnum)) {
                   8728:         var lonhost = hostitem.value;
                   8729:         var currIdx = currBalancers.indexOf(lonhost);
                   8730:         if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
                   8731:             if (currIdx != -1) {
                   8732:                 currBalancers.splice(currIdx,1);
                   8733:             }
                   8734:             addtarget = lonhost;
                   8735:         } else {
                   8736:             if (currIdx == -1) {
                   8737:                 currBalancers.push(lonhost);
                   8738:             }
                   8739:             removetarget = lonhost;
                   8740:             action = 'undelete';
                   8741:         }
                   8742:         balancerChange(balnum,baltotal,action,addtarget,removetarget);
                   8743:     }
                   8744:     return;
                   8745: }
                   8746: 
                   8747: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
                   8748:     if (baltotal > 1) {
                   8749:         var offloadtypes = new Array('primary','default');
                   8750:         var alltargets = new Array('$alltargets');
                   8751:         var insttypes = new Array('$allinsttypes');
                   8752:         for (var i=0; i<baltotal; i++) {
                   8753:             if (i != balnum) {
                   8754:                 for (var j=0; j<offloadtypes.length; j++) {
                   8755:                     var total = alltargets.length - 1;
                   8756:                     for (var k=0; k<total; k++) {
                   8757:                         var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
                   8758:                         var server = serveritem.value;
                   8759:                         if ((action == 'delete') || (action == 'change' && addtarget != ''))  {
                   8760:                             if (server == addtarget) {
                   8761:                                 serveritem.disabled = '';
                   8762:                             }
                   8763:                         }
                   8764:                         if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
                   8765:                             if (server == removetarget) {
                   8766:                                 serveritem.disabled = 'disabled';
                   8767:                                 serveritem.checked = false;
                   8768:                             }
                   8769:                         }
                   8770:                     }
                   8771:                 }
                   8772:                 for (var j=0; j<insttypes.length; j++) {
                   8773:                     if (insttypes[j] != '_LC_external') {
                   8774:                         if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
                   8775:                             var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
                   8776:                             var currSel = singleserver.selectedIndex;
                   8777:                             var currVal = singleserver.options[currSel].value;
                   8778:                             if ((action == 'delete') || (action == 'change' && addtarget != '')) {
                   8779:                                 var numoptions = singleserver.options.length;
                   8780:                                 var needsnew = 1;
                   8781:                                 for (var k=0; k<numoptions; k++) {
                   8782:                                     if (singleserver.options[k] == addtarget) {
                   8783:                                         needsnew = 0;
                   8784:                                         break;
                   8785:                                     }
                   8786:                                 }
                   8787:                                 if (needsnew == 1) {
                   8788:                                     singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
                   8789:                                 }
                   8790:                             }
                   8791:                             if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
                   8792:                                 singleserver.options.length = 0;
                   8793:                                 if ((currVal) && (currVal != removetarget)) {
                   8794:                                     singleserver.options[0] = new Option("","",false,false);
                   8795:                                 } else {
                   8796:                                     singleserver.options[0] = new Option("","",true,true);
                   8797:                                 }
                   8798:                                 var idx = 0;
                   8799:                                 for (var m=0; m<alltargets.length; m++) {
                   8800:                                     if (currBalancers.indexOf(alltargets[m]) == -1) {
                   8801:                                         idx ++;
                   8802:                                         if (currVal == alltargets[m]) {
                   8803:                                             singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
                   8804:                                         } else {
                   8805:                                             singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
                   8806:                                         }
                   8807:                                     }
                   8808:                                 }
                   8809:                             }
                   8810:                         }
                   8811:                     }
                   8812:                 }
1.150     raeburn  8813:             }
                   8814:         }
                   8815:     }
                   8816:     return;
                   8817: }
                   8818: 
1.152     raeburn  8819: // ]]>
                   8820: </script>
                   8821: 
                   8822: END
                   8823: }
                   8824: 
                   8825: sub new_spares_js {
                   8826:     my @sparestypes = ('primary','default');
                   8827:     my $types = join("','",@sparestypes);
                   8828:     my $select = &mt('Select');
                   8829:     return <<"END";
                   8830: 
                   8831: <script type="text/javascript">
                   8832: // <![CDATA[
                   8833: 
                   8834: function updateNewSpares(formname,lonhost) {
                   8835:     var types = new Array('$types');
                   8836:     var include = new Array();
                   8837:     var exclude = new Array();
                   8838:     for (var i=0; i<types.length; i++) {
                   8839:         var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
                   8840:         for (var j=0; j<spareboxes.length; j++) {
                   8841:             if (formname.elements[spareboxes[j]].checked) {
                   8842:                 exclude.push(formname.elements[spareboxes[j]].value);
                   8843:             } else {
                   8844:                 include.push(formname.elements[spareboxes[j]].value);
                   8845:             }
                   8846:         }
                   8847:     }
                   8848:     for (var i=0; i<types.length; i++) {
                   8849:         var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
                   8850:         var selIdx = newSpare.selectedIndex;
                   8851:         var currnew = newSpare.options[selIdx].value;
                   8852:         var okSpares = new Array();
                   8853:         for (var j=0; j<newSpare.options.length; j++) {
                   8854:             var possible = newSpare.options[j].value;
                   8855:             if (possible != '') {
                   8856:                 if (exclude.indexOf(possible) == -1) {
                   8857:                     okSpares.push(possible);
                   8858:                 } else {
                   8859:                     if (currnew == possible) {
                   8860:                         selIdx = 0;
                   8861:                     }
                   8862:                 }
                   8863:             }
                   8864:         }
                   8865:         for (var k=0; k<include.length; k++) {
                   8866:             if (okSpares.indexOf(include[k]) == -1) {
                   8867:                 okSpares.push(include[k]);
                   8868:             }
                   8869:         }
                   8870:         okSpares.sort();
                   8871:         newSpare.options.length = 0;
                   8872:         if (selIdx == 0) {
                   8873:             newSpare.options[0] = new Option("$select","",true,true);
                   8874:         } else {
                   8875:             newSpare.options[0] = new Option("$select","",false,false);
                   8876:         }
                   8877:         for (var m=0; m<okSpares.length; m++) {
                   8878:             var idx = m+1;
                   8879:             var selThis = 0;
                   8880:             if (selIdx != 0) {
                   8881:                 if (okSpares[m] == currnew) {
                   8882:                     selThis = 1;
                   8883:                 }
                   8884:             }
                   8885:             if (selThis == 1) {
                   8886:                 newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
                   8887:             } else {
                   8888:                 newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
                   8889:             }
                   8890:         }
                   8891:     }
                   8892:     return;
                   8893: }
                   8894: 
                   8895: function checkNewSpares(lonhost,type) {
                   8896:     var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
                   8897:     var chosen =  newSpare.options[newSpare.selectedIndex].value;
                   8898:     if (chosen != '') { 
                   8899:         var othertype;
                   8900:         var othernewSpare;
                   8901:         if (type == 'primary') {
                   8902:             othernewSpare = document.getElementById('newspare_default_'+lonhost);
                   8903:         }
                   8904:         if (type == 'default') {
                   8905:             othernewSpare = document.getElementById('newspare_primary_'+lonhost);
                   8906:         }
                   8907:         if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
                   8908:             othernewSpare.selectedIndex = 0;
                   8909:         }
                   8910:     }
                   8911:     return;
                   8912: }
                   8913: 
                   8914: // ]]>
                   8915: </script>
                   8916: 
                   8917: END
                   8918: 
                   8919: }
                   8920: 
                   8921: sub common_domprefs_js {
                   8922:     return <<"END";
                   8923: 
                   8924: <script type="text/javascript">
                   8925: // <![CDATA[
                   8926: 
1.150     raeburn  8927: function getIndicesByName(formname,item) {
1.152     raeburn  8928:     var group = new Array();
1.150     raeburn  8929:     for (var i=0;i<formname.elements.length;i++) {
                   8930:         if (formname.elements[i].name == item) {
1.152     raeburn  8931:             group.push(formname.elements[i].id);
1.150     raeburn  8932:         }
                   8933:     }
1.152     raeburn  8934:     return group;
1.150     raeburn  8935: }
                   8936: 
                   8937: // ]]>
                   8938: </script>
                   8939: 
                   8940: END
1.152     raeburn  8941: 
1.150     raeburn  8942: }
                   8943: 
1.165     raeburn  8944: sub recaptcha_js {
                   8945:     my %lt = &captcha_phrases();
                   8946:     return <<"END";
                   8947: 
                   8948: <script type="text/javascript">
                   8949: // <![CDATA[
                   8950: 
                   8951: function updateCaptcha(caller,context) {
                   8952:     var privitem;
                   8953:     var pubitem;
                   8954:     var privtext;
                   8955:     var pubtext;
                   8956:     if (document.getElementById(context+'_recaptchapub')) {
                   8957:         pubitem = document.getElementById(context+'_recaptchapub');
                   8958:     } else {
                   8959:         return;
                   8960:     }
                   8961:     if (document.getElementById(context+'_recaptchapriv')) {
                   8962:         privitem = document.getElementById(context+'_recaptchapriv');
                   8963:     } else {
                   8964:         return;
                   8965:     }
                   8966:     if (document.getElementById(context+'_recaptchapubtxt')) {
                   8967:         pubtext = document.getElementById(context+'_recaptchapubtxt');
                   8968:     } else {
                   8969:         return;
                   8970:     }
                   8971:     if (document.getElementById(context+'_recaptchaprivtxt')) {
                   8972:         privtext = document.getElementById(context+'_recaptchaprivtxt');
                   8973:     } else {
                   8974:         return;
                   8975:     }
                   8976:     if (caller.checked) {
                   8977:         if (caller.value == 'recaptcha') {
                   8978:             pubitem.type = 'text';
                   8979:             privitem.type = 'text';
                   8980:             pubitem.size = '40';
                   8981:             privitem.size = '40';
                   8982:             pubtext.innerHTML = "$lt{'pub'}";
                   8983:             privtext.innerHTML = "$lt{'priv'}";
                   8984:         } else {
                   8985:             pubitem.type = 'hidden';
                   8986:             privitem.type = 'hidden';
                   8987:             pubtext.innerHTML = '';
                   8988:             privtext.innerHTML = '';
                   8989:         }
                   8990:     }
                   8991:     return;
                   8992: }
                   8993: 
                   8994: // ]]>
                   8995: </script>
                   8996: 
                   8997: END
                   8998: 
                   8999: }
                   9000: 
                   9001: sub captcha_phrases {
                   9002:     return &Apache::lonlocal::texthash (
                   9003:                  priv => 'Private key',
                   9004:                  pub  => 'Public key',
                   9005:                  original  => 'original (CAPTCHA)',
                   9006:                  recaptcha => 'successor (ReCAPTCHA)',
                   9007:                  notused   => 'unused',
                   9008:     );
                   9009: }
                   9010: 
1.3       raeburn  9011: 1;

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