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

1.1       raeburn     1: # The LearningOnline Network with CAPA
                      2: # Handler to set domain-wide configuration settings
                      3: #
1.207   ! bisitz      4: # $Id: domainprefs.pm,v 1.206 2013/09/10 01:51:32 raeburn Exp $
1.2       albertel    5: #
1.1       raeburn     6: # Copyright Michigan State University Board of Trustees
                      7: #
                      8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                      9: #
                     10: # LON-CAPA is free software; you can redistribute it and/or modify
                     11: # it under the terms of the GNU General Public License as published by
                     12: # the Free Software Foundation; either version 2 of the License, or
                     13: # (at your option) any later version.
                     14: #
                     15: # LON-CAPA is distributed in the hope that it will be useful,
                     16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     18: # GNU General Public License for more details.
                     19: #
                     20: # You should have received a copy of the GNU General Public License
                     21: # along with LON-CAPA; if not, write to the Free Software
                     22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA#
                     23: # /home/httpd/html/adm/gpl.txt
                     24: #
                     25: # http://www.lon-capa.org/
                     26: #
                     27: #
                     28: ###############################################################
                     29: ##############################################################
                     30: 
1.101     raeburn    31: =pod
                     32: 
                     33: =head1 NAME
                     34: 
                     35: Apache::domainprefs.pm
                     36: 
                     37: =head1 SYNOPSIS
                     38: 
                     39: Handles configuration of a LON-CAPA domain.  
                     40: 
                     41: This is part of the LearningOnline Network with CAPA project
                     42: described at http://www.lon-capa.org.
                     43: 
                     44: 
                     45: =head1 OVERVIEW
                     46: 
                     47: Each institution using LON-CAPA will typically have a single domain designated 
1.183     bisitz     48: for use by individuals affiliated with the institution.  Accordingly, each domain
1.101     raeburn    49: may define a default set of logos and a color scheme which can be used to "brand"
                     50: the LON-CAPA instance. In addition, an institution will typically have a language
                     51: and timezone which are used for the majority of courses.
                     52: 
                     53: LON-CAPA provides a mechanism to display and modify these defaults, as well as a 
                     54: host of other domain-wide settings which determine the types of functionality
                     55: available to users and courses in the domain.
                     56: 
                     57: There is also a mechanism to configure cataloging of courses in the domain, and
                     58: controls on the operation of automated processes which govern such things as
                     59: roster updates, user directory updates and processing of course requests.
                     60: 
                     61: The domain coordination manual which is built dynamically on install/update of 
                     62: LON-CAPA from the relevant help items provides more information about domain 
                     63: configuration.
                     64: 
                     65: Most of the domain settings are stored in the configuration.db GDBM file which is
                     66: housed on the primary library server for the domain in /home/httpd/lonUsers/$dom,
                     67: where $dom is the domain.  The configuration.db stores settings in a number of 
                     68: frozen hashes of hashes.  In a few cases, domain information must be uploaded to
                     69: the domain as files (e.g., image files for logos etc., or plain text files for
                     70: bubblesheet formats).  In this case the domainprefs.pm must be running in a user
                     71: session hosted on the primary library server in the domain, as these files are 
                     72: stored in author space belonging to a special $dom-domainconfig user.   
                     73: 
                     74: domainprefs.pm in combination with lonconfigsettings.pm will retrieve and display
                     75: the current settings, and provides an interface to make modifications.
                     76: 
                     77: =head1 SUBROUTINES
                     78: 
                     79: =over
                     80: 
                     81: =item print_quotas()
                     82: 
                     83: Inputs: 4 
                     84: 
                     85: $dom,$settings,$rowtotal,$action.
                     86: 
                     87: $dom is the domain, $settings is a reference to a hash of current settings for
                     88: the current context, $rowtotal is a reference to the scalar used to record the 
1.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,
1.197     raeburn    97: used by course owners to request creation of a course, and to display/store
                     98: default quota sizes for authoring spaces.
1.101     raeburn    99: 
                    100: Outputs: 1
                    101: 
                    102: $datatable  - HTML containing form elements which allow settings to be changed. 
                    103: 
                    104: In the case of course requests, radio buttons are displayed for each institutional
                    105: affiliate type (and also default, and _LC_adv) for each of the course types 
                    106: (official, unofficial and community).  In each case the radio buttons allow the 
                    107: selection of one of four values:
                    108: 
1.104     raeburn   109: 0, approval, validate, autolimit=N (where N is blank, or a positive integer).
1.101     raeburn   110: which have the following effects:
                    111: 
                    112: 0
                    113: 
                    114: =over
                    115: 
                    116: - course requests are not allowed for this course types/affiliation
                    117: 
                    118: =back
                    119: 
1.104     raeburn   120: approval 
1.101     raeburn   121: 
                    122: =over 
                    123: 
                    124: - course requests must be approved by a Doman Coordinator in the 
                    125: course's domain
                    126: 
                    127: =back
                    128: 
                    129: validate 
                    130: 
                    131: =over
                    132: 
                    133: - an institutional validation (e.g., check requestor is instructor
                    134: of record) needs to be passed before the course will be created.  The required
                    135: validation is in localenroll.pm on the primary library server for the course 
                    136: domain.
                    137: 
                    138: =back
                    139: 
                    140: autolimit 
                    141: 
                    142: =over
                    143:  
1.143     raeburn   144: - course requests will be processed automatically up to a limit of
1.101     raeburn   145: N requests for the course type for the particular requestor.
                    146: If N is undefined, there is no limit to the number of course requests
                    147: which a course owner may submit and have processed automatically. 
                    148: 
                    149: =back
                    150: 
                    151: =item modify_quotas() 
                    152: 
                    153: =back
                    154: 
                    155: =cut
                    156: 
1.1       raeburn   157: package Apache::domainprefs;
                    158: 
                    159: use strict;
                    160: use Apache::Constants qw(:common :http);
                    161: use Apache::lonnet;
                    162: use Apache::loncommon();
                    163: use Apache::lonhtmlcommon();
                    164: use Apache::lonlocal;
1.43      raeburn   165: use Apache::lonmsg();
1.91      raeburn   166: use Apache::lonconfigsettings;
1.69      raeburn   167: use LONCAPA qw(:DEFAULT :match);
1.6       raeburn   168: use LONCAPA::Enrollment;
1.81      raeburn   169: use LONCAPA::lonauthcgi();
1.9       raeburn   170: use File::Copy;
1.43      raeburn   171: use Locale::Language;
1.62      raeburn   172: use DateTime::TimeZone;
1.68      raeburn   173: use DateTime::Locale;
1.1       raeburn   174: 
1.155     raeburn   175: my $registered_cleanup;
                    176: my $modified_urls;
                    177: 
1.1       raeburn   178: sub handler {
                    179:     my $r=shift;
                    180:     if ($r->header_only) {
                    181:         &Apache::loncommon::content_type($r,'text/html');
                    182:         $r->send_http_header;
                    183:         return OK;
                    184:     }
                    185: 
1.91      raeburn   186:     my $context = 'domain';
1.1       raeburn   187:     my $dom = $env{'request.role.domain'};
1.5       albertel  188:     my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1       raeburn   189:     if (&Apache::lonnet::allowed('mau',$dom)) {
                    190:         &Apache::loncommon::content_type($r,'text/html');
                    191:         $r->send_http_header;
                    192:     } else {
                    193:         $env{'user.error.msg'}=
                    194:         "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
                    195:         return HTTP_NOT_ACCEPTABLE;
                    196:     }
1.155     raeburn   197: 
                    198:     $registered_cleanup=0;
                    199:     @{$modified_urls}=();
                    200: 
1.1       raeburn   201:     &Apache::lonhtmlcommon::clear_breadcrumbs();
                    202:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.58      raeburn   203:                                             ['phase','actions']);
1.30      raeburn   204:     my $phase = 'pickactions';
1.3       raeburn   205:     if ( exists($env{'form.phase'}) ) {
                    206:         $phase = $env{'form.phase'};
                    207:     }
1.150     raeburn   208:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.3       raeburn   209:     my %domconfig =
1.6       raeburn   210:       &Apache::lonnet::get_dom('configuration',['login','rolecolors',
1.125     raeburn   211:                 'quotas','autoenroll','autoupdate','autocreate',
                    212:                 'directorysrch','usercreation','usermodification',
                    213:                 'contacts','defaults','scantron','coursecategories',
                    214:                 'serverstatuses','requestcourses','helpsettings',
1.163     raeburn   215:                 'coursedefaults','usersessions','loadbalancing',
                    216:                 'requestauthor'],$dom);
1.43      raeburn   217:     my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll',
1.125     raeburn   218:                        'autoupdate','autocreate','directorysrch','contacts',
1.48      raeburn   219:                        'usercreation','usermodification','scantron',
1.163     raeburn   220:                        'requestcourses','requestauthor','coursecategories',
                    221:                        'serverstatuses','helpsettings',
1.137     raeburn   222:                        'coursedefaults','usersessions');
1.171     raeburn   223:     my %existing;
                    224:     if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
                    225:         %existing = %{$domconfig{'loadbalancing'}};
                    226:     }
                    227:     if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.150     raeburn   228:         push(@prefs_order,'loadbalancing');
                    229:     }
1.30      raeburn   230:     my %prefs = (
                    231:         'rolecolors' =>
                    232:                    { text => 'Default color schemes',
1.67      raeburn   233:                      help => 'Domain_Configuration_Color_Schemes',
1.30      raeburn   234:                      header => [{col1 => 'Student Settings',
                    235:                                  col2 => '',},
                    236:                                 {col1 => 'Coordinator Settings',
                    237:                                  col2 => '',},
                    238:                                 {col1 => 'Author Settings',
                    239:                                  col2 => '',},
                    240:                                 {col1 => 'Administrator Settings',
                    241:                                  col2 => '',}],
                    242:                     },
1.110     raeburn   243:         'login' =>
1.30      raeburn   244:                     { text => 'Log-in page options',
1.67      raeburn   245:                       help => 'Domain_Configuration_Login_Page',
1.168     raeburn   246:                       header => [{col1 => 'Log-in Page Items',
                    247:                                   col2 => '',},
                    248:                                  {col1 => 'Log-in Help',
                    249:                                   col2 => 'Value'}],
1.30      raeburn   250:                     },
1.43      raeburn   251:         'defaults' => 
1.141     raeburn   252:                     { text => 'Default authentication/language/timezone/portal',
1.67      raeburn   253:                       help => 'Domain_Configuration_LangTZAuth',
1.43      raeburn   254:                       header => [{col1 => 'Setting',
                    255:                                   col2 => 'Value'}],
                    256:                     },
1.30      raeburn   257:         'quotas' => 
1.197     raeburn   258:                     { text => 'Blogs, personal web pages, webDAV/quotas, portfolios',
1.67      raeburn   259:                       help => 'Domain_Configuration_Quotas',
1.77      raeburn   260:                       header => [{col1 => 'User affiliation',
1.72      raeburn   261:                                   col2 => 'Available tools',
1.197     raeburn   262:                                   col3 => 'Quotas, Mb; (Authoring requires role)',}],
1.30      raeburn   263:                     },
                    264:         'autoenroll' =>
                    265:                    { text => 'Auto-enrollment settings',
1.67      raeburn   266:                      help => 'Domain_Configuration_Auto_Enrollment',
1.30      raeburn   267:                      header => [{col1 => 'Configuration setting',
                    268:                                  col2 => 'Value(s)'}],
                    269:                    },
                    270:         'autoupdate' => 
                    271:                    { text => 'Auto-update settings',
1.67      raeburn   272:                      help => 'Domain_Configuration_Auto_Updates',
1.30      raeburn   273:                      header => [{col1 => 'Setting',
                    274:                                  col2 => 'Value',},
1.131     raeburn   275:                                 {col1 => 'Setting',
                    276:                                  col2 => 'Affiliation'},
1.43      raeburn   277:                                 {col1 => 'User population',
1.131     raeburn   278:                                  col2 => 'Updateable user data'}],
1.30      raeburn   279:                   },
1.125     raeburn   280:         'autocreate' => 
                    281:                   { text => 'Auto-course creation settings',
                    282:                      help => 'Domain_Configuration_Auto_Creation',
                    283:                      header => [{col1 => 'Configuration Setting',
                    284:                                  col2 => 'Value',}],
                    285:                   },
1.30      raeburn   286:         'directorysrch' => 
                    287:                   { text => 'Institutional directory searches',
1.67      raeburn   288:                     help => 'Domain_Configuration_InstDirectory_Search',
1.30      raeburn   289:                     header => [{col1 => 'Setting',
                    290:                                 col2 => 'Value',}],
                    291:                   },
                    292:         'contacts' =>
                    293:                   { text => 'Contact Information',
1.67      raeburn   294:                     help => 'Domain_Configuration_Contact_Info',
1.30      raeburn   295:                     header => [{col1 => 'Setting',
                    296:                                 col2 => 'Value',}],
                    297:                   },
                    298: 
                    299:         'usercreation' => 
                    300:                   { text => 'User creation',
1.67      raeburn   301:                     help => 'Domain_Configuration_User_Creation',
1.43      raeburn   302:                     header => [{col1 => 'Format rule type',
                    303:                                 col2 => 'Format rules in force'},
1.34      raeburn   304:                                {col1 => 'User account creation',
                    305:                                 col2 => 'Usernames which may be created',},
1.30      raeburn   306:                                {col1 => 'Context',
1.43      raeburn   307:                                 col2 => 'Assignable authentication types'}],
1.30      raeburn   308:                   },
1.69      raeburn   309:         'usermodification' =>
1.33      raeburn   310:                   { text => 'User modification',
1.67      raeburn   311:                     help => 'Domain_Configuration_User_Modification',
1.33      raeburn   312:                     header => [{col1 => 'Target user has role',
                    313:                                 col2 => 'User information updateable in author context'},
                    314:                                {col1 => 'Target user has role',
1.63      raeburn   315:                                 col2 => 'User information updateable in course context'},
                    316:                                {col1 => "Status of user",
                    317:                                 col2 => 'Information settable when self-creating account (if directory data blank)'}],
1.33      raeburn   318:                   },
1.69      raeburn   319:         'scantron' =>
1.95      www       320:                   { text => 'Bubblesheet format file',
1.67      raeburn   321:                     help => 'Domain_Configuration_Scantron_Format',
1.46      raeburn   322:                     header => [ {col1 => 'Item',
                    323:                                  col2 => '',
                    324:                               }],
                    325:                   },
1.86      raeburn   326:         'requestcourses' => 
                    327:                  {text => 'Request creation of courses',
                    328:                   help => 'Domain_Configuration_Request_Courses',
                    329:                   header => [{col1 => 'User affiliation',
1.102     raeburn   330:                               col2 => 'Availability/Processing of requests',},
                    331:                              {col1 => 'Setting',
                    332:                               col2 => 'Value'}],
1.86      raeburn   333:                  },
1.163     raeburn   334:         'requestauthor' =>
                    335:                  {text => 'Request authoring space',
                    336:                   help => 'Domain_Configuration_Request_Author',
                    337:                   header => [{col1 => 'User affiliation',
                    338:                               col2 => 'Availability/Processing of requests',},
                    339:                              {col1 => 'Setting',
                    340:                               col2 => 'Value'}],
                    341:                  },
1.69      raeburn   342:         'coursecategories' =>
1.120     raeburn   343:                   { text => 'Cataloging of courses/communities',
1.67      raeburn   344:                     help => 'Domain_Configuration_Cataloging_Courses',
1.69      raeburn   345:                     header => [{col1 => 'Category settings',
1.57      raeburn   346:                                 col2 => '',},
                    347:                                {col1 => 'Categories',
                    348:                                 col2 => '',
                    349:                                }],
1.69      raeburn   350:                   },
                    351:         'serverstatuses' =>
1.77      raeburn   352:                  {text   => 'Access to server status pages',
1.69      raeburn   353:                   help   => 'Domain_Configuration_Server_Status',
                    354:                   header => [{col1 => 'Status Page',
                    355:                               col2 => 'Other named users',
                    356:                               col3 => 'Specific IPs',
                    357:                             }],
                    358:                  },
1.118     jms       359:         'helpsettings' =>
                    360:                  {text   => 'Help page settings',
                    361:                   help   => 'Domain_Configuration_Help_Settings',
1.166     raeburn   362:                   header => [{col1 => 'Help Settings (logged-in users)',
                    363:                               col2 => 'Value'}],
1.118     jms       364:                  },
1.121     raeburn   365:         'coursedefaults' => 
                    366:                  {text => 'Course/Community defaults',
                    367:                   help => 'Domain_Configuration_Course_Defaults',
1.139     raeburn   368:                   header => [{col1 => 'Defaults which can be overridden in each course by a CC',
                    369:                               col2 => 'Value',},
                    370:                              {col1 => 'Defaults which can be overridden for each course by a DC',
                    371:                               col2 => 'Value',},],
1.121     raeburn   372:                  },
1.120     raeburn   373:         'privacy' => 
                    374:                  {text   => 'User Privacy',
                    375:                   help   => 'Domain_Configuration_User_Privacy',
                    376:                   header => [{col1 => 'Setting',
                    377:                               col2 => 'Value',}],
                    378:                  },
1.141     raeburn   379:         'usersessions' =>
1.145     raeburn   380:                  {text  => 'User session hosting/offloading',
1.137     raeburn   381:                   help  => 'Domain_Configuration_User_Sessions',
1.145     raeburn   382:                   header => [{col1 => 'Domain server',
                    383:                               col2 => 'Servers to offload sessions to when busy'},
                    384:                              {col1 => 'Hosting of users from other domains',
1.137     raeburn   385:                               col2 => 'Rules'},
                    386:                              {col1 => "Hosting domain's own users elsewhere",
                    387:                               col2 => 'Rules'}],
                    388:                  },
1.150     raeburn   389:          'loadbalancing' =>
1.185     raeburn   390:                  {text  => 'Dedicated Load Balancer(s)',
1.150     raeburn   391:                   help  => 'Domain_Configuration_Load_Balancing',
1.171     raeburn   392:                   header => [{col1 => 'Balancers',
1.150     raeburn   393:                               col2 => 'Default destinations',
1.183     bisitz    394:                               col3 => 'User affiliation',
1.150     raeburn   395:                               col4 => 'Overrides'},
                    396:                             ],
                    397:                  },
1.3       raeburn   398:     );
1.110     raeburn   399:     if (keys(%servers) > 1) {
                    400:         $prefs{'login'}  = { text   => 'Log-in page options',
                    401:                              help   => 'Domain_Configuration_Login_Page',
                    402:                             header => [{col1 => 'Log-in Service',
                    403:                                         col2 => 'Server Setting',},
                    404:                                        {col1 => 'Log-in Page Items',
1.168     raeburn   405:                                         col2 => ''},
                    406:                                        {col1 => 'Log-in Help',
                    407:                                         col2 => 'Value'}],
1.110     raeburn   408:                            };
                    409:     }
1.174     foxr      410: 
1.6       raeburn   411:     my @roles = ('student','coordinator','author','admin');
1.30      raeburn   412:     my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3       raeburn   413:     &Apache::lonhtmlcommon::add_breadcrumb
1.30      raeburn   414:     ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133     raeburn   415:       text=>"Settings to display/modify"});
1.9       raeburn   416:     my $confname = $dom.'-domainconfig';
1.174     foxr      417: 
1.3       raeburn   418:     if ($phase eq 'process') {
1.205     raeburn   419:         if (&Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
                    420:                                                      \%prefs,\%domconfig,$confname,\@roles) eq 'update') {
                    421:             $r->rflush();
                    422:             &devalidate_remote_domconfs($dom);
                    423:         }
1.30      raeburn   424:     } elsif ($phase eq 'display') {
1.192     raeburn   425:         my $js = &recaptcha_js().
                    426:                  &credits_js();
1.171     raeburn   427:         if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152     raeburn   428:             my ($othertitle,$usertypes,$types) =
                    429:                 &Apache::loncommon::sorted_inst_types($dom);
1.171     raeburn   430:             $js .= &lonbalance_targets_js($dom,$types,\%servers,
                    431:                                           $domconfig{'loadbalancing'}).
1.170     raeburn   432:                    &new_spares_js().
                    433:                    &common_domprefs_js().
                    434:                    &Apache::loncommon::javascript_array_indexof();
1.152     raeburn   435:         }
1.150     raeburn   436:         &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1       raeburn   437:     } else {
1.180     raeburn   438: # check if domconfig user exists for the domain.
                    439:         my $servadm = $r->dir_config('lonAdmEMail');
                    440:         my ($configuserok,$author_ok,$switchserver) =
                    441:             &config_check($dom,$confname,$servadm);
                    442:         unless ($configuserok eq 'ok') {
1.181     raeburn   443:             &Apache::lonconfigsettings::print_header($r,$phase,$context);
                    444:             $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
                    445:                            $confname).
                    446:                       '<br />'
                    447:             );
1.180     raeburn   448:             if ($switchserver) {
1.181     raeburn   449:                 $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
                    450:                           '<br />'.
                    451:                           &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
                    452:                           '<br />'.
                    453:                           &mt('The "[_1]" user can be created automatically when a Domain Coordinator visits the web-based "Set domain configuration" screen, in a session hosted on the primary library server.',$confname).
                    454:                           '<br />'.
                    455:                           &mt('To do that now, use the following link: [_1]',$switchserver)
                    456:                 );
                    457:             } else {
                    458:                 $r->print(&mt('To create that user from the command line run the ./UPDATE script found in the top level directory of the extracted LON-CAPA tarball.').
                    459:                           '<br />'.
                    460:                           &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
                    461:                 );
1.180     raeburn   462:             }
                    463:             $r->print(&Apache::loncommon::end_page());
                    464:             return OK;
                    465:         }
1.21      raeburn   466:         if (keys(%domconfig) == 0) {
                    467:             my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29      raeburn   468:             my @ids=&Apache::lonnet::current_machine_ids();
                    469:             if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21      raeburn   470:                 my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41      raeburn   471:                 my @loginimages = ('img','logo','domlogo','login');
1.21      raeburn   472:                 my $custom_img_count = 0;
                    473:                 foreach my $img (@loginimages) {
                    474:                     if ($designhash{$dom.'.login.'.$img} ne '') {
                    475:                         $custom_img_count ++;
                    476:                     }
                    477:                 }
                    478:                 foreach my $role (@roles) {
                    479:                     if ($designhash{$dom.'.'.$role.'.img'} ne '') {
                    480:                         $custom_img_count ++;
                    481:                     }
                    482:                 }
                    483:                 if ($custom_img_count > 0) {
1.94      raeburn   484:                     &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21      raeburn   485:                     my $switch_server = &check_switchserver($dom,$confname);
1.29      raeburn   486:                     $r->print(
                    487:     &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
                    488:     &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
                    489:     &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 />'.
                    490:     &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
                    491:                     if ($switch_server) {
1.30      raeburn   492:                         $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29      raeburn   493:                     }
1.91      raeburn   494:                     $r->print(&Apache::loncommon::end_page());
1.21      raeburn   495:                     return OK;
                    496:                 }
                    497:             }
                    498:         }
1.91      raeburn   499:         &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3       raeburn   500:     }
                    501:     return OK;
                    502: }
                    503: 
                    504: sub process_changes {
1.205     raeburn   505:     my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92      raeburn   506:     my %domconfig;
                    507:     if (ref($values) eq 'HASH') {
                    508:         %domconfig = %{$values};
                    509:     }
1.3       raeburn   510:     my $output;
                    511:     if ($action eq 'login') {
1.205     raeburn   512:         $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6       raeburn   513:     } elsif ($action eq 'rolecolors') {
1.9       raeburn   514:         $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.205     raeburn   515:                                      $lastactref,%domconfig);
1.3       raeburn   516:     } elsif ($action eq 'quotas') {
1.86      raeburn   517:         $output = &modify_quotas($dom,$action,%domconfig);
1.3       raeburn   518:     } elsif ($action eq 'autoenroll') {
1.205     raeburn   519:         $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3       raeburn   520:     } elsif ($action eq 'autoupdate') {
                    521:         $output = &modify_autoupdate($dom,%domconfig);
1.125     raeburn   522:     } elsif ($action eq 'autocreate') {
                    523:         $output = &modify_autocreate($dom,%domconfig);
1.23      raeburn   524:     } elsif ($action eq 'directorysrch') {
                    525:         $output = &modify_directorysrch($dom,%domconfig);
1.27      raeburn   526:     } elsif ($action eq 'usercreation') {
1.28      raeburn   527:         $output = &modify_usercreation($dom,%domconfig);
1.33      raeburn   528:     } elsif ($action eq 'usermodification') {
                    529:         $output = &modify_usermodification($dom,%domconfig);
1.28      raeburn   530:     } elsif ($action eq 'contacts') {
1.205     raeburn   531:         $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43      raeburn   532:     } elsif ($action eq 'defaults') {
1.203     raeburn   533:         $output = &modify_defaults($dom,$r,%domconfig);
1.46      raeburn   534:     } elsif ($action eq 'scantron') {
1.205     raeburn   535:         $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48      raeburn   536:     } elsif ($action eq 'coursecategories') {
                    537:         $output = &modify_coursecategories($dom,%domconfig);
1.69      raeburn   538:     } elsif ($action eq 'serverstatuses') {
                    539:         $output = &modify_serverstatuses($dom,%domconfig);
1.86      raeburn   540:     } elsif ($action eq 'requestcourses') {
                    541:         $output = &modify_quotas($dom,$action,%domconfig);
1.163     raeburn   542:     } elsif ($action eq 'requestauthor') {
                    543:         $output = &modify_quotas($dom,$action,%domconfig);
1.118     jms       544:     } elsif ($action eq 'helpsettings') {
1.122     jms       545:         $output = &modify_helpsettings($r,$dom,$confname,%domconfig);
1.121     raeburn   546:     } elsif ($action eq 'coursedefaults') {
                    547:         $output = &modify_coursedefaults($dom,%domconfig);
1.137     raeburn   548:     } elsif ($action eq 'usersessions') {
                    549:         $output = &modify_usersessions($dom,%domconfig);
1.150     raeburn   550:     } elsif ($action eq 'loadbalancing') {
                    551:         $output = &modify_loadbalancing($dom,%domconfig);
1.3       raeburn   552:     }
                    553:     return $output;
                    554: }
                    555: 
                    556: sub print_config_box {
1.9       raeburn   557:     my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30      raeburn   558:     my $rowtotal = 0;
1.49      raeburn   559:     my $output;
                    560:     if ($action eq 'coursecategories') {
                    561:         $output = &coursecategories_javascript($settings);
1.91      raeburn   562:     }
1.49      raeburn   563:     $output .= 
1.30      raeburn   564:          '<table class="LC_nested_outer">
1.3       raeburn   565:           <tr>
1.66      raeburn   566:            <th align="left" valign="middle"><span class="LC_nobreak">'.
                    567:            &mt($item->{text}).'&nbsp;'.
                    568:            &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
                    569:           '</tr>';
1.30      raeburn   570:     $rowtotal ++;
1.110     raeburn   571:     my $numheaders = 1;
                    572:     if (ref($item->{'header'}) eq 'ARRAY') {
                    573:         $numheaders = scalar(@{$item->{'header'}});
                    574:     }
                    575:     if ($numheaders > 1) {
1.64      raeburn   576:         my $colspan = '';
1.145     raeburn   577:         my $rightcolspan = '';
1.168     raeburn   578:         if (($action eq 'rolecolors') || ($action eq 'coursecategories') || 
                    579:             (($action eq 'login') && ($numheaders < 3))) {
1.64      raeburn   580:             $colspan = ' colspan="2"';
                    581:         }
1.145     raeburn   582:         if ($action eq 'usersessions') {
                    583:             $rightcolspan = ' colspan="3"'; 
                    584:         }
1.30      raeburn   585:         $output .= '
1.3       raeburn   586:           <tr>
                    587:            <td>
                    588:             <table class="LC_nested">
                    589:              <tr class="LC_info_row">
1.59      bisitz    590:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145     raeburn   591:               <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30      raeburn   592:              </tr>';
1.69      raeburn   593:         $rowtotal ++;
1.6       raeburn   594:         if ($action eq 'autoupdate') {
1.30      raeburn   595:             $output .= &print_autoupdate('top',$dom,$settings,\$rowtotal);
1.28      raeburn   596:         } elsif ($action eq 'usercreation') {
1.33      raeburn   597:             $output .= &print_usercreation('top',$dom,$settings,\$rowtotal);
                    598:         } elsif ($action eq 'usermodification') {
                    599:             $output .= &print_usermodification('top',$dom,$settings,\$rowtotal);
1.57      raeburn   600:         } elsif ($action eq 'coursecategories') {
                    601:             $output .= &print_coursecategories('top',$dom,$item,$settings,\$rowtotal);
1.110     raeburn   602:         } elsif ($action eq 'login') {
1.168     raeburn   603:             if ($numheaders == 3) {
                    604:                 $colspan = ' colspan="2"';
                    605:                 $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
                    606:             } else {
                    607:                 $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
                    608:             }
1.102     raeburn   609:         } elsif ($action eq 'requestcourses') {
                    610:             $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.163     raeburn   611:         } elsif ($action eq 'requestauthor') {
                    612:             $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.137     raeburn   613:         } elsif ($action eq 'usersessions') {
                    614:             $output .= &print_usersessions('top',$dom,$settings,\$rowtotal); 
1.122     jms       615:         } elsif ($action eq 'rolecolors') {
1.30      raeburn   616:             $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.139     raeburn   617:         } elsif ($action eq 'coursedefaults') {
                    618:             $output .= &print_coursedefaults('top',$dom,$settings,\$rowtotal);
1.6       raeburn   619:         }
1.30      raeburn   620:         $output .= '
1.6       raeburn   621:            </table>
                    622:           </td>
                    623:          </tr>
                    624:          <tr>
                    625:            <td>
                    626:             <table class="LC_nested">
                    627:              <tr class="LC_info_row">
1.59      bisitz    628:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>';
1.57      raeburn   629:         $output .= '
1.59      bisitz    630:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30      raeburn   631:              </tr>';
                    632:             $rowtotal ++;
1.6       raeburn   633:         if ($action eq 'autoupdate') {
1.131     raeburn   634:             $output .= &print_autoupdate('middle',$dom,$settings,\$rowtotal).'
                    635:            </table>
                    636:           </td>
                    637:          </tr>
                    638:          <tr>
                    639:            <td>
                    640:             <table class="LC_nested">
                    641:              <tr class="LC_info_row">
                    642:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
                    643:               <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>      </tr>'.
                    644:             &print_autoupdate('bottom',$dom,$settings,\$rowtotal);
                    645:             $rowtotal ++;
1.28      raeburn   646:         } elsif ($action eq 'usercreation') {
1.34      raeburn   647:             $output .= &print_usercreation('middle',$dom,$settings,\$rowtotal).'
                    648:            </table>
                    649:           </td>
                    650:          </tr>
                    651:          <tr>
                    652:            <td>
                    653:             <table class="LC_nested">
                    654:              <tr class="LC_info_row">
1.59      bisitz    655:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
                    656:               <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>             </tr>'.
1.34      raeburn   657:             &print_usercreation('bottom',$dom,$settings,\$rowtotal);
                    658:             $rowtotal ++;
1.33      raeburn   659:         } elsif ($action eq 'usermodification') {
1.63      raeburn   660:             $output .= &print_usermodification('middle',$dom,$settings,\$rowtotal).'
                    661:            </table>
                    662:           </td>
                    663:          </tr>
                    664:          <tr>
                    665:            <td>
                    666:             <table class="LC_nested">
                    667:              <tr class="LC_info_row">
                    668:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
                    669:               <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>      </tr>'.
                    670:                        &print_usermodification('bottom',$dom,$settings,\$rowtotal);
                    671:             $rowtotal ++;
1.57      raeburn   672:         } elsif ($action eq 'coursecategories') {
                    673:             $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.110     raeburn   674:         } elsif ($action eq 'login') {
1.168     raeburn   675:             if ($numheaders == 3) {
                    676:                 $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
                    677:            </table>
                    678:           </td>
                    679:          </tr>
                    680:          <tr>
                    681:            <td>
                    682:             <table class="LC_nested">
                    683:              <tr class="LC_info_row">
                    684:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
                    685:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>      </tr>'.
                    686:                        &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
                    687:                 $rowtotal ++;
                    688:             } else {
                    689:                 $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
                    690:             }
1.102     raeburn   691:         } elsif ($action eq 'requestcourses') {
1.163     raeburn   692:             $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
                    693:         } elsif ($action eq 'requestauthor') {
                    694:             $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.137     raeburn   695:         } elsif ($action eq 'usersessions') {
1.145     raeburn   696:             $output .= &print_usersessions('middle',$dom,$settings,\$rowtotal).'
                    697:            </table>
                    698:           </td>
                    699:          </tr>
                    700:          <tr>
                    701:            <td>
                    702:             <table class="LC_nested">
                    703:              <tr class="LC_info_row">
                    704:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
                    705:               <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>      </tr>'.
                    706:                        &print_usersessions('bottom',$dom,$settings,\$rowtotal);
                    707:             $rowtotal ++;
1.139     raeburn   708:         } elsif ($action eq 'coursedefaults') {
                    709:             $output .= &print_coursedefaults('bottom',$dom,$settings,\$rowtotal);
1.122     jms       710:         } elsif ($action eq 'rolecolors') {
1.30      raeburn   711:             $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6       raeburn   712:            </table>
                    713:           </td>
                    714:          </tr>
                    715:          <tr>
                    716:            <td>
                    717:             <table class="LC_nested">
                    718:              <tr class="LC_info_row">
1.69      raeburn   719:               <td class="LC_left_item"'.$colspan.' valign="top">'.
                    720:                &mt($item->{'header'}->[2]->{'col1'}).'</td>
                    721:               <td class="LC_right_item" valign="top">'.
                    722:                &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3       raeburn   723:              </tr>'.
1.30      raeburn   724:             &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3       raeburn   725:            </table>
                    726:           </td>
                    727:          </tr>
                    728:          <tr>
                    729:            <td>
                    730:             <table class="LC_nested">
                    731:              <tr class="LC_info_row">
1.59      bisitz    732:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
                    733:               <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3       raeburn   734:              </tr>'.
1.30      raeburn   735:             &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
                    736:             $rowtotal += 2;
1.6       raeburn   737:         }
1.3       raeburn   738:     } else {
1.30      raeburn   739:         $output .= '
1.3       raeburn   740:           <tr>
                    741:            <td>
                    742:             <table class="LC_nested">
1.30      raeburn   743:              <tr class="LC_info_row">';
1.24      raeburn   744:         if (($action eq 'login') || ($action eq 'directorysrch')) {
1.30      raeburn   745:             $output .= '  
1.59      bisitz    746:               <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69      raeburn   747:         } elsif ($action eq 'serverstatuses') {
                    748:             $output .= '
                    749:               <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
                    750:               '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
                    751: 
1.6       raeburn   752:         } else {
1.30      raeburn   753:             $output .= '
1.69      raeburn   754:               <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
                    755:         }
1.72      raeburn   756:         if (defined($item->{'header'}->[0]->{'col3'})) {
                    757:             $output .= '<td class="LC_left_item" valign="top">'.
                    758:                        &mt($item->{'header'}->[0]->{'col2'});
                    759:             if ($action eq 'serverstatuses') {
                    760:                 $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
                    761:             } 
1.69      raeburn   762:         } else {
                    763:             $output .= '<td class="LC_right_item" valign="top">'.
                    764:                        &mt($item->{'header'}->[0]->{'col2'});
                    765:         }
                    766:         $output .= '</td>';
                    767:         if ($item->{'header'}->[0]->{'col3'}) {
1.150     raeburn   768:             if (defined($item->{'header'}->[0]->{'col4'})) {
                    769:                 $output .= '<td class="LC_left_item" valign="top">'.
                    770:                             &mt($item->{'header'}->[0]->{'col3'});
                    771:             } else {
                    772:                 $output .= '<td class="LC_right_item" valign="top">'.
                    773:                            &mt($item->{'header'}->[0]->{'col3'});
                    774:             }
1.69      raeburn   775:             if ($action eq 'serverstatuses') {
                    776:                 $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
                    777:             }
                    778:             $output .= '</td>';
1.6       raeburn   779:         }
1.150     raeburn   780:         if ($item->{'header'}->[0]->{'col4'}) {
                    781:             $output .= '<td class="LC_right_item" valign="top">'.
                    782:                        &mt($item->{'header'}->[0]->{'col4'});
                    783:         }
1.69      raeburn   784:         $output .= '</tr>';
1.48      raeburn   785:         $rowtotal ++;
1.168     raeburn   786:         if ($action eq 'quotas') {
1.86      raeburn   787:             $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.3       raeburn   788:         } elsif ($action eq 'autoenroll') {
1.30      raeburn   789:             $output .= &print_autoenroll($dom,$settings,\$rowtotal);
1.125     raeburn   790:         } elsif ($action eq 'autocreate') {
                    791:             $output .= &print_autocreate($dom,$settings,\$rowtotal);
1.23      raeburn   792:         } elsif ($action eq 'directorysrch') {
1.30      raeburn   793:             $output .= &print_directorysrch($dom,$settings,\$rowtotal);
1.28      raeburn   794:         } elsif ($action eq 'contacts') {
1.30      raeburn   795:             $output .= &print_contacts($dom,$settings,\$rowtotal);
1.43      raeburn   796:         } elsif ($action eq 'defaults') {
                    797:             $output .= &print_defaults($dom,\$rowtotal);
1.46      raeburn   798:         } elsif ($action eq 'scantron') {
                    799:             $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
1.69      raeburn   800:         } elsif ($action eq 'serverstatuses') {
                    801:             $output .= &print_serverstatuses($dom,$settings,\$rowtotal);
1.118     jms       802:         } elsif ($action eq 'helpsettings') {
1.168     raeburn   803:             $output .= &print_helpsettings($dom,$confname,$settings,\$rowtotal);
1.150     raeburn   804:         } elsif ($action eq 'loadbalancing') {
                    805:             $output .= &print_loadbalancing($dom,$settings,\$rowtotal);
1.121     raeburn   806:         }
1.3       raeburn   807:     }
1.30      raeburn   808:     $output .= '
1.3       raeburn   809:    </table>
                    810:   </td>
                    811:  </tr>
1.30      raeburn   812: </table><br />';
                    813:     return ($output,$rowtotal);
1.1       raeburn   814: }
                    815: 
1.3       raeburn   816: sub print_login {
1.168     raeburn   817:     my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110     raeburn   818:     my ($css_class,$datatable);
1.6       raeburn   819:     my %choices = &login_choices();
1.110     raeburn   820: 
1.168     raeburn   821:     if ($caller eq 'service') {
1.149     raeburn   822:         my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110     raeburn   823:         my $choice = $choices{'disallowlogin'};
                    824:         $css_class = ' class="LC_odd_row"';
1.128     raeburn   825:         $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110     raeburn   826:                       '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128     raeburn   827:                       '<th>'.$choices{'server'}.'</th>'.
                    828:                       '<th>'.$choices{'serverpath'}.'</th>'.
                    829:                       '<th>'.$choices{'custompath'}.'</th>'.
                    830:                       '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110     raeburn   831:         my %disallowed;
                    832:         if (ref($settings) eq 'HASH') {
                    833:             if (ref($settings->{'loginvia'}) eq 'HASH') {
                    834:                %disallowed = %{$settings->{'loginvia'}};
                    835:             }
                    836:         }
                    837:         foreach my $lonhost (sort(keys(%servers))) {
                    838:             my $direct = 'selected="selected"';
1.128     raeburn   839:             if (ref($disallowed{$lonhost}) eq 'HASH') {
                    840:                 if ($disallowed{$lonhost}{'server'} ne '') {
                    841:                     $direct = '';
                    842:                 }
1.110     raeburn   843:             }
1.115     raeburn   844:             $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128     raeburn   845:                           '<td><select name="'.$lonhost.'_server">'.
1.110     raeburn   846:                           '<option value=""'.$direct.'>'.$choices{'directlogin'}.
                    847:                           '</option>';
1.184     raeburn   848:             foreach my $hostid (sort(keys(%servers))) {
1.115     raeburn   849:                 next if ($servers{$hostid} eq $servers{$lonhost});
1.110     raeburn   850:                 my $selected = '';
1.128     raeburn   851:                 if (ref($disallowed{$lonhost}) eq 'HASH') {
                    852:                     if ($hostid eq $disallowed{$lonhost}{'server'}) {
                    853:                         $selected = 'selected="selected"';
                    854:                     }
1.110     raeburn   855:                 }
                    856:                 $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
                    857:                               $servers{$hostid}.'</option>';
                    858:             }
1.128     raeburn   859:             $datatable .= '</select></td>'.
                    860:                           '<td><select name="'.$lonhost.'_serverpath">';
                    861:             foreach my $path ('','/','/adm/login','/adm/roles','custom') {
                    862:                 my $pathname = $path;
                    863:                 if ($path eq 'custom') {
                    864:                     $pathname = &mt('Custom Path').' ->';
                    865:                 }
                    866:                 my $selected = '';
                    867:                 if (ref($disallowed{$lonhost}) eq 'HASH') {
                    868:                     if ($path eq $disallowed{$lonhost}{'serverpath'}) {
                    869:                         $selected = 'selected="selected"';
                    870:                     }
                    871:                 } elsif ($path eq '') {
                    872:                     $selected = 'selected="selected"';
                    873:                 }
                    874:                 $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
                    875:             }
                    876:             $datatable .= '</select></td>';
                    877:             my ($custom,$exempt);
                    878:             if (ref($disallowed{$lonhost}) eq 'HASH') {
                    879:                 $custom = $disallowed{$lonhost}{'custompath'};
                    880:                 $exempt = $disallowed{$lonhost}{'exempt'};
                    881:             }
                    882:             $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
                    883:                           '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
                    884:                           '</tr>';
1.110     raeburn   885:         }
                    886:         $datatable .= '</table></td></tr>';
                    887:         return $datatable;
1.168     raeburn   888:     } elsif ($caller eq 'page') {
                    889:         my %defaultchecked = ( 
                    890:                                'coursecatalog' => 'on',
1.188     raeburn   891:                                'helpdesk'      => 'on',
1.168     raeburn   892:                                'adminmail'     => 'off',
                    893:                                'newuser'       => 'off',
                    894:                              );
1.188     raeburn   895:         my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.168     raeburn   896:         my (%checkedon,%checkedoff);
1.42      raeburn   897:         foreach my $item (@toggles) {
1.168     raeburn   898:             if ($defaultchecked{$item} eq 'on') { 
                    899:                 $checkedon{$item} = ' checked="checked" ';
1.42      raeburn   900:                 $checkedoff{$item} = ' ';
1.168     raeburn   901:             } elsif ($defaultchecked{$item} eq 'off') {
                    902:                 $checkedoff{$item} = ' checked="checked" ';
1.42      raeburn   903:                 $checkedon{$item} = ' ';
                    904:             }
1.1       raeburn   905:         }
1.168     raeburn   906:         my @images = ('img','logo','domlogo','login');
                    907:         my @logintext = ('textcol','bgcol');
                    908:         my @bgs = ('pgbg','mainbg','sidebg');
                    909:         my @links = ('link','alink','vlink');
                    910:         my %designhash = &Apache::loncommon::get_domainconf($dom);
                    911:         my %defaultdesign = %Apache::loncommon::defaultdesign;
                    912:         my (%is_custom,%designs);
                    913:         my %defaults = (
                    914:                        font => $defaultdesign{'login.font'},
                    915:                        );
1.6       raeburn   916:         foreach my $item (@images) {
1.168     raeburn   917:             $defaults{$item} = $defaultdesign{'login.'.$item};
                    918:             $defaults{'showlogo'}{$item} = 1;
                    919:         }
                    920:         foreach my $item (@bgs) {
                    921:             $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6       raeburn   922:         }
1.41      raeburn   923:         foreach my $item (@logintext) {
1.168     raeburn   924:             $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41      raeburn   925:         }
1.168     raeburn   926:         foreach my $item (@links) {
                    927:             $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6       raeburn   928:         }
1.168     raeburn   929:         if (ref($settings) eq 'HASH') {
                    930:             foreach my $item (@toggles) {
                    931:                 if ($settings->{$item} eq '1') {
                    932:                     $checkedon{$item} =  ' checked="checked" ';
                    933:                     $checkedoff{$item} = ' ';
                    934:                 } elsif ($settings->{$item} eq '0') {
                    935:                     $checkedoff{$item} =  ' checked="checked" ';
                    936:                     $checkedon{$item} = ' ';
                    937:                 }
                    938:             }
                    939:             foreach my $item (@images) {
                    940:                 if (defined($settings->{$item})) {
                    941:                     $designs{$item} = $settings->{$item};
                    942:                     $is_custom{$item} = 1;
                    943:                 }
                    944:                 if (defined($settings->{'showlogo'}{$item})) {
                    945:                     $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
                    946:                 }
                    947:             }
                    948:             foreach my $item (@logintext) {
                    949:                 if ($settings->{$item} ne '') {
                    950:                     $designs{'logintext'}{$item} = $settings->{$item};
                    951:                     $is_custom{$item} = 1;
                    952:                 }
                    953:             }
                    954:             if ($settings->{'font'} ne '') {
                    955:                 $designs{'font'} = $settings->{'font'};
                    956:                 $is_custom{'font'} = 1;
                    957:             }
                    958:             foreach my $item (@bgs) {
                    959:                 if ($settings->{$item} ne '') {
                    960:                     $designs{'bgs'}{$item} = $settings->{$item};
                    961:                     $is_custom{$item} = 1;
                    962:                 }
                    963:             }
                    964:             foreach my $item (@links) {
                    965:                 if ($settings->{$item} ne '') {
                    966:                     $designs{'links'}{$item} = $settings->{$item};
                    967:                     $is_custom{$item} = 1;
                    968:                 }
                    969:             }
                    970:         } else {
                    971:             if ($designhash{$dom.'.login.font'} ne '') {
                    972:                 $designs{'font'} = $designhash{$dom.'.login.font'};
                    973:                 $is_custom{'font'} = 1;
                    974:             }
                    975:             foreach my $item (@images) {
                    976:                 if ($designhash{$dom.'.login.'.$item} ne '') {
                    977:                     $designs{$item} = $designhash{$dom.'.login.'.$item};
                    978:                     $is_custom{$item} = 1;
                    979:                 }
                    980:             }
                    981:             foreach my $item (@bgs) {
                    982:                 if ($designhash{$dom.'.login.'.$item} ne '') {
                    983:                     $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
                    984:                     $is_custom{$item} = 1;
                    985:                 }
1.6       raeburn   986:             }
1.168     raeburn   987:             foreach my $item (@links) {
                    988:                 if ($designhash{$dom.'.login.'.$item} ne '') {
                    989:                     $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
                    990:                     $is_custom{$item} = 1;
                    991:                 }
1.6       raeburn   992:             }
                    993:         }
1.168     raeburn   994:         my %alt_text = &Apache::lonlocal::texthash  ( img => 'Log-in banner',
                    995:                                                       logo => 'Institution Logo',
                    996:                                                       domlogo => 'Domain Logo',
                    997:                                                       login => 'Login box');
                    998:         my $itemcount = 1;
                    999:         foreach my $item (@toggles) {
                   1000:             $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   1001:             $datatable .=  
                   1002:                 '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
                   1003:                 '</td><td>'.
                   1004:                 '<span class="LC_nobreak"><label><input type="radio" name="'.
                   1005:                 $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
                   1006:                 '</label>&nbsp;<label><input type="radio" name="'.$item.'"'.
                   1007:                 $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
                   1008:                 '</tr>';
                   1009:             $itemcount ++;
1.6       raeburn  1010:         }
1.168     raeburn  1011:         $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
                   1012:         $datatable .= '</tr></table></td></tr>';
                   1013:     } elsif ($caller eq 'help') {
                   1014:         my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
                   1015:         my $switchserver = &check_switchserver($dom,$confname);
                   1016:         my $itemcount = 1;
                   1017:         $defaulturl = '/adm/loginproblems.html';
                   1018:         $defaulttype = 'default';
                   1019:         %lt = &Apache::lonlocal::texthash (
                   1020:                      del     => 'Delete?',
                   1021:                      rep     => 'Replace:',
                   1022:                      upl     => 'Upload:',
                   1023:                      default => 'Default',
                   1024:                      custom  => 'Custom',
                   1025:                                              );
                   1026:         %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
                   1027:         my @currlangs;
                   1028:         if (ref($settings) eq 'HASH') {
                   1029:             if (ref($settings->{'helpurl'}) eq 'HASH') {
                   1030:                 foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
                   1031:                     next if ($settings->{'helpurl'}{$key} eq '');
                   1032:                     $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
                   1033:                     $type{$key} = 'custom';
                   1034:                     unless ($key eq 'nolang') {
                   1035:                         push(@currlangs,$key);
                   1036:                     }
                   1037:                 }
                   1038:             } elsif ($settings->{'helpurl'} ne '') {
                   1039:                 $type{'nolang'} = 'custom';
                   1040:                 $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8       raeburn  1041:             }
                   1042:         }
1.168     raeburn  1043:         foreach my $lang ('nolang',sort(@currlangs)) {
                   1044:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   1045:             $datatable .= '<tr'.$css_class.'>';
                   1046:             if ($url{$lang} eq '') {
                   1047:                 $url{$lang} = $defaulturl;
                   1048:             }
                   1049:             if ($type{$lang} eq '') {
                   1050:                 $type{$lang} = $defaulttype;
                   1051:             }
                   1052:             $datatable .= '<td colspan="2"><span class="LC_nobreak">';
                   1053:             if ($lang eq 'nolang') {
                   1054:                 $datatable .= &mt('Log-in help page if no specific language file: [_1]',
                   1055:                                   &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
                   1056:             } else {
                   1057:                 $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
                   1058:                                   $langchoices{$lang},
                   1059:                                   &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
                   1060:             }
                   1061:             $datatable .= '</span></td>'."\n".
                   1062:                           '<td class="LC_left_item">';
                   1063:             if ($type{$lang} eq 'custom') {
                   1064:                 $datatable .= '<span class="LC_nobreak"><label>'.
                   1065:                               '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
                   1066:                               $lt{'del'}.'</label>&nbsp;'.$lt{'rep'}.'</span>';
                   1067:             } else {
                   1068:                 $datatable .= $lt{'upl'};
                   1069:             }
                   1070:             $datatable .='<br />';
                   1071:             if ($switchserver) {
                   1072:                 $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   1073:             } else {
                   1074:                 $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6       raeburn  1075:             }
1.168     raeburn  1076:             $datatable .= '</td></tr>';
                   1077:             $itemcount ++;
1.6       raeburn  1078:         }
1.168     raeburn  1079:         my @addlangs;
                   1080:         foreach my $lang (sort(keys(%langchoices))) {
                   1081:             next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
                   1082:             push(@addlangs,$lang);
                   1083:         }
                   1084:         if (@addlangs > 0) {
                   1085:             my %toadd;
                   1086:             map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
                   1087:             $toadd{''} = &mt('Select');
                   1088:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   1089:             $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
                   1090:                           &mt('Add log-in help page for a specific language:').'&nbsp;'.
                   1091:                           &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
                   1092:                           '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
                   1093:             if ($switchserver) {
                   1094:                 $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   1095:             } else {
                   1096:                 $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6       raeburn  1097:             }
1.168     raeburn  1098:             $datatable .= '</td></tr>';
1.169     raeburn  1099:             $itemcount ++;
1.6       raeburn  1100:         }
1.169     raeburn  1101:         $datatable .= &captcha_choice('login',$settings,$itemcount);
1.1       raeburn  1102:     }
1.6       raeburn  1103:     return $datatable;
                   1104: }
                   1105: 
                   1106: sub login_choices {
                   1107:     my %choices =
                   1108:         &Apache::lonlocal::texthash (
1.116     bisitz   1109:             coursecatalog => 'Display Course/Community Catalog link?',
1.110     raeburn  1110:             adminmail     => "Display Administrator's E-mail Address?",
1.188     raeburn  1111:             helpdesk      => 'Display "Contact Helpdesk" link',
1.110     raeburn  1112:             disallowlogin => "Login page requests redirected",
                   1113:             hostid        => "Server",
1.128     raeburn  1114:             server        => "Redirect to:",
                   1115:             serverpath    => "Path",
                   1116:             custompath    => "Custom", 
                   1117:             exempt        => "Exempt IP(s)",
1.110     raeburn  1118:             directlogin   => "No redirect",
                   1119:             newuser       => "Link to create a user account",
                   1120:             img           => "Header",
                   1121:             logo          => "Main Logo",
                   1122:             domlogo       => "Domain Logo",
                   1123:             login         => "Log-in Header", 
                   1124:             textcol       => "Text color",
                   1125:             bgcol         => "Box color",
                   1126:             bgs           => "Background colors",
                   1127:             links         => "Link colors",
                   1128:             font          => "Font color",
                   1129:             pgbg          => "Header",
                   1130:             mainbg        => "Page",
                   1131:             sidebg        => "Login box",
                   1132:             link          => "Link",
                   1133:             alink         => "Active link",
                   1134:             vlink         => "Visited link",
1.6       raeburn  1135:         );
                   1136:     return %choices;
                   1137: }
                   1138: 
                   1139: sub print_rolecolors {
1.30      raeburn  1140:     my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6       raeburn  1141:     my %choices = &color_font_choices();
                   1142:     my @bgs = ('pgbg','tabbg','sidebg');
                   1143:     my @links = ('link','alink','vlink');
                   1144:     my @images = ('img');
                   1145:     my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7       albertel 1146:     my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6       raeburn  1147:     my %defaultdesign = %Apache::loncommon::defaultdesign;
                   1148:     my (%is_custom,%designs);
1.200     raeburn  1149:     my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6       raeburn  1150:     if (ref($settings) eq 'HASH') {
                   1151:         if (ref($settings->{$role}) eq 'HASH') {
                   1152:             if ($settings->{$role}->{'img'} ne '') {
                   1153:                 $designs{'img'} = $settings->{$role}->{'img'};
                   1154:                 $is_custom{'img'} = 1;
                   1155:             }
                   1156:             if ($settings->{$role}->{'font'} ne '') {
                   1157:                 $designs{'font'} = $settings->{$role}->{'font'};
                   1158:                 $is_custom{'font'} = 1;
                   1159:             }
1.97      tempelho 1160:             if ($settings->{$role}->{'fontmenu'} ne '') {
                   1161:                 $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
                   1162:                 $is_custom{'fontmenu'} = 1;
                   1163:             }
1.6       raeburn  1164:             foreach my $item (@bgs) {
                   1165:                 if ($settings->{$role}->{$item} ne '') {
                   1166:                     $designs{'bgs'}{$item} = $settings->{$role}->{$item};
                   1167:                     $is_custom{$item} = 1;
                   1168:                 }
                   1169:             }
                   1170:             foreach my $item (@links) {
                   1171:                 if ($settings->{$role}->{$item} ne '') {
                   1172:                     $designs{'links'}{$item} = $settings->{$role}->{$item};
                   1173:                     $is_custom{$item} = 1;
                   1174:                 }
                   1175:             }
                   1176:         }
                   1177:     } else {
                   1178:         if ($designhash{$dom.'.'.$role.'.img'} ne '') {
                   1179:             $designs{img} = $designhash{$dom.'.'.$role.'.img'};
                   1180:             $is_custom{'img'} = 1;
                   1181:         }
1.97      tempelho 1182:         if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
                   1183:             $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
                   1184:             $is_custom{'fontmenu'} = 1; 
                   1185:         }
1.6       raeburn  1186:         if ($designhash{$dom.'.'.$role.'.font'} ne '') {
                   1187:             $designs{font} = $designhash{$dom.'.'.$role.'.font'};
                   1188:             $is_custom{'font'} = 1;
                   1189:         }
                   1190:         foreach my $item (@bgs) {
                   1191:             if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
                   1192:                 $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
                   1193:                 $is_custom{$item} = 1;
                   1194:             
                   1195:             }
                   1196:         }
                   1197:         foreach my $item (@links) {
                   1198:             if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
                   1199:                 $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
                   1200:                 $is_custom{$item} = 1;
                   1201:             }
                   1202:         }
                   1203:     }
                   1204:     my $itemcount = 1;
1.30      raeburn  1205:     my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6       raeburn  1206:     $datatable .= '</tr></table></td></tr>';
                   1207:     return $datatable;
                   1208: }
                   1209: 
1.200     raeburn  1210: sub role_defaults {
                   1211:     my ($role,$bgs,$links,$images,$logintext) = @_;
1.202     raeburn  1212:     my %defaults;
                   1213:     unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1.200     raeburn  1214:         return %defaults;
                   1215:     }
                   1216:     my %defaultdesign = %Apache::loncommon::defaultdesign;
                   1217:     if ($role eq 'login') {
                   1218:         %defaults = (
                   1219:                        font => $defaultdesign{$role.'.font'},
                   1220:                     );
                   1221:         if (ref($logintext) eq 'ARRAY') {
                   1222:             foreach my $item (@{$logintext}) {
                   1223:                 $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
                   1224:             }
                   1225:         }
                   1226:         foreach my $item (@{$images}) {
                   1227:             $defaults{'showlogo'}{$item} = 1;
                   1228:         }
                   1229:     } else {
                   1230:         %defaults = (
                   1231:                        img => $defaultdesign{$role.'.img'},
                   1232:                        font => $defaultdesign{$role.'.font'},
                   1233:                        fontmenu => $defaultdesign{$role.'.fontmenu'},
                   1234:                     );
                   1235:     }
                   1236:     foreach my $item (@{$bgs}) {
                   1237:         $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
                   1238:     }
                   1239:     foreach my $item (@{$links}) {
                   1240:         $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
                   1241:     }
                   1242:     foreach my $item (@{$images}) {
                   1243:         $defaults{$item} = $defaultdesign{$role.'.'.$item};
                   1244:     }
                   1245:     return %defaults;
                   1246: }
                   1247: 
1.6       raeburn  1248: sub display_color_options {
1.9       raeburn  1249:     my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135     bisitz   1250:         $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159     raeburn  1251:     my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6       raeburn  1252:     my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.176     raeburn  1253:     my $datatable = '<tr'.$css_class.'>'.
1.6       raeburn  1254:         '<td>'.$choices->{'font'}.'</td>';
                   1255:     if (!$is_custom->{'font'}) {
1.30      raeburn  1256:         $datatable .=  '<td>'.&mt('Default in use:').'&nbsp;<span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6       raeburn  1257:     } else {
                   1258:         $datatable .= '<td>&nbsp;</td>';
                   1259:     }
1.174     foxr     1260:     my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
                   1261: 
1.8       raeburn  1262:     $datatable .= '<td><span class="LC_nobreak">'.
1.174     foxr     1263:                   '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1.202     raeburn  1264:                   ' value="'.$current_color.'" />&nbsp;'.
1.174     foxr     1265:                   '&nbsp;</td></tr>';
1.107     raeburn  1266:     unless ($role eq 'login') { 
                   1267:         $datatable .= '<tr'.$css_class.'>'.
                   1268:                       '<td>'.$choices->{'fontmenu'}.'</td>';
                   1269:         if (!$is_custom->{'fontmenu'}) {
                   1270:             $datatable .=  '<td>'.&mt('Default in use:').'&nbsp;<span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
                   1271:         } else {
                   1272:             $datatable .= '<td>&nbsp;</td>';
                   1273:         }
1.202     raeburn  1274: 	$current_color = $designs->{'fontmenu'} ?
1.174     foxr     1275: 	    $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107     raeburn  1276:         $datatable .= '<td><span class="LC_nobreak">'.
1.174     foxr     1277:                       '<input class="colorchooser" type="text" size="10" name="'
                   1278: 		      .$role.'_fontmenu"'.
                   1279:                       ' value="'.$current_color.'" />&nbsp;'.
                   1280:                       '&nbsp;</td></tr>';
1.97      tempelho 1281:     }
1.9       raeburn  1282:     my $switchserver = &check_switchserver($dom,$confname);
1.6       raeburn  1283:     foreach my $img (@{$images}) {
1.18      albertel 1284: 	$itemcount ++;
1.6       raeburn  1285:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8       raeburn  1286:         $datatable .= '<tr'.$css_class.'>'.
1.70      raeburn  1287:                       '<td>'.$choices->{$img};
1.41      raeburn  1288:         my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70      raeburn  1289:         if ($role eq 'login') {
                   1290:             if ($img eq 'login') {
                   1291:                 $login_hdr_pick =
1.135     bisitz   1292:                     &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70      raeburn  1293:                 $logincolors =
                   1294:                     &login_text_colors($img,$role,$logintext,$phase,$choices,
1.201     raeburn  1295:                                        $designs,$defaults);
1.70      raeburn  1296:             } elsif ($img ne 'domlogo') {
                   1297:                 $datatable.= &logo_display_options($img,$defaults,$designs);
                   1298:             }
                   1299:         }
                   1300:         $datatable .= '</td>';
1.6       raeburn  1301:         if ($designs->{$img} ne '') {
                   1302:             $imgfile = $designs->{$img};
1.18      albertel 1303: 	    $img_import = ($imgfile =~ m{^/adm/});
1.6       raeburn  1304:         } else {
                   1305:             $imgfile = $defaults->{$img};
                   1306:         }
                   1307:         if ($imgfile) {
1.9       raeburn  1308:             my ($showfile,$fullsize);
                   1309:             if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6       raeburn  1310:                 my $urldir = $1;
                   1311:                 my $filename = $2;
                   1312:                 my @info = &Apache::lonnet::stat_file($designs->{$img});
                   1313:                 if (@info) {
                   1314:                     my $thumbfile = 'tn-'.$filename;
                   1315:                     my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
                   1316:                     if (@thumb) {
                   1317:                         $showfile = $urldir.'/'.$thumbfile;
                   1318:                     } else {
                   1319:                         $showfile = $imgfile;
                   1320:                     }
                   1321:                 } else {
                   1322:                     $showfile = '';
                   1323:                 }
                   1324:             } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16      raeburn  1325:                 $showfile = $imgfile;
1.6       raeburn  1326:                 my $imgdir = $1;
                   1327:                 my $filename = $2;
1.159     raeburn  1328:                 if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6       raeburn  1329:                     $showfile = "/$imgdir/tn-".$filename;
                   1330:                 } else {
1.159     raeburn  1331:                     my $input = $londocroot.$imgfile;
                   1332:                     my $output = "$londocroot/$imgdir/tn-".$filename;
1.6       raeburn  1333:                     if (!-e $output) {
1.9       raeburn  1334:                         my ($width,$height) = &thumb_dimensions();
1.16      raeburn  1335:                         my ($fullwidth,$fullheight) = &check_dimensions($input);
                   1336:                         if ($fullwidth ne '' && $fullheight ne '') {
                   1337:                             if ($fullwidth > $width && $fullheight > $height) { 
                   1338:                                 my $size = $width.'x'.$height;
                   1339:                                 system("convert -sample $size $input $output");
1.159     raeburn  1340:                                 $showfile = "/$imgdir/tn-".$filename;
1.16      raeburn  1341:                             }
                   1342:                         }
1.6       raeburn  1343:                     }
                   1344:                 }
1.16      raeburn  1345:             }
1.6       raeburn  1346:             if ($showfile) {
1.40      raeburn  1347:                 if ($showfile =~ m{^/(adm|res)/}) {
                   1348:                     if ($showfile =~ m{^/res/}) {
                   1349:                         my $local_showfile =
                   1350:                             &Apache::lonnet::filelocation('',$showfile);
                   1351:                         &Apache::lonnet::repcopy($local_showfile);
                   1352:                     }
                   1353:                     $showfile = &Apache::loncommon::lonhttpdurl($showfile);
                   1354:                 }
                   1355:                 if ($imgfile) {
                   1356:                     if ($imgfile  =~ m{^/(adm|res)/}) {
                   1357:                         if ($imgfile =~ m{^/res/}) {
                   1358:                             my $local_imgfile =
                   1359:                                 &Apache::lonnet::filelocation('',$imgfile);
                   1360:                             &Apache::lonnet::repcopy($local_imgfile);
                   1361:                         }
                   1362:                         $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
                   1363:                     } else {
                   1364:                         $fullsize = $imgfile;
                   1365:                     }
                   1366:                 }
1.41      raeburn  1367:                 $datatable .= '<td>';
                   1368:                 if ($img eq 'login') {
1.135     bisitz   1369:                     $datatable .= $login_hdr_pick;
                   1370:                 } 
1.41      raeburn  1371:                 $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
                   1372:                                              $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6       raeburn  1373:             } else {
1.201     raeburn  1374:                 $datatable .= '<td>&nbsp;</td><td class="LC_left_item">'.
                   1375:                               &mt('Upload:').'<br />';
1.6       raeburn  1376:             }
                   1377:         } else {
1.201     raeburn  1378:             $datatable .= '<td>&nbsp;</td><td class="LC_left_item">'.
                   1379:                           &mt('Upload:').'<br />';
1.6       raeburn  1380:         }
1.9       raeburn  1381:         if ($switchserver) {
                   1382:             $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   1383:         } else {
1.135     bisitz   1384:             if ($img ne 'login') { # suppress file selection for Log-in header
                   1385:                 $datatable .='&nbsp;<input type="file" name="'.$role.'_'.$img.'" />';
                   1386:             }
1.9       raeburn  1387:         }
                   1388:         $datatable .= '</td></tr>';
1.6       raeburn  1389:     }
                   1390:     $itemcount ++;
                   1391:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   1392:     $datatable .= '<tr'.$css_class.'>'.
                   1393:                   '<td>'.$choices->{'bgs'}.'</td>';
                   1394:     my $bgs_def;
                   1395:     foreach my $item (@{$bgs}) {
                   1396:         if (!$is_custom->{$item}) {
1.70      raeburn  1397:             $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  1398:         }
                   1399:     }
                   1400:     if ($bgs_def) {
1.8       raeburn  1401:         $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6       raeburn  1402:     } else {
                   1403:         $datatable .= '<td>&nbsp;</td>';
                   1404:     }
                   1405:     $datatable .= '<td class="LC_right_item">'.
                   1406:                   '<table border="0"><tr>';
1.174     foxr     1407: 
1.6       raeburn  1408:     foreach my $item (@{$bgs}) {
1.201     raeburn  1409:         $datatable .= '<td align="center">'.$choices->{$item};
1.174     foxr     1410: 	my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6       raeburn  1411:         if ($designs->{'bgs'}{$item}) {
1.174     foxr     1412:             $datatable .= '&nbsp;';
1.6       raeburn  1413:         }
1.174     foxr     1414:         $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41      raeburn  1415:                       '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6       raeburn  1416:     }
                   1417:     $datatable .= '</tr></table></td></tr>';
                   1418:     $itemcount ++;
                   1419:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   1420:     $datatable .= '<tr'.$css_class.'>'.
                   1421:                   '<td>'.$choices->{'links'}.'</td>';
                   1422:     my $links_def;
                   1423:     foreach my $item (@{$links}) {
                   1424:         if (!$is_custom->{$item}) {
1.30      raeburn  1425:             $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  1426:         }
                   1427:     }
                   1428:     if ($links_def) {
1.8       raeburn  1429:         $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6       raeburn  1430:     } else {
                   1431:         $datatable .= '<td>&nbsp;</td>';
                   1432:     }
                   1433:     $datatable .= '<td class="LC_right_item">'.
                   1434:                   '<table border="0"><tr>';
                   1435:     foreach my $item (@{$links}) {
1.174     foxr     1436: 	my $color = $designs->{'link'}{$item} ? $designs->{'link'}{$item} : $defaults->{'links'}{$item};
1.201     raeburn  1437:         $datatable .= '<td align="center">'.$choices->{$item}."\n";
1.6       raeburn  1438:         if ($designs->{'links'}{$item}) {
1.174     foxr     1439:             $datatable.='&nbsp;';
1.6       raeburn  1440:         }
1.174     foxr     1441:         $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6       raeburn  1442:                       '" /></td>';
                   1443:     }
1.30      raeburn  1444:     $$rowtotal += $itemcount;
1.3       raeburn  1445:     return $datatable;
                   1446: }
                   1447: 
1.70      raeburn  1448: sub logo_display_options {
                   1449:     my ($img,$defaults,$designs) = @_;
                   1450:     my $checkedon;
                   1451:     if (ref($defaults) eq 'HASH') {
                   1452:         if (ref($defaults->{'showlogo'}) eq 'HASH') {
                   1453:             if ($defaults->{'showlogo'}{$img}) {
                   1454:                 $checkedon = 'checked="checked" ';     
                   1455:             }
                   1456:         } 
                   1457:     }
                   1458:     if (ref($designs) eq 'HASH') {
                   1459:         if (ref($designs->{'showlogo'}) eq 'HASH') {
                   1460:             if (defined($designs->{'showlogo'}{$img})) {
                   1461:                 if ($designs->{'showlogo'}{$img} == 0) {
                   1462:                     $checkedon = '';
                   1463:                 } elsif ($designs->{'showlogo'}{$img} == 1) {
                   1464:                     $checkedon = 'checked="checked" ';
                   1465:                 }
                   1466:             }
                   1467:         }
                   1468:     }
                   1469:     return '<br /><label>&nbsp;&nbsp;<input type="checkbox" name="'.
                   1470:            'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
                   1471:            &mt('show').'</label>'."\n";
                   1472: }
                   1473: 
1.41      raeburn  1474: sub login_header_options  {
1.135     bisitz   1475:     my ($img,$role,$defaults,$is_custom,$choices) = @_;
                   1476:     my $output = '';
1.41      raeburn  1477:     if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135     bisitz   1478:         $output .= &mt('Text default(s):').'<br />';
1.41      raeburn  1479:         if (!$is_custom->{'textcol'}) {
                   1480:             $output .= $choices->{'textcol'}.':&nbsp;'.$defaults->{'logintext'}{'textcol'}.
                   1481:                        '&nbsp;&nbsp;&nbsp;';
                   1482:         }
                   1483:         if (!$is_custom->{'bgcol'}) {
                   1484:             $output .= $choices->{'bgcol'}.':&nbsp;'.
                   1485:                        '<span id="css_'.$role.'_font" style="background-color: '.
                   1486:                        $defaults->{'logintext'}{'bgcol'}.';">&nbsp;&nbsp;&nbsp;</span>';
                   1487:         }
                   1488:         $output .= '<br />';
                   1489:     }
                   1490:     $output .='<br />';
                   1491:     return $output;
                   1492: }
                   1493: 
                   1494: sub login_text_colors {
1.201     raeburn  1495:     my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41      raeburn  1496:     my $color_menu = '<table border="0"><tr>';
                   1497:     foreach my $item (@{$logintext}) {
1.201     raeburn  1498:         $color_menu .= '<td align="center">'.$choices->{$item};
                   1499:         my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
                   1500:         $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
                   1501:                       '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41      raeburn  1502:     }
                   1503:     $color_menu .= '</tr></table><br />';
                   1504:     return $color_menu;
                   1505: }
                   1506: 
                   1507: sub image_changes {
                   1508:     my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
                   1509:     my $output;
1.135     bisitz   1510:     if ($img eq 'login') {
                   1511:             # suppress image for Log-in header
                   1512:     } elsif (!$is_custom) {
1.70      raeburn  1513:         if ($img ne 'domlogo') {
1.41      raeburn  1514:             $output .= &mt('Default image:').'<br />';
                   1515:         } else {
                   1516:             $output .= &mt('Default in use:').'<br />';
                   1517:         }
                   1518:     }
1.135     bisitz   1519:     if ($img eq 'login') { # suppress image for Log-in header
                   1520:         $output .= '<td>'.$logincolors;
1.41      raeburn  1521:     } else {
1.135     bisitz   1522:         if ($img_import) {
                   1523:             $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
                   1524:         }
                   1525:         $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
                   1526:                    $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
                   1527:         if ($is_custom) {
                   1528:             $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
                   1529:                        '<input type="checkbox" name="'.
                   1530:                        $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
                   1531:                        '</label>&nbsp;'.&mt('Replace:').'</span><br />';
                   1532:         } else {
1.201     raeburn  1533:             $output .= '<td valign="middle">'.$logincolors.&mt('Upload:').'<br />';
1.135     bisitz   1534:         }
1.41      raeburn  1535:     }
                   1536:     return $output;
                   1537: }
                   1538: 
1.3       raeburn  1539: sub print_quotas {
1.86      raeburn  1540:     my ($dom,$settings,$rowtotal,$action) = @_;
                   1541:     my $context;
                   1542:     if ($action eq 'quotas') {
                   1543:         $context = 'tools';
                   1544:     } else {
                   1545:         $context = $action;
                   1546:     }
1.197     raeburn  1547:     my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44      raeburn  1548:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3       raeburn  1549:     my $typecount = 0;
1.101     raeburn  1550:     my ($css_class,%titles);
1.86      raeburn  1551:     if ($context eq 'requestcourses') {
1.98      raeburn  1552:         @usertools = ('official','unofficial','community');
1.106     raeburn  1553:         @options =('norequest','approval','validate','autolimit');
1.101     raeburn  1554:         %validations = &Apache::lonnet::auto_courserequest_checks($dom);
                   1555:         %titles = &courserequest_titles();
1.163     raeburn  1556:     } elsif ($context eq 'requestauthor') {
                   1557:         @usertools = ('author');
                   1558:         @options = ('norequest','approval','automatic');
                   1559:         %titles = &authorrequest_titles(); 
1.86      raeburn  1560:     } else {
1.162     raeburn  1561:         @usertools = ('aboutme','blog','webdav','portfolio');
1.101     raeburn  1562:         %titles = &tool_titles();
1.86      raeburn  1563:     }
1.26      raeburn  1564:     if (ref($types) eq 'ARRAY') {
1.23      raeburn  1565:         foreach my $type (@{$types}) {
1.197     raeburn  1566:             my ($currdefquota,$currauthorquota);
1.163     raeburn  1567:             unless (($context eq 'requestcourses') ||
                   1568:                     ($context eq 'requestauthor')) {
1.86      raeburn  1569:                 if (ref($settings) eq 'HASH') {
                   1570:                     if (ref($settings->{defaultquota}) eq 'HASH') {
1.197     raeburn  1571:                         $currdefquota = $settings->{defaultquota}->{$type};
1.86      raeburn  1572:                     } else {
                   1573:                         $currdefquota = $settings->{$type};
                   1574:                     }
1.197     raeburn  1575:                     if (ref($settings->{authorquota}) eq 'HASH') {
                   1576:                         $currauthorquota = $settings->{authorquota}->{$type};
                   1577:                     }
1.78      raeburn  1578:                 }
1.72      raeburn  1579:             }
1.3       raeburn  1580:             if (defined($usertypes->{$type})) {
                   1581:                 $typecount ++;
                   1582:                 $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72      raeburn  1583:                 $datatable .= '<tr'.$css_class.'>'.
1.3       raeburn  1584:                               '<td>'.$usertypes->{$type}.'</td>'.
1.72      raeburn  1585:                               '<td class="LC_left_item">';
1.101     raeburn  1586:                 if ($context eq 'requestcourses') {
                   1587:                     $datatable .= '<table><tr>';
                   1588:                 }
                   1589:                 my %cell;  
1.72      raeburn  1590:                 foreach my $item (@usertools) {
1.101     raeburn  1591:                     if ($context eq 'requestcourses') {
                   1592:                         my ($curroption,$currlimit);
                   1593:                         if (ref($settings) eq 'HASH') {
                   1594:                             if (ref($settings->{$item}) eq 'HASH') {
                   1595:                                 $curroption = $settings->{$item}->{$type};
                   1596:                                 if ($curroption =~ /^autolimit=(\d*)$/) {
                   1597:                                     $currlimit = $1; 
                   1598:                                 }
                   1599:                             }
                   1600:                         }
                   1601:                         if (!$curroption) {
                   1602:                             $curroption = 'norequest';
                   1603:                         }
                   1604:                         $datatable .= '<th>'.$titles{$item}.'</th>';
                   1605:                         foreach my $option (@options) {
                   1606:                             my $val = $option;
                   1607:                             if ($option eq 'norequest') {
                   1608:                                 $val = 0;  
                   1609:                             }
                   1610:                             if ($option eq 'validate') {
                   1611:                                 my $canvalidate = 0;
                   1612:                                 if (ref($validations{$item}) eq 'HASH') { 
                   1613:                                     if ($validations{$item}{$type}) {
                   1614:                                         $canvalidate = 1;
                   1615:                                     }
                   1616:                                 }
                   1617:                                 next if (!$canvalidate);
                   1618:                             }
                   1619:                             my $checked = '';
                   1620:                             if ($option eq $curroption) {
                   1621:                                 $checked = ' checked="checked"';
                   1622:                             } elsif ($option eq 'autolimit') {
                   1623:                                 if ($curroption =~ /^autolimit/) {
                   1624:                                     $checked = ' checked="checked"';
                   1625:                                 }                       
                   1626:                             } 
                   1627:                             $cell{$item} .= '<span class="LC_nobreak"><label>'.
                   1628:                                   '<input type="radio" name="crsreq_'.$item.
                   1629:                                   '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127     raeburn  1630:                                   $titles{$option}.'</label>';
1.101     raeburn  1631:                             if ($option eq 'autolimit') {
1.127     raeburn  1632:                                 $cell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
1.101     raeburn  1633:                                                 $item.'_limit_'.$type.'" size="1" '.
1.103     raeburn  1634:                                                 'value="'.$currlimit.'" />';
1.101     raeburn  1635:                             }
1.127     raeburn  1636:                             $cell{$item} .= '</span> ';
1.103     raeburn  1637:                             if ($option eq 'autolimit') {
1.127     raeburn  1638:                                 $cell{$item} .= $titles{'unlimited'};
1.103     raeburn  1639:                             }
1.101     raeburn  1640:                         }
1.163     raeburn  1641:                     } elsif ($context eq 'requestauthor') {
                   1642:                         my $curroption;
                   1643:                         if (ref($settings) eq 'HASH') {
                   1644:                             $curroption = $settings->{$type};
                   1645:                         }
                   1646:                         if (!$curroption) {
                   1647:                             $curroption = 'norequest';
                   1648:                         }
                   1649:                         foreach my $option (@options) {
                   1650:                             my $val = $option;
                   1651:                             if ($option eq 'norequest') {
                   1652:                                 $val = 0;
                   1653:                             }
                   1654:                             my $checked = '';
                   1655:                             if ($option eq $curroption) {
                   1656:                                 $checked = ' checked="checked"';
                   1657:                             }
                   1658:                             $datatable .= '<span class="LC_nobreak"><label>'.
                   1659:                                   '<input type="radio" name="authorreq_'.$type.
                   1660:                                   '" value="'.$val.'"'.$checked.' />'.
                   1661:                                   $titles{$option}.'</label></span>&nbsp; ';
                   1662:                         }
1.101     raeburn  1663:                     } else {
                   1664:                         my $checked = 'checked="checked" ';
                   1665:                         if (ref($settings) eq 'HASH') {
                   1666:                             if (ref($settings->{$item}) eq 'HASH') {
                   1667:                                 if ($settings->{$item}->{$type} == 0) {
                   1668:                                     $checked = '';
                   1669:                                 } elsif ($settings->{$item}->{$type} == 1) {
                   1670:                                     $checked =  'checked="checked" ';
                   1671:                                 }
1.78      raeburn  1672:                             }
1.72      raeburn  1673:                         }
1.101     raeburn  1674:                         $datatable .= '<span class="LC_nobreak"><label>'.
                   1675:                                       '<input type="checkbox" name="'.$context.'_'.$item.
                   1676:                                       '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
                   1677:                                       '</label></span>&nbsp; ';
1.72      raeburn  1678:                     }
1.101     raeburn  1679:                 }
                   1680:                 if ($context eq 'requestcourses') {
                   1681:                     $datatable .= '</tr><tr>';
                   1682:                     foreach my $item (@usertools) {
1.106     raeburn  1683:                         $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';  
1.101     raeburn  1684:                     }
                   1685:                     $datatable .= '</tr></table>';
1.72      raeburn  1686:                 }
1.86      raeburn  1687:                 $datatable .= '</td>';
1.163     raeburn  1688:                 unless (($context eq 'requestcourses') ||
                   1689:                         ($context eq 'requestauthor')) {
1.86      raeburn  1690:                     $datatable .= 
1.197     raeburn  1691:                               '<td class="LC_right_item">'.
                   1692:                               '<span class="LC_nobreak">'.&mt('Portfolio').':&nbsp;'.
1.3       raeburn  1693:                               '<input type="text" name="quota_'.$type.
1.72      raeburn  1694:                               '" value="'.$currdefquota.
1.197     raeburn  1695:                               '" size="5" /></span>'.('&nbsp;' x 2).
                   1696:                               '<span class="LC_nobreak">'.&mt('Authoring').':&nbsp;'.
                   1697:                               '<input type="text" name="authorquota_'.$type.
                   1698:                               '" value="'.$currauthorquota.
                   1699:                               '" size="5" /></span></td>';
1.86      raeburn  1700:                 }
                   1701:                 $datatable .= '</tr>';
1.3       raeburn  1702:             }
                   1703:         }
                   1704:     }
1.163     raeburn  1705:     unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86      raeburn  1706:         $defaultquota = '20';
1.197     raeburn  1707:         $authorquota = '500';
1.86      raeburn  1708:         if (ref($settings) eq 'HASH') {
                   1709:             if (ref($settings->{'defaultquota'}) eq 'HASH') {
                   1710:                 $defaultquota = $settings->{'defaultquota'}->{'default'};
                   1711:             } elsif (defined($settings->{'default'})) {
                   1712:                 $defaultquota = $settings->{'default'};
                   1713:             }
1.197     raeburn  1714:             if (ref($settings->{'authorquota'}) eq 'HASH') {
                   1715:                 $authorquota = $settings->{'authorquota'}->{'default'};
                   1716:             }
1.3       raeburn  1717:         }
                   1718:     }
                   1719:     $typecount ++;
                   1720:     $css_class = $typecount%2?' class="LC_odd_row"':'';
                   1721:     $datatable .= '<tr'.$css_class.'>'.
1.26      raeburn  1722:                   '<td>'.$othertitle.'</td>'.
1.72      raeburn  1723:                   '<td class="LC_left_item">';
1.101     raeburn  1724:     if ($context eq 'requestcourses') {
                   1725:         $datatable .= '<table><tr>';
                   1726:     }
                   1727:     my %defcell;
1.72      raeburn  1728:     foreach my $item (@usertools) {
1.101     raeburn  1729:         if ($context eq 'requestcourses') {
                   1730:             my ($curroption,$currlimit);
                   1731:             if (ref($settings) eq 'HASH') {
                   1732:                 if (ref($settings->{$item}) eq 'HASH') {
                   1733:                     $curroption = $settings->{$item}->{'default'};
                   1734:                     if ($curroption =~ /^autolimit=(\d*)$/) {
                   1735:                         $currlimit = $1;
                   1736:                     }
                   1737:                 }
                   1738:             }
                   1739:             if (!$curroption) {
                   1740:                 $curroption = 'norequest';
                   1741:             }
                   1742:             $datatable .= '<th>'.$titles{$item}.'</th>';
                   1743:             foreach my $option (@options) {
                   1744:                 my $val = $option;
                   1745:                 if ($option eq 'norequest') {
                   1746:                     $val = 0;
                   1747:                 }
                   1748:                 if ($option eq 'validate') {
                   1749:                     my $canvalidate = 0;
                   1750:                     if (ref($validations{$item}) eq 'HASH') {
                   1751:                         if ($validations{$item}{'default'}) {
                   1752:                             $canvalidate = 1;
                   1753:                         }
                   1754:                     }
                   1755:                     next if (!$canvalidate);
                   1756:                 }
                   1757:                 my $checked = '';
                   1758:                 if ($option eq $curroption) {
                   1759:                     $checked = ' checked="checked"';
                   1760:                 } elsif ($option eq 'autolimit') {
                   1761:                     if ($curroption =~ /^autolimit/) {
                   1762:                         $checked = ' checked="checked"';
                   1763:                     }
                   1764:                 }
                   1765:                 $defcell{$item} .= '<span class="LC_nobreak"><label>'.
                   1766:                                   '<input type="radio" name="crsreq_'.$item.
                   1767:                                   '_default" value="'.$val.'"'.$checked.' />'.
                   1768:                                   $titles{$option}.'</label>';
                   1769:                 if ($option eq 'autolimit') {
1.127     raeburn  1770:                     $defcell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
1.101     raeburn  1771:                                        $item.'_limit_default" size="1" '.
                   1772:                                        'value="'.$currlimit.'" />';
                   1773:                 }
1.127     raeburn  1774:                 $defcell{$item} .= '</span> ';
1.104     raeburn  1775:                 if ($option eq 'autolimit') {
1.127     raeburn  1776:                     $defcell{$item} .= $titles{'unlimited'};
1.104     raeburn  1777:                 }
1.101     raeburn  1778:             }
1.163     raeburn  1779:         } elsif ($context eq 'requestauthor') {
                   1780:             my $curroption;
                   1781:             if (ref($settings) eq 'HASH') {
1.172     raeburn  1782:                 $curroption = $settings->{'default'};
1.163     raeburn  1783:             }
                   1784:             if (!$curroption) {
                   1785:                 $curroption = 'norequest';
                   1786:             }
                   1787:             foreach my $option (@options) {
                   1788:                 my $val = $option;
                   1789:                 if ($option eq 'norequest') {
                   1790:                     $val = 0;
                   1791:                 }
                   1792:                 my $checked = '';
                   1793:                 if ($option eq $curroption) {
                   1794:                     $checked = ' checked="checked"';
                   1795:                 }
                   1796:                 $datatable .= '<span class="LC_nobreak"><label>'.
                   1797:                               '<input type="radio" name="authorreq_default"'.
                   1798:                               ' value="'.$val.'"'.$checked.' />'.
                   1799:                               $titles{$option}.'</label></span>&nbsp; ';
                   1800:             }
1.101     raeburn  1801:         } else {
                   1802:             my $checked = 'checked="checked" ';
                   1803:             if (ref($settings) eq 'HASH') {
                   1804:                 if (ref($settings->{$item}) eq 'HASH') {
                   1805:                     if ($settings->{$item}->{'default'} == 0) {
                   1806:                         $checked = '';
                   1807:                     } elsif ($settings->{$item}->{'default'} == 1) {
                   1808:                         $checked = 'checked="checked" ';
                   1809:                     }
1.78      raeburn  1810:                 }
1.72      raeburn  1811:             }
1.101     raeburn  1812:             $datatable .= '<span class="LC_nobreak"><label>'.
                   1813:                           '<input type="checkbox" name="'.$context.'_'.$item.
                   1814:                           '" value="default" '.$checked.'/>'.$titles{$item}.
                   1815:                           '</label></span>&nbsp; ';
                   1816:         }
                   1817:     }
                   1818:     if ($context eq 'requestcourses') {
                   1819:         $datatable .= '</tr><tr>';
                   1820:         foreach my $item (@usertools) {
1.106     raeburn  1821:             $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72      raeburn  1822:         }
1.101     raeburn  1823:         $datatable .= '</tr></table>';
1.72      raeburn  1824:     }
1.86      raeburn  1825:     $datatable .= '</td>';
1.163     raeburn  1826:     unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.197     raeburn  1827:         $datatable .= '<td class="LC_right_item">'.
                   1828:                       '<span class="LC_nobreak">'.&mt('Portfolio').':&nbsp;'.
1.86      raeburn  1829:                       '<input type="text" name="defaultquota" value="'.
1.197     raeburn  1830:                       $defaultquota.'" size="5" /></span>'.('&nbsp;' x2).
                   1831:                       '<span class="LC_nobreak">'.&mt('Authoring').':&nbsp;'.
                   1832:                       '<input type="text" name="authorquota" value="'.
                   1833:                       $authorquota.'" size="5" /></span></td>';
1.86      raeburn  1834:     }
                   1835:     $datatable .= '</tr>';
1.72      raeburn  1836:     $typecount ++;
                   1837:     $css_class = $typecount%2?' class="LC_odd_row"':'';
                   1838:     $datatable .= '<tr'.$css_class.'>'.
1.197     raeburn  1839:                   '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104     raeburn  1840:     if ($context eq 'requestcourses') {
1.109     raeburn  1841:         $datatable .= &mt('(overrides affiliation, if set)').
                   1842:                       '</td>'.
                   1843:                       '<td class="LC_left_item">'.
                   1844:                       '<table><tr>';
1.101     raeburn  1845:     } else {
1.109     raeburn  1846:         $datatable .= &mt('(overrides affiliation, if checked)').
                   1847:                       '</td>'.
                   1848:                       '<td class="LC_left_item" colspan="2">'.
                   1849:                       '<br />';
1.101     raeburn  1850:     }
                   1851:     my %advcell;
1.72      raeburn  1852:     foreach my $item (@usertools) {
1.101     raeburn  1853:         if ($context eq 'requestcourses') {
                   1854:             my ($curroption,$currlimit);
                   1855:             if (ref($settings) eq 'HASH') {
                   1856:                 if (ref($settings->{$item}) eq 'HASH') {
                   1857:                     $curroption = $settings->{$item}->{'_LC_adv'};
                   1858:                     if ($curroption =~ /^autolimit=(\d*)$/) {
                   1859:                         $currlimit = $1;
                   1860:                     }
                   1861:                 }
                   1862:             }
                   1863:             $datatable .= '<th>'.$titles{$item}.'</th>';
1.104     raeburn  1864:             my $checked = '';
                   1865:             if ($curroption eq '') {
                   1866:                 $checked = ' checked="checked"';
                   1867:             }
                   1868:             $advcell{$item} .= '<span class="LC_nobreak"><label>'.
                   1869:                                '<input type="radio" name="crsreq_'.$item.
                   1870:                                '__LC_adv" value=""'.$checked.' />'.
                   1871:                                &mt('No override set').'</label></span>&nbsp; ';
1.101     raeburn  1872:             foreach my $option (@options) {
                   1873:                 my $val = $option;
                   1874:                 if ($option eq 'norequest') {
                   1875:                     $val = 0;
                   1876:                 }
                   1877:                 if ($option eq 'validate') {
                   1878:                     my $canvalidate = 0;
                   1879:                     if (ref($validations{$item}) eq 'HASH') {
                   1880:                         if ($validations{$item}{'_LC_adv'}) {
                   1881:                             $canvalidate = 1;
                   1882:                         }
                   1883:                     }
                   1884:                     next if (!$canvalidate);
                   1885:                 }
                   1886:                 my $checked = '';
1.104     raeburn  1887:                 if ($val eq $curroption) {
1.101     raeburn  1888:                     $checked = ' checked="checked"';
                   1889:                 } elsif ($option eq 'autolimit') {
                   1890:                     if ($curroption =~ /^autolimit/) {
                   1891:                         $checked = ' checked="checked"';
                   1892:                     }
                   1893:                 }
                   1894:                 $advcell{$item} .= '<span class="LC_nobreak"><label>'.
                   1895:                                   '<input type="radio" name="crsreq_'.$item.
                   1896:                                   '__LC_adv" value="'.$val.'"'.$checked.' />'.
                   1897:                                   $titles{$option}.'</label>';
                   1898:                 if ($option eq 'autolimit') {
1.127     raeburn  1899:                     $advcell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
1.101     raeburn  1900:                                        $item.'_limit__LC_adv" size="1" '.
                   1901:                                        'value="'.$currlimit.'" />';
                   1902:                 }
1.127     raeburn  1903:                 $advcell{$item} .= '</span> ';
1.104     raeburn  1904:                 if ($option eq 'autolimit') {
1.127     raeburn  1905:                     $advcell{$item} .= $titles{'unlimited'};
1.104     raeburn  1906:                 }
1.101     raeburn  1907:             }
1.163     raeburn  1908:         } elsif ($context eq 'requestauthor') {
                   1909:             my $curroption;
                   1910:             if (ref($settings) eq 'HASH') {
                   1911:                 $curroption = $settings->{'_LC_adv'};
                   1912:             }
                   1913:             my $checked = '';
                   1914:             if ($curroption eq '') {
                   1915:                 $checked = ' checked="checked"';
                   1916:             }
                   1917:             $datatable .= '<span class="LC_nobreak"><label>'.
                   1918:                           '<input type="radio" name="authorreq__LC_adv"'.
                   1919:                           ' value=""'.$checked.' />'.
                   1920:                           &mt('No override set').'</label></span>&nbsp; ';
                   1921:             foreach my $option (@options) {
                   1922:                 my $val = $option;
                   1923:                 if ($option eq 'norequest') {
                   1924:                     $val = 0;
                   1925:                 }
                   1926:                 my $checked = '';
                   1927:                 if ($val eq $curroption) {
                   1928:                     $checked = ' checked="checked"';
                   1929:                 }
                   1930:                 $datatable .= '<span class="LC_nobreak"><label>'.
1.173     raeburn  1931:                               '<input type="radio" name="authorreq__LC_adv"'.
                   1932:                               ' value="'.$val.'"'.$checked.' />'.
1.163     raeburn  1933:                               $titles{$option}.'</label></span>&nbsp; ';
                   1934:             }
1.101     raeburn  1935:         } else {
                   1936:             my $checked = 'checked="checked" ';
                   1937:             if (ref($settings) eq 'HASH') {
                   1938:                 if (ref($settings->{$item}) eq 'HASH') {
                   1939:                     if ($settings->{$item}->{'_LC_adv'} == 0) {
                   1940:                         $checked = '';
                   1941:                     } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
                   1942:                         $checked = 'checked="checked" ';
                   1943:                     }
1.79      raeburn  1944:                 }
1.72      raeburn  1945:             }
1.101     raeburn  1946:             $datatable .= '<span class="LC_nobreak"><label>'.
                   1947:                           '<input type="checkbox" name="'.$context.'_'.$item.
                   1948:                           '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
                   1949:                           '</label></span>&nbsp; ';
                   1950:         }
                   1951:     }
                   1952:     if ($context eq 'requestcourses') {
                   1953:         $datatable .= '</tr><tr>';
                   1954:         foreach my $item (@usertools) {
1.106     raeburn  1955:             $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72      raeburn  1956:         }
1.101     raeburn  1957:         $datatable .= '</tr></table>';
1.72      raeburn  1958:     }
1.98      raeburn  1959:     $datatable .= '</td></tr>';
1.30      raeburn  1960:     $$rowtotal += $typecount;
1.3       raeburn  1961:     return $datatable;
                   1962: }
                   1963: 
1.163     raeburn  1964: sub print_requestmail {
                   1965:     my ($dom,$action,$settings,$rowtotal) = @_;
1.191     raeburn  1966:     my ($now,$datatable,%currapp,$rows);
1.102     raeburn  1967:     $now = time;
                   1968:     if (ref($settings) eq 'HASH') {
                   1969:         if (ref($settings->{'notify'}) eq 'HASH') {
                   1970:             if ($settings->{'notify'}{'approval'} ne '') {
1.191     raeburn  1971:                map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102     raeburn  1972:             }
                   1973:         }
                   1974:     }
1.191     raeburn  1975:     my $numinrow = 2;
1.102     raeburn  1976:     my $css_class = 'class="LC_odd_row"';
1.163     raeburn  1977:     my $text;
                   1978:     if ($action eq 'requestcourses') {
                   1979:         $text = &mt('Receive notification of course requests requiring approval');
                   1980:     } else {
                   1981:         $text = &mt('Receive notification of authoring space requests requiring approval')
                   1982:     }
                   1983:     $datatable = '<tr '.$css_class.'>'.
                   1984:                  ' <td>'.$text.'</td>'.
1.102     raeburn  1985:                  ' <td class="LC_left_item">';
1.191     raeburn  1986:     my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
                   1987:                                                  'reqapprovalnotify',%currapp);
                   1988:     if ($numdc > 0) {
                   1989:         $datatable .= $table;
1.102     raeburn  1990:     } else {
                   1991:         $datatable .= &mt('There are no active Domain Coordinators');
                   1992:     }
                   1993:     $datatable .='</td></tr>';
                   1994:     $$rowtotal += $rows;
                   1995:     return $datatable;
                   1996: }
                   1997: 
1.3       raeburn  1998: sub print_autoenroll {
1.30      raeburn  1999:     my ($dom,$settings,$rowtotal) = @_;
1.3       raeburn  2000:     my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.129     raeburn  2001:     my ($defdom,$runon,$runoff,$coownerson,$coownersoff);
1.3       raeburn  2002:     if (ref($settings) eq 'HASH') {
                   2003:         if (exists($settings->{'run'})) {
                   2004:             if ($settings->{'run'} eq '0') {
                   2005:                 $runoff = ' checked="checked" ';
                   2006:                 $runon = ' ';
                   2007:             } else {
                   2008:                 $runon = ' checked="checked" ';
                   2009:                 $runoff = ' ';
                   2010:             }
                   2011:         } else {
                   2012:             if ($autorun) {
                   2013:                 $runon = ' checked="checked" ';
                   2014:                 $runoff = ' ';
                   2015:             } else {
                   2016:                 $runoff = ' checked="checked" ';
                   2017:                 $runon = ' ';
                   2018:             }
                   2019:         }
1.129     raeburn  2020:         if (exists($settings->{'co-owners'})) {
                   2021:             if ($settings->{'co-owners'} eq '0') {
                   2022:                 $coownersoff = ' checked="checked" ';
                   2023:                 $coownerson = ' ';
                   2024:             } else {
                   2025:                 $coownerson = ' checked="checked" ';
                   2026:                 $coownersoff = ' ';
                   2027:             }
                   2028:         } else {
                   2029:             $coownersoff = ' checked="checked" ';
                   2030:             $coownerson = ' ';
                   2031:         }
1.3       raeburn  2032:         if (exists($settings->{'sender_domain'})) {
                   2033:             $defdom = $settings->{'sender_domain'};
                   2034:         }
1.14      raeburn  2035:     } else {
                   2036:         if ($autorun) {
                   2037:             $runon = ' checked="checked" ';
                   2038:             $runoff = ' ';
                   2039:         } else {
                   2040:             $runoff = ' checked="checked" ';
                   2041:             $runon = ' ';
                   2042:         }
1.3       raeburn  2043:     }
                   2044:     my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39      raeburn  2045:     my $notif_sender;
                   2046:     if (ref($settings) eq 'HASH') {
                   2047:         $notif_sender = $settings->{'sender_uname'};
                   2048:     }
1.3       raeburn  2049:     my $datatable='<tr class="LC_odd_row">'.
                   2050:                   '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8       raeburn  2051:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3       raeburn  2052:                   '<input type="radio" name="autoenroll_run"'.
1.8       raeburn  2053:                   $runon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   2054:                   '<label><input type="radio" name="autoenroll_run"'.
1.14      raeburn  2055:                   $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3       raeburn  2056:                   '</tr><tr>'.
                   2057:                   '<td>'.&mt('Notification messages - sender').
1.8       raeburn  2058:                   '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3       raeburn  2059:                   &mt('username').':&nbsp;'.
                   2060:                   '<input type="text" name="sender_uname" value="'.
1.39      raeburn  2061:                   $notif_sender.'" size="10" />&nbsp;&nbsp;'.&mt('domain').
1.129     raeburn  2062:                   ':&nbsp;'.$domform.'</span></td></tr>'.
                   2063:                   '<tr class="LC_odd_row">'.
                   2064:                   '<td>'.&mt('Automatically assign co-ownership').'</td>'.
                   2065:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   2066:                   '<input type="radio" name="autoassign_coowners"'.
                   2067:                   $coownerson.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   2068:                   '<label><input type="radio" name="autoassign_coowners"'.
                   2069:                   $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
                   2070:                   '</tr>';
                   2071:     $$rowtotal += 3;
1.3       raeburn  2072:     return $datatable;
                   2073: }
                   2074: 
                   2075: sub print_autoupdate {
1.30      raeburn  2076:     my ($position,$dom,$settings,$rowtotal) = @_;
1.3       raeburn  2077:     my $datatable;
                   2078:     if ($position eq 'top') {
                   2079:         my $updateon = ' ';
                   2080:         my $updateoff = ' checked="checked" ';
                   2081:         my $classlistson = ' ';
                   2082:         my $classlistsoff = ' checked="checked" ';
                   2083:         if (ref($settings) eq 'HASH') {
                   2084:             if ($settings->{'run'} eq '1') {
                   2085:                 $updateon = $updateoff;
                   2086:                 $updateoff = ' ';
                   2087:             }
                   2088:             if ($settings->{'classlists'} eq '1') {
                   2089:                 $classlistson = $classlistsoff;
                   2090:                 $classlistsoff = ' ';
                   2091:             }
                   2092:         }
                   2093:         my %title = (
                   2094:                    run => 'Auto-update active?',
                   2095:                    classlists => 'Update information in classlists?',
                   2096:                     );
                   2097:         $datatable = '<tr class="LC_odd_row">'. 
                   2098:                   '<td>'.&mt($title{'run'}).'</td>'.
1.8       raeburn  2099:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3       raeburn  2100:                   '<input type="radio" name="autoupdate_run"'.
1.8       raeburn  2101:                   $updateon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   2102:                   '<label><input type="radio" name="autoupdate_run"'.
                   2103:                   $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3       raeburn  2104:                   '</tr><tr>'.
                   2105:                   '<td>'.&mt($title{'classlists'}).'</td>'.
1.8       raeburn  2106:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
                   2107:                   '<label><input type="radio" name="classlists"'.
                   2108:                   $classlistson.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   2109:                   '<label><input type="radio" name="classlists"'.
                   2110:                   $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3       raeburn  2111:                   '</tr>';
1.30      raeburn  2112:         $$rowtotal += 2;
1.131     raeburn  2113:     } elsif ($position eq 'middle') {
                   2114:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   2115:         my $numinrow = 3;
                   2116:         my $locknamesettings;
                   2117:         $datatable .= &insttypes_row($settings,$types,$usertypes,
                   2118:                                      $dom,$numinrow,$othertitle,
                   2119:                                     'lockablenames');
                   2120:         $$rowtotal ++;
1.3       raeburn  2121:     } else {
1.44      raeburn  2122:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132     raeburn  2123:         my @fields = ('lastname','firstname','middlename','generation',
1.20      raeburn  2124:                       'permanentemail','id');
1.33      raeburn  2125:         my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3       raeburn  2126:         my $numrows = 0;
1.26      raeburn  2127:         if (ref($types) eq 'ARRAY') {
                   2128:             if (@{$types} > 0) {
                   2129:                 $datatable = 
                   2130:                     &usertype_update_row($settings,$usertypes,\%fieldtitles,
                   2131:                                          \@fields,$types,\$numrows);
1.30      raeburn  2132:                     $$rowtotal += @{$types}; 
1.26      raeburn  2133:             }
1.3       raeburn  2134:         }
                   2135:         $datatable .= 
                   2136:             &usertype_update_row($settings,{'default' => $othertitle},
                   2137:                                  \%fieldtitles,\@fields,['default'],
                   2138:                                  \$numrows);
1.30      raeburn  2139:         $$rowtotal ++;     
1.3       raeburn  2140:     }
                   2141:     return $datatable;
                   2142: }
                   2143: 
1.125     raeburn  2144: sub print_autocreate {
                   2145:     my ($dom,$settings,$rowtotal) = @_;
1.191     raeburn  2146:     my (%createon,%createoff,%currhash);
1.125     raeburn  2147:     my @types = ('xml','req');
                   2148:     if (ref($settings) eq 'HASH') {
                   2149:         foreach my $item (@types) {
                   2150:             $createoff{$item} = ' checked="checked" ';
                   2151:             $createon{$item} = ' ';
                   2152:             if (exists($settings->{$item})) {
                   2153:                 if ($settings->{$item}) {
                   2154:                     $createon{$item} = ' checked="checked" ';
                   2155:                     $createoff{$item} = ' ';
                   2156:                 }
                   2157:             }
                   2158:         }
1.191     raeburn  2159:         if ($settings->{'xmldc'} ne '') { 
                   2160:             $currhash{$settings->{'xmldc'}} = 1;
                   2161:         }
1.125     raeburn  2162:     } else {
                   2163:         foreach my $item (@types) {
                   2164:             $createoff{$item} = ' checked="checked" ';
                   2165:             $createon{$item} = ' ';
                   2166:         }
                   2167:     }
                   2168:     $$rowtotal += 2;
1.191     raeburn  2169:     my $numinrow = 2;
1.125     raeburn  2170:     my $datatable='<tr class="LC_odd_row">'.
                   2171:                   '<td>'.&mt('Create pending official courses from XML files').'</td>'.
                   2172:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   2173:                   '<input type="radio" name="autocreate_xml"'.
                   2174:                   $createon{'xml'}.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   2175:                   '<label><input type="radio" name="autocreate_xml"'.
1.143     raeburn  2176:                   $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
                   2177:                   '</td></tr><tr>'.
                   2178:                   '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
                   2179:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   2180:                   '<input type="radio" name="autocreate_req"'.
                   2181:                   $createon{'req'}.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   2182:                   '<label><input type="radio" name="autocreate_req"'.
                   2183:                   $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.191     raeburn  2184:     my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
                   2185:                                                    'autocreate_xmldc',%currhash);
1.125     raeburn  2186:     if ($numdc > 1) {
1.143     raeburn  2187:         $datatable .= '</td></tr><tr class="LC_odd_row"><td>'.
                   2188:                       &mt('Course creation processed as: (choose Dom. Coord.)').
                   2189:                       '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.125     raeburn  2190:     } else {
1.143     raeburn  2191:         $datatable .= $dctable.'</td></tr>';
1.125     raeburn  2192:     }
1.191     raeburn  2193:     $$rowtotal += $rows;
1.125     raeburn  2194:     return $datatable;
                   2195: }
                   2196: 
1.23      raeburn  2197: sub print_directorysrch {
1.30      raeburn  2198:     my ($dom,$settings,$rowtotal) = @_;
1.23      raeburn  2199:     my $srchon = ' ';
                   2200:     my $srchoff = ' checked="checked" ';
1.25      raeburn  2201:     my ($exacton,$containson,$beginson);
1.24      raeburn  2202:     my $localon = ' ';
                   2203:     my $localoff = ' checked="checked" ';
1.23      raeburn  2204:     if (ref($settings) eq 'HASH') {
                   2205:         if ($settings->{'available'} eq '1') {
                   2206:             $srchon = $srchoff;
                   2207:             $srchoff = ' ';
                   2208:         }
1.24      raeburn  2209:         if ($settings->{'localonly'} eq '1') {
                   2210:             $localon = $localoff;
                   2211:             $localoff = ' ';
                   2212:         }
1.25      raeburn  2213:         if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
                   2214:             foreach my $type (@{$settings->{'searchtypes'}}) {
                   2215:                 if ($type eq 'exact') {
                   2216:                     $exacton = ' checked="checked" ';
                   2217:                 } elsif ($type eq 'contains') {
                   2218:                     $containson = ' checked="checked" ';
                   2219:                 } elsif ($type eq 'begins') {
                   2220:                     $beginson = ' checked="checked" ';
                   2221:                 }
                   2222:             }
                   2223:         } else {
                   2224:             if ($settings->{'searchtypes'} eq 'exact') {
                   2225:                 $exacton = ' checked="checked" ';
                   2226:             } elsif ($settings->{'searchtypes'} eq 'contains') {
                   2227:                 $containson = ' checked="checked" ';
                   2228:             } elsif ($settings->{'searchtypes'} eq 'specify') {
                   2229:                 $exacton = ' checked="checked" ';
                   2230:                 $containson = ' checked="checked" ';
                   2231:             }
1.23      raeburn  2232:         }
                   2233:     }
                   2234:     my ($searchtitles,$titleorder) = &sorted_searchtitles();
1.45      raeburn  2235:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23      raeburn  2236: 
                   2237:     my $numinrow = 4;
1.26      raeburn  2238:     my $cansrchrow = 0;
1.23      raeburn  2239:     my $datatable='<tr class="LC_odd_row">'.
1.30      raeburn  2240:                   '<td colspan="2"><span class ="LC_nobreak">'.&mt('Directory search available?').'</span></td>'.
1.23      raeburn  2241:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   2242:                   '<input type="radio" name="dirsrch_available"'.
                   2243:                   $srchon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   2244:                   '<label><input type="radio" name="dirsrch_available"'.
                   2245:                   $srchoff.' value="0" />'.&mt('No').'</label></span></td>'.
                   2246:                   '</tr><tr>'.
1.30      raeburn  2247:                   '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search?').'</span></td>'.
1.24      raeburn  2248:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   2249:                   '<input type="radio" name="dirsrch_localonly"'.
                   2250:                   $localoff.' value="0" />'.&mt('Yes').'</label>&nbsp;'.
                   2251:                   '<label><input type="radio" name="dirsrch_localonly"'.
                   2252:                   $localon.' value="1" />'.&mt('No').'</label></span></td>'.
1.25      raeburn  2253:                   '</tr>';
1.30      raeburn  2254:     $$rowtotal += 2;
1.26      raeburn  2255:     if (ref($usertypes) eq 'HASH') {
                   2256:         if (keys(%{$usertypes}) > 0) {
1.93      raeburn  2257:             $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
                   2258:                                          $numinrow,$othertitle,'cansearch');
1.26      raeburn  2259:             $cansrchrow = 1;
                   2260:         }
                   2261:     }
                   2262:     if ($cansrchrow) {
1.30      raeburn  2263:         $$rowtotal ++;
1.26      raeburn  2264:         $datatable .= '<tr>';
                   2265:     } else {
                   2266:         $datatable .= '<tr class="LC_odd_row">';
                   2267:     }
1.30      raeburn  2268:     $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
                   2269:                   '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
1.25      raeburn  2270:     foreach my $title (@{$titleorder}) {
                   2271:         if (defined($searchtitles->{$title})) {
                   2272:             my $check = ' ';
1.93      raeburn  2273:             if (ref($settings) eq 'HASH') {
1.39      raeburn  2274:                 if (ref($settings->{'searchby'}) eq 'ARRAY') {
                   2275:                     if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
                   2276:                         $check = ' checked="checked" ';
                   2277:                     }
1.25      raeburn  2278:                 }
                   2279:             }
                   2280:             $datatable .= '<td class="LC_left_item">'.
                   2281:                           '<span class="LC_nobreak"><label>'.
                   2282:                           '<input type="checkbox" name="searchby" '.
                   2283:                           'value="'.$title.'"'.$check.'/>'.
                   2284:                           $searchtitles->{$title}.'</label></span></td>';
                   2285:         }
                   2286:     }
1.26      raeburn  2287:     $datatable .= '</tr></table></td></tr>';
1.30      raeburn  2288:     $$rowtotal ++;
1.26      raeburn  2289:     if ($cansrchrow) {
                   2290:         $datatable .= '<tr class="LC_odd_row">';
                   2291:     } else {
                   2292:         $datatable .= '<tr>';
                   2293:     }
1.30      raeburn  2294:     $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.   
1.26      raeburn  2295:                   '<td class="LC_left_item" colspan="2">'.
1.25      raeburn  2296:                   '<span class="LC_nobreak"><label>'.
                   2297:                   '<input type="checkbox" name="searchtypes" '.
                   2298:                   $exacton.' value="exact" />'.&mt('Exact match').
                   2299:                   '</label>&nbsp;'.
                   2300:                   '<label><input type="checkbox" name="searchtypes" '.
                   2301:                   $beginson.' value="begins" />'.&mt('Begins with').
                   2302:                   '</label>&nbsp;'.
                   2303:                   '<label><input type="checkbox" name="searchtypes" '.
                   2304:                   $containson.' value="contains" />'.&mt('Contains').
                   2305:                   '</label></span></td></tr>';
1.30      raeburn  2306:     $$rowtotal ++;
1.25      raeburn  2307:     return $datatable;
                   2308: }
                   2309: 
1.28      raeburn  2310: sub print_contacts {
1.30      raeburn  2311:     my ($dom,$settings,$rowtotal) = @_;
1.28      raeburn  2312:     my $datatable;
                   2313:     my @contacts = ('adminemail','supportemail');
1.134     raeburn  2314:     my (%checked,%to,%otheremails,%bccemails);
1.102     raeburn  2315:     my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail',
1.203     raeburn  2316:                     'requestsmail','updatesmail','idconflictsmail');
1.28      raeburn  2317:     foreach my $type (@mailings) {
                   2318:         $otheremails{$type} = '';
                   2319:     }
1.134     raeburn  2320:     $bccemails{'helpdeskmail'} = '';
1.28      raeburn  2321:     if (ref($settings) eq 'HASH') {
                   2322:         foreach my $item (@contacts) {
                   2323:             if (exists($settings->{$item})) {
                   2324:                 $to{$item} = $settings->{$item};
                   2325:             }
                   2326:         }
                   2327:         foreach my $type (@mailings) {
                   2328:             if (exists($settings->{$type})) {
                   2329:                 if (ref($settings->{$type}) eq 'HASH') {
                   2330:                     foreach my $item (@contacts) {
                   2331:                         if ($settings->{$type}{$item}) {
                   2332:                             $checked{$type}{$item} = ' checked="checked" ';
                   2333:                         }
                   2334:                     }
                   2335:                     $otheremails{$type} = $settings->{$type}{'others'};
1.134     raeburn  2336:                     if ($type eq 'helpdeskmail') {
                   2337:                         $bccemails{$type} = $settings->{$type}{'bcc'};
                   2338:                     }
1.28      raeburn  2339:                 }
1.89      raeburn  2340:             } elsif ($type eq 'lonstatusmail') {
                   2341:                 $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.28      raeburn  2342:             }
                   2343:         }
                   2344:     } else {
                   2345:         $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
                   2346:         $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
                   2347:         $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
                   2348:         $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.89      raeburn  2349:         $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
                   2350:         $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" '; 
1.102     raeburn  2351:         $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
1.190     raeburn  2352:         $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
1.203     raeburn  2353:         $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.28      raeburn  2354:     }
                   2355:     my ($titles,$short_titles) = &contact_titles();
                   2356:     my $rownum = 0;
                   2357:     my $css_class;
                   2358:     foreach my $item (@contacts) {
1.69      raeburn  2359:         $css_class = $rownum%2?' class="LC_odd_row"':'';
1.30      raeburn  2360:         $datatable .= '<tr'.$css_class.'>'. 
                   2361:                   '<td><span class="LC_nobreak">'.$titles->{$item}.
                   2362:                   '</span></td><td class="LC_right_item">'.
1.28      raeburn  2363:                   '<input type="text" name="'.$item.'" value="'.
                   2364:                   $to{$item}.'" /></td></tr>';
1.203     raeburn  2365:         $rownum ++;
1.28      raeburn  2366:     }
                   2367:     foreach my $type (@mailings) {
1.69      raeburn  2368:         $css_class = $rownum%2?' class="LC_odd_row"':'';
1.28      raeburn  2369:         $datatable .= '<tr'.$css_class.'>'.
1.30      raeburn  2370:                       '<td><span class="LC_nobreak">'.
                   2371:                       $titles->{$type}.': </span></td>'.
1.28      raeburn  2372:                       '<td class="LC_left_item">'.
                   2373:                       '<span class="LC_nobreak">';
                   2374:         foreach my $item (@contacts) {
                   2375:             $datatable .= '<label>'.
                   2376:                           '<input type="checkbox" name="'.$type.'"'.
                   2377:                           $checked{$type}{$item}.
                   2378:                           ' value="'.$item.'" />'.$short_titles->{$item}.
                   2379:                           '</label>&nbsp;';
                   2380:         }
                   2381:         $datatable .= '</span><br />'.&mt('Others').':&nbsp;&nbsp;'.
                   2382:                       '<input type="text" name="'.$type.'_others" '.
1.134     raeburn  2383:                       'value="'.$otheremails{$type}.'"  />';
                   2384:         if ($type eq 'helpdeskmail') {
1.136     raeburn  2385:             $datatable .= '<br />'.&mt('Bcc:').('&nbsp;'x6).
1.134     raeburn  2386:                           '<input type="text" name="'.$type.'_bcc" '.
                   2387:                           'value="'.$bccemails{$type}.'"  />';
                   2388:         }
                   2389:         $datatable .= '</td></tr>'."\n";
1.203     raeburn  2390:         $rownum ++;
1.28      raeburn  2391:     }
1.203     raeburn  2392:     my %choices;
                   2393:     $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',
                   2394:                                    &Apache::loncommon::modal_link('http://loncapa.org/core.html',
                   2395:                                    &mt('LON-CAPA core group - MSU'),600,500));
                   2396:     $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
                   2397:                                     &Apache::loncommon::modal_link('http://loncapa.org/core.html',
                   2398:                                     &mt('LON-CAPA core group - MSU'),600,500));
                   2399:     my @toggles = ('reporterrors','reportupdates');
                   2400:     my %defaultchecked = ('reporterrors'  => 'on',
                   2401:                           'reportupdates' => 'on');
                   2402:     (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
                   2403:                                                \%choices,$rownum);
                   2404:     $datatable .= $reports;
1.30      raeburn  2405:     $$rowtotal += $rownum;
1.28      raeburn  2406:     return $datatable;
                   2407: }
                   2408: 
1.118     jms      2409: sub print_helpsettings {
1.168     raeburn  2410:     my ($dom,$confname,$settings,$rowtotal) = @_;
                   2411:     my ($datatable,$itemcount);
1.166     raeburn  2412:     $itemcount = 1;
1.168     raeburn  2413:     my (%choices,%defaultchecked,@toggles);
                   2414:     $choices{'submitbugs'} = &mt('Display link to: [_1]?',
                   2415:                                  &Apache::loncommon::modal_link('http://bugs.loncapa.org',
                   2416:                                  &mt('LON-CAPA bug tracker'),600,500));
                   2417:     %defaultchecked = ('submitbugs' => 'on');
                   2418:     @toggles = ('submitbugs',);
1.166     raeburn  2419: 
1.168     raeburn  2420:     ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
                   2421:                                                  \%choices,$itemcount);
1.166     raeburn  2422:     return $datatable;
1.121     raeburn  2423: }
                   2424: 
                   2425: sub radiobutton_prefs {
1.192     raeburn  2426:     my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
                   2427:         $additional) = @_;
1.121     raeburn  2428:     return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
                   2429:                    (ref($choices) eq 'HASH'));
                   2430: 
1.170     raeburn  2431:     my (%checkedon,%checkedoff,$datatable,$css_class);
1.121     raeburn  2432: 
                   2433:     foreach my $item (@{$toggles}) {
                   2434:         if ($defaultchecked->{$item} eq 'on') {
1.118     jms      2435:             $checkedon{$item} = ' checked="checked" ';
                   2436:             $checkedoff{$item} = ' ';
1.121     raeburn  2437:         } elsif ($defaultchecked->{$item} eq 'off') {
1.118     jms      2438:             $checkedoff{$item} = ' checked="checked" ';
                   2439:             $checkedon{$item} = ' ';
                   2440:         }
                   2441:     }
                   2442:     if (ref($settings) eq 'HASH') {
1.121     raeburn  2443:         foreach my $item (@{$toggles}) {
1.118     jms      2444:             if ($settings->{$item} eq '1') {
                   2445:                 $checkedon{$item} =  ' checked="checked" ';
                   2446:                 $checkedoff{$item} = ' ';
                   2447:             } elsif ($settings->{$item} eq '0') {
                   2448:                 $checkedoff{$item} =  ' checked="checked" ';
                   2449:                 $checkedon{$item} = ' ';
                   2450:             }
                   2451:         }
1.121     raeburn  2452:     }
1.192     raeburn  2453:     if ($onclick) {
                   2454:         $onclick = ' onclick="'.$onclick.'"';
                   2455:     }
1.121     raeburn  2456:     foreach my $item (@{$toggles}) {
1.118     jms      2457:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121     raeburn  2458:         $datatable .=
1.192     raeburn  2459:             '<tr'.$css_class.'><td valign="top">'.
                   2460:             '<span class="LC_nobreak">'.$choices->{$item}.
1.118     jms      2461:             '</span></td>'.
                   2462:             '<td class="LC_right_item"><span class="LC_nobreak">'.
                   2463:             '<label><input type="radio" name="'.
1.192     raeburn  2464:             $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118     jms      2465:             '</label>&nbsp;<label><input type="radio" name="'.$item.'" '.
1.192     raeburn  2466:             $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
                   2467:             '</span>'.$additional.
                   2468:             '</td>'.
1.118     jms      2469:             '</tr>';
                   2470:         $itemcount ++;
1.121     raeburn  2471:     }
                   2472:     return ($datatable,$itemcount);
                   2473: }
                   2474: 
                   2475: sub print_coursedefaults {
1.139     raeburn  2476:     my ($position,$dom,$settings,$rowtotal) = @_;
1.192     raeburn  2477:     my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121     raeburn  2478:     my $itemcount = 1;
1.192     raeburn  2479:     my %choices =  &Apache::lonlocal::texthash (
                   2480:         canuse_pdfforms      => 'Course/Community users can create/upload PDF forms',
1.198     raeburn  2481:         uploadquota          => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.192     raeburn  2482:         anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
                   2483:         coursecredits        => 'Credits can be specified for courses',
                   2484:     );
1.198     raeburn  2485:     my %staticdefaults = (
                   2486:                            anonsurvey_threshold => 10,
                   2487:                            uploadquota          => 500,
                   2488:                          );
1.139     raeburn  2489:     if ($position eq 'top') {
                   2490:         %defaultchecked = ('canuse_pdfforms' => 'off');
1.192     raeburn  2491:         @toggles = ('canuse_pdfforms');
1.139     raeburn  2492:         ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.121     raeburn  2493:                                                  \%choices,$itemcount);
1.139     raeburn  2494:     } else {
                   2495:         $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.198     raeburn  2496:         my ($currdefresponder,$def_official_credits,$def_unofficial_credits,%curruploadquota);
1.192     raeburn  2497:         my $currusecredits = 0;
1.198     raeburn  2498:         my @types = ('official','unofficial','community');
1.139     raeburn  2499:         if (ref($settings) eq 'HASH') {
                   2500:             $currdefresponder = $settings->{'anonsurvey_threshold'};
1.198     raeburn  2501:             if (ref($settings->{'uploadquota'}) eq 'HASH') {
                   2502:                 foreach my $type (keys(%{$settings->{'uploadquota'}})) {
                   2503:                     $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
                   2504:                 }
                   2505:             }
1.192     raeburn  2506:             if (ref($settings->{'coursecredits'}) eq 'HASH') {
                   2507:                 $def_official_credits = $settings->{'coursecredits'}->{'official'};
                   2508:                 $def_unofficial_credits = $settings->{'coursecredits'}->{'unofficial'};
                   2509:                 if (($def_official_credits ne '') || ($def_unofficial_credits ne '')) {
                   2510:                     $currusecredits = 1;
                   2511:                 }
                   2512:             }
1.139     raeburn  2513:         }
                   2514:         if (!$currdefresponder) {
1.198     raeburn  2515:             $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139     raeburn  2516:         } elsif ($currdefresponder < 1) {
                   2517:             $currdefresponder = 1;
                   2518:         }
1.198     raeburn  2519:         foreach my $type (@types) {
                   2520:             if ($curruploadquota{$type} eq '') {
                   2521:                 $curruploadquota{$type} = $staticdefaults{'uploadquota'};
                   2522:             }
                   2523:         }
1.139     raeburn  2524:         $datatable .=
1.192     raeburn  2525:                 '<tr'.$css_class.'><td><span class="LC_nobreak">'.
                   2526:                 $choices{'anonsurvey_threshold'}.
1.139     raeburn  2527:                 '</span></td>'.
                   2528:                 '<td class="LC_right_item"><span class="LC_nobreak">'.
                   2529:                 '<input type="text" name="anonsurvey_threshold"'.
                   2530:                 ' value="'.$currdefresponder.'" size="5" /></span>'.
1.198     raeburn  2531:                 '</td></tr>'."\n".
                   2532:                 '<tr><td><span class="LC_nobreak">'.
                   2533:                 $choices{'uploadquota'}.
                   2534:                 '</span></td>'.
                   2535:                 '<td align="right" class="LC_right_item">'.
                   2536:                 '<table><tr>';
                   2537:         foreach my $type (@types) {
                   2538:             $datatable .= '<td align="center">'.&mt($type).'<br />'.
                   2539:                            '<input type="text" name="uploadquota_'.$type.'"'.
                   2540:                            ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
                   2541:         }
                   2542:         $datatable .= '</tr></table></td></tr>'."\n";
                   2543:         $itemcount += 2;
1.192     raeburn  2544:         my $onclick = 'toggleCredits(this.form);';
                   2545:         my $display = 'none';  
                   2546:         if ($currusecredits) {
                   2547:             $display = 'block';
                   2548:         }
                   2549:         my $additional = '<div id="credits" style="display: '.$display.'">'.
                   2550:                          '<span class="LC_nobreak">'.
                   2551:                          &mt('Default credits for official courses [_1]',
                   2552:                          '<input type="text" name="official_credits" value="'.
                   2553:                          $def_official_credits.'" size="3" />').
                   2554:                          '</span><br />'.
                   2555:                          '<span class="LC_nobreak">'.
                   2556:                          &mt('Default credits for unofficial courses [_1]',
                   2557:                          '<input type="text" name="unofficial_credits" value="'.
                   2558:                          $def_unofficial_credits.'" size="3" />').
                   2559:                          '</span></div>'."\n";
                   2560:         %defaultchecked = ('coursecredits' => 'off');
                   2561:         @toggles = ('coursecredits');
                   2562:         my $current = {
                   2563:                         'coursecredits' => $currusecredits,
                   2564:                       };
                   2565:         (my $table,$itemcount) =
                   2566:             &radiobutton_prefs($current,\@toggles,\%defaultchecked,
                   2567:                                \%choices,$itemcount,$onclick,$additional);
                   2568:         $datatable .= $table;
1.139     raeburn  2569:     }
1.192     raeburn  2570:     $$rowtotal += $itemcount;
1.121     raeburn  2571:     return $datatable;
1.118     jms      2572: }
                   2573: 
1.137     raeburn  2574: sub print_usersessions {
                   2575:     my ($position,$dom,$settings,$rowtotal) = @_;
                   2576:     my ($css_class,$datatable,%checked,%choices);
1.140     raeburn  2577:     my (%by_ip,%by_location,@intdoms);
                   2578:     &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145     raeburn  2579: 
                   2580:     my @alldoms = &Apache::lonnet::all_domains();
1.152     raeburn  2581:     my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149     raeburn  2582:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152     raeburn  2583:     my %altids = &id_for_thisdom(%servers);
1.145     raeburn  2584:     my $itemcount = 1;
                   2585:     if ($position eq 'top') {
1.152     raeburn  2586:         if (keys(%serverhomes) > 1) {
1.145     raeburn  2587:             my %spareid = &current_offloads_to($dom,$settings,\%servers);
1.152     raeburn  2588:             $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$rowtotal);
1.145     raeburn  2589:         } else {
1.140     raeburn  2590:             $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150     raeburn  2591:                           &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140     raeburn  2592:         }
1.137     raeburn  2593:     } else {
1.145     raeburn  2594:         if (keys(%by_location) == 0) {
                   2595:             $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150     raeburn  2596:                           &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145     raeburn  2597:         } else {
                   2598:             my %lt = &usersession_titles();
                   2599:             my $numinrow = 5;
                   2600:             my $prefix;
                   2601:             my @types;
                   2602:             if ($position eq 'bottom') {
                   2603:                 $prefix = 'remote';
                   2604:                 @types = ('version','excludedomain','includedomain');
                   2605:             } else {
                   2606:                 $prefix = 'hosted';
                   2607:                 @types = ('excludedomain','includedomain');
                   2608:             }
                   2609:             my (%current,%checkedon,%checkedoff);
                   2610:             my @lcversions = &Apache::lonnet::all_loncaparevs();
                   2611:             my @locations = sort(keys(%by_location));
                   2612:             foreach my $type (@types) {
                   2613:                 $checkedon{$type} = '';
                   2614:                 $checkedoff{$type} = ' checked="checked"';
                   2615:             }
                   2616:             if (ref($settings) eq 'HASH') {
                   2617:                 if (ref($settings->{$prefix}) eq 'HASH') {
                   2618:                     foreach my $key (keys(%{$settings->{$prefix}})) {
                   2619:                         $current{$key} = $settings->{$prefix}{$key};
                   2620:                         if ($key eq 'version') {
                   2621:                             if ($current{$key} ne '') {
                   2622:                                 $checkedon{$key} = ' checked="checked"';
                   2623:                                 $checkedoff{$key} = '';
                   2624:                             }
                   2625:                         } elsif (ref($current{$key}) eq 'ARRAY') {
                   2626:                             $checkedon{$key} = ' checked="checked"';
                   2627:                             $checkedoff{$key} = '';
                   2628:                         }
1.137     raeburn  2629:                     }
                   2630:                 }
                   2631:             }
1.145     raeburn  2632:             foreach my $type (@types) {
                   2633:                 next if ($type ne 'version' && !@locations);
                   2634:                 $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   2635:                 $datatable .= '<tr'.$css_class.'>
                   2636:                                <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
                   2637:                                <span class="LC_nobreak">&nbsp;
                   2638:                                <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>&nbsp;
                   2639:                                <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
                   2640:                 if ($type eq 'version') {
                   2641:                     my $selector = '<select name="'.$prefix.'_version">';
                   2642:                     foreach my $version (@lcversions) {
                   2643:                         my $selected = '';
                   2644:                         if ($current{'version'} eq $version) {
                   2645:                             $selected = ' selected="selected"';
                   2646:                         }
                   2647:                         $selector .= ' <option value="'.$version.'"'.
                   2648:                                      $selected.'>'.$version.'</option>';
                   2649:                     }
                   2650:                     $selector .= '</select> ';
                   2651:                     $datatable .= &mt('remote server must be version: [_1] or later',$selector);
                   2652:                 } else {
                   2653:                     $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
                   2654:                                  'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
                   2655:                                  ' />'.('&nbsp;'x2).
                   2656:                                  '<input type="button" value="'.&mt('uncheck all').'" '.
                   2657:                                  'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
                   2658:                                  "\n".
                   2659:                                  '</div><div><table>';
                   2660:                     my $rem;
                   2661:                     for (my $i=0; $i<@locations; $i++) {
                   2662:                         my ($showloc,$value,$checkedtype);
                   2663:                         if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
                   2664:                             my $ip = $by_location{$locations[$i]}->[0];
                   2665:                             if (ref($by_ip{$ip}) eq 'ARRAY') {
                   2666:                                  $value = join(':',@{$by_ip{$ip}});
                   2667:                                 $showloc = join(', ',@{$by_ip{$ip}});
                   2668:                                 if (ref($current{$type}) eq 'ARRAY') {
                   2669:                                     foreach my $loc (@{$by_ip{$ip}}) {  
                   2670:                                         if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
                   2671:                                             $checkedtype = ' checked="checked"';
                   2672:                                             last;
                   2673:                                         }
                   2674:                                     }
1.138     raeburn  2675:                                 }
                   2676:                             }
                   2677:                         }
1.145     raeburn  2678:                         $rem = $i%($numinrow);
                   2679:                         if ($rem == 0) {
                   2680:                             if ($i > 0) {
                   2681:                                 $datatable .= '</tr>';
                   2682:                             }
                   2683:                             $datatable .= '<tr>';
                   2684:                         }
                   2685:                         $datatable .= '<td class="LC_left_item">'.
                   2686:                                       '<span class="LC_nobreak"><label>'.
                   2687:                                       '<input type="checkbox" name="'.$prefix.'_'.$type.
                   2688:                                       '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
                   2689:                                       '</label></span></td>';
1.137     raeburn  2690:                     }
1.145     raeburn  2691:                     $rem = @locations%($numinrow);
                   2692:                     my $colsleft = $numinrow - $rem;
                   2693:                     if ($colsleft > 1 ) {
                   2694:                         $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   2695:                                       '&nbsp;</td>';
                   2696:                     } elsif ($colsleft == 1) {
                   2697:                         $datatable .= '<td class="LC_left_item">&nbsp;</td>';
1.137     raeburn  2698:                     }
1.145     raeburn  2699:                     $datatable .= '</tr></table>';
1.137     raeburn  2700:                 }
1.145     raeburn  2701:                 $datatable .= '</td></tr>';
                   2702:                 $itemcount ++;
1.137     raeburn  2703:             }
                   2704:         }
                   2705:     }
                   2706:     $$rowtotal += $itemcount;
                   2707:     return $datatable;
                   2708: }
                   2709: 
1.138     raeburn  2710: sub build_location_hashes {
                   2711:     my ($intdoms,$by_ip,$by_location) = @_;
                   2712:     return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
                   2713:                   (ref($by_location) eq 'HASH')); 
                   2714:     my %iphost = &Apache::lonnet::get_iphost();
                   2715:     my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
                   2716:     my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
                   2717:     if (ref($iphost{$primary_ip}) eq 'ARRAY') {
                   2718:         foreach my $id (@{$iphost{$primary_ip}}) {
                   2719:             my $intdom = &Apache::lonnet::internet_dom($id);
                   2720:             unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
                   2721:                 push(@{$intdoms},$intdom);
                   2722:             }
                   2723:         }
                   2724:     }
                   2725:     foreach my $ip (keys(%iphost)) {
                   2726:         if (ref($iphost{$ip}) eq 'ARRAY') {
                   2727:             foreach my $id (@{$iphost{$ip}}) {
                   2728:                 my $location = &Apache::lonnet::internet_dom($id);
                   2729:                 if ($location) {
                   2730:                     next if (grep(/^\Q$location\E$/,@{$intdoms}));
                   2731:                     if (ref($by_ip->{$ip}) eq 'ARRAY') {
                   2732:                         unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
                   2733:                             push(@{$by_ip->{$ip}},$location);
                   2734:                         }
                   2735:                     } else {
                   2736:                         $by_ip->{$ip} = [$location];
                   2737:                     }
                   2738:                 }
                   2739:             }
                   2740:         }
                   2741:     }
                   2742:     foreach my $ip (sort(keys(%{$by_ip}))) {
                   2743:         if (ref($by_ip->{$ip}) eq 'ARRAY') {
                   2744:             @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
                   2745:             my $first = $by_ip->{$ip}->[0];
                   2746:             if (ref($by_location->{$first}) eq 'ARRAY') {
                   2747:                 unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
                   2748:                     push(@{$by_location->{$first}},$ip);
                   2749:                 }
                   2750:             } else {
                   2751:                 $by_location->{$first} = [$ip];
                   2752:             }
                   2753:         }
                   2754:     }
                   2755:     return;
                   2756: }
                   2757: 
1.145     raeburn  2758: sub current_offloads_to {
                   2759:     my ($dom,$settings,$servers) = @_;
                   2760:     my (%spareid,%otherdomconfigs);
1.152     raeburn  2761:     if (ref($servers) eq 'HASH') {
1.145     raeburn  2762:         foreach my $lonhost (sort(keys(%{$servers}))) {
                   2763:             my $gotspares;
1.152     raeburn  2764:             if (ref($settings) eq 'HASH') {
                   2765:                 if (ref($settings->{'spares'}) eq 'HASH') {
                   2766:                     if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
                   2767:                         $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
                   2768:                         $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
                   2769:                         $gotspares = 1;
                   2770:                     }
1.145     raeburn  2771:                 }
                   2772:             }
                   2773:             unless ($gotspares) {
                   2774:                 my $gotspares;
                   2775:                 my $serverhomeID =
                   2776:                     &Apache::lonnet::get_server_homeID($servers->{$lonhost});
                   2777:                 my $serverhomedom =
                   2778:                     &Apache::lonnet::host_domain($serverhomeID);
                   2779:                 if ($serverhomedom ne $dom) {
                   2780:                     if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
                   2781:                         if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
                   2782:                             if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
                   2783:                                 $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
                   2784:                                 $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
                   2785:                                 $gotspares = 1;
                   2786:                             }
                   2787:                         }
                   2788:                     } else {
                   2789:                         $otherdomconfigs{$serverhomedom} =
                   2790:                             &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
                   2791:                         if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
                   2792:                             if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
                   2793:                                 if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
                   2794:                                     if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
                   2795:                                         $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
                   2796:                                         $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
                   2797:                                         $gotspares = 1;
                   2798:                                     }
                   2799:                                 }
                   2800:                             }
                   2801:                         }
                   2802:                     }
                   2803:                 }
                   2804:             }
                   2805:             unless ($gotspares) {
                   2806:                 if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
                   2807:                     $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
                   2808:                     $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
                   2809:                } else {
                   2810:                     my $server_hostname = &Apache::lonnet::hostname($lonhost);
                   2811:                     my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
                   2812:                     if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
                   2813:                         $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
                   2814:                         $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
                   2815:                     } else {
1.150     raeburn  2816:                         my %what = (
                   2817:                              spareid => 1,
                   2818:                         );
                   2819:                         my ($result,$returnhash) = 
                   2820:                             &Apache::lonnet::get_remote_globals($lonhost,\%what);
                   2821:                         if ($result eq 'ok') { 
                   2822:                             if (ref($returnhash) eq 'HASH') {
                   2823:                                 if (ref($returnhash->{'spareid'}) eq 'HASH') {
                   2824:                                     $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
                   2825:                                     $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
                   2826:                                 }
                   2827:                             }
1.145     raeburn  2828:                         }
                   2829:                     }
                   2830:                 }
                   2831:             }
                   2832:         }
                   2833:     }
                   2834:     return %spareid;
                   2835: }
                   2836: 
                   2837: sub spares_row {
1.152     raeburn  2838:     my ($dom,$servers,$spareid,$serverhomes,$altids,$rowtotal) = @_;
1.145     raeburn  2839:     my $css_class;
                   2840:     my $numinrow = 4;
                   2841:     my $itemcount = 1;
                   2842:     my $datatable;
1.152     raeburn  2843:     my %typetitles = &sparestype_titles();
                   2844:     if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145     raeburn  2845:         foreach my $server (sort(keys(%{$servers}))) {
1.152     raeburn  2846:             my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
                   2847:             my ($othercontrol,$serverdom);
                   2848:             if ($serverhome ne $server) {
                   2849:                 $serverdom = &Apache::lonnet::host_domain($serverhome);
                   2850:                 $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
                   2851:             } else {
                   2852:                 $serverdom = &Apache::lonnet::host_domain($server);
                   2853:                 if ($serverdom ne $dom) {
                   2854:                     $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
                   2855:                 }
                   2856:             }
                   2857:             next unless (ref($spareid->{$server}) eq 'HASH');
1.145     raeburn  2858:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   2859:             $datatable .= '<tr'.$css_class.'>
                   2860:                            <td rowspan="2">
1.183     bisitz   2861:                             <span class="LC_nobreak">'.
                   2862:                           &mt('[_1] when busy, offloads to:'
                   2863:                               ,'<b>'.$server.'</b>').
                   2864:                           "\n";
1.145     raeburn  2865:             my (%current,%canselect);
1.152     raeburn  2866:             my @choices = 
                   2867:                 &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
                   2868:             foreach my $type ('primary','default') {
                   2869:                 if (ref($spareid->{$server}) eq 'HASH') {
1.145     raeburn  2870:                     if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
                   2871:                         my @spares = @{$spareid->{$server}{$type}};
                   2872:                         if (@spares > 0) {
1.152     raeburn  2873:                             if ($othercontrol) {
                   2874:                                 $current{$type} = join(', ',@spares);
                   2875:                             } else {
                   2876:                                 $current{$type} .= '<table>';
                   2877:                                 my $numspares = scalar(@spares);
                   2878:                                 for (my $i=0;  $i<@spares; $i++) {
                   2879:                                     my $rem = $i%($numinrow);
                   2880:                                     if ($rem == 0) {
                   2881:                                         if ($i > 0) {
                   2882:                                             $current{$type} .= '</tr>';
                   2883:                                         }
                   2884:                                         $current{$type} .= '<tr>';
1.145     raeburn  2885:                                     }
1.152     raeburn  2886:                                     $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;'.
                   2887:                                                        $spareid->{$server}{$type}[$i].
                   2888:                                                        '</label></td>'."\n";
                   2889:                                 }
                   2890:                                 my $rem = @spares%($numinrow);
                   2891:                                 my $colsleft = $numinrow - $rem;
                   2892:                                 if ($colsleft > 1 ) {
                   2893:                                     $current{$type} .= '<td colspan="'.$colsleft.
                   2894:                                                        '" class="LC_left_item">'.
                   2895:                                                        '&nbsp;</td>';
                   2896:                                 } elsif ($colsleft == 1) {
                   2897:                                     $current{$type} .= '<td class="LC_left_item">&nbsp;</td>'."\n";
1.145     raeburn  2898:                                 }
1.152     raeburn  2899:                                 $current{$type} .= '</tr></table>';
1.150     raeburn  2900:                             }
1.145     raeburn  2901:                         }
                   2902:                     }
                   2903:                     if ($current{$type} eq '') {
                   2904:                         $current{$type} = &mt('None specified');
                   2905:                     }
1.152     raeburn  2906:                     if ($othercontrol) {
                   2907:                         if ($type eq 'primary') {
                   2908:                             $canselect{$type} = $othercontrol;
                   2909:                         }
                   2910:                     } else {
                   2911:                         $canselect{$type} = 
                   2912:                             &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').'&nbsp;'.
                   2913:                             '<select name="newspare_'.$type.'_'.$server.'" '.
                   2914:                             'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
                   2915:                             '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
                   2916:                         if (@choices > 0) {
                   2917:                             foreach my $lonhost (@choices) {
                   2918:                                 $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
                   2919:                             }
                   2920:                         }
                   2921:                         $canselect{$type} .= '</select>'."\n";
                   2922:                     }
                   2923:                 } else {
                   2924:                     $current{$type} = &mt('Could not be determined');
                   2925:                     if ($type eq 'primary') {
                   2926:                         $canselect{$type} =  $othercontrol;
                   2927:                     }
1.145     raeburn  2928:                 }
1.152     raeburn  2929:                 if ($type eq 'default') {
                   2930:                     $datatable .= '<tr'.$css_class.'>';
                   2931:                 }
                   2932:                 $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
                   2933:                               '<td>'.$current{$type}.'</td>'."\n".
                   2934:                               '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145     raeburn  2935:             }
                   2936:             $itemcount ++;
                   2937:         }
                   2938:     }
                   2939:     $$rowtotal += $itemcount;
                   2940:     return $datatable;
                   2941: }
                   2942: 
1.152     raeburn  2943: sub possible_newspares {
                   2944:     my ($server,$currspares,$serverhomes,$altids) = @_;
                   2945:     my $serverhostname = &Apache::lonnet::hostname($server);
                   2946:     my %excluded;
                   2947:     if ($serverhostname ne '') {
                   2948:         %excluded = (
                   2949:                        $serverhostname => 1,
                   2950:                     );
                   2951:     }
                   2952:     if (ref($currspares) eq 'HASH') {
                   2953:         foreach my $type (keys(%{$currspares})) {
                   2954:             if (ref($currspares->{$type}) eq 'ARRAY') {
                   2955:                 if (@{$currspares->{$type}} > 0) {
                   2956:                     foreach my $curr (@{$currspares->{$type}}) {
                   2957:                         my $hostname = &Apache::lonnet::hostname($curr);
                   2958:                         $excluded{$hostname} = 1;
                   2959:                     }
                   2960:                 }
                   2961:             }
                   2962:         }
                   2963:     }
                   2964:     my @choices;
                   2965:     if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
                   2966:         if (keys(%{$serverhomes}) > 1) {
                   2967:             foreach my $name (sort(keys(%{$serverhomes}))) {
                   2968:                 unless ($excluded{$name}) {
                   2969:                     if (exists($altids->{$serverhomes->{$name}})) {
                   2970:                         push(@choices,$altids->{$serverhomes->{$name}});
                   2971:                     } else {
                   2972:                         push(@choices,$serverhomes->{$name});
1.145     raeburn  2973:                     }
                   2974:                 }
                   2975:             }
                   2976:         }
                   2977:     }
1.152     raeburn  2978:     return sort(@choices);
1.145     raeburn  2979: }
                   2980: 
1.150     raeburn  2981: sub print_loadbalancing {
                   2982:     my ($dom,$settings,$rowtotal) = @_;
                   2983:     my $primary_id = &Apache::lonnet::domain($dom,'primary');
                   2984:     my $intdom = &Apache::lonnet::internet_dom($primary_id);
                   2985:     my $numinrow = 1;
                   2986:     my $datatable;
                   2987:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.171     raeburn  2988:     my (%currbalancer,%currtargets,%currrules,%existing);
                   2989:     if (ref($settings) eq 'HASH') {
                   2990:         %existing = %{$settings};
                   2991:     }
                   2992:     if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
                   2993:         &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
                   2994:                                   \%currtargets,\%currrules);
1.150     raeburn  2995:     } else {
                   2996:         return;
                   2997:     }
                   2998:     my ($othertitle,$usertypes,$types) =
                   2999:         &Apache::loncommon::sorted_inst_types($dom);
                   3000:     my $rownum = 6;
                   3001:     if (ref($types) eq 'ARRAY') {
                   3002:         $rownum += scalar(@{$types});
                   3003:     }
1.171     raeburn  3004:     my @css_class = ('LC_odd_row','LC_even_row');
                   3005:     my $balnum = 0;
                   3006:     my $islast;
                   3007:     my (@toshow,$disabledtext);
                   3008:     if (keys(%currbalancer) > 0) {
                   3009:         @toshow = sort(keys(%currbalancer));
                   3010:         if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
                   3011:             push(@toshow,'');
                   3012:         }
                   3013:     } else {
                   3014:         @toshow = ('');
                   3015:         $disabledtext = &mt('No existing load balancer');
                   3016:     }
                   3017:     foreach my $lonhost (@toshow) {
                   3018:         if ($balnum == scalar(@toshow)-1) {
                   3019:             $islast = 1;
                   3020:         } else {
                   3021:             $islast = 0;
                   3022:         }
                   3023:         my $cssidx = $balnum%2;
                   3024:         my $targets_div_style = 'display: none';
                   3025:         my $disabled_div_style = 'display: block';
                   3026:         my $homedom_div_style = 'display: none';
                   3027:         $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
                   3028:                       '<td rowspan="'.$rownum.'" valign="top">'.
                   3029:                       '<p>';
                   3030:         if ($lonhost eq '') {
                   3031:             $datatable .= '<span class="LC_nobreak">'; 
                   3032:             if (keys(%currbalancer) > 0) {
                   3033:                 $datatable .= &mt('Add balancer:');
                   3034:             } else {
                   3035:                 $datatable .= &mt('Enable balancer:');
                   3036:             }
                   3037:             $datatable .= '&nbsp;'.
                   3038:                           '<select name="loadbalancing_lonhost_'.$balnum.'"'.
                   3039:                           ' id="loadbalancing_lonhost_'.$balnum.'"'.
                   3040:                           ' onchange="toggleTargets('."'$balnum'".');">'."\n".
                   3041:                           '<option value="" selected="selected">'.&mt('None').
                   3042:                           '</option>'."\n";
                   3043:             foreach my $server (sort(keys(%servers))) {
                   3044:                 next if ($currbalancer{$server});
                   3045:                 $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
                   3046:             }
                   3047:             $datatable .= 
                   3048:                 '</select>'."\n".
                   3049:                 '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" />&nbsp;</span>'."\n";
                   3050:         } else {
                   3051:             $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
                   3052:                           '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" />&nbsp;'.
                   3053:                            &mt('Stop balancing').'</label>'.
                   3054:                            '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
                   3055:             $targets_div_style = 'display: block';
                   3056:             $disabled_div_style = 'display: none';
                   3057:             if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
                   3058:                 $homedom_div_style = 'display: block';
                   3059:             }
                   3060:         }
                   3061:         $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
                   3062:                   '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
                   3063:                   $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
                   3064:                   '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
                   3065:         my ($numspares,@spares) = &count_servers($lonhost,%servers);
                   3066:         my @sparestypes = ('primary','default');
                   3067:         my %typetitles = &sparestype_titles();
                   3068:         foreach my $sparetype (@sparestypes) {
                   3069:             my $targettable;
                   3070:             for (my $i=0; $i<$numspares; $i++) {
                   3071:                 my $checked;
                   3072:                 if (ref($currtargets{$lonhost}) eq 'HASH') {
                   3073:                     if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
                   3074:                         if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
                   3075:                             $checked = ' checked="checked"';
                   3076:                         }
                   3077:                     }
                   3078:                 }
                   3079:                 my ($chkboxval,$disabled);
                   3080:                 if (($lonhost ne '') && (exists($servers{$lonhost}))) {
                   3081:                     $chkboxval = $spares[$i];
                   3082:                 }
                   3083:                 if (exists($currbalancer{$spares[$i]})) {
                   3084:                     $disabled = ' disabled="disabled"';
                   3085:                 }
                   3086:                 $targettable .= 
                   3087:                     '<td><label><input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
                   3088:                     $checked.$disabled.' value="'.$chkboxval.'" id="loadbalancing_target_'.$balnum.'_'.$sparetype.'_'.$i.'" onclick="checkOffloads('."this,'$balnum','$sparetype'".');" /><span id="loadbalancing_targettxt_'.$balnum.'_'.$sparetype.'_'.$i.'">&nbsp;'.$chkboxval.
                   3089:                     '</span></label></td>';
                   3090:                 my $rem = $i%($numinrow);
                   3091:                 if ($rem == 0) {
                   3092:                     if (($i > 0) && ($i < $numspares-1)) {
                   3093:                         $targettable .= '</tr>';
                   3094:                     }
                   3095:                     if ($i < $numspares-1) {
                   3096:                         $targettable .= '<tr>';
1.150     raeburn  3097:                     }
                   3098:                 }
                   3099:             }
1.171     raeburn  3100:             if ($targettable ne '') {
                   3101:                 my $rem = $numspares%($numinrow);
                   3102:                 my $colsleft = $numinrow - $rem;
                   3103:                 if ($colsleft > 1 ) {
                   3104:                     $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   3105:                                     '&nbsp;</td>';
                   3106:                 } elsif ($colsleft == 1) {
                   3107:                     $targettable .= '<td class="LC_left_item">&nbsp;</td>';
                   3108:                 }
                   3109:                 $datatable .=  '<i>'.$typetitles{$sparetype}.'</i><br />'.
                   3110:                                '<table><tr>'.$targettable.'</tr></table><br />';
                   3111:             }
                   3112:         }
                   3113:         $datatable .= '</div></td></tr>'.
                   3114:                       &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
                   3115:                                            $othertitle,$usertypes,$types,\%servers,
                   3116:                                            \%currbalancer,$lonhost,
                   3117:                                            $targets_div_style,$homedom_div_style,
                   3118:                                            $css_class[$cssidx],$balnum,$islast);
                   3119:         $$rowtotal += $rownum;
                   3120:         $balnum ++;
                   3121:     }
                   3122:     $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
                   3123:     return $datatable;
                   3124: }
                   3125: 
                   3126: sub get_loadbalancers_config {
                   3127:     my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
                   3128:     return unless ((ref($servers) eq 'HASH') &&
                   3129:                    (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
                   3130:                    (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
                   3131:     if (keys(%{$existing}) > 0) {
                   3132:         my $oldlonhost;
                   3133:         foreach my $key (sort(keys(%{$existing}))) {
                   3134:             if ($key eq 'lonhost') {
                   3135:                 $oldlonhost = $existing->{'lonhost'};
                   3136:                 $currbalancer->{$oldlonhost} = 1;
                   3137:             } elsif ($key eq 'targets') {
                   3138:                 if ($oldlonhost) {
                   3139:                     $currtargets->{$oldlonhost} = $existing->{'targets'};
                   3140:                 }
                   3141:             } elsif ($key eq 'rules') {
                   3142:                 if ($oldlonhost) {
                   3143:                     $currrules->{$oldlonhost} = $existing->{'rules'};
                   3144:                 }
                   3145:             } elsif (ref($existing->{$key}) eq 'HASH') {
                   3146:                 $currbalancer->{$key} = 1;
                   3147:                 $currtargets->{$key} = $existing->{$key}{'targets'};
                   3148:                 $currrules->{$key} = $existing->{$key}{'rules'};
1.150     raeburn  3149:             }
                   3150:         }
1.171     raeburn  3151:     } else {
                   3152:         my ($balancerref,$targetsref) =
                   3153:                 &Apache::lonnet::get_lonbalancer_config($servers);
                   3154:         if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
                   3155:             foreach my $server (sort(keys(%{$balancerref}))) {
                   3156:                 $currbalancer->{$server} = 1;
                   3157:                 $currtargets->{$server} = $targetsref->{$server};
1.150     raeburn  3158:             }
                   3159:         }
                   3160:     }
1.171     raeburn  3161:     return;
1.150     raeburn  3162: }
                   3163: 
                   3164: sub loadbalancing_rules {
                   3165:     my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171     raeburn  3166:         $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
                   3167:         $css_class,$balnum,$islast) = @_;
1.150     raeburn  3168:     my $output;
1.171     raeburn  3169:     my $num = 0;
1.150     raeburn  3170:     my ($alltypes,$othertypes,$titles) = 
                   3171:         &loadbalancing_titles($dom,$intdom,$usertypes,$types);
                   3172:     if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH'))  {
                   3173:         foreach my $type (@{$alltypes}) {
1.171     raeburn  3174:             $num ++;
1.150     raeburn  3175:             my $current;
                   3176:             if (ref($currrules) eq 'HASH') {
                   3177:                 $current = $currrules->{$type};
                   3178:             }
                   3179:             if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.171     raeburn  3180:                 if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150     raeburn  3181:                     $current = '';
                   3182:                 }
                   3183:             }
                   3184:             $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171     raeburn  3185:                                              $servers,$currbalancer,$lonhost,$dom,
                   3186:                                              $targets_div_style,$homedom_div_style,
                   3187:                                              $css_class,$balnum,$num,$islast);
1.150     raeburn  3188:         }
                   3189:     }
                   3190:     return $output;
                   3191: }
                   3192: 
                   3193: sub loadbalancing_titles {
                   3194:     my ($dom,$intdom,$usertypes,$types) = @_;
                   3195:     my %othertypes = (
                   3196:            '_LC_adv'         => &mt('Advanced users from [_1]',$dom),
                   3197:            '_LC_author'      => &mt('Users from [_1] with author role',$dom),
                   3198:            '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
                   3199:            '_LC_external'    => &mt('Users not from [_1]',$intdom),
                   3200:                      );
                   3201:     my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external');
                   3202:     if (ref($types) eq 'ARRAY') {
                   3203:         unshift(@alltypes,@{$types},'default');
                   3204:     }
                   3205:     my %titles;
                   3206:     foreach my $type (@alltypes) {
                   3207:         if ($type =~ /^_LC_/) {
                   3208:             $titles{$type} = $othertypes{$type};
                   3209:         } elsif ($type eq 'default') {
                   3210:             $titles{$type} = &mt('All users from [_1]',$dom);
                   3211:             if (ref($types) eq 'ARRAY') {
                   3212:                 if (@{$types} > 0) {
                   3213:                     $titles{$type} = &mt('Other users from [_1]',$dom);
                   3214:                 }
                   3215:             }
                   3216:         } elsif (ref($usertypes) eq 'HASH') {
                   3217:             $titles{$type} = $usertypes->{$type};
                   3218:         }
                   3219:     }
                   3220:     return (\@alltypes,\%othertypes,\%titles);
                   3221: }
                   3222: 
                   3223: sub loadbalance_rule_row {
1.171     raeburn  3224:     my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
                   3225:         $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.150     raeburn  3226:     my @rulenames = ('default','homeserver');
                   3227:     my %ruletitles = &offloadtype_text();
                   3228:     if ($type eq '_LC_external') {
                   3229:         push(@rulenames,'externalbalancer');
                   3230:     } else {
                   3231:         push(@rulenames,'specific');
                   3232:     }
1.161     raeburn  3233:     push(@rulenames,'none');
1.150     raeburn  3234:     my $style = $targets_div_style;
                   3235:     if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
                   3236:         $style = $homedom_div_style;
                   3237:     }
1.171     raeburn  3238:     my $space;
                   3239:     if ($islast && $num == 1) {
                   3240:         $space = '<div display="inline-block">&nbsp;</div>';
                   3241:     }
1.150     raeburn  3242:     my $output = 
1.171     raeburn  3243:         '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
                   3244:         '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
                   3245:         '<td valaign="top">'.$space.
                   3246:         '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150     raeburn  3247:     for (my $i=0; $i<@rulenames; $i++) {
                   3248:         my $rule = $rulenames[$i];
                   3249:         my ($checked,$extra);
                   3250:         if ($rulenames[$i] eq 'default') {
                   3251:             $rule = '';
                   3252:         }
                   3253:         if ($rulenames[$i] eq 'specific') {
                   3254:             if (ref($servers) eq 'HASH') {
                   3255:                 my $default;
                   3256:                 if (($current ne '') && (exists($servers->{$current}))) {
                   3257:                     $checked = ' checked="checked"';
                   3258:                 }
                   3259:                 unless ($checked) {
                   3260:                     $default = ' selected="selected"';
                   3261:                 }
1.171     raeburn  3262:                 $extra = 
                   3263:                     ':&nbsp;<select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
                   3264:                     '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
                   3265:                     '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
                   3266:                     '<option value=""'.$default.'></option>'."\n";
                   3267:                 foreach my $server (sort(keys(%{$servers}))) {
                   3268:                     if (ref($currbalancer) eq 'HASH') {
                   3269:                         next if (exists($currbalancer->{$server}));
                   3270:                     }
1.150     raeburn  3271:                     my $selected;
1.171     raeburn  3272:                     if ($server eq $current) {
1.150     raeburn  3273:                         $selected = ' selected="selected"';
                   3274:                     }
1.171     raeburn  3275:                     $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150     raeburn  3276:                 }
                   3277:                 $extra .= '</select>';
                   3278:             }
                   3279:         } elsif ($rule eq $current) {
                   3280:             $checked = ' checked="checked"';
                   3281:         }
                   3282:         $output .= '<span class="LC_nobreak"><label>'.
1.171     raeburn  3283:                    '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
                   3284:                    '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
                   3285:                    $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.150     raeburn  3286:                    ')"'.$checked.' />&nbsp;'.$ruletitles{$rulenames[$i]}.
                   3287:                    '</label>'.$extra.'</span><br />'."\n";
                   3288:     }
                   3289:     $output .= '</div></td></tr>'."\n";
                   3290:     return $output;
                   3291: }
                   3292: 
                   3293: sub offloadtype_text {
                   3294:     my %ruletitles = &Apache::lonlocal::texthash (
                   3295:            'default'          => 'Offloads to default destinations',
                   3296:            'homeserver'       => "Offloads to user's home server",
                   3297:            'externalbalancer' => "Offloads to Load Balancer in user's domain",
                   3298:            'specific'         => 'Offloads to specific server',
1.161     raeburn  3299:            'none'             => 'No offload',
1.150     raeburn  3300:     );
                   3301:     return %ruletitles;
                   3302: }
                   3303: 
                   3304: sub sparestype_titles {
                   3305:     my %typestitles = &Apache::lonlocal::texthash (
                   3306:                           'primary' => 'primary',
                   3307:                           'default' => 'default',
                   3308:                       );
                   3309:     return %typestitles;
                   3310: }
                   3311: 
1.28      raeburn  3312: sub contact_titles {
                   3313:     my %titles = &Apache::lonlocal::texthash (
                   3314:                    'supportemail' => 'Support E-mail address',
1.69      raeburn  3315:                    'adminemail'   => 'Default Server Admin E-mail address',
1.28      raeburn  3316:                    'errormail'    => 'Error reports to be e-mailed to',
                   3317:                    'packagesmail' => 'Package update alerts to be e-mailed to',
1.89      raeburn  3318:                    'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
                   3319:                    'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
1.102     raeburn  3320:                    'requestsmail' => 'E-mail from course requests requiring approval',
1.190     raeburn  3321:                    'updatesmail'  => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.203     raeburn  3322:                    'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.28      raeburn  3323:                  );
                   3324:     my %short_titles = &Apache::lonlocal::texthash (
                   3325:                            adminemail   => 'Admin E-mail address',
                   3326:                            supportemail => 'Support E-mail',
                   3327:                        );   
                   3328:     return (\%titles,\%short_titles);
                   3329: }
                   3330: 
1.72      raeburn  3331: sub tool_titles {
                   3332:     my %titles = &Apache::lonlocal::texthash (
1.162     raeburn  3333:                      aboutme    => 'Personal web page',
1.86      raeburn  3334:                      blog       => 'Blog',
1.162     raeburn  3335:                      webdav     => 'WebDAV',
1.86      raeburn  3336:                      portfolio  => 'Portfolio',
1.88      bisitz   3337:                      official   => 'Official courses (with institutional codes)',
                   3338:                      unofficial => 'Unofficial courses',
1.98      raeburn  3339:                      community  => 'Communities',
1.86      raeburn  3340:                  );
1.72      raeburn  3341:     return %titles;
                   3342: }
                   3343: 
1.101     raeburn  3344: sub courserequest_titles {
                   3345:     my %titles = &Apache::lonlocal::texthash (
                   3346:                                    official   => 'Official',
                   3347:                                    unofficial => 'Unofficial',
                   3348:                                    community  => 'Communities',
                   3349:                                    norequest  => 'Not allowed',
1.104     raeburn  3350:                                    approval   => 'Approval by Dom. Coord.',
1.101     raeburn  3351:                                    validate   => 'With validation',
                   3352:                                    autolimit  => 'Numerical limit',
1.103     raeburn  3353:                                    unlimited  => '(blank for unlimited)',
1.101     raeburn  3354:                  );
                   3355:     return %titles;
                   3356: }
                   3357: 
1.163     raeburn  3358: sub authorrequest_titles {
                   3359:     my %titles = &Apache::lonlocal::texthash (
                   3360:                                    norequest  => 'Not allowed',
                   3361:                                    approval   => 'Approval by Dom. Coord.',
                   3362:                                    automatic  => 'Automatic approval',
                   3363:                  );
                   3364:     return %titles;
                   3365: } 
                   3366: 
1.101     raeburn  3367: sub courserequest_conditions {
                   3368:     my %conditions = &Apache::lonlocal::texthash (
1.104     raeburn  3369:        approval    => '(Processing of request subject to approval by Domain Coordinator).',
1.193     bisitz   3370:        validate   => '(Processing of request subject to institutional validation).',
1.101     raeburn  3371:                  );
                   3372:     return %conditions;
                   3373: }
                   3374: 
                   3375: 
1.27      raeburn  3376: sub print_usercreation {
1.30      raeburn  3377:     my ($position,$dom,$settings,$rowtotal) = @_;
1.27      raeburn  3378:     my $numinrow = 4;
1.28      raeburn  3379:     my $datatable;
                   3380:     if ($position eq 'top') {
1.30      raeburn  3381:         $$rowtotal ++;
1.34      raeburn  3382:         my $rowcount = 0;
1.32      raeburn  3383:         my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28      raeburn  3384:         if (ref($rules) eq 'HASH') {
                   3385:             if (keys(%{$rules}) > 0) {
1.32      raeburn  3386:                 $datatable .= &user_formats_row('username',$settings,$rules,
                   3387:                                                 $ruleorder,$numinrow,$rowcount);
1.30      raeburn  3388:                 $$rowtotal ++;
1.32      raeburn  3389:                 $rowcount ++;
                   3390:             }
                   3391:         }
                   3392:         my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
                   3393:         if (ref($idrules) eq 'HASH') {
                   3394:             if (keys(%{$idrules}) > 0) {
                   3395:                 $datatable .= &user_formats_row('id',$settings,$idrules,
                   3396:                                                 $idruleorder,$numinrow,$rowcount);
                   3397:                 $$rowtotal ++;
                   3398:                 $rowcount ++;
1.28      raeburn  3399:             }
                   3400:         }
1.43      raeburn  3401:         my ($emailrules,$emailruleorder) = 
                   3402:             &Apache::lonnet::inst_userrules($dom,'email');
                   3403:         if (ref($emailrules) eq 'HASH') {
                   3404:             if (keys(%{$emailrules}) > 0) {
                   3405:                 $datatable .= &user_formats_row('email',$settings,$emailrules,
                   3406:                                                 $emailruleorder,$numinrow,$rowcount);
                   3407:                 $$rowtotal ++;
                   3408:                 $rowcount ++;
                   3409:             }
                   3410:         }
1.39      raeburn  3411:         if ($rowcount == 0) {
                   3412:             $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';  
                   3413:             $$rowtotal ++;
                   3414:             $rowcount ++;
                   3415:         }
1.34      raeburn  3416:     } elsif ($position eq 'middle') {
1.100     raeburn  3417:         my @creators = ('author','course','requestcrs','selfcreate');
1.37      raeburn  3418:         my ($rules,$ruleorder) =
                   3419:             &Apache::lonnet::inst_userrules($dom,'username');
1.34      raeburn  3420:         my %lt = &usercreation_types();
                   3421:         my %checked;
1.50      raeburn  3422:         my @selfcreate; 
1.34      raeburn  3423:         if (ref($settings) eq 'HASH') {
                   3424:             if (ref($settings->{'cancreate'}) eq 'HASH') {
                   3425:                 foreach my $item (@creators) {
                   3426:                     $checked{$item} = $settings->{'cancreate'}{$item};
                   3427:                 }
1.50      raeburn  3428:                 if (ref($settings->{'cancreate'}{'selfcreate'}) eq 'ARRAY') {
                   3429:                     @selfcreate = @{$settings->{'cancreate'}{'selfcreate'}};
                   3430:                 } elsif ($settings->{'cancreate'}{'selfcreate'} ne '') {
                   3431:                     if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
                   3432:                         @selfcreate = ('email','login','sso');
                   3433:                     } elsif ($settings->{'cancreate'}{'selfcreate'} ne 'none') {
                   3434:                         @selfcreate = ($settings->{'cancreate'}{'selfcreate'});
                   3435:                     }
                   3436:                 }
1.34      raeburn  3437:             } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
                   3438:                 foreach my $item (@creators) {
                   3439:                     if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
                   3440:                         $checked{$item} = 'none';
                   3441:                     }
                   3442:                 }
                   3443:             }
                   3444:         }
                   3445:         my $rownum = 0;
                   3446:         foreach my $item (@creators) {
                   3447:             $rownum ++;
1.50      raeburn  3448:             if ($item ne 'selfcreate') {  
                   3449:                 if ($checked{$item} eq '') {
1.43      raeburn  3450:                     $checked{$item} = 'any';
                   3451:                 }
1.34      raeburn  3452:             }
                   3453:             my $css_class;
                   3454:             if ($rownum%2) {
                   3455:                 $css_class = '';
                   3456:             } else {
                   3457:                 $css_class = ' class="LC_odd_row" ';
                   3458:             }
                   3459:             $datatable .= '<tr'.$css_class.'>'.
                   3460:                          '<td><span class="LC_nobreak">'.$lt{$item}.
                   3461:                          '</span></td><td align="right">';
1.50      raeburn  3462:             my @options;
1.45      raeburn  3463:             if ($item eq 'selfcreate') {
1.43      raeburn  3464:                 push(@options,('email','login','sso'));
                   3465:             } else {
1.50      raeburn  3466:                 @options = ('any');
1.43      raeburn  3467:                 if (ref($rules) eq 'HASH') {
                   3468:                     if (keys(%{$rules}) > 0) {
                   3469:                         push(@options,('official','unofficial'));
                   3470:                     }
1.37      raeburn  3471:                 }
1.50      raeburn  3472:                 push(@options,'none');
1.37      raeburn  3473:             }
                   3474:             foreach my $option (@options) {
1.50      raeburn  3475:                 my $type = 'radio';
1.34      raeburn  3476:                 my $check = ' ';
1.50      raeburn  3477:                 if ($item eq 'selfcreate') {
                   3478:                     $type = 'checkbox';
                   3479:                     if (grep(/^\Q$option\E$/,@selfcreate)) {
                   3480:                         $check = ' checked="checked" ';
                   3481:                     }
                   3482:                 } else {
                   3483:                     if ($checked{$item} eq $option) {
                   3484:                         $check = ' checked="checked" ';
                   3485:                     }
1.34      raeburn  3486:                 } 
                   3487:                 $datatable .= '<span class="LC_nobreak"><label>'.
1.50      raeburn  3488:                               '<input type="'.$type.'" name="can_createuser_'.
1.34      raeburn  3489:                               $item.'" value="'.$option.'"'.$check.'/>&nbsp;'.
                   3490:                               $lt{$option}.'</label>&nbsp;&nbsp;</span>';
                   3491:             }
                   3492:             $datatable .= '</td></tr>';
                   3493:         }
1.93      raeburn  3494:         my ($othertitle,$usertypes,$types) =
                   3495:             &Apache::loncommon::sorted_inst_types($dom);
1.165     raeburn  3496:         my $createsettings;
                   3497:         if (ref($settings) eq 'HASH') {
                   3498:             $createsettings = $settings->{cancreate};
                   3499:         }
1.93      raeburn  3500:         if (ref($usertypes) eq 'HASH') {
                   3501:             if (keys(%{$usertypes}) > 0) {
1.99      raeburn  3502:                 $datatable .= &insttypes_row($createsettings,$types,$usertypes,
1.93      raeburn  3503:                                              $dom,$numinrow,$othertitle,
                   3504:                                              'statustocreate');
                   3505:                 $$rowtotal ++;
1.169     raeburn  3506:                 $rownum ++;
1.93      raeburn  3507:             }
                   3508:         }
1.169     raeburn  3509:         $datatable .= &captcha_choice('cancreate',$createsettings,$rownum);
1.28      raeburn  3510:     } else {
                   3511:         my @contexts = ('author','course','domain');
                   3512:         my @authtypes = ('int','krb4','krb5','loc');
                   3513:         my %checked;
                   3514:         if (ref($settings) eq 'HASH') {
                   3515:             if (ref($settings->{'authtypes'}) eq 'HASH') {
                   3516:                 foreach my $item (@contexts) {
                   3517:                     if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
                   3518:                         foreach my $auth (@authtypes) {
                   3519:                             if ($settings->{'authtypes'}{$item}{$auth}) {
                   3520:                                 $checked{$item}{$auth} = ' checked="checked" ';
                   3521:                             }
                   3522:                         }
                   3523:                     }
                   3524:                 }
1.27      raeburn  3525:             }
1.35      raeburn  3526:         } else {
                   3527:             foreach my $item (@contexts) {
1.36      raeburn  3528:                 foreach my $auth (@authtypes) {
1.35      raeburn  3529:                     $checked{$item}{$auth} = ' checked="checked" ';
                   3530:                 }
                   3531:             }
1.27      raeburn  3532:         }
1.28      raeburn  3533:         my %title = &context_names();
                   3534:         my %authname = &authtype_names();
                   3535:         my $rownum = 0;
                   3536:         my $css_class; 
                   3537:         foreach my $item (@contexts) {
                   3538:             if ($rownum%2) {
                   3539:                 $css_class = '';
                   3540:             } else {
                   3541:                 $css_class = ' class="LC_odd_row" ';
                   3542:             }
1.30      raeburn  3543:             $datatable .=   '<tr'.$css_class.'>'.
1.28      raeburn  3544:                             '<td>'.$title{$item}.
                   3545:                             '</td><td class="LC_left_item">'.
                   3546:                             '<span class="LC_nobreak">';
                   3547:             foreach my $auth (@authtypes) {
                   3548:                 $datatable .= '<label>'. 
                   3549:                               '<input type="checkbox" name="'.$item.'_auth" '.
                   3550:                               $checked{$item}{$auth}.' value="'.$auth.'" />'.
                   3551:                               $authname{$auth}.'</label>&nbsp;';
                   3552:             }
                   3553:             $datatable .= '</span></td></tr>';
                   3554:             $rownum ++;
1.27      raeburn  3555:         }
1.30      raeburn  3556:         $$rowtotal += $rownum;
1.27      raeburn  3557:     }
                   3558:     return $datatable;
                   3559: }
                   3560: 
1.165     raeburn  3561: sub captcha_choice {
1.169     raeburn  3562:     my ($context,$settings,$itemcount) = @_;
1.165     raeburn  3563:     my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext);
                   3564:     my %lt = &captcha_phrases();
                   3565:     $keyentry = 'hidden';
                   3566:     if ($context eq 'cancreate') {
                   3567:         $rowname = &mt('CAPTCHA validation (e-mail as username)');
1.169     raeburn  3568:     } elsif ($context eq 'login') {
                   3569:         $rowname =  &mt('"Contact helpdesk" CAPTCHA validation');
1.165     raeburn  3570:     }
                   3571:     if (ref($settings) eq 'HASH') {
                   3572:         if ($settings->{'captcha'}) {
                   3573:             $checked{$settings->{'captcha'}} = ' checked="checked"';
                   3574:         } else {
                   3575:             $checked{'original'} = ' checked="checked"';
                   3576:         }
                   3577:         if ($settings->{'captcha'} eq 'recaptcha') {
                   3578:             $pubtext = $lt{'pub'};
                   3579:             $privtext = $lt{'priv'};
                   3580:             $keyentry = 'text';
                   3581:         }
                   3582:         if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
                   3583:             $currpub = $settings->{'recaptchakeys'}{'public'};
                   3584:             $currpriv = $settings->{'recaptchakeys'}{'private'};
                   3585:         }
                   3586:     } else {
                   3587:         $checked{'original'} = ' checked="checked"';
                   3588:     }
1.169     raeburn  3589:     my $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   3590:     my $output = '<tr'.$css_class.'>'.
                   3591:                  '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
1.165     raeburn  3592:                  '<table><tr><td>'."\n";
                   3593:     foreach my $option ('original','recaptcha','notused') {
                   3594:         $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
                   3595:                    $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
                   3596:                    $lt{$option}.'</label></span>';
                   3597:         unless ($option eq 'notused') {
                   3598:             $output .= ('&nbsp;'x2)."\n";
                   3599:         }
                   3600:     }
                   3601: #
                   3602: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
                   3603: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
                   3604: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu) 
                   3605: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
                   3606: #  
                   3607:     $output .= '</td></tr>'."\n".
                   3608:                '<tr><td>'."\n".
                   3609:                '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span>&nbsp;'."\n".
                   3610:                '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
                   3611:                $currpub.'" size="40" /></span><br />'."\n".
                   3612:                '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span>&nbsp;'."\n".
                   3613:                '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
                   3614:                $currpriv.'" size="40" /></span></td></tr></table>'."\n".
                   3615:                '</td></tr>';
                   3616:     return $output;
                   3617: }
                   3618: 
1.32      raeburn  3619: sub user_formats_row {
                   3620:     my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
                   3621:     my $output;
                   3622:     my %text = (
                   3623:                    'username' => 'new usernames',
                   3624:                    'id'       => 'IDs',
1.45      raeburn  3625:                    'email'    => 'self-created accounts (e-mail)',
1.32      raeburn  3626:                );
                   3627:     my $css_class = $rowcount%2?' class="LC_odd_row"':'';
                   3628:     $output = '<tr '.$css_class.'>'.
1.63      raeburn  3629:               '<td><span class="LC_nobreak">';
                   3630:     if ($type eq 'email') {
                   3631:         $output .= &mt("Formats disallowed for $text{$type}: ");
                   3632:     } else {
                   3633:         $output .= &mt("Format rules to check for $text{$type}: ");
                   3634:     }
                   3635:     $output .= '</span></td>'.
                   3636:                '<td class="LC_left_item" colspan="2"><table>';
1.27      raeburn  3637:     my $rem;
                   3638:     if (ref($ruleorder) eq 'ARRAY') {
                   3639:         for (my $i=0; $i<@{$ruleorder}; $i++) {
                   3640:             if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
                   3641:                 my $rem = $i%($numinrow);
                   3642:                 if ($rem == 0) {
                   3643:                     if ($i > 0) {
                   3644:                         $output .= '</tr>';
                   3645:                     }
                   3646:                     $output .= '<tr>';
                   3647:                 }
                   3648:                 my $check = ' ';
1.39      raeburn  3649:                 if (ref($settings) eq 'HASH') {
                   3650:                     if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
                   3651:                         if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
                   3652:                             $check = ' checked="checked" ';
                   3653:                         }
1.27      raeburn  3654:                     }
                   3655:                 }
                   3656:                 $output .= '<td class="LC_left_item">'.
                   3657:                            '<span class="LC_nobreak"><label>'.
1.32      raeburn  3658:                            '<input type="checkbox" name="'.$type.'_rule" '.
1.27      raeburn  3659:                            'value="'.$ruleorder->[$i].'"'.$check.'/>'.
                   3660:                            $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
                   3661:             }
                   3662:         }
                   3663:         $rem = @{$ruleorder}%($numinrow);
                   3664:     }
                   3665:     my $colsleft = $numinrow - $rem;
                   3666:     if ($colsleft > 1 ) {
                   3667:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   3668:                    '&nbsp;</td>';
                   3669:     } elsif ($colsleft == 1) {
                   3670:         $output .= '<td class="LC_left_item">&nbsp;</td>';
                   3671:     }
                   3672:     $output .= '</tr></table></td></tr>';
                   3673:     return $output;
                   3674: }
                   3675: 
1.34      raeburn  3676: sub usercreation_types {
                   3677:     my %lt = &Apache::lonlocal::texthash (
                   3678:                     author     => 'When adding a co-author',
                   3679:                     course     => 'When adding a user to a course',
1.100     raeburn  3680:                     requestcrs => 'When requesting a course',
1.45      raeburn  3681:                     selfcreate => 'User creates own account', 
1.34      raeburn  3682:                     any        => 'Any',
                   3683:                     official   => 'Institutional only ',
                   3684:                     unofficial => 'Non-institutional only',
1.85      schafran 3685:                     email      => 'E-mail address',
1.43      raeburn  3686:                     login      => 'Institutional Login',
                   3687:                     sso        => 'SSO', 
1.34      raeburn  3688:                     none       => 'None',
                   3689:     );
                   3690:     return %lt;
1.48      raeburn  3691: }
1.34      raeburn  3692: 
1.28      raeburn  3693: sub authtype_names {
                   3694:     my %lt = &Apache::lonlocal::texthash(
                   3695:                       int    => 'Internal',
                   3696:                       krb4   => 'Kerberos 4',
                   3697:                       krb5   => 'Kerberos 5',
                   3698:                       loc    => 'Local',
                   3699:                   );
                   3700:     return %lt;
                   3701: }
                   3702: 
                   3703: sub context_names {
                   3704:     my %context_title = &Apache::lonlocal::texthash(
                   3705:        author => 'Creating users when an Author',
                   3706:        course => 'Creating users when in a course',
                   3707:        domain => 'Creating users when a Domain Coordinator',
                   3708:     );
                   3709:     return %context_title;
                   3710: }
                   3711: 
1.33      raeburn  3712: sub print_usermodification {
                   3713:     my ($position,$dom,$settings,$rowtotal) = @_;
                   3714:     my $numinrow = 4;
                   3715:     my ($context,$datatable,$rowcount);
                   3716:     if ($position eq 'top') {
                   3717:         $rowcount = 0;
                   3718:         $context = 'author'; 
                   3719:         foreach my $role ('ca','aa') {
                   3720:             $datatable .= &modifiable_userdata_row($context,$role,$settings,
                   3721:                                                    $numinrow,$rowcount);
                   3722:             $$rowtotal ++;
                   3723:             $rowcount ++;
                   3724:         }
1.63      raeburn  3725:     } elsif ($position eq 'middle') {
1.33      raeburn  3726:         $context = 'course';
                   3727:         $rowcount = 0;
                   3728:         foreach my $role ('st','ep','ta','in','cr') {
                   3729:             $datatable .= &modifiable_userdata_row($context,$role,$settings,
                   3730:                                                    $numinrow,$rowcount);
                   3731:             $$rowtotal ++;
                   3732:             $rowcount ++;
                   3733:         }
1.63      raeburn  3734:     } elsif ($position eq 'bottom') {
                   3735:         $context = 'selfcreate';
                   3736:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   3737:         $usertypes->{'default'} = $othertitle;
                   3738:         if (ref($types) eq 'ARRAY') {
                   3739:             push(@{$types},'default');
                   3740:             $usertypes->{'default'} = $othertitle;
                   3741:             foreach my $status (@{$types}) {
                   3742:                 $datatable .= &modifiable_userdata_row($context,$status,$settings,
                   3743:                                                        $numinrow,$rowcount,$usertypes);
                   3744:                 $$rowtotal ++;
                   3745:                 $rowcount ++;
                   3746:             }
                   3747:         }
1.33      raeburn  3748:     }
                   3749:     return $datatable;
                   3750: }
                   3751: 
1.43      raeburn  3752: sub print_defaults {
                   3753:     my ($dom,$rowtotal) = @_;
1.68      raeburn  3754:     my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
1.141     raeburn  3755:                  'datelocale_def','portal_def');
1.43      raeburn  3756:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.141     raeburn  3757:     my $titles = &defaults_titles($dom);
1.43      raeburn  3758:     my $rownum = 0;
                   3759:     my ($datatable,$css_class);
                   3760:     foreach my $item (@items) {
                   3761:         if ($rownum%2) {
                   3762:             $css_class = '';
                   3763:         } else {
                   3764:             $css_class = ' class="LC_odd_row" ';
                   3765:         }
                   3766:         $datatable .= '<tr'.$css_class.'>'.
                   3767:                   '<td><span class="LC_nobreak">'.$titles->{$item}.
                   3768:                   '</span></td><td class="LC_right_item">';
                   3769:         if ($item eq 'auth_def') {
                   3770:             my @authtypes = ('internal','krb4','krb5','localauth');
                   3771:             my %shortauth = (
                   3772:                              internal => 'int',
                   3773:                              krb4 => 'krb4',
                   3774:                              krb5 => 'krb5',
                   3775:                              localauth  => 'loc'
                   3776:                            );
                   3777:             my %authnames = &authtype_names();
                   3778:             foreach my $auth (@authtypes) {
                   3779:                 my $checked = ' ';
                   3780:                 if ($domdefaults{$item} eq $auth) {
                   3781:                     $checked = ' checked="checked" ';
                   3782:                 }
                   3783:                 $datatable .= '<label><input type="radio" name="'.$item.
                   3784:                               '" value="'.$auth.'"'.$checked.'/>'.
                   3785:                               $authnames{$shortauth{$auth}}.'</label>&nbsp;&nbsp;';
                   3786:             }
1.54      raeburn  3787:         } elsif ($item eq 'timezone_def') {
                   3788:             my $includeempty = 1;
                   3789:             $datatable .= &Apache::loncommon::select_timezone($item,$domdefaults{$item},undef,$includeempty);
1.68      raeburn  3790:         } elsif ($item eq 'datelocale_def') {
                   3791:             my $includeempty = 1;
                   3792:             $datatable .= &Apache::loncommon::select_datelocale($item,$domdefaults{$item},undef,$includeempty);
1.167     raeburn  3793:         } elsif ($item eq 'lang_def') {
1.168     raeburn  3794:             my %langchoices = &get_languages_hash();
                   3795:             $langchoices{''} = 'No language preference';
1.167     raeburn  3796:             %langchoices = &Apache::lonlocal::texthash(%langchoices);
                   3797:             $datatable .= &Apache::loncommon::select_form($domdefaults{$item},$item,
                   3798:                                                           \%langchoices);
1.43      raeburn  3799:         } else {
1.141     raeburn  3800:             my $size;
                   3801:             if ($item eq 'portal_def') {
                   3802:                 $size = ' size="25"';
                   3803:             }
1.43      raeburn  3804:             $datatable .= '<input type="text" name="'.$item.'" value="'.
1.141     raeburn  3805:                           $domdefaults{$item}.'"'.$size.' />';
1.43      raeburn  3806:         }
                   3807:         $datatable .= '</td></tr>';
                   3808:         $rownum ++;
                   3809:     }
                   3810:     $$rowtotal += $rownum;
                   3811:     return $datatable;
                   3812: }
                   3813: 
1.168     raeburn  3814: sub get_languages_hash {
                   3815:     my %langchoices;
                   3816:     foreach my $id (&Apache::loncommon::languageids()) {
                   3817:         my $code = &Apache::loncommon::supportedlanguagecode($id);
                   3818:         if ($code ne '') {
                   3819:             $langchoices{$code} =  &Apache::loncommon::plainlanguagedescription($id);
                   3820:         }
                   3821:     }
                   3822:     return %langchoices;
                   3823: }
                   3824: 
1.43      raeburn  3825: sub defaults_titles {
1.141     raeburn  3826:     my ($dom) = @_;
1.43      raeburn  3827:     my %titles = &Apache::lonlocal::texthash (
                   3828:                    'auth_def'      => 'Default authentication type',
                   3829:                    'auth_arg_def'  => 'Default authentication argument',
                   3830:                    'lang_def'      => 'Default language',
1.54      raeburn  3831:                    'timezone_def'  => 'Default timezone',
1.68      raeburn  3832:                    'datelocale_def' => 'Default locale for dates',
1.141     raeburn  3833:                    'portal_def'     => 'Portal/Default URL',
1.43      raeburn  3834:                  );
1.141     raeburn  3835:     if ($dom) {
                   3836:         my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
                   3837:         my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
                   3838:         my $protocol = $Apache::lonnet::protocol{$uprimary_id};
                   3839:         $protocol = 'http' if ($protocol ne 'https');
                   3840:         if ($uint_dom) {
                   3841:             $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
                   3842:                                          $uint_dom);
                   3843:         }
                   3844:     }
1.43      raeburn  3845:     return (\%titles);
                   3846: }
                   3847: 
1.46      raeburn  3848: sub print_scantronformat {
                   3849:     my ($r,$dom,$confname,$settings,$rowtotal) = @_;
                   3850:     my $itemcount = 1;
1.60      raeburn  3851:     my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
                   3852:         %confhash);
1.46      raeburn  3853:     my $switchserver = &check_switchserver($dom,$confname);
                   3854:     my %lt = &Apache::lonlocal::texthash (
1.95      www      3855:                 default => 'Default bubblesheet format file error',
                   3856:                 custom  => 'Custom bubblesheet format file error',
1.46      raeburn  3857:              );
                   3858:     my %scantronfiles = (
                   3859:         default => 'default.tab',
                   3860:         custom => 'custom.tab',
                   3861:     );
                   3862:     foreach my $key (keys(%scantronfiles)) {
                   3863:         $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
                   3864:                               .$scantronfiles{$key};
                   3865:     }
                   3866:     my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
                   3867:     if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
                   3868:         if (!$switchserver) {
                   3869:             my $servadm = $r->dir_config('lonAdmEMail');
                   3870:             my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
                   3871:             if ($configuserok eq 'ok') {
                   3872:                 if ($author_ok eq 'ok') {
                   3873:                     my %legacyfile = (
                   3874:  default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab', 
                   3875:  custom  => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab', 
                   3876:                     );
                   3877:                     my %md5chk;
                   3878:                     foreach my $type (keys(%legacyfile)) {
1.60      raeburn  3879:                         ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
                   3880:                         chomp($md5chk{$type});
1.46      raeburn  3881:                     }
                   3882:                     if ($md5chk{'default'} ne $md5chk{'custom'}) {
                   3883:                         foreach my $type (keys(%legacyfile)) {
1.60      raeburn  3884:                             ($scantronurls{$type},my $error) = 
1.46      raeburn  3885:                                 &legacy_scantronformat($r,$dom,$confname,
                   3886:                                                  $type,$legacyfile{$type},
                   3887:                                                  $scantronurls{$type},
                   3888:                                                  $scantronfiles{$type});
1.60      raeburn  3889:                             if ($error ne '') {
                   3890:                                 $error{$type} = $error;
                   3891:                             }
                   3892:                         }
                   3893:                         if (keys(%error) == 0) {
                   3894:                             $is_custom = 1;
                   3895:                             $confhash{'scantron'}{'scantronformat'} = 
                   3896:                                 $scantronurls{'custom'};
                   3897:                             my $putresult = 
                   3898:                                 &Apache::lonnet::put_dom('configuration',
                   3899:                                                          \%confhash,$dom);
                   3900:                             if ($putresult ne 'ok') {
                   3901:                                 $error{'custom'} = 
                   3902:                                     '<span class="LC_error">'.
                   3903:                                     &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
                   3904:                             }
1.46      raeburn  3905:                         }
                   3906:                     } else {
1.60      raeburn  3907:                         ($scantronurls{'default'},my $error) =
1.46      raeburn  3908:                             &legacy_scantronformat($r,$dom,$confname,
                   3909:                                           'default',$legacyfile{'default'},
                   3910:                                           $scantronurls{'default'},
                   3911:                                           $scantronfiles{'default'});
1.60      raeburn  3912:                         if ($error eq '') {
                   3913:                             $confhash{'scantron'}{'scantronformat'} = ''; 
                   3914:                             my $putresult =
                   3915:                                 &Apache::lonnet::put_dom('configuration',
                   3916:                                                          \%confhash,$dom);
                   3917:                             if ($putresult ne 'ok') {
                   3918:                                 $error{'default'} =
                   3919:                                     '<span class="LC_error">'.
                   3920:                                     &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
                   3921:                             }
                   3922:                         } else {
                   3923:                             $error{'default'} = $error;
                   3924:                         }
1.46      raeburn  3925:                     }
                   3926:                 }
                   3927:             }
                   3928:         } else {
1.95      www      3929:             $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46      raeburn  3930:         }
                   3931:     }
                   3932:     if (ref($settings) eq 'HASH') {
                   3933:         if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
                   3934:             my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
                   3935:             if ((!@info) || ($info[0] eq 'no_such_dir')) {
                   3936:                 $scantronurl = '';
                   3937:             } else {
                   3938:                 $scantronurl = $settings->{'scantronformat'};
                   3939:             }
                   3940:             $is_custom = 1;
                   3941:         } else {
                   3942:             $scantronurl = $scantronurls{'default'};
                   3943:         }
                   3944:     } else {
1.60      raeburn  3945:         if ($is_custom) {
                   3946:             $scantronurl = $scantronurls{'custom'};
                   3947:         } else {
                   3948:             $scantronurl = $scantronurls{'default'};
                   3949:         }
1.46      raeburn  3950:     }
                   3951:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   3952:     $datatable .= '<tr'.$css_class.'>';
                   3953:     if (!$is_custom) {
1.65      raeburn  3954:         $datatable .= '<td>'.&mt('Default in use:').'<br />'.
                   3955:                       '<span class="LC_nobreak">';
1.46      raeburn  3956:         if ($scantronurl) {
1.199     raeburn  3957:             $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
                   3958:                                                          undef,undef,undef,undef,'background-color:#ffffff');
1.46      raeburn  3959:         } else {
                   3960:             $datatable = &mt('File unavailable for display');
                   3961:         }
1.65      raeburn  3962:         $datatable .= '</span></td>';
1.60      raeburn  3963:         if (keys(%error) == 0) { 
                   3964:             $datatable .= '<td valign="bottom">';
                   3965:             if (!$switchserver) {
                   3966:                 $datatable .= &mt('Upload:').'<br />';
                   3967:             }
                   3968:         } else {
                   3969:             my $errorstr;
                   3970:             foreach my $key (sort(keys(%error))) {
                   3971:                 $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
                   3972:             }
                   3973:             $datatable .= '<td>'.$errorstr;
                   3974:         }
1.46      raeburn  3975:     } else {
                   3976:         if (keys(%error) > 0) {
                   3977:             my $errorstr;
                   3978:             foreach my $key (sort(keys(%error))) {
                   3979:                 $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
                   3980:             } 
1.60      raeburn  3981:             $datatable .= '<td>'.$errorstr.'</td><td>&nbsp;';
1.46      raeburn  3982:         } elsif ($scantronurl) {
1.199     raeburn  3983:             my $link =  &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
                   3984:                                                        undef,undef,undef,undef,'background-color:#ffffff');
1.65      raeburn  3985:             $datatable .= '<td><span class="LC_nobreak">'.
1.199     raeburn  3986:                           $link.
                   3987:                           '<label><input type="checkbox" name="scantronformat_del"'.
                   3988:                           ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65      raeburn  3989:                           '<td><span class="LC_nobreak">&nbsp;'.
                   3990:                           &mt('Replace:').'</span><br />';
1.46      raeburn  3991:         }
                   3992:     }
                   3993:     if (keys(%error) == 0) {
                   3994:         if ($switchserver) {
                   3995:             $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   3996:         } else {
1.65      raeburn  3997:             $datatable .='<span class="LC_nobreak">&nbsp;'.
                   3998:                          '<input type="file" name="scantronformat" /></span>';
1.46      raeburn  3999:         }
                   4000:     }
                   4001:     $datatable .= '</td></tr>';
                   4002:     $$rowtotal ++;
                   4003:     return $datatable;
                   4004: }
                   4005: 
                   4006: sub legacy_scantronformat {
                   4007:     my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
                   4008:     my ($url,$error);
                   4009:     my @statinfo = &Apache::lonnet::stat_file($newurl);
                   4010:     if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
                   4011:         (my $result,$url) =
                   4012:             &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
                   4013:                          '','',$newfile);
                   4014:         if ($result ne 'ok') {
1.130     raeburn  4015:             $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46      raeburn  4016:         }
                   4017:     }
                   4018:     return ($url,$error);
                   4019: }
1.43      raeburn  4020: 
1.49      raeburn  4021: sub print_coursecategories {
1.57      raeburn  4022:     my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
                   4023:     my $datatable;
                   4024:     if ($position eq 'top') {
                   4025:         my $toggle_cats_crs = ' ';
                   4026:         my $toggle_cats_dom = ' checked="checked" ';
                   4027:         my $can_cat_crs = ' ';
                   4028:         my $can_cat_dom = ' checked="checked" ';
1.120     raeburn  4029:         my $toggle_catscomm_comm = ' ';
                   4030:         my $toggle_catscomm_dom = ' checked="checked" ';
                   4031:         my $can_catcomm_comm = ' ';
                   4032:         my $can_catcomm_dom = ' checked="checked" ';
                   4033: 
1.57      raeburn  4034:         if (ref($settings) eq 'HASH') {
                   4035:             if ($settings->{'togglecats'} eq 'crs') {
                   4036:                 $toggle_cats_crs = $toggle_cats_dom;
                   4037:                 $toggle_cats_dom = ' ';
                   4038:             }
                   4039:             if ($settings->{'categorize'} eq 'crs') {
                   4040:                 $can_cat_crs = $can_cat_dom;
                   4041:                 $can_cat_dom = ' ';
                   4042:             }
1.120     raeburn  4043:             if ($settings->{'togglecatscomm'} eq 'comm') {
                   4044:                 $toggle_catscomm_comm = $toggle_catscomm_dom;
                   4045:                 $toggle_catscomm_dom = ' ';
                   4046:             }
                   4047:             if ($settings->{'categorizecomm'} eq 'comm') {
                   4048:                 $can_catcomm_comm = $can_catcomm_dom;
                   4049:                 $can_catcomm_dom = ' ';
                   4050:             }
1.57      raeburn  4051:         }
                   4052:         my %title = &Apache::lonlocal::texthash (
1.120     raeburn  4053:                      togglecats     => 'Show/Hide a course in catalog',
                   4054:                      togglecatscomm => 'Show/Hide a community in catalog',
                   4055:                      categorize     => 'Assign a category to a course',
                   4056:                      categorizecomm => 'Assign a category to a community',
1.57      raeburn  4057:                     );
                   4058:         my %level = &Apache::lonlocal::texthash (
1.120     raeburn  4059:                      dom  => 'Set in Domain',
                   4060:                      crs  => 'Set in Course',
                   4061:                      comm => 'Set in Community',
1.57      raeburn  4062:                     );
                   4063:         $datatable = '<tr class="LC_odd_row">'.
                   4064:                   '<td>'.$title{'togglecats'}.'</td>'.
                   4065:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   4066:                   '<input type="radio" name="togglecats"'.
                   4067:                   $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   4068:                   '<label><input type="radio" name="togglecats"'.
                   4069:                   $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
                   4070:                   '</tr><tr>'.
                   4071:                   '<td>'.$title{'categorize'}.'</td>'.
                   4072:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
                   4073:                   '<label><input type="radio" name="categorize"'.
                   4074:                   $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   4075:                   '<label><input type="radio" name="categorize"'.
                   4076:                   $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120     raeburn  4077:                   '</tr><tr class="LC_odd_row">'.
                   4078:                   '<td>'.$title{'togglecatscomm'}.'</td>'.
                   4079:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   4080:                   '<input type="radio" name="togglecatscomm"'.
                   4081:                   $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   4082:                   '<label><input type="radio" name="togglecatscomm"'.
                   4083:                   $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
                   4084:                   '</tr><tr>'.
                   4085:                   '<td>'.$title{'categorizecomm'}.'</td>'.
                   4086:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
                   4087:                   '<label><input type="radio" name="categorizecomm"'.
                   4088:                   $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   4089:                   '<label><input type="radio" name="categorizecomm"'.
                   4090:                   $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57      raeburn  4091:                   '</tr>';
1.120     raeburn  4092:         $$rowtotal += 4;
1.57      raeburn  4093:     } else {
                   4094:         my $css_class;
                   4095:         my $itemcount = 1;
                   4096:         my $cathash; 
                   4097:         if (ref($settings) eq 'HASH') {
                   4098:             $cathash = $settings->{'cats'};
                   4099:         }
                   4100:         if (ref($cathash) eq 'HASH') {
                   4101:             my (@cats,@trails,%allitems,%idx,@jsarray);
                   4102:             &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
                   4103:                                                    \%allitems,\%idx,\@jsarray);
                   4104:             my $maxdepth = scalar(@cats);
                   4105:             my $colattrib = '';
                   4106:             if ($maxdepth > 2) {
                   4107:                 $colattrib = ' colspan="2" ';
                   4108:             }
                   4109:             my @path;
                   4110:             if (@cats > 0) {
                   4111:                 if (ref($cats[0]) eq 'ARRAY') {
                   4112:                     my $numtop = @{$cats[0]};
                   4113:                     my $maxnum = $numtop;
1.120     raeburn  4114:                     my %default_names = (
                   4115:                           instcode    => &mt('Official courses'),
                   4116:                           communities => &mt('Communities'),
                   4117:                     );
                   4118: 
                   4119:                     if ((!grep(/^instcode$/,@{$cats[0]})) || 
                   4120:                         ($cathash->{'instcode::0'} eq '') ||
                   4121:                         (!grep(/^communities$/,@{$cats[0]})) || 
                   4122:                         ($cathash->{'communities::0'} eq '')) {
1.57      raeburn  4123:                         $maxnum ++;
                   4124:                     }
                   4125:                     my $lastidx;
                   4126:                     for (my $i=0; $i<$numtop; $i++) {
                   4127:                         my $parent = $cats[0][$i];
                   4128:                         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   4129:                         my $item = &escape($parent).'::0';
                   4130:                         my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
                   4131:                         $lastidx = $idx{$item};
                   4132:                         $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
                   4133:                                       .'<select name="'.$item.'"'.$chgstr.'>';
                   4134:                         for (my $k=0; $k<=$maxnum; $k++) {
                   4135:                             my $vpos = $k+1;
                   4136:                             my $selstr;
                   4137:                             if ($k == $i) {
                   4138:                                 $selstr = ' selected="selected" ';
                   4139:                             }
                   4140:                             $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   4141:                         }
                   4142:                         $datatable .= '</select></td><td>';
1.120     raeburn  4143:                         if ($parent eq 'instcode' || $parent eq 'communities') {
                   4144:                             $datatable .=  '<span class="LC_nobreak">'
                   4145:                                            .$default_names{$parent}.'</span>';
                   4146:                             if ($parent eq 'instcode') {
                   4147:                                 $datatable .= '<br /><span class="LC_nobreak">('
                   4148:                                               .&mt('with institutional codes')
                   4149:                                               .')</span></td><td'.$colattrib.'>';
                   4150:                             } else {
                   4151:                                 $datatable .= '<table><tr><td>';
                   4152:                             }
                   4153:                             $datatable .= '<span class="LC_nobreak">'
                   4154:                                           .'<label><input type="radio" name="'
                   4155:                                           .$parent.'" value="1" checked="checked" />'
                   4156:                                           .&mt('Display').'</label>';
                   4157:                             if ($parent eq 'instcode') {
                   4158:                                 $datatable .= '&nbsp;';
                   4159:                             } else {
                   4160:                                 $datatable .= '</span></td></tr><tr><td>'
                   4161:                                               .'<span class="LC_nobreak">';
                   4162:                             }
                   4163:                             $datatable .= '<label><input type="radio" name="'
                   4164:                                           .$parent.'" value="0" />'
                   4165:                                           .&mt('Do not display').'</label></span>';
                   4166:                             if ($parent eq 'communities') {
                   4167:                                 $datatable .= '</td></tr></table>';
                   4168:                             }
                   4169:                             $datatable .= '</td>';
1.57      raeburn  4170:                         } else {
                   4171:                             $datatable .= $parent
                   4172:                                           .'&nbsp;<label><input type="checkbox" name="deletecategory" '
                   4173:                                           .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
                   4174:                         }
                   4175:                         my $depth = 1;
                   4176:                         push(@path,$parent);
                   4177:                         $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
                   4178:                         pop(@path);
                   4179:                         $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
                   4180:                         $itemcount ++;
                   4181:                     }
1.48      raeburn  4182:                     $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57      raeburn  4183:                     my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
                   4184:                     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48      raeburn  4185:                     for (my $k=0; $k<=$maxnum; $k++) {
                   4186:                         my $vpos = $k+1;
                   4187:                         my $selstr;
1.57      raeburn  4188:                         if ($k == $numtop) {
1.48      raeburn  4189:                             $selstr = ' selected="selected" ';
                   4190:                         }
                   4191:                         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   4192:                     }
1.59      bisitz   4193:                     $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').'&nbsp;'
1.57      raeburn  4194:                                   .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
                   4195:                                   .'</tr>'."\n";
1.48      raeburn  4196:                     $itemcount ++;
1.120     raeburn  4197:                     foreach my $default ('instcode','communities') {
                   4198:                         if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
                   4199:                             $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   4200:                             my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
                   4201:                             $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
                   4202:                                           '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
                   4203:                             for (my $k=0; $k<=$maxnum; $k++) {
                   4204:                                 my $vpos = $k+1;
                   4205:                                 my $selstr;
                   4206:                                 if ($k == $maxnum) {
                   4207:                                     $selstr = ' selected="selected" ';
                   4208:                                 }
                   4209:                                 $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57      raeburn  4210:                             }
1.120     raeburn  4211:                             $datatable .= '</select></span></td>'.
                   4212:                                           '<td><span class="LC_nobreak">'.
                   4213:                                           $default_names{$default}.'</span>';
                   4214:                             if ($default eq 'instcode') {
                   4215:                                 $datatable .= '<br /><span class="LC_nobreak">(' 
                   4216:                                               .&mt('with institutional codes').')</span>';
                   4217:                             }
                   4218:                             $datatable .= '</td>'
                   4219:                                           .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
                   4220:                                           .&mt('Display').'</label>&nbsp;'
                   4221:                                           .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
                   4222:                                           .&mt('Do not display').'</label></span></td></tr>';
1.48      raeburn  4223:                         }
                   4224:                     }
                   4225:                 }
1.57      raeburn  4226:             } else {
                   4227:                 $datatable .= &initialize_categories($itemcount);
1.48      raeburn  4228:             }
                   4229:         } else {
1.57      raeburn  4230:             $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[0]->{'col2'}.'</td>'
                   4231:                           .&initialize_categories($itemcount);
1.48      raeburn  4232:         }
1.57      raeburn  4233:         $$rowtotal += $itemcount;
1.48      raeburn  4234:     }
                   4235:     return $datatable;
                   4236: }
                   4237: 
1.69      raeburn  4238: sub print_serverstatuses {
                   4239:     my ($dom,$settings,$rowtotal) = @_;
                   4240:     my $datatable;
                   4241:     my @pages = &serverstatus_pages();
                   4242:     my (%namedaccess,%machineaccess);
                   4243:     foreach my $type (@pages) {
                   4244:         $namedaccess{$type} = '';
                   4245:         $machineaccess{$type}= '';
                   4246:     }
                   4247:     if (ref($settings) eq 'HASH') {
                   4248:         foreach my $type (@pages) {
                   4249:             if (exists($settings->{$type})) {
                   4250:                 if (ref($settings->{$type}) eq 'HASH') {
                   4251:                     foreach my $key (keys(%{$settings->{$type}})) {
                   4252:                         if ($key eq 'namedusers') {
                   4253:                             $namedaccess{$type} = $settings->{$type}->{$key};
                   4254:                         } elsif ($key eq 'machines') {
                   4255:                             $machineaccess{$type} = $settings->{$type}->{$key};
                   4256:                         }
                   4257:                     }
                   4258:                 }
                   4259:             }
                   4260:         }
                   4261:     }
1.81      raeburn  4262:     my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69      raeburn  4263:     my $rownum = 0;
                   4264:     my $css_class;
                   4265:     foreach my $type (@pages) {
                   4266:         $rownum ++;
                   4267:         $css_class = $rownum%2?' class="LC_odd_row"':'';
                   4268:         $datatable .= '<tr'.$css_class.'>'.
                   4269:                       '<td><span class="LC_nobreak">'.
                   4270:                       $titles->{$type}.'</span></td>'.
                   4271:                       '<td class="LC_left_item">'.
                   4272:                       '<input type="text" name="'.$type.'_namedusers" '.
                   4273:                       'value="'.$namedaccess{$type}.'" size="30" /></td>'.
                   4274:                       '<td class="LC_right_item">'.
                   4275:                       '<span class="LC_nobreak">'.
                   4276:                       '<input type="text" name="'.$type.'_machines" '.
                   4277:                       'value="'.$machineaccess{$type}.'" size="10" />'.
                   4278:                       '</td></tr>'."\n";
                   4279:     }
                   4280:     $$rowtotal += $rownum;
                   4281:     return $datatable;
                   4282: }
                   4283: 
                   4284: sub serverstatus_pages {
                   4285:     return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.189     raeburn  4286:             'checksums','clusterstatus','metadata_keywords','metadata_harvest',
1.156     raeburn  4287:             'takeoffline','takeonline','showenv','toggledebug','ping','domconf');
1.69      raeburn  4288: }
                   4289: 
1.49      raeburn  4290: sub coursecategories_javascript {
                   4291:     my ($settings) = @_;
1.57      raeburn  4292:     my ($output,$jstext,$cathash);
1.49      raeburn  4293:     if (ref($settings) eq 'HASH') {
1.57      raeburn  4294:         $cathash = $settings->{'cats'};
                   4295:     }
                   4296:     if (ref($cathash) eq 'HASH') {
1.49      raeburn  4297:         my (@cats,@jsarray,%idx);
1.57      raeburn  4298:         &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49      raeburn  4299:         if (@jsarray > 0) {
                   4300:             $jstext = '    var categories = Array('.scalar(@jsarray).');'."\n";
                   4301:             for (my $i=0; $i<@jsarray; $i++) {
                   4302:                 if (ref($jsarray[$i]) eq 'ARRAY') {
                   4303:                     my $catstr = join('","',@{$jsarray[$i]});
                   4304:                     $jstext .= '    categories['.$i.'] = Array("'.$catstr.'");'."\n";
                   4305:                 }
                   4306:             }
                   4307:         }
                   4308:     } else {
                   4309:         $jstext  = '    var categories = Array(1);'."\n".
                   4310:                    '    categories[0] = Array("instcode_pos");'."\n"; 
                   4311:     }
1.120     raeburn  4312:     my $instcode_reserved = &mt('The name: "instcode" is a reserved category');
                   4313:     my $communities_reserved = &mt('The name: "communities" is a reserved category');
                   4314:     my $choose_again = '\\n'.&mt('Please use a different name for the new top level category'); 
1.49      raeburn  4315:     $output = <<"ENDSCRIPT";
                   4316: <script type="text/javascript">
1.109     raeburn  4317: // <![CDATA[
1.49      raeburn  4318: function reorderCats(form,parent,item,idx) {
                   4319:     var changedVal;
                   4320: $jstext
                   4321:     var newpos = 'addcategory_pos';
                   4322:     var current = new Array;
                   4323:     if (parent == '') {
                   4324:         var has_instcode = 0;
                   4325:         var maxtop = categories[idx].length;
                   4326:         for (var j=0; j<maxtop; j++) {
                   4327:             if (categories[idx][j] == 'instcode::0') {
                   4328:                 has_instcode == 1;
                   4329:             }
                   4330:         }
                   4331:         if (has_instcode == 0) {
                   4332:             categories[idx][maxtop] = 'instcode_pos';
                   4333:         }
                   4334:     } else {
                   4335:         newpos += '_'+parent;
                   4336:     }
                   4337:     var maxh = 1 + categories[idx].length;
                   4338:     var current = new Array;
                   4339:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
                   4340:     if (item == newpos) {
                   4341:         changedVal = newitemVal;
                   4342:     } else {
                   4343:         changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
                   4344:         current[newitemVal] = newpos;
                   4345:     }
                   4346:     for (var i=0; i<categories[idx].length; i++) {
                   4347:         var elementName = categories[idx][i];
                   4348:         if (elementName != item) {
                   4349:             if (form.elements[elementName]) {
                   4350:                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   4351:                 current[currVal] = elementName;
                   4352:             }
                   4353:         }
                   4354:     }
                   4355:     var oldVal;
                   4356:     for (var j=0; j<maxh; j++) {
                   4357:         if (current[j] == undefined) {
                   4358:             oldVal = j;
                   4359:         }
                   4360:     }
                   4361:     if (oldVal < changedVal) {
                   4362:         for (var k=oldVal+1; k<=changedVal ; k++) {
                   4363:            var elementName = current[k];
                   4364:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   4365:         }
                   4366:     } else {
                   4367:         for (var k=changedVal; k<oldVal; k++) {
                   4368:             var elementName = current[k];
                   4369:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   4370:         }
                   4371:     }
                   4372:     return;
                   4373: }
1.120     raeburn  4374: 
                   4375: function categoryCheck(form) {
                   4376:     if (form.elements['addcategory_name'].value == 'instcode') {
                   4377:         alert('$instcode_reserved\\n$choose_again');
                   4378:         return false;
                   4379:     }
                   4380:     if (form.elements['addcategory_name'].value == 'communities') {
                   4381:         alert('$communities_reserved\\n$choose_again');
                   4382:         return false;
                   4383:     }
                   4384:     return true;
                   4385: }
                   4386: 
1.109     raeburn  4387: // ]]>
1.49      raeburn  4388: </script>
                   4389: 
                   4390: ENDSCRIPT
                   4391:     return $output;
                   4392: }
                   4393: 
1.48      raeburn  4394: sub initialize_categories {
                   4395:     my ($itemcount) = @_;
1.120     raeburn  4396:     my ($datatable,$css_class,$chgstr);
                   4397:     my %default_names = (
                   4398:                       instcode    => 'Official courses (with institutional codes)',
                   4399:                       communities => 'Communities',
                   4400:                         );
                   4401:     my $select0 = ' selected="selected"';
                   4402:     my $select1 = '';
                   4403:     foreach my $default ('instcode','communities') {
                   4404:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   4405:         $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
                   4406:         if ($default eq 'communities') {
                   4407:             $select1 = $select0;
                   4408:             $select0 = '';
                   4409:         }
                   4410:         $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
                   4411:                      .'<select name="'.$default.'_pos">'
                   4412:                      .'<option value="0"'.$select0.'>1</option>'
                   4413:                      .'<option value="1"'.$select1.'>2</option>'
                   4414:                      .'<option value="2">3</option></select>&nbsp;'
                   4415:                      .$default_names{$default}
                   4416:                      .'</span></td><td><span class="LC_nobreak">'
                   4417:                      .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
                   4418:                      .&mt('Display').'</label>&nbsp;<label>'
                   4419:                      .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48      raeburn  4420:                  .'</label></span></td></tr>';
1.120     raeburn  4421:         $itemcount ++;
                   4422:     }
1.48      raeburn  4423:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49      raeburn  4424:     $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48      raeburn  4425:     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120     raeburn  4426:                   .'<select name="addcategory_pos"'.$chgstr.'>'
                   4427:                   .'<option value="0">1</option>'
                   4428:                   .'<option value="1">2</option>'
                   4429:                   .'<option value="2" selected="selected">3</option></select>&nbsp;'
1.48      raeburn  4430:                   .&mt('Add category').'</td><td>'.&mt('Name:')
                   4431:                   .'&nbsp;<input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
                   4432:     return $datatable;
                   4433: }
                   4434: 
                   4435: sub build_category_rows {
1.49      raeburn  4436:     my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
                   4437:     my ($text,$name,$item,$chgstr);
1.48      raeburn  4438:     if (ref($cats) eq 'ARRAY') {
                   4439:         my $maxdepth = scalar(@{$cats});
                   4440:         if (ref($cats->[$depth]) eq 'HASH') {
                   4441:             if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
                   4442:                 my $numchildren = @{$cats->[$depth]{$parent}};
                   4443:                 my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204     raeburn  4444:                 $text .= '<td><table class="LC_data_table">';
1.49      raeburn  4445:                 my ($idxnum,$parent_name,$parent_item);
                   4446:                 my $higher = $depth - 1;
                   4447:                 if ($higher == 0) {
                   4448:                     $parent_name = &escape($parent).'::'.$higher;
                   4449:                 } else {
                   4450:                     if (ref($path) eq 'ARRAY') {
                   4451:                         $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
                   4452:                     }
                   4453:                 }
                   4454:                 $parent_item = 'addcategory_pos_'.$parent_name;
1.48      raeburn  4455:                 for (my $j=0; $j<=$numchildren; $j++) {
1.49      raeburn  4456:                     if ($j < $numchildren) {
1.48      raeburn  4457:                         $name = $cats->[$depth]{$parent}[$j];
                   4458:                         $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49      raeburn  4459:                         $idxnum = $idx->{$item};
                   4460:                     } else {
                   4461:                         $name = $parent_name;
                   4462:                         $item = $parent_item;
1.48      raeburn  4463:                     }
1.49      raeburn  4464:                     $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
                   4465:                     $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48      raeburn  4466:                     for (my $i=0; $i<=$numchildren; $i++) {
                   4467:                         my $vpos = $i+1;
                   4468:                         my $selstr;
                   4469:                         if ($j == $i) {
                   4470:                             $selstr = ' selected="selected" ';
                   4471:                         }
                   4472:                         $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
                   4473:                     }
                   4474:                     $text .= '</select>&nbsp;';
                   4475:                     if ($j < $numchildren) {
                   4476:                         my $deeper = $depth+1;
                   4477:                         $text .= $name.'&nbsp;'
                   4478:                                  .'<label><input type="checkbox" name="deletecategory" value="'
                   4479:                                  .$item.'" />'.&mt('Delete').'</label></span></td><td>';
                   4480:                         if(ref($path) eq 'ARRAY') {
                   4481:                             push(@{$path},$name);
1.49      raeburn  4482:                             $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48      raeburn  4483:                             pop(@{$path});
                   4484:                         }
                   4485:                     } else {
1.59      bisitz   4486:                         $text .= &mt('Add subcategory:').'&nbsp;</span><input type="textbox" size="20" name="addcategory_name_';
1.48      raeburn  4487:                         if ($j == $numchildren) {
                   4488:                             $text .= $name;
                   4489:                         } else {
                   4490:                             $text .= $item;
                   4491:                         }
                   4492:                         $text .= '" value="" />';
                   4493:                     }
                   4494:                     $text .= '</td></tr>';
                   4495:                 }
                   4496:                 $text .= '</table></td>';
                   4497:             } else {
                   4498:                 my $higher = $depth-1;
                   4499:                 if ($higher == 0) {
                   4500:                     $name = &escape($parent).'::'.$higher;
                   4501:                 } else {
                   4502:                     if (ref($path) eq 'ARRAY') {
                   4503:                         $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
                   4504:                     }
                   4505:                 }
                   4506:                 my $colspan;
                   4507:                 if ($parent ne 'instcode') {
                   4508:                     $colspan = $maxdepth - $depth - 1;
                   4509:                     $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
                   4510:                 }
                   4511:             }
                   4512:         }
                   4513:     }
                   4514:     return $text;
                   4515: }
                   4516: 
1.33      raeburn  4517: sub modifiable_userdata_row {
1.63      raeburn  4518:     my ($context,$role,$settings,$numinrow,$rowcount,$usertypes) = @_;
1.33      raeburn  4519:     my $rolename;
1.63      raeburn  4520:     if ($context eq 'selfcreate') {
                   4521:         if (ref($usertypes) eq 'HASH') {
                   4522:             $rolename = $usertypes->{$role};
                   4523:         } else {
                   4524:             $rolename = $role;
                   4525:         }
1.33      raeburn  4526:     } else {
1.63      raeburn  4527:         if ($role eq 'cr') {
                   4528:             $rolename = &mt('Custom role');
                   4529:         } else {
                   4530:             $rolename = &Apache::lonnet::plaintext($role);
                   4531:         }
1.33      raeburn  4532:     }
                   4533:     my @fields = ('lastname','firstname','middlename','generation',
                   4534:                   'permanentemail','id');
                   4535:     my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
                   4536:     my $output;
                   4537:     my $css_class = $rowcount%2?' class="LC_odd_row"':'';
                   4538:     $output = '<tr '.$css_class.'>'.
                   4539:               '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
                   4540:               '<td class="LC_left_item" colspan="2"><table>';
                   4541:     my $rem;
                   4542:     my %checks;
                   4543:     if (ref($settings) eq 'HASH') {
                   4544:         if (ref($settings->{$context}) eq 'HASH') {
                   4545:             if (ref($settings->{$context}->{$role}) eq 'HASH') {
                   4546:                 foreach my $field (@fields) {
                   4547:                     if ($settings->{$context}->{$role}->{$field}) {
                   4548:                         $checks{$field} = ' checked="checked" ';
                   4549:                     }
                   4550:                 }
                   4551:             }
                   4552:         }
                   4553:     }
                   4554:     for (my $i=0; $i<@fields; $i++) {
                   4555:         my $rem = $i%($numinrow);
                   4556:         if ($rem == 0) {
                   4557:             if ($i > 0) {
                   4558:                 $output .= '</tr>';
                   4559:             }
                   4560:             $output .= '<tr>';
                   4561:         }
                   4562:         my $check = ' ';
                   4563:         if (exists($checks{$fields[$i]})) {
                   4564:             $check = $checks{$fields[$i]}
                   4565:         } else {
                   4566:             if ($role eq 'st') {
                   4567:                 if (ref($settings) ne 'HASH') {
                   4568:                     $check = ' checked="checked" '; 
                   4569:                 }
                   4570:             }
                   4571:         }
                   4572:         $output .= '<td class="LC_left_item">'.
                   4573:                    '<span class="LC_nobreak"><label>'.
                   4574:                    '<input type="checkbox" name="canmodify_'.$role.'" '.
                   4575:                    'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
                   4576:                    '</label></span></td>';
                   4577:         $rem = @fields%($numinrow);
                   4578:     }
                   4579:     my $colsleft = $numinrow - $rem;
                   4580:     if ($colsleft > 1 ) {
                   4581:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   4582:                    '&nbsp;</td>';
                   4583:     } elsif ($colsleft == 1) {
                   4584:         $output .= '<td class="LC_left_item">&nbsp;</td>';
                   4585:     }
                   4586:     $output .= '</tr></table></td></tr>';
                   4587:     return $output;
                   4588: }
1.28      raeburn  4589: 
1.93      raeburn  4590: sub insttypes_row {
                   4591:     my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context) = @_;
                   4592:     my %lt = &Apache::lonlocal::texthash (
                   4593:                       cansearch => 'Users allowed to search',
                   4594:                       statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131     raeburn  4595:                       lockablenames => 'User preference to lock name',
1.93      raeburn  4596:              );
                   4597:     my $showdom;
                   4598:     if ($context eq 'cansearch') {
                   4599:         $showdom = ' ('.$dom.')';
                   4600:     }
1.165     raeburn  4601:     my $class = 'LC_left_item';
                   4602:     if ($context eq 'statustocreate') {
                   4603:         $class = 'LC_right_item';
                   4604:     }
1.25      raeburn  4605:     my $output =  '<tr class="LC_odd_row">'.
1.93      raeburn  4606:                   '<td>'.$lt{$context}.$showdom.
1.165     raeburn  4607:                   '</td><td class="'.$class.'" colspan="2"><table>';
1.26      raeburn  4608:     my $rem;
                   4609:     if (ref($types) eq 'ARRAY') {
                   4610:         for (my $i=0; $i<@{$types}; $i++) {
                   4611:             if (defined($usertypes->{$types->[$i]})) {
                   4612:                 my $rem = $i%($numinrow);
                   4613:                 if ($rem == 0) {
                   4614:                     if ($i > 0) {
                   4615:                         $output .= '</tr>';
                   4616:                     }
                   4617:                     $output .= '<tr>';
1.23      raeburn  4618:                 }
1.26      raeburn  4619:                 my $check = ' ';
1.99      raeburn  4620:                 if (ref($settings) eq 'HASH') {
                   4621:                     if (ref($settings->{$context}) eq 'ARRAY') {
                   4622:                         if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
                   4623:                             $check = ' checked="checked" ';
                   4624:                         }
                   4625:                     } elsif ($context eq 'statustocreate') {
1.26      raeburn  4626:                         $check = ' checked="checked" ';
                   4627:                     }
1.23      raeburn  4628:                 }
1.26      raeburn  4629:                 $output .= '<td class="LC_left_item">'.
                   4630:                            '<span class="LC_nobreak"><label>'.
1.93      raeburn  4631:                            '<input type="checkbox" name="'.$context.'" '.
1.26      raeburn  4632:                            'value="'.$types->[$i].'"'.$check.'/>'.
                   4633:                            $usertypes->{$types->[$i]}.'</label></span></td>';
1.23      raeburn  4634:             }
                   4635:         }
1.26      raeburn  4636:         $rem = @{$types}%($numinrow);
1.23      raeburn  4637:     }
                   4638:     my $colsleft = $numinrow - $rem;
1.131     raeburn  4639:     if (($rem == 0) && (@{$types} > 0)) {
                   4640:         $output .= '<tr>';
                   4641:     }
1.23      raeburn  4642:     if ($colsleft > 1) {
1.25      raeburn  4643:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23      raeburn  4644:     } else {
1.25      raeburn  4645:         $output .= '<td class="LC_left_item">';
1.23      raeburn  4646:     }
                   4647:     my $defcheck = ' ';
1.99      raeburn  4648:     if (ref($settings) eq 'HASH') {  
                   4649:         if (ref($settings->{$context}) eq 'ARRAY') {
                   4650:             if (grep(/^default$/,@{$settings->{$context}})) {
                   4651:                 $defcheck = ' checked="checked" ';
                   4652:             }
                   4653:         } elsif ($context eq 'statustocreate') {
1.26      raeburn  4654:             $defcheck = ' checked="checked" ';
                   4655:         }
1.23      raeburn  4656:     }
1.25      raeburn  4657:     $output .= '<span class="LC_nobreak"><label>'.
1.93      raeburn  4658:                '<input type="checkbox" name="'.$context.'" '.
1.25      raeburn  4659:                'value="default"'.$defcheck.'/>'.
                   4660:                $othertitle.'</label></span></td>'.
                   4661:                '</tr></table></td></tr>';
                   4662:     return $output;
1.23      raeburn  4663: }
                   4664: 
                   4665: sub sorted_searchtitles {
                   4666:     my %searchtitles = &Apache::lonlocal::texthash(
                   4667:                          'uname' => 'username',
                   4668:                          'lastname' => 'last name',
                   4669:                          'lastfirst' => 'last name, first name',
                   4670:                      );
                   4671:     my @titleorder = ('uname','lastname','lastfirst');
                   4672:     return (\%searchtitles,\@titleorder);
                   4673: }
                   4674: 
1.25      raeburn  4675: sub sorted_searchtypes {
                   4676:     my %srchtypes_desc = (
                   4677:                            exact    => 'is exact match',
                   4678:                            contains => 'contains ..',
                   4679:                            begins   => 'begins with ..',
                   4680:                          );
                   4681:     my @srchtypeorder = ('exact','begins','contains');
                   4682:     return (\%srchtypes_desc,\@srchtypeorder);
                   4683: }
                   4684: 
1.3       raeburn  4685: sub usertype_update_row {
                   4686:     my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
                   4687:     my $datatable;
                   4688:     my $numinrow = 4;
                   4689:     foreach my $type (@{$types}) {
                   4690:         if (defined($usertypes->{$type})) {
                   4691:             $$rownums ++;
                   4692:             my $css_class = $$rownums%2?' class="LC_odd_row"':'';
                   4693:             $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
                   4694:                           '</td><td class="LC_left_item"><table>';
                   4695:             for (my $i=0; $i<@{$fields}; $i++) {
                   4696:                 my $rem = $i%($numinrow);
                   4697:                 if ($rem == 0) {
                   4698:                     if ($i > 0) {
                   4699:                         $datatable .= '</tr>';
                   4700:                     }
                   4701:                     $datatable .= '<tr>';
                   4702:                 }
                   4703:                 my $check = ' ';
1.39      raeburn  4704:                 if (ref($settings) eq 'HASH') {
                   4705:                     if (ref($settings->{'fields'}) eq 'HASH') {
                   4706:                         if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
                   4707:                             if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
                   4708:                                 $check = ' checked="checked" ';
                   4709:                             }
1.3       raeburn  4710:                         }
                   4711:                     }
                   4712:                 }
                   4713: 
                   4714:                 if ($i == @{$fields}-1) {
                   4715:                     my $colsleft = $numinrow - $rem;
                   4716:                     if ($colsleft > 1) {
                   4717:                         $datatable .= '<td colspan="'.$colsleft.'">';
                   4718:                     } else {
                   4719:                         $datatable .= '<td>';
                   4720:                     }
                   4721:                 } else {
                   4722:                     $datatable .= '<td>';
                   4723:                 }
1.8       raeburn  4724:                 $datatable .= '<span class="LC_nobreak"><label>'.
                   4725:                               '<input type="checkbox" name="updateable_'.$type.
                   4726:                               '_'.$fields->[$i].'" value="1"'.$check.'/>'.
                   4727:                               $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3       raeburn  4728:             }
                   4729:             $datatable .= '</tr></table></td></tr>';
                   4730:         }
                   4731:     }
                   4732:     return $datatable;
1.1       raeburn  4733: }
                   4734: 
                   4735: sub modify_login {
1.205     raeburn  4736:     my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168     raeburn  4737:     my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
                   4738:         %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
                   4739:     %title = ( coursecatalog => 'Display course catalog',
                   4740:                adminmail => 'Display administrator E-mail address',
1.188     raeburn  4741:                helpdesk  => 'Display "Contact Helpdesk" link',
1.168     raeburn  4742:                newuser => 'Link for visitors to create a user account',
                   4743:                loginheader => 'Log-in box header');
                   4744:     @offon = ('off','on');
1.112     raeburn  4745:     if (ref($domconfig{login}) eq 'HASH') {
                   4746:         if (ref($domconfig{login}{loginvia}) eq 'HASH') {
                   4747:             foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
                   4748:                 $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
                   4749:             }
                   4750:         }
                   4751:     }
1.9       raeburn  4752:     ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
                   4753:                                            \%domconfig,\%loginhash);
1.188     raeburn  4754:     my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42      raeburn  4755:     foreach my $item (@toggles) {
                   4756:         $loginhash{login}{$item} = $env{'form.'.$item};
                   4757:     }
1.41      raeburn  4758:     $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6       raeburn  4759:     if (ref($colchanges{'login'}) eq 'HASH') {  
                   4760:         $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
                   4761:                                          \%loginhash);
                   4762:     }
1.110     raeburn  4763: 
1.149     raeburn  4764:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.128     raeburn  4765:     my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110     raeburn  4766:     if (keys(%servers) > 1) {
                   4767:         foreach my $lonhost (keys(%servers)) {
1.128     raeburn  4768:             next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
                   4769:             if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
                   4770:                 if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
                   4771:                     $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
                   4772:                 } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
                   4773:                     if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
                   4774:                         $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
                   4775:                         $changes{'loginvia'}{$lonhost} = 1;
                   4776:                     } else {
                   4777:                         $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
                   4778:                         $changes{'loginvia'}{$lonhost} = 1;
                   4779:                     }
                   4780:                 } else {
                   4781:                     if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
                   4782:                         $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
                   4783:                         $changes{'loginvia'}{$lonhost} = 1;
                   4784:                     }
                   4785:                 }
                   4786:                 if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
                   4787:                     foreach my $item (@loginvia_attribs) {
                   4788:                         $loginhash{login}{loginvia}{$lonhost}{$item} = '';
                   4789:                     }
                   4790:                 } else {
                   4791:                     foreach my $item (@loginvia_attribs) {
                   4792:                         my $new = $env{'form.'.$lonhost.'_'.$item};
                   4793:                         if (($item eq 'serverpath') && ($new eq 'custom')) {
                   4794:                             $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
                   4795:                             if ($env{'form.'.$lonhost.'_custompath'} eq '') {
                   4796:                                 $new = '/';
                   4797:                             }
                   4798:                         }
                   4799:                         if (($item eq 'custompath') && 
                   4800:                             ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
                   4801:                             $new = '';
                   4802:                         }
                   4803:                         if ($new ne $curr_loginvia{$lonhost}{$item}) {
                   4804:                             $changes{'loginvia'}{$lonhost} = 1;
                   4805:                         }
                   4806:                         if ($item eq 'exempt') {
                   4807:                             $new =~ s/^\s+//;
                   4808:                             $new =~ s/\s+$//;
                   4809:                             my @poss_ips = split(/\s*[,:]\s*/,$new);
                   4810:                             my @okips;
                   4811:                             foreach my $ip (@poss_ips) {
                   4812:                                 if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
                   4813:                                     if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
                   4814:                                         push(@okips,$ip); 
                   4815:                                     }
                   4816:                                 }
                   4817:                             }
                   4818:                             if (@okips > 0) {
                   4819:                                 $new = join(',',@okips); 
                   4820:                             } else {
                   4821:                                 $new = ''; 
                   4822:                             }
                   4823:                         }
                   4824:                         $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
                   4825:                     }
                   4826:                 }
1.112     raeburn  4827:             } else {
1.128     raeburn  4828:                 if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
                   4829:                     $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112     raeburn  4830:                     $changes{'loginvia'}{$lonhost} = 1;
1.128     raeburn  4831:                     foreach my $item (@loginvia_attribs) {
                   4832:                         my $new = $env{'form.'.$lonhost.'_'.$item};
                   4833:                         if (($item eq 'serverpath') && ($new eq 'custom')) {
                   4834:                             if ($env{'form.'.$lonhost.'_custompath'} eq '') {
                   4835:                                 $new = '/';
                   4836:                             }
                   4837:                         }
                   4838:                         if (($item eq 'custompath') && 
                   4839:                             ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
                   4840:                             $new = '';
                   4841:                         }
                   4842:                         $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
                   4843:                     }
1.110     raeburn  4844:                 }
                   4845:             }
                   4846:         }
                   4847:     }
1.119     raeburn  4848: 
1.168     raeburn  4849:     my $servadm = $r->dir_config('lonAdmEMail');
                   4850:     my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
                   4851:     if (ref($domconfig{'login'}) eq 'HASH') {
                   4852:         if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
                   4853:             foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
                   4854:                 if ($lang eq 'nolang') {
                   4855:                     push(@currlangs,$lang);
                   4856:                 } elsif (defined($langchoices{$lang})) {
                   4857:                     push(@currlangs,$lang);
                   4858:                 } else {
                   4859:                     next;
                   4860:                 }
                   4861:             }
                   4862:         }
                   4863:     }
                   4864:     my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
                   4865:     if (@currlangs > 0) {
                   4866:         foreach my $lang (@currlangs) {
                   4867:             if (grep(/^\Q$lang\E$/,@delurls)) {
                   4868:                 $changes{'helpurl'}{$lang} = 1;
                   4869:             } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
                   4870:                 $changes{'helpurl'}{$lang} = 1;
                   4871:                 $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
                   4872:                 push(@newlangs,$lang);
                   4873:             } else {
                   4874:                 $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
                   4875:             }
                   4876:         }
                   4877:     }
                   4878:     unless (grep(/^nolang$/,@currlangs)) {
                   4879:         if ($env{'form.loginhelpurl_nolang.filename'}) {
                   4880:             $changes{'helpurl'}{'nolang'} = 1;
                   4881:             $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
                   4882:             push(@newlangs,'nolang');
                   4883:         }
                   4884:     }
                   4885:     if ($env{'form.loginhelpurl_add_lang'}) {
                   4886:         if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
                   4887:             ($env{'form.loginhelpurl_add_file.filename'})) {
                   4888:             $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
                   4889:             $addedfile = $env{'form.loginhelpurl_add_lang'};
                   4890:         }
                   4891:     }
                   4892:     if ((@newlangs > 0) || ($addedfile)) {
                   4893:         my $error;
                   4894:         my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
                   4895:         if ($configuserok eq 'ok') {
                   4896:             if ($switchserver) {
                   4897:                 $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
                   4898:             } elsif ($author_ok eq 'ok') {
                   4899:                 my @allnew = @newlangs;
                   4900:                 if ($addedfile ne '') {
                   4901:                     push(@allnew,$addedfile);
                   4902:                 }
                   4903:                 foreach my $lang (@allnew) {
                   4904:                     my $formelem = 'loginhelpurl_'.$lang;
                   4905:                     if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
                   4906:                         $formelem = 'loginhelpurl_add_file';
                   4907:                     }
                   4908:                     (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
                   4909:                                                                "help/$lang",'','',$newfile{$lang});
                   4910:                     if ($result eq 'ok') {
                   4911:                         $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
                   4912:                         $changes{'helpurl'}{$lang} = 1;
                   4913:                     } else {
                   4914:                         my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
                   4915:                         $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
                   4916:                         if ((grep(/^\Q$lang\E$/,@currlangs)) && 
                   4917:                             (!grep(/^\Q$lang\E$/,@delurls))) {
                   4918: 
                   4919:                             $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
                   4920:                         }
                   4921:                     }
                   4922:                 }
                   4923:             } else {
                   4924:                 $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);
                   4925:             }
                   4926:         } else {
                   4927:             $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);
                   4928:         }
                   4929:         if ($error) {
                   4930:             &Apache::lonnet::logthis($error);
                   4931:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   4932:         }
                   4933:     }
1.169     raeburn  4934:     &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168     raeburn  4935: 
                   4936:     my $defaulthelpfile = '/adm/loginproblems.html';
                   4937:     my $defaulttext = &mt('Default in use');
                   4938: 
1.1       raeburn  4939:     my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
                   4940:                                              $dom);
                   4941:     if ($putresult eq 'ok') {
1.188     raeburn  4942:         my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42      raeburn  4943:         my %defaultchecked = (
                   4944:                     'coursecatalog' => 'on',
1.188     raeburn  4945:                     'helpdesk'      => 'on',
1.42      raeburn  4946:                     'adminmail'     => 'off',
1.43      raeburn  4947:                     'newuser'       => 'off',
1.42      raeburn  4948:         );
1.55      raeburn  4949:         if (ref($domconfig{'login'}) eq 'HASH') {
                   4950:             foreach my $item (@toggles) {
                   4951:                 if ($defaultchecked{$item} eq 'on') { 
                   4952:                     if (($domconfig{'login'}{$item} eq '0') &&
                   4953:                         ($env{'form.'.$item} eq '1')) {
                   4954:                         $changes{$item} = 1;
                   4955:                     } elsif (($domconfig{'login'}{$item} eq '' ||
                   4956:                               $domconfig{'login'}{$item} eq '1') &&
                   4957:                              ($env{'form.'.$item} eq '0')) {
                   4958:                         $changes{$item} = 1;
                   4959:                     }
                   4960:                 } elsif ($defaultchecked{$item} eq 'off') {
                   4961:                     if (($domconfig{'login'}{$item} eq '1') &&
                   4962:                         ($env{'form.'.$item} eq '0')) {
                   4963:                         $changes{$item} = 1;
                   4964:                     } elsif (($domconfig{'login'}{$item} eq '' ||
                   4965:                               $domconfig{'login'}{$item} eq '0') &&
                   4966:                              ($env{'form.'.$item} eq '1')) {
                   4967:                         $changes{$item} = 1;
                   4968:                     }
1.42      raeburn  4969:                 }
                   4970:             }
1.41      raeburn  4971:         }
1.6       raeburn  4972:         if (keys(%changes) > 0 || $colchgtext) {
1.41      raeburn  4973:             &Apache::loncommon::devalidate_domconfig_cache($dom);
1.205     raeburn  4974:             $$lastactref = 'update';
1.1       raeburn  4975:             $resulttext = &mt('Changes made:').'<ul>';
                   4976:             foreach my $item (sort(keys(%changes))) {
1.135     bisitz   4977:                 if ($item eq 'loginvia') {
1.112     raeburn  4978:                     if (ref($changes{$item}) eq 'HASH') {
                   4979:                         $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
                   4980:                         foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128     raeburn  4981:                             if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
                   4982:                                 if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
                   4983:                                     my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
                   4984:                                     $protocol = 'http' if ($protocol ne 'https');
                   4985:                                     my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
                   4986: 
                   4987:                                     if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
                   4988:                                         $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
                   4989:                                     } else {
                   4990:                                         $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'}; 
                   4991:                                     }
                   4992:                                     $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
                   4993:                                     if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
                   4994:                                         $resulttext .= '&nbsp;'.&mt('No redirection for clients from following IPs:').'&nbsp;'.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
                   4995:                                     }
                   4996:                                     $resulttext .= '</li>';
                   4997:                                 } else {
                   4998:                                     $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
                   4999:                                 }
1.112     raeburn  5000:                             } else {
1.128     raeburn  5001:                                 $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112     raeburn  5002:                             }
                   5003:                         }
1.128     raeburn  5004:                         $resulttext .= '</ul></li>';
1.112     raeburn  5005:                     }
1.168     raeburn  5006:                 } elsif ($item eq 'helpurl') {
                   5007:                     if (ref($changes{$item}) eq 'HASH') {
                   5008:                         foreach my $lang (sort(keys(%{$changes{$item}}))) {
                   5009:                             if (grep(/^\Q$lang\E$/,@delurls)) {
                   5010:                                 my ($chg,$link);
                   5011:                                 $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
                   5012:                                 if ($lang eq 'nolang') {
                   5013:                                     $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
                   5014:                                 } else {
                   5015:                                     $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
                   5016:                                 }
                   5017:                                 $resulttext .= '<li>'.$chg.'</li>';
                   5018:                             } else {
                   5019:                                 my $chg;
                   5020:                                 if ($lang eq 'nolang') {
                   5021:                                     $chg = &mt('custom log-in help file for no preferred language');
                   5022:                                 } else {
                   5023:                                     $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
                   5024:                                 }
                   5025:                                 $resulttext .= '<li>'.&Apache::loncommon::modal_link(
                   5026:                                                       $loginhash{'login'}{'helpurl'}{$lang}.
                   5027:                                                       '?inhibitmenu=yes',$chg,600,500).
                   5028:                                                '</li>';
                   5029:                             }
                   5030:                         }
                   5031:                     }
1.169     raeburn  5032:                 } elsif ($item eq 'captcha') {
                   5033:                     if (ref($loginhash{'login'}) eq 'HASH') {
                   5034:                         my $chgtxt; 
                   5035:                         if ($loginhash{'login'}{$item} eq 'notused') {
                   5036:                             $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
                   5037:                         } else {
                   5038:                             my %captchas = &captcha_phrases();
                   5039:                             if ($captchas{$loginhash{'login'}{$item}}) {
                   5040:                                 $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
                   5041:                             } else {
                   5042:                                 $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
                   5043:                             }
                   5044:                         }
                   5045:                         $resulttext .= '<li>'.$chgtxt.'</li>';
                   5046:                     }
                   5047:                 } elsif ($item eq 'recaptchakeys') {
                   5048:                     if (ref($loginhash{'login'}) eq 'HASH') {
                   5049:                         my ($privkey,$pubkey);
                   5050:                         if (ref($loginhash{'login'}{$item}) eq 'HASH') {
                   5051:                             $pubkey = $loginhash{'login'}{$item}{'public'};
                   5052:                             $privkey = $loginhash{'login'}{$item}{'private'};
                   5053:                         }
                   5054:                         my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
                   5055:                         if (!$pubkey) {
                   5056:                             $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
                   5057:                         } else {
                   5058:                             $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
                   5059:                         }
                   5060:                         if (!$privkey) {
                   5061:                             $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
                   5062:                         } else {
                   5063:                             $chgtxt .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
                   5064:                         }
                   5065:                         $chgtxt .= '</ul>';
                   5066:                         $resulttext .= '<li>'.$chgtxt.'</li>';
                   5067:                     }
1.41      raeburn  5068:                 } else {
                   5069:                     $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
                   5070:                 }
1.1       raeburn  5071:             }
1.6       raeburn  5072:             $resulttext .= $colchgtext.'</ul>';
1.1       raeburn  5073:         } else {
                   5074:             $resulttext = &mt('No changes made to log-in page settings');
                   5075:         }
                   5076:     } else {
1.11      albertel 5077:         $resulttext = '<span class="LC_error">'.
                   5078: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  5079:     }
1.6       raeburn  5080:     if ($errors) {
1.9       raeburn  5081:         $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6       raeburn  5082:                        $errors.'</ul>';
                   5083:     }
                   5084:     return $resulttext;
                   5085: }
                   5086: 
                   5087: sub color_font_choices {
                   5088:     my %choices =
                   5089:         &Apache::lonlocal::texthash (
                   5090:             img => "Header",
                   5091:             bgs => "Background colors",
                   5092:             links => "Link colors",
1.55      raeburn  5093:             images => "Images",
1.6       raeburn  5094:             font => "Font color",
1.201     raeburn  5095:             fontmenu => "Font menu",
1.76      raeburn  5096:             pgbg => "Page",
1.6       raeburn  5097:             tabbg => "Header",
                   5098:             sidebg => "Border",
                   5099:             link => "Link",
                   5100:             alink => "Active link",
                   5101:             vlink => "Visited link",
                   5102:         );
                   5103:     return %choices;
                   5104: }
                   5105: 
                   5106: sub modify_rolecolors {
1.205     raeburn  5107:     my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6       raeburn  5108:     my ($resulttext,%rolehash);
                   5109:     $rolehash{'rolecolors'} = {};
1.55      raeburn  5110:     if (ref($domconfig{'rolecolors'}) ne 'HASH') {
                   5111:         if ($domconfig{'rolecolors'} eq '') {
                   5112:             $domconfig{'rolecolors'} = {};
                   5113:         }
                   5114:     }
1.9       raeburn  5115:     my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6       raeburn  5116:                          $domconfig{'rolecolors'},$rolehash{'rolecolors'});
                   5117:     my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
                   5118:                                              $dom);
                   5119:     if ($putresult eq 'ok') {
                   5120:         if (keys(%changes) > 0) {
1.41      raeburn  5121:             &Apache::loncommon::devalidate_domconfig_cache($dom);
1.205     raeburn  5122:             $$lastactref = 'update';
1.6       raeburn  5123:             $resulttext = &display_colorchgs($dom,\%changes,$roles,
                   5124:                                              $rolehash{'rolecolors'});
                   5125:         } else {
                   5126:             $resulttext = &mt('No changes made to default color schemes');
                   5127:         }
                   5128:     } else {
1.11      albertel 5129:         $resulttext = '<span class="LC_error">'.
                   5130: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.6       raeburn  5131:     }
                   5132:     if ($errors) {
                   5133:         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
                   5134:                        $errors.'</ul>';
                   5135:     }
                   5136:     return $resulttext;
                   5137: }
                   5138: 
                   5139: sub modify_colors {
1.9       raeburn  5140:     my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12      raeburn  5141:     my (%changes,%choices);
1.51      raeburn  5142:     my @bgs;
1.6       raeburn  5143:     my @links = ('link','alink','vlink');
1.41      raeburn  5144:     my @logintext;
1.6       raeburn  5145:     my @images;
                   5146:     my $servadm = $r->dir_config('lonAdmEMail');
                   5147:     my $errors;
1.200     raeburn  5148:     my %defaults;
1.6       raeburn  5149:     foreach my $role (@{$roles}) {
                   5150:         if ($role eq 'login') {
1.12      raeburn  5151:             %choices = &login_choices();
1.41      raeburn  5152:             @logintext = ('textcol','bgcol');
1.12      raeburn  5153:         } else {
                   5154:             %choices = &color_font_choices();
                   5155:         }
                   5156:         if ($role eq 'login') {
1.41      raeburn  5157:             @images = ('img','logo','domlogo','login');
1.51      raeburn  5158:             @bgs = ('pgbg','mainbg','sidebg');
1.6       raeburn  5159:         } else {
                   5160:             @images = ('img');
1.200     raeburn  5161:             @bgs = ('pgbg','tabbg','sidebg');
                   5162:         }
                   5163:         my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
                   5164:         unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
                   5165:             $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
                   5166:         }
                   5167:         if ($role eq 'login') {
                   5168:             foreach my $item (@logintext) {
                   5169:                 unless ($env{'form.'.$role.'_'.$item} eq  $defaults{'logintext'}{$item}) {
                   5170:                     $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
                   5171:                 }
                   5172:             }
                   5173:         } else {
                   5174:             unless($env{'form.'.$role.'_fontmenu'} eq $defaults{'fontmenu'}) {
                   5175:                 $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
                   5176:             }
1.6       raeburn  5177:         }
1.200     raeburn  5178:         foreach my $item (@bgs) {
                   5179:             unless ($env{'form.'.$role.'_'.$item} eq $defaults{'bgs'}{$item} ) {
                   5180:                 $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
                   5181:             }
                   5182:         }
                   5183:         foreach my $item (@links) {
                   5184:             unless ($env{'form.'.$role.'_'.$item} eq  $defaults{'links'}{$item}) {
                   5185:                 $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
                   5186:             }
1.6       raeburn  5187:         }
1.46      raeburn  5188:         my ($configuserok,$author_ok,$switchserver) = 
                   5189:             &config_check($dom,$confname,$servadm);
1.9       raeburn  5190:         my ($width,$height) = &thumb_dimensions();
1.40      raeburn  5191:         if (ref($domconfig->{$role}) ne 'HASH') {
                   5192:             $domconfig->{$role} = {};
                   5193:         }
1.8       raeburn  5194:         foreach my $img (@images) {
1.70      raeburn  5195:             if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {  
                   5196:                 if (defined($env{'form.login_showlogo_'.$img})) {
                   5197:                     $confhash->{$role}{'showlogo'}{$img} = 1;
                   5198:                 } else { 
                   5199:                     $confhash->{$role}{'showlogo'}{$img} = 0;
                   5200:                 }
                   5201:             } 
1.18      albertel 5202: 	    if ( ! $env{'form.'.$role.'_'.$img.'.filename'} 
                   5203: 		 && !defined($domconfig->{$role}{$img})
                   5204: 		 && !$env{'form.'.$role.'_del_'.$img}
                   5205: 		 && $env{'form.'.$role.'_import_'.$img}) {
                   5206: 		# import the old configured image from the .tab setting
                   5207: 		# if they haven't provided a new one 
                   5208: 		$domconfig->{$role}{$img} = 
                   5209: 		    $env{'form.'.$role.'_import_'.$img};
                   5210: 	    }
1.6       raeburn  5211:             if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9       raeburn  5212:                 my $error;
1.6       raeburn  5213:                 if ($configuserok eq 'ok') {
1.9       raeburn  5214:                     if ($switchserver) {
1.12      raeburn  5215:                         $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9       raeburn  5216:                     } else {
                   5217:                         if ($author_ok eq 'ok') {
                   5218:                             my ($result,$logourl) = 
                   5219:                                 &publishlogo($r,'upload',$role.'_'.$img,
                   5220:                                            $dom,$confname,$img,$width,$height);
                   5221:                             if ($result eq 'ok') {
                   5222:                                 $confhash->{$role}{$img} = $logourl;
1.12      raeburn  5223:                                 $changes{$role}{'images'}{$img} = 1;
1.9       raeburn  5224:                             } else {
1.12      raeburn  5225:                                 $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  5226:                             }
                   5227:                         } else {
1.46      raeburn  5228:                             $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  5229:                         }
                   5230:                     }
                   5231:                 } else {
1.46      raeburn  5232:                     $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  5233:                 }
                   5234:                 if ($error) {
1.8       raeburn  5235:                     &Apache::lonnet::logthis($error);
1.11      albertel 5236:                     $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8       raeburn  5237:                 }
                   5238:             } elsif ($domconfig->{$role}{$img} ne '') {
1.9       raeburn  5239:                 if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
                   5240:                     my $error;
                   5241:                     if ($configuserok eq 'ok') {
                   5242: # is confname an author?
                   5243:                         if ($switchserver eq '') {
                   5244:                             if ($author_ok eq 'ok') {
                   5245:                                 my ($result,$logourl) = 
                   5246:                                &publishlogo($r,'copy',$domconfig->{$role}{$img},
                   5247:                                             $dom,$confname,$img,$width,$height);
                   5248:                                 if ($result eq 'ok') {
                   5249:                                     $confhash->{$role}{$img} = $logourl;
1.18      albertel 5250: 				    $changes{$role}{'images'}{$img} = 1;
1.9       raeburn  5251:                                 }
                   5252:                             }
                   5253:                         }
                   5254:                     }
1.6       raeburn  5255:                 }
                   5256:             }
                   5257:         }
                   5258:         if (ref($domconfig) eq 'HASH') {
                   5259:             if (ref($domconfig->{$role}) eq 'HASH') {
                   5260:                 foreach my $img (@images) {
                   5261:                     if ($domconfig->{$role}{$img} ne '') {
                   5262:                         if ($env{'form.'.$role.'_del_'.$img}) {
                   5263:                             $confhash->{$role}{$img} = '';
1.12      raeburn  5264:                             $changes{$role}{'images'}{$img} = 1;
1.6       raeburn  5265:                         } else {
1.9       raeburn  5266:                             if ($confhash->{$role}{$img} eq '') {
                   5267:                                 $confhash->{$role}{$img} = $domconfig->{$role}{$img};
                   5268:                             }
1.6       raeburn  5269:                         }
                   5270:                     } else {
                   5271:                         if ($env{'form.'.$role.'_del_'.$img}) {
                   5272:                             $confhash->{$role}{$img} = '';
1.12      raeburn  5273:                             $changes{$role}{'images'}{$img} = 1;
1.6       raeburn  5274:                         } 
                   5275:                     }
1.70      raeburn  5276:                     if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
                   5277:                         if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
                   5278:                             if ($confhash->{$role}{'showlogo'}{$img} ne 
                   5279:                                 $domconfig->{$role}{'showlogo'}{$img}) {
                   5280:                                 $changes{$role}{'showlogo'}{$img} = 1; 
                   5281:                             }
                   5282:                         } else {
                   5283:                             if ($confhash->{$role}{'showlogo'}{$img} == 0) {
                   5284:                                 $changes{$role}{'showlogo'}{$img} = 1;
                   5285:                             }
                   5286:                         }
                   5287:                     }
                   5288:                 }
1.6       raeburn  5289:                 if ($domconfig->{$role}{'font'} ne '') {
                   5290:                     if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
                   5291:                         $changes{$role}{'font'} = 1;
                   5292:                     }
                   5293:                 } else {
                   5294:                     if ($confhash->{$role}{'font'}) {
                   5295:                         $changes{$role}{'font'} = 1;
                   5296:                     }
                   5297:                 }
1.107     raeburn  5298:                 if ($role ne 'login') {
                   5299:                     if ($domconfig->{$role}{'fontmenu'} ne '') {
                   5300:                         if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
                   5301:                             $changes{$role}{'fontmenu'} = 1;
                   5302:                         }
                   5303:                     } else {
                   5304:                         if ($confhash->{$role}{'fontmenu'}) {
                   5305:                             $changes{$role}{'fontmenu'} = 1;
                   5306:                         }
1.97      tempelho 5307:                     }
                   5308:                 }
1.6       raeburn  5309:                 foreach my $item (@bgs) {
                   5310:                     if ($domconfig->{$role}{$item} ne '') {
                   5311:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
                   5312:                             $changes{$role}{'bgs'}{$item} = 1;
                   5313:                         } 
                   5314:                     } else {
                   5315:                         if ($confhash->{$role}{$item}) {
                   5316:                             $changes{$role}{'bgs'}{$item} = 1;
                   5317:                         }
                   5318:                     }
                   5319:                 }
                   5320:                 foreach my $item (@links) {
                   5321:                     if ($domconfig->{$role}{$item} ne '') {
                   5322:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
                   5323:                             $changes{$role}{'links'}{$item} = 1;
                   5324:                         }
                   5325:                     } else {
                   5326:                         if ($confhash->{$role}{$item}) {
                   5327:                             $changes{$role}{'links'}{$item} = 1;
                   5328:                         }
                   5329:                     }
                   5330:                 }
1.41      raeburn  5331:                 foreach my $item (@logintext) {
                   5332:                     if ($domconfig->{$role}{$item} ne '') {
                   5333:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
                   5334:                             $changes{$role}{'logintext'}{$item} = 1;
                   5335:                         }
                   5336:                     } else {
                   5337:                         if ($confhash->{$role}{$item}) {
                   5338:                             $changes{$role}{'logintext'}{$item} = 1;
                   5339:                         }
                   5340:                     }
                   5341:                 }
1.6       raeburn  5342:             } else {
                   5343:                 &default_change_checker($role,\@images,\@links,\@bgs,
1.41      raeburn  5344:                                         \@logintext,$confhash,\%changes); 
1.6       raeburn  5345:             }
                   5346:         } else {
                   5347:             &default_change_checker($role,\@images,\@links,\@bgs,
1.41      raeburn  5348:                                     \@logintext,$confhash,\%changes); 
1.6       raeburn  5349:         }
                   5350:     }
                   5351:     return ($errors,%changes);
                   5352: }
                   5353: 
1.46      raeburn  5354: sub config_check {
                   5355:     my ($dom,$confname,$servadm) = @_;
                   5356:     my ($configuserok,$author_ok,$switchserver,%currroles);
                   5357:     my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
                   5358:     ($configuserok,%currroles) = &check_configuser($uhome,$dom,
                   5359:                                                    $confname,$servadm);
                   5360:     if ($configuserok eq 'ok') {
                   5361:         $switchserver = &check_switchserver($dom,$confname);
                   5362:         if ($switchserver eq '') {
                   5363:             $author_ok = &check_authorstatus($dom,$confname,%currroles);
                   5364:         }
                   5365:     }
                   5366:     return ($configuserok,$author_ok,$switchserver);
                   5367: }
                   5368: 
1.6       raeburn  5369: sub default_change_checker {
1.41      raeburn  5370:     my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6       raeburn  5371:     foreach my $item (@{$links}) {
                   5372:         if ($confhash->{$role}{$item}) {
                   5373:             $changes->{$role}{'links'}{$item} = 1;
                   5374:         }
                   5375:     }
                   5376:     foreach my $item (@{$bgs}) {
                   5377:         if ($confhash->{$role}{$item}) {
                   5378:             $changes->{$role}{'bgs'}{$item} = 1;
                   5379:         }
                   5380:     }
1.41      raeburn  5381:     foreach my $item (@{$logintext}) {
                   5382:         if ($confhash->{$role}{$item}) {
                   5383:             $changes->{$role}{'logintext'}{$item} = 1;
                   5384:         }
                   5385:     }
1.6       raeburn  5386:     foreach my $img (@{$images}) {
                   5387:         if ($env{'form.'.$role.'_del_'.$img}) {
                   5388:             $confhash->{$role}{$img} = '';
1.12      raeburn  5389:             $changes->{$role}{'images'}{$img} = 1;
1.6       raeburn  5390:         }
1.70      raeburn  5391:         if ($role eq 'login') {
                   5392:             if ($confhash->{$role}{'showlogo'}{$img} == 0) {
                   5393:                 $changes->{$role}{'showlogo'}{$img} = 1;
                   5394:             }
                   5395:         }
1.6       raeburn  5396:     }
                   5397:     if ($confhash->{$role}{'font'}) {
                   5398:         $changes->{$role}{'font'} = 1;
                   5399:     }
1.48      raeburn  5400: }
1.6       raeburn  5401: 
                   5402: sub display_colorchgs {
                   5403:     my ($dom,$changes,$roles,$confhash) = @_;
                   5404:     my (%choices,$resulttext);
                   5405:     if (!grep(/^login$/,@{$roles})) {
                   5406:         $resulttext = &mt('Changes made:').'<br />';
                   5407:     }
                   5408:     foreach my $role (@{$roles}) {
                   5409:         if ($role eq 'login') {
                   5410:             %choices = &login_choices();
                   5411:         } else {
                   5412:             %choices = &color_font_choices();
                   5413:         }
                   5414:         if (ref($changes->{$role}) eq 'HASH') {
                   5415:             if ($role ne 'login') {
                   5416:                 $resulttext .= '<h4>'.&mt($role).'</h4>';
                   5417:             }
                   5418:             foreach my $key (sort(keys(%{$changes->{$role}}))) {
                   5419:                 if ($role ne 'login') {
                   5420:                     $resulttext .= '<ul>';
                   5421:                 }
                   5422:                 if (ref($changes->{$role}{$key}) eq 'HASH') {
                   5423:                     if ($role ne 'login') {
                   5424:                         $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
                   5425:                     }
                   5426:                     foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70      raeburn  5427:                         if (($role eq 'login') && ($key eq 'showlogo')) {
                   5428:                             if ($confhash->{$role}{$key}{$item}) {
                   5429:                                 $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
                   5430:                             } else {
                   5431:                                 $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
                   5432:                             }
                   5433:                         } elsif ($confhash->{$role}{$item} eq '') {
1.6       raeburn  5434:                             $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
                   5435:                         } else {
1.12      raeburn  5436:                             my $newitem = $confhash->{$role}{$item};
                   5437:                             if ($key eq 'images') {
                   5438:                                 $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
                   5439:                             }
                   5440:                             $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6       raeburn  5441:                         }
                   5442:                     }
                   5443:                     if ($role ne 'login') {
                   5444:                         $resulttext .= '</ul></li>';
                   5445:                     }
                   5446:                 } else {
                   5447:                     if ($confhash->{$role}{$key} eq '') {
                   5448:                         $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
                   5449:                     } else {
                   5450:                         $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
                   5451:                     }
                   5452:                 }
                   5453:                 if ($role ne 'login') {
                   5454:                     $resulttext .= '</ul>';
                   5455:                 }
                   5456:             }
                   5457:         }
                   5458:     }
1.3       raeburn  5459:     return $resulttext;
1.1       raeburn  5460: }
                   5461: 
1.9       raeburn  5462: sub thumb_dimensions {
                   5463:     return ('200','50');
                   5464: }
                   5465: 
1.16      raeburn  5466: sub check_dimensions {
                   5467:     my ($inputfile) = @_;
                   5468:     my ($fullwidth,$fullheight);
                   5469:     if ($inputfile =~ m|^[/\w.\-]+$|) {
                   5470:         if (open(PIPE,"identify $inputfile 2>&1 |")) {
                   5471:             my $imageinfo = <PIPE>;
                   5472:             if (!close(PIPE)) {
                   5473:                 &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
                   5474:             }
                   5475:             chomp($imageinfo);
                   5476:             my ($fullsize) = 
1.21      raeburn  5477:                 ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16      raeburn  5478:             if ($fullsize) {
                   5479:                 ($fullwidth,$fullheight) = split(/x/,$fullsize);
                   5480:             }
                   5481:         }
                   5482:     }
                   5483:     return ($fullwidth,$fullheight);
                   5484: }
                   5485: 
1.9       raeburn  5486: sub check_configuser {
                   5487:     my ($uhome,$dom,$confname,$servadm) = @_;
                   5488:     my ($configuserok,%currroles);
                   5489:     if ($uhome eq 'no_host') {
                   5490:         srand( time() ^ ($$ + ($$ << 15))  ); # Seed rand.
                   5491:         my $configpass = &LONCAPA::Enrollment::create_password();
                   5492:         $configuserok = 
                   5493:             &Apache::lonnet::modifyuser($dom,$confname,'','internal',
                   5494:                              $configpass,'','','','','',undef,$servadm);
                   5495:     } else {
                   5496:         $configuserok = 'ok';
                   5497:         %currroles = 
                   5498:             &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
                   5499:     }
                   5500:     return ($configuserok,%currroles);
                   5501: }
                   5502: 
                   5503: sub check_authorstatus {
                   5504:     my ($dom,$confname,%currroles) = @_;
                   5505:     my $author_ok;
1.40      raeburn  5506:     if (!$currroles{':'.$dom.':au'}) {
1.9       raeburn  5507:         my $start = time;
                   5508:         my $end = 0;
                   5509:         $author_ok = 
                   5510:             &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47      raeburn  5511:                                         'au',$end,$start,'','','domconfig');
1.9       raeburn  5512:     } else {
                   5513:         $author_ok = 'ok';
                   5514:     }
                   5515:     return $author_ok;
                   5516: }
                   5517: 
                   5518: sub publishlogo {
1.46      raeburn  5519:     my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9       raeburn  5520:     my ($output,$fname,$logourl);
                   5521:     if ($action eq 'upload') {
                   5522:         $fname=$env{'form.'.$formname.'.filename'};
                   5523:         chop($env{'form.'.$formname});
                   5524:     } else {
                   5525:         ($fname) = ($formname =~ /([^\/]+)$/);
                   5526:     }
1.46      raeburn  5527:     if ($savefileas ne '') {
                   5528:         $fname = $savefileas;
                   5529:     }
1.9       raeburn  5530:     $fname=&Apache::lonnet::clean_filename($fname);
                   5531: # See if there is anything left
                   5532:     unless ($fname) { return ('error: no uploaded file'); }
                   5533:     $fname="$subdir/$fname";
1.164     raeburn  5534:     my $docroot=$r->dir_config('lonDocRoot'); 
                   5535:     my $filepath="$docroot/priv";
                   5536:     my $relpath = "$dom/$confname";
1.9       raeburn  5537:     my ($fnamepath,$file,$fetchthumb);
                   5538:     $file=$fname;
                   5539:     if ($fname=~m|/|) {
                   5540:         ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
                   5541:     }
1.164     raeburn  5542:     my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9       raeburn  5543:     my $count;
1.164     raeburn  5544:     for ($count=5;$count<=$#parts;$count++) {
1.9       raeburn  5545:         $filepath.="/$parts[$count]";
                   5546:         if ((-e $filepath)!=1) {
                   5547:             mkdir($filepath,02770);
                   5548:         }
                   5549:     }
                   5550:     # Check for bad extension and disallow upload
                   5551:     if ($file=~/\.(\w+)$/ &&
                   5552:         (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
                   5553:         $output = 
1.207   ! bisitz   5554:             &mt('Invalid file extension ([_1]) - reserved for internal use.',$1); 
1.9       raeburn  5555:     } elsif ($file=~/\.(\w+)$/ &&
                   5556:         !defined(&Apache::loncommon::fileembstyle($1))) {
                   5557:         $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
                   5558:     } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.195     bisitz   5559:         $output = &mt('Filename not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
1.9       raeburn  5560:     } elsif (-d "$filepath/$file") {
1.195     bisitz   5561:         $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9       raeburn  5562:     } else {
                   5563:         my $source = $filepath.'/'.$file;
                   5564:         my $logfile;
                   5565:         if (!open($logfile,">>$source".'.log')) {
1.196     raeburn  5566:             return (&mt('No write permission to Authoring Space'));
1.9       raeburn  5567:         }
                   5568:         print $logfile
                   5569: "\n================= Publish ".localtime()." ================\n".
                   5570: $env{'user.name'}.':'.$env{'user.domain'}."\n";
                   5571: # Save the file
                   5572:         if (!open(FH,'>'.$source)) {
                   5573:             &Apache::lonnet::logthis('Failed to create '.$source);
                   5574:             return (&mt('Failed to create file'));
                   5575:         }
                   5576:         if ($action eq 'upload') {
                   5577:             if (!print FH ($env{'form.'.$formname})) {
                   5578:                 &Apache::lonnet::logthis('Failed to write to '.$source);
                   5579:                 return (&mt('Failed to write file'));
                   5580:             }
                   5581:         } else {
                   5582:             my $original = &Apache::lonnet::filelocation('',$formname);
                   5583:             if(!copy($original,$source)) {
                   5584:                 &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
                   5585:                 return (&mt('Failed to write file'));
                   5586:             }
                   5587:         }
                   5588:         close(FH);
                   5589:         chmod(0660, $source); # Permissions to rw-rw---.
                   5590: 
                   5591:         my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
                   5592:         my $copyfile=$targetdir.'/'.$file;
                   5593: 
                   5594:         my @parts=split(/\//,$targetdir);
                   5595:         my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
                   5596:         for (my $count=5;$count<=$#parts;$count++) {
                   5597:             $path.="/$parts[$count]";
                   5598:             if (!-e $path) {
                   5599:                 print $logfile "\nCreating directory ".$path;
                   5600:                 mkdir($path,02770);
                   5601:             }
                   5602:         }
                   5603:         my $versionresult;
                   5604:         if (-e $copyfile) {
                   5605:             $versionresult = &logo_versioning($targetdir,$file,$logfile);
                   5606:         } else {
                   5607:             $versionresult = 'ok';
                   5608:         }
                   5609:         if ($versionresult eq 'ok') {
                   5610:             if (copy($source,$copyfile)) {
                   5611:                 print $logfile "\nCopied original source to ".$copyfile."\n";
                   5612:                 $output = 'ok';
                   5613:                 $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155     raeburn  5614:                 push(@{$modified_urls},[$copyfile,$source]);
                   5615:                 my $metaoutput = 
                   5616:                     &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
                   5617:                 unless ($registered_cleanup) {
                   5618:                     my $handlers = $r->get_handlers('PerlCleanupHandler');
                   5619:                     $r->set_handlers('PerlCleanupHandler' => [\&notifysubscribed,@{$handlers}]);
                   5620:                     $registered_cleanup=1;
                   5621:                 }
1.9       raeburn  5622:             } else {
                   5623:                 print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
                   5624:                 $output = &mt('Failed to copy file to RES space').", $!";
                   5625:             }
                   5626:             if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
                   5627:                 my $inputfile = $filepath.'/'.$file;
                   5628:                 my $outfile = $filepath.'/'.'tn-'.$file;
1.16      raeburn  5629:                 my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
                   5630:                 if ($fullwidth ne '' && $fullheight ne '') { 
                   5631:                     if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
                   5632:                         my $thumbsize = $thumbwidth.'x'.$thumbheight;
                   5633:                         system("convert -sample $thumbsize $inputfile $outfile");
                   5634:                         chmod(0660, $filepath.'/tn-'.$file);
                   5635:                         if (-e $outfile) {
                   5636:                             my $copyfile=$targetdir.'/tn-'.$file;
                   5637:                             if (copy($outfile,$copyfile)) {
                   5638:                                 print $logfile "\nCopied source to ".$copyfile."\n";
1.155     raeburn  5639:                                 my $thumb_metaoutput = 
                   5640:                                     &write_metadata($dom,$confname,$formname,
                   5641:                                                     $targetdir,'tn-'.$file,$logfile);
                   5642:                                 push(@{$modified_urls},[$copyfile,$outfile]);
                   5643:                                 unless ($registered_cleanup) {
                   5644:                                     my $handlers = $r->get_handlers('PerlCleanupHandler');
                   5645:                                     $r->set_handlers('PerlCleanupHandler' => [\&notifysubscribed,@{$handlers}]);
                   5646:                                     $registered_cleanup=1;
                   5647:                                 }
1.16      raeburn  5648:                             } else {
                   5649:                                 print $logfile "\nUnable to write ".$copyfile.
                   5650:                                                ':'.$!."\n";
                   5651:                             }
                   5652:                         }
1.9       raeburn  5653:                     }
                   5654:                 }
                   5655:             }
                   5656:         } else {
                   5657:             $output = $versionresult;
                   5658:         }
                   5659:     }
                   5660:     return ($output,$logourl);
                   5661: }
                   5662: 
                   5663: sub logo_versioning {
                   5664:     my ($targetdir,$file,$logfile) = @_;
                   5665:     my $target = $targetdir.'/'.$file;
                   5666:     my ($maxversion,$fn,$extn,$output);
                   5667:     $maxversion = 0;
                   5668:     if ($file =~ /^(.+)\.(\w+)$/) {
                   5669:         $fn=$1;
                   5670:         $extn=$2;
                   5671:     }
                   5672:     opendir(DIR,$targetdir);
                   5673:     while (my $filename=readdir(DIR)) {
                   5674:         if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
                   5675:             $maxversion=($1>$maxversion)?$1:$maxversion;
                   5676:         }
                   5677:     }
                   5678:     $maxversion++;
                   5679:     print $logfile "\nCreating old version ".$maxversion."\n";
                   5680:     my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
                   5681:     if (copy($target,$copyfile)) {
                   5682:         print $logfile "Copied old target to ".$copyfile."\n";
                   5683:         $copyfile=$copyfile.'.meta';
                   5684:         if (copy($target.'.meta',$copyfile)) {
                   5685:             print $logfile "Copied old target metadata to ".$copyfile."\n";
                   5686:             $output = 'ok';
                   5687:         } else {
                   5688:             print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
                   5689:             $output = &mt('Failed to copy old meta').", $!, ";
                   5690:         }
                   5691:     } else {
                   5692:         print $logfile "Unable to write ".$copyfile.':'.$!."\n";
                   5693:         $output = &mt('Failed to copy old target').", $!, ";
                   5694:     }
                   5695:     return $output;
                   5696: }
                   5697: 
                   5698: sub write_metadata {
                   5699:     my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
                   5700:     my (%metadatafields,%metadatakeys,$output);
                   5701:     $metadatafields{'title'}=$formname;
                   5702:     $metadatafields{'creationdate'}=time;
                   5703:     $metadatafields{'lastrevisiondate'}=time;
                   5704:     $metadatafields{'copyright'}='public';
                   5705:     $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
                   5706:                                          $env{'user.domain'};
                   5707:     $metadatafields{'authorspace'}=$confname.':'.$dom;
                   5708:     $metadatafields{'domain'}=$dom;
                   5709:     {
                   5710:         print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
                   5711:         my $mfh;
1.155     raeburn  5712:         if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
1.184     raeburn  5713:             foreach (sort(keys(%metadatafields))) {
1.155     raeburn  5714:                 unless ($_=~/\./) {
                   5715:                     my $unikey=$_;
                   5716:                     $unikey=~/^([A-Za-z]+)/;
                   5717:                     my $tag=$1;
                   5718:                     $tag=~tr/A-Z/a-z/;
                   5719:                     print $mfh "\n\<$tag";
                   5720:                     foreach (split(/\,/,$metadatakeys{$unikey})) {
                   5721:                         my $value=$metadatafields{$unikey.'.'.$_};
                   5722:                         $value=~s/\"/\'\'/g;
                   5723:                         print $mfh ' '.$_.'="'.$value.'"';
                   5724:                     }
                   5725:                     print $mfh '>'.
                   5726:                         &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
                   5727:                             .'</'.$tag.'>';
                   5728:                 }
                   5729:             }
                   5730:             $output = 'ok';
                   5731:             print $logfile "\nWrote metadata";
                   5732:             close($mfh);
                   5733:         } else {
                   5734:             print $logfile "\nFailed to open metadata file";
1.9       raeburn  5735:             $output = &mt('Could not write metadata');
                   5736:         }
                   5737:     }
1.155     raeburn  5738:     return $output;
                   5739: }
                   5740: 
                   5741: sub notifysubscribed {
                   5742:     foreach my $targetsource (@{$modified_urls}){
                   5743:         next unless (ref($targetsource) eq 'ARRAY');
                   5744:         my ($target,$source)=@{$targetsource};
                   5745:         if ($source ne '') {
                   5746:             if (open(my $logfh,'>>'.$source.'.log')) {
                   5747:                 print $logfh "\nCleanup phase: Notifications\n";
                   5748:                 my @subscribed=&subscribed_hosts($target);
                   5749:                 foreach my $subhost (@subscribed) {
                   5750:                     print $logfh "\nNotifying host ".$subhost.':';
                   5751:                     my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
                   5752:                     print $logfh $reply;
                   5753:                 }
                   5754:                 my @subscribedmeta=&subscribed_hosts("$target.meta");
                   5755:                 foreach my $subhost (@subscribedmeta) {
                   5756:                     print $logfh "\nNotifying host for metadata only ".$subhost.':';
                   5757:                     my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
                   5758:                                                         $subhost);
                   5759:                     print $logfh $reply;
                   5760:                 }
                   5761:                 print $logfh "\n============ Done ============\n";
1.160     raeburn  5762:                 close($logfh);
1.155     raeburn  5763:             }
                   5764:         }
                   5765:     }
                   5766:     return OK;
                   5767: }
                   5768: 
                   5769: sub subscribed_hosts {
                   5770:     my ($target) = @_;
                   5771:     my @subscribed;
                   5772:     if (open(my $fh,"<$target.subscription")) {
                   5773:         while (my $subline=<$fh>) {
                   5774:             if ($subline =~ /^($match_lonid):/) {
                   5775:                 my $host = $1;
                   5776:                 if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
                   5777:                     unless (grep(/^\Q$host\E$/,@subscribed)) {
                   5778:                         push(@subscribed,$host);
                   5779:                     }
                   5780:                 }
                   5781:             }
                   5782:         }
                   5783:     }
                   5784:     return @subscribed;
1.9       raeburn  5785: }
                   5786: 
                   5787: sub check_switchserver {
                   5788:     my ($dom,$confname) = @_;
                   5789:     my ($allowed,$switchserver);
                   5790:     my $home = &Apache::lonnet::homeserver($confname,$dom);
                   5791:     if ($home eq 'no_host') {
                   5792:         $home = &Apache::lonnet::domain($dom,'primary');
                   5793:     }
                   5794:     my @ids=&Apache::lonnet::current_machine_ids();
1.10      albertel 5795:     foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
                   5796:     if (!$allowed) {
1.180     raeburn  5797: 	$switchserver='<a href="/adm/switchserver?otherserver='.$home.'&amp;role=dc./'.$dom.'/&amp;destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9       raeburn  5798:     }
                   5799:     return $switchserver;
                   5800: }
                   5801: 
1.1       raeburn  5802: sub modify_quotas {
1.86      raeburn  5803:     my ($dom,$action,%domconfig) = @_;
1.101     raeburn  5804:     my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
                   5805:         %limithash,$toolregexp,%conditions,$resulttext,%changes);
1.86      raeburn  5806:     if ($action eq 'quotas') {
                   5807:         $context = 'tools'; 
1.163     raeburn  5808:     } else {
1.86      raeburn  5809:         $context = $action;
                   5810:     }
                   5811:     if ($context eq 'requestcourses') {
1.98      raeburn  5812:         @usertools = ('official','unofficial','community');
1.106     raeburn  5813:         @options =('norequest','approval','validate','autolimit');
1.101     raeburn  5814:         %validations = &Apache::lonnet::auto_courserequest_checks($dom);
                   5815:         %titles = &courserequest_titles();
                   5816:         $toolregexp = join('|',@usertools);
                   5817:         %conditions = &courserequest_conditions();
1.163     raeburn  5818:     } elsif ($context eq 'requestauthor') {
                   5819:         @usertools = ('author');
                   5820:         %titles = &authorrequest_titles();
1.86      raeburn  5821:     } else {
1.162     raeburn  5822:         @usertools = ('aboutme','blog','webdav','portfolio');
1.101     raeburn  5823:         %titles = &tool_titles();
1.86      raeburn  5824:     }
1.72      raeburn  5825:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.44      raeburn  5826:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1       raeburn  5827:     foreach my $key (keys(%env)) {
1.101     raeburn  5828:         if ($context eq 'requestcourses') {
                   5829:             if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
                   5830:                 my $item = $1;
                   5831:                 my $type = $2;
                   5832:                 if ($type =~ /^limit_(.+)/) {
                   5833:                     $limithash{$item}{$1} = $env{$key};
                   5834:                 } else {
                   5835:                     $confhash{$item}{$type} = $env{$key};
                   5836:                 }
                   5837:             }
1.163     raeburn  5838:         } elsif ($context eq 'requestauthor') {
                   5839:             if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
                   5840:                 $confhash{$1} = $env{$key};
                   5841:             }
1.101     raeburn  5842:         } else {
1.86      raeburn  5843:             if ($key =~ /^form\.quota_(.+)$/) {
                   5844:                 $confhash{'defaultquota'}{$1} = $env{$key};
1.197     raeburn  5845:             } elsif ($key =~ /^form\.authorquota_(.+)$/) {
                   5846:                 $confhash{'authorquota'}{$1} = $env{$key};
                   5847:             } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101     raeburn  5848:                 @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
                   5849:             }
1.72      raeburn  5850:         }
                   5851:     }
1.163     raeburn  5852:     if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.102     raeburn  5853:         my @approvalnotify = &Apache::loncommon::get_env_multiple('form.reqapprovalnotify');
                   5854:         @approvalnotify = sort(@approvalnotify);
                   5855:         $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
                   5856:         if (ref($domconfig{$action}) eq 'HASH') {
                   5857:             if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
                   5858:                 if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
                   5859:                     $changes{'notify'}{'approval'} = 1;
                   5860:                 }
                   5861:             } else {
1.144     raeburn  5862:                 if ($confhash{'notify'}{'approval'}) {
1.102     raeburn  5863:                     $changes{'notify'}{'approval'} = 1;
                   5864:                 }
                   5865:             }
                   5866:         } else {
1.144     raeburn  5867:             if ($confhash{'notify'}{'approval'}) {
1.102     raeburn  5868:                 $changes{'notify'}{'approval'} = 1;
                   5869:             }
                   5870:         }
                   5871:     } else {
1.86      raeburn  5872:         $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.197     raeburn  5873:         $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86      raeburn  5874:     }
1.72      raeburn  5875:     foreach my $item (@usertools) {
                   5876:         foreach my $type (@{$types},'default','_LC_adv') {
1.104     raeburn  5877:             my $unset; 
1.101     raeburn  5878:             if ($context eq 'requestcourses') {
1.104     raeburn  5879:                 $unset = '0';
                   5880:                 if ($type eq '_LC_adv') {
                   5881:                     $unset = '';
                   5882:                 }
1.101     raeburn  5883:                 if ($confhash{$item}{$type} eq 'autolimit') {
                   5884:                     $confhash{$item}{$type} .= '=';
                   5885:                     unless ($limithash{$item}{$type} =~ /\D/) {
                   5886:                         $confhash{$item}{$type} .= $limithash{$item}{$type};
                   5887:                     }
                   5888:                 }
1.163     raeburn  5889:             } elsif ($context eq 'requestauthor') {
                   5890:                 $unset = '0';
                   5891:                 if ($type eq '_LC_adv') {
                   5892:                     $unset = '';
                   5893:                 }
1.72      raeburn  5894:             } else {
1.101     raeburn  5895:                 if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
                   5896:                     $confhash{$item}{$type} = 1;
                   5897:                 } else {
                   5898:                     $confhash{$item}{$type} = 0;
                   5899:                 }
1.72      raeburn  5900:             }
1.86      raeburn  5901:             if (ref($domconfig{$action}) eq 'HASH') {
1.163     raeburn  5902:                 if ($action eq 'requestauthor') {
                   5903:                     if ($domconfig{$action}{$type} ne $confhash{$type}) {
                   5904:                         $changes{$type} = 1;
                   5905:                     }
                   5906:                 } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86      raeburn  5907:                     if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
                   5908:                         $changes{$item}{$type} = 1;
                   5909:                     }
                   5910:                 } else {
                   5911:                     if ($context eq 'requestcourses') {
1.104     raeburn  5912:                         if ($confhash{$item}{$type} ne $unset) {
1.86      raeburn  5913:                             $changes{$item}{$type} = 1;
                   5914:                         }
                   5915:                     } else {
                   5916:                         if (!$confhash{$item}{$type}) {
                   5917:                             $changes{$item}{$type} = 1;
                   5918:                         }
                   5919:                     }
                   5920:                 }
                   5921:             } else {
                   5922:                 if ($context eq 'requestcourses') {
1.104     raeburn  5923:                     if ($confhash{$item}{$type} ne $unset) {
1.72      raeburn  5924:                         $changes{$item}{$type} = 1;
                   5925:                     }
1.163     raeburn  5926:                 } elsif ($context eq 'requestauthor') {
                   5927:                     if ($confhash{$type} ne $unset) {
                   5928:                         $changes{$type} = 1;
                   5929:                     }
1.72      raeburn  5930:                 } else {
                   5931:                     if (!$confhash{$item}{$type}) {
                   5932:                         $changes{$item}{$type} = 1;
                   5933:                     }
                   5934:                 }
                   5935:             }
1.1       raeburn  5936:         }
                   5937:     }
1.163     raeburn  5938:     unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86      raeburn  5939:         if (ref($domconfig{'quotas'}) eq 'HASH') {
                   5940:             if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
                   5941:                 foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
                   5942:                     if (exists($confhash{'defaultquota'}{$key})) {
                   5943:                         if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
                   5944:                             $changes{'defaultquota'}{$key} = 1;
                   5945:                         }
                   5946:                     } else {
                   5947:                         $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72      raeburn  5948:                     }
                   5949:                 }
1.86      raeburn  5950:             } else {
                   5951:                 foreach my $key (keys(%{$domconfig{'quotas'}})) {
                   5952:                     if (exists($confhash{'defaultquota'}{$key})) {
                   5953:                         if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
                   5954:                             $changes{'defaultquota'}{$key} = 1;
                   5955:                         }
                   5956:                     } else {
                   5957:                         $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72      raeburn  5958:                     }
1.1       raeburn  5959:                 }
                   5960:             }
1.197     raeburn  5961:             if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
                   5962:                 foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
                   5963:                     if (exists($confhash{'authorquota'}{$key})) {
                   5964:                         if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
                   5965:                             $changes{'authorquota'}{$key} = 1;
                   5966:                         }
                   5967:                     } else {
                   5968:                         $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
                   5969:                     }
                   5970:                 }
                   5971:             }
1.1       raeburn  5972:         }
1.86      raeburn  5973:         if (ref($confhash{'defaultquota'}) eq 'HASH') {
                   5974:             foreach my $key (keys(%{$confhash{'defaultquota'}})) {
                   5975:                 if (ref($domconfig{'quotas'}) eq 'HASH') {
                   5976:                     if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
                   5977:                         if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
                   5978:                             $changes{'defaultquota'}{$key} = 1;
                   5979:                         }
                   5980:                     } else {
                   5981:                         if (!exists($domconfig{'quotas'}{$key})) {
                   5982:                             $changes{'defaultquota'}{$key} = 1;
                   5983:                         }
1.72      raeburn  5984:                     }
                   5985:                 } else {
1.86      raeburn  5986:                     $changes{'defaultquota'}{$key} = 1;
1.55      raeburn  5987:                 }
1.1       raeburn  5988:             }
                   5989:         }
1.197     raeburn  5990:         if (ref($confhash{'authorquota'}) eq 'HASH') {
                   5991:             foreach my $key (keys(%{$confhash{'authorquota'}})) {
                   5992:                 if (ref($domconfig{'quotas'}) eq 'HASH') {
                   5993:                     if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
                   5994:                         if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
                   5995:                             $changes{'authorquota'}{$key} = 1;
                   5996:                         }
                   5997:                     } else {
                   5998:                         $changes{'authorquota'}{$key} = 1;
                   5999:                     }
                   6000:                 } else {
                   6001:                     $changes{'authorquota'}{$key} = 1;
                   6002:                 }
                   6003:             }
                   6004:         }
1.1       raeburn  6005:     }
1.72      raeburn  6006: 
1.163     raeburn  6007:     if ($context eq 'requestauthor') {
                   6008:         $domdefaults{'requestauthor'} = \%confhash;
                   6009:     } else {
                   6010:         foreach my $key (keys(%confhash)) {
                   6011:             $domdefaults{$key} = $confhash{$key};
                   6012:         }
1.72      raeburn  6013:     }
1.163     raeburn  6014: 
1.1       raeburn  6015:     my %quotahash = (
1.86      raeburn  6016:                       $action => { %confhash }
1.1       raeburn  6017:                     );
                   6018:     my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
                   6019:                                              $dom);
                   6020:     if ($putresult eq 'ok') {
                   6021:         if (keys(%changes) > 0) {
1.72      raeburn  6022:             my $cachetime = 24*60*60;
                   6023:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
                   6024: 
1.1       raeburn  6025:             $resulttext = &mt('Changes made:').'<ul>';
1.163     raeburn  6026:             unless (($context eq 'requestcourses') || 
                   6027:                     ($context eq 'requestauthor')) {
1.86      raeburn  6028:                 if (ref($changes{'defaultquota'}) eq 'HASH') {
                   6029:                     $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
                   6030:                     foreach my $type (@{$types},'default') {
                   6031:                         if (defined($changes{'defaultquota'}{$type})) {
                   6032:                             my $typetitle = $usertypes->{$type};
                   6033:                             if ($type eq 'default') {
                   6034:                                 $typetitle = $othertitle;
                   6035:                             }
                   6036:                             $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72      raeburn  6037:                         }
                   6038:                     }
1.86      raeburn  6039:                     $resulttext .= '</ul></li>';
1.72      raeburn  6040:                 }
1.197     raeburn  6041:                 if (ref($changes{'authorquota'}) eq 'HASH') {
                   6042:                     $resulttext .= '<li>'.&mt('Authoring space default quotas').'<ul>';
                   6043:                     foreach my $type (@{$types},'default') {
                   6044:                         if (defined($changes{'authorquota'}{$type})) {
                   6045:                             my $typetitle = $usertypes->{$type};
                   6046:                             if ($type eq 'default') {
                   6047:                                 $typetitle = $othertitle;
                   6048:                             }
                   6049:                             $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
                   6050:                         }
                   6051:                     }
                   6052:                     $resulttext .= '</ul></li>';
                   6053:                 }
1.72      raeburn  6054:             }
1.80      raeburn  6055:             my %newenv;
1.72      raeburn  6056:             foreach my $item (@usertools) {
1.163     raeburn  6057:                 my (%haschgs,%inconf);
                   6058:                 if ($context eq 'requestauthor') {
                   6059:                     %haschgs = %changes;
                   6060:                     %inconf = %confhash; 
                   6061:                 } else {
                   6062:                     if (ref($changes{$item}) eq 'HASH') {
                   6063:                         %haschgs = %{$changes{$item}};
                   6064:                     }
                   6065:                     if (ref($confhash{$item}) eq 'HASH') {
                   6066:                         %inconf = %{$confhash{$item}};
                   6067:                     }
                   6068:                 }
                   6069:                 if (keys(%haschgs) > 0) {
1.80      raeburn  6070:                     my $newacc = 
                   6071:                         &Apache::lonnet::usertools_access($env{'user.name'},
                   6072:                                                           $env{'user.domain'},
1.86      raeburn  6073:                                                           $item,'reload',$context);
1.163     raeburn  6074:                     if (($context eq 'requestcourses') || 
                   6075:                         ($context eq 'requestauthor')) {
1.108     raeburn  6076:                         if ($env{'environment.canrequest.'.$item} ne $newacc) {
                   6077:                             $newenv{'environment.canrequest.'.$item} = $newacc;
1.86      raeburn  6078:                         }
                   6079:                     } else {
                   6080:                         if ($env{'environment.availabletools.'.$item} ne $newacc) { 
                   6081:                             $newenv{'environment.availabletools.'.$item} = $newacc;
                   6082:                         }
1.80      raeburn  6083:                     }
1.163     raeburn  6084:                     unless ($context eq 'requestauthor') {
                   6085:                         $resulttext .= '<li>'.$titles{$item}.'<ul>';
                   6086:                     }
1.72      raeburn  6087:                     foreach my $type (@{$types},'default','_LC_adv') {
1.163     raeburn  6088:                         if ($haschgs{$type}) {
1.72      raeburn  6089:                             my $typetitle = $usertypes->{$type};
                   6090:                             if ($type eq 'default') {
                   6091:                                 $typetitle = $othertitle;
                   6092:                             } elsif ($type eq '_LC_adv') {
                   6093:                                 $typetitle = 'LON-CAPA Advanced Users'; 
                   6094:                             }
1.163     raeburn  6095:                             if ($inconf{$type}) {
1.101     raeburn  6096:                                 if ($context eq 'requestcourses') {
                   6097:                                     my $cond;
1.163     raeburn  6098:                                     if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101     raeburn  6099:                                         if ($1 eq '') {
                   6100:                                             $cond = &mt('(Automatic processing of any request).');
                   6101:                                         } else {
                   6102:                                             $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
                   6103:                                         }
                   6104:                                     } else { 
1.163     raeburn  6105:                                         $cond = $conditions{$inconf{$type}};
1.101     raeburn  6106:                                     }
                   6107:                                     $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172     raeburn  6108:                                 } elsif ($context eq 'requestauthor') {
                   6109:                                     $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
                   6110:                                                              $titles{$inconf{$type}},$typetitle);
                   6111: 
1.101     raeburn  6112:                                 } else {
                   6113:                                     $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
                   6114:                                 }
1.72      raeburn  6115:                             } else {
1.104     raeburn  6116:                                 if ($type eq '_LC_adv') {
1.163     raeburn  6117:                                     if ($inconf{$type} eq '0') {
1.104     raeburn  6118:                                         $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
                   6119:                                     } else { 
                   6120:                                         $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
                   6121:                                     }
                   6122:                                 } else {
                   6123:                                     $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
                   6124:                                 }
1.72      raeburn  6125:                             }
                   6126:                         }
1.26      raeburn  6127:                     }
1.163     raeburn  6128:                     unless ($context eq 'requestauthor') {
                   6129:                         $resulttext .= '</ul></li>';
                   6130:                     }
1.26      raeburn  6131:                 }
1.1       raeburn  6132:             }
1.163     raeburn  6133:             if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102     raeburn  6134:                 if (ref($changes{'notify'}) eq 'HASH') {
                   6135:                     if ($changes{'notify'}{'approval'}) {
                   6136:                         if (ref($confhash{'notify'}) eq 'HASH') {
                   6137:                             if ($confhash{'notify'}{'approval'}) {
                   6138:                                 $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
                   6139:                             } else {
1.163     raeburn  6140:                                 $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102     raeburn  6141:                             }
                   6142:                         }
                   6143:                     }
                   6144:                 }
                   6145:             }
1.1       raeburn  6146:             $resulttext .= '</ul>';
1.80      raeburn  6147:             if (keys(%newenv)) {
                   6148:                 &Apache::lonnet::appenv(\%newenv);
                   6149:             }
1.1       raeburn  6150:         } else {
1.86      raeburn  6151:             if ($context eq 'requestcourses') {
                   6152:                 $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163     raeburn  6153:             } elsif ($context eq 'requestauthor') {
                   6154:                 $resulttext = &mt('No changes made to rights to request author space.');
1.86      raeburn  6155:             } else {
1.90      weissno  6156:                 $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86      raeburn  6157:             }
1.1       raeburn  6158:         }
                   6159:     } else {
1.11      albertel 6160:         $resulttext = '<span class="LC_error">'.
                   6161: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  6162:     }
1.3       raeburn  6163:     return $resulttext;
1.1       raeburn  6164: }
                   6165: 
1.3       raeburn  6166: sub modify_autoenroll {
1.205     raeburn  6167:     my ($dom,$lastactref,%domconfig) = @_;
1.1       raeburn  6168:     my ($resulttext,%changes);
                   6169:     my %currautoenroll;
                   6170:     if (ref($domconfig{'autoenroll'}) eq 'HASH') {
                   6171:         foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
                   6172:             $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
                   6173:         }
                   6174:     }
                   6175:     my $autorun = &Apache::lonnet::auto_run(undef,$dom),
                   6176:     my %title = ( run => 'Auto-enrollment active',
1.129     raeburn  6177:                   sender => 'Sender for notification messages',
                   6178:                   coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)');
1.1       raeburn  6179:     my @offon = ('off','on');
1.17      raeburn  6180:     my $sender_uname = $env{'form.sender_uname'};
                   6181:     my $sender_domain = $env{'form.sender_domain'};
                   6182:     if ($sender_domain eq '') {
                   6183:         $sender_uname = '';
                   6184:     } elsif ($sender_uname eq '') {
                   6185:         $sender_domain = '';
                   6186:     }
1.129     raeburn  6187:     my $coowners = $env{'form.autoassign_coowners'};
1.1       raeburn  6188:     my %autoenrollhash =  (
1.129     raeburn  6189:                        autoenroll => { 'run' => $env{'form.autoenroll_run'},
                   6190:                                        'sender_uname' => $sender_uname,
                   6191:                                        'sender_domain' => $sender_domain,
                   6192:                                        'co-owners' => $coowners,
1.1       raeburn  6193:                                 }
                   6194:                      );
1.4       raeburn  6195:     my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
                   6196:                                              $dom);
1.1       raeburn  6197:     if ($putresult eq 'ok') {
                   6198:         if (exists($currautoenroll{'run'})) {
                   6199:              if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
                   6200:                  $changes{'run'} = 1;
                   6201:              }
                   6202:         } elsif ($autorun) {
                   6203:             if ($env{'form.autoenroll_run'} ne '1') {
1.23      raeburn  6204:                  $changes{'run'} = 1;
1.1       raeburn  6205:             }
                   6206:         }
1.17      raeburn  6207:         if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1       raeburn  6208:             $changes{'sender'} = 1;
                   6209:         }
1.17      raeburn  6210:         if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1       raeburn  6211:             $changes{'sender'} = 1;
                   6212:         }
1.129     raeburn  6213:         if ($currautoenroll{'co-owners'} ne '') {
                   6214:             if ($currautoenroll{'co-owners'} ne $coowners) {
                   6215:                 $changes{'coowners'} = 1;
                   6216:             }
                   6217:         } elsif ($coowners) {
                   6218:             $changes{'coowners'} = 1;
                   6219:         }      
1.1       raeburn  6220:         if (keys(%changes) > 0) {
                   6221:             $resulttext = &mt('Changes made:').'<ul>';
1.3       raeburn  6222:             if ($changes{'run'}) {
1.1       raeburn  6223:                 $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
                   6224:             }
                   6225:             if ($changes{'sender'}) {
1.17      raeburn  6226:                 if ($sender_uname eq '' || $sender_domain eq '') {
                   6227:                     $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
                   6228:                 } else {
                   6229:                     $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
                   6230:                 }
1.1       raeburn  6231:             }
1.129     raeburn  6232:             if ($changes{'coowners'}) {
                   6233:                 $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
                   6234:                 &Apache::loncommon::devalidate_domconfig_cache($dom);
1.205     raeburn  6235:                 $$lastactref = 'update';
1.129     raeburn  6236:             }
1.1       raeburn  6237:             $resulttext .= '</ul>';
                   6238:         } else {
                   6239:             $resulttext = &mt('No changes made to auto-enrollment settings');
                   6240:         }
                   6241:     } else {
1.11      albertel 6242:         $resulttext = '<span class="LC_error">'.
                   6243: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  6244:     }
1.3       raeburn  6245:     return $resulttext;
1.1       raeburn  6246: }
                   6247: 
                   6248: sub modify_autoupdate {
1.3       raeburn  6249:     my ($dom,%domconfig) = @_;
1.1       raeburn  6250:     my ($resulttext,%currautoupdate,%fields,%changes);
                   6251:     if (ref($domconfig{'autoupdate'}) eq 'HASH') {
                   6252:         foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
                   6253:             $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
                   6254:         }
                   6255:     }
                   6256:     my @offon = ('off','on');
                   6257:     my %title = &Apache::lonlocal::texthash (
                   6258:                    run => 'Auto-update:',
                   6259:                    classlists => 'Updates to user information in classlists?'
                   6260:                 );
1.44      raeburn  6261:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1       raeburn  6262:     my %fieldtitles = &Apache::lonlocal::texthash (
                   6263:                         id => 'Student/Employee ID',
1.20      raeburn  6264:                         permanentemail => 'E-mail address',
1.1       raeburn  6265:                         lastname => 'Last Name',
                   6266:                         firstname => 'First Name',
                   6267:                         middlename => 'Middle Name',
1.132     raeburn  6268:                         generation => 'Generation',
1.1       raeburn  6269:                       );
1.142     raeburn  6270:     $othertitle = &mt('All users');
1.1       raeburn  6271:     if (keys(%{$usertypes}) >  0) {
1.26      raeburn  6272:         $othertitle = &mt('Other users');
1.1       raeburn  6273:     }
                   6274:     foreach my $key (keys(%env)) {
                   6275:         if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132     raeburn  6276:             my ($usertype,$item) = ($1,$2);
                   6277:             if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
                   6278:                 if ($usertype eq 'default') {   
                   6279:                     push(@{$fields{$1}},$2);
                   6280:                 } elsif (ref($types) eq 'ARRAY') {
                   6281:                     if (grep(/^\Q$usertype\E$/,@{$types})) {
                   6282:                         push(@{$fields{$1}},$2);
                   6283:                     }
                   6284:                 }
                   6285:             }
1.1       raeburn  6286:         }
                   6287:     }
1.131     raeburn  6288:     my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
                   6289:     @lockablenames = sort(@lockablenames);
                   6290:     if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
                   6291:         my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
                   6292:         if (@changed) {
                   6293:             $changes{'lockablenames'} = 1;
                   6294:         }
                   6295:     } else {
                   6296:         if (@lockablenames) {
                   6297:             $changes{'lockablenames'} = 1;
                   6298:         }
                   6299:     }
1.1       raeburn  6300:     my %updatehash = (
                   6301:                       autoupdate => { run => $env{'form.autoupdate_run'},
                   6302:                                       classlists => $env{'form.classlists'},
                   6303:                                       fields => {%fields},
1.131     raeburn  6304:                                       lockablenames => \@lockablenames,
1.1       raeburn  6305:                                     }
                   6306:                      );
                   6307:     foreach my $key (keys(%currautoupdate)) {
                   6308:         if (($key eq 'run') || ($key eq 'classlists')) {
                   6309:             if (exists($updatehash{autoupdate}{$key})) {
                   6310:                 if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
                   6311:                     $changes{$key} = 1;
                   6312:                 }
                   6313:             }
                   6314:         } elsif ($key eq 'fields') {
                   6315:             if (ref($currautoupdate{$key}) eq 'HASH') {
1.26      raeburn  6316:                 foreach my $item (@{$types},'default') {
1.1       raeburn  6317:                     if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
                   6318:                         my $change = 0;
                   6319:                         foreach my $type (@{$currautoupdate{$key}{$item}}) {
                   6320:                             if (!exists($fields{$item})) {
                   6321:                                 $change = 1;
1.132     raeburn  6322:                                 last;
1.1       raeburn  6323:                             } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26      raeburn  6324:                                 if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1       raeburn  6325:                                     $change = 1;
1.132     raeburn  6326:                                     last;
1.1       raeburn  6327:                                 }
                   6328:                             }
                   6329:                         }
                   6330:                         if ($change) {
                   6331:                             push(@{$changes{$key}},$item);
                   6332:                         }
1.26      raeburn  6333:                     } 
1.1       raeburn  6334:                 }
                   6335:             }
1.131     raeburn  6336:         } elsif ($key eq 'lockablenames') {
                   6337:             if (ref($currautoupdate{$key}) eq 'ARRAY') {
                   6338:                 my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
                   6339:                 if (@changed) {
                   6340:                     $changes{'lockablenames'} = 1;
                   6341:                 }
                   6342:             } else {
                   6343:                 if (@lockablenames) {
                   6344:                     $changes{'lockablenames'} = 1;
                   6345:                 }
                   6346:             }
                   6347:         }
                   6348:     }
                   6349:     unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
                   6350:         if (@lockablenames) {
                   6351:             $changes{'lockablenames'} = 1;
1.1       raeburn  6352:         }
                   6353:     }
1.26      raeburn  6354:     foreach my $item (@{$types},'default') {
                   6355:         if (defined($fields{$item})) {
                   6356:             if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132     raeburn  6357:                 if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
                   6358:                     my $change = 0;
                   6359:                     if (ref($fields{$item}) eq 'ARRAY') {
                   6360:                         foreach my $type (@{$fields{$item}}) {
                   6361:                             if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
                   6362:                                 $change = 1;
                   6363:                                 last;
                   6364:                             }
                   6365:                         }
                   6366:                     }
                   6367:                     if ($change) {
                   6368:                         push(@{$changes{'fields'}},$item);
                   6369:                     }
                   6370:                 } else {
1.26      raeburn  6371:                     push(@{$changes{'fields'}},$item);
                   6372:                 }
                   6373:             } else {
                   6374:                 push(@{$changes{'fields'}},$item);
1.1       raeburn  6375:             }
                   6376:         }
                   6377:     }
                   6378:     my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
                   6379:                                              $dom);
                   6380:     if ($putresult eq 'ok') {
                   6381:         if (keys(%changes) > 0) {
                   6382:             $resulttext = &mt('Changes made:').'<ul>';
                   6383:             foreach my $key (sort(keys(%changes))) {
1.131     raeburn  6384:                 if ($key eq 'lockablenames') {
                   6385:                     $resulttext .= '<li>';
                   6386:                     if (@lockablenames) {
                   6387:                         $usertypes->{'default'} = $othertitle;
                   6388:                         $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
                   6389:                                    join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
                   6390:                     } else {
                   6391:                         $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
                   6392:                     }
                   6393:                     $resulttext .= '</li>';
                   6394:                 } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1       raeburn  6395:                     foreach my $item (@{$changes{$key}}) {
                   6396:                         my @newvalues;
                   6397:                         foreach my $type (@{$fields{$item}}) {
                   6398:                             push(@newvalues,$fieldtitles{$type});
                   6399:                         }
1.3       raeburn  6400:                         my $newvaluestr;
                   6401:                         if (@newvalues > 0) {
                   6402:                             $newvaluestr = join(', ',@newvalues);
                   6403:                         } else {
                   6404:                             $newvaluestr = &mt('none');
1.6       raeburn  6405:                         }
1.1       raeburn  6406:                         if ($item eq 'default') {
1.26      raeburn  6407:                             $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1       raeburn  6408:                         } else {
1.26      raeburn  6409:                             $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1       raeburn  6410:                         }
                   6411:                     }
                   6412:                 } else {
                   6413:                     my $newvalue;
                   6414:                     if ($key eq 'run') {
                   6415:                         $newvalue = $offon[$env{'form.autoupdate_run'}];
                   6416:                     } else {
                   6417:                         $newvalue = $offon[$env{'form.'.$key}];
1.3       raeburn  6418:                     }
1.1       raeburn  6419:                     $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
                   6420:                 }
                   6421:             }
                   6422:             $resulttext .= '</ul>';
                   6423:         } else {
1.3       raeburn  6424:             $resulttext = &mt('No changes made to autoupdates');
1.1       raeburn  6425:         }
                   6426:     } else {
1.11      albertel 6427:         $resulttext = '<span class="LC_error">'.
                   6428: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  6429:     }
1.3       raeburn  6430:     return $resulttext;
1.1       raeburn  6431: }
                   6432: 
1.125     raeburn  6433: sub modify_autocreate {
                   6434:     my ($dom,%domconfig) = @_;
                   6435:     my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
                   6436:     if (ref($domconfig{'autocreate'}) eq 'HASH') {
                   6437:         foreach my $key (keys(%{$domconfig{'autocreate'}})) {
                   6438:             $currautocreate{$key} = $domconfig{'autocreate'}{$key};
                   6439:         }
                   6440:     }
                   6441:     my %title= ( xml => 'Auto-creation of courses in XML course description files',
                   6442:                  req => 'Auto-creation of validated requests for official courses',
                   6443:                  xmldc => 'Identity of course creator of courses from XML files',
                   6444:                );
                   6445:     my @types = ('xml','req');
                   6446:     foreach my $item (@types) {
                   6447:         $newvals{$item} = $env{'form.autocreate_'.$item};
                   6448:         $newvals{$item} =~ s/\D//g;
                   6449:         $newvals{$item} = 0 if ($newvals{$item} eq '');
                   6450:     }
                   6451:     $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
                   6452:     my %domcoords = &get_active_dcs($dom);
                   6453:     unless (exists($domcoords{$newvals{'xmldc'}})) {
                   6454:         $newvals{'xmldc'} = '';
                   6455:     } 
                   6456:     %autocreatehash =  (
                   6457:                         autocreate => { xml => $newvals{'xml'},
                   6458:                                         req => $newvals{'req'},
                   6459:                                       }
                   6460:                        );
                   6461:     if ($newvals{'xmldc'} ne '') {
                   6462:         $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
                   6463:     }
                   6464:     my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
                   6465:                                              $dom);
                   6466:     if ($putresult eq 'ok') {
                   6467:         my @items = @types;
                   6468:         if ($newvals{'xml'}) {
                   6469:             push(@items,'xmldc');
                   6470:         }
                   6471:         foreach my $item (@items) {
                   6472:             if (exists($currautocreate{$item})) {
                   6473:                 if ($currautocreate{$item} ne $newvals{$item}) {
                   6474:                     $changes{$item} = 1;
                   6475:                 }
                   6476:             } elsif ($newvals{$item}) {
                   6477:                 $changes{$item} = 1;
                   6478:             }
                   6479:         }
                   6480:         if (keys(%changes) > 0) {
                   6481:             my @offon = ('off','on'); 
                   6482:             $resulttext = &mt('Changes made:').'<ul>';
                   6483:             foreach my $item (@types) {
                   6484:                 if ($changes{$item}) {
                   6485:                     my $newtxt = $offon[$newvals{$item}];
1.178     raeburn  6486:                     $resulttext .= '<li>'.
                   6487:                                    &mt("$title{$item} set to [_1]$newtxt [_2]",
                   6488:                                        '<b>','</b>').
                   6489:                                    '</li>';
1.125     raeburn  6490:                 }
                   6491:             }
                   6492:             if ($changes{'xmldc'}) {
                   6493:                 my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
                   6494:                 my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178     raeburn  6495:                 $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>'; 
1.125     raeburn  6496:             }
                   6497:             $resulttext .= '</ul>';
                   6498:         } else {
                   6499:             $resulttext = &mt('No changes made to auto-creation settings');
                   6500:         }
                   6501:     } else {
                   6502:         $resulttext = '<span class="LC_error">'.
                   6503:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   6504:     }
                   6505:     return $resulttext;
                   6506: }
                   6507: 
1.23      raeburn  6508: sub modify_directorysrch {
                   6509:     my ($dom,%domconfig) = @_;
                   6510:     my ($resulttext,%changes);
                   6511:     my %currdirsrch;
                   6512:     if (ref($domconfig{'directorysrch'}) eq 'HASH') {
                   6513:         foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
                   6514:             $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
                   6515:         }
                   6516:     }
                   6517:     my %title = ( available => 'Directory search available',
1.24      raeburn  6518:                   localonly => 'Other domains can search',
1.23      raeburn  6519:                   searchby => 'Search types',
                   6520:                   searchtypes => 'Search latitude');
                   6521:     my @offon = ('off','on');
1.24      raeburn  6522:     my @otherdoms = ('Yes','No');
1.23      raeburn  6523: 
1.25      raeburn  6524:     my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');  
1.23      raeburn  6525:     my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
                   6526:     my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
                   6527: 
1.44      raeburn  6528:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26      raeburn  6529:     if (keys(%{$usertypes}) == 0) {
                   6530:         @cansearch = ('default');
                   6531:     } else {
                   6532:         if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
                   6533:             foreach my $type (@{$currdirsrch{'cansearch'}}) {
                   6534:                 if (!grep(/^\Q$type\E$/,@cansearch)) {
                   6535:                     push(@{$changes{'cansearch'}},$type);
                   6536:                 }
1.23      raeburn  6537:             }
1.26      raeburn  6538:             foreach my $type (@cansearch) {
                   6539:                 if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
                   6540:                     push(@{$changes{'cansearch'}},$type);
                   6541:                 }
1.23      raeburn  6542:             }
1.26      raeburn  6543:         } else {
                   6544:             push(@{$changes{'cansearch'}},@cansearch);
1.23      raeburn  6545:         }
                   6546:     }
                   6547: 
                   6548:     if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
                   6549:         foreach my $by (@{$currdirsrch{'searchby'}}) {
                   6550:             if (!grep(/^\Q$by\E$/,@searchby)) {
                   6551:                 push(@{$changes{'searchby'}},$by);
                   6552:             }
                   6553:         }
                   6554:         foreach my $by (@searchby) {
                   6555:             if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
                   6556:                 push(@{$changes{'searchby'}},$by);
                   6557:             }
                   6558:         }
                   6559:     } else {
                   6560:         push(@{$changes{'searchby'}},@searchby);
                   6561:     }
1.25      raeburn  6562: 
                   6563:     if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
                   6564:         foreach my $type (@{$currdirsrch{'searchtypes'}}) {
                   6565:             if (!grep(/^\Q$type\E$/,@searchtypes)) {
                   6566:                 push(@{$changes{'searchtypes'}},$type);
                   6567:             }
                   6568:         }
                   6569:         foreach my $type (@searchtypes) {
                   6570:             if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
                   6571:                 push(@{$changes{'searchtypes'}},$type);
                   6572:             }
                   6573:         }
                   6574:     } else {
                   6575:         if (exists($currdirsrch{'searchtypes'})) {
                   6576:             foreach my $type (@searchtypes) {  
                   6577:                 if ($type ne $currdirsrch{'searchtypes'}) { 
                   6578:                     push(@{$changes{'searchtypes'}},$type);
                   6579:                 }
                   6580:             }
                   6581:             if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
                   6582:                 push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
                   6583:             }   
                   6584:         } else {
                   6585:             push(@{$changes{'searchtypes'}},@searchtypes); 
                   6586:         }
                   6587:     }
                   6588: 
1.23      raeburn  6589:     my %dirsrch_hash =  (
                   6590:             directorysrch => { available => $env{'form.dirsrch_available'},
                   6591:                                cansearch => \@cansearch,
1.24      raeburn  6592:                                localonly => $env{'form.dirsrch_localonly'},
1.23      raeburn  6593:                                searchby => \@searchby,
1.25      raeburn  6594:                                searchtypes => \@searchtypes,
1.23      raeburn  6595:                              }
                   6596:             );
                   6597:     my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
                   6598:                                              $dom);
                   6599:     if ($putresult eq 'ok') {
                   6600:         if (exists($currdirsrch{'available'})) {
                   6601:              if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
                   6602:                  $changes{'available'} = 1;
                   6603:              }
                   6604:         } else {
                   6605:             if ($env{'form.dirsrch_available'} eq '1') {
                   6606:                 $changes{'available'} = 1;
                   6607:             }
                   6608:         }
1.24      raeburn  6609:         if (exists($currdirsrch{'localonly'})) {
                   6610:              if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
                   6611:                  $changes{'localonly'} = 1;
                   6612:              }
                   6613:         } else {
                   6614:             if ($env{'form.dirsrch_localonly'} eq '1') {
                   6615:                 $changes{'localonly'} = 1;
                   6616:             }
                   6617:         }
1.23      raeburn  6618:         if (keys(%changes) > 0) {
                   6619:             $resulttext = &mt('Changes made:').'<ul>';
                   6620:             if ($changes{'available'}) {
                   6621:                 $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
                   6622:             }
1.24      raeburn  6623:             if ($changes{'localonly'}) {
                   6624:                 $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
                   6625:             }
                   6626: 
1.23      raeburn  6627:             if (ref($changes{'cansearch'}) eq 'ARRAY') {
                   6628:                 my $chgtext;
1.26      raeburn  6629:                 if (ref($usertypes) eq 'HASH') {
                   6630:                     if (keys(%{$usertypes}) > 0) {
                   6631:                         foreach my $type (@{$types}) {
                   6632:                             if (grep(/^\Q$type\E$/,@cansearch)) {
                   6633:                                 $chgtext .= $usertypes->{$type}.'; ';
                   6634:                             }
                   6635:                         }
                   6636:                         if (grep(/^default$/,@cansearch)) {
                   6637:                             $chgtext .= $othertitle;
                   6638:                         } else {
                   6639:                             $chgtext =~ s/\; $//;
                   6640:                         }
1.178     raeburn  6641:                         $resulttext .= 
                   6642:                             '<li>'.
                   6643:                             &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
                   6644:                                 '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
                   6645:                             '</li>';
1.23      raeburn  6646:                     }
                   6647:                 }
                   6648:             }
                   6649:             if (ref($changes{'searchby'}) eq 'ARRAY') {
                   6650:                 my ($searchtitles,$titleorder) = &sorted_searchtitles();
                   6651:                 my $chgtext;
                   6652:                 foreach my $type (@{$titleorder}) {
                   6653:                     if (grep(/^\Q$type\E$/,@searchby)) {
                   6654:                         if (defined($searchtitles->{$type})) {
                   6655:                             $chgtext .= $searchtitles->{$type}.'; ';
                   6656:                         }
                   6657:                     }
                   6658:                 }
                   6659:                 $chgtext =~ s/\; $//;
                   6660:                 $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
                   6661:             }
1.25      raeburn  6662:             if (ref($changes{'searchtypes'}) eq 'ARRAY') {
                   6663:                 my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes(); 
                   6664:                 my $chgtext;
                   6665:                 foreach my $type (@{$srchtypeorder}) {
                   6666:                     if (grep(/^\Q$type\E$/,@searchtypes)) {
                   6667:                         if (defined($srchtypes_desc->{$type})) {
                   6668:                             $chgtext .= $srchtypes_desc->{$type}.'; ';
                   6669:                         }
                   6670:                     }
                   6671:                 }
                   6672:                 $chgtext =~ s/\; $//;
1.178     raeburn  6673:                 $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23      raeburn  6674:             }
                   6675:             $resulttext .= '</ul>';
                   6676:         } else {
                   6677:             $resulttext = &mt('No changes made to institution directory search settings');
                   6678:         }
                   6679:     } else {
                   6680:         $resulttext = '<span class="LC_error">'.
1.27      raeburn  6681:                       &mt('An error occurred: [_1]',$putresult).'</span>';
                   6682:     }
                   6683:     return $resulttext;
                   6684: }
                   6685: 
1.28      raeburn  6686: sub modify_contacts {
1.205     raeburn  6687:     my ($dom,$lastactref,%domconfig) = @_;
1.28      raeburn  6688:     my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
                   6689:     if (ref($domconfig{'contacts'}) eq 'HASH') {
                   6690:         foreach my $key (keys(%{$domconfig{'contacts'}})) {
                   6691:             $currsetting{$key} = $domconfig{'contacts'}{$key};
                   6692:         }
                   6693:     }
1.134     raeburn  6694:     my (%others,%to,%bcc);
1.28      raeburn  6695:     my @contacts = ('supportemail','adminemail');
1.102     raeburn  6696:     my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
1.203     raeburn  6697:                     'requestsmail','updatesmail','idconflictsmail');
                   6698:     my @toggles = ('reporterrors','reportupdates');
1.28      raeburn  6699:     foreach my $type (@mailings) {
                   6700:         @{$newsetting{$type}} = 
                   6701:             &Apache::loncommon::get_env_multiple('form.'.$type);
                   6702:         foreach my $item (@contacts) {
                   6703:             if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
                   6704:                 $contacts_hash{contacts}{$type}{$item} = 1;
                   6705:             } else {
                   6706:                 $contacts_hash{contacts}{$type}{$item} = 0;
                   6707:             }
                   6708:         }  
                   6709:         $others{$type} = $env{'form.'.$type.'_others'};
                   6710:         $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.134     raeburn  6711:         if ($type eq 'helpdeskmail') {
                   6712:             $bcc{$type} = $env{'form.'.$type.'_bcc'};
                   6713:             $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
                   6714:         }
1.28      raeburn  6715:     }
                   6716:     foreach my $item (@contacts) {
                   6717:         $to{$item} = $env{'form.'.$item};
                   6718:         $contacts_hash{'contacts'}{$item} = $to{$item};
                   6719:     }
1.203     raeburn  6720:     foreach my $item (@toggles) {
                   6721:         if ($env{'form.'.$item} =~ /^(0|1)$/) {
                   6722:             $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
                   6723:         }
                   6724:     }
1.28      raeburn  6725:     if (keys(%currsetting) > 0) {
                   6726:         foreach my $item (@contacts) {
                   6727:             if ($to{$item} ne $currsetting{$item}) {
                   6728:                 $changes{$item} = 1;
                   6729:             }
                   6730:         }
                   6731:         foreach my $type (@mailings) {
                   6732:             foreach my $item (@contacts) {
                   6733:                 if (ref($currsetting{$type}) eq 'HASH') {
                   6734:                     if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
                   6735:                         push(@{$changes{$type}},$item);
                   6736:                     }
                   6737:                 } else {
                   6738:                     push(@{$changes{$type}},@{$newsetting{$type}});
                   6739:                 }
                   6740:             }
                   6741:             if ($others{$type} ne $currsetting{$type}{'others'}) {
                   6742:                 push(@{$changes{$type}},'others');
                   6743:             }
1.134     raeburn  6744:             if ($type eq 'helpdeskmail') {   
                   6745:                 if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
                   6746:                     push(@{$changes{$type}},'bcc'); 
                   6747:                 }
                   6748:             }
1.28      raeburn  6749:         }
                   6750:     } else {
                   6751:         my %default;
                   6752:         $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
                   6753:         $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
                   6754:         $default{'errormail'} = 'adminemail';
                   6755:         $default{'packagesmail'} = 'adminemail';
                   6756:         $default{'helpdeskmail'} = 'supportemail';
1.89      raeburn  6757:         $default{'lonstatusmail'} = 'adminemail';
1.102     raeburn  6758:         $default{'requestsmail'} = 'adminemail';
1.190     raeburn  6759:         $default{'updatesmail'} = 'adminemail';
1.28      raeburn  6760:         foreach my $item (@contacts) {
                   6761:            if ($to{$item} ne $default{$item}) {
                   6762:               $changes{$item} = 1;
1.203     raeburn  6763:            }
1.28      raeburn  6764:         }
                   6765:         foreach my $type (@mailings) {
                   6766:             if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
                   6767:                
                   6768:                 push(@{$changes{$type}},@{$newsetting{$type}});
                   6769:             }
                   6770:             if ($others{$type} ne '') {
                   6771:                 push(@{$changes{$type}},'others');
1.134     raeburn  6772:             }
                   6773:             if ($type eq 'helpdeskmail') {
                   6774:                 if ($bcc{$type} ne '') {
                   6775:                     push(@{$changes{$type}},'bcc');
                   6776:                 }
                   6777:             }
1.28      raeburn  6778:         }
                   6779:     }
1.203     raeburn  6780:     foreach my $item (@toggles) {
                   6781:         if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
                   6782:             $changes{$item} = 1;
                   6783:         } elsif ((!$env{'form.'.$item}) &&
                   6784:                  (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
                   6785:             $changes{$item} = 1;
                   6786:         }
                   6787:     }
1.28      raeburn  6788:     my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
                   6789:                                              $dom);
                   6790:     if ($putresult eq 'ok') {
                   6791:         if (keys(%changes) > 0) {
1.205     raeburn  6792:             &Apache::loncommon::devalidate_domconfig_cache($dom);
                   6793:             $$lastactref = 'update';
1.28      raeburn  6794:             my ($titles,$short_titles)  = &contact_titles();
                   6795:             $resulttext = &mt('Changes made:').'<ul>';
                   6796:             foreach my $item (@contacts) {
                   6797:                 if ($changes{$item}) {
                   6798:                     $resulttext .= '<li>'.$titles->{$item}.
                   6799:                                     &mt(' set to: ').
                   6800:                                     '<span class="LC_cusr_emph">'.
                   6801:                                     $to{$item}.'</span></li>';
                   6802:                 }
                   6803:             }
                   6804:             foreach my $type (@mailings) {
                   6805:                 if (ref($changes{$type}) eq 'ARRAY') {
                   6806:                     $resulttext .= '<li>'.$titles->{$type}.': ';
                   6807:                     my @text;
                   6808:                     foreach my $item (@{$newsetting{$type}}) {
                   6809:                         push(@text,$short_titles->{$item});
                   6810:                     }
                   6811:                     if ($others{$type} ne '') {
                   6812:                         push(@text,$others{$type});
                   6813:                     }
                   6814:                     $resulttext .= '<span class="LC_cusr_emph">'.
1.134     raeburn  6815:                                    join(', ',@text).'</span>';
                   6816:                     if ($type eq 'helpdeskmail') {
                   6817:                         if ($bcc{$type} ne '') {
                   6818:                             $resulttext .= '&nbsp;'.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
                   6819:                         }
                   6820:                     }
                   6821:                     $resulttext .= '</li>';
1.28      raeburn  6822:                 }
                   6823:             }
1.203     raeburn  6824:             my @offon = ('off','on');
                   6825:             if ($changes{'reporterrors'}) {
                   6826:                 $resulttext .= '<li>'.
                   6827:                                &mt('E-mail error reports to [_1] set to "'.
                   6828:                                    $offon[$env{'form.reporterrors'}].'".',
                   6829:                                    &Apache::loncommon::modal_link('http://loncapa.org/core.html',
                   6830:                                        &mt('LON-CAPA core group - MSU'),600,500)).
                   6831:                                '</li>';
                   6832:             }
                   6833:             if ($changes{'reportupdates'}) {
                   6834:                 $resulttext .= '<li>'.
                   6835:                                 &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
                   6836:                                     $offon[$env{'form.reportupdates'}].'".',
                   6837:                                     &Apache::loncommon::modal_link('http://loncapa.org/core.html',
                   6838:                                         &mt('LON-CAPA core group - MSU'),600,500)).
                   6839:                                 '</li>';
                   6840:             }
1.28      raeburn  6841:             $resulttext .= '</ul>';
                   6842:         } else {
1.34      raeburn  6843:             $resulttext = &mt('No changes made to contact information');
1.28      raeburn  6844:         }
                   6845:     } else {
                   6846:         $resulttext = '<span class="LC_error">'.
                   6847:             &mt('An error occurred: [_1].',$putresult).'</span>';
                   6848:     }
                   6849:     return $resulttext;
                   6850: }
                   6851: 
                   6852: sub modify_usercreation {
1.27      raeburn  6853:     my ($dom,%domconfig) = @_;
1.34      raeburn  6854:     my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate);
1.43      raeburn  6855:     my $warningmsg;
1.27      raeburn  6856:     if (ref($domconfig{'usercreation'}) eq 'HASH') {
                   6857:         foreach my $key (keys(%{$domconfig{'usercreation'}})) {
                   6858:             $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
                   6859:         }
                   6860:     }
                   6861:     my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32      raeburn  6862:     my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.43      raeburn  6863:     my @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
1.100     raeburn  6864:     my @contexts = ('author','course','requestcrs','selfcreate');
1.34      raeburn  6865:     foreach my $item(@contexts) {
1.45      raeburn  6866:         if ($item eq 'selfcreate') {
1.50      raeburn  6867:             @{$cancreate{$item}} = &Apache::loncommon::get_env_multiple('form.can_createuser_'.$item);
1.43      raeburn  6868:             my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
                   6869:             if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) || ($domdefaults{'auth_def'} eq 'localauth'))) {
1.50      raeburn  6870:                 if (ref($cancreate{$item}) eq 'ARRAY') { 
                   6871:                     if (grep(/^login$/,@{$cancreate{$item}})) {
                   6872:                         $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.');   
                   6873:                     }
1.43      raeburn  6874:                 }
                   6875:             }
1.50      raeburn  6876:         } else {
                   6877:             $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.43      raeburn  6878:         }
1.34      raeburn  6879:     }
1.93      raeburn  6880:     my ($othertitle,$usertypes,$types) = 
                   6881:         &Apache::loncommon::sorted_inst_types($dom);
                   6882:     if (ref($types) eq 'ARRAY') {
                   6883:         if (@{$types} > 0) {
                   6884:             @{$cancreate{'statustocreate'}} = 
                   6885:                 &Apache::loncommon::get_env_multiple('form.statustocreate');
1.103     raeburn  6886:         } else {
                   6887:             @{$cancreate{'statustocreate'}} = ();
1.93      raeburn  6888:         }
                   6889:         push(@contexts,'statustocreate');
                   6890:     }
1.165     raeburn  6891:     &process_captcha('cancreate',\%changes,\%cancreate,\%curr_usercreation);
1.34      raeburn  6892:     if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
                   6893:         foreach my $item (@contexts) {
1.93      raeburn  6894:             if (($item eq 'selfcreate') || ($item eq 'statustocreate')) {
                   6895:                 if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
1.50      raeburn  6896:                     foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
1.103     raeburn  6897:                         if (ref($cancreate{$item}) eq 'ARRAY') {
                   6898:                             if (!grep(/^$curr$/,@{$cancreate{$item}})) {
                   6899:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   6900:                                     push(@{$changes{'cancreate'}},$item);
                   6901:                                 }
1.50      raeburn  6902:                             }
                   6903:                         }
                   6904:                     }
                   6905:                 } else {
                   6906:                     if ($curr_usercreation{'cancreate'}{$item} eq '') {
                   6907:                         if (@{$cancreate{$item}} > 0) {
                   6908:                             if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   6909:                                 push(@{$changes{'cancreate'}},$item);
                   6910:                             }
                   6911:                         }
                   6912:                     } else {
                   6913:                         if ($curr_usercreation{'cancreate'}{$item} eq 'any') {
                   6914:                             if (@{$cancreate{$item}} < 3) {
                   6915:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   6916:                                     push(@{$changes{'cancreate'}},$item);
                   6917:                                 }
                   6918:                             }
                   6919:                         } elsif ($curr_usercreation{'cancreate'}{$item} eq 'none') {
                   6920:                             if (@{$cancreate{$item}} > 0) {
                   6921:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   6922:                                     push(@{$changes{'cancreate'}},$item);
                   6923:                                 }
                   6924:                             }
                   6925:                         } elsif (!grep(/^$curr_usercreation{'cancreate'}{$item}$/,@{$cancreate{$item}})) {
                   6926:                             if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   6927:                                 push(@{$changes{'cancreate'}},$item);
                   6928:                             }
                   6929:                         }
                   6930:                     }
                   6931:                 }
                   6932:                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   6933:                     foreach my $type (@{$cancreate{$item}}) {
                   6934:                         if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
                   6935:                             if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
                   6936:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   6937:                                     push(@{$changes{'cancreate'}},$item);
                   6938:                                 }
                   6939:                             }
                   6940:                         } elsif (($curr_usercreation{'cancreate'}{$item} ne 'any') &&
                   6941:                                  ($curr_usercreation{'cancreate'}{$item} ne 'none')) {
                   6942:                             if ($curr_usercreation{'cancreate'}{$item} ne $type) {
                   6943:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   6944:                                     push(@{$changes{'cancreate'}},$item);
                   6945:                                 }
                   6946:                             }
                   6947:                         }
                   6948:                     }
                   6949:                 }
                   6950:             } else {
                   6951:                 if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
                   6952:                     push(@{$changes{'cancreate'}},$item);
                   6953:                 }
                   6954:             }
1.27      raeburn  6955:         }
1.34      raeburn  6956:     } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
                   6957:         foreach my $item (@contexts) {
1.43      raeburn  6958:             if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34      raeburn  6959:                 if ($cancreate{$item} ne 'any') {
                   6960:                     push(@{$changes{'cancreate'}},$item);
                   6961:                 }
                   6962:             } else {
                   6963:                 if ($cancreate{$item} ne 'none') {
                   6964:                     push(@{$changes{'cancreate'}},$item);
                   6965:                 }
1.27      raeburn  6966:             }
                   6967:         }
                   6968:     } else {
1.43      raeburn  6969:         foreach my $item (@contexts)  {
1.34      raeburn  6970:             push(@{$changes{'cancreate'}},$item);
                   6971:         }
1.27      raeburn  6972:     }
1.34      raeburn  6973: 
1.27      raeburn  6974:     if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
                   6975:         foreach my $type (@{$curr_usercreation{'username_rule'}}) {
                   6976:             if (!grep(/^\Q$type\E$/,@username_rule)) {
                   6977:                 push(@{$changes{'username_rule'}},$type);
                   6978:             }
                   6979:         }
                   6980:         foreach my $type (@username_rule) {
                   6981:             if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
                   6982:                 push(@{$changes{'username_rule'}},$type);
                   6983:             }
                   6984:         }
                   6985:     } else {
                   6986:         push(@{$changes{'username_rule'}},@username_rule);
                   6987:     }
                   6988: 
1.32      raeburn  6989:     if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
                   6990:         foreach my $type (@{$curr_usercreation{'id_rule'}}) {
                   6991:             if (!grep(/^\Q$type\E$/,@id_rule)) {
                   6992:                 push(@{$changes{'id_rule'}},$type);
                   6993:             }
                   6994:         }
                   6995:         foreach my $type (@id_rule) {
                   6996:             if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
                   6997:                 push(@{$changes{'id_rule'}},$type);
                   6998:             }
                   6999:         }
                   7000:     } else {
                   7001:         push(@{$changes{'id_rule'}},@id_rule);
                   7002:     }
                   7003: 
1.43      raeburn  7004:     if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
                   7005:         foreach my $type (@{$curr_usercreation{'email_rule'}}) {
                   7006:             if (!grep(/^\Q$type\E$/,@email_rule)) {
                   7007:                 push(@{$changes{'email_rule'}},$type);
                   7008:             }
                   7009:         }
                   7010:         foreach my $type (@email_rule) {
                   7011:             if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
                   7012:                 push(@{$changes{'email_rule'}},$type);
                   7013:             }
                   7014:         }
                   7015:     } else {
                   7016:         push(@{$changes{'email_rule'}},@email_rule);
                   7017:     }
                   7018: 
                   7019:     my @authen_contexts = ('author','course','domain');
1.28      raeburn  7020:     my @authtypes = ('int','krb4','krb5','loc');
                   7021:     my %authhash;
1.43      raeburn  7022:     foreach my $item (@authen_contexts) {
1.28      raeburn  7023:         my @authallowed =  &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
                   7024:         foreach my $auth (@authtypes) {
                   7025:             if (grep(/^\Q$auth\E$/,@authallowed)) {
                   7026:                 $authhash{$item}{$auth} = 1;
                   7027:             } else {
                   7028:                 $authhash{$item}{$auth} = 0;
                   7029:             }
                   7030:         }
                   7031:     }
                   7032:     if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43      raeburn  7033:         foreach my $item (@authen_contexts) {
1.28      raeburn  7034:             if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
                   7035:                 foreach my $auth (@authtypes) {
                   7036:                     if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
                   7037:                         push(@{$changes{'authtypes'}},$item);
                   7038:                         last;
                   7039:                     }
                   7040:                 }
                   7041:             }
                   7042:         }
                   7043:     } else {
1.43      raeburn  7044:         foreach my $item (@authen_contexts) {
1.28      raeburn  7045:             push(@{$changes{'authtypes'}},$item);
                   7046:         }
                   7047:     }
                   7048: 
1.27      raeburn  7049:     my %usercreation_hash =  (
1.28      raeburn  7050:             usercreation => {
1.34      raeburn  7051:                               cancreate     => \%cancreate,
1.27      raeburn  7052:                               username_rule => \@username_rule,
1.32      raeburn  7053:                               id_rule       => \@id_rule,
1.43      raeburn  7054:                               email_rule    => \@email_rule,
1.32      raeburn  7055:                               authtypes     => \%authhash,
1.27      raeburn  7056:                             }
                   7057:             );
                   7058: 
                   7059:     my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
                   7060:                                              $dom);
1.50      raeburn  7061: 
                   7062:     my %selfcreatetypes = (
                   7063:                              sso   => 'users authenticated by institutional single sign on',
                   7064:                              login => 'users authenticated by institutional log-in',
                   7065:                              email => 'users who provide a valid e-mail address for use as the username',
                   7066:                           );
1.27      raeburn  7067:     if ($putresult eq 'ok') {
                   7068:         if (keys(%changes) > 0) {
                   7069:             $resulttext = &mt('Changes made:').'<ul>';
                   7070:             if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.34      raeburn  7071:                 my %lt = &usercreation_types();
                   7072:                 foreach my $type (@{$changes{'cancreate'}}) {
1.100     raeburn  7073:                     my $chgtext;
1.165     raeburn  7074:                     unless (($type eq 'statustocreate') || ($type eq 'captcha') || ($type eq 'recaptchakeys')) {
1.100     raeburn  7075:                         $chgtext = $lt{$type}.', ';
                   7076:                     }
1.45      raeburn  7077:                     if ($type eq 'selfcreate') {
1.50      raeburn  7078:                         if (@{$cancreate{$type}} == 0) {
1.43      raeburn  7079:                             $chgtext .= &mt('creation of a new user account is not permitted.');
1.50      raeburn  7080:                         } else {
1.100     raeburn  7081:                             $chgtext .= &mt('creation of a new account is permitted for:').'<ul>';
1.50      raeburn  7082:                             foreach my $case (@{$cancreate{$type}}) {
                   7083:                                 $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
                   7084:                             }
                   7085:                             $chgtext .= '</ul>';
1.100     raeburn  7086:                             if (ref($cancreate{$type}) eq 'ARRAY') {
                   7087:                                 if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
                   7088:                                     if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
                   7089:                                         if (@{$cancreate{'statustocreate'}} == 0) {
                   7090:                                             $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
                   7091:                                         }
                   7092:                                     }
                   7093:                                 }
                   7094:                             }
1.43      raeburn  7095:                         }
1.93      raeburn  7096:                     } elsif ($type eq 'statustocreate') {
1.96      raeburn  7097:                         if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
                   7098:                             (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
                   7099:                             if (@{$cancreate{'selfcreate'}} > 0) {
                   7100:                                 if (@{$cancreate{'statustocreate'}} == 0) {
1.100     raeburn  7101: 
                   7102:                                     $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96      raeburn  7103:                                     if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.100     raeburn  7104:                                         $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
                   7105:                                     } 
1.96      raeburn  7106:                                 } elsif (ref($usertypes) eq 'HASH') {
                   7107:                                     if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100     raeburn  7108:                                         $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
                   7109:                                     } else {
                   7110:                                         $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
                   7111:                                     }
                   7112:                                     $chgtext .= '<ul>';
                   7113:                                     foreach my $case (@{$cancreate{$type}}) {
                   7114:                                         if ($case eq 'default') {
                   7115:                                             $chgtext .= '<li>'.$othertitle.'</li>';
                   7116:                                         } else {
                   7117:                                             $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93      raeburn  7118:                                         }
                   7119:                                     }
1.100     raeburn  7120:                                     $chgtext .= '</ul>';
                   7121:                                     if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
                   7122:                                         $chgtext .= '<br /><span class="LC_warning">'.&mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').'</span>';
                   7123:                                     }
                   7124:                                 }
                   7125:                             } else {
                   7126:                                 if (@{$cancreate{$type}} == 0) {
                   7127:                                     $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
                   7128:                                 } else {
                   7129:                                     $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  7130:                                 }
                   7131:                             }
                   7132:                         }
1.165     raeburn  7133:                     } elsif ($type eq 'captcha') {
                   7134:                         if ($cancreate{$type} eq 'notused') {
                   7135:                             $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
                   7136:                         } else {
                   7137:                             my %captchas = &captcha_phrases();
                   7138:                             if ($captchas{$cancreate{$type}}) {
                   7139:                                 $chgtext .= &mt("Validation for self-creation screen set to $captchas{$cancreate{$type}}.");
                   7140:                             } else {
                   7141:                                 $chgtext .= &mt('Validation for self-creation screen set to unknown type.'); 
                   7142:                             }
                   7143:                         }
                   7144:                     } elsif ($type eq 'recaptchakeys') {
                   7145:                         my ($privkey,$pubkey);
                   7146:                         if (ref($cancreate{$type}) eq 'HASH') {
                   7147:                             $pubkey = $cancreate{$type}{'public'};
                   7148:                             $privkey = $cancreate{$type}{'private'};
                   7149:                         }
                   7150:                         $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
                   7151:                         if (!$pubkey) {
                   7152:                             $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
                   7153:                         } else {
                   7154:                             $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
                   7155:                         }
                   7156:                         if (!$privkey) {
                   7157:                             $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
                   7158:                         } else {
                   7159:                             $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
                   7160:                         }
                   7161:                         $chgtext .= '</ul>';
1.43      raeburn  7162:                     } else {
                   7163:                         if ($cancreate{$type} eq 'none') {
                   7164:                             $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
                   7165:                         } elsif ($cancreate{$type} eq 'any') {
                   7166:                             $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
                   7167:                         } elsif ($cancreate{$type} eq 'official') {
                   7168:                             $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
                   7169:                         } elsif ($cancreate{$type} eq 'unofficial') {
                   7170:                             $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
                   7171:                         }
1.34      raeburn  7172:                     }
                   7173:                     $resulttext .= '<li>'.$chgtext.'</li>';
1.27      raeburn  7174:                 }
                   7175:             }
                   7176:             if (ref($changes{'username_rule'}) eq 'ARRAY') {
1.32      raeburn  7177:                 my ($rules,$ruleorder) = 
                   7178:                     &Apache::lonnet::inst_userrules($dom,'username');
1.27      raeburn  7179:                 my $chgtext = '<ul>';
                   7180:                 foreach my $type (@username_rule) {
                   7181:                     if (ref($rules->{$type}) eq 'HASH') {
                   7182:                         $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
                   7183:                     }
                   7184:                 }
                   7185:                 $chgtext .= '</ul>';
                   7186:                 if (@username_rule > 0) {
                   7187:                     $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';     
                   7188:                 } else {
1.28      raeburn  7189:                     $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>'; 
1.27      raeburn  7190:                 }
                   7191:             }
1.32      raeburn  7192:             if (ref($changes{'id_rule'}) eq 'ARRAY') {
                   7193:                 my ($idrules,$idruleorder) = 
                   7194:                     &Apache::lonnet::inst_userrules($dom,'id');
                   7195:                 my $chgtext = '<ul>';
                   7196:                 foreach my $type (@id_rule) {
                   7197:                     if (ref($idrules->{$type}) eq 'HASH') {
                   7198:                         $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
                   7199:                     }
                   7200:                 }
                   7201:                 $chgtext .= '</ul>';
                   7202:                 if (@id_rule > 0) {
                   7203:                     $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
                   7204:                 } else {
                   7205:                     $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
                   7206:                 }
                   7207:             }
1.43      raeburn  7208:             if (ref($changes{'email_rule'}) eq 'ARRAY') {
                   7209:                 my ($emailrules,$emailruleorder) =
                   7210:                     &Apache::lonnet::inst_userrules($dom,'email');
                   7211:                 my $chgtext = '<ul>';
                   7212:                 foreach my $type (@email_rule) {
                   7213:                     if (ref($emailrules->{$type}) eq 'HASH') {
                   7214:                         $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
                   7215:                     }
                   7216:                 }
                   7217:                 $chgtext .= '</ul>';
                   7218:                 if (@email_rule > 0) {
                   7219:                     $resulttext .= '<li>'.&mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').$chgtext.'</li>';
                   7220:                 } else {
                   7221:                     $resulttext .= '<li>'.&mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').'</li>';
                   7222:                 }
                   7223:             }
                   7224: 
1.28      raeburn  7225:             my %authname = &authtype_names();
                   7226:             my %context_title = &context_names();
                   7227:             if (ref($changes{'authtypes'}) eq 'ARRAY') {
                   7228:                 my $chgtext = '<ul>';
                   7229:                 foreach my $type (@{$changes{'authtypes'}}) {
                   7230:                     my @allowed;
                   7231:                     $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
                   7232:                     foreach my $auth (@authtypes) {
                   7233:                         if ($authhash{$type}{$auth}) {
                   7234:                             push(@allowed,$authname{$auth});
                   7235:                         }
                   7236:                     }
1.43      raeburn  7237:                     if (@allowed > 0) {
                   7238:                         $chgtext .= join(', ',@allowed).'</li>';
                   7239:                     } else {
                   7240:                         $chgtext .= &mt('none').'</li>';
                   7241:                     }
1.28      raeburn  7242:                 }
                   7243:                 $chgtext .= '</ul>';
                   7244:                 $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
                   7245:                 $resulttext .= '</li>';
                   7246:             }
1.27      raeburn  7247:             $resulttext .= '</ul>';
                   7248:         } else {
1.28      raeburn  7249:             $resulttext = &mt('No changes made to user creation settings');
1.27      raeburn  7250:         }
                   7251:     } else {
                   7252:         $resulttext = '<span class="LC_error">'.
1.23      raeburn  7253:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   7254:     }
1.43      raeburn  7255:     if ($warningmsg ne '') {
                   7256:         $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
                   7257:     }
1.23      raeburn  7258:     return $resulttext;
                   7259: }
                   7260: 
1.165     raeburn  7261: sub process_captcha {
                   7262:     my ($container,$changes,$newsettings,$current) = @_;
                   7263:     return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
                   7264:     $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
                   7265:     unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
                   7266:         $newsettings->{'captcha'} = 'original';
                   7267:     }
                   7268:     if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
1.169     raeburn  7269:         if ($container eq 'cancreate') { 
                   7270:             if (ref($changes->{'cancreate'}) eq 'ARRAY') {
                   7271:                 push(@{$changes->{'cancreate'}},'captcha');
                   7272:             } elsif (!defined($changes->{'cancreate'})) {
                   7273:                 $changes->{'cancreate'} = ['captcha'];
                   7274:             }
                   7275:         } else {
                   7276:             $changes->{'captcha'} = 1;
1.165     raeburn  7277:         }
                   7278:     }
                   7279:     my ($newpub,$newpriv,$currpub,$currpriv);
                   7280:     if ($newsettings->{'captcha'} eq 'recaptcha') {
                   7281:         $newpub = $env{'form.'.$container.'_recaptchapub'};
                   7282:         $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.169     raeburn  7283:         $newpub =~ s/\W//g;
                   7284:         $newpriv =~ s/\W//g;
                   7285:         $newsettings->{'recaptchakeys'} = {
                   7286:                                              public  => $newpub,
                   7287:                                              private => $newpriv,
                   7288:                                           };
1.165     raeburn  7289:     }
                   7290:     if (ref($current->{'recaptchakeys'}) eq 'HASH') {
                   7291:         $currpub = $current->{'recaptchakeys'}{'public'};
                   7292:         $currpriv = $current->{'recaptchakeys'}{'private'};
1.179     raeburn  7293:         unless ($newsettings->{'captcha'} eq 'recaptcha') {
                   7294:             $newsettings->{'recaptchakeys'} = {
                   7295:                                                  public  => '',
                   7296:                                                  private => '',
                   7297:                                               }
                   7298:         }
1.165     raeburn  7299:     }
                   7300:     if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169     raeburn  7301:         if ($container eq 'cancreate') {
                   7302:             if (ref($changes->{'cancreate'}) eq 'ARRAY') {
                   7303:                 push(@{$changes->{'cancreate'}},'recaptchakeys');
                   7304:             } elsif (!defined($changes->{'cancreate'})) {
                   7305:                 $changes->{'cancreate'} = ['recaptchakeys'];
                   7306:             }
                   7307:         } else {
                   7308:             $changes->{'recaptchakeys'} = 1; 
1.165     raeburn  7309:         }
                   7310:     }
                   7311:     return;
                   7312: }
                   7313: 
1.33      raeburn  7314: sub modify_usermodification {
                   7315:     my ($dom,%domconfig) = @_;
                   7316:     my ($resulttext,%curr_usermodification,%changes);
                   7317:     if (ref($domconfig{'usermodification'}) eq 'HASH') {
                   7318:         foreach my $key (keys(%{$domconfig{'usermodification'}})) {
                   7319:             $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
                   7320:         }
                   7321:     }
1.63      raeburn  7322:     my @contexts = ('author','course','selfcreate');
1.33      raeburn  7323:     my %context_title = (
                   7324:                            author => 'In author context',
                   7325:                            course => 'In course context',
1.63      raeburn  7326:                            selfcreate => 'When self creating account', 
1.33      raeburn  7327:                         );
                   7328:     my @fields = ('lastname','firstname','middlename','generation',
                   7329:                   'permanentemail','id');
                   7330:     my %roles = (
                   7331:                   author => ['ca','aa'],
                   7332:                   course => ['st','ep','ta','in','cr'],
                   7333:                 );
1.63      raeburn  7334:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   7335:     if (ref($types) eq 'ARRAY') {
                   7336:         push(@{$types},'default');
                   7337:         $usertypes->{'default'} = $othertitle;
                   7338:     }
                   7339:     $roles{'selfcreate'} = $types;  
1.33      raeburn  7340:     my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
                   7341:     my %modifyhash;
                   7342:     foreach my $context (@contexts) {
                   7343:         foreach my $role (@{$roles{$context}}) {
                   7344:             my @modifiable =  &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
                   7345:             foreach my $item (@fields) {
                   7346:                 if (grep(/^\Q$item\E$/,@modifiable)) {
                   7347:                     $modifyhash{$context}{$role}{$item} = 1;
                   7348:                 } else {
                   7349:                     $modifyhash{$context}{$role}{$item} = 0;
                   7350:                 }
                   7351:             }
                   7352:         }
                   7353:         if (ref($curr_usermodification{$context}) eq 'HASH') {
                   7354:             foreach my $role (@{$roles{$context}}) {
                   7355:                 if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
                   7356:                     foreach my $field (@fields) {
                   7357:                         if ($modifyhash{$context}{$role}{$field} ne 
                   7358:                                 $curr_usermodification{$context}{$role}{$field}) {
                   7359:                             push(@{$changes{$context}},$role);
                   7360:                             last;
                   7361:                         }
                   7362:                     }
                   7363:                 }
                   7364:             }
                   7365:         } else {
                   7366:             foreach my $context (@contexts) {
                   7367:                 foreach my $role (@{$roles{$context}}) {
                   7368:                     push(@{$changes{$context}},$role);
                   7369:                 }
                   7370:             }
                   7371:         }
                   7372:     }
                   7373:     my %usermodification_hash =  (
                   7374:                                    usermodification => \%modifyhash,
                   7375:                                  );
                   7376:     my $putresult = &Apache::lonnet::put_dom('configuration',
                   7377:                                              \%usermodification_hash,$dom);
                   7378:     if ($putresult eq 'ok') {
                   7379:         if (keys(%changes) > 0) {
                   7380:             $resulttext = &mt('Changes made: ').'<ul>';
                   7381:             foreach my $context (@contexts) {
                   7382:                 if (ref($changes{$context}) eq 'ARRAY') {
                   7383:                     $resulttext .= '<li>'.$context_title{$context}.':<ul>';
                   7384:                     if (ref($changes{$context}) eq 'ARRAY') {
                   7385:                         foreach my $role (@{$changes{$context}}) {
                   7386:                             my $rolename;
1.63      raeburn  7387:                             if ($context eq 'selfcreate') {
                   7388:                                 $rolename = $role;
                   7389:                                 if (ref($usertypes) eq 'HASH') {
                   7390:                                     if ($usertypes->{$role} ne '') {
                   7391:                                         $rolename = $usertypes->{$role};
                   7392:                                     }
                   7393:                                 }
1.33      raeburn  7394:                             } else {
1.63      raeburn  7395:                                 if ($role eq 'cr') {
                   7396:                                     $rolename = &mt('Custom');
                   7397:                                 } else {
                   7398:                                     $rolename = &Apache::lonnet::plaintext($role);
                   7399:                                 }
1.33      raeburn  7400:                             }
                   7401:                             my @modifiable;
1.63      raeburn  7402:                             if ($context eq 'selfcreate') {
1.126     bisitz   7403:                                 $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  7404:                             } else {
                   7405:                                 $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
                   7406:                             }
1.33      raeburn  7407:                             foreach my $field (@fields) {
                   7408:                                 if ($modifyhash{$context}{$role}{$field}) {
                   7409:                                     push(@modifiable,$fieldtitles{$field});
                   7410:                                 }
                   7411:                             }
                   7412:                             if (@modifiable > 0) {
                   7413:                                 $resulttext .= join(', ',@modifiable);
                   7414:                             } else {
                   7415:                                 $resulttext .= &mt('none'); 
                   7416:                             }
                   7417:                             $resulttext .= '</li>';
                   7418:                         }
                   7419:                         $resulttext .= '</ul></li>';
                   7420:                     }
                   7421:                 }
                   7422:             }
                   7423:             $resulttext .= '</ul>';
                   7424:         } else {
                   7425:             $resulttext = &mt('No changes made to user modification settings');
                   7426:         }
                   7427:     } else {
                   7428:         $resulttext = '<span class="LC_error">'.
                   7429:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   7430:     }
                   7431:     return $resulttext;
                   7432: }
                   7433: 
1.43      raeburn  7434: sub modify_defaults {
1.203     raeburn  7435:     my ($dom,$r,%domconfig) = @_;
1.43      raeburn  7436:     my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
                   7437:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.141     raeburn  7438:     my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
1.43      raeburn  7439:     my @authtypes = ('internal','krb4','krb5','localauth');
                   7440:     foreach my $item (@items) {
                   7441:         $newvalues{$item} = $env{'form.'.$item};
                   7442:         if ($item eq 'auth_def') {
                   7443:             if ($newvalues{$item} ne '') {
                   7444:                 if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
                   7445:                     push(@errors,$item);
                   7446:                 }
                   7447:             }
                   7448:         } elsif ($item eq 'lang_def') {
                   7449:             if ($newvalues{$item} ne '') {
                   7450:                 if ($newvalues{$item} =~ /^(\w+)/) {
                   7451:                     my $langcode = $1;
1.103     raeburn  7452:                     if ($langcode ne 'x_chef') {
                   7453:                         if (code2language($langcode) eq '') {
                   7454:                             push(@errors,$item);
                   7455:                         }
1.43      raeburn  7456:                     }
                   7457:                 } else {
                   7458:                     push(@errors,$item);
                   7459:                 }
                   7460:             }
1.54      raeburn  7461:         } elsif ($item eq 'timezone_def') {
                   7462:             if ($newvalues{$item} ne '') {
1.62      raeburn  7463:                 if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54      raeburn  7464:                     push(@errors,$item);   
                   7465:                 }
                   7466:             }
1.68      raeburn  7467:         } elsif ($item eq 'datelocale_def') {
                   7468:             if ($newvalues{$item} ne '') {
                   7469:                 my @datelocale_ids = DateTime::Locale->ids();
                   7470:                 if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
                   7471:                     push(@errors,$item);
                   7472:                 }
                   7473:             }
1.141     raeburn  7474:         } elsif ($item eq 'portal_def') {
                   7475:             if ($newvalues{$item} ne '') {
                   7476:                 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])\/?$/) {
                   7477:                     push(@errors,$item);
                   7478:                 }
                   7479:             }
1.43      raeburn  7480:         }
                   7481:         if (grep(/^\Q$item\E$/,@errors)) {
                   7482:             $newvalues{$item} = $domdefaults{$item};
                   7483:         } elsif ($domdefaults{$item} ne $newvalues{$item}) {
                   7484:             $changes{$item} = 1;
                   7485:         }
1.72      raeburn  7486:         $domdefaults{$item} = $newvalues{$item};
1.43      raeburn  7487:     }
                   7488:     my %defaults_hash = (
1.72      raeburn  7489:                          defaults => \%newvalues,
                   7490:                         );
1.43      raeburn  7491:     my $title = &defaults_titles();
                   7492:     my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
                   7493:                                              $dom);
                   7494:     if ($putresult eq 'ok') {
                   7495:         if (keys(%changes) > 0) {
                   7496:             $resulttext = &mt('Changes made:').'<ul>';
                   7497:             my $version = $r->dir_config('lonVersion');
                   7498:             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";
                   7499:             foreach my $item (sort(keys(%changes))) {
                   7500:                 my $value = $env{'form.'.$item};
                   7501:                 if ($value eq '') {
                   7502:                     $value = &mt('none');
                   7503:                 } elsif ($item eq 'auth_def') {
                   7504:                     my %authnames = &authtype_names();
                   7505:                     my %shortauth = (
                   7506:                              internal => 'int',
                   7507:                              krb4 => 'krb4',
                   7508:                              krb5 => 'krb5',
                   7509:                              localauth  => 'loc',
                   7510:                     );
                   7511:                     $value = $authnames{$shortauth{$value}};
                   7512:                 }
                   7513:                 $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
                   7514:                 $mailmsgtext .= "$title->{$item} set to $value\n";  
                   7515:             }
                   7516:             $resulttext .= '</ul>';
                   7517:             $mailmsgtext .= "\n";
                   7518:             my $cachetime = 24*60*60;
1.72      raeburn  7519:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.68      raeburn  7520:             if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203     raeburn  7521:                 my $notify = 1;
                   7522:                 if (ref($domconfig{'contacts'}) eq 'HASH') {
                   7523:                     if ($domconfig{'contacts'}{'reportupdates'} == 0) {
                   7524:                         $notify = 0;
                   7525:                     }
                   7526:                 }
                   7527:                 if ($notify) {
                   7528:                     &Apache::lonmsg::sendemail('installrecord@loncapa.org',
                   7529:                                                "LON-CAPA Domain Settings Change - $dom",
                   7530:                                                $mailmsgtext);
                   7531:                 }
1.54      raeburn  7532:             }
1.43      raeburn  7533:         } else {
1.54      raeburn  7534:             $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43      raeburn  7535:         }
                   7536:     } else {
                   7537:         $resulttext = '<span class="LC_error">'.
                   7538:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   7539:     }
                   7540:     if (@errors > 0) {
                   7541:         $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
                   7542:         foreach my $item (@errors) {
                   7543:             $resulttext .= ' "'.$title->{$item}.'",';
                   7544:         }
                   7545:         $resulttext =~ s/,$//;
                   7546:     }
                   7547:     return $resulttext;
                   7548: }
                   7549: 
1.46      raeburn  7550: sub modify_scantron {
1.205     raeburn  7551:     my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46      raeburn  7552:     my ($resulttext,%confhash,%changes,$errors);
                   7553:     my $custom = 'custom.tab';
                   7554:     my $default = 'default.tab';
                   7555:     my $servadm = $r->dir_config('lonAdmEMail');
                   7556:     my ($configuserok,$author_ok,$switchserver) = 
                   7557:         &config_check($dom,$confname,$servadm);
                   7558:     if ($env{'form.scantronformat.filename'} ne '') {
                   7559:         my $error;
                   7560:         if ($configuserok eq 'ok') {
                   7561:             if ($switchserver) {
1.130     raeburn  7562:                 $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46      raeburn  7563:             } else {
                   7564:                 if ($author_ok eq 'ok') {
                   7565:                     my ($result,$scantronurl) =
                   7566:                         &publishlogo($r,'upload','scantronformat',$dom,
                   7567:                                      $confname,'scantron','','',$custom);
                   7568:                     if ($result eq 'ok') {
                   7569:                         $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48      raeburn  7570:                         $changes{'scantronformat'} = 1;
1.46      raeburn  7571:                     } else {
                   7572:                         $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
                   7573:                     }
                   7574:                 } else {
                   7575:                     $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);
                   7576:                 }
                   7577:             }
                   7578:         } else {
                   7579:             $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);
                   7580:         }
                   7581:         if ($error) {
                   7582:             &Apache::lonnet::logthis($error);
                   7583:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   7584:         }
                   7585:     }
1.48      raeburn  7586:     if (ref($domconfig{'scantron'}) eq 'HASH') {
                   7587:         if ($domconfig{'scantron'}{'scantronformat'} ne '') {
                   7588:             if ($env{'form.scantronformat_del'}) {
                   7589:                 $confhash{'scantron'}{'scantronformat'} = '';
                   7590:                 $changes{'scantronformat'} = 1;
1.46      raeburn  7591:             }
                   7592:         }
                   7593:     }
                   7594:     if (keys(%confhash) > 0) {
                   7595:         my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
                   7596:                                                  $dom);
                   7597:         if ($putresult eq 'ok') {
                   7598:             if (keys(%changes) > 0) {
1.48      raeburn  7599:                 if (ref($confhash{'scantron'}) eq 'HASH') {
                   7600:                     $resulttext = &mt('Changes made:').'<ul>';
                   7601:                     if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130     raeburn  7602:                         $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48      raeburn  7603:                     } else {
1.130     raeburn  7604:                         $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46      raeburn  7605:                     }
1.48      raeburn  7606:                     $resulttext .= '</ul>';
                   7607:                 } else {
1.130     raeburn  7608:                     $resulttext = &mt('Changes made to bubblesheet format file.');
1.46      raeburn  7609:                 }
                   7610:                 $resulttext .= '</ul>';
                   7611:                 &Apache::loncommon::devalidate_domconfig_cache($dom);
1.206     raeburn  7612:                 $$lastactref = 'update';
1.46      raeburn  7613:             } else {
1.130     raeburn  7614:                 $resulttext = &mt('No changes made to bubblesheet format file');
1.46      raeburn  7615:             }
                   7616:         } else {
                   7617:             $resulttext = '<span class="LC_error">'.
                   7618:                 &mt('An error occurred: [_1]',$putresult).'</span>';
                   7619:         }
                   7620:     } else {
1.130     raeburn  7621:         $resulttext = &mt('No changes made to bubblesheet format file'); 
1.46      raeburn  7622:     }
                   7623:     if ($errors) {
                   7624:         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
                   7625:                        $errors.'</ul>';
                   7626:     }
                   7627:     return $resulttext;
                   7628: }
                   7629: 
1.48      raeburn  7630: sub modify_coursecategories {
                   7631:     my ($dom,%domconfig) = @_;
1.57      raeburn  7632:     my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
                   7633:         $cathash);
1.48      raeburn  7634:     my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.55      raeburn  7635:     if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57      raeburn  7636:         $cathash = $domconfig{'coursecategories'}{'cats'};
                   7637:         if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
                   7638:             $changes{'togglecats'} = 1;
                   7639:             $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
                   7640:         }
                   7641:         if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
                   7642:             $changes{'categorize'} = 1;
                   7643:             $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
                   7644:         }
1.120     raeburn  7645:         if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
                   7646:             $changes{'togglecatscomm'} = 1;
                   7647:             $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
                   7648:         }
                   7649:         if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
                   7650:             $changes{'categorizecomm'} = 1;
                   7651:             $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
                   7652:         }
1.57      raeburn  7653:     } else {
                   7654:         $changes{'togglecats'} = 1;
                   7655:         $changes{'categorize'} = 1;
1.124     raeburn  7656:         $changes{'togglecatscomm'} = 1;
                   7657:         $changes{'categorizecomm'} = 1;
1.87      raeburn  7658:         $domconfig{'coursecategories'} = {
                   7659:                                              togglecats => $env{'form.togglecats'},
                   7660:                                              categorize => $env{'form.categorize'},
1.124     raeburn  7661:                                              togglecatscomm => $env{'form.togglecatscomm'},
                   7662:                                              categorizecomm => $env{'form.categorizecomm'},
1.120     raeburn  7663:                                          };
1.57      raeburn  7664:     }
                   7665:     if (ref($cathash) eq 'HASH') {
                   7666:         if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '')  && ($env{'form.instcode'} == 0)) {
1.55      raeburn  7667:             push (@deletecategory,'instcode::0');
                   7668:         }
1.120     raeburn  7669:         if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '')  && ($env{'form.communities'} == 0)) {
                   7670:             push(@deletecategory,'communities::0');
                   7671:         }
1.48      raeburn  7672:     }
1.57      raeburn  7673:     my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
                   7674:     if (ref($cathash) eq 'HASH') {
1.48      raeburn  7675:         if (@deletecategory > 0) {
                   7676:             #FIXME Need to remove category from all courses using a deleted category 
1.57      raeburn  7677:             &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48      raeburn  7678:             foreach my $item (@deletecategory) {
1.57      raeburn  7679:                 if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
                   7680:                     delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48      raeburn  7681:                     $deletions{$item} = 1;
1.57      raeburn  7682:                     &recurse_cat_deletes($item,$cathash,\%deletions);
1.48      raeburn  7683:                 }
                   7684:             }
                   7685:         }
1.57      raeburn  7686:         foreach my $item (keys(%{$cathash})) {
1.48      raeburn  7687:             my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57      raeburn  7688:             if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48      raeburn  7689:                 $reorderings{$item} = 1;
1.57      raeburn  7690:                 $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48      raeburn  7691:             }
                   7692:             if ($env{'form.addcategory_name_'.$item} ne '') {
                   7693:                 my $newcat = $env{'form.addcategory_name_'.$item};
                   7694:                 my $newdepth = $depth+1;
                   7695:                 my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57      raeburn  7696:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48      raeburn  7697:                 $adds{$newitem} = 1; 
                   7698:             }
                   7699:             if ($env{'form.subcat_'.$item} ne '') {
                   7700:                 my $newcat = $env{'form.subcat_'.$item};
                   7701:                 my $newdepth = $depth+1;
                   7702:                 my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57      raeburn  7703:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48      raeburn  7704:                 $adds{$newitem} = 1;
                   7705:             }
                   7706:         }
                   7707:     }
                   7708:     if ($env{'form.instcode'} eq '1') {
1.57      raeburn  7709:         if (ref($cathash) eq 'HASH') {
1.48      raeburn  7710:             my $newitem = 'instcode::0';
1.57      raeburn  7711:             if ($cathash->{$newitem} eq '') {  
                   7712:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48      raeburn  7713:                 $adds{$newitem} = 1;
                   7714:             }
                   7715:         } else {
                   7716:             my $newitem = 'instcode::0';
1.57      raeburn  7717:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48      raeburn  7718:             $adds{$newitem} = 1;
                   7719:         }
                   7720:     }
1.120     raeburn  7721:     if ($env{'form.communities'} eq '1') {
                   7722:         if (ref($cathash) eq 'HASH') {
                   7723:             my $newitem = 'communities::0';
                   7724:             if ($cathash->{$newitem} eq '') {
                   7725:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
                   7726:                 $adds{$newitem} = 1;
                   7727:             }
                   7728:         } else {
                   7729:             my $newitem = 'communities::0';
                   7730:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
                   7731:             $adds{$newitem} = 1;
                   7732:         }
                   7733:     }
1.48      raeburn  7734:     if ($env{'form.addcategory_name'} ne '') {
1.120     raeburn  7735:         if (($env{'form.addcategory_name'} ne 'instcode') &&
                   7736:             ($env{'form.addcategory_name'} ne 'communities')) {
                   7737:             my $newitem = &escape($env{'form.addcategory_name'}).'::0';
                   7738:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
                   7739:             $adds{$newitem} = 1;
                   7740:         }
1.48      raeburn  7741:     }
1.57      raeburn  7742:     my $putresult;
1.48      raeburn  7743:     if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
                   7744:         if (keys(%deletions) > 0) {
                   7745:             foreach my $key (keys(%deletions)) {
                   7746:                 if ($predelallitems{$key} ne '') {
                   7747:                     $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
                   7748:                 }
                   7749:             }
                   7750:         }
                   7751:         my (@chkcats,@chktrails,%chkallitems);
1.57      raeburn  7752:         &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48      raeburn  7753:         if (ref($chkcats[0]) eq 'ARRAY') {
                   7754:             my $depth = 0;
                   7755:             my $chg = 0;
                   7756:             for (my $i=0; $i<@{$chkcats[0]}; $i++) {
                   7757:                 my $name = $chkcats[0][$i];
                   7758:                 my $item;
                   7759:                 if ($name eq '') {
                   7760:                     $chg ++;
                   7761:                 } else {
                   7762:                     $item = &escape($name).'::0';
                   7763:                     if ($chg) {
1.57      raeburn  7764:                         $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48      raeburn  7765:                     }
                   7766:                     $depth ++; 
1.57      raeburn  7767:                     &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48      raeburn  7768:                     $depth --;
                   7769:                 }
                   7770:             }
                   7771:         }
1.57      raeburn  7772:     }
                   7773:     if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
                   7774:         $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48      raeburn  7775:         if ($putresult eq 'ok') {
1.57      raeburn  7776:             my %title = (
1.120     raeburn  7777:                          togglecats     => 'Show/Hide a course in catalog',
                   7778:                          categorize     => 'Assign a category to a course',
                   7779:                          togglecatscomm => 'Show/Hide a community in catalog',
                   7780:                          categorizecomm => 'Assign a category to a community',
1.57      raeburn  7781:                         );
                   7782:             my %level = (
1.120     raeburn  7783:                          dom  => 'set in Domain ("Modify Course/Community")',
                   7784:                          crs  => 'set in Course ("Course Configuration")',
                   7785:                          comm => 'set in Community ("Community Configuration")',
1.57      raeburn  7786:                         );
1.48      raeburn  7787:             $resulttext = &mt('Changes made:').'<ul>';
1.57      raeburn  7788:             if ($changes{'togglecats'}) {
                   7789:                 $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>'; 
                   7790:             }
                   7791:             if ($changes{'categorize'}) {
                   7792:                 $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48      raeburn  7793:             }
1.120     raeburn  7794:             if ($changes{'togglecatscomm'}) {
                   7795:                 $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
                   7796:             }
                   7797:             if ($changes{'categorizecomm'}) {
                   7798:                 $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
                   7799:             }
1.57      raeburn  7800:             if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
                   7801:                 my $cathash;
                   7802:                 if (ref($domconfig{'coursecategories'}) eq 'HASH') {
                   7803:                     $cathash = $domconfig{'coursecategories'}{'cats'};
                   7804:                 } else {
                   7805:                     $cathash = {};
                   7806:                 } 
                   7807:                 my (@cats,@trails,%allitems);
                   7808:                     &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
                   7809:                 if (keys(%deletions) > 0) {
                   7810:                     $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
                   7811:                     foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) { 
                   7812:                         $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
                   7813:                     }
                   7814:                     $resulttext .= '</ul></li>';
                   7815:                 }
                   7816:                 if (keys(%reorderings) > 0) {
                   7817:                     my %sort_by_trail;
                   7818:                     $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
                   7819:                     foreach my $key (keys(%reorderings)) {
                   7820:                         if ($allitems{$key} ne '') {
                   7821:                             $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
                   7822:                         }
1.48      raeburn  7823:                     }
1.57      raeburn  7824:                     foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
                   7825:                         $resulttext .= '<li>'.$trails[$trail].'</li>';
                   7826:                     }
                   7827:                     $resulttext .= '</ul></li>';
1.48      raeburn  7828:                 }
1.57      raeburn  7829:                 if (keys(%adds) > 0) {
                   7830:                     my %sort_by_trail;
                   7831:                     $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
                   7832:                     foreach my $key (keys(%adds)) {
                   7833:                         if ($allitems{$key} ne '') {
                   7834:                             $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
                   7835:                         }
                   7836:                     }
                   7837:                     foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
                   7838:                         $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48      raeburn  7839:                     }
1.57      raeburn  7840:                     $resulttext .= '</ul></li>';
1.48      raeburn  7841:                 }
                   7842:             }
                   7843:             $resulttext .= '</ul>';
                   7844:         } else {
                   7845:             $resulttext = '<span class="LC_error">'.
1.57      raeburn  7846:                           &mt('An error occurred: [_1]',$putresult).'</span>';
1.48      raeburn  7847:         }
                   7848:     } else {
1.120     raeburn  7849:         $resulttext = &mt('No changes made to course and community categories');
1.48      raeburn  7850:     }
                   7851:     return $resulttext;
                   7852: }
                   7853: 
1.69      raeburn  7854: sub modify_serverstatuses {
                   7855:     my ($dom,%domconfig) = @_;
                   7856:     my ($resulttext,%changes,%currserverstatus,%newserverstatus);
                   7857:     if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
                   7858:         %currserverstatus = %{$domconfig{'serverstatuses'}};
                   7859:     }
                   7860:     my @pages = &serverstatus_pages();
                   7861:     foreach my $type (@pages) {
                   7862:         $newserverstatus{$type}{'namedusers'} = '';
                   7863:         $newserverstatus{$type}{'machines'} = '';
                   7864:         if (defined($env{'form.'.$type.'_namedusers'})) {
                   7865:             my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
                   7866:             my @okusers;
                   7867:             foreach my $user (@users) {
                   7868:                 my ($uname,$udom) = split(/:/,$user);
                   7869:                 if (($udom =~ /^$match_domain$/) &&   
                   7870:                     (&Apache::lonnet::domain($udom)) &&
                   7871:                     ($uname =~ /^$match_username$/)) {
                   7872:                     if (!grep(/^\Q$user\E/,@okusers)) {
                   7873:                         push(@okusers,$user);
                   7874:                     }
                   7875:                 }
                   7876:             }
                   7877:             if (@okusers > 0) {
                   7878:                  @okusers = sort(@okusers);
                   7879:                  $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
                   7880:             }
                   7881:         }
                   7882:         if (defined($env{'form.'.$type.'_machines'})) {
                   7883:             my @machines = split(/,/,$env{'form.'.$type.'_machines'});
                   7884:             my @okmachines;
                   7885:             foreach my $ip (@machines) {
                   7886:                 my @parts = split(/\./,$ip);
                   7887:                 next if (@parts < 4);
                   7888:                 my $badip = 0;
                   7889:                 for (my $i=0; $i<4; $i++) {
                   7890:                     if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
                   7891:                         $badip = 1;
                   7892:                         last;
                   7893:                     }
                   7894:                 }
                   7895:                 if (!$badip) {
                   7896:                     push(@okmachines,$ip);     
                   7897:                 }
                   7898:             }
                   7899:             @okmachines = sort(@okmachines);
                   7900:             $newserverstatus{$type}{'machines'} = join(',',@okmachines);
                   7901:         }
                   7902:     }
                   7903:     my %serverstatushash =  (
                   7904:                                 serverstatuses => \%newserverstatus,
                   7905:                             );
                   7906:     foreach my $type (@pages) {
1.83      raeburn  7907:         foreach my $setting ('namedusers','machines') {
1.84      raeburn  7908:             my (@current,@new);
1.83      raeburn  7909:             if (ref($currserverstatus{$type}) eq 'HASH') {
1.84      raeburn  7910:                 if ($currserverstatus{$type}{$setting} ne '') { 
                   7911:                     @current = split(/,/,$currserverstatus{$type}{$setting});
                   7912:                 }
                   7913:             }
                   7914:             if ($newserverstatus{$type}{$setting} ne '') {
                   7915:                 @new = split(/,/,$newserverstatus{$type}{$setting});
1.83      raeburn  7916:             }
                   7917:             if (@current > 0) {
                   7918:                 if (@new > 0) {
                   7919:                     foreach my $item (@current) {
                   7920:                         if (!grep(/^\Q$item\E$/,@new)) {
                   7921:                             $changes{$type}{$setting} = 1;
1.82      raeburn  7922:                             last;
                   7923:                         }
                   7924:                     }
1.84      raeburn  7925:                     foreach my $item (@new) {
                   7926:                         if (!grep(/^\Q$item\E$/,@current)) {
                   7927:                             $changes{$type}{$setting} = 1;
                   7928:                             last;
1.82      raeburn  7929:                         }
                   7930:                     }
                   7931:                 } else {
1.83      raeburn  7932:                     $changes{$type}{$setting} = 1;
1.69      raeburn  7933:                 }
1.83      raeburn  7934:             } elsif (@new > 0) {
                   7935:                 $changes{$type}{$setting} = 1;
1.69      raeburn  7936:             }
                   7937:         }
                   7938:     }
                   7939:     if (keys(%changes) > 0) {
1.81      raeburn  7940:         my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69      raeburn  7941:         my $putresult = &Apache::lonnet::put_dom('configuration',
                   7942:                                                  \%serverstatushash,$dom);
                   7943:         if ($putresult eq 'ok') {
                   7944:             $resulttext .= &mt('Changes made:').'<ul>';
                   7945:             foreach my $type (@pages) {
1.84      raeburn  7946:                 if (ref($changes{$type}) eq 'HASH') {
1.69      raeburn  7947:                     $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84      raeburn  7948:                     if ($changes{$type}{'namedusers'}) {
1.69      raeburn  7949:                         if ($newserverstatus{$type}{'namedusers'} eq '') {
                   7950:                             $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
                   7951:                         } else {
                   7952:                             $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
                   7953:                         }
1.84      raeburn  7954:                     }
                   7955:                     if ($changes{$type}{'machines'}) {
1.69      raeburn  7956:                         if ($newserverstatus{$type}{'machines'} eq '') {
                   7957:                             $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
                   7958:                         } else {
                   7959:                             $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
                   7960:                         }
                   7961: 
                   7962:                     }
                   7963:                     $resulttext .= '</ul></li>';
                   7964:                 }
                   7965:             }
                   7966:             $resulttext .= '</ul>';
                   7967:         } else {
                   7968:             $resulttext = '<span class="LC_error">'.
                   7969:                           &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
                   7970: 
                   7971:         }
                   7972:     } else {
                   7973:         $resulttext = &mt('No changes made to access to server status pages');
                   7974:     }
                   7975:     return $resulttext;
                   7976: }
                   7977: 
1.118     jms      7978: sub modify_helpsettings {
1.122     jms      7979:     my ($r,$dom,$confname,%domconfig) = @_;
1.166     raeburn  7980:     my ($resulttext,$errors,%changes,%helphash);
                   7981:     my %defaultchecked = ('submitbugs' => 'on');
                   7982:     my @offon = ('off','on');
1.118     jms      7983:     my @toggles = ('submitbugs');
                   7984:     if (ref($domconfig{'helpsettings'}) eq 'HASH') {
                   7985:         foreach my $item (@toggles) {
1.166     raeburn  7986:             if ($defaultchecked{$item} eq 'on') { 
                   7987:                 if ($domconfig{'helpsettings'}{$item} eq '') {
                   7988:                     if ($env{'form.'.$item} eq '0') {
                   7989:                         $changes{$item} = 1;
                   7990:                     }
                   7991:                 } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
                   7992:                     $changes{$item} = 1;
                   7993:                 }
                   7994:             } elsif ($defaultchecked{$item} eq 'off') {
                   7995:                 if ($domconfig{'helpsettings'}{$item} eq '') {
                   7996:                     if ($env{'form.'.$item} eq '1') {
                   7997:                         $changes{$item} = 1;
                   7998:                     }
                   7999:                 } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
                   8000:                     $changes{$item} = 1;
                   8001:                 }
                   8002:             }
                   8003:             if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) { 
                   8004:                 $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
                   8005:             }
                   8006:         }
1.118     jms      8007:     }
1.123     jms      8008:     my $putresult;
                   8009:     if (keys(%changes) > 0) {
1.166     raeburn  8010:         $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168     raeburn  8011:         if ($putresult eq 'ok') {
1.166     raeburn  8012:             $resulttext = &mt('Changes made:').'<ul>';
                   8013:             foreach my $item (sort(keys(%changes))) {
                   8014:                 if ($item eq 'submitbugs') {
                   8015:                     $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
                   8016:                                               &Apache::loncommon::modal_link('http://bugs.loncapa.org',
                   8017:                                               &mt('LON-CAPA bug tracker'),600,500)).'</li>';
                   8018:                 }
                   8019:             }
                   8020:             $resulttext .= '</ul>';
                   8021:         } else {
                   8022:             $resulttext = &mt('No changes made to help settings');
1.168     raeburn  8023:             $errors .= '<li><span class="LC_error">'.
                   8024:                        &mt('An error occurred storing the settings: [_1]',
                   8025:                            $putresult).'</span></li>';
1.166     raeburn  8026:         }
1.118     jms      8027:     }
                   8028:     if ($errors) {
1.168     raeburn  8029:         $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.118     jms      8030:                        $errors.'</ul>';
                   8031:     }
                   8032:     return $resulttext;
                   8033: }
                   8034: 
1.121     raeburn  8035: sub modify_coursedefaults {
                   8036:     my ($dom,%domconfig) = @_;
                   8037:     my ($resulttext,$errors,%changes,%defaultshash);
                   8038:     my %defaultchecked = ('canuse_pdfforms' => 'off');
                   8039:     my @toggles = ('canuse_pdfforms');
1.198     raeburn  8040:     my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
                   8041:                    'uploadquota_community');
                   8042:     my @types = ('official','unofficial','community');
                   8043:     my %staticdefaults = (
                   8044:                            anonsurvey_threshold => 10,
                   8045:                            uploadquota          => 500,
                   8046:                          );
1.121     raeburn  8047: 
                   8048:     $defaultshash{'coursedefaults'} = {};
                   8049: 
                   8050:     if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
                   8051:         if ($domconfig{'coursedefaults'} eq '') {
                   8052:             $domconfig{'coursedefaults'} = {};
                   8053:         }
                   8054:     }
                   8055: 
                   8056:     if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
                   8057:         foreach my $item (@toggles) {
                   8058:             if ($defaultchecked{$item} eq 'on') {
                   8059:                 if (($domconfig{'coursedefaults'}{$item} eq '') &&
                   8060:                     ($env{'form.'.$item} eq '0')) {
                   8061:                     $changes{$item} = 1;
1.192     raeburn  8062:                 } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121     raeburn  8063:                     $changes{$item} = 1;
                   8064:                 }
                   8065:             } elsif ($defaultchecked{$item} eq 'off') {
                   8066:                 if (($domconfig{'coursedefaults'}{$item} eq '') &&
                   8067:                     ($env{'form.'.$item} eq '1')) {
                   8068:                     $changes{$item} = 1;
                   8069:                 } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
                   8070:                     $changes{$item} = 1;
                   8071:                 }
                   8072:             }
                   8073:             $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
                   8074:         }
1.198     raeburn  8075:         foreach my $item (@numbers) {
                   8076:             my ($currdef,$newdef);
                   8077:             my $newdef = $env{'form.'.$item};
                   8078:             if ($item eq 'anonsurvey_threshold') {
                   8079:                 $currdef = $domconfig{'coursedefaults'}{$item};
                   8080:                 $newdef =~ s/\D//g;
                   8081:                 if ($newdef eq '' || $newdef < 1) {
                   8082:                     $newdef = 1;
                   8083:                 }
                   8084:                 $defaultshash{'coursedefaults'}{$item} = $newdef;
                   8085:             } else {
                   8086:                 my ($type) = ($item =~ /^\Quploadquota_\E(\w+)$/);
                   8087:                 if (ref($domconfig{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
                   8088:                     $currdef = $domconfig{'coursedefaults'}{'uploadquota'}{$type};
                   8089:                 }
                   8090:                 $newdef =~ s/[^\w.\-]//g;
                   8091:                 $defaultshash{'coursedefaults'}{'uploadquota'}{$type} = $newdef;
                   8092:             }
                   8093:             if ($currdef ne $newdef) {
                   8094:                 my $staticdef;
                   8095:                 if ($item eq 'anonsurvey_threshold') {
                   8096:                     unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
                   8097:                         $changes{$item} = 1;
                   8098:                     }
                   8099:                 } else {
                   8100:                     unless (($currdef eq '') && ($newdef == $staticdefaults{'uploadquota'})) {
                   8101:                         $changes{'uploadquota'} = 1;
                   8102:                     }
                   8103:                 }
1.139     raeburn  8104:             }
                   8105:         }
1.192     raeburn  8106:         my $officialcreds = $env{'form.official_credits'};
                   8107:         $officialcreds =~ s/^[^\d\.]//g;
                   8108:         my $unofficialcreds = $env{'form.unofficial_credits'};
                   8109:         $unofficialcreds =~ s/^[^\d\.]//g;
                   8110:         if (ref($domconfig{'coursedefaults'}{'coursecredits'} ne 'HASH') &&
                   8111:                 ($env{'form.coursecredits'} eq '1')) {
                   8112:                 $changes{'coursecredits'} = 1;
                   8113:         } else {
                   8114:             if (($domconfig{'coursedefaults'}{'coursecredits'}{'official'} ne $officialcreds)  ||
                   8115:                 ($domconfig{'coursedefaults'}{'coursecredits'}{'unofficial'} ne $unofficialcreds)) {
                   8116:                 $changes{'coursecredits'} = 1;
                   8117:             }
                   8118:         }
                   8119:         $defaultshash{'coursedefaults'}{'coursecredits'} = {
                   8120:             official   => $officialcreds,
                   8121:             unofficial => $unofficialcreds,
                   8122:         }
1.121     raeburn  8123:     }
                   8124:     my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
                   8125:                                              $dom);
                   8126:     if ($putresult eq 'ok') {
1.192     raeburn  8127:         my %domdefaults;
1.121     raeburn  8128:         if (keys(%changes) > 0) {
1.198     raeburn  8129:             if (($changes{'canuse_pdfforms'}) || ($changes{'coursecredits'}) || ($changes{'uploadquota'})) {
1.192     raeburn  8130:                 %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
                   8131:                 if ($changes{'canuse_pdfforms'}) {
                   8132:                     $domdefaults{'canuse_pdfforms'}=$defaultshash{'coursedefaults'}{'canuse_pdfforms'};
                   8133:                 }
                   8134:                 if ($changes{'coursecredits'}) {
                   8135:                     if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
                   8136:                         $domdefaults{'officialcredits'} =
                   8137:                             $defaultshash{'coursedefaults'}{'coursecredits'}{'official'};
                   8138:                         $domdefaults{'unofficialcredits'} =
                   8139:                             $defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'};
                   8140:                     }
                   8141:                 }
1.198     raeburn  8142:                 if ($changes{'uploadquota'}) {
                   8143:                     if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
                   8144:                         foreach my $type (@types) {
                   8145:                             $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
                   8146:                         }
                   8147:                     }
                   8148:                 }
1.121     raeburn  8149:                 my $cachetime = 24*60*60;
                   8150:                 &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
                   8151:             }
                   8152:             $resulttext = &mt('Changes made:').'<ul>';
                   8153:             foreach my $item (sort(keys(%changes))) {
                   8154:                 if ($item eq 'canuse_pdfforms') {
                   8155:                     if ($env{'form.'.$item} eq '1') {
                   8156:                         $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
                   8157:                     } else {
                   8158:                         $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
                   8159:                     }
1.139     raeburn  8160:                 } elsif ($item eq 'anonsurvey_threshold') {
1.192     raeburn  8161:                     $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198     raeburn  8162:                 } elsif ($item eq 'uploadquota') {
                   8163:                     if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
                   8164:                         $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
                   8165:                                        '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
                   8166:                                        '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
                   8167:                                        '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
                   8168:                                        '</ul>'.
                   8169:                                        '</li>';
                   8170:                     } else {
                   8171:                         $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
                   8172:                     }
1.192     raeburn  8173:                 } elsif ($item eq 'coursecredits') {
                   8174:                     if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
                   8175:                         if (($domdefaults{'officialcredits'} eq '') &&
                   8176:                             ($domdefaults{'unofficialcredits'} eq '')) {
                   8177:                             $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
                   8178:                         } else {
                   8179:                             $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
                   8180:                                            '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
                   8181:                                            '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
                   8182:                                            '</ul>'.
                   8183:                                            '</li>';
                   8184:                         }
                   8185:                     } else {
                   8186:                         $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
                   8187:                     }
1.140     raeburn  8188:                 }
1.121     raeburn  8189:             }
                   8190:             $resulttext .= '</ul>';
                   8191:         } else {
                   8192:             $resulttext = &mt('No changes made to course defaults');
                   8193:         }
                   8194:     } else {
                   8195:         $resulttext = '<span class="LC_error">'.
                   8196:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   8197:     }
                   8198:     return $resulttext;
                   8199: }
                   8200: 
1.137     raeburn  8201: sub modify_usersessions {
                   8202:     my ($dom,%domconfig) = @_;
1.145     raeburn  8203:     my @hostingtypes = ('version','excludedomain','includedomain');
                   8204:     my @offloadtypes = ('primary','default');
                   8205:     my %types = (
                   8206:                   remote => \@hostingtypes,
                   8207:                   hosted => \@hostingtypes,
                   8208:                   spares => \@offloadtypes,
                   8209:                 );
                   8210:     my @prefixes = ('remote','hosted','spares');
1.137     raeburn  8211:     my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138     raeburn  8212:     my (%by_ip,%by_location,@intdoms);
                   8213:     &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
                   8214:     my @locations = sort(keys(%by_location));
1.137     raeburn  8215:     my (%defaultshash,%changes);
                   8216:     foreach my $prefix (@prefixes) {
                   8217:         $defaultshash{'usersessions'}{$prefix} = {};
                   8218:     }
                   8219:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
                   8220:     my $resulttext;
1.138     raeburn  8221:     my %iphost = &Apache::lonnet::get_iphost();
1.137     raeburn  8222:     foreach my $prefix (@prefixes) {
1.145     raeburn  8223:         next if ($prefix eq 'spares');
                   8224:         foreach my $type (@{$types{$prefix}}) {
1.137     raeburn  8225:             my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
                   8226:             if ($type eq 'version') {
                   8227:                 my $value = $env{'form.'.$prefix.'_'.$type};
                   8228:                 my $okvalue;
                   8229:                 if ($value ne '') {
                   8230:                     if (grep(/^\Q$value\E$/,@lcversions)) {
                   8231:                         $okvalue = $value;
                   8232:                     }
                   8233:                 }
                   8234:                 if (ref($domconfig{'usersessions'}) eq 'HASH') {
                   8235:                     if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
                   8236:                         if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
                   8237:                             if ($inuse == 0) {
                   8238:                                 $changes{$prefix}{$type} = 1;
                   8239:                             } else {
                   8240:                                 if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
                   8241:                                     $changes{$prefix}{$type} = 1;
                   8242:                                 }
                   8243:                                 if ($okvalue ne '') {
                   8244:                                     $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
                   8245:                                 } 
                   8246:                             }
                   8247:                         } else {
                   8248:                             if (($inuse == 1) && ($okvalue ne '')) {
                   8249:                                 $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
                   8250:                                 $changes{$prefix}{$type} = 1;
                   8251:                             }
                   8252:                         }
                   8253:                     } else {
                   8254:                         if (($inuse == 1) && ($okvalue ne '')) {
                   8255:                             $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
                   8256:                             $changes{$prefix}{$type} = 1;
                   8257:                         }
                   8258:                     }
                   8259:                 } else {
                   8260:                     if (($inuse == 1) && ($okvalue ne '')) {
                   8261:                         $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
                   8262:                         $changes{$prefix}{$type} = 1;
                   8263:                     }
                   8264:                 }
                   8265:             } else {
                   8266:                 my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
                   8267:                 my @okvals;
                   8268:                 foreach my $val (@vals) {
1.138     raeburn  8269:                     if ($val =~ /:/) {
                   8270:                         my @items = split(/:/,$val);
                   8271:                         foreach my $item (@items) {
                   8272:                             if (ref($by_location{$item}) eq 'ARRAY') {
                   8273:                                 push(@okvals,$item);
                   8274:                             }
                   8275:                         }
                   8276:                     } else {
                   8277:                         if (ref($by_location{$val}) eq 'ARRAY') {
                   8278:                             push(@okvals,$val);
                   8279:                         }
1.137     raeburn  8280:                     }
                   8281:                 }
                   8282:                 @okvals = sort(@okvals);
                   8283:                 if (ref($domconfig{'usersessions'}) eq 'HASH') {
                   8284:                     if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
                   8285:                         if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
                   8286:                             if ($inuse == 0) {
                   8287:                                 $changes{$prefix}{$type} = 1; 
                   8288:                             } else {
                   8289:                                 $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
                   8290:                                 my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
                   8291:                                 if (@changed > 0) {
                   8292:                                     $changes{$prefix}{$type} = 1;
                   8293:                                 }
                   8294:                             }
                   8295:                         } else {
                   8296:                             if ($inuse == 1) {
                   8297:                                 $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
                   8298:                                 $changes{$prefix}{$type} = 1;
                   8299:                             }
                   8300:                         } 
                   8301:                     } else {
                   8302:                         if ($inuse == 1) {
                   8303:                             $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
                   8304:                             $changes{$prefix}{$type} = 1;
                   8305:                         }
                   8306:                     }
                   8307:                 } else {
                   8308:                     if ($inuse == 1) {
                   8309:                         $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
                   8310:                         $changes{$prefix}{$type} = 1;
                   8311:                     }
                   8312:                 }
                   8313:             }
                   8314:         }
                   8315:     }
1.145     raeburn  8316: 
                   8317:     my @alldoms = &Apache::lonnet::all_domains();
1.149     raeburn  8318:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145     raeburn  8319:     my %spareid = &current_offloads_to($dom,$domconfig{'usersessions'},\%servers);
                   8320:     my $savespares;
                   8321: 
                   8322:     foreach my $lonhost (sort(keys(%servers))) {
                   8323:         my $serverhomeID =
                   8324:             &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152     raeburn  8325:         my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145     raeburn  8326:         $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
                   8327:         my %spareschg;
                   8328:         foreach my $type (@{$types{'spares'}}) {
                   8329:             my @okspares;
                   8330:             my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
                   8331:             foreach my $server (@checked) {
1.152     raeburn  8332:                 if (&Apache::lonnet::hostname($server) ne '') {
                   8333:                     unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
                   8334:                         unless (grep(/^\Q$server\E$/,@okspares)) {
                   8335:                             push(@okspares,$server);
                   8336:                         }
1.145     raeburn  8337:                     }
                   8338:                 }
                   8339:             }
                   8340:             my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
                   8341:             my $newspare;
1.152     raeburn  8342:             if (($new ne '') && (&Apache::lonnet::hostname($new))) {
                   8343:                 unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145     raeburn  8344:                     $newspare = $new;
                   8345:                 }
                   8346:             }
1.152     raeburn  8347:             my @spares;
                   8348:             if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
                   8349:                 @spares = sort(@okspares,$newspare);
                   8350:             } else {
                   8351:                 @spares = sort(@okspares);
                   8352:             }
                   8353:             $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145     raeburn  8354:             if (ref($spareid{$lonhost}) eq 'HASH') {
                   8355:                 if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152     raeburn  8356:                     my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145     raeburn  8357:                     if (@diffs > 0) {
                   8358:                         $spareschg{$type} = 1;
                   8359:                     }
                   8360:                 }
                   8361:             }
                   8362:         }
                   8363:         if (keys(%spareschg) > 0) {
                   8364:             $changes{'spares'}{$lonhost} = \%spareschg;
                   8365:         }
                   8366:     }
                   8367: 
                   8368:     if (ref($domconfig{'usersessions'}) eq 'HASH') {
                   8369:         if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
                   8370:             if (ref($changes{'spares'}) eq 'HASH') {
                   8371:                 if (keys(%{$changes{'spares'}}) > 0) {
                   8372:                     $savespares = 1;
                   8373:                 }
                   8374:             }
                   8375:         } else {
                   8376:             $savespares = 1;
                   8377:         }
                   8378:     }
                   8379: 
1.147     raeburn  8380:     my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
                   8381:     if ((keys(%changes) > 0) || ($savespares)) {
1.137     raeburn  8382:         my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
                   8383:                                                  $dom);
                   8384:         if ($putresult eq 'ok') {
                   8385:             if (ref($defaultshash{'usersessions'}) eq 'HASH') {
                   8386:                 if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
                   8387:                     $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
                   8388:                 }
                   8389:                 if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
                   8390:                     $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
                   8391:                 }
                   8392:             }
                   8393:             my $cachetime = 24*60*60;
                   8394:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.147     raeburn  8395:             if (keys(%changes) > 0) {
                   8396:                 my %lt = &usersession_titles();
                   8397:                 $resulttext = &mt('Changes made:').'<ul>';
                   8398:                 foreach my $prefix (@prefixes) {
                   8399:                     if (ref($changes{$prefix}) eq 'HASH') {
                   8400:                         $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
                   8401:                         if ($prefix eq 'spares') {
                   8402:                             if (ref($changes{$prefix}) eq 'HASH') {
                   8403:                                 foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
                   8404:                                     $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148     raeburn  8405:                                     my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
                   8406:                                     &Apache::lonnet::remote_devalidate_cache($lonhost,'spares',$lonhostdom);
1.147     raeburn  8407:                                     if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
                   8408:                                         foreach my $type (@{$types{$prefix}}) {
                   8409:                                             if ($changes{$prefix}{$lonhost}{$type}) {
                   8410:                                                 my $offloadto = &mt('None');
                   8411:                                                 if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
                   8412:                                                     if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {   
                   8413:                                                         $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
                   8414:                                                     }
1.145     raeburn  8415:                                                 }
1.147     raeburn  8416:                                                 $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).('&nbsp;'x3);
1.145     raeburn  8417:                                             }
1.137     raeburn  8418:                                         }
                   8419:                                     }
1.147     raeburn  8420:                                     $resulttext .= '</li>';
1.137     raeburn  8421:                                 }
                   8422:                             }
1.147     raeburn  8423:                         } else {
                   8424:                             foreach my $type (@{$types{$prefix}}) {
                   8425:                                 if (defined($changes{$prefix}{$type})) {
                   8426:                                     my $newvalue;
                   8427:                                     if (ref($defaultshash{'usersessions'}) eq 'HASH') {
                   8428:                                         if (ref($defaultshash{'usersessions'}{$prefix})) {
                   8429:                                             if ($type eq 'version') {
                   8430:                                                 $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
                   8431:                                             } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
                   8432:                                                 if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
                   8433:                                                     $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
                   8434:                                                 }
1.145     raeburn  8435:                                             }
                   8436:                                         }
                   8437:                                     }
1.147     raeburn  8438:                                     if ($newvalue eq '') {
                   8439:                                         if ($type eq 'version') {
                   8440:                                             $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
                   8441:                                         } else {
                   8442:                                             $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
                   8443:                                         }
1.145     raeburn  8444:                                     } else {
1.147     raeburn  8445:                                         if ($type eq 'version') {
                   8446:                                             $newvalue .= ' '.&mt('(or later)'); 
                   8447:                                         }
                   8448:                                         $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145     raeburn  8449:                                     }
1.137     raeburn  8450:                                 }
                   8451:                             }
                   8452:                         }
1.147     raeburn  8453:                         $resulttext .= '</ul>';
1.137     raeburn  8454:                     }
                   8455:                 }
1.147     raeburn  8456:                 $resulttext .= '</ul>';
                   8457:             } else {
                   8458:                 $resulttext = $nochgmsg;
1.137     raeburn  8459:             }
                   8460:         } else {
                   8461:             $resulttext = '<span class="LC_error">'.
                   8462:                           &mt('An error occurred: [_1]',$putresult).'</span>';
                   8463:         }
                   8464:     } else {
1.147     raeburn  8465:         $resulttext = $nochgmsg;
1.137     raeburn  8466:     }
                   8467:     return $resulttext;
                   8468: }
                   8469: 
1.150     raeburn  8470: sub modify_loadbalancing {
                   8471:     my ($dom,%domconfig) = @_;
                   8472:     my $primary_id = &Apache::lonnet::domain($dom,'primary');
                   8473:     my $intdom = &Apache::lonnet::internet_dom($primary_id);
                   8474:     my ($othertitle,$usertypes,$types) =
                   8475:         &Apache::loncommon::sorted_inst_types($dom);
                   8476:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
                   8477:     my @sparestypes = ('primary','default');
                   8478:     my %typetitles = &sparestype_titles();
                   8479:     my $resulttext;
1.171     raeburn  8480:     my (%currbalancer,%currtargets,%currrules,%existing);
                   8481:     if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
                   8482:         %existing = %{$domconfig{'loadbalancing'}};
                   8483:     }
                   8484:     &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
                   8485:                               \%currtargets,\%currrules);
                   8486:     my ($saveloadbalancing,%defaultshash,%changes);
                   8487:     my ($alltypes,$othertypes,$titles) =
                   8488:         &loadbalancing_titles($dom,$intdom,$usertypes,$types);
                   8489:     my %ruletitles = &offloadtype_text();
                   8490:     my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
                   8491:     for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
                   8492:         my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
                   8493:         if ($balancer eq '') {
                   8494:             next;
                   8495:         }
                   8496:         if (!exists($servers{$balancer})) { 
                   8497:             if (exists($currbalancer{$balancer})) {
                   8498:                 push(@{$changes{'delete'}},$balancer);
1.150     raeburn  8499:             }
1.171     raeburn  8500:             next;
                   8501:         }
                   8502:         if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
                   8503:             push(@{$changes{'delete'}},$balancer);
                   8504:             next;
                   8505:         }
                   8506:         if (!exists($currbalancer{$balancer})) {
                   8507:             push(@{$changes{'add'}},$balancer);
                   8508:         }
                   8509:         $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
                   8510:         $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
                   8511:         $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
                   8512:         unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
                   8513:             $saveloadbalancing = 1;
                   8514:         }
                   8515:         foreach my $sparetype (@sparestypes) {
                   8516:             my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
                   8517:             my @offloadto;
                   8518:             foreach my $target (@targets) {
                   8519:                 if (($servers{$target}) && ($target ne $balancer)) {
                   8520:                     if ($sparetype eq 'default') {
                   8521:                         if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
                   8522:                             next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150     raeburn  8523:                         }
                   8524:                     }
1.171     raeburn  8525:                     unless(grep(/^\Q$target\E$/,@offloadto)) {
                   8526:                         push(@offloadto,$target);
                   8527:                     }
1.150     raeburn  8528:                 }
1.171     raeburn  8529:                 $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150     raeburn  8530:             }
                   8531:         }
1.171     raeburn  8532:         if (ref($currtargets{$balancer}) eq 'HASH') {
1.150     raeburn  8533:             foreach my $sparetype (@sparestypes) {
1.171     raeburn  8534:                 if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
                   8535:                     my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150     raeburn  8536:                     if (@targetdiffs > 0) {
1.171     raeburn  8537:                         $changes{'curr'}{$balancer}{'targets'} = 1;
1.150     raeburn  8538:                     }
1.171     raeburn  8539:                 } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
                   8540:                     if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
                   8541:                         $changes{'curr'}{$balancer}{'targets'} = 1;
1.150     raeburn  8542:                     }
                   8543:                 }
                   8544:             }
                   8545:         } else {
1.171     raeburn  8546:             if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
                   8547:                 foreach my $sparetype (@sparestypes) { 
                   8548:                     if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
                   8549:                         if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
                   8550:                             $changes{'curr'}{$balancer}{'targets'} = 1;
                   8551:                         }
1.150     raeburn  8552:                     }
                   8553:                 }
                   8554:             }  
                   8555:         }
                   8556:         my $ishomedom;
1.171     raeburn  8557:         if (&Apache::lonnet::host_domain($balancer) eq $dom) {
                   8558:             $ishomedom = 1;
1.150     raeburn  8559:         }
                   8560:         if (ref($alltypes) eq 'ARRAY') {
                   8561:             foreach my $type (@{$alltypes}) {
                   8562:                 my $rule;
1.171     raeburn  8563:                 unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) && 
1.150     raeburn  8564:                          (!$ishomedom)) {
1.171     raeburn  8565:                     $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
                   8566:                 }
                   8567:                 if ($rule eq 'specific') {
                   8568:                     $rule = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.150     raeburn  8569:                 }
1.171     raeburn  8570:                 $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
                   8571:                 if (ref($currrules{$balancer}) eq 'HASH') {
                   8572:                     if ($rule ne $currrules{$balancer}{$type}) {
                   8573:                         $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150     raeburn  8574:                     }
                   8575:                 } elsif ($rule ne '') {
1.171     raeburn  8576:                     $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150     raeburn  8577:                 }
                   8578:             }
                   8579:         }
1.171     raeburn  8580:     }
                   8581:     my $nochgmsg = &mt('No changes made to Load Balancer settings.');
                   8582:     if ((keys(%changes) > 0) || ($saveloadbalancing)) {
                   8583:         unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
                   8584:             $defaultshash{'loadbalancing'} = {};
                   8585:         }
                   8586:         my $putresult = &Apache::lonnet::put_dom('configuration',
                   8587:                                                  \%defaultshash,$dom);
                   8588:  
                   8589:         if ($putresult eq 'ok') {
                   8590:             if (keys(%changes) > 0) {
                   8591:                 if (ref($changes{'delete'}) eq 'ARRAY') {
                   8592:                     foreach my $balancer (sort(@{$changes{'delete'}})) {
                   8593:                         $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.150     raeburn  8594:                         &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
                   8595:                     }
1.171     raeburn  8596:                 }
                   8597:                 if (ref($changes{'add'}) eq 'ARRAY') {
                   8598:                     foreach my $balancer (sort(@{$changes{'add'}})) {   
                   8599:                         $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
                   8600:                     }
                   8601:                 }
                   8602:                 if (ref($changes{'curr'}) eq 'HASH') {
                   8603:                     foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
                   8604:                         if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
                   8605:                             if ($changes{'curr'}{$balancer}{'targets'}) {
                   8606:                                 my %offloadstr;
                   8607:                                 foreach my $sparetype (@sparestypes) {
                   8608:                                     if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
                   8609:                                         if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
                   8610:                                             $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
                   8611:                                         }
                   8612:                                     }
1.150     raeburn  8613:                                 }
1.171     raeburn  8614:                                 if (keys(%offloadstr) == 0) {
                   8615:                                     $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150     raeburn  8616:                                 } else {
1.171     raeburn  8617:                                     my $showoffload;
                   8618:                                     foreach my $sparetype (@sparestypes) {
                   8619:                                         $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>:&nbsp;';
                   8620:                                         if (defined($offloadstr{$sparetype})) {
                   8621:                                             $showoffload .= $offloadstr{$sparetype};
                   8622:                                         } else {
                   8623:                                             $showoffload .= &mt('None');
                   8624:                                         }
                   8625:                                         $showoffload .= ('&nbsp;'x3);
                   8626:                                     }
                   8627:                                     $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150     raeburn  8628:                                 }
                   8629:                             }
                   8630:                         }
1.171     raeburn  8631:                         if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
                   8632:                             if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
                   8633:                                 foreach my $type (@{$alltypes}) {
                   8634:                                     if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
                   8635:                                         my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
                   8636:                                         my $balancetext;
                   8637:                                         if ($rule eq '') {
                   8638:                                             $balancetext =  $ruletitles{'default'};
                   8639:                                         } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer')) {
                   8640:                                             $balancetext =  $ruletitles{$rule};
                   8641:                                         } else {
                   8642:                                             $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
                   8643:                                         }
                   8644:                                         $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';     
1.150     raeburn  8645:                                     }
                   8646:                                 }
                   8647:                             }
                   8648:                         }
1.171     raeburn  8649:                         &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
1.150     raeburn  8650:                     }
1.171     raeburn  8651:                 }
                   8652:                 if ($resulttext ne '') {
                   8653:                     $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150     raeburn  8654:                 } else {
                   8655:                     $resulttext = $nochgmsg;
                   8656:                 }
                   8657:             } else {
1.171     raeburn  8658:                 $resulttext = $nochgmsg;
1.150     raeburn  8659:             }
                   8660:         } else {
1.171     raeburn  8661:             $resulttext = '<span class="LC_error">'.
                   8662:                           &mt('An error occurred: [_1]',$putresult).'</span>';
1.150     raeburn  8663:         }
                   8664:     } else {
1.171     raeburn  8665:         $resulttext = $nochgmsg;
1.150     raeburn  8666:     }
                   8667:     return $resulttext;
                   8668: }
                   8669: 
1.48      raeburn  8670: sub recurse_check {
                   8671:     my ($chkcats,$categories,$depth,$name) = @_;
                   8672:     if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
                   8673:         my $chg = 0;
                   8674:         for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
                   8675:             my $category = $chkcats->[$depth]{$name}[$j];
                   8676:             my $item;
                   8677:             if ($category eq '') {
                   8678:                 $chg ++;
                   8679:             } else {
                   8680:                 my $deeper = $depth + 1;
                   8681:                 $item = &escape($category).':'.&escape($name).':'.$depth;
                   8682:                 if ($chg) {
                   8683:                     $categories->{$item} -= $chg;
                   8684:                 }
                   8685:                 &recurse_check($chkcats,$categories,$deeper,$category);
                   8686:                 $deeper --;
                   8687:             }
                   8688:         }
                   8689:     }
                   8690:     return;
                   8691: }
                   8692: 
                   8693: sub recurse_cat_deletes {
                   8694:     my ($item,$coursecategories,$deletions) = @_;
                   8695:     my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
                   8696:     my $subdepth = $depth + 1;
                   8697:     if (ref($coursecategories) eq 'HASH') {
                   8698:         foreach my $subitem (keys(%{$coursecategories})) {
                   8699:             my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
                   8700:             if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
                   8701:                 delete($coursecategories->{$subitem});
                   8702:                 $deletions->{$subitem} = 1;
                   8703:                 &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168     raeburn  8704:             }
1.48      raeburn  8705:         }
                   8706:     }
                   8707:     return;
                   8708: }
                   8709: 
1.125     raeburn  8710: sub get_active_dcs {
                   8711:     my ($dom) = @_;
1.191     raeburn  8712:     my $now = time;
                   8713:     my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
1.125     raeburn  8714:     my %domcoords;
                   8715:     my $numdcs = 0;
                   8716:     foreach my $server (keys(%dompersonnel)) {
                   8717:         foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
                   8718:             my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
1.191     raeburn  8719:             $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
1.125     raeburn  8720:         }
                   8721:     }
                   8722:     return %domcoords;
                   8723: }
                   8724: 
                   8725: sub active_dc_picker {
1.191     raeburn  8726:     my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.125     raeburn  8727:     my %domcoords = &get_active_dcs($dom); 
1.191     raeburn  8728:     my @domcoord = keys(%domcoords);
                   8729:     if (keys(%currhash)) {
                   8730:         foreach my $dc (keys(%currhash)) {
                   8731:             unless (exists($domcoords{$dc})) {
                   8732:                 push(@domcoord,$dc);
                   8733:             }
                   8734:         }
                   8735:     }
                   8736:     @domcoord = sort(@domcoord);
                   8737:     my $numdcs = scalar(@domcoord); 
                   8738:     my $rows = 0;
                   8739:     my $table;
1.125     raeburn  8740:     if ($numdcs > 1) {
1.191     raeburn  8741:         $table = '<table>';
                   8742:         for (my $i=0; $i<@domcoord; $i++) {
1.125     raeburn  8743:             my $rem = $i%($numinrow);
                   8744:             if ($rem == 0) {
                   8745:                 if ($i > 0) {
1.191     raeburn  8746:                     $table .= '</tr>';
1.125     raeburn  8747:                 }
1.191     raeburn  8748:                 $table .= '<tr>';
                   8749:                 $rows ++;
1.125     raeburn  8750:             }
1.191     raeburn  8751:             my $check = '';
                   8752:             if ($inputtype eq 'radio') {
                   8753:                 if (keys(%currhash) == 0) {
                   8754:                     if (!$i) {
                   8755:                         $check = ' checked="checked"';
                   8756:                     }
                   8757:                 } elsif (exists($currhash{$domcoord[$i]})) {
                   8758:                     $check = ' checked="checked"';
                   8759:                 }
                   8760:             } else {
                   8761:                 if (exists($currhash{$domcoord[$i]})) {
                   8762:                     $check = ' checked="checked"';
1.125     raeburn  8763:                 }
                   8764:             }
1.191     raeburn  8765:             if ($i == @domcoord - 1) {
1.125     raeburn  8766:                 my $colsleft = $numinrow - $rem;
                   8767:                 if ($colsleft > 1) {
1.191     raeburn  8768:                     $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125     raeburn  8769:                 } else {
1.191     raeburn  8770:                     $table .= '<td class="LC_left_item">';
1.125     raeburn  8771:                 }
                   8772:             } else {
1.191     raeburn  8773:                 $table .= '<td class="LC_left_item">';
                   8774:             }
                   8775:             my ($dcname,$dcdom) = split(':',$domcoord[$i]);
                   8776:             my $user = &Apache::loncommon::plainname($dcname,$dcdom);
                   8777:             $table .= '<span class="LC_nobreak"><label>'.
                   8778:                       '<input type="'.$inputtype.'" name="'.$name.'"'.
                   8779:                       ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
                   8780:             if ($user ne $dcname.':'.$dcdom) {
                   8781:                 $table .=  ' ('.$dcname.':'.$dcdom.')'.
                   8782:                            '</label></span></td>';
                   8783:             }
                   8784:         }
                   8785:         $table .= '</tr></table>';
                   8786:     } elsif ($numdcs == 1) {
                   8787:         if ($inputtype eq 'radio') {
                   8788:             $table .= '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />';
                   8789:         } else {
                   8790:             my $check;
                   8791:             if (exists($currhash{$domcoord[0]})) {
                   8792:                 $check = ' checked="checked"';
1.125     raeburn  8793:             }
1.191     raeburn  8794:             $table .= '<input type="checkbox" name="'.$name.'" '.
                   8795:                       'value="'.$domcoord[0].'"'.$check.' />';
                   8796:             $rows ++;
1.125     raeburn  8797:         }
                   8798:     }
1.191     raeburn  8799:     return ($numdcs,$table,$rows);
1.125     raeburn  8800: }
                   8801: 
1.137     raeburn  8802: sub usersession_titles {
                   8803:     return &Apache::lonlocal::texthash(
                   8804:                hosted => 'Hosting of sessions for users from other domains on servers in this domain',
                   8805:                remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145     raeburn  8806:                spares => 'Servers offloaded to, when busy',
1.137     raeburn  8807:                version => 'LON-CAPA version requirement',
1.138     raeburn  8808:                excludedomain => 'Allow all, but exclude specific domains',
                   8809:                includedomain => 'Deny all, but include specific domains',
1.145     raeburn  8810:                primary => 'Primary (checked first)',
1.154     raeburn  8811:                default => 'Default',
1.137     raeburn  8812:            );
                   8813: }
                   8814: 
1.152     raeburn  8815: sub id_for_thisdom {
                   8816:     my (%servers) = @_;
                   8817:     my %altids;
                   8818:     foreach my $server (keys(%servers)) {
                   8819:         my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
                   8820:         if ($serverhome ne $server) {
                   8821:             $altids{$serverhome} = $server;
                   8822:         }
                   8823:     }
                   8824:     return %altids;
                   8825: }
                   8826: 
1.150     raeburn  8827: sub count_servers {
                   8828:     my ($currbalancer,%servers) = @_;
                   8829:     my (@spares,$numspares);
                   8830:     foreach my $lonhost (sort(keys(%servers))) {
                   8831:         next if ($currbalancer eq $lonhost);
                   8832:         push(@spares,$lonhost);
                   8833:     }
                   8834:     if ($currbalancer) {
                   8835:         $numspares = scalar(@spares);
                   8836:     } else {
                   8837:         $numspares = scalar(@spares) - 1;
                   8838:     }
                   8839:     return ($numspares,@spares);
                   8840: }
                   8841: 
                   8842: sub lonbalance_targets_js {
1.171     raeburn  8843:     my ($dom,$types,$servers,$settings) = @_;
1.150     raeburn  8844:     my $select = &mt('Select');
                   8845:     my ($alltargets,$allishome,$allinsttypes,@alltypes);
                   8846:     if (ref($servers) eq 'HASH') {
                   8847:         $alltargets = join("','",sort(keys(%{$servers})));
                   8848:         my @homedoms;
                   8849:         foreach my $server (sort(keys(%{$servers}))) {
                   8850:             if (&Apache::lonnet::host_domain($server) eq $dom) {
                   8851:                 push(@homedoms,'1');
                   8852:             } else {
                   8853:                 push(@homedoms,'0');
                   8854:             }
                   8855:         }
                   8856:         $allishome = join("','",@homedoms);
                   8857:     }
                   8858:     if (ref($types) eq 'ARRAY') {
                   8859:         if (@{$types} > 0) {
                   8860:             @alltypes = @{$types};
                   8861:         }
                   8862:     }
                   8863:     push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
                   8864:     $allinsttypes = join("','",@alltypes);
1.171     raeburn  8865:     my (%currbalancer,%currtargets,%currrules,%existing);
                   8866:     if (ref($settings) eq 'HASH') {
                   8867:         %existing = %{$settings};
                   8868:     }
                   8869:     &get_loadbalancers_config($servers,\%existing,\%currbalancer,
                   8870:                               \%currtargets,\%currrules);
                   8871:     my $balancers = join("','",sort(keys(%currbalancer))); 
1.150     raeburn  8872:     return <<"END";
                   8873: 
                   8874: <script type="text/javascript">
                   8875: // <![CDATA[
                   8876: 
1.171     raeburn  8877: currBalancers = new Array('$balancers');
                   8878: 
                   8879: function toggleTargets(balnum) {
                   8880:     var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
                   8881:     var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
                   8882:     var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
                   8883:     var prevbalancer = prevhostitem.value;
                   8884:     var baltotal = document.getElementById('loadbalancing_total').value;
                   8885:     prevhostitem.value = balancer;
                   8886:     if (prevbalancer != '') {
                   8887:         var prevIdx = currBalancers.indexOf(prevbalancer);
                   8888:         if (prevIdx != -1) {
                   8889:             currBalancers.splice(prevIdx,1);
                   8890:         }
                   8891:     }
1.150     raeburn  8892:     if (balancer == '') {
1.171     raeburn  8893:         hideSpares(balnum);
1.150     raeburn  8894:     } else {
1.171     raeburn  8895:         var currIdx = currBalancers.indexOf(balancer);
                   8896:         if (currIdx == -1) {
                   8897:             currBalancers.push(balancer);
                   8898:         }
1.150     raeburn  8899:         var homedoms = new Array('$allishome');
1.171     raeburn  8900:         var ishomedom = homedoms[lonhostitem.selectedIndex];
                   8901:         showSpares(balancer,ishomedom,balnum);
1.150     raeburn  8902:     }
1.171     raeburn  8903:     balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150     raeburn  8904:     return;
                   8905: }
                   8906: 
1.171     raeburn  8907: function showSpares(balancer,ishomedom,balnum) {
1.150     raeburn  8908:     var alltargets = new Array('$alltargets');
                   8909:     var insttypes = new Array('$allinsttypes');
1.151     raeburn  8910:     var offloadtypes = new Array('primary','default');
                   8911: 
1.171     raeburn  8912:     document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
                   8913:     document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152     raeburn  8914:  
1.151     raeburn  8915:     for (var i=0; i<offloadtypes.length; i++) {
                   8916:         var count = 0;
                   8917:         for (var j=0; j<alltargets.length; j++) {
                   8918:             if (alltargets[j] != balancer) {
1.171     raeburn  8919:                 var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
                   8920:                 item.value = alltargets[j];
                   8921:                 item.style.textAlign='left';
                   8922:                 item.style.textFace='normal';
                   8923:                 document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
                   8924:                 if (currBalancers.indexOf(alltargets[j]) == -1) {
                   8925:                     item.disabled = '';
                   8926:                 } else {
                   8927:                     item.disabled = 'disabled';
                   8928:                     item.checked = false;
                   8929:                 }
1.151     raeburn  8930:                 count ++;
                   8931:             }
1.150     raeburn  8932:         }
                   8933:     }
1.151     raeburn  8934:     for (var k=0; k<insttypes.length; k++) {
                   8935:         if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150     raeburn  8936:             if (ishomedom == 1) {
1.171     raeburn  8937:                 document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
                   8938:                 document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150     raeburn  8939:             } else {
1.171     raeburn  8940:                 document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
                   8941:                 document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150     raeburn  8942: 
                   8943:             }
                   8944:         } else {
1.171     raeburn  8945:             document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
                   8946:             document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150     raeburn  8947:         }
1.151     raeburn  8948:         if ((insttypes[k] != '_LC_external') && 
                   8949:             ((insttypes[k] != '_LC_internetdom') ||
                   8950:              ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171     raeburn  8951:             var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
                   8952:             item.options.length = 0;
                   8953:             item.options[0] = new Option("","",true,true);
                   8954:             var idx = 0;  
1.151     raeburn  8955:             for (var m=0; m<alltargets.length; m++) {
1.171     raeburn  8956:                 if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
                   8957:                     idx ++;
                   8958:                     item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
                   8959:                     
1.150     raeburn  8960:                 }
                   8961:             }
                   8962:         }
                   8963:     }
                   8964:     return;
                   8965: }
                   8966: 
1.171     raeburn  8967: function hideSpares(balnum) {
1.150     raeburn  8968:     var alltargets = new Array('$alltargets');
                   8969:     var insttypes = new Array('$allinsttypes');
                   8970:     var offloadtypes = new Array('primary','default');
                   8971: 
1.171     raeburn  8972:     document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
                   8973:     document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150     raeburn  8974: 
                   8975:     var total = alltargets.length - 1;
                   8976:     for (var i=0; i<offloadtypes; i++) {
                   8977:         for (var j=0; j<total; j++) {
1.171     raeburn  8978:            document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
                   8979:            document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
                   8980:            document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151     raeburn  8981:         }
1.150     raeburn  8982:     }
                   8983:     for (var k=0; k<insttypes.length; k++) {
1.171     raeburn  8984:         document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
                   8985:         document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151     raeburn  8986:         if (insttypes[k] != '_LC_external') {
1.171     raeburn  8987:             document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
                   8988:             document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150     raeburn  8989:         }
                   8990:     }
                   8991:     return;
                   8992: }
                   8993: 
1.171     raeburn  8994: function checkOffloads(item,balnum,type) {
1.150     raeburn  8995:     var alltargets = new Array('$alltargets');
                   8996:     var offloadtypes = new Array('primary','default');
                   8997:     if (item.checked) {
                   8998:         var total = alltargets.length - 1;
                   8999:         var other;
                   9000:         if (type == offloadtypes[0]) {
1.151     raeburn  9001:             other = offloadtypes[1];
1.150     raeburn  9002:         } else {
1.151     raeburn  9003:             other = offloadtypes[0];
1.150     raeburn  9004:         }
                   9005:         for (var i=0; i<total; i++) {
1.171     raeburn  9006:             var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150     raeburn  9007:             if (server == item.value) {
1.171     raeburn  9008:                 if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
                   9009:                     document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150     raeburn  9010:                 }
                   9011:             }
                   9012:         }
                   9013:     }
                   9014:     return;
                   9015: }
                   9016: 
1.171     raeburn  9017: function singleServerToggle(balnum,type) {
                   9018:     var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150     raeburn  9019:     if (offloadtoSelIdx == 0) {
1.171     raeburn  9020:         document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
                   9021:         document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150     raeburn  9022: 
                   9023:     } else {
1.171     raeburn  9024:         document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
                   9025:         document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150     raeburn  9026:     }
                   9027:     return;
                   9028: }
                   9029: 
1.171     raeburn  9030: function balanceruleChange(formname,balnum,type) {
1.150     raeburn  9031:     if (type == '_LC_external') {
1.171     raeburn  9032:         return;
1.150     raeburn  9033:     }
1.171     raeburn  9034:     var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150     raeburn  9035:     for (var i=0; i<typesRules.length; i++) {
                   9036:         if (formname.elements[typesRules[i]].checked) {
                   9037:             if (formname.elements[typesRules[i]].value != 'specific') {
1.171     raeburn  9038:                 document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
                   9039:                 document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150     raeburn  9040:             } else {
1.171     raeburn  9041:                 document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
                   9042:             }
                   9043:         }
                   9044:     }
                   9045:     return;
                   9046: }
                   9047: 
                   9048: function balancerDeleteChange(balnum) {
                   9049:     var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
                   9050:     var baltotal = document.getElementById('loadbalancing_total').value;
                   9051:     var addtarget;
                   9052:     var removetarget;
                   9053:     var action = 'delete';
                   9054:     if (document.getElementById('loadbalancing_delete_'+balnum)) {
                   9055:         var lonhost = hostitem.value;
                   9056:         var currIdx = currBalancers.indexOf(lonhost);
                   9057:         if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
                   9058:             if (currIdx != -1) {
                   9059:                 currBalancers.splice(currIdx,1);
                   9060:             }
                   9061:             addtarget = lonhost;
                   9062:         } else {
                   9063:             if (currIdx == -1) {
                   9064:                 currBalancers.push(lonhost);
                   9065:             }
                   9066:             removetarget = lonhost;
                   9067:             action = 'undelete';
                   9068:         }
                   9069:         balancerChange(balnum,baltotal,action,addtarget,removetarget);
                   9070:     }
                   9071:     return;
                   9072: }
                   9073: 
                   9074: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
                   9075:     if (baltotal > 1) {
                   9076:         var offloadtypes = new Array('primary','default');
                   9077:         var alltargets = new Array('$alltargets');
                   9078:         var insttypes = new Array('$allinsttypes');
                   9079:         for (var i=0; i<baltotal; i++) {
                   9080:             if (i != balnum) {
                   9081:                 for (var j=0; j<offloadtypes.length; j++) {
                   9082:                     var total = alltargets.length - 1;
                   9083:                     for (var k=0; k<total; k++) {
                   9084:                         var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
                   9085:                         var server = serveritem.value;
                   9086:                         if ((action == 'delete') || (action == 'change' && addtarget != ''))  {
                   9087:                             if (server == addtarget) {
                   9088:                                 serveritem.disabled = '';
                   9089:                             }
                   9090:                         }
                   9091:                         if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
                   9092:                             if (server == removetarget) {
                   9093:                                 serveritem.disabled = 'disabled';
                   9094:                                 serveritem.checked = false;
                   9095:                             }
                   9096:                         }
                   9097:                     }
                   9098:                 }
                   9099:                 for (var j=0; j<insttypes.length; j++) {
                   9100:                     if (insttypes[j] != '_LC_external') {
                   9101:                         if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
                   9102:                             var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
                   9103:                             var currSel = singleserver.selectedIndex;
                   9104:                             var currVal = singleserver.options[currSel].value;
                   9105:                             if ((action == 'delete') || (action == 'change' && addtarget != '')) {
                   9106:                                 var numoptions = singleserver.options.length;
                   9107:                                 var needsnew = 1;
                   9108:                                 for (var k=0; k<numoptions; k++) {
                   9109:                                     if (singleserver.options[k] == addtarget) {
                   9110:                                         needsnew = 0;
                   9111:                                         break;
                   9112:                                     }
                   9113:                                 }
                   9114:                                 if (needsnew == 1) {
                   9115:                                     singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
                   9116:                                 }
                   9117:                             }
                   9118:                             if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
                   9119:                                 singleserver.options.length = 0;
                   9120:                                 if ((currVal) && (currVal != removetarget)) {
                   9121:                                     singleserver.options[0] = new Option("","",false,false);
                   9122:                                 } else {
                   9123:                                     singleserver.options[0] = new Option("","",true,true);
                   9124:                                 }
                   9125:                                 var idx = 0;
                   9126:                                 for (var m=0; m<alltargets.length; m++) {
                   9127:                                     if (currBalancers.indexOf(alltargets[m]) == -1) {
                   9128:                                         idx ++;
                   9129:                                         if (currVal == alltargets[m]) {
                   9130:                                             singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
                   9131:                                         } else {
                   9132:                                             singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
                   9133:                                         }
                   9134:                                     }
                   9135:                                 }
                   9136:                             }
                   9137:                         }
                   9138:                     }
                   9139:                 }
1.150     raeburn  9140:             }
                   9141:         }
                   9142:     }
                   9143:     return;
                   9144: }
                   9145: 
1.152     raeburn  9146: // ]]>
                   9147: </script>
                   9148: 
                   9149: END
                   9150: }
                   9151: 
                   9152: sub new_spares_js {
                   9153:     my @sparestypes = ('primary','default');
                   9154:     my $types = join("','",@sparestypes);
                   9155:     my $select = &mt('Select');
                   9156:     return <<"END";
                   9157: 
                   9158: <script type="text/javascript">
                   9159: // <![CDATA[
                   9160: 
                   9161: function updateNewSpares(formname,lonhost) {
                   9162:     var types = new Array('$types');
                   9163:     var include = new Array();
                   9164:     var exclude = new Array();
                   9165:     for (var i=0; i<types.length; i++) {
                   9166:         var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
                   9167:         for (var j=0; j<spareboxes.length; j++) {
                   9168:             if (formname.elements[spareboxes[j]].checked) {
                   9169:                 exclude.push(formname.elements[spareboxes[j]].value);
                   9170:             } else {
                   9171:                 include.push(formname.elements[spareboxes[j]].value);
                   9172:             }
                   9173:         }
                   9174:     }
                   9175:     for (var i=0; i<types.length; i++) {
                   9176:         var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
                   9177:         var selIdx = newSpare.selectedIndex;
                   9178:         var currnew = newSpare.options[selIdx].value;
                   9179:         var okSpares = new Array();
                   9180:         for (var j=0; j<newSpare.options.length; j++) {
                   9181:             var possible = newSpare.options[j].value;
                   9182:             if (possible != '') {
                   9183:                 if (exclude.indexOf(possible) == -1) {
                   9184:                     okSpares.push(possible);
                   9185:                 } else {
                   9186:                     if (currnew == possible) {
                   9187:                         selIdx = 0;
                   9188:                     }
                   9189:                 }
                   9190:             }
                   9191:         }
                   9192:         for (var k=0; k<include.length; k++) {
                   9193:             if (okSpares.indexOf(include[k]) == -1) {
                   9194:                 okSpares.push(include[k]);
                   9195:             }
                   9196:         }
                   9197:         okSpares.sort();
                   9198:         newSpare.options.length = 0;
                   9199:         if (selIdx == 0) {
                   9200:             newSpare.options[0] = new Option("$select","",true,true);
                   9201:         } else {
                   9202:             newSpare.options[0] = new Option("$select","",false,false);
                   9203:         }
                   9204:         for (var m=0; m<okSpares.length; m++) {
                   9205:             var idx = m+1;
                   9206:             var selThis = 0;
                   9207:             if (selIdx != 0) {
                   9208:                 if (okSpares[m] == currnew) {
                   9209:                     selThis = 1;
                   9210:                 }
                   9211:             }
                   9212:             if (selThis == 1) {
                   9213:                 newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
                   9214:             } else {
                   9215:                 newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
                   9216:             }
                   9217:         }
                   9218:     }
                   9219:     return;
                   9220: }
                   9221: 
                   9222: function checkNewSpares(lonhost,type) {
                   9223:     var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
                   9224:     var chosen =  newSpare.options[newSpare.selectedIndex].value;
                   9225:     if (chosen != '') { 
                   9226:         var othertype;
                   9227:         var othernewSpare;
                   9228:         if (type == 'primary') {
                   9229:             othernewSpare = document.getElementById('newspare_default_'+lonhost);
                   9230:         }
                   9231:         if (type == 'default') {
                   9232:             othernewSpare = document.getElementById('newspare_primary_'+lonhost);
                   9233:         }
                   9234:         if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
                   9235:             othernewSpare.selectedIndex = 0;
                   9236:         }
                   9237:     }
                   9238:     return;
                   9239: }
                   9240: 
                   9241: // ]]>
                   9242: </script>
                   9243: 
                   9244: END
                   9245: 
                   9246: }
                   9247: 
                   9248: sub common_domprefs_js {
                   9249:     return <<"END";
                   9250: 
                   9251: <script type="text/javascript">
                   9252: // <![CDATA[
                   9253: 
1.150     raeburn  9254: function getIndicesByName(formname,item) {
1.152     raeburn  9255:     var group = new Array();
1.150     raeburn  9256:     for (var i=0;i<formname.elements.length;i++) {
                   9257:         if (formname.elements[i].name == item) {
1.152     raeburn  9258:             group.push(formname.elements[i].id);
1.150     raeburn  9259:         }
                   9260:     }
1.152     raeburn  9261:     return group;
1.150     raeburn  9262: }
                   9263: 
                   9264: // ]]>
                   9265: </script>
                   9266: 
                   9267: END
1.152     raeburn  9268: 
1.150     raeburn  9269: }
                   9270: 
1.165     raeburn  9271: sub recaptcha_js {
                   9272:     my %lt = &captcha_phrases();
                   9273:     return <<"END";
                   9274: 
                   9275: <script type="text/javascript">
                   9276: // <![CDATA[
                   9277: 
                   9278: function updateCaptcha(caller,context) {
                   9279:     var privitem;
                   9280:     var pubitem;
                   9281:     var privtext;
                   9282:     var pubtext;
                   9283:     if (document.getElementById(context+'_recaptchapub')) {
                   9284:         pubitem = document.getElementById(context+'_recaptchapub');
                   9285:     } else {
                   9286:         return;
                   9287:     }
                   9288:     if (document.getElementById(context+'_recaptchapriv')) {
                   9289:         privitem = document.getElementById(context+'_recaptchapriv');
                   9290:     } else {
                   9291:         return;
                   9292:     }
                   9293:     if (document.getElementById(context+'_recaptchapubtxt')) {
                   9294:         pubtext = document.getElementById(context+'_recaptchapubtxt');
                   9295:     } else {
                   9296:         return;
                   9297:     }
                   9298:     if (document.getElementById(context+'_recaptchaprivtxt')) {
                   9299:         privtext = document.getElementById(context+'_recaptchaprivtxt');
                   9300:     } else {
                   9301:         return;
                   9302:     }
                   9303:     if (caller.checked) {
                   9304:         if (caller.value == 'recaptcha') {
                   9305:             pubitem.type = 'text';
                   9306:             privitem.type = 'text';
                   9307:             pubitem.size = '40';
                   9308:             privitem.size = '40';
                   9309:             pubtext.innerHTML = "$lt{'pub'}";
                   9310:             privtext.innerHTML = "$lt{'priv'}";
                   9311:         } else {
                   9312:             pubitem.type = 'hidden';
                   9313:             privitem.type = 'hidden';
                   9314:             pubtext.innerHTML = '';
                   9315:             privtext.innerHTML = '';
                   9316:         }
                   9317:     }
                   9318:     return;
                   9319: }
                   9320: 
                   9321: // ]]>
                   9322: </script>
                   9323: 
                   9324: END
                   9325: 
                   9326: }
                   9327: 
1.192     raeburn  9328: sub credits_js {
                   9329:     return <<"END";
                   9330: 
                   9331: <script type="text/javascript">
                   9332: // <![CDATA[
                   9333: 
                   9334: function toggleCredits(domForm) {
                   9335:     if (document.getElementById('credits')) {
                   9336:         creditsitem = document.getElementById('credits');
                   9337:         var creditsLength = domForm.coursecredits.length;
                   9338:         if (creditsLength) {
                   9339:             var currval;
                   9340:             for (var i=0; i<creditsLength; i++) {
                   9341:                 if (domForm.coursecredits[i].checked) {
                   9342:                    currval = domForm.coursecredits[i].value;
                   9343:                 }
                   9344:             }
                   9345:             if (currval == 1) {
                   9346:                 creditsitem.style.display = 'block';
                   9347:             } else {
                   9348:                 creditsitem.style.display = 'none';
                   9349:             }
                   9350:         }
                   9351:     }
                   9352:     return;
                   9353: }
                   9354: 
                   9355: // ]]>
                   9356: </script>
                   9357: 
                   9358: END
                   9359: 
                   9360: }
                   9361: 
1.165     raeburn  9362: sub captcha_phrases {
                   9363:     return &Apache::lonlocal::texthash (
                   9364:                  priv => 'Private key',
                   9365:                  pub  => 'Public key',
                   9366:                  original  => 'original (CAPTCHA)',
                   9367:                  recaptcha => 'successor (ReCAPTCHA)',
                   9368:                  notused   => 'unused',
                   9369:     );
                   9370: }
                   9371: 
1.205     raeburn  9372: 
                   9373: sub devalidate_remote_domconfs {
                   9374:     my ($dom) = @_;
                   9375:     my $primary_id = &Apache::lonnet::domain($dom,'primary');
                   9376:     my $intdom = &Apache::lonnet::internet_dom($primary_id);
                   9377:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
                   9378:     my %thismachine;
                   9379:     map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
                   9380:     if (keys(%servers) > 1) {
                   9381:         foreach my $server (keys(%servers)) {
                   9382:             next if ($thismachine{$server});
                   9383:             &Apache::lonnet::remote_devalidate_cache($server,'domainconfig',$dom);
                   9384:         }
                   9385:     }
                   9386:     return;
                   9387: }
                   9388: 
1.3       raeburn  9389: 1;

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