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

1.1       raeburn     1: # The LearningOnline Network with CAPA
                      2: # Handler to set domain-wide configuration settings
                      3: #
1.211   ! raeburn     4: # $Id: domainprefs.pm,v 1.210 2013/09/29 06:53:35 raeburn Exp $
1.2       albertel    5: #
1.1       raeburn     6: # Copyright Michigan State University Board of Trustees
                      7: #
                      8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                      9: #
                     10: # LON-CAPA is free software; you can redistribute it and/or modify
                     11: # it under the terms of the GNU General Public License as published by
                     12: # the Free Software Foundation; either version 2 of the License, or
                     13: # (at your option) any later version.
                     14: #
                     15: # LON-CAPA is distributed in the hope that it will be useful,
                     16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     18: # GNU General Public License for more details.
                     19: #
                     20: # You should have received a copy of the GNU General Public License
                     21: # along with LON-CAPA; if not, write to the Free Software
                     22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA#
                     23: # /home/httpd/html/adm/gpl.txt
                     24: #
                     25: # http://www.lon-capa.org/
                     26: #
                     27: #
                     28: ###############################################################
                     29: ##############################################################
                     30: 
1.101     raeburn    31: =pod
                     32: 
                     33: =head1 NAME
                     34: 
                     35: Apache::domainprefs.pm
                     36: 
                     37: =head1 SYNOPSIS
                     38: 
                     39: Handles configuration of a LON-CAPA domain.  
                     40: 
                     41: This is part of the LearningOnline Network with CAPA project
                     42: described at http://www.lon-capa.org.
                     43: 
                     44: 
                     45: =head1 OVERVIEW
                     46: 
                     47: Each institution using LON-CAPA will typically have a single domain designated 
1.183     bisitz     48: for use by individuals affiliated with the institution.  Accordingly, each domain
1.101     raeburn    49: may define a default set of logos and a color scheme which can be used to "brand"
                     50: the LON-CAPA instance. In addition, an institution will typically have a language
                     51: and timezone which are used for the majority of courses.
                     52: 
                     53: LON-CAPA provides a mechanism to display and modify these defaults, as well as a 
                     54: host of other domain-wide settings which determine the types of functionality
                     55: available to users and courses in the domain.
                     56: 
                     57: There is also a mechanism to configure cataloging of courses in the domain, and
                     58: controls on the operation of automated processes which govern such things as
                     59: roster updates, user directory updates and processing of course requests.
                     60: 
                     61: The domain coordination manual which is built dynamically on install/update of 
                     62: LON-CAPA from the relevant help items provides more information about domain 
                     63: configuration.
                     64: 
                     65: Most of the domain settings are stored in the configuration.db GDBM file which is
                     66: housed on the primary library server for the domain in /home/httpd/lonUsers/$dom,
                     67: where $dom is the domain.  The configuration.db stores settings in a number of 
                     68: frozen hashes of hashes.  In a few cases, domain information must be uploaded to
                     69: the domain as files (e.g., image files for logos etc., or plain text files for
                     70: bubblesheet formats).  In this case the domainprefs.pm must be running in a user
                     71: session hosted on the primary library server in the domain, as these files are 
                     72: stored in author space belonging to a special $dom-domainconfig user.   
                     73: 
                     74: domainprefs.pm in combination with lonconfigsettings.pm will retrieve and display
                     75: the current settings, and provides an interface to make modifications.
                     76: 
                     77: =head1 SUBROUTINES
                     78: 
                     79: =over
                     80: 
                     81: =item print_quotas()
                     82: 
                     83: Inputs: 4 
                     84: 
                     85: $dom,$settings,$rowtotal,$action.
                     86: 
                     87: $dom is the domain, $settings is a reference to a hash of current settings for
                     88: the current context, $rowtotal is a reference to the scalar used to record the 
1.210     raeburn    89: number of rows displayed on the page, and $action is the context (quotas, 
1.163     raeburn    90: requestcourses or requestauthor).
1.101     raeburn    91: 
                     92: The print_quotas routine was orginally created to display/store information
                     93: about default quota sizes for portfolio spaces for the different types of 
                     94: institutional affiliation in the domain (e.g., Faculty, Staff, Student etc.), 
                     95: but is now also used to manage availability of user tools: 
                     96: i.e., blogs, aboutme page, and portfolios, and the course request tool,
1.197     raeburn    97: used by course owners to request creation of a course, and to display/store
                     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.',
1.210     raeburn   445:                           $confname).
1.181     raeburn   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.210     raeburn   578:         if (($action eq 'rolecolors') || ($action eq 'coursecategories') ||
1.168     raeburn   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');
1.210     raeburn  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.208     raeburn  1966:     my ($now,$datatable,%currapp);
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.210     raeburn  2159:         if ($settings->{'xmldc'} ne '') {
1.191     raeburn  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);';
1.210     raeburn  2545:         my $display = 'none';
1.192     raeburn  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);
1.209     raeburn  3000:     my $rownum = 8;
1.150     raeburn  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 '') {
1.210     raeburn  3031:             $datatable .= '<span class="LC_nobreak">';
1.171     raeburn  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:             }
1.210     raeburn  3047:             $datatable .=
1.171     raeburn  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:                 }
1.210     raeburn  3086:                 $targettable .=
1.171     raeburn  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.210     raeburn  3170:     my ($alltypes,$othertypes,$titles) =
1.150     raeburn  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:             }
1.209     raeburn  3179:             if (($type eq '_LC_external') || ($type eq '_LC_internetdom') || ($type eq '_LC_ipchange')) {
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),
1.209     raeburn  3200:            '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
                   3201:            '_LC_ipchange'    => &mt('Non-SSO users with IP mismatch'),
1.150     raeburn  3202:                      );
1.209     raeburn  3203:     my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.150     raeburn  3204:     if (ref($types) eq 'ARRAY') {
                   3205:         unshift(@alltypes,@{$types},'default');
                   3206:     }
                   3207:     my %titles;
                   3208:     foreach my $type (@alltypes) {
                   3209:         if ($type =~ /^_LC_/) {
                   3210:             $titles{$type} = $othertypes{$type};
                   3211:         } elsif ($type eq 'default') {
                   3212:             $titles{$type} = &mt('All users from [_1]',$dom);
                   3213:             if (ref($types) eq 'ARRAY') {
                   3214:                 if (@{$types} > 0) {
                   3215:                     $titles{$type} = &mt('Other users from [_1]',$dom);
                   3216:                 }
                   3217:             }
                   3218:         } elsif (ref($usertypes) eq 'HASH') {
                   3219:             $titles{$type} = $usertypes->{$type};
                   3220:         }
                   3221:     }
                   3222:     return (\@alltypes,\%othertypes,\%titles);
                   3223: }
                   3224: 
                   3225: sub loadbalance_rule_row {
1.171     raeburn  3226:     my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
                   3227:         $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.209     raeburn  3228:     my @rulenames;
1.150     raeburn  3229:     my %ruletitles = &offloadtype_text();
1.209     raeburn  3230:     if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
                   3231:         @rulenames = ('balancer','offloadedto');
1.150     raeburn  3232:     } else {
1.209     raeburn  3233:         @rulenames = ('default','homeserver');
                   3234:         if ($type eq '_LC_external') {
                   3235:             push(@rulenames,'externalbalancer');
                   3236:         } else {
                   3237:             push(@rulenames,'specific');
                   3238:         }
                   3239:         push(@rulenames,'none');
1.150     raeburn  3240:     }
                   3241:     my $style = $targets_div_style;
1.209     raeburn  3242:     if (($type eq '_LC_external') || ($type eq '_LC_internetdom') || ($type eq '_LC_ipchange')) {
1.150     raeburn  3243:         $style = $homedom_div_style;
                   3244:     }
1.171     raeburn  3245:     my $space;
                   3246:     if ($islast && $num == 1) {
                   3247:         $space = '<div display="inline-block">&nbsp;</div>';
                   3248:     }
1.210     raeburn  3249:     my $output =
1.171     raeburn  3250:         '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
                   3251:         '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
                   3252:         '<td valaign="top">'.$space.
                   3253:         '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150     raeburn  3254:     for (my $i=0; $i<@rulenames; $i++) {
                   3255:         my $rule = $rulenames[$i];
                   3256:         my ($checked,$extra);
                   3257:         if ($rulenames[$i] eq 'default') {
                   3258:             $rule = '';
                   3259:         }
                   3260:         if ($rulenames[$i] eq 'specific') {
                   3261:             if (ref($servers) eq 'HASH') {
                   3262:                 my $default;
                   3263:                 if (($current ne '') && (exists($servers->{$current}))) {
                   3264:                     $checked = ' checked="checked"';
                   3265:                 }
                   3266:                 unless ($checked) {
                   3267:                     $default = ' selected="selected"';
                   3268:                 }
1.210     raeburn  3269:                 $extra =
1.171     raeburn  3270:                     ':&nbsp;<select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
                   3271:                     '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
                   3272:                     '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
                   3273:                     '<option value=""'.$default.'></option>'."\n";
                   3274:                 foreach my $server (sort(keys(%{$servers}))) {
                   3275:                     if (ref($currbalancer) eq 'HASH') {
                   3276:                         next if (exists($currbalancer->{$server}));
                   3277:                     }
1.150     raeburn  3278:                     my $selected;
1.171     raeburn  3279:                     if ($server eq $current) {
1.150     raeburn  3280:                         $selected = ' selected="selected"';
                   3281:                     }
1.171     raeburn  3282:                     $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150     raeburn  3283:                 }
                   3284:                 $extra .= '</select>';
                   3285:             }
                   3286:         } elsif ($rule eq $current) {
                   3287:             $checked = ' checked="checked"';
                   3288:         }
                   3289:         $output .= '<span class="LC_nobreak"><label>'.
1.171     raeburn  3290:                    '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
                   3291:                    '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
                   3292:                    $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.150     raeburn  3293:                    ')"'.$checked.' />&nbsp;'.$ruletitles{$rulenames[$i]}.
                   3294:                    '</label>'.$extra.'</span><br />'."\n";
                   3295:     }
                   3296:     $output .= '</div></td></tr>'."\n";
                   3297:     return $output;
                   3298: }
                   3299: 
                   3300: sub offloadtype_text {
                   3301:     my %ruletitles = &Apache::lonlocal::texthash (
                   3302:            'default'          => 'Offloads to default destinations',
                   3303:            'homeserver'       => "Offloads to user's home server",
                   3304:            'externalbalancer' => "Offloads to Load Balancer in user's domain",
                   3305:            'specific'         => 'Offloads to specific server',
1.161     raeburn  3306:            'none'             => 'No offload',
1.209     raeburn  3307:            'balancer'         => 'Session hosted on Load Balancer, after re-authentication',
                   3308:            'offloadedto'      => 'Session hosted on offload server, after re-authentication',
1.150     raeburn  3309:     );
                   3310:     return %ruletitles;
                   3311: }
                   3312: 
                   3313: sub sparestype_titles {
                   3314:     my %typestitles = &Apache::lonlocal::texthash (
                   3315:                           'primary' => 'primary',
                   3316:                           'default' => 'default',
                   3317:                       );
                   3318:     return %typestitles;
                   3319: }
                   3320: 
1.28      raeburn  3321: sub contact_titles {
                   3322:     my %titles = &Apache::lonlocal::texthash (
                   3323:                    'supportemail' => 'Support E-mail address',
1.69      raeburn  3324:                    'adminemail'   => 'Default Server Admin E-mail address',
1.28      raeburn  3325:                    'errormail'    => 'Error reports to be e-mailed to',
                   3326:                    'packagesmail' => 'Package update alerts to be e-mailed to',
1.89      raeburn  3327:                    'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
                   3328:                    'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
1.102     raeburn  3329:                    'requestsmail' => 'E-mail from course requests requiring approval',
1.190     raeburn  3330:                    'updatesmail'  => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.203     raeburn  3331:                    'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.28      raeburn  3332:                  );
                   3333:     my %short_titles = &Apache::lonlocal::texthash (
                   3334:                            adminemail   => 'Admin E-mail address',
                   3335:                            supportemail => 'Support E-mail',
                   3336:                        );   
                   3337:     return (\%titles,\%short_titles);
                   3338: }
                   3339: 
1.72      raeburn  3340: sub tool_titles {
                   3341:     my %titles = &Apache::lonlocal::texthash (
1.162     raeburn  3342:                      aboutme    => 'Personal web page',
1.86      raeburn  3343:                      blog       => 'Blog',
1.162     raeburn  3344:                      webdav     => 'WebDAV',
1.86      raeburn  3345:                      portfolio  => 'Portfolio',
1.88      bisitz   3346:                      official   => 'Official courses (with institutional codes)',
                   3347:                      unofficial => 'Unofficial courses',
1.98      raeburn  3348:                      community  => 'Communities',
1.86      raeburn  3349:                  );
1.72      raeburn  3350:     return %titles;
                   3351: }
                   3352: 
1.101     raeburn  3353: sub courserequest_titles {
                   3354:     my %titles = &Apache::lonlocal::texthash (
                   3355:                                    official   => 'Official',
                   3356:                                    unofficial => 'Unofficial',
                   3357:                                    community  => 'Communities',
                   3358:                                    norequest  => 'Not allowed',
1.104     raeburn  3359:                                    approval   => 'Approval by Dom. Coord.',
1.101     raeburn  3360:                                    validate   => 'With validation',
                   3361:                                    autolimit  => 'Numerical limit',
1.103     raeburn  3362:                                    unlimited  => '(blank for unlimited)',
1.101     raeburn  3363:                  );
                   3364:     return %titles;
                   3365: }
                   3366: 
1.163     raeburn  3367: sub authorrequest_titles {
                   3368:     my %titles = &Apache::lonlocal::texthash (
                   3369:                                    norequest  => 'Not allowed',
                   3370:                                    approval   => 'Approval by Dom. Coord.',
                   3371:                                    automatic  => 'Automatic approval',
                   3372:                  );
                   3373:     return %titles;
1.210     raeburn  3374: }
1.163     raeburn  3375: 
1.101     raeburn  3376: sub courserequest_conditions {
                   3377:     my %conditions = &Apache::lonlocal::texthash (
1.104     raeburn  3378:        approval    => '(Processing of request subject to approval by Domain Coordinator).',
1.193     bisitz   3379:        validate   => '(Processing of request subject to institutional validation).',
1.101     raeburn  3380:                  );
                   3381:     return %conditions;
                   3382: }
                   3383: 
                   3384: 
1.27      raeburn  3385: sub print_usercreation {
1.30      raeburn  3386:     my ($position,$dom,$settings,$rowtotal) = @_;
1.27      raeburn  3387:     my $numinrow = 4;
1.28      raeburn  3388:     my $datatable;
                   3389:     if ($position eq 'top') {
1.30      raeburn  3390:         $$rowtotal ++;
1.34      raeburn  3391:         my $rowcount = 0;
1.32      raeburn  3392:         my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28      raeburn  3393:         if (ref($rules) eq 'HASH') {
                   3394:             if (keys(%{$rules}) > 0) {
1.32      raeburn  3395:                 $datatable .= &user_formats_row('username',$settings,$rules,
                   3396:                                                 $ruleorder,$numinrow,$rowcount);
1.30      raeburn  3397:                 $$rowtotal ++;
1.32      raeburn  3398:                 $rowcount ++;
                   3399:             }
                   3400:         }
                   3401:         my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
                   3402:         if (ref($idrules) eq 'HASH') {
                   3403:             if (keys(%{$idrules}) > 0) {
                   3404:                 $datatable .= &user_formats_row('id',$settings,$idrules,
                   3405:                                                 $idruleorder,$numinrow,$rowcount);
                   3406:                 $$rowtotal ++;
                   3407:                 $rowcount ++;
1.28      raeburn  3408:             }
                   3409:         }
1.43      raeburn  3410:         my ($emailrules,$emailruleorder) = 
                   3411:             &Apache::lonnet::inst_userrules($dom,'email');
                   3412:         if (ref($emailrules) eq 'HASH') {
                   3413:             if (keys(%{$emailrules}) > 0) {
                   3414:                 $datatable .= &user_formats_row('email',$settings,$emailrules,
                   3415:                                                 $emailruleorder,$numinrow,$rowcount);
                   3416:                 $$rowtotal ++;
                   3417:                 $rowcount ++;
                   3418:             }
                   3419:         }
1.39      raeburn  3420:         if ($rowcount == 0) {
                   3421:             $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';  
                   3422:             $$rowtotal ++;
                   3423:             $rowcount ++;
                   3424:         }
1.34      raeburn  3425:     } elsif ($position eq 'middle') {
1.100     raeburn  3426:         my @creators = ('author','course','requestcrs','selfcreate');
1.37      raeburn  3427:         my ($rules,$ruleorder) =
                   3428:             &Apache::lonnet::inst_userrules($dom,'username');
1.34      raeburn  3429:         my %lt = &usercreation_types();
                   3430:         my %checked;
1.50      raeburn  3431:         my @selfcreate; 
1.34      raeburn  3432:         if (ref($settings) eq 'HASH') {
                   3433:             if (ref($settings->{'cancreate'}) eq 'HASH') {
                   3434:                 foreach my $item (@creators) {
                   3435:                     $checked{$item} = $settings->{'cancreate'}{$item};
                   3436:                 }
1.50      raeburn  3437:                 if (ref($settings->{'cancreate'}{'selfcreate'}) eq 'ARRAY') {
                   3438:                     @selfcreate = @{$settings->{'cancreate'}{'selfcreate'}};
                   3439:                 } elsif ($settings->{'cancreate'}{'selfcreate'} ne '') {
                   3440:                     if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
                   3441:                         @selfcreate = ('email','login','sso');
                   3442:                     } elsif ($settings->{'cancreate'}{'selfcreate'} ne 'none') {
                   3443:                         @selfcreate = ($settings->{'cancreate'}{'selfcreate'});
                   3444:                     }
                   3445:                 }
1.34      raeburn  3446:             } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
                   3447:                 foreach my $item (@creators) {
                   3448:                     if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
                   3449:                         $checked{$item} = 'none';
                   3450:                     }
                   3451:                 }
                   3452:             }
                   3453:         }
                   3454:         my $rownum = 0;
                   3455:         foreach my $item (@creators) {
                   3456:             $rownum ++;
1.50      raeburn  3457:             if ($item ne 'selfcreate') {  
                   3458:                 if ($checked{$item} eq '') {
1.43      raeburn  3459:                     $checked{$item} = 'any';
                   3460:                 }
1.34      raeburn  3461:             }
                   3462:             my $css_class;
                   3463:             if ($rownum%2) {
                   3464:                 $css_class = '';
                   3465:             } else {
                   3466:                 $css_class = ' class="LC_odd_row" ';
                   3467:             }
                   3468:             $datatable .= '<tr'.$css_class.'>'.
                   3469:                          '<td><span class="LC_nobreak">'.$lt{$item}.
                   3470:                          '</span></td><td align="right">';
1.50      raeburn  3471:             my @options;
1.45      raeburn  3472:             if ($item eq 'selfcreate') {
1.43      raeburn  3473:                 push(@options,('email','login','sso'));
                   3474:             } else {
1.50      raeburn  3475:                 @options = ('any');
1.43      raeburn  3476:                 if (ref($rules) eq 'HASH') {
                   3477:                     if (keys(%{$rules}) > 0) {
                   3478:                         push(@options,('official','unofficial'));
                   3479:                     }
1.37      raeburn  3480:                 }
1.50      raeburn  3481:                 push(@options,'none');
1.37      raeburn  3482:             }
                   3483:             foreach my $option (@options) {
1.50      raeburn  3484:                 my $type = 'radio';
1.34      raeburn  3485:                 my $check = ' ';
1.50      raeburn  3486:                 if ($item eq 'selfcreate') {
                   3487:                     $type = 'checkbox';
                   3488:                     if (grep(/^\Q$option\E$/,@selfcreate)) {
                   3489:                         $check = ' checked="checked" ';
                   3490:                     }
                   3491:                 } else {
                   3492:                     if ($checked{$item} eq $option) {
                   3493:                         $check = ' checked="checked" ';
                   3494:                     }
1.34      raeburn  3495:                 } 
                   3496:                 $datatable .= '<span class="LC_nobreak"><label>'.
1.50      raeburn  3497:                               '<input type="'.$type.'" name="can_createuser_'.
1.34      raeburn  3498:                               $item.'" value="'.$option.'"'.$check.'/>&nbsp;'.
                   3499:                               $lt{$option}.'</label>&nbsp;&nbsp;</span>';
                   3500:             }
                   3501:             $datatable .= '</td></tr>';
                   3502:         }
1.93      raeburn  3503:         my ($othertitle,$usertypes,$types) =
                   3504:             &Apache::loncommon::sorted_inst_types($dom);
1.165     raeburn  3505:         my $createsettings;
                   3506:         if (ref($settings) eq 'HASH') {
                   3507:             $createsettings = $settings->{cancreate};
                   3508:         }
1.93      raeburn  3509:         if (ref($usertypes) eq 'HASH') {
                   3510:             if (keys(%{$usertypes}) > 0) {
1.99      raeburn  3511:                 $datatable .= &insttypes_row($createsettings,$types,$usertypes,
1.93      raeburn  3512:                                              $dom,$numinrow,$othertitle,
                   3513:                                              'statustocreate');
                   3514:                 $$rowtotal ++;
1.169     raeburn  3515:                 $rownum ++;
1.93      raeburn  3516:             }
                   3517:         }
1.169     raeburn  3518:         $datatable .= &captcha_choice('cancreate',$createsettings,$rownum);
1.28      raeburn  3519:     } else {
                   3520:         my @contexts = ('author','course','domain');
                   3521:         my @authtypes = ('int','krb4','krb5','loc');
                   3522:         my %checked;
                   3523:         if (ref($settings) eq 'HASH') {
                   3524:             if (ref($settings->{'authtypes'}) eq 'HASH') {
                   3525:                 foreach my $item (@contexts) {
                   3526:                     if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
                   3527:                         foreach my $auth (@authtypes) {
                   3528:                             if ($settings->{'authtypes'}{$item}{$auth}) {
                   3529:                                 $checked{$item}{$auth} = ' checked="checked" ';
                   3530:                             }
                   3531:                         }
                   3532:                     }
                   3533:                 }
1.27      raeburn  3534:             }
1.35      raeburn  3535:         } else {
                   3536:             foreach my $item (@contexts) {
1.36      raeburn  3537:                 foreach my $auth (@authtypes) {
1.35      raeburn  3538:                     $checked{$item}{$auth} = ' checked="checked" ';
                   3539:                 }
                   3540:             }
1.27      raeburn  3541:         }
1.28      raeburn  3542:         my %title = &context_names();
                   3543:         my %authname = &authtype_names();
                   3544:         my $rownum = 0;
                   3545:         my $css_class; 
                   3546:         foreach my $item (@contexts) {
                   3547:             if ($rownum%2) {
                   3548:                 $css_class = '';
                   3549:             } else {
                   3550:                 $css_class = ' class="LC_odd_row" ';
                   3551:             }
1.30      raeburn  3552:             $datatable .=   '<tr'.$css_class.'>'.
1.28      raeburn  3553:                             '<td>'.$title{$item}.
                   3554:                             '</td><td class="LC_left_item">'.
                   3555:                             '<span class="LC_nobreak">';
                   3556:             foreach my $auth (@authtypes) {
                   3557:                 $datatable .= '<label>'. 
                   3558:                               '<input type="checkbox" name="'.$item.'_auth" '.
                   3559:                               $checked{$item}{$auth}.' value="'.$auth.'" />'.
                   3560:                               $authname{$auth}.'</label>&nbsp;';
                   3561:             }
                   3562:             $datatable .= '</span></td></tr>';
                   3563:             $rownum ++;
1.27      raeburn  3564:         }
1.30      raeburn  3565:         $$rowtotal += $rownum;
1.27      raeburn  3566:     }
                   3567:     return $datatable;
                   3568: }
                   3569: 
1.165     raeburn  3570: sub captcha_choice {
1.169     raeburn  3571:     my ($context,$settings,$itemcount) = @_;
1.165     raeburn  3572:     my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext);
                   3573:     my %lt = &captcha_phrases();
                   3574:     $keyentry = 'hidden';
                   3575:     if ($context eq 'cancreate') {
                   3576:         $rowname = &mt('CAPTCHA validation (e-mail as username)');
1.169     raeburn  3577:     } elsif ($context eq 'login') {
                   3578:         $rowname =  &mt('"Contact helpdesk" CAPTCHA validation');
1.165     raeburn  3579:     }
                   3580:     if (ref($settings) eq 'HASH') {
                   3581:         if ($settings->{'captcha'}) {
                   3582:             $checked{$settings->{'captcha'}} = ' checked="checked"';
                   3583:         } else {
                   3584:             $checked{'original'} = ' checked="checked"';
                   3585:         }
                   3586:         if ($settings->{'captcha'} eq 'recaptcha') {
                   3587:             $pubtext = $lt{'pub'};
                   3588:             $privtext = $lt{'priv'};
                   3589:             $keyentry = 'text';
                   3590:         }
                   3591:         if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
                   3592:             $currpub = $settings->{'recaptchakeys'}{'public'};
                   3593:             $currpriv = $settings->{'recaptchakeys'}{'private'};
                   3594:         }
                   3595:     } else {
                   3596:         $checked{'original'} = ' checked="checked"';
                   3597:     }
1.169     raeburn  3598:     my $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   3599:     my $output = '<tr'.$css_class.'>'.
                   3600:                  '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
1.165     raeburn  3601:                  '<table><tr><td>'."\n";
                   3602:     foreach my $option ('original','recaptcha','notused') {
                   3603:         $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
                   3604:                    $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
                   3605:                    $lt{$option}.'</label></span>';
                   3606:         unless ($option eq 'notused') {
                   3607:             $output .= ('&nbsp;'x2)."\n";
                   3608:         }
                   3609:     }
                   3610: #
                   3611: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
                   3612: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
1.210     raeburn  3613: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
1.165     raeburn  3614: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
1.210     raeburn  3615: #
1.165     raeburn  3616:     $output .= '</td></tr>'."\n".
                   3617:                '<tr><td>'."\n".
                   3618:                '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span>&nbsp;'."\n".
                   3619:                '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
                   3620:                $currpub.'" size="40" /></span><br />'."\n".
                   3621:                '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span>&nbsp;'."\n".
                   3622:                '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
                   3623:                $currpriv.'" size="40" /></span></td></tr></table>'."\n".
                   3624:                '</td></tr>';
                   3625:     return $output;
                   3626: }
                   3627: 
1.32      raeburn  3628: sub user_formats_row {
                   3629:     my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
                   3630:     my $output;
                   3631:     my %text = (
                   3632:                    'username' => 'new usernames',
                   3633:                    'id'       => 'IDs',
1.45      raeburn  3634:                    'email'    => 'self-created accounts (e-mail)',
1.32      raeburn  3635:                );
                   3636:     my $css_class = $rowcount%2?' class="LC_odd_row"':'';
                   3637:     $output = '<tr '.$css_class.'>'.
1.63      raeburn  3638:               '<td><span class="LC_nobreak">';
                   3639:     if ($type eq 'email') {
                   3640:         $output .= &mt("Formats disallowed for $text{$type}: ");
                   3641:     } else {
                   3642:         $output .= &mt("Format rules to check for $text{$type}: ");
                   3643:     }
                   3644:     $output .= '</span></td>'.
                   3645:                '<td class="LC_left_item" colspan="2"><table>';
1.27      raeburn  3646:     my $rem;
                   3647:     if (ref($ruleorder) eq 'ARRAY') {
                   3648:         for (my $i=0; $i<@{$ruleorder}; $i++) {
                   3649:             if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
                   3650:                 my $rem = $i%($numinrow);
                   3651:                 if ($rem == 0) {
                   3652:                     if ($i > 0) {
                   3653:                         $output .= '</tr>';
                   3654:                     }
                   3655:                     $output .= '<tr>';
                   3656:                 }
                   3657:                 my $check = ' ';
1.39      raeburn  3658:                 if (ref($settings) eq 'HASH') {
                   3659:                     if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
                   3660:                         if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
                   3661:                             $check = ' checked="checked" ';
                   3662:                         }
1.27      raeburn  3663:                     }
                   3664:                 }
                   3665:                 $output .= '<td class="LC_left_item">'.
                   3666:                            '<span class="LC_nobreak"><label>'.
1.32      raeburn  3667:                            '<input type="checkbox" name="'.$type.'_rule" '.
1.27      raeburn  3668:                            'value="'.$ruleorder->[$i].'"'.$check.'/>'.
                   3669:                            $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
                   3670:             }
                   3671:         }
                   3672:         $rem = @{$ruleorder}%($numinrow);
                   3673:     }
                   3674:     my $colsleft = $numinrow - $rem;
                   3675:     if ($colsleft > 1 ) {
                   3676:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   3677:                    '&nbsp;</td>';
                   3678:     } elsif ($colsleft == 1) {
                   3679:         $output .= '<td class="LC_left_item">&nbsp;</td>';
                   3680:     }
                   3681:     $output .= '</tr></table></td></tr>';
                   3682:     return $output;
                   3683: }
                   3684: 
1.34      raeburn  3685: sub usercreation_types {
                   3686:     my %lt = &Apache::lonlocal::texthash (
                   3687:                     author     => 'When adding a co-author',
                   3688:                     course     => 'When adding a user to a course',
1.100     raeburn  3689:                     requestcrs => 'When requesting a course',
1.45      raeburn  3690:                     selfcreate => 'User creates own account', 
1.34      raeburn  3691:                     any        => 'Any',
                   3692:                     official   => 'Institutional only ',
                   3693:                     unofficial => 'Non-institutional only',
1.85      schafran 3694:                     email      => 'E-mail address',
1.43      raeburn  3695:                     login      => 'Institutional Login',
                   3696:                     sso        => 'SSO', 
1.34      raeburn  3697:                     none       => 'None',
                   3698:     );
                   3699:     return %lt;
1.48      raeburn  3700: }
1.34      raeburn  3701: 
1.28      raeburn  3702: sub authtype_names {
                   3703:     my %lt = &Apache::lonlocal::texthash(
                   3704:                       int    => 'Internal',
                   3705:                       krb4   => 'Kerberos 4',
                   3706:                       krb5   => 'Kerberos 5',
                   3707:                       loc    => 'Local',
                   3708:                   );
                   3709:     return %lt;
                   3710: }
                   3711: 
                   3712: sub context_names {
                   3713:     my %context_title = &Apache::lonlocal::texthash(
                   3714:        author => 'Creating users when an Author',
                   3715:        course => 'Creating users when in a course',
                   3716:        domain => 'Creating users when a Domain Coordinator',
                   3717:     );
                   3718:     return %context_title;
                   3719: }
                   3720: 
1.33      raeburn  3721: sub print_usermodification {
                   3722:     my ($position,$dom,$settings,$rowtotal) = @_;
                   3723:     my $numinrow = 4;
                   3724:     my ($context,$datatable,$rowcount);
                   3725:     if ($position eq 'top') {
                   3726:         $rowcount = 0;
                   3727:         $context = 'author'; 
                   3728:         foreach my $role ('ca','aa') {
                   3729:             $datatable .= &modifiable_userdata_row($context,$role,$settings,
                   3730:                                                    $numinrow,$rowcount);
                   3731:             $$rowtotal ++;
                   3732:             $rowcount ++;
                   3733:         }
1.63      raeburn  3734:     } elsif ($position eq 'middle') {
1.33      raeburn  3735:         $context = 'course';
                   3736:         $rowcount = 0;
                   3737:         foreach my $role ('st','ep','ta','in','cr') {
                   3738:             $datatable .= &modifiable_userdata_row($context,$role,$settings,
                   3739:                                                    $numinrow,$rowcount);
                   3740:             $$rowtotal ++;
                   3741:             $rowcount ++;
                   3742:         }
1.63      raeburn  3743:     } elsif ($position eq 'bottom') {
                   3744:         $context = 'selfcreate';
                   3745:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   3746:         $usertypes->{'default'} = $othertitle;
                   3747:         if (ref($types) eq 'ARRAY') {
                   3748:             push(@{$types},'default');
                   3749:             $usertypes->{'default'} = $othertitle;
                   3750:             foreach my $status (@{$types}) {
                   3751:                 $datatable .= &modifiable_userdata_row($context,$status,$settings,
                   3752:                                                        $numinrow,$rowcount,$usertypes);
                   3753:                 $$rowtotal ++;
                   3754:                 $rowcount ++;
                   3755:             }
                   3756:         }
1.33      raeburn  3757:     }
                   3758:     return $datatable;
                   3759: }
                   3760: 
1.43      raeburn  3761: sub print_defaults {
                   3762:     my ($dom,$rowtotal) = @_;
1.68      raeburn  3763:     my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
1.141     raeburn  3764:                  'datelocale_def','portal_def');
1.43      raeburn  3765:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.141     raeburn  3766:     my $titles = &defaults_titles($dom);
1.43      raeburn  3767:     my $rownum = 0;
                   3768:     my ($datatable,$css_class);
                   3769:     foreach my $item (@items) {
                   3770:         if ($rownum%2) {
                   3771:             $css_class = '';
                   3772:         } else {
                   3773:             $css_class = ' class="LC_odd_row" ';
                   3774:         }
                   3775:         $datatable .= '<tr'.$css_class.'>'.
                   3776:                   '<td><span class="LC_nobreak">'.$titles->{$item}.
                   3777:                   '</span></td><td class="LC_right_item">';
                   3778:         if ($item eq 'auth_def') {
                   3779:             my @authtypes = ('internal','krb4','krb5','localauth');
                   3780:             my %shortauth = (
                   3781:                              internal => 'int',
                   3782:                              krb4 => 'krb4',
                   3783:                              krb5 => 'krb5',
                   3784:                              localauth  => 'loc'
                   3785:                            );
                   3786:             my %authnames = &authtype_names();
                   3787:             foreach my $auth (@authtypes) {
                   3788:                 my $checked = ' ';
                   3789:                 if ($domdefaults{$item} eq $auth) {
                   3790:                     $checked = ' checked="checked" ';
                   3791:                 }
                   3792:                 $datatable .= '<label><input type="radio" name="'.$item.
                   3793:                               '" value="'.$auth.'"'.$checked.'/>'.
                   3794:                               $authnames{$shortauth{$auth}}.'</label>&nbsp;&nbsp;';
                   3795:             }
1.54      raeburn  3796:         } elsif ($item eq 'timezone_def') {
                   3797:             my $includeempty = 1;
                   3798:             $datatable .= &Apache::loncommon::select_timezone($item,$domdefaults{$item},undef,$includeempty);
1.68      raeburn  3799:         } elsif ($item eq 'datelocale_def') {
                   3800:             my $includeempty = 1;
                   3801:             $datatable .= &Apache::loncommon::select_datelocale($item,$domdefaults{$item},undef,$includeempty);
1.167     raeburn  3802:         } elsif ($item eq 'lang_def') {
1.168     raeburn  3803:             my %langchoices = &get_languages_hash();
                   3804:             $langchoices{''} = 'No language preference';
1.167     raeburn  3805:             %langchoices = &Apache::lonlocal::texthash(%langchoices);
                   3806:             $datatable .= &Apache::loncommon::select_form($domdefaults{$item},$item,
                   3807:                                                           \%langchoices);
1.43      raeburn  3808:         } else {
1.141     raeburn  3809:             my $size;
                   3810:             if ($item eq 'portal_def') {
                   3811:                 $size = ' size="25"';
                   3812:             }
1.43      raeburn  3813:             $datatable .= '<input type="text" name="'.$item.'" value="'.
1.141     raeburn  3814:                           $domdefaults{$item}.'"'.$size.' />';
1.43      raeburn  3815:         }
                   3816:         $datatable .= '</td></tr>';
                   3817:         $rownum ++;
                   3818:     }
                   3819:     $$rowtotal += $rownum;
                   3820:     return $datatable;
                   3821: }
                   3822: 
1.168     raeburn  3823: sub get_languages_hash {
                   3824:     my %langchoices;
                   3825:     foreach my $id (&Apache::loncommon::languageids()) {
                   3826:         my $code = &Apache::loncommon::supportedlanguagecode($id);
                   3827:         if ($code ne '') {
                   3828:             $langchoices{$code} =  &Apache::loncommon::plainlanguagedescription($id);
                   3829:         }
                   3830:     }
                   3831:     return %langchoices;
                   3832: }
                   3833: 
1.43      raeburn  3834: sub defaults_titles {
1.141     raeburn  3835:     my ($dom) = @_;
1.43      raeburn  3836:     my %titles = &Apache::lonlocal::texthash (
                   3837:                    'auth_def'      => 'Default authentication type',
                   3838:                    'auth_arg_def'  => 'Default authentication argument',
                   3839:                    'lang_def'      => 'Default language',
1.54      raeburn  3840:                    'timezone_def'  => 'Default timezone',
1.68      raeburn  3841:                    'datelocale_def' => 'Default locale for dates',
1.141     raeburn  3842:                    'portal_def'     => 'Portal/Default URL',
1.43      raeburn  3843:                  );
1.141     raeburn  3844:     if ($dom) {
                   3845:         my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
                   3846:         my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
                   3847:         my $protocol = $Apache::lonnet::protocol{$uprimary_id};
                   3848:         $protocol = 'http' if ($protocol ne 'https');
                   3849:         if ($uint_dom) {
                   3850:             $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
                   3851:                                          $uint_dom);
                   3852:         }
                   3853:     }
1.43      raeburn  3854:     return (\%titles);
                   3855: }
                   3856: 
1.46      raeburn  3857: sub print_scantronformat {
                   3858:     my ($r,$dom,$confname,$settings,$rowtotal) = @_;
                   3859:     my $itemcount = 1;
1.60      raeburn  3860:     my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
                   3861:         %confhash);
1.46      raeburn  3862:     my $switchserver = &check_switchserver($dom,$confname);
                   3863:     my %lt = &Apache::lonlocal::texthash (
1.95      www      3864:                 default => 'Default bubblesheet format file error',
                   3865:                 custom  => 'Custom bubblesheet format file error',
1.46      raeburn  3866:              );
                   3867:     my %scantronfiles = (
                   3868:         default => 'default.tab',
                   3869:         custom => 'custom.tab',
                   3870:     );
                   3871:     foreach my $key (keys(%scantronfiles)) {
                   3872:         $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
                   3873:                               .$scantronfiles{$key};
                   3874:     }
                   3875:     my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
                   3876:     if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
                   3877:         if (!$switchserver) {
                   3878:             my $servadm = $r->dir_config('lonAdmEMail');
                   3879:             my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
                   3880:             if ($configuserok eq 'ok') {
                   3881:                 if ($author_ok eq 'ok') {
                   3882:                     my %legacyfile = (
                   3883:  default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab', 
                   3884:  custom  => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab', 
                   3885:                     );
                   3886:                     my %md5chk;
                   3887:                     foreach my $type (keys(%legacyfile)) {
1.60      raeburn  3888:                         ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
                   3889:                         chomp($md5chk{$type});
1.46      raeburn  3890:                     }
                   3891:                     if ($md5chk{'default'} ne $md5chk{'custom'}) {
                   3892:                         foreach my $type (keys(%legacyfile)) {
1.60      raeburn  3893:                             ($scantronurls{$type},my $error) = 
1.46      raeburn  3894:                                 &legacy_scantronformat($r,$dom,$confname,
                   3895:                                                  $type,$legacyfile{$type},
                   3896:                                                  $scantronurls{$type},
                   3897:                                                  $scantronfiles{$type});
1.60      raeburn  3898:                             if ($error ne '') {
                   3899:                                 $error{$type} = $error;
                   3900:                             }
                   3901:                         }
                   3902:                         if (keys(%error) == 0) {
                   3903:                             $is_custom = 1;
                   3904:                             $confhash{'scantron'}{'scantronformat'} = 
                   3905:                                 $scantronurls{'custom'};
                   3906:                             my $putresult = 
                   3907:                                 &Apache::lonnet::put_dom('configuration',
                   3908:                                                          \%confhash,$dom);
                   3909:                             if ($putresult ne 'ok') {
                   3910:                                 $error{'custom'} = 
                   3911:                                     '<span class="LC_error">'.
                   3912:                                     &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
                   3913:                             }
1.46      raeburn  3914:                         }
                   3915:                     } else {
1.60      raeburn  3916:                         ($scantronurls{'default'},my $error) =
1.46      raeburn  3917:                             &legacy_scantronformat($r,$dom,$confname,
                   3918:                                           'default',$legacyfile{'default'},
                   3919:                                           $scantronurls{'default'},
                   3920:                                           $scantronfiles{'default'});
1.60      raeburn  3921:                         if ($error eq '') {
                   3922:                             $confhash{'scantron'}{'scantronformat'} = ''; 
                   3923:                             my $putresult =
                   3924:                                 &Apache::lonnet::put_dom('configuration',
                   3925:                                                          \%confhash,$dom);
                   3926:                             if ($putresult ne 'ok') {
                   3927:                                 $error{'default'} =
                   3928:                                     '<span class="LC_error">'.
                   3929:                                     &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
                   3930:                             }
                   3931:                         } else {
                   3932:                             $error{'default'} = $error;
                   3933:                         }
1.46      raeburn  3934:                     }
                   3935:                 }
                   3936:             }
                   3937:         } else {
1.95      www      3938:             $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46      raeburn  3939:         }
                   3940:     }
                   3941:     if (ref($settings) eq 'HASH') {
                   3942:         if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
                   3943:             my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
                   3944:             if ((!@info) || ($info[0] eq 'no_such_dir')) {
                   3945:                 $scantronurl = '';
                   3946:             } else {
                   3947:                 $scantronurl = $settings->{'scantronformat'};
                   3948:             }
                   3949:             $is_custom = 1;
                   3950:         } else {
                   3951:             $scantronurl = $scantronurls{'default'};
                   3952:         }
                   3953:     } else {
1.60      raeburn  3954:         if ($is_custom) {
                   3955:             $scantronurl = $scantronurls{'custom'};
                   3956:         } else {
                   3957:             $scantronurl = $scantronurls{'default'};
                   3958:         }
1.46      raeburn  3959:     }
                   3960:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   3961:     $datatable .= '<tr'.$css_class.'>';
                   3962:     if (!$is_custom) {
1.65      raeburn  3963:         $datatable .= '<td>'.&mt('Default in use:').'<br />'.
                   3964:                       '<span class="LC_nobreak">';
1.46      raeburn  3965:         if ($scantronurl) {
1.199     raeburn  3966:             $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
                   3967:                                                          undef,undef,undef,undef,'background-color:#ffffff');
1.46      raeburn  3968:         } else {
                   3969:             $datatable = &mt('File unavailable for display');
                   3970:         }
1.65      raeburn  3971:         $datatable .= '</span></td>';
1.60      raeburn  3972:         if (keys(%error) == 0) { 
                   3973:             $datatable .= '<td valign="bottom">';
                   3974:             if (!$switchserver) {
                   3975:                 $datatable .= &mt('Upload:').'<br />';
                   3976:             }
                   3977:         } else {
                   3978:             my $errorstr;
                   3979:             foreach my $key (sort(keys(%error))) {
                   3980:                 $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
                   3981:             }
                   3982:             $datatable .= '<td>'.$errorstr;
                   3983:         }
1.46      raeburn  3984:     } else {
                   3985:         if (keys(%error) > 0) {
                   3986:             my $errorstr;
                   3987:             foreach my $key (sort(keys(%error))) {
                   3988:                 $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
                   3989:             } 
1.60      raeburn  3990:             $datatable .= '<td>'.$errorstr.'</td><td>&nbsp;';
1.46      raeburn  3991:         } elsif ($scantronurl) {
1.199     raeburn  3992:             my $link =  &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
                   3993:                                                        undef,undef,undef,undef,'background-color:#ffffff');
1.65      raeburn  3994:             $datatable .= '<td><span class="LC_nobreak">'.
1.199     raeburn  3995:                           $link.
                   3996:                           '<label><input type="checkbox" name="scantronformat_del"'.
                   3997:                           ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65      raeburn  3998:                           '<td><span class="LC_nobreak">&nbsp;'.
                   3999:                           &mt('Replace:').'</span><br />';
1.46      raeburn  4000:         }
                   4001:     }
                   4002:     if (keys(%error) == 0) {
                   4003:         if ($switchserver) {
                   4004:             $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   4005:         } else {
1.65      raeburn  4006:             $datatable .='<span class="LC_nobreak">&nbsp;'.
                   4007:                          '<input type="file" name="scantronformat" /></span>';
1.46      raeburn  4008:         }
                   4009:     }
                   4010:     $datatable .= '</td></tr>';
                   4011:     $$rowtotal ++;
                   4012:     return $datatable;
                   4013: }
                   4014: 
                   4015: sub legacy_scantronformat {
                   4016:     my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
                   4017:     my ($url,$error);
                   4018:     my @statinfo = &Apache::lonnet::stat_file($newurl);
                   4019:     if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
                   4020:         (my $result,$url) =
                   4021:             &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
                   4022:                          '','',$newfile);
                   4023:         if ($result ne 'ok') {
1.130     raeburn  4024:             $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46      raeburn  4025:         }
                   4026:     }
                   4027:     return ($url,$error);
                   4028: }
1.43      raeburn  4029: 
1.49      raeburn  4030: sub print_coursecategories {
1.57      raeburn  4031:     my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
                   4032:     my $datatable;
                   4033:     if ($position eq 'top') {
                   4034:         my $toggle_cats_crs = ' ';
                   4035:         my $toggle_cats_dom = ' checked="checked" ';
                   4036:         my $can_cat_crs = ' ';
                   4037:         my $can_cat_dom = ' checked="checked" ';
1.120     raeburn  4038:         my $toggle_catscomm_comm = ' ';
                   4039:         my $toggle_catscomm_dom = ' checked="checked" ';
                   4040:         my $can_catcomm_comm = ' ';
                   4041:         my $can_catcomm_dom = ' checked="checked" ';
                   4042: 
1.57      raeburn  4043:         if (ref($settings) eq 'HASH') {
                   4044:             if ($settings->{'togglecats'} eq 'crs') {
                   4045:                 $toggle_cats_crs = $toggle_cats_dom;
                   4046:                 $toggle_cats_dom = ' ';
                   4047:             }
                   4048:             if ($settings->{'categorize'} eq 'crs') {
                   4049:                 $can_cat_crs = $can_cat_dom;
                   4050:                 $can_cat_dom = ' ';
                   4051:             }
1.120     raeburn  4052:             if ($settings->{'togglecatscomm'} eq 'comm') {
                   4053:                 $toggle_catscomm_comm = $toggle_catscomm_dom;
                   4054:                 $toggle_catscomm_dom = ' ';
                   4055:             }
                   4056:             if ($settings->{'categorizecomm'} eq 'comm') {
                   4057:                 $can_catcomm_comm = $can_catcomm_dom;
                   4058:                 $can_catcomm_dom = ' ';
                   4059:             }
1.57      raeburn  4060:         }
                   4061:         my %title = &Apache::lonlocal::texthash (
1.120     raeburn  4062:                      togglecats     => 'Show/Hide a course in catalog',
                   4063:                      togglecatscomm => 'Show/Hide a community in catalog',
                   4064:                      categorize     => 'Assign a category to a course',
                   4065:                      categorizecomm => 'Assign a category to a community',
1.57      raeburn  4066:                     );
                   4067:         my %level = &Apache::lonlocal::texthash (
1.120     raeburn  4068:                      dom  => 'Set in Domain',
                   4069:                      crs  => 'Set in Course',
                   4070:                      comm => 'Set in Community',
1.57      raeburn  4071:                     );
                   4072:         $datatable = '<tr class="LC_odd_row">'.
                   4073:                   '<td>'.$title{'togglecats'}.'</td>'.
                   4074:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   4075:                   '<input type="radio" name="togglecats"'.
                   4076:                   $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   4077:                   '<label><input type="radio" name="togglecats"'.
                   4078:                   $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
                   4079:                   '</tr><tr>'.
                   4080:                   '<td>'.$title{'categorize'}.'</td>'.
                   4081:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
                   4082:                   '<label><input type="radio" name="categorize"'.
                   4083:                   $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   4084:                   '<label><input type="radio" name="categorize"'.
                   4085:                   $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120     raeburn  4086:                   '</tr><tr class="LC_odd_row">'.
                   4087:                   '<td>'.$title{'togglecatscomm'}.'</td>'.
                   4088:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   4089:                   '<input type="radio" name="togglecatscomm"'.
                   4090:                   $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   4091:                   '<label><input type="radio" name="togglecatscomm"'.
                   4092:                   $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
                   4093:                   '</tr><tr>'.
                   4094:                   '<td>'.$title{'categorizecomm'}.'</td>'.
                   4095:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
                   4096:                   '<label><input type="radio" name="categorizecomm"'.
                   4097:                   $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   4098:                   '<label><input type="radio" name="categorizecomm"'.
                   4099:                   $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57      raeburn  4100:                   '</tr>';
1.120     raeburn  4101:         $$rowtotal += 4;
1.57      raeburn  4102:     } else {
                   4103:         my $css_class;
                   4104:         my $itemcount = 1;
                   4105:         my $cathash; 
                   4106:         if (ref($settings) eq 'HASH') {
                   4107:             $cathash = $settings->{'cats'};
                   4108:         }
                   4109:         if (ref($cathash) eq 'HASH') {
                   4110:             my (@cats,@trails,%allitems,%idx,@jsarray);
                   4111:             &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
                   4112:                                                    \%allitems,\%idx,\@jsarray);
                   4113:             my $maxdepth = scalar(@cats);
                   4114:             my $colattrib = '';
                   4115:             if ($maxdepth > 2) {
                   4116:                 $colattrib = ' colspan="2" ';
                   4117:             }
                   4118:             my @path;
                   4119:             if (@cats > 0) {
                   4120:                 if (ref($cats[0]) eq 'ARRAY') {
                   4121:                     my $numtop = @{$cats[0]};
                   4122:                     my $maxnum = $numtop;
1.120     raeburn  4123:                     my %default_names = (
                   4124:                           instcode    => &mt('Official courses'),
                   4125:                           communities => &mt('Communities'),
                   4126:                     );
                   4127: 
                   4128:                     if ((!grep(/^instcode$/,@{$cats[0]})) || 
                   4129:                         ($cathash->{'instcode::0'} eq '') ||
                   4130:                         (!grep(/^communities$/,@{$cats[0]})) || 
                   4131:                         ($cathash->{'communities::0'} eq '')) {
1.57      raeburn  4132:                         $maxnum ++;
                   4133:                     }
                   4134:                     my $lastidx;
                   4135:                     for (my $i=0; $i<$numtop; $i++) {
                   4136:                         my $parent = $cats[0][$i];
                   4137:                         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   4138:                         my $item = &escape($parent).'::0';
                   4139:                         my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
                   4140:                         $lastidx = $idx{$item};
                   4141:                         $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
                   4142:                                       .'<select name="'.$item.'"'.$chgstr.'>';
                   4143:                         for (my $k=0; $k<=$maxnum; $k++) {
                   4144:                             my $vpos = $k+1;
                   4145:                             my $selstr;
                   4146:                             if ($k == $i) {
                   4147:                                 $selstr = ' selected="selected" ';
                   4148:                             }
                   4149:                             $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   4150:                         }
                   4151:                         $datatable .= '</select></td><td>';
1.120     raeburn  4152:                         if ($parent eq 'instcode' || $parent eq 'communities') {
                   4153:                             $datatable .=  '<span class="LC_nobreak">'
                   4154:                                            .$default_names{$parent}.'</span>';
                   4155:                             if ($parent eq 'instcode') {
                   4156:                                 $datatable .= '<br /><span class="LC_nobreak">('
                   4157:                                               .&mt('with institutional codes')
                   4158:                                               .')</span></td><td'.$colattrib.'>';
                   4159:                             } else {
                   4160:                                 $datatable .= '<table><tr><td>';
                   4161:                             }
                   4162:                             $datatable .= '<span class="LC_nobreak">'
                   4163:                                           .'<label><input type="radio" name="'
                   4164:                                           .$parent.'" value="1" checked="checked" />'
                   4165:                                           .&mt('Display').'</label>';
                   4166:                             if ($parent eq 'instcode') {
                   4167:                                 $datatable .= '&nbsp;';
                   4168:                             } else {
                   4169:                                 $datatable .= '</span></td></tr><tr><td>'
                   4170:                                               .'<span class="LC_nobreak">';
                   4171:                             }
                   4172:                             $datatable .= '<label><input type="radio" name="'
                   4173:                                           .$parent.'" value="0" />'
                   4174:                                           .&mt('Do not display').'</label></span>';
                   4175:                             if ($parent eq 'communities') {
                   4176:                                 $datatable .= '</td></tr></table>';
                   4177:                             }
                   4178:                             $datatable .= '</td>';
1.57      raeburn  4179:                         } else {
                   4180:                             $datatable .= $parent
                   4181:                                           .'&nbsp;<label><input type="checkbox" name="deletecategory" '
                   4182:                                           .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
                   4183:                         }
                   4184:                         my $depth = 1;
                   4185:                         push(@path,$parent);
                   4186:                         $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
                   4187:                         pop(@path);
                   4188:                         $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
                   4189:                         $itemcount ++;
                   4190:                     }
1.48      raeburn  4191:                     $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57      raeburn  4192:                     my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
                   4193:                     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48      raeburn  4194:                     for (my $k=0; $k<=$maxnum; $k++) {
                   4195:                         my $vpos = $k+1;
                   4196:                         my $selstr;
1.57      raeburn  4197:                         if ($k == $numtop) {
1.48      raeburn  4198:                             $selstr = ' selected="selected" ';
                   4199:                         }
                   4200:                         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   4201:                     }
1.59      bisitz   4202:                     $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').'&nbsp;'
1.57      raeburn  4203:                                   .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
                   4204:                                   .'</tr>'."\n";
1.48      raeburn  4205:                     $itemcount ++;
1.120     raeburn  4206:                     foreach my $default ('instcode','communities') {
                   4207:                         if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
                   4208:                             $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   4209:                             my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
                   4210:                             $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
                   4211:                                           '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
                   4212:                             for (my $k=0; $k<=$maxnum; $k++) {
                   4213:                                 my $vpos = $k+1;
                   4214:                                 my $selstr;
                   4215:                                 if ($k == $maxnum) {
                   4216:                                     $selstr = ' selected="selected" ';
                   4217:                                 }
                   4218:                                 $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57      raeburn  4219:                             }
1.120     raeburn  4220:                             $datatable .= '</select></span></td>'.
                   4221:                                           '<td><span class="LC_nobreak">'.
                   4222:                                           $default_names{$default}.'</span>';
                   4223:                             if ($default eq 'instcode') {
                   4224:                                 $datatable .= '<br /><span class="LC_nobreak">(' 
                   4225:                                               .&mt('with institutional codes').')</span>';
                   4226:                             }
                   4227:                             $datatable .= '</td>'
                   4228:                                           .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
                   4229:                                           .&mt('Display').'</label>&nbsp;'
                   4230:                                           .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
                   4231:                                           .&mt('Do not display').'</label></span></td></tr>';
1.48      raeburn  4232:                         }
                   4233:                     }
                   4234:                 }
1.57      raeburn  4235:             } else {
                   4236:                 $datatable .= &initialize_categories($itemcount);
1.48      raeburn  4237:             }
                   4238:         } else {
1.57      raeburn  4239:             $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[0]->{'col2'}.'</td>'
                   4240:                           .&initialize_categories($itemcount);
1.48      raeburn  4241:         }
1.57      raeburn  4242:         $$rowtotal += $itemcount;
1.48      raeburn  4243:     }
                   4244:     return $datatable;
                   4245: }
                   4246: 
1.69      raeburn  4247: sub print_serverstatuses {
                   4248:     my ($dom,$settings,$rowtotal) = @_;
                   4249:     my $datatable;
                   4250:     my @pages = &serverstatus_pages();
                   4251:     my (%namedaccess,%machineaccess);
                   4252:     foreach my $type (@pages) {
                   4253:         $namedaccess{$type} = '';
                   4254:         $machineaccess{$type}= '';
                   4255:     }
                   4256:     if (ref($settings) eq 'HASH') {
                   4257:         foreach my $type (@pages) {
                   4258:             if (exists($settings->{$type})) {
                   4259:                 if (ref($settings->{$type}) eq 'HASH') {
                   4260:                     foreach my $key (keys(%{$settings->{$type}})) {
                   4261:                         if ($key eq 'namedusers') {
                   4262:                             $namedaccess{$type} = $settings->{$type}->{$key};
                   4263:                         } elsif ($key eq 'machines') {
                   4264:                             $machineaccess{$type} = $settings->{$type}->{$key};
                   4265:                         }
                   4266:                     }
                   4267:                 }
                   4268:             }
                   4269:         }
                   4270:     }
1.81      raeburn  4271:     my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69      raeburn  4272:     my $rownum = 0;
                   4273:     my $css_class;
                   4274:     foreach my $type (@pages) {
                   4275:         $rownum ++;
                   4276:         $css_class = $rownum%2?' class="LC_odd_row"':'';
                   4277:         $datatable .= '<tr'.$css_class.'>'.
                   4278:                       '<td><span class="LC_nobreak">'.
                   4279:                       $titles->{$type}.'</span></td>'.
                   4280:                       '<td class="LC_left_item">'.
                   4281:                       '<input type="text" name="'.$type.'_namedusers" '.
                   4282:                       'value="'.$namedaccess{$type}.'" size="30" /></td>'.
                   4283:                       '<td class="LC_right_item">'.
                   4284:                       '<span class="LC_nobreak">'.
                   4285:                       '<input type="text" name="'.$type.'_machines" '.
                   4286:                       'value="'.$machineaccess{$type}.'" size="10" />'.
                   4287:                       '</td></tr>'."\n";
                   4288:     }
                   4289:     $$rowtotal += $rownum;
                   4290:     return $datatable;
                   4291: }
                   4292: 
                   4293: sub serverstatus_pages {
                   4294:     return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.189     raeburn  4295:             'checksums','clusterstatus','metadata_keywords','metadata_harvest',
1.156     raeburn  4296:             'takeoffline','takeonline','showenv','toggledebug','ping','domconf');
1.69      raeburn  4297: }
                   4298: 
1.49      raeburn  4299: sub coursecategories_javascript {
                   4300:     my ($settings) = @_;
1.57      raeburn  4301:     my ($output,$jstext,$cathash);
1.49      raeburn  4302:     if (ref($settings) eq 'HASH') {
1.57      raeburn  4303:         $cathash = $settings->{'cats'};
                   4304:     }
                   4305:     if (ref($cathash) eq 'HASH') {
1.49      raeburn  4306:         my (@cats,@jsarray,%idx);
1.57      raeburn  4307:         &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49      raeburn  4308:         if (@jsarray > 0) {
                   4309:             $jstext = '    var categories = Array('.scalar(@jsarray).');'."\n";
                   4310:             for (my $i=0; $i<@jsarray; $i++) {
                   4311:                 if (ref($jsarray[$i]) eq 'ARRAY') {
                   4312:                     my $catstr = join('","',@{$jsarray[$i]});
                   4313:                     $jstext .= '    categories['.$i.'] = Array("'.$catstr.'");'."\n";
                   4314:                 }
                   4315:             }
                   4316:         }
                   4317:     } else {
                   4318:         $jstext  = '    var categories = Array(1);'."\n".
                   4319:                    '    categories[0] = Array("instcode_pos");'."\n"; 
                   4320:     }
1.120     raeburn  4321:     my $instcode_reserved = &mt('The name: "instcode" is a reserved category');
                   4322:     my $communities_reserved = &mt('The name: "communities" is a reserved category');
                   4323:     my $choose_again = '\\n'.&mt('Please use a different name for the new top level category'); 
1.49      raeburn  4324:     $output = <<"ENDSCRIPT";
                   4325: <script type="text/javascript">
1.109     raeburn  4326: // <![CDATA[
1.49      raeburn  4327: function reorderCats(form,parent,item,idx) {
                   4328:     var changedVal;
                   4329: $jstext
                   4330:     var newpos = 'addcategory_pos';
                   4331:     var current = new Array;
                   4332:     if (parent == '') {
                   4333:         var has_instcode = 0;
                   4334:         var maxtop = categories[idx].length;
                   4335:         for (var j=0; j<maxtop; j++) {
                   4336:             if (categories[idx][j] == 'instcode::0') {
                   4337:                 has_instcode == 1;
                   4338:             }
                   4339:         }
                   4340:         if (has_instcode == 0) {
                   4341:             categories[idx][maxtop] = 'instcode_pos';
                   4342:         }
                   4343:     } else {
                   4344:         newpos += '_'+parent;
                   4345:     }
                   4346:     var maxh = 1 + categories[idx].length;
                   4347:     var current = new Array;
                   4348:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
                   4349:     if (item == newpos) {
                   4350:         changedVal = newitemVal;
                   4351:     } else {
                   4352:         changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
                   4353:         current[newitemVal] = newpos;
                   4354:     }
                   4355:     for (var i=0; i<categories[idx].length; i++) {
                   4356:         var elementName = categories[idx][i];
                   4357:         if (elementName != item) {
                   4358:             if (form.elements[elementName]) {
                   4359:                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   4360:                 current[currVal] = elementName;
                   4361:             }
                   4362:         }
                   4363:     }
                   4364:     var oldVal;
                   4365:     for (var j=0; j<maxh; j++) {
                   4366:         if (current[j] == undefined) {
                   4367:             oldVal = j;
                   4368:         }
                   4369:     }
                   4370:     if (oldVal < changedVal) {
                   4371:         for (var k=oldVal+1; k<=changedVal ; k++) {
                   4372:            var elementName = current[k];
                   4373:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   4374:         }
                   4375:     } else {
                   4376:         for (var k=changedVal; k<oldVal; k++) {
                   4377:             var elementName = current[k];
                   4378:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   4379:         }
                   4380:     }
                   4381:     return;
                   4382: }
1.120     raeburn  4383: 
                   4384: function categoryCheck(form) {
                   4385:     if (form.elements['addcategory_name'].value == 'instcode') {
                   4386:         alert('$instcode_reserved\\n$choose_again');
                   4387:         return false;
                   4388:     }
                   4389:     if (form.elements['addcategory_name'].value == 'communities') {
                   4390:         alert('$communities_reserved\\n$choose_again');
                   4391:         return false;
                   4392:     }
                   4393:     return true;
                   4394: }
                   4395: 
1.109     raeburn  4396: // ]]>
1.49      raeburn  4397: </script>
                   4398: 
                   4399: ENDSCRIPT
                   4400:     return $output;
                   4401: }
                   4402: 
1.48      raeburn  4403: sub initialize_categories {
                   4404:     my ($itemcount) = @_;
1.120     raeburn  4405:     my ($datatable,$css_class,$chgstr);
                   4406:     my %default_names = (
                   4407:                       instcode    => 'Official courses (with institutional codes)',
                   4408:                       communities => 'Communities',
                   4409:                         );
                   4410:     my $select0 = ' selected="selected"';
                   4411:     my $select1 = '';
                   4412:     foreach my $default ('instcode','communities') {
                   4413:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   4414:         $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
                   4415:         if ($default eq 'communities') {
                   4416:             $select1 = $select0;
                   4417:             $select0 = '';
                   4418:         }
                   4419:         $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
                   4420:                      .'<select name="'.$default.'_pos">'
                   4421:                      .'<option value="0"'.$select0.'>1</option>'
                   4422:                      .'<option value="1"'.$select1.'>2</option>'
                   4423:                      .'<option value="2">3</option></select>&nbsp;'
                   4424:                      .$default_names{$default}
                   4425:                      .'</span></td><td><span class="LC_nobreak">'
                   4426:                      .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
                   4427:                      .&mt('Display').'</label>&nbsp;<label>'
                   4428:                      .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48      raeburn  4429:                  .'</label></span></td></tr>';
1.120     raeburn  4430:         $itemcount ++;
                   4431:     }
1.48      raeburn  4432:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49      raeburn  4433:     $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48      raeburn  4434:     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120     raeburn  4435:                   .'<select name="addcategory_pos"'.$chgstr.'>'
                   4436:                   .'<option value="0">1</option>'
                   4437:                   .'<option value="1">2</option>'
                   4438:                   .'<option value="2" selected="selected">3</option></select>&nbsp;'
1.48      raeburn  4439:                   .&mt('Add category').'</td><td>'.&mt('Name:')
                   4440:                   .'&nbsp;<input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
                   4441:     return $datatable;
                   4442: }
                   4443: 
                   4444: sub build_category_rows {
1.49      raeburn  4445:     my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
                   4446:     my ($text,$name,$item,$chgstr);
1.48      raeburn  4447:     if (ref($cats) eq 'ARRAY') {
                   4448:         my $maxdepth = scalar(@{$cats});
                   4449:         if (ref($cats->[$depth]) eq 'HASH') {
                   4450:             if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
                   4451:                 my $numchildren = @{$cats->[$depth]{$parent}};
                   4452:                 my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204     raeburn  4453:                 $text .= '<td><table class="LC_data_table">';
1.49      raeburn  4454:                 my ($idxnum,$parent_name,$parent_item);
                   4455:                 my $higher = $depth - 1;
                   4456:                 if ($higher == 0) {
                   4457:                     $parent_name = &escape($parent).'::'.$higher;
                   4458:                 } else {
                   4459:                     if (ref($path) eq 'ARRAY') {
                   4460:                         $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
                   4461:                     }
                   4462:                 }
                   4463:                 $parent_item = 'addcategory_pos_'.$parent_name;
1.48      raeburn  4464:                 for (my $j=0; $j<=$numchildren; $j++) {
1.49      raeburn  4465:                     if ($j < $numchildren) {
1.48      raeburn  4466:                         $name = $cats->[$depth]{$parent}[$j];
                   4467:                         $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49      raeburn  4468:                         $idxnum = $idx->{$item};
                   4469:                     } else {
                   4470:                         $name = $parent_name;
                   4471:                         $item = $parent_item;
1.48      raeburn  4472:                     }
1.49      raeburn  4473:                     $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
                   4474:                     $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48      raeburn  4475:                     for (my $i=0; $i<=$numchildren; $i++) {
                   4476:                         my $vpos = $i+1;
                   4477:                         my $selstr;
                   4478:                         if ($j == $i) {
                   4479:                             $selstr = ' selected="selected" ';
                   4480:                         }
                   4481:                         $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
                   4482:                     }
                   4483:                     $text .= '</select>&nbsp;';
                   4484:                     if ($j < $numchildren) {
                   4485:                         my $deeper = $depth+1;
                   4486:                         $text .= $name.'&nbsp;'
                   4487:                                  .'<label><input type="checkbox" name="deletecategory" value="'
                   4488:                                  .$item.'" />'.&mt('Delete').'</label></span></td><td>';
                   4489:                         if(ref($path) eq 'ARRAY') {
                   4490:                             push(@{$path},$name);
1.49      raeburn  4491:                             $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48      raeburn  4492:                             pop(@{$path});
                   4493:                         }
                   4494:                     } else {
1.59      bisitz   4495:                         $text .= &mt('Add subcategory:').'&nbsp;</span><input type="textbox" size="20" name="addcategory_name_';
1.48      raeburn  4496:                         if ($j == $numchildren) {
                   4497:                             $text .= $name;
                   4498:                         } else {
                   4499:                             $text .= $item;
                   4500:                         }
                   4501:                         $text .= '" value="" />';
                   4502:                     }
                   4503:                     $text .= '</td></tr>';
                   4504:                 }
                   4505:                 $text .= '</table></td>';
                   4506:             } else {
                   4507:                 my $higher = $depth-1;
                   4508:                 if ($higher == 0) {
                   4509:                     $name = &escape($parent).'::'.$higher;
                   4510:                 } else {
                   4511:                     if (ref($path) eq 'ARRAY') {
                   4512:                         $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
                   4513:                     }
                   4514:                 }
                   4515:                 my $colspan;
                   4516:                 if ($parent ne 'instcode') {
                   4517:                     $colspan = $maxdepth - $depth - 1;
                   4518:                     $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
                   4519:                 }
                   4520:             }
                   4521:         }
                   4522:     }
                   4523:     return $text;
                   4524: }
                   4525: 
1.33      raeburn  4526: sub modifiable_userdata_row {
1.63      raeburn  4527:     my ($context,$role,$settings,$numinrow,$rowcount,$usertypes) = @_;
1.33      raeburn  4528:     my $rolename;
1.63      raeburn  4529:     if ($context eq 'selfcreate') {
                   4530:         if (ref($usertypes) eq 'HASH') {
                   4531:             $rolename = $usertypes->{$role};
                   4532:         } else {
                   4533:             $rolename = $role;
                   4534:         }
1.33      raeburn  4535:     } else {
1.63      raeburn  4536:         if ($role eq 'cr') {
                   4537:             $rolename = &mt('Custom role');
                   4538:         } else {
                   4539:             $rolename = &Apache::lonnet::plaintext($role);
                   4540:         }
1.33      raeburn  4541:     }
                   4542:     my @fields = ('lastname','firstname','middlename','generation',
                   4543:                   'permanentemail','id');
                   4544:     my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
                   4545:     my $output;
                   4546:     my $css_class = $rowcount%2?' class="LC_odd_row"':'';
                   4547:     $output = '<tr '.$css_class.'>'.
                   4548:               '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
                   4549:               '<td class="LC_left_item" colspan="2"><table>';
                   4550:     my $rem;
                   4551:     my %checks;
                   4552:     if (ref($settings) eq 'HASH') {
                   4553:         if (ref($settings->{$context}) eq 'HASH') {
                   4554:             if (ref($settings->{$context}->{$role}) eq 'HASH') {
                   4555:                 foreach my $field (@fields) {
                   4556:                     if ($settings->{$context}->{$role}->{$field}) {
                   4557:                         $checks{$field} = ' checked="checked" ';
                   4558:                     }
                   4559:                 }
                   4560:             }
                   4561:         }
                   4562:     }
                   4563:     for (my $i=0; $i<@fields; $i++) {
                   4564:         my $rem = $i%($numinrow);
                   4565:         if ($rem == 0) {
                   4566:             if ($i > 0) {
                   4567:                 $output .= '</tr>';
                   4568:             }
                   4569:             $output .= '<tr>';
                   4570:         }
                   4571:         my $check = ' ';
                   4572:         if (exists($checks{$fields[$i]})) {
                   4573:             $check = $checks{$fields[$i]}
                   4574:         } else {
                   4575:             if ($role eq 'st') {
                   4576:                 if (ref($settings) ne 'HASH') {
                   4577:                     $check = ' checked="checked" '; 
                   4578:                 }
                   4579:             }
                   4580:         }
                   4581:         $output .= '<td class="LC_left_item">'.
                   4582:                    '<span class="LC_nobreak"><label>'.
                   4583:                    '<input type="checkbox" name="canmodify_'.$role.'" '.
                   4584:                    'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
                   4585:                    '</label></span></td>';
                   4586:         $rem = @fields%($numinrow);
                   4587:     }
                   4588:     my $colsleft = $numinrow - $rem;
                   4589:     if ($colsleft > 1 ) {
                   4590:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   4591:                    '&nbsp;</td>';
                   4592:     } elsif ($colsleft == 1) {
                   4593:         $output .= '<td class="LC_left_item">&nbsp;</td>';
                   4594:     }
                   4595:     $output .= '</tr></table></td></tr>';
                   4596:     return $output;
                   4597: }
1.28      raeburn  4598: 
1.93      raeburn  4599: sub insttypes_row {
                   4600:     my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context) = @_;
                   4601:     my %lt = &Apache::lonlocal::texthash (
                   4602:                       cansearch => 'Users allowed to search',
                   4603:                       statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131     raeburn  4604:                       lockablenames => 'User preference to lock name',
1.93      raeburn  4605:              );
                   4606:     my $showdom;
                   4607:     if ($context eq 'cansearch') {
                   4608:         $showdom = ' ('.$dom.')';
                   4609:     }
1.165     raeburn  4610:     my $class = 'LC_left_item';
                   4611:     if ($context eq 'statustocreate') {
                   4612:         $class = 'LC_right_item';
                   4613:     }
1.25      raeburn  4614:     my $output =  '<tr class="LC_odd_row">'.
1.93      raeburn  4615:                   '<td>'.$lt{$context}.$showdom.
1.165     raeburn  4616:                   '</td><td class="'.$class.'" colspan="2"><table>';
1.26      raeburn  4617:     my $rem;
                   4618:     if (ref($types) eq 'ARRAY') {
                   4619:         for (my $i=0; $i<@{$types}; $i++) {
                   4620:             if (defined($usertypes->{$types->[$i]})) {
                   4621:                 my $rem = $i%($numinrow);
                   4622:                 if ($rem == 0) {
                   4623:                     if ($i > 0) {
                   4624:                         $output .= '</tr>';
                   4625:                     }
                   4626:                     $output .= '<tr>';
1.23      raeburn  4627:                 }
1.26      raeburn  4628:                 my $check = ' ';
1.99      raeburn  4629:                 if (ref($settings) eq 'HASH') {
                   4630:                     if (ref($settings->{$context}) eq 'ARRAY') {
                   4631:                         if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
                   4632:                             $check = ' checked="checked" ';
                   4633:                         }
                   4634:                     } elsif ($context eq 'statustocreate') {
1.26      raeburn  4635:                         $check = ' checked="checked" ';
                   4636:                     }
1.23      raeburn  4637:                 }
1.26      raeburn  4638:                 $output .= '<td class="LC_left_item">'.
                   4639:                            '<span class="LC_nobreak"><label>'.
1.93      raeburn  4640:                            '<input type="checkbox" name="'.$context.'" '.
1.26      raeburn  4641:                            'value="'.$types->[$i].'"'.$check.'/>'.
                   4642:                            $usertypes->{$types->[$i]}.'</label></span></td>';
1.23      raeburn  4643:             }
                   4644:         }
1.26      raeburn  4645:         $rem = @{$types}%($numinrow);
1.23      raeburn  4646:     }
                   4647:     my $colsleft = $numinrow - $rem;
1.131     raeburn  4648:     if (($rem == 0) && (@{$types} > 0)) {
                   4649:         $output .= '<tr>';
                   4650:     }
1.23      raeburn  4651:     if ($colsleft > 1) {
1.25      raeburn  4652:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23      raeburn  4653:     } else {
1.25      raeburn  4654:         $output .= '<td class="LC_left_item">';
1.23      raeburn  4655:     }
                   4656:     my $defcheck = ' ';
1.99      raeburn  4657:     if (ref($settings) eq 'HASH') {  
                   4658:         if (ref($settings->{$context}) eq 'ARRAY') {
                   4659:             if (grep(/^default$/,@{$settings->{$context}})) {
                   4660:                 $defcheck = ' checked="checked" ';
                   4661:             }
                   4662:         } elsif ($context eq 'statustocreate') {
1.26      raeburn  4663:             $defcheck = ' checked="checked" ';
                   4664:         }
1.23      raeburn  4665:     }
1.25      raeburn  4666:     $output .= '<span class="LC_nobreak"><label>'.
1.93      raeburn  4667:                '<input type="checkbox" name="'.$context.'" '.
1.25      raeburn  4668:                'value="default"'.$defcheck.'/>'.
                   4669:                $othertitle.'</label></span></td>'.
                   4670:                '</tr></table></td></tr>';
                   4671:     return $output;
1.23      raeburn  4672: }
                   4673: 
                   4674: sub sorted_searchtitles {
                   4675:     my %searchtitles = &Apache::lonlocal::texthash(
                   4676:                          'uname' => 'username',
                   4677:                          'lastname' => 'last name',
                   4678:                          'lastfirst' => 'last name, first name',
                   4679:                      );
                   4680:     my @titleorder = ('uname','lastname','lastfirst');
                   4681:     return (\%searchtitles,\@titleorder);
                   4682: }
                   4683: 
1.25      raeburn  4684: sub sorted_searchtypes {
                   4685:     my %srchtypes_desc = (
                   4686:                            exact    => 'is exact match',
                   4687:                            contains => 'contains ..',
                   4688:                            begins   => 'begins with ..',
                   4689:                          );
                   4690:     my @srchtypeorder = ('exact','begins','contains');
                   4691:     return (\%srchtypes_desc,\@srchtypeorder);
                   4692: }
                   4693: 
1.3       raeburn  4694: sub usertype_update_row {
                   4695:     my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
                   4696:     my $datatable;
                   4697:     my $numinrow = 4;
                   4698:     foreach my $type (@{$types}) {
                   4699:         if (defined($usertypes->{$type})) {
                   4700:             $$rownums ++;
                   4701:             my $css_class = $$rownums%2?' class="LC_odd_row"':'';
                   4702:             $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
                   4703:                           '</td><td class="LC_left_item"><table>';
                   4704:             for (my $i=0; $i<@{$fields}; $i++) {
                   4705:                 my $rem = $i%($numinrow);
                   4706:                 if ($rem == 0) {
                   4707:                     if ($i > 0) {
                   4708:                         $datatable .= '</tr>';
                   4709:                     }
                   4710:                     $datatable .= '<tr>';
                   4711:                 }
                   4712:                 my $check = ' ';
1.39      raeburn  4713:                 if (ref($settings) eq 'HASH') {
                   4714:                     if (ref($settings->{'fields'}) eq 'HASH') {
                   4715:                         if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
                   4716:                             if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
                   4717:                                 $check = ' checked="checked" ';
                   4718:                             }
1.3       raeburn  4719:                         }
                   4720:                     }
                   4721:                 }
                   4722: 
                   4723:                 if ($i == @{$fields}-1) {
                   4724:                     my $colsleft = $numinrow - $rem;
                   4725:                     if ($colsleft > 1) {
                   4726:                         $datatable .= '<td colspan="'.$colsleft.'">';
                   4727:                     } else {
                   4728:                         $datatable .= '<td>';
                   4729:                     }
                   4730:                 } else {
                   4731:                     $datatable .= '<td>';
                   4732:                 }
1.8       raeburn  4733:                 $datatable .= '<span class="LC_nobreak"><label>'.
                   4734:                               '<input type="checkbox" name="updateable_'.$type.
                   4735:                               '_'.$fields->[$i].'" value="1"'.$check.'/>'.
                   4736:                               $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3       raeburn  4737:             }
                   4738:             $datatable .= '</tr></table></td></tr>';
                   4739:         }
                   4740:     }
                   4741:     return $datatable;
1.1       raeburn  4742: }
                   4743: 
                   4744: sub modify_login {
1.205     raeburn  4745:     my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168     raeburn  4746:     my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
                   4747:         %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
                   4748:     %title = ( coursecatalog => 'Display course catalog',
                   4749:                adminmail => 'Display administrator E-mail address',
1.188     raeburn  4750:                helpdesk  => 'Display "Contact Helpdesk" link',
1.168     raeburn  4751:                newuser => 'Link for visitors to create a user account',
                   4752:                loginheader => 'Log-in box header');
                   4753:     @offon = ('off','on');
1.112     raeburn  4754:     if (ref($domconfig{login}) eq 'HASH') {
                   4755:         if (ref($domconfig{login}{loginvia}) eq 'HASH') {
                   4756:             foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
                   4757:                 $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
                   4758:             }
                   4759:         }
                   4760:     }
1.9       raeburn  4761:     ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
                   4762:                                            \%domconfig,\%loginhash);
1.188     raeburn  4763:     my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42      raeburn  4764:     foreach my $item (@toggles) {
                   4765:         $loginhash{login}{$item} = $env{'form.'.$item};
                   4766:     }
1.41      raeburn  4767:     $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6       raeburn  4768:     if (ref($colchanges{'login'}) eq 'HASH') {  
                   4769:         $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
                   4770:                                          \%loginhash);
                   4771:     }
1.110     raeburn  4772: 
1.149     raeburn  4773:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.128     raeburn  4774:     my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110     raeburn  4775:     if (keys(%servers) > 1) {
                   4776:         foreach my $lonhost (keys(%servers)) {
1.128     raeburn  4777:             next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
                   4778:             if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
                   4779:                 if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
                   4780:                     $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
                   4781:                 } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
                   4782:                     if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
                   4783:                         $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
                   4784:                         $changes{'loginvia'}{$lonhost} = 1;
                   4785:                     } else {
                   4786:                         $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
                   4787:                         $changes{'loginvia'}{$lonhost} = 1;
                   4788:                     }
                   4789:                 } else {
                   4790:                     if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
                   4791:                         $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
                   4792:                         $changes{'loginvia'}{$lonhost} = 1;
                   4793:                     }
                   4794:                 }
                   4795:                 if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
                   4796:                     foreach my $item (@loginvia_attribs) {
                   4797:                         $loginhash{login}{loginvia}{$lonhost}{$item} = '';
                   4798:                     }
                   4799:                 } else {
                   4800:                     foreach my $item (@loginvia_attribs) {
                   4801:                         my $new = $env{'form.'.$lonhost.'_'.$item};
                   4802:                         if (($item eq 'serverpath') && ($new eq 'custom')) {
                   4803:                             $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
                   4804:                             if ($env{'form.'.$lonhost.'_custompath'} eq '') {
                   4805:                                 $new = '/';
                   4806:                             }
                   4807:                         }
                   4808:                         if (($item eq 'custompath') && 
                   4809:                             ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
                   4810:                             $new = '';
                   4811:                         }
                   4812:                         if ($new ne $curr_loginvia{$lonhost}{$item}) {
                   4813:                             $changes{'loginvia'}{$lonhost} = 1;
                   4814:                         }
                   4815:                         if ($item eq 'exempt') {
                   4816:                             $new =~ s/^\s+//;
                   4817:                             $new =~ s/\s+$//;
                   4818:                             my @poss_ips = split(/\s*[,:]\s*/,$new);
                   4819:                             my @okips;
                   4820:                             foreach my $ip (@poss_ips) {
                   4821:                                 if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
                   4822:                                     if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
                   4823:                                         push(@okips,$ip); 
                   4824:                                     }
                   4825:                                 }
                   4826:                             }
                   4827:                             if (@okips > 0) {
                   4828:                                 $new = join(',',@okips); 
                   4829:                             } else {
                   4830:                                 $new = ''; 
                   4831:                             }
                   4832:                         }
                   4833:                         $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
                   4834:                     }
                   4835:                 }
1.112     raeburn  4836:             } else {
1.128     raeburn  4837:                 if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
                   4838:                     $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112     raeburn  4839:                     $changes{'loginvia'}{$lonhost} = 1;
1.128     raeburn  4840:                     foreach my $item (@loginvia_attribs) {
                   4841:                         my $new = $env{'form.'.$lonhost.'_'.$item};
                   4842:                         if (($item eq 'serverpath') && ($new eq 'custom')) {
                   4843:                             if ($env{'form.'.$lonhost.'_custompath'} eq '') {
                   4844:                                 $new = '/';
                   4845:                             }
                   4846:                         }
                   4847:                         if (($item eq 'custompath') && 
                   4848:                             ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
                   4849:                             $new = '';
                   4850:                         }
                   4851:                         $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
                   4852:                     }
1.110     raeburn  4853:                 }
                   4854:             }
                   4855:         }
                   4856:     }
1.119     raeburn  4857: 
1.168     raeburn  4858:     my $servadm = $r->dir_config('lonAdmEMail');
                   4859:     my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
                   4860:     if (ref($domconfig{'login'}) eq 'HASH') {
                   4861:         if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
                   4862:             foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
                   4863:                 if ($lang eq 'nolang') {
                   4864:                     push(@currlangs,$lang);
                   4865:                 } elsif (defined($langchoices{$lang})) {
                   4866:                     push(@currlangs,$lang);
                   4867:                 } else {
                   4868:                     next;
                   4869:                 }
                   4870:             }
                   4871:         }
                   4872:     }
                   4873:     my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
                   4874:     if (@currlangs > 0) {
                   4875:         foreach my $lang (@currlangs) {
                   4876:             if (grep(/^\Q$lang\E$/,@delurls)) {
                   4877:                 $changes{'helpurl'}{$lang} = 1;
                   4878:             } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
                   4879:                 $changes{'helpurl'}{$lang} = 1;
                   4880:                 $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
                   4881:                 push(@newlangs,$lang);
                   4882:             } else {
                   4883:                 $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
                   4884:             }
                   4885:         }
                   4886:     }
                   4887:     unless (grep(/^nolang$/,@currlangs)) {
                   4888:         if ($env{'form.loginhelpurl_nolang.filename'}) {
                   4889:             $changes{'helpurl'}{'nolang'} = 1;
                   4890:             $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
                   4891:             push(@newlangs,'nolang');
                   4892:         }
                   4893:     }
                   4894:     if ($env{'form.loginhelpurl_add_lang'}) {
                   4895:         if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
                   4896:             ($env{'form.loginhelpurl_add_file.filename'})) {
                   4897:             $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
                   4898:             $addedfile = $env{'form.loginhelpurl_add_lang'};
                   4899:         }
                   4900:     }
                   4901:     if ((@newlangs > 0) || ($addedfile)) {
                   4902:         my $error;
                   4903:         my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
                   4904:         if ($configuserok eq 'ok') {
                   4905:             if ($switchserver) {
                   4906:                 $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
                   4907:             } elsif ($author_ok eq 'ok') {
                   4908:                 my @allnew = @newlangs;
                   4909:                 if ($addedfile ne '') {
                   4910:                     push(@allnew,$addedfile);
                   4911:                 }
                   4912:                 foreach my $lang (@allnew) {
                   4913:                     my $formelem = 'loginhelpurl_'.$lang;
                   4914:                     if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
                   4915:                         $formelem = 'loginhelpurl_add_file';
                   4916:                     }
                   4917:                     (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
                   4918:                                                                "help/$lang",'','',$newfile{$lang});
                   4919:                     if ($result eq 'ok') {
                   4920:                         $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
                   4921:                         $changes{'helpurl'}{$lang} = 1;
                   4922:                     } else {
                   4923:                         my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
                   4924:                         $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210     raeburn  4925:                         if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168     raeburn  4926:                             (!grep(/^\Q$lang\E$/,@delurls))) {
                   4927: 
                   4928:                             $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
                   4929:                         }
                   4930:                     }
                   4931:                 }
                   4932:             } else {
                   4933:                 $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);
                   4934:             }
                   4935:         } else {
                   4936:             $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);
                   4937:         }
                   4938:         if ($error) {
                   4939:             &Apache::lonnet::logthis($error);
                   4940:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   4941:         }
                   4942:     }
1.169     raeburn  4943:     &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168     raeburn  4944: 
                   4945:     my $defaulthelpfile = '/adm/loginproblems.html';
                   4946:     my $defaulttext = &mt('Default in use');
                   4947: 
1.1       raeburn  4948:     my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
                   4949:                                              $dom);
                   4950:     if ($putresult eq 'ok') {
1.188     raeburn  4951:         my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42      raeburn  4952:         my %defaultchecked = (
                   4953:                     'coursecatalog' => 'on',
1.188     raeburn  4954:                     'helpdesk'      => 'on',
1.42      raeburn  4955:                     'adminmail'     => 'off',
1.43      raeburn  4956:                     'newuser'       => 'off',
1.42      raeburn  4957:         );
1.55      raeburn  4958:         if (ref($domconfig{'login'}) eq 'HASH') {
                   4959:             foreach my $item (@toggles) {
                   4960:                 if ($defaultchecked{$item} eq 'on') { 
                   4961:                     if (($domconfig{'login'}{$item} eq '0') &&
                   4962:                         ($env{'form.'.$item} eq '1')) {
                   4963:                         $changes{$item} = 1;
                   4964:                     } elsif (($domconfig{'login'}{$item} eq '' ||
                   4965:                               $domconfig{'login'}{$item} eq '1') &&
                   4966:                              ($env{'form.'.$item} eq '0')) {
                   4967:                         $changes{$item} = 1;
                   4968:                     }
                   4969:                 } elsif ($defaultchecked{$item} eq 'off') {
                   4970:                     if (($domconfig{'login'}{$item} eq '1') &&
                   4971:                         ($env{'form.'.$item} eq '0')) {
                   4972:                         $changes{$item} = 1;
                   4973:                     } elsif (($domconfig{'login'}{$item} eq '' ||
                   4974:                               $domconfig{'login'}{$item} eq '0') &&
                   4975:                              ($env{'form.'.$item} eq '1')) {
                   4976:                         $changes{$item} = 1;
                   4977:                     }
1.42      raeburn  4978:                 }
                   4979:             }
1.41      raeburn  4980:         }
1.6       raeburn  4981:         if (keys(%changes) > 0 || $colchgtext) {
1.41      raeburn  4982:             &Apache::loncommon::devalidate_domconfig_cache($dom);
1.205     raeburn  4983:             $$lastactref = 'update';
1.1       raeburn  4984:             $resulttext = &mt('Changes made:').'<ul>';
                   4985:             foreach my $item (sort(keys(%changes))) {
1.135     bisitz   4986:                 if ($item eq 'loginvia') {
1.112     raeburn  4987:                     if (ref($changes{$item}) eq 'HASH') {
                   4988:                         $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
                   4989:                         foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128     raeburn  4990:                             if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
                   4991:                                 if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
                   4992:                                     my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
                   4993:                                     $protocol = 'http' if ($protocol ne 'https');
                   4994:                                     my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
                   4995: 
                   4996:                                     if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
                   4997:                                         $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
                   4998:                                     } else {
                   4999:                                         $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'}; 
                   5000:                                     }
                   5001:                                     $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
                   5002:                                     if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
                   5003:                                         $resulttext .= '&nbsp;'.&mt('No redirection for clients from following IPs:').'&nbsp;'.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
                   5004:                                     }
                   5005:                                     $resulttext .= '</li>';
                   5006:                                 } else {
                   5007:                                     $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
                   5008:                                 }
1.112     raeburn  5009:                             } else {
1.128     raeburn  5010:                                 $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112     raeburn  5011:                             }
                   5012:                         }
1.128     raeburn  5013:                         $resulttext .= '</ul></li>';
1.112     raeburn  5014:                     }
1.168     raeburn  5015:                 } elsif ($item eq 'helpurl') {
                   5016:                     if (ref($changes{$item}) eq 'HASH') {
                   5017:                         foreach my $lang (sort(keys(%{$changes{$item}}))) {
                   5018:                             if (grep(/^\Q$lang\E$/,@delurls)) {
                   5019:                                 my ($chg,$link);
                   5020:                                 $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
                   5021:                                 if ($lang eq 'nolang') {
                   5022:                                     $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
                   5023:                                 } else {
                   5024:                                     $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
                   5025:                                 }
                   5026:                                 $resulttext .= '<li>'.$chg.'</li>';
                   5027:                             } else {
                   5028:                                 my $chg;
                   5029:                                 if ($lang eq 'nolang') {
                   5030:                                     $chg = &mt('custom log-in help file for no preferred language');
                   5031:                                 } else {
                   5032:                                     $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
                   5033:                                 }
                   5034:                                 $resulttext .= '<li>'.&Apache::loncommon::modal_link(
                   5035:                                                       $loginhash{'login'}{'helpurl'}{$lang}.
                   5036:                                                       '?inhibitmenu=yes',$chg,600,500).
                   5037:                                                '</li>';
                   5038:                             }
                   5039:                         }
                   5040:                     }
1.169     raeburn  5041:                 } elsif ($item eq 'captcha') {
                   5042:                     if (ref($loginhash{'login'}) eq 'HASH') {
1.210     raeburn  5043:                         my $chgtxt;
1.169     raeburn  5044:                         if ($loginhash{'login'}{$item} eq 'notused') {
                   5045:                             $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
                   5046:                         } else {
                   5047:                             my %captchas = &captcha_phrases();
                   5048:                             if ($captchas{$loginhash{'login'}{$item}}) {
                   5049:                                 $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
                   5050:                             } else {
                   5051:                                 $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
                   5052:                             }
                   5053:                         }
                   5054:                         $resulttext .= '<li>'.$chgtxt.'</li>';
                   5055:                     }
                   5056:                 } elsif ($item eq 'recaptchakeys') {
                   5057:                     if (ref($loginhash{'login'}) eq 'HASH') {
                   5058:                         my ($privkey,$pubkey);
                   5059:                         if (ref($loginhash{'login'}{$item}) eq 'HASH') {
                   5060:                             $pubkey = $loginhash{'login'}{$item}{'public'};
                   5061:                             $privkey = $loginhash{'login'}{$item}{'private'};
                   5062:                         }
                   5063:                         my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
                   5064:                         if (!$pubkey) {
                   5065:                             $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
                   5066:                         } else {
                   5067:                             $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
                   5068:                         }
                   5069:                         if (!$privkey) {
                   5070:                             $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
                   5071:                         } else {
                   5072:                             $chgtxt .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
                   5073:                         }
                   5074:                         $chgtxt .= '</ul>';
                   5075:                         $resulttext .= '<li>'.$chgtxt.'</li>';
                   5076:                     }
1.41      raeburn  5077:                 } else {
                   5078:                     $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
                   5079:                 }
1.1       raeburn  5080:             }
1.6       raeburn  5081:             $resulttext .= $colchgtext.'</ul>';
1.1       raeburn  5082:         } else {
                   5083:             $resulttext = &mt('No changes made to log-in page settings');
                   5084:         }
                   5085:     } else {
1.11      albertel 5086:         $resulttext = '<span class="LC_error">'.
                   5087: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  5088:     }
1.6       raeburn  5089:     if ($errors) {
1.9       raeburn  5090:         $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6       raeburn  5091:                        $errors.'</ul>';
                   5092:     }
                   5093:     return $resulttext;
                   5094: }
                   5095: 
                   5096: sub color_font_choices {
                   5097:     my %choices =
                   5098:         &Apache::lonlocal::texthash (
                   5099:             img => "Header",
                   5100:             bgs => "Background colors",
                   5101:             links => "Link colors",
1.55      raeburn  5102:             images => "Images",
1.6       raeburn  5103:             font => "Font color",
1.201     raeburn  5104:             fontmenu => "Font menu",
1.76      raeburn  5105:             pgbg => "Page",
1.6       raeburn  5106:             tabbg => "Header",
                   5107:             sidebg => "Border",
                   5108:             link => "Link",
                   5109:             alink => "Active link",
                   5110:             vlink => "Visited link",
                   5111:         );
                   5112:     return %choices;
                   5113: }
                   5114: 
                   5115: sub modify_rolecolors {
1.205     raeburn  5116:     my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6       raeburn  5117:     my ($resulttext,%rolehash);
                   5118:     $rolehash{'rolecolors'} = {};
1.55      raeburn  5119:     if (ref($domconfig{'rolecolors'}) ne 'HASH') {
                   5120:         if ($domconfig{'rolecolors'} eq '') {
                   5121:             $domconfig{'rolecolors'} = {};
                   5122:         }
                   5123:     }
1.9       raeburn  5124:     my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6       raeburn  5125:                          $domconfig{'rolecolors'},$rolehash{'rolecolors'});
                   5126:     my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
                   5127:                                              $dom);
                   5128:     if ($putresult eq 'ok') {
                   5129:         if (keys(%changes) > 0) {
1.41      raeburn  5130:             &Apache::loncommon::devalidate_domconfig_cache($dom);
1.205     raeburn  5131:             $$lastactref = 'update';
1.6       raeburn  5132:             $resulttext = &display_colorchgs($dom,\%changes,$roles,
                   5133:                                              $rolehash{'rolecolors'});
                   5134:         } else {
                   5135:             $resulttext = &mt('No changes made to default color schemes');
                   5136:         }
                   5137:     } else {
1.11      albertel 5138:         $resulttext = '<span class="LC_error">'.
                   5139: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.6       raeburn  5140:     }
                   5141:     if ($errors) {
                   5142:         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
                   5143:                        $errors.'</ul>';
                   5144:     }
                   5145:     return $resulttext;
                   5146: }
                   5147: 
                   5148: sub modify_colors {
1.9       raeburn  5149:     my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12      raeburn  5150:     my (%changes,%choices);
1.51      raeburn  5151:     my @bgs;
1.6       raeburn  5152:     my @links = ('link','alink','vlink');
1.41      raeburn  5153:     my @logintext;
1.6       raeburn  5154:     my @images;
                   5155:     my $servadm = $r->dir_config('lonAdmEMail');
                   5156:     my $errors;
1.200     raeburn  5157:     my %defaults;
1.6       raeburn  5158:     foreach my $role (@{$roles}) {
                   5159:         if ($role eq 'login') {
1.12      raeburn  5160:             %choices = &login_choices();
1.41      raeburn  5161:             @logintext = ('textcol','bgcol');
1.12      raeburn  5162:         } else {
                   5163:             %choices = &color_font_choices();
                   5164:         }
                   5165:         if ($role eq 'login') {
1.41      raeburn  5166:             @images = ('img','logo','domlogo','login');
1.51      raeburn  5167:             @bgs = ('pgbg','mainbg','sidebg');
1.6       raeburn  5168:         } else {
                   5169:             @images = ('img');
1.200     raeburn  5170:             @bgs = ('pgbg','tabbg','sidebg');
                   5171:         }
                   5172:         my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
                   5173:         unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
                   5174:             $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
                   5175:         }
                   5176:         if ($role eq 'login') {
                   5177:             foreach my $item (@logintext) {
                   5178:                 unless ($env{'form.'.$role.'_'.$item} eq  $defaults{'logintext'}{$item}) {
                   5179:                     $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
                   5180:                 }
                   5181:             }
                   5182:         } else {
                   5183:             unless($env{'form.'.$role.'_fontmenu'} eq $defaults{'fontmenu'}) {
                   5184:                 $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
                   5185:             }
1.6       raeburn  5186:         }
1.200     raeburn  5187:         foreach my $item (@bgs) {
                   5188:             unless ($env{'form.'.$role.'_'.$item} eq $defaults{'bgs'}{$item} ) {
                   5189:                 $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
                   5190:             }
                   5191:         }
                   5192:         foreach my $item (@links) {
                   5193:             unless ($env{'form.'.$role.'_'.$item} eq  $defaults{'links'}{$item}) {
                   5194:                 $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
                   5195:             }
1.6       raeburn  5196:         }
1.46      raeburn  5197:         my ($configuserok,$author_ok,$switchserver) = 
                   5198:             &config_check($dom,$confname,$servadm);
1.9       raeburn  5199:         my ($width,$height) = &thumb_dimensions();
1.40      raeburn  5200:         if (ref($domconfig->{$role}) ne 'HASH') {
                   5201:             $domconfig->{$role} = {};
                   5202:         }
1.8       raeburn  5203:         foreach my $img (@images) {
1.70      raeburn  5204:             if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {  
                   5205:                 if (defined($env{'form.login_showlogo_'.$img})) {
                   5206:                     $confhash->{$role}{'showlogo'}{$img} = 1;
                   5207:                 } else { 
                   5208:                     $confhash->{$role}{'showlogo'}{$img} = 0;
                   5209:                 }
                   5210:             } 
1.18      albertel 5211: 	    if ( ! $env{'form.'.$role.'_'.$img.'.filename'} 
                   5212: 		 && !defined($domconfig->{$role}{$img})
                   5213: 		 && !$env{'form.'.$role.'_del_'.$img}
                   5214: 		 && $env{'form.'.$role.'_import_'.$img}) {
                   5215: 		# import the old configured image from the .tab setting
                   5216: 		# if they haven't provided a new one 
                   5217: 		$domconfig->{$role}{$img} = 
                   5218: 		    $env{'form.'.$role.'_import_'.$img};
                   5219: 	    }
1.6       raeburn  5220:             if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9       raeburn  5221:                 my $error;
1.6       raeburn  5222:                 if ($configuserok eq 'ok') {
1.9       raeburn  5223:                     if ($switchserver) {
1.12      raeburn  5224:                         $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9       raeburn  5225:                     } else {
                   5226:                         if ($author_ok eq 'ok') {
                   5227:                             my ($result,$logourl) = 
                   5228:                                 &publishlogo($r,'upload',$role.'_'.$img,
                   5229:                                            $dom,$confname,$img,$width,$height);
                   5230:                             if ($result eq 'ok') {
                   5231:                                 $confhash->{$role}{$img} = $logourl;
1.12      raeburn  5232:                                 $changes{$role}{'images'}{$img} = 1;
1.9       raeburn  5233:                             } else {
1.12      raeburn  5234:                                 $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  5235:                             }
                   5236:                         } else {
1.46      raeburn  5237:                             $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  5238:                         }
                   5239:                     }
                   5240:                 } else {
1.46      raeburn  5241:                     $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  5242:                 }
                   5243:                 if ($error) {
1.8       raeburn  5244:                     &Apache::lonnet::logthis($error);
1.11      albertel 5245:                     $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8       raeburn  5246:                 }
                   5247:             } elsif ($domconfig->{$role}{$img} ne '') {
1.9       raeburn  5248:                 if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
                   5249:                     my $error;
                   5250:                     if ($configuserok eq 'ok') {
                   5251: # is confname an author?
                   5252:                         if ($switchserver eq '') {
                   5253:                             if ($author_ok eq 'ok') {
                   5254:                                 my ($result,$logourl) = 
                   5255:                                &publishlogo($r,'copy',$domconfig->{$role}{$img},
                   5256:                                             $dom,$confname,$img,$width,$height);
                   5257:                                 if ($result eq 'ok') {
                   5258:                                     $confhash->{$role}{$img} = $logourl;
1.18      albertel 5259: 				    $changes{$role}{'images'}{$img} = 1;
1.9       raeburn  5260:                                 }
                   5261:                             }
                   5262:                         }
                   5263:                     }
1.6       raeburn  5264:                 }
                   5265:             }
                   5266:         }
                   5267:         if (ref($domconfig) eq 'HASH') {
                   5268:             if (ref($domconfig->{$role}) eq 'HASH') {
                   5269:                 foreach my $img (@images) {
                   5270:                     if ($domconfig->{$role}{$img} ne '') {
                   5271:                         if ($env{'form.'.$role.'_del_'.$img}) {
                   5272:                             $confhash->{$role}{$img} = '';
1.12      raeburn  5273:                             $changes{$role}{'images'}{$img} = 1;
1.6       raeburn  5274:                         } else {
1.9       raeburn  5275:                             if ($confhash->{$role}{$img} eq '') {
                   5276:                                 $confhash->{$role}{$img} = $domconfig->{$role}{$img};
                   5277:                             }
1.6       raeburn  5278:                         }
                   5279:                     } else {
                   5280:                         if ($env{'form.'.$role.'_del_'.$img}) {
                   5281:                             $confhash->{$role}{$img} = '';
1.12      raeburn  5282:                             $changes{$role}{'images'}{$img} = 1;
1.6       raeburn  5283:                         } 
                   5284:                     }
1.70      raeburn  5285:                     if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
                   5286:                         if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
                   5287:                             if ($confhash->{$role}{'showlogo'}{$img} ne 
                   5288:                                 $domconfig->{$role}{'showlogo'}{$img}) {
                   5289:                                 $changes{$role}{'showlogo'}{$img} = 1; 
                   5290:                             }
                   5291:                         } else {
                   5292:                             if ($confhash->{$role}{'showlogo'}{$img} == 0) {
                   5293:                                 $changes{$role}{'showlogo'}{$img} = 1;
                   5294:                             }
                   5295:                         }
                   5296:                     }
                   5297:                 }
1.6       raeburn  5298:                 if ($domconfig->{$role}{'font'} ne '') {
                   5299:                     if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
                   5300:                         $changes{$role}{'font'} = 1;
                   5301:                     }
                   5302:                 } else {
                   5303:                     if ($confhash->{$role}{'font'}) {
                   5304:                         $changes{$role}{'font'} = 1;
                   5305:                     }
                   5306:                 }
1.107     raeburn  5307:                 if ($role ne 'login') {
                   5308:                     if ($domconfig->{$role}{'fontmenu'} ne '') {
                   5309:                         if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
                   5310:                             $changes{$role}{'fontmenu'} = 1;
                   5311:                         }
                   5312:                     } else {
                   5313:                         if ($confhash->{$role}{'fontmenu'}) {
                   5314:                             $changes{$role}{'fontmenu'} = 1;
                   5315:                         }
1.97      tempelho 5316:                     }
                   5317:                 }
1.6       raeburn  5318:                 foreach my $item (@bgs) {
                   5319:                     if ($domconfig->{$role}{$item} ne '') {
                   5320:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
                   5321:                             $changes{$role}{'bgs'}{$item} = 1;
                   5322:                         } 
                   5323:                     } else {
                   5324:                         if ($confhash->{$role}{$item}) {
                   5325:                             $changes{$role}{'bgs'}{$item} = 1;
                   5326:                         }
                   5327:                     }
                   5328:                 }
                   5329:                 foreach my $item (@links) {
                   5330:                     if ($domconfig->{$role}{$item} ne '') {
                   5331:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
                   5332:                             $changes{$role}{'links'}{$item} = 1;
                   5333:                         }
                   5334:                     } else {
                   5335:                         if ($confhash->{$role}{$item}) {
                   5336:                             $changes{$role}{'links'}{$item} = 1;
                   5337:                         }
                   5338:                     }
                   5339:                 }
1.41      raeburn  5340:                 foreach my $item (@logintext) {
                   5341:                     if ($domconfig->{$role}{$item} ne '') {
                   5342:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
                   5343:                             $changes{$role}{'logintext'}{$item} = 1;
                   5344:                         }
                   5345:                     } else {
                   5346:                         if ($confhash->{$role}{$item}) {
                   5347:                             $changes{$role}{'logintext'}{$item} = 1;
                   5348:                         }
                   5349:                     }
                   5350:                 }
1.6       raeburn  5351:             } else {
                   5352:                 &default_change_checker($role,\@images,\@links,\@bgs,
1.41      raeburn  5353:                                         \@logintext,$confhash,\%changes); 
1.6       raeburn  5354:             }
                   5355:         } else {
                   5356:             &default_change_checker($role,\@images,\@links,\@bgs,
1.41      raeburn  5357:                                     \@logintext,$confhash,\%changes); 
1.6       raeburn  5358:         }
                   5359:     }
                   5360:     return ($errors,%changes);
                   5361: }
                   5362: 
1.46      raeburn  5363: sub config_check {
                   5364:     my ($dom,$confname,$servadm) = @_;
                   5365:     my ($configuserok,$author_ok,$switchserver,%currroles);
                   5366:     my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
                   5367:     ($configuserok,%currroles) = &check_configuser($uhome,$dom,
                   5368:                                                    $confname,$servadm);
                   5369:     if ($configuserok eq 'ok') {
                   5370:         $switchserver = &check_switchserver($dom,$confname);
                   5371:         if ($switchserver eq '') {
                   5372:             $author_ok = &check_authorstatus($dom,$confname,%currroles);
                   5373:         }
                   5374:     }
                   5375:     return ($configuserok,$author_ok,$switchserver);
                   5376: }
                   5377: 
1.6       raeburn  5378: sub default_change_checker {
1.41      raeburn  5379:     my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6       raeburn  5380:     foreach my $item (@{$links}) {
                   5381:         if ($confhash->{$role}{$item}) {
                   5382:             $changes->{$role}{'links'}{$item} = 1;
                   5383:         }
                   5384:     }
                   5385:     foreach my $item (@{$bgs}) {
                   5386:         if ($confhash->{$role}{$item}) {
                   5387:             $changes->{$role}{'bgs'}{$item} = 1;
                   5388:         }
                   5389:     }
1.41      raeburn  5390:     foreach my $item (@{$logintext}) {
                   5391:         if ($confhash->{$role}{$item}) {
                   5392:             $changes->{$role}{'logintext'}{$item} = 1;
                   5393:         }
                   5394:     }
1.6       raeburn  5395:     foreach my $img (@{$images}) {
                   5396:         if ($env{'form.'.$role.'_del_'.$img}) {
                   5397:             $confhash->{$role}{$img} = '';
1.12      raeburn  5398:             $changes->{$role}{'images'}{$img} = 1;
1.6       raeburn  5399:         }
1.70      raeburn  5400:         if ($role eq 'login') {
                   5401:             if ($confhash->{$role}{'showlogo'}{$img} == 0) {
                   5402:                 $changes->{$role}{'showlogo'}{$img} = 1;
                   5403:             }
                   5404:         }
1.6       raeburn  5405:     }
                   5406:     if ($confhash->{$role}{'font'}) {
                   5407:         $changes->{$role}{'font'} = 1;
                   5408:     }
1.48      raeburn  5409: }
1.6       raeburn  5410: 
                   5411: sub display_colorchgs {
                   5412:     my ($dom,$changes,$roles,$confhash) = @_;
                   5413:     my (%choices,$resulttext);
                   5414:     if (!grep(/^login$/,@{$roles})) {
                   5415:         $resulttext = &mt('Changes made:').'<br />';
                   5416:     }
                   5417:     foreach my $role (@{$roles}) {
                   5418:         if ($role eq 'login') {
                   5419:             %choices = &login_choices();
                   5420:         } else {
                   5421:             %choices = &color_font_choices();
                   5422:         }
                   5423:         if (ref($changes->{$role}) eq 'HASH') {
                   5424:             if ($role ne 'login') {
                   5425:                 $resulttext .= '<h4>'.&mt($role).'</h4>';
                   5426:             }
                   5427:             foreach my $key (sort(keys(%{$changes->{$role}}))) {
                   5428:                 if ($role ne 'login') {
                   5429:                     $resulttext .= '<ul>';
                   5430:                 }
                   5431:                 if (ref($changes->{$role}{$key}) eq 'HASH') {
                   5432:                     if ($role ne 'login') {
                   5433:                         $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
                   5434:                     }
                   5435:                     foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70      raeburn  5436:                         if (($role eq 'login') && ($key eq 'showlogo')) {
                   5437:                             if ($confhash->{$role}{$key}{$item}) {
                   5438:                                 $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
                   5439:                             } else {
                   5440:                                 $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
                   5441:                             }
                   5442:                         } elsif ($confhash->{$role}{$item} eq '') {
1.6       raeburn  5443:                             $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
                   5444:                         } else {
1.12      raeburn  5445:                             my $newitem = $confhash->{$role}{$item};
                   5446:                             if ($key eq 'images') {
                   5447:                                 $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
                   5448:                             }
                   5449:                             $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6       raeburn  5450:                         }
                   5451:                     }
                   5452:                     if ($role ne 'login') {
                   5453:                         $resulttext .= '</ul></li>';
                   5454:                     }
                   5455:                 } else {
                   5456:                     if ($confhash->{$role}{$key} eq '') {
                   5457:                         $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
                   5458:                     } else {
                   5459:                         $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
                   5460:                     }
                   5461:                 }
                   5462:                 if ($role ne 'login') {
                   5463:                     $resulttext .= '</ul>';
                   5464:                 }
                   5465:             }
                   5466:         }
                   5467:     }
1.3       raeburn  5468:     return $resulttext;
1.1       raeburn  5469: }
                   5470: 
1.9       raeburn  5471: sub thumb_dimensions {
                   5472:     return ('200','50');
                   5473: }
                   5474: 
1.16      raeburn  5475: sub check_dimensions {
                   5476:     my ($inputfile) = @_;
                   5477:     my ($fullwidth,$fullheight);
                   5478:     if ($inputfile =~ m|^[/\w.\-]+$|) {
                   5479:         if (open(PIPE,"identify $inputfile 2>&1 |")) {
                   5480:             my $imageinfo = <PIPE>;
                   5481:             if (!close(PIPE)) {
                   5482:                 &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
                   5483:             }
                   5484:             chomp($imageinfo);
                   5485:             my ($fullsize) = 
1.21      raeburn  5486:                 ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16      raeburn  5487:             if ($fullsize) {
                   5488:                 ($fullwidth,$fullheight) = split(/x/,$fullsize);
                   5489:             }
                   5490:         }
                   5491:     }
                   5492:     return ($fullwidth,$fullheight);
                   5493: }
                   5494: 
1.9       raeburn  5495: sub check_configuser {
                   5496:     my ($uhome,$dom,$confname,$servadm) = @_;
                   5497:     my ($configuserok,%currroles);
                   5498:     if ($uhome eq 'no_host') {
                   5499:         srand( time() ^ ($$ + ($$ << 15))  ); # Seed rand.
                   5500:         my $configpass = &LONCAPA::Enrollment::create_password();
                   5501:         $configuserok = 
                   5502:             &Apache::lonnet::modifyuser($dom,$confname,'','internal',
                   5503:                              $configpass,'','','','','',undef,$servadm);
                   5504:     } else {
                   5505:         $configuserok = 'ok';
                   5506:         %currroles = 
                   5507:             &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
                   5508:     }
                   5509:     return ($configuserok,%currroles);
                   5510: }
                   5511: 
                   5512: sub check_authorstatus {
                   5513:     my ($dom,$confname,%currroles) = @_;
                   5514:     my $author_ok;
1.40      raeburn  5515:     if (!$currroles{':'.$dom.':au'}) {
1.9       raeburn  5516:         my $start = time;
                   5517:         my $end = 0;
                   5518:         $author_ok = 
                   5519:             &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47      raeburn  5520:                                         'au',$end,$start,'','','domconfig');
1.9       raeburn  5521:     } else {
                   5522:         $author_ok = 'ok';
                   5523:     }
                   5524:     return $author_ok;
                   5525: }
                   5526: 
                   5527: sub publishlogo {
1.46      raeburn  5528:     my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9       raeburn  5529:     my ($output,$fname,$logourl);
                   5530:     if ($action eq 'upload') {
                   5531:         $fname=$env{'form.'.$formname.'.filename'};
                   5532:         chop($env{'form.'.$formname});
                   5533:     } else {
                   5534:         ($fname) = ($formname =~ /([^\/]+)$/);
                   5535:     }
1.46      raeburn  5536:     if ($savefileas ne '') {
                   5537:         $fname = $savefileas;
                   5538:     }
1.9       raeburn  5539:     $fname=&Apache::lonnet::clean_filename($fname);
                   5540: # See if there is anything left
                   5541:     unless ($fname) { return ('error: no uploaded file'); }
                   5542:     $fname="$subdir/$fname";
1.210     raeburn  5543:     my $docroot=$r->dir_config('lonDocRoot');
1.164     raeburn  5544:     my $filepath="$docroot/priv";
                   5545:     my $relpath = "$dom/$confname";
1.9       raeburn  5546:     my ($fnamepath,$file,$fetchthumb);
                   5547:     $file=$fname;
                   5548:     if ($fname=~m|/|) {
                   5549:         ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
                   5550:     }
1.164     raeburn  5551:     my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9       raeburn  5552:     my $count;
1.164     raeburn  5553:     for ($count=5;$count<=$#parts;$count++) {
1.9       raeburn  5554:         $filepath.="/$parts[$count]";
                   5555:         if ((-e $filepath)!=1) {
                   5556:             mkdir($filepath,02770);
                   5557:         }
                   5558:     }
                   5559:     # Check for bad extension and disallow upload
                   5560:     if ($file=~/\.(\w+)$/ &&
                   5561:         (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
                   5562:         $output = 
1.207     bisitz   5563:             &mt('Invalid file extension ([_1]) - reserved for internal use.',$1); 
1.9       raeburn  5564:     } elsif ($file=~/\.(\w+)$/ &&
                   5565:         !defined(&Apache::loncommon::fileembstyle($1))) {
                   5566:         $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
                   5567:     } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.195     bisitz   5568:         $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  5569:     } elsif (-d "$filepath/$file") {
1.195     bisitz   5570:         $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9       raeburn  5571:     } else {
                   5572:         my $source = $filepath.'/'.$file;
                   5573:         my $logfile;
                   5574:         if (!open($logfile,">>$source".'.log')) {
1.196     raeburn  5575:             return (&mt('No write permission to Authoring Space'));
1.9       raeburn  5576:         }
                   5577:         print $logfile
                   5578: "\n================= Publish ".localtime()." ================\n".
                   5579: $env{'user.name'}.':'.$env{'user.domain'}."\n";
                   5580: # Save the file
                   5581:         if (!open(FH,'>'.$source)) {
                   5582:             &Apache::lonnet::logthis('Failed to create '.$source);
                   5583:             return (&mt('Failed to create file'));
                   5584:         }
                   5585:         if ($action eq 'upload') {
                   5586:             if (!print FH ($env{'form.'.$formname})) {
                   5587:                 &Apache::lonnet::logthis('Failed to write to '.$source);
                   5588:                 return (&mt('Failed to write file'));
                   5589:             }
                   5590:         } else {
                   5591:             my $original = &Apache::lonnet::filelocation('',$formname);
                   5592:             if(!copy($original,$source)) {
                   5593:                 &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
                   5594:                 return (&mt('Failed to write file'));
                   5595:             }
                   5596:         }
                   5597:         close(FH);
                   5598:         chmod(0660, $source); # Permissions to rw-rw---.
                   5599: 
                   5600:         my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
                   5601:         my $copyfile=$targetdir.'/'.$file;
                   5602: 
                   5603:         my @parts=split(/\//,$targetdir);
                   5604:         my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
                   5605:         for (my $count=5;$count<=$#parts;$count++) {
                   5606:             $path.="/$parts[$count]";
                   5607:             if (!-e $path) {
                   5608:                 print $logfile "\nCreating directory ".$path;
                   5609:                 mkdir($path,02770);
                   5610:             }
                   5611:         }
                   5612:         my $versionresult;
                   5613:         if (-e $copyfile) {
                   5614:             $versionresult = &logo_versioning($targetdir,$file,$logfile);
                   5615:         } else {
                   5616:             $versionresult = 'ok';
                   5617:         }
                   5618:         if ($versionresult eq 'ok') {
                   5619:             if (copy($source,$copyfile)) {
                   5620:                 print $logfile "\nCopied original source to ".$copyfile."\n";
                   5621:                 $output = 'ok';
                   5622:                 $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155     raeburn  5623:                 push(@{$modified_urls},[$copyfile,$source]);
                   5624:                 my $metaoutput = 
                   5625:                     &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
                   5626:                 unless ($registered_cleanup) {
                   5627:                     my $handlers = $r->get_handlers('PerlCleanupHandler');
                   5628:                     $r->set_handlers('PerlCleanupHandler' => [\&notifysubscribed,@{$handlers}]);
                   5629:                     $registered_cleanup=1;
                   5630:                 }
1.9       raeburn  5631:             } else {
                   5632:                 print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
                   5633:                 $output = &mt('Failed to copy file to RES space').", $!";
                   5634:             }
                   5635:             if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
                   5636:                 my $inputfile = $filepath.'/'.$file;
                   5637:                 my $outfile = $filepath.'/'.'tn-'.$file;
1.16      raeburn  5638:                 my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
                   5639:                 if ($fullwidth ne '' && $fullheight ne '') { 
                   5640:                     if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
                   5641:                         my $thumbsize = $thumbwidth.'x'.$thumbheight;
                   5642:                         system("convert -sample $thumbsize $inputfile $outfile");
                   5643:                         chmod(0660, $filepath.'/tn-'.$file);
                   5644:                         if (-e $outfile) {
                   5645:                             my $copyfile=$targetdir.'/tn-'.$file;
                   5646:                             if (copy($outfile,$copyfile)) {
                   5647:                                 print $logfile "\nCopied source to ".$copyfile."\n";
1.155     raeburn  5648:                                 my $thumb_metaoutput = 
                   5649:                                     &write_metadata($dom,$confname,$formname,
                   5650:                                                     $targetdir,'tn-'.$file,$logfile);
                   5651:                                 push(@{$modified_urls},[$copyfile,$outfile]);
                   5652:                                 unless ($registered_cleanup) {
                   5653:                                     my $handlers = $r->get_handlers('PerlCleanupHandler');
                   5654:                                     $r->set_handlers('PerlCleanupHandler' => [\&notifysubscribed,@{$handlers}]);
                   5655:                                     $registered_cleanup=1;
                   5656:                                 }
1.16      raeburn  5657:                             } else {
                   5658:                                 print $logfile "\nUnable to write ".$copyfile.
                   5659:                                                ':'.$!."\n";
                   5660:                             }
                   5661:                         }
1.9       raeburn  5662:                     }
                   5663:                 }
                   5664:             }
                   5665:         } else {
                   5666:             $output = $versionresult;
                   5667:         }
                   5668:     }
                   5669:     return ($output,$logourl);
                   5670: }
                   5671: 
                   5672: sub logo_versioning {
                   5673:     my ($targetdir,$file,$logfile) = @_;
                   5674:     my $target = $targetdir.'/'.$file;
                   5675:     my ($maxversion,$fn,$extn,$output);
                   5676:     $maxversion = 0;
                   5677:     if ($file =~ /^(.+)\.(\w+)$/) {
                   5678:         $fn=$1;
                   5679:         $extn=$2;
                   5680:     }
                   5681:     opendir(DIR,$targetdir);
                   5682:     while (my $filename=readdir(DIR)) {
                   5683:         if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
                   5684:             $maxversion=($1>$maxversion)?$1:$maxversion;
                   5685:         }
                   5686:     }
                   5687:     $maxversion++;
                   5688:     print $logfile "\nCreating old version ".$maxversion."\n";
                   5689:     my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
                   5690:     if (copy($target,$copyfile)) {
                   5691:         print $logfile "Copied old target to ".$copyfile."\n";
                   5692:         $copyfile=$copyfile.'.meta';
                   5693:         if (copy($target.'.meta',$copyfile)) {
                   5694:             print $logfile "Copied old target metadata to ".$copyfile."\n";
                   5695:             $output = 'ok';
                   5696:         } else {
                   5697:             print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
                   5698:             $output = &mt('Failed to copy old meta').", $!, ";
                   5699:         }
                   5700:     } else {
                   5701:         print $logfile "Unable to write ".$copyfile.':'.$!."\n";
                   5702:         $output = &mt('Failed to copy old target').", $!, ";
                   5703:     }
                   5704:     return $output;
                   5705: }
                   5706: 
                   5707: sub write_metadata {
                   5708:     my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
                   5709:     my (%metadatafields,%metadatakeys,$output);
                   5710:     $metadatafields{'title'}=$formname;
                   5711:     $metadatafields{'creationdate'}=time;
                   5712:     $metadatafields{'lastrevisiondate'}=time;
                   5713:     $metadatafields{'copyright'}='public';
                   5714:     $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
                   5715:                                          $env{'user.domain'};
                   5716:     $metadatafields{'authorspace'}=$confname.':'.$dom;
                   5717:     $metadatafields{'domain'}=$dom;
                   5718:     {
                   5719:         print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
                   5720:         my $mfh;
1.155     raeburn  5721:         if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
1.184     raeburn  5722:             foreach (sort(keys(%metadatafields))) {
1.155     raeburn  5723:                 unless ($_=~/\./) {
                   5724:                     my $unikey=$_;
                   5725:                     $unikey=~/^([A-Za-z]+)/;
                   5726:                     my $tag=$1;
                   5727:                     $tag=~tr/A-Z/a-z/;
                   5728:                     print $mfh "\n\<$tag";
                   5729:                     foreach (split(/\,/,$metadatakeys{$unikey})) {
                   5730:                         my $value=$metadatafields{$unikey.'.'.$_};
                   5731:                         $value=~s/\"/\'\'/g;
                   5732:                         print $mfh ' '.$_.'="'.$value.'"';
                   5733:                     }
                   5734:                     print $mfh '>'.
                   5735:                         &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
                   5736:                             .'</'.$tag.'>';
                   5737:                 }
                   5738:             }
                   5739:             $output = 'ok';
                   5740:             print $logfile "\nWrote metadata";
                   5741:             close($mfh);
                   5742:         } else {
                   5743:             print $logfile "\nFailed to open metadata file";
1.9       raeburn  5744:             $output = &mt('Could not write metadata');
                   5745:         }
                   5746:     }
1.155     raeburn  5747:     return $output;
                   5748: }
                   5749: 
                   5750: sub notifysubscribed {
                   5751:     foreach my $targetsource (@{$modified_urls}){
                   5752:         next unless (ref($targetsource) eq 'ARRAY');
                   5753:         my ($target,$source)=@{$targetsource};
                   5754:         if ($source ne '') {
                   5755:             if (open(my $logfh,'>>'.$source.'.log')) {
                   5756:                 print $logfh "\nCleanup phase: Notifications\n";
                   5757:                 my @subscribed=&subscribed_hosts($target);
                   5758:                 foreach my $subhost (@subscribed) {
                   5759:                     print $logfh "\nNotifying host ".$subhost.':';
                   5760:                     my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
                   5761:                     print $logfh $reply;
                   5762:                 }
                   5763:                 my @subscribedmeta=&subscribed_hosts("$target.meta");
                   5764:                 foreach my $subhost (@subscribedmeta) {
                   5765:                     print $logfh "\nNotifying host for metadata only ".$subhost.':';
                   5766:                     my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
                   5767:                                                         $subhost);
                   5768:                     print $logfh $reply;
                   5769:                 }
                   5770:                 print $logfh "\n============ Done ============\n";
1.160     raeburn  5771:                 close($logfh);
1.155     raeburn  5772:             }
                   5773:         }
                   5774:     }
                   5775:     return OK;
                   5776: }
                   5777: 
                   5778: sub subscribed_hosts {
                   5779:     my ($target) = @_;
                   5780:     my @subscribed;
                   5781:     if (open(my $fh,"<$target.subscription")) {
                   5782:         while (my $subline=<$fh>) {
                   5783:             if ($subline =~ /^($match_lonid):/) {
                   5784:                 my $host = $1;
                   5785:                 if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
                   5786:                     unless (grep(/^\Q$host\E$/,@subscribed)) {
                   5787:                         push(@subscribed,$host);
                   5788:                     }
                   5789:                 }
                   5790:             }
                   5791:         }
                   5792:     }
                   5793:     return @subscribed;
1.9       raeburn  5794: }
                   5795: 
                   5796: sub check_switchserver {
                   5797:     my ($dom,$confname) = @_;
                   5798:     my ($allowed,$switchserver);
                   5799:     my $home = &Apache::lonnet::homeserver($confname,$dom);
                   5800:     if ($home eq 'no_host') {
                   5801:         $home = &Apache::lonnet::domain($dom,'primary');
                   5802:     }
                   5803:     my @ids=&Apache::lonnet::current_machine_ids();
1.10      albertel 5804:     foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
                   5805:     if (!$allowed) {
1.180     raeburn  5806: 	$switchserver='<a href="/adm/switchserver?otherserver='.$home.'&amp;role=dc./'.$dom.'/&amp;destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9       raeburn  5807:     }
                   5808:     return $switchserver;
                   5809: }
                   5810: 
1.1       raeburn  5811: sub modify_quotas {
1.86      raeburn  5812:     my ($dom,$action,%domconfig) = @_;
1.101     raeburn  5813:     my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
                   5814:         %limithash,$toolregexp,%conditions,$resulttext,%changes);
1.86      raeburn  5815:     if ($action eq 'quotas') {
                   5816:         $context = 'tools'; 
1.163     raeburn  5817:     } else {
1.86      raeburn  5818:         $context = $action;
                   5819:     }
                   5820:     if ($context eq 'requestcourses') {
1.98      raeburn  5821:         @usertools = ('official','unofficial','community');
1.106     raeburn  5822:         @options =('norequest','approval','validate','autolimit');
1.101     raeburn  5823:         %validations = &Apache::lonnet::auto_courserequest_checks($dom);
                   5824:         %titles = &courserequest_titles();
                   5825:         $toolregexp = join('|',@usertools);
                   5826:         %conditions = &courserequest_conditions();
1.163     raeburn  5827:     } elsif ($context eq 'requestauthor') {
                   5828:         @usertools = ('author');
                   5829:         %titles = &authorrequest_titles();
1.86      raeburn  5830:     } else {
1.162     raeburn  5831:         @usertools = ('aboutme','blog','webdav','portfolio');
1.101     raeburn  5832:         %titles = &tool_titles();
1.86      raeburn  5833:     }
1.72      raeburn  5834:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.44      raeburn  5835:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1       raeburn  5836:     foreach my $key (keys(%env)) {
1.101     raeburn  5837:         if ($context eq 'requestcourses') {
                   5838:             if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
                   5839:                 my $item = $1;
                   5840:                 my $type = $2;
                   5841:                 if ($type =~ /^limit_(.+)/) {
                   5842:                     $limithash{$item}{$1} = $env{$key};
                   5843:                 } else {
                   5844:                     $confhash{$item}{$type} = $env{$key};
                   5845:                 }
                   5846:             }
1.163     raeburn  5847:         } elsif ($context eq 'requestauthor') {
                   5848:             if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
                   5849:                 $confhash{$1} = $env{$key};
                   5850:             }
1.101     raeburn  5851:         } else {
1.86      raeburn  5852:             if ($key =~ /^form\.quota_(.+)$/) {
                   5853:                 $confhash{'defaultquota'}{$1} = $env{$key};
1.197     raeburn  5854:             } elsif ($key =~ /^form\.authorquota_(.+)$/) {
                   5855:                 $confhash{'authorquota'}{$1} = $env{$key};
                   5856:             } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101     raeburn  5857:                 @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
                   5858:             }
1.72      raeburn  5859:         }
                   5860:     }
1.163     raeburn  5861:     if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.102     raeburn  5862:         my @approvalnotify = &Apache::loncommon::get_env_multiple('form.reqapprovalnotify');
                   5863:         @approvalnotify = sort(@approvalnotify);
                   5864:         $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
                   5865:         if (ref($domconfig{$action}) eq 'HASH') {
                   5866:             if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
                   5867:                 if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
                   5868:                     $changes{'notify'}{'approval'} = 1;
                   5869:                 }
                   5870:             } else {
1.144     raeburn  5871:                 if ($confhash{'notify'}{'approval'}) {
1.102     raeburn  5872:                     $changes{'notify'}{'approval'} = 1;
                   5873:                 }
                   5874:             }
                   5875:         } else {
1.144     raeburn  5876:             if ($confhash{'notify'}{'approval'}) {
1.102     raeburn  5877:                 $changes{'notify'}{'approval'} = 1;
                   5878:             }
                   5879:         }
                   5880:     } else {
1.86      raeburn  5881:         $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.197     raeburn  5882:         $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86      raeburn  5883:     }
1.72      raeburn  5884:     foreach my $item (@usertools) {
                   5885:         foreach my $type (@{$types},'default','_LC_adv') {
1.104     raeburn  5886:             my $unset; 
1.101     raeburn  5887:             if ($context eq 'requestcourses') {
1.104     raeburn  5888:                 $unset = '0';
                   5889:                 if ($type eq '_LC_adv') {
                   5890:                     $unset = '';
                   5891:                 }
1.101     raeburn  5892:                 if ($confhash{$item}{$type} eq 'autolimit') {
                   5893:                     $confhash{$item}{$type} .= '=';
                   5894:                     unless ($limithash{$item}{$type} =~ /\D/) {
                   5895:                         $confhash{$item}{$type} .= $limithash{$item}{$type};
                   5896:                     }
                   5897:                 }
1.163     raeburn  5898:             } elsif ($context eq 'requestauthor') {
                   5899:                 $unset = '0';
                   5900:                 if ($type eq '_LC_adv') {
                   5901:                     $unset = '';
                   5902:                 }
1.72      raeburn  5903:             } else {
1.101     raeburn  5904:                 if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
                   5905:                     $confhash{$item}{$type} = 1;
                   5906:                 } else {
                   5907:                     $confhash{$item}{$type} = 0;
                   5908:                 }
1.72      raeburn  5909:             }
1.86      raeburn  5910:             if (ref($domconfig{$action}) eq 'HASH') {
1.163     raeburn  5911:                 if ($action eq 'requestauthor') {
                   5912:                     if ($domconfig{$action}{$type} ne $confhash{$type}) {
                   5913:                         $changes{$type} = 1;
                   5914:                     }
                   5915:                 } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86      raeburn  5916:                     if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
                   5917:                         $changes{$item}{$type} = 1;
                   5918:                     }
                   5919:                 } else {
                   5920:                     if ($context eq 'requestcourses') {
1.104     raeburn  5921:                         if ($confhash{$item}{$type} ne $unset) {
1.86      raeburn  5922:                             $changes{$item}{$type} = 1;
                   5923:                         }
                   5924:                     } else {
                   5925:                         if (!$confhash{$item}{$type}) {
                   5926:                             $changes{$item}{$type} = 1;
                   5927:                         }
                   5928:                     }
                   5929:                 }
                   5930:             } else {
                   5931:                 if ($context eq 'requestcourses') {
1.104     raeburn  5932:                     if ($confhash{$item}{$type} ne $unset) {
1.72      raeburn  5933:                         $changes{$item}{$type} = 1;
                   5934:                     }
1.163     raeburn  5935:                 } elsif ($context eq 'requestauthor') {
                   5936:                     if ($confhash{$type} ne $unset) {
                   5937:                         $changes{$type} = 1;
                   5938:                     }
1.72      raeburn  5939:                 } else {
                   5940:                     if (!$confhash{$item}{$type}) {
                   5941:                         $changes{$item}{$type} = 1;
                   5942:                     }
                   5943:                 }
                   5944:             }
1.1       raeburn  5945:         }
                   5946:     }
1.163     raeburn  5947:     unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86      raeburn  5948:         if (ref($domconfig{'quotas'}) eq 'HASH') {
                   5949:             if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
                   5950:                 foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
                   5951:                     if (exists($confhash{'defaultquota'}{$key})) {
                   5952:                         if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
                   5953:                             $changes{'defaultquota'}{$key} = 1;
                   5954:                         }
                   5955:                     } else {
                   5956:                         $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72      raeburn  5957:                     }
                   5958:                 }
1.86      raeburn  5959:             } else {
                   5960:                 foreach my $key (keys(%{$domconfig{'quotas'}})) {
                   5961:                     if (exists($confhash{'defaultquota'}{$key})) {
                   5962:                         if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
                   5963:                             $changes{'defaultquota'}{$key} = 1;
                   5964:                         }
                   5965:                     } else {
                   5966:                         $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72      raeburn  5967:                     }
1.1       raeburn  5968:                 }
                   5969:             }
1.197     raeburn  5970:             if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
                   5971:                 foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
                   5972:                     if (exists($confhash{'authorquota'}{$key})) {
                   5973:                         if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
                   5974:                             $changes{'authorquota'}{$key} = 1;
                   5975:                         }
                   5976:                     } else {
                   5977:                         $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
                   5978:                     }
                   5979:                 }
                   5980:             }
1.1       raeburn  5981:         }
1.86      raeburn  5982:         if (ref($confhash{'defaultquota'}) eq 'HASH') {
                   5983:             foreach my $key (keys(%{$confhash{'defaultquota'}})) {
                   5984:                 if (ref($domconfig{'quotas'}) eq 'HASH') {
                   5985:                     if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
                   5986:                         if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
                   5987:                             $changes{'defaultquota'}{$key} = 1;
                   5988:                         }
                   5989:                     } else {
                   5990:                         if (!exists($domconfig{'quotas'}{$key})) {
                   5991:                             $changes{'defaultquota'}{$key} = 1;
                   5992:                         }
1.72      raeburn  5993:                     }
                   5994:                 } else {
1.86      raeburn  5995:                     $changes{'defaultquota'}{$key} = 1;
1.55      raeburn  5996:                 }
1.1       raeburn  5997:             }
                   5998:         }
1.197     raeburn  5999:         if (ref($confhash{'authorquota'}) eq 'HASH') {
                   6000:             foreach my $key (keys(%{$confhash{'authorquota'}})) {
                   6001:                 if (ref($domconfig{'quotas'}) eq 'HASH') {
                   6002:                     if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
                   6003:                         if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
                   6004:                             $changes{'authorquota'}{$key} = 1;
                   6005:                         }
                   6006:                     } else {
                   6007:                         $changes{'authorquota'}{$key} = 1;
                   6008:                     }
                   6009:                 } else {
                   6010:                     $changes{'authorquota'}{$key} = 1;
                   6011:                 }
                   6012:             }
                   6013:         }
1.1       raeburn  6014:     }
1.72      raeburn  6015: 
1.163     raeburn  6016:     if ($context eq 'requestauthor') {
                   6017:         $domdefaults{'requestauthor'} = \%confhash;
                   6018:     } else {
                   6019:         foreach my $key (keys(%confhash)) {
                   6020:             $domdefaults{$key} = $confhash{$key};
                   6021:         }
1.72      raeburn  6022:     }
1.163     raeburn  6023: 
1.1       raeburn  6024:     my %quotahash = (
1.86      raeburn  6025:                       $action => { %confhash }
1.1       raeburn  6026:                     );
                   6027:     my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
                   6028:                                              $dom);
                   6029:     if ($putresult eq 'ok') {
                   6030:         if (keys(%changes) > 0) {
1.72      raeburn  6031:             my $cachetime = 24*60*60;
                   6032:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
                   6033: 
1.1       raeburn  6034:             $resulttext = &mt('Changes made:').'<ul>';
1.210     raeburn  6035:             unless (($context eq 'requestcourses') ||
1.163     raeburn  6036:                     ($context eq 'requestauthor')) {
1.86      raeburn  6037:                 if (ref($changes{'defaultquota'}) eq 'HASH') {
                   6038:                     $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
                   6039:                     foreach my $type (@{$types},'default') {
                   6040:                         if (defined($changes{'defaultquota'}{$type})) {
                   6041:                             my $typetitle = $usertypes->{$type};
                   6042:                             if ($type eq 'default') {
                   6043:                                 $typetitle = $othertitle;
                   6044:                             }
                   6045:                             $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72      raeburn  6046:                         }
                   6047:                     }
1.86      raeburn  6048:                     $resulttext .= '</ul></li>';
1.72      raeburn  6049:                 }
1.197     raeburn  6050:                 if (ref($changes{'authorquota'}) eq 'HASH') {
                   6051:                     $resulttext .= '<li>'.&mt('Authoring space default quotas').'<ul>';
                   6052:                     foreach my $type (@{$types},'default') {
                   6053:                         if (defined($changes{'authorquota'}{$type})) {
                   6054:                             my $typetitle = $usertypes->{$type};
                   6055:                             if ($type eq 'default') {
                   6056:                                 $typetitle = $othertitle;
                   6057:                             }
                   6058:                             $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
                   6059:                         }
                   6060:                     }
                   6061:                     $resulttext .= '</ul></li>';
                   6062:                 }
1.72      raeburn  6063:             }
1.80      raeburn  6064:             my %newenv;
1.72      raeburn  6065:             foreach my $item (@usertools) {
1.163     raeburn  6066:                 my (%haschgs,%inconf);
                   6067:                 if ($context eq 'requestauthor') {
                   6068:                     %haschgs = %changes;
1.210     raeburn  6069:                     %inconf = %confhash;
1.163     raeburn  6070:                 } else {
                   6071:                     if (ref($changes{$item}) eq 'HASH') {
                   6072:                         %haschgs = %{$changes{$item}};
                   6073:                     }
                   6074:                     if (ref($confhash{$item}) eq 'HASH') {
                   6075:                         %inconf = %{$confhash{$item}};
                   6076:                     }
                   6077:                 }
                   6078:                 if (keys(%haschgs) > 0) {
1.80      raeburn  6079:                     my $newacc = 
                   6080:                         &Apache::lonnet::usertools_access($env{'user.name'},
                   6081:                                                           $env{'user.domain'},
1.86      raeburn  6082:                                                           $item,'reload',$context);
1.210     raeburn  6083:                     if (($context eq 'requestcourses') ||
1.163     raeburn  6084:                         ($context eq 'requestauthor')) {
1.108     raeburn  6085:                         if ($env{'environment.canrequest.'.$item} ne $newacc) {
                   6086:                             $newenv{'environment.canrequest.'.$item} = $newacc;
1.86      raeburn  6087:                         }
                   6088:                     } else {
                   6089:                         if ($env{'environment.availabletools.'.$item} ne $newacc) { 
                   6090:                             $newenv{'environment.availabletools.'.$item} = $newacc;
                   6091:                         }
1.80      raeburn  6092:                     }
1.163     raeburn  6093:                     unless ($context eq 'requestauthor') {
                   6094:                         $resulttext .= '<li>'.$titles{$item}.'<ul>';
                   6095:                     }
1.72      raeburn  6096:                     foreach my $type (@{$types},'default','_LC_adv') {
1.163     raeburn  6097:                         if ($haschgs{$type}) {
1.72      raeburn  6098:                             my $typetitle = $usertypes->{$type};
                   6099:                             if ($type eq 'default') {
                   6100:                                 $typetitle = $othertitle;
                   6101:                             } elsif ($type eq '_LC_adv') {
                   6102:                                 $typetitle = 'LON-CAPA Advanced Users'; 
                   6103:                             }
1.163     raeburn  6104:                             if ($inconf{$type}) {
1.101     raeburn  6105:                                 if ($context eq 'requestcourses') {
                   6106:                                     my $cond;
1.163     raeburn  6107:                                     if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101     raeburn  6108:                                         if ($1 eq '') {
                   6109:                                             $cond = &mt('(Automatic processing of any request).');
                   6110:                                         } else {
                   6111:                                             $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
                   6112:                                         }
                   6113:                                     } else { 
1.163     raeburn  6114:                                         $cond = $conditions{$inconf{$type}};
1.101     raeburn  6115:                                     }
                   6116:                                     $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172     raeburn  6117:                                 } elsif ($context eq 'requestauthor') {
                   6118:                                     $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
                   6119:                                                              $titles{$inconf{$type}},$typetitle);
                   6120: 
1.101     raeburn  6121:                                 } else {
                   6122:                                     $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
                   6123:                                 }
1.72      raeburn  6124:                             } else {
1.104     raeburn  6125:                                 if ($type eq '_LC_adv') {
1.163     raeburn  6126:                                     if ($inconf{$type} eq '0') {
1.104     raeburn  6127:                                         $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
                   6128:                                     } else { 
                   6129:                                         $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
                   6130:                                     }
                   6131:                                 } else {
                   6132:                                     $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
                   6133:                                 }
1.72      raeburn  6134:                             }
                   6135:                         }
1.26      raeburn  6136:                     }
1.163     raeburn  6137:                     unless ($context eq 'requestauthor') {
                   6138:                         $resulttext .= '</ul></li>';
                   6139:                     }
1.26      raeburn  6140:                 }
1.1       raeburn  6141:             }
1.163     raeburn  6142:             if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102     raeburn  6143:                 if (ref($changes{'notify'}) eq 'HASH') {
                   6144:                     if ($changes{'notify'}{'approval'}) {
                   6145:                         if (ref($confhash{'notify'}) eq 'HASH') {
                   6146:                             if ($confhash{'notify'}{'approval'}) {
                   6147:                                 $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
                   6148:                             } else {
1.163     raeburn  6149:                                 $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102     raeburn  6150:                             }
                   6151:                         }
                   6152:                     }
                   6153:                 }
                   6154:             }
1.1       raeburn  6155:             $resulttext .= '</ul>';
1.80      raeburn  6156:             if (keys(%newenv)) {
                   6157:                 &Apache::lonnet::appenv(\%newenv);
                   6158:             }
1.1       raeburn  6159:         } else {
1.86      raeburn  6160:             if ($context eq 'requestcourses') {
                   6161:                 $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163     raeburn  6162:             } elsif ($context eq 'requestauthor') {
                   6163:                 $resulttext = &mt('No changes made to rights to request author space.');
1.86      raeburn  6164:             } else {
1.90      weissno  6165:                 $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86      raeburn  6166:             }
1.1       raeburn  6167:         }
                   6168:     } else {
1.11      albertel 6169:         $resulttext = '<span class="LC_error">'.
                   6170: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  6171:     }
1.3       raeburn  6172:     return $resulttext;
1.1       raeburn  6173: }
                   6174: 
1.3       raeburn  6175: sub modify_autoenroll {
1.205     raeburn  6176:     my ($dom,$lastactref,%domconfig) = @_;
1.1       raeburn  6177:     my ($resulttext,%changes);
                   6178:     my %currautoenroll;
                   6179:     if (ref($domconfig{'autoenroll'}) eq 'HASH') {
                   6180:         foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
                   6181:             $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
                   6182:         }
                   6183:     }
                   6184:     my $autorun = &Apache::lonnet::auto_run(undef,$dom),
                   6185:     my %title = ( run => 'Auto-enrollment active',
1.129     raeburn  6186:                   sender => 'Sender for notification messages',
                   6187:                   coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)');
1.1       raeburn  6188:     my @offon = ('off','on');
1.17      raeburn  6189:     my $sender_uname = $env{'form.sender_uname'};
                   6190:     my $sender_domain = $env{'form.sender_domain'};
                   6191:     if ($sender_domain eq '') {
                   6192:         $sender_uname = '';
                   6193:     } elsif ($sender_uname eq '') {
                   6194:         $sender_domain = '';
                   6195:     }
1.129     raeburn  6196:     my $coowners = $env{'form.autoassign_coowners'};
1.1       raeburn  6197:     my %autoenrollhash =  (
1.129     raeburn  6198:                        autoenroll => { 'run' => $env{'form.autoenroll_run'},
                   6199:                                        'sender_uname' => $sender_uname,
                   6200:                                        'sender_domain' => $sender_domain,
                   6201:                                        'co-owners' => $coowners,
1.1       raeburn  6202:                                 }
                   6203:                      );
1.4       raeburn  6204:     my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
                   6205:                                              $dom);
1.1       raeburn  6206:     if ($putresult eq 'ok') {
                   6207:         if (exists($currautoenroll{'run'})) {
                   6208:              if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
                   6209:                  $changes{'run'} = 1;
                   6210:              }
                   6211:         } elsif ($autorun) {
                   6212:             if ($env{'form.autoenroll_run'} ne '1') {
1.23      raeburn  6213:                  $changes{'run'} = 1;
1.1       raeburn  6214:             }
                   6215:         }
1.17      raeburn  6216:         if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1       raeburn  6217:             $changes{'sender'} = 1;
                   6218:         }
1.17      raeburn  6219:         if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1       raeburn  6220:             $changes{'sender'} = 1;
                   6221:         }
1.129     raeburn  6222:         if ($currautoenroll{'co-owners'} ne '') {
                   6223:             if ($currautoenroll{'co-owners'} ne $coowners) {
                   6224:                 $changes{'coowners'} = 1;
                   6225:             }
                   6226:         } elsif ($coowners) {
                   6227:             $changes{'coowners'} = 1;
                   6228:         }      
1.1       raeburn  6229:         if (keys(%changes) > 0) {
                   6230:             $resulttext = &mt('Changes made:').'<ul>';
1.3       raeburn  6231:             if ($changes{'run'}) {
1.1       raeburn  6232:                 $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
                   6233:             }
                   6234:             if ($changes{'sender'}) {
1.17      raeburn  6235:                 if ($sender_uname eq '' || $sender_domain eq '') {
                   6236:                     $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
                   6237:                 } else {
                   6238:                     $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
                   6239:                 }
1.1       raeburn  6240:             }
1.129     raeburn  6241:             if ($changes{'coowners'}) {
                   6242:                 $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
                   6243:                 &Apache::loncommon::devalidate_domconfig_cache($dom);
1.205     raeburn  6244:                 $$lastactref = 'update';
1.129     raeburn  6245:             }
1.1       raeburn  6246:             $resulttext .= '</ul>';
                   6247:         } else {
                   6248:             $resulttext = &mt('No changes made to auto-enrollment settings');
                   6249:         }
                   6250:     } else {
1.11      albertel 6251:         $resulttext = '<span class="LC_error">'.
                   6252: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  6253:     }
1.3       raeburn  6254:     return $resulttext;
1.1       raeburn  6255: }
                   6256: 
                   6257: sub modify_autoupdate {
1.3       raeburn  6258:     my ($dom,%domconfig) = @_;
1.1       raeburn  6259:     my ($resulttext,%currautoupdate,%fields,%changes);
                   6260:     if (ref($domconfig{'autoupdate'}) eq 'HASH') {
                   6261:         foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
                   6262:             $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
                   6263:         }
                   6264:     }
                   6265:     my @offon = ('off','on');
                   6266:     my %title = &Apache::lonlocal::texthash (
                   6267:                    run => 'Auto-update:',
                   6268:                    classlists => 'Updates to user information in classlists?'
                   6269:                 );
1.44      raeburn  6270:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1       raeburn  6271:     my %fieldtitles = &Apache::lonlocal::texthash (
                   6272:                         id => 'Student/Employee ID',
1.20      raeburn  6273:                         permanentemail => 'E-mail address',
1.1       raeburn  6274:                         lastname => 'Last Name',
                   6275:                         firstname => 'First Name',
                   6276:                         middlename => 'Middle Name',
1.132     raeburn  6277:                         generation => 'Generation',
1.1       raeburn  6278:                       );
1.142     raeburn  6279:     $othertitle = &mt('All users');
1.1       raeburn  6280:     if (keys(%{$usertypes}) >  0) {
1.26      raeburn  6281:         $othertitle = &mt('Other users');
1.1       raeburn  6282:     }
                   6283:     foreach my $key (keys(%env)) {
                   6284:         if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132     raeburn  6285:             my ($usertype,$item) = ($1,$2);
                   6286:             if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
                   6287:                 if ($usertype eq 'default') {   
                   6288:                     push(@{$fields{$1}},$2);
                   6289:                 } elsif (ref($types) eq 'ARRAY') {
                   6290:                     if (grep(/^\Q$usertype\E$/,@{$types})) {
                   6291:                         push(@{$fields{$1}},$2);
                   6292:                     }
                   6293:                 }
                   6294:             }
1.1       raeburn  6295:         }
                   6296:     }
1.131     raeburn  6297:     my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
                   6298:     @lockablenames = sort(@lockablenames);
                   6299:     if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
                   6300:         my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
                   6301:         if (@changed) {
                   6302:             $changes{'lockablenames'} = 1;
                   6303:         }
                   6304:     } else {
                   6305:         if (@lockablenames) {
                   6306:             $changes{'lockablenames'} = 1;
                   6307:         }
                   6308:     }
1.1       raeburn  6309:     my %updatehash = (
                   6310:                       autoupdate => { run => $env{'form.autoupdate_run'},
                   6311:                                       classlists => $env{'form.classlists'},
                   6312:                                       fields => {%fields},
1.131     raeburn  6313:                                       lockablenames => \@lockablenames,
1.1       raeburn  6314:                                     }
                   6315:                      );
                   6316:     foreach my $key (keys(%currautoupdate)) {
                   6317:         if (($key eq 'run') || ($key eq 'classlists')) {
                   6318:             if (exists($updatehash{autoupdate}{$key})) {
                   6319:                 if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
                   6320:                     $changes{$key} = 1;
                   6321:                 }
                   6322:             }
                   6323:         } elsif ($key eq 'fields') {
                   6324:             if (ref($currautoupdate{$key}) eq 'HASH') {
1.26      raeburn  6325:                 foreach my $item (@{$types},'default') {
1.1       raeburn  6326:                     if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
                   6327:                         my $change = 0;
                   6328:                         foreach my $type (@{$currautoupdate{$key}{$item}}) {
                   6329:                             if (!exists($fields{$item})) {
                   6330:                                 $change = 1;
1.132     raeburn  6331:                                 last;
1.1       raeburn  6332:                             } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26      raeburn  6333:                                 if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1       raeburn  6334:                                     $change = 1;
1.132     raeburn  6335:                                     last;
1.1       raeburn  6336:                                 }
                   6337:                             }
                   6338:                         }
                   6339:                         if ($change) {
                   6340:                             push(@{$changes{$key}},$item);
                   6341:                         }
1.26      raeburn  6342:                     } 
1.1       raeburn  6343:                 }
                   6344:             }
1.131     raeburn  6345:         } elsif ($key eq 'lockablenames') {
                   6346:             if (ref($currautoupdate{$key}) eq 'ARRAY') {
                   6347:                 my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
                   6348:                 if (@changed) {
                   6349:                     $changes{'lockablenames'} = 1;
                   6350:                 }
                   6351:             } else {
                   6352:                 if (@lockablenames) {
                   6353:                     $changes{'lockablenames'} = 1;
                   6354:                 }
                   6355:             }
                   6356:         }
                   6357:     }
                   6358:     unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
                   6359:         if (@lockablenames) {
                   6360:             $changes{'lockablenames'} = 1;
1.1       raeburn  6361:         }
                   6362:     }
1.26      raeburn  6363:     foreach my $item (@{$types},'default') {
                   6364:         if (defined($fields{$item})) {
                   6365:             if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132     raeburn  6366:                 if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
                   6367:                     my $change = 0;
                   6368:                     if (ref($fields{$item}) eq 'ARRAY') {
                   6369:                         foreach my $type (@{$fields{$item}}) {
                   6370:                             if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
                   6371:                                 $change = 1;
                   6372:                                 last;
                   6373:                             }
                   6374:                         }
                   6375:                     }
                   6376:                     if ($change) {
                   6377:                         push(@{$changes{'fields'}},$item);
                   6378:                     }
                   6379:                 } else {
1.26      raeburn  6380:                     push(@{$changes{'fields'}},$item);
                   6381:                 }
                   6382:             } else {
                   6383:                 push(@{$changes{'fields'}},$item);
1.1       raeburn  6384:             }
                   6385:         }
                   6386:     }
                   6387:     my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
                   6388:                                              $dom);
                   6389:     if ($putresult eq 'ok') {
                   6390:         if (keys(%changes) > 0) {
                   6391:             $resulttext = &mt('Changes made:').'<ul>';
                   6392:             foreach my $key (sort(keys(%changes))) {
1.131     raeburn  6393:                 if ($key eq 'lockablenames') {
                   6394:                     $resulttext .= '<li>';
                   6395:                     if (@lockablenames) {
                   6396:                         $usertypes->{'default'} = $othertitle;
                   6397:                         $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
                   6398:                                    join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
                   6399:                     } else {
                   6400:                         $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
                   6401:                     }
                   6402:                     $resulttext .= '</li>';
                   6403:                 } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1       raeburn  6404:                     foreach my $item (@{$changes{$key}}) {
                   6405:                         my @newvalues;
                   6406:                         foreach my $type (@{$fields{$item}}) {
                   6407:                             push(@newvalues,$fieldtitles{$type});
                   6408:                         }
1.3       raeburn  6409:                         my $newvaluestr;
                   6410:                         if (@newvalues > 0) {
                   6411:                             $newvaluestr = join(', ',@newvalues);
                   6412:                         } else {
                   6413:                             $newvaluestr = &mt('none');
1.6       raeburn  6414:                         }
1.1       raeburn  6415:                         if ($item eq 'default') {
1.26      raeburn  6416:                             $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1       raeburn  6417:                         } else {
1.26      raeburn  6418:                             $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1       raeburn  6419:                         }
                   6420:                     }
                   6421:                 } else {
                   6422:                     my $newvalue;
                   6423:                     if ($key eq 'run') {
                   6424:                         $newvalue = $offon[$env{'form.autoupdate_run'}];
                   6425:                     } else {
                   6426:                         $newvalue = $offon[$env{'form.'.$key}];
1.3       raeburn  6427:                     }
1.1       raeburn  6428:                     $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
                   6429:                 }
                   6430:             }
                   6431:             $resulttext .= '</ul>';
                   6432:         } else {
1.3       raeburn  6433:             $resulttext = &mt('No changes made to autoupdates');
1.1       raeburn  6434:         }
                   6435:     } else {
1.11      albertel 6436:         $resulttext = '<span class="LC_error">'.
                   6437: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  6438:     }
1.3       raeburn  6439:     return $resulttext;
1.1       raeburn  6440: }
                   6441: 
1.125     raeburn  6442: sub modify_autocreate {
                   6443:     my ($dom,%domconfig) = @_;
                   6444:     my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
                   6445:     if (ref($domconfig{'autocreate'}) eq 'HASH') {
                   6446:         foreach my $key (keys(%{$domconfig{'autocreate'}})) {
                   6447:             $currautocreate{$key} = $domconfig{'autocreate'}{$key};
                   6448:         }
                   6449:     }
                   6450:     my %title= ( xml => 'Auto-creation of courses in XML course description files',
                   6451:                  req => 'Auto-creation of validated requests for official courses',
                   6452:                  xmldc => 'Identity of course creator of courses from XML files',
                   6453:                );
                   6454:     my @types = ('xml','req');
                   6455:     foreach my $item (@types) {
                   6456:         $newvals{$item} = $env{'form.autocreate_'.$item};
                   6457:         $newvals{$item} =~ s/\D//g;
                   6458:         $newvals{$item} = 0 if ($newvals{$item} eq '');
                   6459:     }
                   6460:     $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
                   6461:     my %domcoords = &get_active_dcs($dom);
                   6462:     unless (exists($domcoords{$newvals{'xmldc'}})) {
                   6463:         $newvals{'xmldc'} = '';
                   6464:     } 
                   6465:     %autocreatehash =  (
                   6466:                         autocreate => { xml => $newvals{'xml'},
                   6467:                                         req => $newvals{'req'},
                   6468:                                       }
                   6469:                        );
                   6470:     if ($newvals{'xmldc'} ne '') {
                   6471:         $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
                   6472:     }
                   6473:     my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
                   6474:                                              $dom);
                   6475:     if ($putresult eq 'ok') {
                   6476:         my @items = @types;
                   6477:         if ($newvals{'xml'}) {
                   6478:             push(@items,'xmldc');
                   6479:         }
                   6480:         foreach my $item (@items) {
                   6481:             if (exists($currautocreate{$item})) {
                   6482:                 if ($currautocreate{$item} ne $newvals{$item}) {
                   6483:                     $changes{$item} = 1;
                   6484:                 }
                   6485:             } elsif ($newvals{$item}) {
                   6486:                 $changes{$item} = 1;
                   6487:             }
                   6488:         }
                   6489:         if (keys(%changes) > 0) {
                   6490:             my @offon = ('off','on'); 
                   6491:             $resulttext = &mt('Changes made:').'<ul>';
                   6492:             foreach my $item (@types) {
                   6493:                 if ($changes{$item}) {
                   6494:                     my $newtxt = $offon[$newvals{$item}];
1.178     raeburn  6495:                     $resulttext .= '<li>'.
                   6496:                                    &mt("$title{$item} set to [_1]$newtxt [_2]",
                   6497:                                        '<b>','</b>').
                   6498:                                    '</li>';
1.125     raeburn  6499:                 }
                   6500:             }
                   6501:             if ($changes{'xmldc'}) {
                   6502:                 my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
                   6503:                 my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178     raeburn  6504:                 $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>'; 
1.125     raeburn  6505:             }
                   6506:             $resulttext .= '</ul>';
                   6507:         } else {
                   6508:             $resulttext = &mt('No changes made to auto-creation settings');
                   6509:         }
                   6510:     } else {
                   6511:         $resulttext = '<span class="LC_error">'.
                   6512:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   6513:     }
                   6514:     return $resulttext;
                   6515: }
                   6516: 
1.23      raeburn  6517: sub modify_directorysrch {
                   6518:     my ($dom,%domconfig) = @_;
                   6519:     my ($resulttext,%changes);
                   6520:     my %currdirsrch;
                   6521:     if (ref($domconfig{'directorysrch'}) eq 'HASH') {
                   6522:         foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
                   6523:             $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
                   6524:         }
                   6525:     }
                   6526:     my %title = ( available => 'Directory search available',
1.24      raeburn  6527:                   localonly => 'Other domains can search',
1.23      raeburn  6528:                   searchby => 'Search types',
                   6529:                   searchtypes => 'Search latitude');
                   6530:     my @offon = ('off','on');
1.24      raeburn  6531:     my @otherdoms = ('Yes','No');
1.23      raeburn  6532: 
1.25      raeburn  6533:     my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');  
1.23      raeburn  6534:     my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
                   6535:     my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
                   6536: 
1.44      raeburn  6537:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26      raeburn  6538:     if (keys(%{$usertypes}) == 0) {
                   6539:         @cansearch = ('default');
                   6540:     } else {
                   6541:         if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
                   6542:             foreach my $type (@{$currdirsrch{'cansearch'}}) {
                   6543:                 if (!grep(/^\Q$type\E$/,@cansearch)) {
                   6544:                     push(@{$changes{'cansearch'}},$type);
                   6545:                 }
1.23      raeburn  6546:             }
1.26      raeburn  6547:             foreach my $type (@cansearch) {
                   6548:                 if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
                   6549:                     push(@{$changes{'cansearch'}},$type);
                   6550:                 }
1.23      raeburn  6551:             }
1.26      raeburn  6552:         } else {
                   6553:             push(@{$changes{'cansearch'}},@cansearch);
1.23      raeburn  6554:         }
                   6555:     }
                   6556: 
                   6557:     if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
                   6558:         foreach my $by (@{$currdirsrch{'searchby'}}) {
                   6559:             if (!grep(/^\Q$by\E$/,@searchby)) {
                   6560:                 push(@{$changes{'searchby'}},$by);
                   6561:             }
                   6562:         }
                   6563:         foreach my $by (@searchby) {
                   6564:             if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
                   6565:                 push(@{$changes{'searchby'}},$by);
                   6566:             }
                   6567:         }
                   6568:     } else {
                   6569:         push(@{$changes{'searchby'}},@searchby);
                   6570:     }
1.25      raeburn  6571: 
                   6572:     if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
                   6573:         foreach my $type (@{$currdirsrch{'searchtypes'}}) {
                   6574:             if (!grep(/^\Q$type\E$/,@searchtypes)) {
                   6575:                 push(@{$changes{'searchtypes'}},$type);
                   6576:             }
                   6577:         }
                   6578:         foreach my $type (@searchtypes) {
                   6579:             if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
                   6580:                 push(@{$changes{'searchtypes'}},$type);
                   6581:             }
                   6582:         }
                   6583:     } else {
                   6584:         if (exists($currdirsrch{'searchtypes'})) {
                   6585:             foreach my $type (@searchtypes) {  
                   6586:                 if ($type ne $currdirsrch{'searchtypes'}) { 
                   6587:                     push(@{$changes{'searchtypes'}},$type);
                   6588:                 }
                   6589:             }
                   6590:             if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
                   6591:                 push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
                   6592:             }   
                   6593:         } else {
                   6594:             push(@{$changes{'searchtypes'}},@searchtypes); 
                   6595:         }
                   6596:     }
                   6597: 
1.23      raeburn  6598:     my %dirsrch_hash =  (
                   6599:             directorysrch => { available => $env{'form.dirsrch_available'},
                   6600:                                cansearch => \@cansearch,
1.24      raeburn  6601:                                localonly => $env{'form.dirsrch_localonly'},
1.23      raeburn  6602:                                searchby => \@searchby,
1.25      raeburn  6603:                                searchtypes => \@searchtypes,
1.23      raeburn  6604:                              }
                   6605:             );
                   6606:     my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
                   6607:                                              $dom);
                   6608:     if ($putresult eq 'ok') {
                   6609:         if (exists($currdirsrch{'available'})) {
                   6610:              if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
                   6611:                  $changes{'available'} = 1;
                   6612:              }
                   6613:         } else {
                   6614:             if ($env{'form.dirsrch_available'} eq '1') {
                   6615:                 $changes{'available'} = 1;
                   6616:             }
                   6617:         }
1.24      raeburn  6618:         if (exists($currdirsrch{'localonly'})) {
                   6619:              if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
                   6620:                  $changes{'localonly'} = 1;
                   6621:              }
                   6622:         } else {
                   6623:             if ($env{'form.dirsrch_localonly'} eq '1') {
                   6624:                 $changes{'localonly'} = 1;
                   6625:             }
                   6626:         }
1.23      raeburn  6627:         if (keys(%changes) > 0) {
                   6628:             $resulttext = &mt('Changes made:').'<ul>';
                   6629:             if ($changes{'available'}) {
                   6630:                 $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
                   6631:             }
1.24      raeburn  6632:             if ($changes{'localonly'}) {
                   6633:                 $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
                   6634:             }
                   6635: 
1.23      raeburn  6636:             if (ref($changes{'cansearch'}) eq 'ARRAY') {
                   6637:                 my $chgtext;
1.26      raeburn  6638:                 if (ref($usertypes) eq 'HASH') {
                   6639:                     if (keys(%{$usertypes}) > 0) {
                   6640:                         foreach my $type (@{$types}) {
                   6641:                             if (grep(/^\Q$type\E$/,@cansearch)) {
                   6642:                                 $chgtext .= $usertypes->{$type}.'; ';
                   6643:                             }
                   6644:                         }
                   6645:                         if (grep(/^default$/,@cansearch)) {
                   6646:                             $chgtext .= $othertitle;
                   6647:                         } else {
                   6648:                             $chgtext =~ s/\; $//;
                   6649:                         }
1.210     raeburn  6650:                         $resulttext .=
1.178     raeburn  6651:                             '<li>'.
                   6652:                             &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
                   6653:                                 '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
                   6654:                             '</li>';
1.23      raeburn  6655:                     }
                   6656:                 }
                   6657:             }
                   6658:             if (ref($changes{'searchby'}) eq 'ARRAY') {
                   6659:                 my ($searchtitles,$titleorder) = &sorted_searchtitles();
                   6660:                 my $chgtext;
                   6661:                 foreach my $type (@{$titleorder}) {
                   6662:                     if (grep(/^\Q$type\E$/,@searchby)) {
                   6663:                         if (defined($searchtitles->{$type})) {
                   6664:                             $chgtext .= $searchtitles->{$type}.'; ';
                   6665:                         }
                   6666:                     }
                   6667:                 }
                   6668:                 $chgtext =~ s/\; $//;
                   6669:                 $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
                   6670:             }
1.25      raeburn  6671:             if (ref($changes{'searchtypes'}) eq 'ARRAY') {
                   6672:                 my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes(); 
                   6673:                 my $chgtext;
                   6674:                 foreach my $type (@{$srchtypeorder}) {
                   6675:                     if (grep(/^\Q$type\E$/,@searchtypes)) {
                   6676:                         if (defined($srchtypes_desc->{$type})) {
                   6677:                             $chgtext .= $srchtypes_desc->{$type}.'; ';
                   6678:                         }
                   6679:                     }
                   6680:                 }
                   6681:                 $chgtext =~ s/\; $//;
1.178     raeburn  6682:                 $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23      raeburn  6683:             }
                   6684:             $resulttext .= '</ul>';
                   6685:         } else {
                   6686:             $resulttext = &mt('No changes made to institution directory search settings');
                   6687:         }
                   6688:     } else {
                   6689:         $resulttext = '<span class="LC_error">'.
1.27      raeburn  6690:                       &mt('An error occurred: [_1]',$putresult).'</span>';
                   6691:     }
                   6692:     return $resulttext;
                   6693: }
                   6694: 
1.28      raeburn  6695: sub modify_contacts {
1.205     raeburn  6696:     my ($dom,$lastactref,%domconfig) = @_;
1.28      raeburn  6697:     my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
                   6698:     if (ref($domconfig{'contacts'}) eq 'HASH') {
                   6699:         foreach my $key (keys(%{$domconfig{'contacts'}})) {
                   6700:             $currsetting{$key} = $domconfig{'contacts'}{$key};
                   6701:         }
                   6702:     }
1.134     raeburn  6703:     my (%others,%to,%bcc);
1.28      raeburn  6704:     my @contacts = ('supportemail','adminemail');
1.102     raeburn  6705:     my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
1.203     raeburn  6706:                     'requestsmail','updatesmail','idconflictsmail');
                   6707:     my @toggles = ('reporterrors','reportupdates');
1.28      raeburn  6708:     foreach my $type (@mailings) {
                   6709:         @{$newsetting{$type}} = 
                   6710:             &Apache::loncommon::get_env_multiple('form.'.$type);
                   6711:         foreach my $item (@contacts) {
                   6712:             if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
                   6713:                 $contacts_hash{contacts}{$type}{$item} = 1;
                   6714:             } else {
                   6715:                 $contacts_hash{contacts}{$type}{$item} = 0;
                   6716:             }
                   6717:         }  
                   6718:         $others{$type} = $env{'form.'.$type.'_others'};
                   6719:         $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.134     raeburn  6720:         if ($type eq 'helpdeskmail') {
                   6721:             $bcc{$type} = $env{'form.'.$type.'_bcc'};
                   6722:             $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
                   6723:         }
1.28      raeburn  6724:     }
                   6725:     foreach my $item (@contacts) {
                   6726:         $to{$item} = $env{'form.'.$item};
                   6727:         $contacts_hash{'contacts'}{$item} = $to{$item};
                   6728:     }
1.203     raeburn  6729:     foreach my $item (@toggles) {
                   6730:         if ($env{'form.'.$item} =~ /^(0|1)$/) {
                   6731:             $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
                   6732:         }
                   6733:     }
1.28      raeburn  6734:     if (keys(%currsetting) > 0) {
                   6735:         foreach my $item (@contacts) {
                   6736:             if ($to{$item} ne $currsetting{$item}) {
                   6737:                 $changes{$item} = 1;
                   6738:             }
                   6739:         }
                   6740:         foreach my $type (@mailings) {
                   6741:             foreach my $item (@contacts) {
                   6742:                 if (ref($currsetting{$type}) eq 'HASH') {
                   6743:                     if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
                   6744:                         push(@{$changes{$type}},$item);
                   6745:                     }
                   6746:                 } else {
                   6747:                     push(@{$changes{$type}},@{$newsetting{$type}});
                   6748:                 }
                   6749:             }
                   6750:             if ($others{$type} ne $currsetting{$type}{'others'}) {
                   6751:                 push(@{$changes{$type}},'others');
                   6752:             }
1.134     raeburn  6753:             if ($type eq 'helpdeskmail') {   
                   6754:                 if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
                   6755:                     push(@{$changes{$type}},'bcc'); 
                   6756:                 }
                   6757:             }
1.28      raeburn  6758:         }
                   6759:     } else {
                   6760:         my %default;
                   6761:         $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
                   6762:         $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
                   6763:         $default{'errormail'} = 'adminemail';
                   6764:         $default{'packagesmail'} = 'adminemail';
                   6765:         $default{'helpdeskmail'} = 'supportemail';
1.89      raeburn  6766:         $default{'lonstatusmail'} = 'adminemail';
1.102     raeburn  6767:         $default{'requestsmail'} = 'adminemail';
1.190     raeburn  6768:         $default{'updatesmail'} = 'adminemail';
1.28      raeburn  6769:         foreach my $item (@contacts) {
                   6770:            if ($to{$item} ne $default{$item}) {
                   6771:               $changes{$item} = 1;
1.203     raeburn  6772:            }
1.28      raeburn  6773:         }
                   6774:         foreach my $type (@mailings) {
                   6775:             if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
                   6776:                
                   6777:                 push(@{$changes{$type}},@{$newsetting{$type}});
                   6778:             }
                   6779:             if ($others{$type} ne '') {
                   6780:                 push(@{$changes{$type}},'others');
1.134     raeburn  6781:             }
                   6782:             if ($type eq 'helpdeskmail') {
                   6783:                 if ($bcc{$type} ne '') {
                   6784:                     push(@{$changes{$type}},'bcc');
                   6785:                 }
                   6786:             }
1.28      raeburn  6787:         }
                   6788:     }
1.203     raeburn  6789:     foreach my $item (@toggles) {
                   6790:         if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
                   6791:             $changes{$item} = 1;
                   6792:         } elsif ((!$env{'form.'.$item}) &&
                   6793:                  (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
                   6794:             $changes{$item} = 1;
                   6795:         }
                   6796:     }
1.28      raeburn  6797:     my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
                   6798:                                              $dom);
                   6799:     if ($putresult eq 'ok') {
                   6800:         if (keys(%changes) > 0) {
1.205     raeburn  6801:             &Apache::loncommon::devalidate_domconfig_cache($dom);
                   6802:             $$lastactref = 'update';
1.28      raeburn  6803:             my ($titles,$short_titles)  = &contact_titles();
                   6804:             $resulttext = &mt('Changes made:').'<ul>';
                   6805:             foreach my $item (@contacts) {
                   6806:                 if ($changes{$item}) {
                   6807:                     $resulttext .= '<li>'.$titles->{$item}.
                   6808:                                     &mt(' set to: ').
                   6809:                                     '<span class="LC_cusr_emph">'.
                   6810:                                     $to{$item}.'</span></li>';
                   6811:                 }
                   6812:             }
                   6813:             foreach my $type (@mailings) {
                   6814:                 if (ref($changes{$type}) eq 'ARRAY') {
                   6815:                     $resulttext .= '<li>'.$titles->{$type}.': ';
                   6816:                     my @text;
                   6817:                     foreach my $item (@{$newsetting{$type}}) {
                   6818:                         push(@text,$short_titles->{$item});
                   6819:                     }
                   6820:                     if ($others{$type} ne '') {
                   6821:                         push(@text,$others{$type});
                   6822:                     }
                   6823:                     $resulttext .= '<span class="LC_cusr_emph">'.
1.134     raeburn  6824:                                    join(', ',@text).'</span>';
                   6825:                     if ($type eq 'helpdeskmail') {
                   6826:                         if ($bcc{$type} ne '') {
                   6827:                             $resulttext .= '&nbsp;'.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
                   6828:                         }
                   6829:                     }
                   6830:                     $resulttext .= '</li>';
1.28      raeburn  6831:                 }
                   6832:             }
1.203     raeburn  6833:             my @offon = ('off','on');
                   6834:             if ($changes{'reporterrors'}) {
                   6835:                 $resulttext .= '<li>'.
                   6836:                                &mt('E-mail error reports to [_1] set to "'.
                   6837:                                    $offon[$env{'form.reporterrors'}].'".',
                   6838:                                    &Apache::loncommon::modal_link('http://loncapa.org/core.html',
                   6839:                                        &mt('LON-CAPA core group - MSU'),600,500)).
                   6840:                                '</li>';
                   6841:             }
                   6842:             if ($changes{'reportupdates'}) {
                   6843:                 $resulttext .= '<li>'.
                   6844:                                 &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
                   6845:                                     $offon[$env{'form.reportupdates'}].'".',
                   6846:                                     &Apache::loncommon::modal_link('http://loncapa.org/core.html',
                   6847:                                         &mt('LON-CAPA core group - MSU'),600,500)).
                   6848:                                 '</li>';
                   6849:             }
1.28      raeburn  6850:             $resulttext .= '</ul>';
                   6851:         } else {
1.34      raeburn  6852:             $resulttext = &mt('No changes made to contact information');
1.28      raeburn  6853:         }
                   6854:     } else {
                   6855:         $resulttext = '<span class="LC_error">'.
                   6856:             &mt('An error occurred: [_1].',$putresult).'</span>';
                   6857:     }
                   6858:     return $resulttext;
                   6859: }
                   6860: 
                   6861: sub modify_usercreation {
1.27      raeburn  6862:     my ($dom,%domconfig) = @_;
1.34      raeburn  6863:     my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate);
1.43      raeburn  6864:     my $warningmsg;
1.27      raeburn  6865:     if (ref($domconfig{'usercreation'}) eq 'HASH') {
                   6866:         foreach my $key (keys(%{$domconfig{'usercreation'}})) {
                   6867:             $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
                   6868:         }
                   6869:     }
                   6870:     my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32      raeburn  6871:     my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.43      raeburn  6872:     my @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
1.100     raeburn  6873:     my @contexts = ('author','course','requestcrs','selfcreate');
1.34      raeburn  6874:     foreach my $item(@contexts) {
1.45      raeburn  6875:         if ($item eq 'selfcreate') {
1.50      raeburn  6876:             @{$cancreate{$item}} = &Apache::loncommon::get_env_multiple('form.can_createuser_'.$item);
1.43      raeburn  6877:             my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
                   6878:             if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) || ($domdefaults{'auth_def'} eq 'localauth'))) {
1.50      raeburn  6879:                 if (ref($cancreate{$item}) eq 'ARRAY') { 
                   6880:                     if (grep(/^login$/,@{$cancreate{$item}})) {
                   6881:                         $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.');   
                   6882:                     }
1.43      raeburn  6883:                 }
                   6884:             }
1.50      raeburn  6885:         } else {
                   6886:             $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.43      raeburn  6887:         }
1.34      raeburn  6888:     }
1.93      raeburn  6889:     my ($othertitle,$usertypes,$types) = 
                   6890:         &Apache::loncommon::sorted_inst_types($dom);
                   6891:     if (ref($types) eq 'ARRAY') {
                   6892:         if (@{$types} > 0) {
                   6893:             @{$cancreate{'statustocreate'}} = 
                   6894:                 &Apache::loncommon::get_env_multiple('form.statustocreate');
1.103     raeburn  6895:         } else {
                   6896:             @{$cancreate{'statustocreate'}} = ();
1.93      raeburn  6897:         }
                   6898:         push(@contexts,'statustocreate');
                   6899:     }
1.165     raeburn  6900:     &process_captcha('cancreate',\%changes,\%cancreate,\%curr_usercreation);
1.34      raeburn  6901:     if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
                   6902:         foreach my $item (@contexts) {
1.93      raeburn  6903:             if (($item eq 'selfcreate') || ($item eq 'statustocreate')) {
                   6904:                 if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
1.50      raeburn  6905:                     foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
1.103     raeburn  6906:                         if (ref($cancreate{$item}) eq 'ARRAY') {
                   6907:                             if (!grep(/^$curr$/,@{$cancreate{$item}})) {
                   6908:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   6909:                                     push(@{$changes{'cancreate'}},$item);
                   6910:                                 }
1.50      raeburn  6911:                             }
                   6912:                         }
                   6913:                     }
                   6914:                 } else {
                   6915:                     if ($curr_usercreation{'cancreate'}{$item} eq '') {
                   6916:                         if (@{$cancreate{$item}} > 0) {
                   6917:                             if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   6918:                                 push(@{$changes{'cancreate'}},$item);
                   6919:                             }
                   6920:                         }
                   6921:                     } else {
                   6922:                         if ($curr_usercreation{'cancreate'}{$item} eq 'any') {
                   6923:                             if (@{$cancreate{$item}} < 3) {
                   6924:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   6925:                                     push(@{$changes{'cancreate'}},$item);
                   6926:                                 }
                   6927:                             }
                   6928:                         } elsif ($curr_usercreation{'cancreate'}{$item} eq 'none') {
                   6929:                             if (@{$cancreate{$item}} > 0) {
                   6930:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   6931:                                     push(@{$changes{'cancreate'}},$item);
                   6932:                                 }
                   6933:                             }
                   6934:                         } elsif (!grep(/^$curr_usercreation{'cancreate'}{$item}$/,@{$cancreate{$item}})) {
                   6935:                             if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   6936:                                 push(@{$changes{'cancreate'}},$item);
                   6937:                             }
                   6938:                         }
                   6939:                     }
                   6940:                 }
                   6941:                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   6942:                     foreach my $type (@{$cancreate{$item}}) {
                   6943:                         if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
                   6944:                             if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
                   6945:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   6946:                                     push(@{$changes{'cancreate'}},$item);
                   6947:                                 }
                   6948:                             }
                   6949:                         } elsif (($curr_usercreation{'cancreate'}{$item} ne 'any') &&
                   6950:                                  ($curr_usercreation{'cancreate'}{$item} ne 'none')) {
                   6951:                             if ($curr_usercreation{'cancreate'}{$item} ne $type) {
                   6952:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   6953:                                     push(@{$changes{'cancreate'}},$item);
                   6954:                                 }
                   6955:                             }
                   6956:                         }
                   6957:                     }
                   6958:                 }
                   6959:             } else {
                   6960:                 if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
                   6961:                     push(@{$changes{'cancreate'}},$item);
                   6962:                 }
                   6963:             }
1.27      raeburn  6964:         }
1.34      raeburn  6965:     } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
                   6966:         foreach my $item (@contexts) {
1.43      raeburn  6967:             if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34      raeburn  6968:                 if ($cancreate{$item} ne 'any') {
                   6969:                     push(@{$changes{'cancreate'}},$item);
                   6970:                 }
                   6971:             } else {
                   6972:                 if ($cancreate{$item} ne 'none') {
                   6973:                     push(@{$changes{'cancreate'}},$item);
                   6974:                 }
1.27      raeburn  6975:             }
                   6976:         }
                   6977:     } else {
1.43      raeburn  6978:         foreach my $item (@contexts)  {
1.34      raeburn  6979:             push(@{$changes{'cancreate'}},$item);
                   6980:         }
1.27      raeburn  6981:     }
1.34      raeburn  6982: 
1.27      raeburn  6983:     if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
                   6984:         foreach my $type (@{$curr_usercreation{'username_rule'}}) {
                   6985:             if (!grep(/^\Q$type\E$/,@username_rule)) {
                   6986:                 push(@{$changes{'username_rule'}},$type);
                   6987:             }
                   6988:         }
                   6989:         foreach my $type (@username_rule) {
                   6990:             if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
                   6991:                 push(@{$changes{'username_rule'}},$type);
                   6992:             }
                   6993:         }
                   6994:     } else {
                   6995:         push(@{$changes{'username_rule'}},@username_rule);
                   6996:     }
                   6997: 
1.32      raeburn  6998:     if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
                   6999:         foreach my $type (@{$curr_usercreation{'id_rule'}}) {
                   7000:             if (!grep(/^\Q$type\E$/,@id_rule)) {
                   7001:                 push(@{$changes{'id_rule'}},$type);
                   7002:             }
                   7003:         }
                   7004:         foreach my $type (@id_rule) {
                   7005:             if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
                   7006:                 push(@{$changes{'id_rule'}},$type);
                   7007:             }
                   7008:         }
                   7009:     } else {
                   7010:         push(@{$changes{'id_rule'}},@id_rule);
                   7011:     }
                   7012: 
1.43      raeburn  7013:     if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
                   7014:         foreach my $type (@{$curr_usercreation{'email_rule'}}) {
                   7015:             if (!grep(/^\Q$type\E$/,@email_rule)) {
                   7016:                 push(@{$changes{'email_rule'}},$type);
                   7017:             }
                   7018:         }
                   7019:         foreach my $type (@email_rule) {
                   7020:             if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
                   7021:                 push(@{$changes{'email_rule'}},$type);
                   7022:             }
                   7023:         }
                   7024:     } else {
                   7025:         push(@{$changes{'email_rule'}},@email_rule);
                   7026:     }
                   7027: 
                   7028:     my @authen_contexts = ('author','course','domain');
1.28      raeburn  7029:     my @authtypes = ('int','krb4','krb5','loc');
                   7030:     my %authhash;
1.43      raeburn  7031:     foreach my $item (@authen_contexts) {
1.28      raeburn  7032:         my @authallowed =  &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
                   7033:         foreach my $auth (@authtypes) {
                   7034:             if (grep(/^\Q$auth\E$/,@authallowed)) {
                   7035:                 $authhash{$item}{$auth} = 1;
                   7036:             } else {
                   7037:                 $authhash{$item}{$auth} = 0;
                   7038:             }
                   7039:         }
                   7040:     }
                   7041:     if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43      raeburn  7042:         foreach my $item (@authen_contexts) {
1.28      raeburn  7043:             if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
                   7044:                 foreach my $auth (@authtypes) {
                   7045:                     if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
                   7046:                         push(@{$changes{'authtypes'}},$item);
                   7047:                         last;
                   7048:                     }
                   7049:                 }
                   7050:             }
                   7051:         }
                   7052:     } else {
1.43      raeburn  7053:         foreach my $item (@authen_contexts) {
1.28      raeburn  7054:             push(@{$changes{'authtypes'}},$item);
                   7055:         }
                   7056:     }
                   7057: 
1.27      raeburn  7058:     my %usercreation_hash =  (
1.28      raeburn  7059:             usercreation => {
1.34      raeburn  7060:                               cancreate     => \%cancreate,
1.27      raeburn  7061:                               username_rule => \@username_rule,
1.32      raeburn  7062:                               id_rule       => \@id_rule,
1.43      raeburn  7063:                               email_rule    => \@email_rule,
1.32      raeburn  7064:                               authtypes     => \%authhash,
1.27      raeburn  7065:                             }
                   7066:             );
                   7067: 
                   7068:     my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
                   7069:                                              $dom);
1.50      raeburn  7070: 
                   7071:     my %selfcreatetypes = (
                   7072:                              sso   => 'users authenticated by institutional single sign on',
                   7073:                              login => 'users authenticated by institutional log-in',
                   7074:                              email => 'users who provide a valid e-mail address for use as the username',
                   7075:                           );
1.27      raeburn  7076:     if ($putresult eq 'ok') {
                   7077:         if (keys(%changes) > 0) {
                   7078:             $resulttext = &mt('Changes made:').'<ul>';
                   7079:             if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.34      raeburn  7080:                 my %lt = &usercreation_types();
                   7081:                 foreach my $type (@{$changes{'cancreate'}}) {
1.100     raeburn  7082:                     my $chgtext;
1.165     raeburn  7083:                     unless (($type eq 'statustocreate') || ($type eq 'captcha') || ($type eq 'recaptchakeys')) {
1.100     raeburn  7084:                         $chgtext = $lt{$type}.', ';
                   7085:                     }
1.45      raeburn  7086:                     if ($type eq 'selfcreate') {
1.50      raeburn  7087:                         if (@{$cancreate{$type}} == 0) {
1.43      raeburn  7088:                             $chgtext .= &mt('creation of a new user account is not permitted.');
1.50      raeburn  7089:                         } else {
1.100     raeburn  7090:                             $chgtext .= &mt('creation of a new account is permitted for:').'<ul>';
1.50      raeburn  7091:                             foreach my $case (@{$cancreate{$type}}) {
                   7092:                                 $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
                   7093:                             }
                   7094:                             $chgtext .= '</ul>';
1.100     raeburn  7095:                             if (ref($cancreate{$type}) eq 'ARRAY') {
                   7096:                                 if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
                   7097:                                     if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
                   7098:                                         if (@{$cancreate{'statustocreate'}} == 0) {
                   7099:                                             $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
                   7100:                                         }
                   7101:                                     }
                   7102:                                 }
                   7103:                             }
1.43      raeburn  7104:                         }
1.93      raeburn  7105:                     } elsif ($type eq 'statustocreate') {
1.96      raeburn  7106:                         if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
                   7107:                             (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
                   7108:                             if (@{$cancreate{'selfcreate'}} > 0) {
                   7109:                                 if (@{$cancreate{'statustocreate'}} == 0) {
1.100     raeburn  7110: 
                   7111:                                     $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96      raeburn  7112:                                     if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.100     raeburn  7113:                                         $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
                   7114:                                     } 
1.96      raeburn  7115:                                 } elsif (ref($usertypes) eq 'HASH') {
                   7116:                                     if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100     raeburn  7117:                                         $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
                   7118:                                     } else {
                   7119:                                         $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
                   7120:                                     }
                   7121:                                     $chgtext .= '<ul>';
                   7122:                                     foreach my $case (@{$cancreate{$type}}) {
                   7123:                                         if ($case eq 'default') {
                   7124:                                             $chgtext .= '<li>'.$othertitle.'</li>';
                   7125:                                         } else {
                   7126:                                             $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93      raeburn  7127:                                         }
                   7128:                                     }
1.100     raeburn  7129:                                     $chgtext .= '</ul>';
                   7130:                                     if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
                   7131:                                         $chgtext .= '<br /><span class="LC_warning">'.&mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').'</span>';
                   7132:                                     }
                   7133:                                 }
                   7134:                             } else {
                   7135:                                 if (@{$cancreate{$type}} == 0) {
                   7136:                                     $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
                   7137:                                 } else {
                   7138:                                     $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  7139:                                 }
                   7140:                             }
                   7141:                         }
1.165     raeburn  7142:                     } elsif ($type eq 'captcha') {
                   7143:                         if ($cancreate{$type} eq 'notused') {
                   7144:                             $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
                   7145:                         } else {
                   7146:                             my %captchas = &captcha_phrases();
                   7147:                             if ($captchas{$cancreate{$type}}) {
                   7148:                                 $chgtext .= &mt("Validation for self-creation screen set to $captchas{$cancreate{$type}}.");
                   7149:                             } else {
1.210     raeburn  7150:                                 $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165     raeburn  7151:                             }
                   7152:                         }
                   7153:                     } elsif ($type eq 'recaptchakeys') {
                   7154:                         my ($privkey,$pubkey);
                   7155:                         if (ref($cancreate{$type}) eq 'HASH') {
                   7156:                             $pubkey = $cancreate{$type}{'public'};
                   7157:                             $privkey = $cancreate{$type}{'private'};
                   7158:                         }
                   7159:                         $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
                   7160:                         if (!$pubkey) {
                   7161:                             $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
                   7162:                         } else {
                   7163:                             $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
                   7164:                         }
                   7165:                         if (!$privkey) {
                   7166:                             $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
                   7167:                         } else {
                   7168:                             $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
                   7169:                         }
                   7170:                         $chgtext .= '</ul>';
1.43      raeburn  7171:                     } else {
                   7172:                         if ($cancreate{$type} eq 'none') {
                   7173:                             $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
                   7174:                         } elsif ($cancreate{$type} eq 'any') {
                   7175:                             $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
                   7176:                         } elsif ($cancreate{$type} eq 'official') {
                   7177:                             $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
                   7178:                         } elsif ($cancreate{$type} eq 'unofficial') {
                   7179:                             $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
                   7180:                         }
1.34      raeburn  7181:                     }
                   7182:                     $resulttext .= '<li>'.$chgtext.'</li>';
1.27      raeburn  7183:                 }
                   7184:             }
                   7185:             if (ref($changes{'username_rule'}) eq 'ARRAY') {
1.32      raeburn  7186:                 my ($rules,$ruleorder) = 
                   7187:                     &Apache::lonnet::inst_userrules($dom,'username');
1.27      raeburn  7188:                 my $chgtext = '<ul>';
                   7189:                 foreach my $type (@username_rule) {
                   7190:                     if (ref($rules->{$type}) eq 'HASH') {
                   7191:                         $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
                   7192:                     }
                   7193:                 }
                   7194:                 $chgtext .= '</ul>';
                   7195:                 if (@username_rule > 0) {
                   7196:                     $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';     
                   7197:                 } else {
1.28      raeburn  7198:                     $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>'; 
1.27      raeburn  7199:                 }
                   7200:             }
1.32      raeburn  7201:             if (ref($changes{'id_rule'}) eq 'ARRAY') {
                   7202:                 my ($idrules,$idruleorder) = 
                   7203:                     &Apache::lonnet::inst_userrules($dom,'id');
                   7204:                 my $chgtext = '<ul>';
                   7205:                 foreach my $type (@id_rule) {
                   7206:                     if (ref($idrules->{$type}) eq 'HASH') {
                   7207:                         $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
                   7208:                     }
                   7209:                 }
                   7210:                 $chgtext .= '</ul>';
                   7211:                 if (@id_rule > 0) {
                   7212:                     $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
                   7213:                 } else {
                   7214:                     $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
                   7215:                 }
                   7216:             }
1.43      raeburn  7217:             if (ref($changes{'email_rule'}) eq 'ARRAY') {
                   7218:                 my ($emailrules,$emailruleorder) =
                   7219:                     &Apache::lonnet::inst_userrules($dom,'email');
                   7220:                 my $chgtext = '<ul>';
                   7221:                 foreach my $type (@email_rule) {
                   7222:                     if (ref($emailrules->{$type}) eq 'HASH') {
                   7223:                         $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
                   7224:                     }
                   7225:                 }
                   7226:                 $chgtext .= '</ul>';
                   7227:                 if (@email_rule > 0) {
                   7228:                     $resulttext .= '<li>'.&mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').$chgtext.'</li>';
                   7229:                 } else {
                   7230:                     $resulttext .= '<li>'.&mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').'</li>';
                   7231:                 }
                   7232:             }
                   7233: 
1.28      raeburn  7234:             my %authname = &authtype_names();
                   7235:             my %context_title = &context_names();
                   7236:             if (ref($changes{'authtypes'}) eq 'ARRAY') {
                   7237:                 my $chgtext = '<ul>';
                   7238:                 foreach my $type (@{$changes{'authtypes'}}) {
                   7239:                     my @allowed;
                   7240:                     $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
                   7241:                     foreach my $auth (@authtypes) {
                   7242:                         if ($authhash{$type}{$auth}) {
                   7243:                             push(@allowed,$authname{$auth});
                   7244:                         }
                   7245:                     }
1.43      raeburn  7246:                     if (@allowed > 0) {
                   7247:                         $chgtext .= join(', ',@allowed).'</li>';
                   7248:                     } else {
                   7249:                         $chgtext .= &mt('none').'</li>';
                   7250:                     }
1.28      raeburn  7251:                 }
                   7252:                 $chgtext .= '</ul>';
                   7253:                 $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
                   7254:                 $resulttext .= '</li>';
                   7255:             }
1.27      raeburn  7256:             $resulttext .= '</ul>';
                   7257:         } else {
1.28      raeburn  7258:             $resulttext = &mt('No changes made to user creation settings');
1.27      raeburn  7259:         }
                   7260:     } else {
                   7261:         $resulttext = '<span class="LC_error">'.
1.23      raeburn  7262:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   7263:     }
1.43      raeburn  7264:     if ($warningmsg ne '') {
                   7265:         $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
                   7266:     }
1.23      raeburn  7267:     return $resulttext;
                   7268: }
                   7269: 
1.165     raeburn  7270: sub process_captcha {
                   7271:     my ($container,$changes,$newsettings,$current) = @_;
                   7272:     return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
                   7273:     $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
                   7274:     unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
                   7275:         $newsettings->{'captcha'} = 'original';
                   7276:     }
                   7277:     if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
1.210     raeburn  7278:         if ($container eq 'cancreate') {
1.169     raeburn  7279:             if (ref($changes->{'cancreate'}) eq 'ARRAY') {
                   7280:                 push(@{$changes->{'cancreate'}},'captcha');
                   7281:             } elsif (!defined($changes->{'cancreate'})) {
                   7282:                 $changes->{'cancreate'} = ['captcha'];
                   7283:             }
                   7284:         } else {
                   7285:             $changes->{'captcha'} = 1;
1.165     raeburn  7286:         }
                   7287:     }
                   7288:     my ($newpub,$newpriv,$currpub,$currpriv);
                   7289:     if ($newsettings->{'captcha'} eq 'recaptcha') {
                   7290:         $newpub = $env{'form.'.$container.'_recaptchapub'};
                   7291:         $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.169     raeburn  7292:         $newpub =~ s/\W//g;
                   7293:         $newpriv =~ s/\W//g;
                   7294:         $newsettings->{'recaptchakeys'} = {
                   7295:                                              public  => $newpub,
                   7296:                                              private => $newpriv,
                   7297:                                           };
1.165     raeburn  7298:     }
                   7299:     if (ref($current->{'recaptchakeys'}) eq 'HASH') {
                   7300:         $currpub = $current->{'recaptchakeys'}{'public'};
                   7301:         $currpriv = $current->{'recaptchakeys'}{'private'};
1.179     raeburn  7302:         unless ($newsettings->{'captcha'} eq 'recaptcha') {
                   7303:             $newsettings->{'recaptchakeys'} = {
                   7304:                                                  public  => '',
                   7305:                                                  private => '',
                   7306:                                               }
                   7307:         }
1.165     raeburn  7308:     }
                   7309:     if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169     raeburn  7310:         if ($container eq 'cancreate') {
                   7311:             if (ref($changes->{'cancreate'}) eq 'ARRAY') {
                   7312:                 push(@{$changes->{'cancreate'}},'recaptchakeys');
                   7313:             } elsif (!defined($changes->{'cancreate'})) {
                   7314:                 $changes->{'cancreate'} = ['recaptchakeys'];
                   7315:             }
                   7316:         } else {
1.210     raeburn  7317:             $changes->{'recaptchakeys'} = 1;
1.165     raeburn  7318:         }
                   7319:     }
                   7320:     return;
                   7321: }
                   7322: 
1.33      raeburn  7323: sub modify_usermodification {
                   7324:     my ($dom,%domconfig) = @_;
                   7325:     my ($resulttext,%curr_usermodification,%changes);
                   7326:     if (ref($domconfig{'usermodification'}) eq 'HASH') {
                   7327:         foreach my $key (keys(%{$domconfig{'usermodification'}})) {
                   7328:             $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
                   7329:         }
                   7330:     }
1.63      raeburn  7331:     my @contexts = ('author','course','selfcreate');
1.33      raeburn  7332:     my %context_title = (
                   7333:                            author => 'In author context',
                   7334:                            course => 'In course context',
1.63      raeburn  7335:                            selfcreate => 'When self creating account', 
1.33      raeburn  7336:                         );
                   7337:     my @fields = ('lastname','firstname','middlename','generation',
                   7338:                   'permanentemail','id');
                   7339:     my %roles = (
                   7340:                   author => ['ca','aa'],
                   7341:                   course => ['st','ep','ta','in','cr'],
                   7342:                 );
1.63      raeburn  7343:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   7344:     if (ref($types) eq 'ARRAY') {
                   7345:         push(@{$types},'default');
                   7346:         $usertypes->{'default'} = $othertitle;
                   7347:     }
                   7348:     $roles{'selfcreate'} = $types;  
1.33      raeburn  7349:     my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
                   7350:     my %modifyhash;
                   7351:     foreach my $context (@contexts) {
                   7352:         foreach my $role (@{$roles{$context}}) {
                   7353:             my @modifiable =  &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
                   7354:             foreach my $item (@fields) {
                   7355:                 if (grep(/^\Q$item\E$/,@modifiable)) {
                   7356:                     $modifyhash{$context}{$role}{$item} = 1;
                   7357:                 } else {
                   7358:                     $modifyhash{$context}{$role}{$item} = 0;
                   7359:                 }
                   7360:             }
                   7361:         }
                   7362:         if (ref($curr_usermodification{$context}) eq 'HASH') {
                   7363:             foreach my $role (@{$roles{$context}}) {
                   7364:                 if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
                   7365:                     foreach my $field (@fields) {
                   7366:                         if ($modifyhash{$context}{$role}{$field} ne 
                   7367:                                 $curr_usermodification{$context}{$role}{$field}) {
                   7368:                             push(@{$changes{$context}},$role);
                   7369:                             last;
                   7370:                         }
                   7371:                     }
                   7372:                 }
                   7373:             }
                   7374:         } else {
                   7375:             foreach my $context (@contexts) {
                   7376:                 foreach my $role (@{$roles{$context}}) {
                   7377:                     push(@{$changes{$context}},$role);
                   7378:                 }
                   7379:             }
                   7380:         }
                   7381:     }
                   7382:     my %usermodification_hash =  (
                   7383:                                    usermodification => \%modifyhash,
                   7384:                                  );
                   7385:     my $putresult = &Apache::lonnet::put_dom('configuration',
                   7386:                                              \%usermodification_hash,$dom);
                   7387:     if ($putresult eq 'ok') {
                   7388:         if (keys(%changes) > 0) {
                   7389:             $resulttext = &mt('Changes made: ').'<ul>';
                   7390:             foreach my $context (@contexts) {
                   7391:                 if (ref($changes{$context}) eq 'ARRAY') {
                   7392:                     $resulttext .= '<li>'.$context_title{$context}.':<ul>';
                   7393:                     if (ref($changes{$context}) eq 'ARRAY') {
                   7394:                         foreach my $role (@{$changes{$context}}) {
                   7395:                             my $rolename;
1.63      raeburn  7396:                             if ($context eq 'selfcreate') {
                   7397:                                 $rolename = $role;
                   7398:                                 if (ref($usertypes) eq 'HASH') {
                   7399:                                     if ($usertypes->{$role} ne '') {
                   7400:                                         $rolename = $usertypes->{$role};
                   7401:                                     }
                   7402:                                 }
1.33      raeburn  7403:                             } else {
1.63      raeburn  7404:                                 if ($role eq 'cr') {
                   7405:                                     $rolename = &mt('Custom');
                   7406:                                 } else {
                   7407:                                     $rolename = &Apache::lonnet::plaintext($role);
                   7408:                                 }
1.33      raeburn  7409:                             }
                   7410:                             my @modifiable;
1.63      raeburn  7411:                             if ($context eq 'selfcreate') {
1.126     bisitz   7412:                                 $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  7413:                             } else {
                   7414:                                 $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
                   7415:                             }
1.33      raeburn  7416:                             foreach my $field (@fields) {
                   7417:                                 if ($modifyhash{$context}{$role}{$field}) {
                   7418:                                     push(@modifiable,$fieldtitles{$field});
                   7419:                                 }
                   7420:                             }
                   7421:                             if (@modifiable > 0) {
                   7422:                                 $resulttext .= join(', ',@modifiable);
                   7423:                             } else {
                   7424:                                 $resulttext .= &mt('none'); 
                   7425:                             }
                   7426:                             $resulttext .= '</li>';
                   7427:                         }
                   7428:                         $resulttext .= '</ul></li>';
                   7429:                     }
                   7430:                 }
                   7431:             }
                   7432:             $resulttext .= '</ul>';
                   7433:         } else {
                   7434:             $resulttext = &mt('No changes made to user modification settings');
                   7435:         }
                   7436:     } else {
                   7437:         $resulttext = '<span class="LC_error">'.
                   7438:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   7439:     }
                   7440:     return $resulttext;
                   7441: }
                   7442: 
1.43      raeburn  7443: sub modify_defaults {
1.203     raeburn  7444:     my ($dom,$r,%domconfig) = @_;
1.43      raeburn  7445:     my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
                   7446:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.141     raeburn  7447:     my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
1.43      raeburn  7448:     my @authtypes = ('internal','krb4','krb5','localauth');
                   7449:     foreach my $item (@items) {
                   7450:         $newvalues{$item} = $env{'form.'.$item};
                   7451:         if ($item eq 'auth_def') {
                   7452:             if ($newvalues{$item} ne '') {
                   7453:                 if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
                   7454:                     push(@errors,$item);
                   7455:                 }
                   7456:             }
                   7457:         } elsif ($item eq 'lang_def') {
                   7458:             if ($newvalues{$item} ne '') {
                   7459:                 if ($newvalues{$item} =~ /^(\w+)/) {
                   7460:                     my $langcode = $1;
1.103     raeburn  7461:                     if ($langcode ne 'x_chef') {
                   7462:                         if (code2language($langcode) eq '') {
                   7463:                             push(@errors,$item);
                   7464:                         }
1.43      raeburn  7465:                     }
                   7466:                 } else {
                   7467:                     push(@errors,$item);
                   7468:                 }
                   7469:             }
1.54      raeburn  7470:         } elsif ($item eq 'timezone_def') {
                   7471:             if ($newvalues{$item} ne '') {
1.62      raeburn  7472:                 if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54      raeburn  7473:                     push(@errors,$item);   
                   7474:                 }
                   7475:             }
1.68      raeburn  7476:         } elsif ($item eq 'datelocale_def') {
                   7477:             if ($newvalues{$item} ne '') {
                   7478:                 my @datelocale_ids = DateTime::Locale->ids();
                   7479:                 if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
                   7480:                     push(@errors,$item);
                   7481:                 }
                   7482:             }
1.141     raeburn  7483:         } elsif ($item eq 'portal_def') {
                   7484:             if ($newvalues{$item} ne '') {
                   7485:                 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])\/?$/) {
                   7486:                     push(@errors,$item);
                   7487:                 }
                   7488:             }
1.43      raeburn  7489:         }
                   7490:         if (grep(/^\Q$item\E$/,@errors)) {
                   7491:             $newvalues{$item} = $domdefaults{$item};
                   7492:         } elsif ($domdefaults{$item} ne $newvalues{$item}) {
                   7493:             $changes{$item} = 1;
                   7494:         }
1.72      raeburn  7495:         $domdefaults{$item} = $newvalues{$item};
1.43      raeburn  7496:     }
                   7497:     my %defaults_hash = (
1.72      raeburn  7498:                          defaults => \%newvalues,
                   7499:                         );
1.43      raeburn  7500:     my $title = &defaults_titles();
                   7501:     my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
                   7502:                                              $dom);
                   7503:     if ($putresult eq 'ok') {
                   7504:         if (keys(%changes) > 0) {
                   7505:             $resulttext = &mt('Changes made:').'<ul>';
                   7506:             my $version = $r->dir_config('lonVersion');
                   7507:             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";
                   7508:             foreach my $item (sort(keys(%changes))) {
                   7509:                 my $value = $env{'form.'.$item};
                   7510:                 if ($value eq '') {
                   7511:                     $value = &mt('none');
                   7512:                 } elsif ($item eq 'auth_def') {
                   7513:                     my %authnames = &authtype_names();
                   7514:                     my %shortauth = (
                   7515:                              internal => 'int',
                   7516:                              krb4 => 'krb4',
                   7517:                              krb5 => 'krb5',
                   7518:                              localauth  => 'loc',
                   7519:                     );
                   7520:                     $value = $authnames{$shortauth{$value}};
                   7521:                 }
                   7522:                 $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
                   7523:                 $mailmsgtext .= "$title->{$item} set to $value\n";  
                   7524:             }
                   7525:             $resulttext .= '</ul>';
                   7526:             $mailmsgtext .= "\n";
                   7527:             my $cachetime = 24*60*60;
1.72      raeburn  7528:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.68      raeburn  7529:             if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203     raeburn  7530:                 my $notify = 1;
                   7531:                 if (ref($domconfig{'contacts'}) eq 'HASH') {
                   7532:                     if ($domconfig{'contacts'}{'reportupdates'} == 0) {
                   7533:                         $notify = 0;
                   7534:                     }
                   7535:                 }
                   7536:                 if ($notify) {
                   7537:                     &Apache::lonmsg::sendemail('installrecord@loncapa.org',
                   7538:                                                "LON-CAPA Domain Settings Change - $dom",
                   7539:                                                $mailmsgtext);
                   7540:                 }
1.54      raeburn  7541:             }
1.43      raeburn  7542:         } else {
1.54      raeburn  7543:             $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43      raeburn  7544:         }
                   7545:     } else {
                   7546:         $resulttext = '<span class="LC_error">'.
                   7547:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   7548:     }
                   7549:     if (@errors > 0) {
                   7550:         $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
                   7551:         foreach my $item (@errors) {
                   7552:             $resulttext .= ' "'.$title->{$item}.'",';
                   7553:         }
                   7554:         $resulttext =~ s/,$//;
                   7555:     }
                   7556:     return $resulttext;
                   7557: }
                   7558: 
1.46      raeburn  7559: sub modify_scantron {
1.205     raeburn  7560:     my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46      raeburn  7561:     my ($resulttext,%confhash,%changes,$errors);
                   7562:     my $custom = 'custom.tab';
                   7563:     my $default = 'default.tab';
                   7564:     my $servadm = $r->dir_config('lonAdmEMail');
                   7565:     my ($configuserok,$author_ok,$switchserver) = 
                   7566:         &config_check($dom,$confname,$servadm);
                   7567:     if ($env{'form.scantronformat.filename'} ne '') {
                   7568:         my $error;
                   7569:         if ($configuserok eq 'ok') {
                   7570:             if ($switchserver) {
1.130     raeburn  7571:                 $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46      raeburn  7572:             } else {
                   7573:                 if ($author_ok eq 'ok') {
                   7574:                     my ($result,$scantronurl) =
                   7575:                         &publishlogo($r,'upload','scantronformat',$dom,
                   7576:                                      $confname,'scantron','','',$custom);
                   7577:                     if ($result eq 'ok') {
                   7578:                         $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48      raeburn  7579:                         $changes{'scantronformat'} = 1;
1.46      raeburn  7580:                     } else {
                   7581:                         $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
                   7582:                     }
                   7583:                 } else {
                   7584:                     $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);
                   7585:                 }
                   7586:             }
                   7587:         } else {
                   7588:             $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);
                   7589:         }
                   7590:         if ($error) {
                   7591:             &Apache::lonnet::logthis($error);
                   7592:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   7593:         }
                   7594:     }
1.48      raeburn  7595:     if (ref($domconfig{'scantron'}) eq 'HASH') {
                   7596:         if ($domconfig{'scantron'}{'scantronformat'} ne '') {
                   7597:             if ($env{'form.scantronformat_del'}) {
                   7598:                 $confhash{'scantron'}{'scantronformat'} = '';
                   7599:                 $changes{'scantronformat'} = 1;
1.46      raeburn  7600:             }
                   7601:         }
                   7602:     }
                   7603:     if (keys(%confhash) > 0) {
                   7604:         my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
                   7605:                                                  $dom);
                   7606:         if ($putresult eq 'ok') {
                   7607:             if (keys(%changes) > 0) {
1.48      raeburn  7608:                 if (ref($confhash{'scantron'}) eq 'HASH') {
                   7609:                     $resulttext = &mt('Changes made:').'<ul>';
                   7610:                     if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130     raeburn  7611:                         $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48      raeburn  7612:                     } else {
1.130     raeburn  7613:                         $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46      raeburn  7614:                     }
1.48      raeburn  7615:                     $resulttext .= '</ul>';
                   7616:                 } else {
1.130     raeburn  7617:                     $resulttext = &mt('Changes made to bubblesheet format file.');
1.46      raeburn  7618:                 }
                   7619:                 $resulttext .= '</ul>';
                   7620:                 &Apache::loncommon::devalidate_domconfig_cache($dom);
1.206     raeburn  7621:                 $$lastactref = 'update';
1.46      raeburn  7622:             } else {
1.130     raeburn  7623:                 $resulttext = &mt('No changes made to bubblesheet format file');
1.46      raeburn  7624:             }
                   7625:         } else {
                   7626:             $resulttext = '<span class="LC_error">'.
                   7627:                 &mt('An error occurred: [_1]',$putresult).'</span>';
                   7628:         }
                   7629:     } else {
1.130     raeburn  7630:         $resulttext = &mt('No changes made to bubblesheet format file'); 
1.46      raeburn  7631:     }
                   7632:     if ($errors) {
                   7633:         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
                   7634:                        $errors.'</ul>';
                   7635:     }
                   7636:     return $resulttext;
                   7637: }
                   7638: 
1.48      raeburn  7639: sub modify_coursecategories {
                   7640:     my ($dom,%domconfig) = @_;
1.57      raeburn  7641:     my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
                   7642:         $cathash);
1.48      raeburn  7643:     my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.55      raeburn  7644:     if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57      raeburn  7645:         $cathash = $domconfig{'coursecategories'}{'cats'};
                   7646:         if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
                   7647:             $changes{'togglecats'} = 1;
                   7648:             $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
                   7649:         }
                   7650:         if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
                   7651:             $changes{'categorize'} = 1;
                   7652:             $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
                   7653:         }
1.120     raeburn  7654:         if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
                   7655:             $changes{'togglecatscomm'} = 1;
                   7656:             $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
                   7657:         }
                   7658:         if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
                   7659:             $changes{'categorizecomm'} = 1;
                   7660:             $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
                   7661:         }
1.57      raeburn  7662:     } else {
                   7663:         $changes{'togglecats'} = 1;
                   7664:         $changes{'categorize'} = 1;
1.124     raeburn  7665:         $changes{'togglecatscomm'} = 1;
                   7666:         $changes{'categorizecomm'} = 1;
1.87      raeburn  7667:         $domconfig{'coursecategories'} = {
                   7668:                                              togglecats => $env{'form.togglecats'},
                   7669:                                              categorize => $env{'form.categorize'},
1.124     raeburn  7670:                                              togglecatscomm => $env{'form.togglecatscomm'},
                   7671:                                              categorizecomm => $env{'form.categorizecomm'},
1.120     raeburn  7672:                                          };
1.57      raeburn  7673:     }
                   7674:     if (ref($cathash) eq 'HASH') {
                   7675:         if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '')  && ($env{'form.instcode'} == 0)) {
1.55      raeburn  7676:             push (@deletecategory,'instcode::0');
                   7677:         }
1.120     raeburn  7678:         if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '')  && ($env{'form.communities'} == 0)) {
                   7679:             push(@deletecategory,'communities::0');
                   7680:         }
1.48      raeburn  7681:     }
1.57      raeburn  7682:     my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
                   7683:     if (ref($cathash) eq 'HASH') {
1.48      raeburn  7684:         if (@deletecategory > 0) {
                   7685:             #FIXME Need to remove category from all courses using a deleted category 
1.57      raeburn  7686:             &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48      raeburn  7687:             foreach my $item (@deletecategory) {
1.57      raeburn  7688:                 if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
                   7689:                     delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48      raeburn  7690:                     $deletions{$item} = 1;
1.57      raeburn  7691:                     &recurse_cat_deletes($item,$cathash,\%deletions);
1.48      raeburn  7692:                 }
                   7693:             }
                   7694:         }
1.57      raeburn  7695:         foreach my $item (keys(%{$cathash})) {
1.48      raeburn  7696:             my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57      raeburn  7697:             if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48      raeburn  7698:                 $reorderings{$item} = 1;
1.57      raeburn  7699:                 $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48      raeburn  7700:             }
                   7701:             if ($env{'form.addcategory_name_'.$item} ne '') {
                   7702:                 my $newcat = $env{'form.addcategory_name_'.$item};
                   7703:                 my $newdepth = $depth+1;
                   7704:                 my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57      raeburn  7705:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48      raeburn  7706:                 $adds{$newitem} = 1; 
                   7707:             }
                   7708:             if ($env{'form.subcat_'.$item} ne '') {
                   7709:                 my $newcat = $env{'form.subcat_'.$item};
                   7710:                 my $newdepth = $depth+1;
                   7711:                 my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57      raeburn  7712:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48      raeburn  7713:                 $adds{$newitem} = 1;
                   7714:             }
                   7715:         }
                   7716:     }
                   7717:     if ($env{'form.instcode'} eq '1') {
1.57      raeburn  7718:         if (ref($cathash) eq 'HASH') {
1.48      raeburn  7719:             my $newitem = 'instcode::0';
1.57      raeburn  7720:             if ($cathash->{$newitem} eq '') {  
                   7721:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48      raeburn  7722:                 $adds{$newitem} = 1;
                   7723:             }
                   7724:         } else {
                   7725:             my $newitem = 'instcode::0';
1.57      raeburn  7726:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48      raeburn  7727:             $adds{$newitem} = 1;
                   7728:         }
                   7729:     }
1.120     raeburn  7730:     if ($env{'form.communities'} eq '1') {
                   7731:         if (ref($cathash) eq 'HASH') {
                   7732:             my $newitem = 'communities::0';
                   7733:             if ($cathash->{$newitem} eq '') {
                   7734:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
                   7735:                 $adds{$newitem} = 1;
                   7736:             }
                   7737:         } else {
                   7738:             my $newitem = 'communities::0';
                   7739:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
                   7740:             $adds{$newitem} = 1;
                   7741:         }
                   7742:     }
1.48      raeburn  7743:     if ($env{'form.addcategory_name'} ne '') {
1.120     raeburn  7744:         if (($env{'form.addcategory_name'} ne 'instcode') &&
                   7745:             ($env{'form.addcategory_name'} ne 'communities')) {
                   7746:             my $newitem = &escape($env{'form.addcategory_name'}).'::0';
                   7747:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
                   7748:             $adds{$newitem} = 1;
                   7749:         }
1.48      raeburn  7750:     }
1.57      raeburn  7751:     my $putresult;
1.48      raeburn  7752:     if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
                   7753:         if (keys(%deletions) > 0) {
                   7754:             foreach my $key (keys(%deletions)) {
                   7755:                 if ($predelallitems{$key} ne '') {
                   7756:                     $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
                   7757:                 }
                   7758:             }
                   7759:         }
                   7760:         my (@chkcats,@chktrails,%chkallitems);
1.57      raeburn  7761:         &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48      raeburn  7762:         if (ref($chkcats[0]) eq 'ARRAY') {
                   7763:             my $depth = 0;
                   7764:             my $chg = 0;
                   7765:             for (my $i=0; $i<@{$chkcats[0]}; $i++) {
                   7766:                 my $name = $chkcats[0][$i];
                   7767:                 my $item;
                   7768:                 if ($name eq '') {
                   7769:                     $chg ++;
                   7770:                 } else {
                   7771:                     $item = &escape($name).'::0';
                   7772:                     if ($chg) {
1.57      raeburn  7773:                         $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48      raeburn  7774:                     }
                   7775:                     $depth ++; 
1.57      raeburn  7776:                     &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48      raeburn  7777:                     $depth --;
                   7778:                 }
                   7779:             }
                   7780:         }
1.57      raeburn  7781:     }
                   7782:     if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
                   7783:         $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48      raeburn  7784:         if ($putresult eq 'ok') {
1.57      raeburn  7785:             my %title = (
1.120     raeburn  7786:                          togglecats     => 'Show/Hide a course in catalog',
                   7787:                          categorize     => 'Assign a category to a course',
                   7788:                          togglecatscomm => 'Show/Hide a community in catalog',
                   7789:                          categorizecomm => 'Assign a category to a community',
1.57      raeburn  7790:                         );
                   7791:             my %level = (
1.120     raeburn  7792:                          dom  => 'set in Domain ("Modify Course/Community")',
                   7793:                          crs  => 'set in Course ("Course Configuration")',
                   7794:                          comm => 'set in Community ("Community Configuration")',
1.57      raeburn  7795:                         );
1.48      raeburn  7796:             $resulttext = &mt('Changes made:').'<ul>';
1.57      raeburn  7797:             if ($changes{'togglecats'}) {
                   7798:                 $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>'; 
                   7799:             }
                   7800:             if ($changes{'categorize'}) {
                   7801:                 $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48      raeburn  7802:             }
1.120     raeburn  7803:             if ($changes{'togglecatscomm'}) {
                   7804:                 $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
                   7805:             }
                   7806:             if ($changes{'categorizecomm'}) {
                   7807:                 $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
                   7808:             }
1.57      raeburn  7809:             if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
                   7810:                 my $cathash;
                   7811:                 if (ref($domconfig{'coursecategories'}) eq 'HASH') {
                   7812:                     $cathash = $domconfig{'coursecategories'}{'cats'};
                   7813:                 } else {
                   7814:                     $cathash = {};
                   7815:                 } 
                   7816:                 my (@cats,@trails,%allitems);
                   7817:                     &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
                   7818:                 if (keys(%deletions) > 0) {
                   7819:                     $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
                   7820:                     foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) { 
                   7821:                         $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
                   7822:                     }
                   7823:                     $resulttext .= '</ul></li>';
                   7824:                 }
                   7825:                 if (keys(%reorderings) > 0) {
                   7826:                     my %sort_by_trail;
                   7827:                     $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
                   7828:                     foreach my $key (keys(%reorderings)) {
                   7829:                         if ($allitems{$key} ne '') {
                   7830:                             $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
                   7831:                         }
1.48      raeburn  7832:                     }
1.57      raeburn  7833:                     foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
                   7834:                         $resulttext .= '<li>'.$trails[$trail].'</li>';
                   7835:                     }
                   7836:                     $resulttext .= '</ul></li>';
1.48      raeburn  7837:                 }
1.57      raeburn  7838:                 if (keys(%adds) > 0) {
                   7839:                     my %sort_by_trail;
                   7840:                     $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
                   7841:                     foreach my $key (keys(%adds)) {
                   7842:                         if ($allitems{$key} ne '') {
                   7843:                             $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
                   7844:                         }
                   7845:                     }
                   7846:                     foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
                   7847:                         $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48      raeburn  7848:                     }
1.57      raeburn  7849:                     $resulttext .= '</ul></li>';
1.48      raeburn  7850:                 }
                   7851:             }
                   7852:             $resulttext .= '</ul>';
                   7853:         } else {
                   7854:             $resulttext = '<span class="LC_error">'.
1.57      raeburn  7855:                           &mt('An error occurred: [_1]',$putresult).'</span>';
1.48      raeburn  7856:         }
                   7857:     } else {
1.120     raeburn  7858:         $resulttext = &mt('No changes made to course and community categories');
1.48      raeburn  7859:     }
                   7860:     return $resulttext;
                   7861: }
                   7862: 
1.69      raeburn  7863: sub modify_serverstatuses {
                   7864:     my ($dom,%domconfig) = @_;
                   7865:     my ($resulttext,%changes,%currserverstatus,%newserverstatus);
                   7866:     if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
                   7867:         %currserverstatus = %{$domconfig{'serverstatuses'}};
                   7868:     }
                   7869:     my @pages = &serverstatus_pages();
                   7870:     foreach my $type (@pages) {
                   7871:         $newserverstatus{$type}{'namedusers'} = '';
                   7872:         $newserverstatus{$type}{'machines'} = '';
                   7873:         if (defined($env{'form.'.$type.'_namedusers'})) {
                   7874:             my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
                   7875:             my @okusers;
                   7876:             foreach my $user (@users) {
                   7877:                 my ($uname,$udom) = split(/:/,$user);
                   7878:                 if (($udom =~ /^$match_domain$/) &&   
                   7879:                     (&Apache::lonnet::domain($udom)) &&
                   7880:                     ($uname =~ /^$match_username$/)) {
                   7881:                     if (!grep(/^\Q$user\E/,@okusers)) {
                   7882:                         push(@okusers,$user);
                   7883:                     }
                   7884:                 }
                   7885:             }
                   7886:             if (@okusers > 0) {
                   7887:                  @okusers = sort(@okusers);
                   7888:                  $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
                   7889:             }
                   7890:         }
                   7891:         if (defined($env{'form.'.$type.'_machines'})) {
                   7892:             my @machines = split(/,/,$env{'form.'.$type.'_machines'});
                   7893:             my @okmachines;
                   7894:             foreach my $ip (@machines) {
                   7895:                 my @parts = split(/\./,$ip);
                   7896:                 next if (@parts < 4);
                   7897:                 my $badip = 0;
                   7898:                 for (my $i=0; $i<4; $i++) {
                   7899:                     if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
                   7900:                         $badip = 1;
                   7901:                         last;
                   7902:                     }
                   7903:                 }
                   7904:                 if (!$badip) {
                   7905:                     push(@okmachines,$ip);     
                   7906:                 }
                   7907:             }
                   7908:             @okmachines = sort(@okmachines);
                   7909:             $newserverstatus{$type}{'machines'} = join(',',@okmachines);
                   7910:         }
                   7911:     }
                   7912:     my %serverstatushash =  (
                   7913:                                 serverstatuses => \%newserverstatus,
                   7914:                             );
                   7915:     foreach my $type (@pages) {
1.83      raeburn  7916:         foreach my $setting ('namedusers','machines') {
1.84      raeburn  7917:             my (@current,@new);
1.83      raeburn  7918:             if (ref($currserverstatus{$type}) eq 'HASH') {
1.84      raeburn  7919:                 if ($currserverstatus{$type}{$setting} ne '') { 
                   7920:                     @current = split(/,/,$currserverstatus{$type}{$setting});
                   7921:                 }
                   7922:             }
                   7923:             if ($newserverstatus{$type}{$setting} ne '') {
                   7924:                 @new = split(/,/,$newserverstatus{$type}{$setting});
1.83      raeburn  7925:             }
                   7926:             if (@current > 0) {
                   7927:                 if (@new > 0) {
                   7928:                     foreach my $item (@current) {
                   7929:                         if (!grep(/^\Q$item\E$/,@new)) {
                   7930:                             $changes{$type}{$setting} = 1;
1.82      raeburn  7931:                             last;
                   7932:                         }
                   7933:                     }
1.84      raeburn  7934:                     foreach my $item (@new) {
                   7935:                         if (!grep(/^\Q$item\E$/,@current)) {
                   7936:                             $changes{$type}{$setting} = 1;
                   7937:                             last;
1.82      raeburn  7938:                         }
                   7939:                     }
                   7940:                 } else {
1.83      raeburn  7941:                     $changes{$type}{$setting} = 1;
1.69      raeburn  7942:                 }
1.83      raeburn  7943:             } elsif (@new > 0) {
                   7944:                 $changes{$type}{$setting} = 1;
1.69      raeburn  7945:             }
                   7946:         }
                   7947:     }
                   7948:     if (keys(%changes) > 0) {
1.81      raeburn  7949:         my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69      raeburn  7950:         my $putresult = &Apache::lonnet::put_dom('configuration',
                   7951:                                                  \%serverstatushash,$dom);
                   7952:         if ($putresult eq 'ok') {
                   7953:             $resulttext .= &mt('Changes made:').'<ul>';
                   7954:             foreach my $type (@pages) {
1.84      raeburn  7955:                 if (ref($changes{$type}) eq 'HASH') {
1.69      raeburn  7956:                     $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84      raeburn  7957:                     if ($changes{$type}{'namedusers'}) {
1.69      raeburn  7958:                         if ($newserverstatus{$type}{'namedusers'} eq '') {
                   7959:                             $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
                   7960:                         } else {
                   7961:                             $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
                   7962:                         }
1.84      raeburn  7963:                     }
                   7964:                     if ($changes{$type}{'machines'}) {
1.69      raeburn  7965:                         if ($newserverstatus{$type}{'machines'} eq '') {
                   7966:                             $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
                   7967:                         } else {
                   7968:                             $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
                   7969:                         }
                   7970: 
                   7971:                     }
                   7972:                     $resulttext .= '</ul></li>';
                   7973:                 }
                   7974:             }
                   7975:             $resulttext .= '</ul>';
                   7976:         } else {
                   7977:             $resulttext = '<span class="LC_error">'.
                   7978:                           &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
                   7979: 
                   7980:         }
                   7981:     } else {
                   7982:         $resulttext = &mt('No changes made to access to server status pages');
                   7983:     }
                   7984:     return $resulttext;
                   7985: }
                   7986: 
1.118     jms      7987: sub modify_helpsettings {
1.122     jms      7988:     my ($r,$dom,$confname,%domconfig) = @_;
1.166     raeburn  7989:     my ($resulttext,$errors,%changes,%helphash);
                   7990:     my %defaultchecked = ('submitbugs' => 'on');
                   7991:     my @offon = ('off','on');
1.118     jms      7992:     my @toggles = ('submitbugs');
                   7993:     if (ref($domconfig{'helpsettings'}) eq 'HASH') {
                   7994:         foreach my $item (@toggles) {
1.166     raeburn  7995:             if ($defaultchecked{$item} eq 'on') { 
                   7996:                 if ($domconfig{'helpsettings'}{$item} eq '') {
                   7997:                     if ($env{'form.'.$item} eq '0') {
                   7998:                         $changes{$item} = 1;
                   7999:                     }
                   8000:                 } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
                   8001:                     $changes{$item} = 1;
                   8002:                 }
                   8003:             } elsif ($defaultchecked{$item} eq 'off') {
                   8004:                 if ($domconfig{'helpsettings'}{$item} eq '') {
                   8005:                     if ($env{'form.'.$item} eq '1') {
                   8006:                         $changes{$item} = 1;
                   8007:                     }
                   8008:                 } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
                   8009:                     $changes{$item} = 1;
                   8010:                 }
                   8011:             }
1.210     raeburn  8012:             if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
1.166     raeburn  8013:                 $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
                   8014:             }
                   8015:         }
1.118     jms      8016:     }
1.123     jms      8017:     my $putresult;
                   8018:     if (keys(%changes) > 0) {
1.166     raeburn  8019:         $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168     raeburn  8020:         if ($putresult eq 'ok') {
1.166     raeburn  8021:             $resulttext = &mt('Changes made:').'<ul>';
                   8022:             foreach my $item (sort(keys(%changes))) {
                   8023:                 if ($item eq 'submitbugs') {
                   8024:                     $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
                   8025:                                               &Apache::loncommon::modal_link('http://bugs.loncapa.org',
                   8026:                                               &mt('LON-CAPA bug tracker'),600,500)).'</li>';
                   8027:                 }
                   8028:             }
                   8029:             $resulttext .= '</ul>';
                   8030:         } else {
                   8031:             $resulttext = &mt('No changes made to help settings');
1.168     raeburn  8032:             $errors .= '<li><span class="LC_error">'.
                   8033:                        &mt('An error occurred storing the settings: [_1]',
                   8034:                            $putresult).'</span></li>';
1.166     raeburn  8035:         }
1.118     jms      8036:     }
                   8037:     if ($errors) {
1.168     raeburn  8038:         $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.118     jms      8039:                        $errors.'</ul>';
                   8040:     }
                   8041:     return $resulttext;
                   8042: }
                   8043: 
1.121     raeburn  8044: sub modify_coursedefaults {
                   8045:     my ($dom,%domconfig) = @_;
                   8046:     my ($resulttext,$errors,%changes,%defaultshash);
                   8047:     my %defaultchecked = ('canuse_pdfforms' => 'off');
                   8048:     my @toggles = ('canuse_pdfforms');
1.198     raeburn  8049:     my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
                   8050:                    'uploadquota_community');
                   8051:     my @types = ('official','unofficial','community');
                   8052:     my %staticdefaults = (
                   8053:                            anonsurvey_threshold => 10,
                   8054:                            uploadquota          => 500,
                   8055:                          );
1.121     raeburn  8056: 
                   8057:     $defaultshash{'coursedefaults'} = {};
                   8058: 
                   8059:     if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
                   8060:         if ($domconfig{'coursedefaults'} eq '') {
                   8061:             $domconfig{'coursedefaults'} = {};
                   8062:         }
                   8063:     }
                   8064: 
                   8065:     if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
                   8066:         foreach my $item (@toggles) {
                   8067:             if ($defaultchecked{$item} eq 'on') {
                   8068:                 if (($domconfig{'coursedefaults'}{$item} eq '') &&
                   8069:                     ($env{'form.'.$item} eq '0')) {
                   8070:                     $changes{$item} = 1;
1.192     raeburn  8071:                 } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121     raeburn  8072:                     $changes{$item} = 1;
                   8073:                 }
                   8074:             } elsif ($defaultchecked{$item} eq 'off') {
                   8075:                 if (($domconfig{'coursedefaults'}{$item} eq '') &&
                   8076:                     ($env{'form.'.$item} eq '1')) {
                   8077:                     $changes{$item} = 1;
                   8078:                 } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
                   8079:                     $changes{$item} = 1;
                   8080:                 }
                   8081:             }
                   8082:             $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
                   8083:         }
1.198     raeburn  8084:         foreach my $item (@numbers) {
                   8085:             my ($currdef,$newdef);
1.208     raeburn  8086:             $newdef = $env{'form.'.$item};
1.198     raeburn  8087:             if ($item eq 'anonsurvey_threshold') {
                   8088:                 $currdef = $domconfig{'coursedefaults'}{$item};
                   8089:                 $newdef =~ s/\D//g;
                   8090:                 if ($newdef eq '' || $newdef < 1) {
                   8091:                     $newdef = 1;
                   8092:                 }
                   8093:                 $defaultshash{'coursedefaults'}{$item} = $newdef;
                   8094:             } else {
                   8095:                 my ($type) = ($item =~ /^\Quploadquota_\E(\w+)$/);
                   8096:                 if (ref($domconfig{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
                   8097:                     $currdef = $domconfig{'coursedefaults'}{'uploadquota'}{$type};
                   8098:                 }
                   8099:                 $newdef =~ s/[^\w.\-]//g;
                   8100:                 $defaultshash{'coursedefaults'}{'uploadquota'}{$type} = $newdef;
                   8101:             }
                   8102:             if ($currdef ne $newdef) {
                   8103:                 my $staticdef;
                   8104:                 if ($item eq 'anonsurvey_threshold') {
                   8105:                     unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
                   8106:                         $changes{$item} = 1;
                   8107:                     }
                   8108:                 } else {
                   8109:                     unless (($currdef eq '') && ($newdef == $staticdefaults{'uploadquota'})) {
                   8110:                         $changes{'uploadquota'} = 1;
                   8111:                     }
                   8112:                 }
1.139     raeburn  8113:             }
                   8114:         }
1.192     raeburn  8115:         my $officialcreds = $env{'form.official_credits'};
                   8116:         $officialcreds =~ s/^[^\d\.]//g;
                   8117:         my $unofficialcreds = $env{'form.unofficial_credits'};
                   8118:         $unofficialcreds =~ s/^[^\d\.]//g;
                   8119:         if (ref($domconfig{'coursedefaults'}{'coursecredits'} ne 'HASH') &&
                   8120:                 ($env{'form.coursecredits'} eq '1')) {
                   8121:                 $changes{'coursecredits'} = 1;
                   8122:         } else {
                   8123:             if (($domconfig{'coursedefaults'}{'coursecredits'}{'official'} ne $officialcreds)  ||
                   8124:                 ($domconfig{'coursedefaults'}{'coursecredits'}{'unofficial'} ne $unofficialcreds)) {
                   8125:                 $changes{'coursecredits'} = 1;
                   8126:             }
                   8127:         }
                   8128:         $defaultshash{'coursedefaults'}{'coursecredits'} = {
                   8129:             official   => $officialcreds,
                   8130:             unofficial => $unofficialcreds,
                   8131:         }
1.121     raeburn  8132:     }
                   8133:     my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
                   8134:                                              $dom);
                   8135:     if ($putresult eq 'ok') {
1.192     raeburn  8136:         my %domdefaults;
1.121     raeburn  8137:         if (keys(%changes) > 0) {
1.198     raeburn  8138:             if (($changes{'canuse_pdfforms'}) || ($changes{'coursecredits'}) || ($changes{'uploadquota'})) {
1.192     raeburn  8139:                 %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
                   8140:                 if ($changes{'canuse_pdfforms'}) {
                   8141:                     $domdefaults{'canuse_pdfforms'}=$defaultshash{'coursedefaults'}{'canuse_pdfforms'};
                   8142:                 }
                   8143:                 if ($changes{'coursecredits'}) {
                   8144:                     if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
                   8145:                         $domdefaults{'officialcredits'} =
                   8146:                             $defaultshash{'coursedefaults'}{'coursecredits'}{'official'};
                   8147:                         $domdefaults{'unofficialcredits'} =
                   8148:                             $defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'};
                   8149:                     }
                   8150:                 }
1.198     raeburn  8151:                 if ($changes{'uploadquota'}) {
                   8152:                     if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
                   8153:                         foreach my $type (@types) {
                   8154:                             $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
                   8155:                         }
                   8156:                     }
                   8157:                 }
1.121     raeburn  8158:                 my $cachetime = 24*60*60;
                   8159:                 &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
                   8160:             }
                   8161:             $resulttext = &mt('Changes made:').'<ul>';
                   8162:             foreach my $item (sort(keys(%changes))) {
                   8163:                 if ($item eq 'canuse_pdfforms') {
                   8164:                     if ($env{'form.'.$item} eq '1') {
                   8165:                         $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
                   8166:                     } else {
                   8167:                         $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
                   8168:                     }
1.139     raeburn  8169:                 } elsif ($item eq 'anonsurvey_threshold') {
1.192     raeburn  8170:                     $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198     raeburn  8171:                 } elsif ($item eq 'uploadquota') {
                   8172:                     if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
                   8173:                         $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
                   8174:                                        '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
                   8175:                                        '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
                   8176:                                        '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
                   8177:                                        '</ul>'.
                   8178:                                        '</li>';
                   8179:                     } else {
                   8180:                         $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
                   8181:                     }
1.192     raeburn  8182:                 } elsif ($item eq 'coursecredits') {
                   8183:                     if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
                   8184:                         if (($domdefaults{'officialcredits'} eq '') &&
                   8185:                             ($domdefaults{'unofficialcredits'} eq '')) {
                   8186:                             $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
                   8187:                         } else {
                   8188:                             $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
                   8189:                                            '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
                   8190:                                            '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
                   8191:                                            '</ul>'.
                   8192:                                            '</li>';
                   8193:                         }
                   8194:                     } else {
                   8195:                         $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
                   8196:                     }
1.140     raeburn  8197:                 }
1.121     raeburn  8198:             }
                   8199:             $resulttext .= '</ul>';
                   8200:         } else {
                   8201:             $resulttext = &mt('No changes made to course defaults');
                   8202:         }
                   8203:     } else {
                   8204:         $resulttext = '<span class="LC_error">'.
                   8205:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   8206:     }
                   8207:     return $resulttext;
                   8208: }
                   8209: 
1.137     raeburn  8210: sub modify_usersessions {
                   8211:     my ($dom,%domconfig) = @_;
1.145     raeburn  8212:     my @hostingtypes = ('version','excludedomain','includedomain');
                   8213:     my @offloadtypes = ('primary','default');
                   8214:     my %types = (
                   8215:                   remote => \@hostingtypes,
                   8216:                   hosted => \@hostingtypes,
                   8217:                   spares => \@offloadtypes,
                   8218:                 );
                   8219:     my @prefixes = ('remote','hosted','spares');
1.137     raeburn  8220:     my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138     raeburn  8221:     my (%by_ip,%by_location,@intdoms);
                   8222:     &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
                   8223:     my @locations = sort(keys(%by_location));
1.137     raeburn  8224:     my (%defaultshash,%changes);
                   8225:     foreach my $prefix (@prefixes) {
                   8226:         $defaultshash{'usersessions'}{$prefix} = {};
                   8227:     }
                   8228:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
                   8229:     my $resulttext;
1.138     raeburn  8230:     my %iphost = &Apache::lonnet::get_iphost();
1.137     raeburn  8231:     foreach my $prefix (@prefixes) {
1.145     raeburn  8232:         next if ($prefix eq 'spares');
                   8233:         foreach my $type (@{$types{$prefix}}) {
1.137     raeburn  8234:             my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
                   8235:             if ($type eq 'version') {
                   8236:                 my $value = $env{'form.'.$prefix.'_'.$type};
                   8237:                 my $okvalue;
                   8238:                 if ($value ne '') {
                   8239:                     if (grep(/^\Q$value\E$/,@lcversions)) {
                   8240:                         $okvalue = $value;
                   8241:                     }
                   8242:                 }
                   8243:                 if (ref($domconfig{'usersessions'}) eq 'HASH') {
                   8244:                     if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
                   8245:                         if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
                   8246:                             if ($inuse == 0) {
                   8247:                                 $changes{$prefix}{$type} = 1;
                   8248:                             } else {
                   8249:                                 if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
                   8250:                                     $changes{$prefix}{$type} = 1;
                   8251:                                 }
                   8252:                                 if ($okvalue ne '') {
                   8253:                                     $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
                   8254:                                 } 
                   8255:                             }
                   8256:                         } else {
                   8257:                             if (($inuse == 1) && ($okvalue ne '')) {
                   8258:                                 $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
                   8259:                                 $changes{$prefix}{$type} = 1;
                   8260:                             }
                   8261:                         }
                   8262:                     } else {
                   8263:                         if (($inuse == 1) && ($okvalue ne '')) {
                   8264:                             $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
                   8265:                             $changes{$prefix}{$type} = 1;
                   8266:                         }
                   8267:                     }
                   8268:                 } else {
                   8269:                     if (($inuse == 1) && ($okvalue ne '')) {
                   8270:                         $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
                   8271:                         $changes{$prefix}{$type} = 1;
                   8272:                     }
                   8273:                 }
                   8274:             } else {
                   8275:                 my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
                   8276:                 my @okvals;
                   8277:                 foreach my $val (@vals) {
1.138     raeburn  8278:                     if ($val =~ /:/) {
                   8279:                         my @items = split(/:/,$val);
                   8280:                         foreach my $item (@items) {
                   8281:                             if (ref($by_location{$item}) eq 'ARRAY') {
                   8282:                                 push(@okvals,$item);
                   8283:                             }
                   8284:                         }
                   8285:                     } else {
                   8286:                         if (ref($by_location{$val}) eq 'ARRAY') {
                   8287:                             push(@okvals,$val);
                   8288:                         }
1.137     raeburn  8289:                     }
                   8290:                 }
                   8291:                 @okvals = sort(@okvals);
                   8292:                 if (ref($domconfig{'usersessions'}) eq 'HASH') {
                   8293:                     if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
                   8294:                         if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
                   8295:                             if ($inuse == 0) {
                   8296:                                 $changes{$prefix}{$type} = 1; 
                   8297:                             } else {
                   8298:                                 $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
                   8299:                                 my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
                   8300:                                 if (@changed > 0) {
                   8301:                                     $changes{$prefix}{$type} = 1;
                   8302:                                 }
                   8303:                             }
                   8304:                         } else {
                   8305:                             if ($inuse == 1) {
                   8306:                                 $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
                   8307:                                 $changes{$prefix}{$type} = 1;
                   8308:                             }
                   8309:                         } 
                   8310:                     } else {
                   8311:                         if ($inuse == 1) {
                   8312:                             $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
                   8313:                             $changes{$prefix}{$type} = 1;
                   8314:                         }
                   8315:                     }
                   8316:                 } else {
                   8317:                     if ($inuse == 1) {
                   8318:                         $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
                   8319:                         $changes{$prefix}{$type} = 1;
                   8320:                     }
                   8321:                 }
                   8322:             }
                   8323:         }
                   8324:     }
1.145     raeburn  8325: 
                   8326:     my @alldoms = &Apache::lonnet::all_domains();
1.149     raeburn  8327:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145     raeburn  8328:     my %spareid = &current_offloads_to($dom,$domconfig{'usersessions'},\%servers);
                   8329:     my $savespares;
                   8330: 
                   8331:     foreach my $lonhost (sort(keys(%servers))) {
                   8332:         my $serverhomeID =
                   8333:             &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152     raeburn  8334:         my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145     raeburn  8335:         $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
                   8336:         my %spareschg;
                   8337:         foreach my $type (@{$types{'spares'}}) {
                   8338:             my @okspares;
                   8339:             my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
                   8340:             foreach my $server (@checked) {
1.152     raeburn  8341:                 if (&Apache::lonnet::hostname($server) ne '') {
                   8342:                     unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
                   8343:                         unless (grep(/^\Q$server\E$/,@okspares)) {
                   8344:                             push(@okspares,$server);
                   8345:                         }
1.145     raeburn  8346:                     }
                   8347:                 }
                   8348:             }
                   8349:             my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
                   8350:             my $newspare;
1.152     raeburn  8351:             if (($new ne '') && (&Apache::lonnet::hostname($new))) {
                   8352:                 unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145     raeburn  8353:                     $newspare = $new;
                   8354:                 }
                   8355:             }
1.152     raeburn  8356:             my @spares;
                   8357:             if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
                   8358:                 @spares = sort(@okspares,$newspare);
                   8359:             } else {
                   8360:                 @spares = sort(@okspares);
                   8361:             }
                   8362:             $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145     raeburn  8363:             if (ref($spareid{$lonhost}) eq 'HASH') {
                   8364:                 if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152     raeburn  8365:                     my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145     raeburn  8366:                     if (@diffs > 0) {
                   8367:                         $spareschg{$type} = 1;
                   8368:                     }
                   8369:                 }
                   8370:             }
                   8371:         }
                   8372:         if (keys(%spareschg) > 0) {
                   8373:             $changes{'spares'}{$lonhost} = \%spareschg;
                   8374:         }
                   8375:     }
                   8376: 
                   8377:     if (ref($domconfig{'usersessions'}) eq 'HASH') {
                   8378:         if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
                   8379:             if (ref($changes{'spares'}) eq 'HASH') {
                   8380:                 if (keys(%{$changes{'spares'}}) > 0) {
                   8381:                     $savespares = 1;
                   8382:                 }
                   8383:             }
                   8384:         } else {
                   8385:             $savespares = 1;
                   8386:         }
                   8387:     }
                   8388: 
1.147     raeburn  8389:     my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
                   8390:     if ((keys(%changes) > 0) || ($savespares)) {
1.137     raeburn  8391:         my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
                   8392:                                                  $dom);
                   8393:         if ($putresult eq 'ok') {
                   8394:             if (ref($defaultshash{'usersessions'}) eq 'HASH') {
                   8395:                 if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
                   8396:                     $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
                   8397:                 }
                   8398:                 if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
                   8399:                     $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
                   8400:                 }
                   8401:             }
                   8402:             my $cachetime = 24*60*60;
                   8403:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.147     raeburn  8404:             if (keys(%changes) > 0) {
                   8405:                 my %lt = &usersession_titles();
                   8406:                 $resulttext = &mt('Changes made:').'<ul>';
                   8407:                 foreach my $prefix (@prefixes) {
                   8408:                     if (ref($changes{$prefix}) eq 'HASH') {
                   8409:                         $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
                   8410:                         if ($prefix eq 'spares') {
                   8411:                             if (ref($changes{$prefix}) eq 'HASH') {
                   8412:                                 foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
                   8413:                                     $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148     raeburn  8414:                                     my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211   ! raeburn  8415:                                     my $cachekey = &escape('spares').':'.&escape($lonhostdom);
        !          8416:                                     &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147     raeburn  8417:                                     if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
                   8418:                                         foreach my $type (@{$types{$prefix}}) {
                   8419:                                             if ($changes{$prefix}{$lonhost}{$type}) {
                   8420:                                                 my $offloadto = &mt('None');
                   8421:                                                 if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
                   8422:                                                     if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {   
                   8423:                                                         $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
                   8424:                                                     }
1.145     raeburn  8425:                                                 }
1.147     raeburn  8426:                                                 $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).('&nbsp;'x3);
1.145     raeburn  8427:                                             }
1.137     raeburn  8428:                                         }
                   8429:                                     }
1.147     raeburn  8430:                                     $resulttext .= '</li>';
1.137     raeburn  8431:                                 }
                   8432:                             }
1.147     raeburn  8433:                         } else {
                   8434:                             foreach my $type (@{$types{$prefix}}) {
                   8435:                                 if (defined($changes{$prefix}{$type})) {
                   8436:                                     my $newvalue;
                   8437:                                     if (ref($defaultshash{'usersessions'}) eq 'HASH') {
                   8438:                                         if (ref($defaultshash{'usersessions'}{$prefix})) {
                   8439:                                             if ($type eq 'version') {
                   8440:                                                 $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
                   8441:                                             } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
                   8442:                                                 if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
                   8443:                                                     $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
                   8444:                                                 }
1.145     raeburn  8445:                                             }
                   8446:                                         }
                   8447:                                     }
1.147     raeburn  8448:                                     if ($newvalue eq '') {
                   8449:                                         if ($type eq 'version') {
                   8450:                                             $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
                   8451:                                         } else {
                   8452:                                             $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
                   8453:                                         }
1.145     raeburn  8454:                                     } else {
1.147     raeburn  8455:                                         if ($type eq 'version') {
                   8456:                                             $newvalue .= ' '.&mt('(or later)'); 
                   8457:                                         }
                   8458:                                         $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145     raeburn  8459:                                     }
1.137     raeburn  8460:                                 }
                   8461:                             }
                   8462:                         }
1.147     raeburn  8463:                         $resulttext .= '</ul>';
1.137     raeburn  8464:                     }
                   8465:                 }
1.147     raeburn  8466:                 $resulttext .= '</ul>';
                   8467:             } else {
                   8468:                 $resulttext = $nochgmsg;
1.137     raeburn  8469:             }
                   8470:         } else {
                   8471:             $resulttext = '<span class="LC_error">'.
                   8472:                           &mt('An error occurred: [_1]',$putresult).'</span>';
                   8473:         }
                   8474:     } else {
1.147     raeburn  8475:         $resulttext = $nochgmsg;
1.137     raeburn  8476:     }
                   8477:     return $resulttext;
                   8478: }
                   8479: 
1.150     raeburn  8480: sub modify_loadbalancing {
                   8481:     my ($dom,%domconfig) = @_;
                   8482:     my $primary_id = &Apache::lonnet::domain($dom,'primary');
                   8483:     my $intdom = &Apache::lonnet::internet_dom($primary_id);
                   8484:     my ($othertitle,$usertypes,$types) =
                   8485:         &Apache::loncommon::sorted_inst_types($dom);
                   8486:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
                   8487:     my @sparestypes = ('primary','default');
                   8488:     my %typetitles = &sparestype_titles();
                   8489:     my $resulttext;
1.171     raeburn  8490:     my (%currbalancer,%currtargets,%currrules,%existing);
                   8491:     if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
                   8492:         %existing = %{$domconfig{'loadbalancing'}};
                   8493:     }
                   8494:     &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
                   8495:                               \%currtargets,\%currrules);
                   8496:     my ($saveloadbalancing,%defaultshash,%changes);
                   8497:     my ($alltypes,$othertypes,$titles) =
                   8498:         &loadbalancing_titles($dom,$intdom,$usertypes,$types);
                   8499:     my %ruletitles = &offloadtype_text();
                   8500:     my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
                   8501:     for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
                   8502:         my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
                   8503:         if ($balancer eq '') {
                   8504:             next;
                   8505:         }
1.210     raeburn  8506:         if (!exists($servers{$balancer})) {
1.171     raeburn  8507:             if (exists($currbalancer{$balancer})) {
                   8508:                 push(@{$changes{'delete'}},$balancer);
1.150     raeburn  8509:             }
1.171     raeburn  8510:             next;
                   8511:         }
                   8512:         if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
                   8513:             push(@{$changes{'delete'}},$balancer);
                   8514:             next;
                   8515:         }
                   8516:         if (!exists($currbalancer{$balancer})) {
                   8517:             push(@{$changes{'add'}},$balancer);
                   8518:         }
                   8519:         $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
                   8520:         $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
                   8521:         $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
                   8522:         unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
                   8523:             $saveloadbalancing = 1;
                   8524:         }
                   8525:         foreach my $sparetype (@sparestypes) {
                   8526:             my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
                   8527:             my @offloadto;
                   8528:             foreach my $target (@targets) {
                   8529:                 if (($servers{$target}) && ($target ne $balancer)) {
                   8530:                     if ($sparetype eq 'default') {
                   8531:                         if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
                   8532:                             next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150     raeburn  8533:                         }
                   8534:                     }
1.171     raeburn  8535:                     unless(grep(/^\Q$target\E$/,@offloadto)) {
                   8536:                         push(@offloadto,$target);
                   8537:                     }
1.150     raeburn  8538:                 }
1.171     raeburn  8539:                 $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150     raeburn  8540:             }
                   8541:         }
1.171     raeburn  8542:         if (ref($currtargets{$balancer}) eq 'HASH') {
1.150     raeburn  8543:             foreach my $sparetype (@sparestypes) {
1.171     raeburn  8544:                 if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
                   8545:                     my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150     raeburn  8546:                     if (@targetdiffs > 0) {
1.171     raeburn  8547:                         $changes{'curr'}{$balancer}{'targets'} = 1;
1.150     raeburn  8548:                     }
1.171     raeburn  8549:                 } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
                   8550:                     if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
                   8551:                         $changes{'curr'}{$balancer}{'targets'} = 1;
1.150     raeburn  8552:                     }
                   8553:                 }
                   8554:             }
                   8555:         } else {
1.171     raeburn  8556:             if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210     raeburn  8557:                 foreach my $sparetype (@sparestypes) {
1.171     raeburn  8558:                     if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
                   8559:                         if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
                   8560:                             $changes{'curr'}{$balancer}{'targets'} = 1;
                   8561:                         }
1.150     raeburn  8562:                     }
                   8563:                 }
1.210     raeburn  8564:             }
1.150     raeburn  8565:         }
                   8566:         my $ishomedom;
1.171     raeburn  8567:         if (&Apache::lonnet::host_domain($balancer) eq $dom) {
                   8568:             $ishomedom = 1;
1.150     raeburn  8569:         }
                   8570:         if (ref($alltypes) eq 'ARRAY') {
                   8571:             foreach my $type (@{$alltypes}) {
                   8572:                 my $rule;
1.210     raeburn  8573:                 unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150     raeburn  8574:                          (!$ishomedom)) {
1.171     raeburn  8575:                     $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
                   8576:                 }
                   8577:                 if ($rule eq 'specific') {
                   8578:                     $rule = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.150     raeburn  8579:                 }
1.171     raeburn  8580:                 $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
                   8581:                 if (ref($currrules{$balancer}) eq 'HASH') {
                   8582:                     if ($rule ne $currrules{$balancer}{$type}) {
                   8583:                         $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150     raeburn  8584:                     }
                   8585:                 } elsif ($rule ne '') {
1.171     raeburn  8586:                     $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150     raeburn  8587:                 }
                   8588:             }
                   8589:         }
1.171     raeburn  8590:     }
                   8591:     my $nochgmsg = &mt('No changes made to Load Balancer settings.');
                   8592:     if ((keys(%changes) > 0) || ($saveloadbalancing)) {
                   8593:         unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
                   8594:             $defaultshash{'loadbalancing'} = {};
                   8595:         }
                   8596:         my $putresult = &Apache::lonnet::put_dom('configuration',
                   8597:                                                  \%defaultshash,$dom);
                   8598:         if ($putresult eq 'ok') {
                   8599:             if (keys(%changes) > 0) {
                   8600:                 if (ref($changes{'delete'}) eq 'ARRAY') {
                   8601:                     foreach my $balancer (sort(@{$changes{'delete'}})) {
                   8602:                         $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.211   ! raeburn  8603:                         my $cachekey = &escape('loadbalancing').':'.&escape($dom);
        !          8604:                         &Apache::lonnet::remote_devalidate_cache($balancer,[$cachekey]);
1.150     raeburn  8605:                     }
1.171     raeburn  8606:                 }
                   8607:                 if (ref($changes{'add'}) eq 'ARRAY') {
1.210     raeburn  8608:                     foreach my $balancer (sort(@{$changes{'add'}})) {
1.171     raeburn  8609:                         $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
                   8610:                     }
                   8611:                 }
                   8612:                 if (ref($changes{'curr'}) eq 'HASH') {
                   8613:                     foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
                   8614:                         if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
                   8615:                             if ($changes{'curr'}{$balancer}{'targets'}) {
                   8616:                                 my %offloadstr;
                   8617:                                 foreach my $sparetype (@sparestypes) {
                   8618:                                     if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
                   8619:                                         if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
                   8620:                                             $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
                   8621:                                         }
                   8622:                                     }
1.150     raeburn  8623:                                 }
1.171     raeburn  8624:                                 if (keys(%offloadstr) == 0) {
                   8625:                                     $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150     raeburn  8626:                                 } else {
1.171     raeburn  8627:                                     my $showoffload;
                   8628:                                     foreach my $sparetype (@sparestypes) {
                   8629:                                         $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>:&nbsp;';
                   8630:                                         if (defined($offloadstr{$sparetype})) {
                   8631:                                             $showoffload .= $offloadstr{$sparetype};
                   8632:                                         } else {
                   8633:                                             $showoffload .= &mt('None');
                   8634:                                         }
                   8635:                                         $showoffload .= ('&nbsp;'x3);
                   8636:                                     }
                   8637:                                     $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150     raeburn  8638:                                 }
                   8639:                             }
                   8640:                         }
1.171     raeburn  8641:                         if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
                   8642:                             if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
                   8643:                                 foreach my $type (@{$alltypes}) {
                   8644:                                     if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
                   8645:                                         my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
                   8646:                                         my $balancetext;
                   8647:                                         if ($rule eq '') {
                   8648:                                             $balancetext =  $ruletitles{'default'};
1.209     raeburn  8649:                                         } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
                   8650:                                                  ($rule eq 'balancer') || ($rule eq 'offloadedto')) {
1.171     raeburn  8651:                                             $balancetext =  $ruletitles{$rule};
                   8652:                                         } else {
                   8653:                                             $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
                   8654:                                         }
1.210     raeburn  8655:                                         $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150     raeburn  8656:                                     }
                   8657:                                 }
                   8658:                             }
                   8659:                         }
1.211   ! raeburn  8660:                         my $cachekey = &scape('loadbalancing').':'.&escape($dom);
        !          8661:                         &Apache::lonnet::remote_devalidate_cache($balancer,[$cachekey]);
1.150     raeburn  8662:                     }
1.171     raeburn  8663:                 }
                   8664:                 if ($resulttext ne '') {
                   8665:                     $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150     raeburn  8666:                 } else {
                   8667:                     $resulttext = $nochgmsg;
                   8668:                 }
                   8669:             } else {
1.171     raeburn  8670:                 $resulttext = $nochgmsg;
1.150     raeburn  8671:             }
                   8672:         } else {
1.171     raeburn  8673:             $resulttext = '<span class="LC_error">'.
                   8674:                           &mt('An error occurred: [_1]',$putresult).'</span>';
1.150     raeburn  8675:         }
                   8676:     } else {
1.171     raeburn  8677:         $resulttext = $nochgmsg;
1.150     raeburn  8678:     }
                   8679:     return $resulttext;
                   8680: }
                   8681: 
1.48      raeburn  8682: sub recurse_check {
                   8683:     my ($chkcats,$categories,$depth,$name) = @_;
                   8684:     if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
                   8685:         my $chg = 0;
                   8686:         for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
                   8687:             my $category = $chkcats->[$depth]{$name}[$j];
                   8688:             my $item;
                   8689:             if ($category eq '') {
                   8690:                 $chg ++;
                   8691:             } else {
                   8692:                 my $deeper = $depth + 1;
                   8693:                 $item = &escape($category).':'.&escape($name).':'.$depth;
                   8694:                 if ($chg) {
                   8695:                     $categories->{$item} -= $chg;
                   8696:                 }
                   8697:                 &recurse_check($chkcats,$categories,$deeper,$category);
                   8698:                 $deeper --;
                   8699:             }
                   8700:         }
                   8701:     }
                   8702:     return;
                   8703: }
                   8704: 
                   8705: sub recurse_cat_deletes {
                   8706:     my ($item,$coursecategories,$deletions) = @_;
                   8707:     my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
                   8708:     my $subdepth = $depth + 1;
                   8709:     if (ref($coursecategories) eq 'HASH') {
                   8710:         foreach my $subitem (keys(%{$coursecategories})) {
                   8711:             my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
                   8712:             if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
                   8713:                 delete($coursecategories->{$subitem});
                   8714:                 $deletions->{$subitem} = 1;
                   8715:                 &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168     raeburn  8716:             }
1.48      raeburn  8717:         }
                   8718:     }
                   8719:     return;
                   8720: }
                   8721: 
1.125     raeburn  8722: sub get_active_dcs {
                   8723:     my ($dom) = @_;
1.191     raeburn  8724:     my $now = time;
                   8725:     my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
1.125     raeburn  8726:     my %domcoords;
                   8727:     my $numdcs = 0;
                   8728:     foreach my $server (keys(%dompersonnel)) {
                   8729:         foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
                   8730:             my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
1.191     raeburn  8731:             $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
1.125     raeburn  8732:         }
                   8733:     }
                   8734:     return %domcoords;
                   8735: }
                   8736: 
                   8737: sub active_dc_picker {
1.191     raeburn  8738:     my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.125     raeburn  8739:     my %domcoords = &get_active_dcs($dom); 
1.191     raeburn  8740:     my @domcoord = keys(%domcoords);
                   8741:     if (keys(%currhash)) {
                   8742:         foreach my $dc (keys(%currhash)) {
                   8743:             unless (exists($domcoords{$dc})) {
                   8744:                 push(@domcoord,$dc);
                   8745:             }
                   8746:         }
                   8747:     }
                   8748:     @domcoord = sort(@domcoord);
1.210     raeburn  8749:     my $numdcs = scalar(@domcoord);
1.191     raeburn  8750:     my $rows = 0;
                   8751:     my $table;
1.125     raeburn  8752:     if ($numdcs > 1) {
1.191     raeburn  8753:         $table = '<table>';
                   8754:         for (my $i=0; $i<@domcoord; $i++) {
1.125     raeburn  8755:             my $rem = $i%($numinrow);
                   8756:             if ($rem == 0) {
                   8757:                 if ($i > 0) {
1.191     raeburn  8758:                     $table .= '</tr>';
1.125     raeburn  8759:                 }
1.191     raeburn  8760:                 $table .= '<tr>';
                   8761:                 $rows ++;
1.125     raeburn  8762:             }
1.191     raeburn  8763:             my $check = '';
                   8764:             if ($inputtype eq 'radio') {
                   8765:                 if (keys(%currhash) == 0) {
                   8766:                     if (!$i) {
                   8767:                         $check = ' checked="checked"';
                   8768:                     }
                   8769:                 } elsif (exists($currhash{$domcoord[$i]})) {
                   8770:                     $check = ' checked="checked"';
                   8771:                 }
                   8772:             } else {
                   8773:                 if (exists($currhash{$domcoord[$i]})) {
                   8774:                     $check = ' checked="checked"';
1.125     raeburn  8775:                 }
                   8776:             }
1.191     raeburn  8777:             if ($i == @domcoord - 1) {
1.125     raeburn  8778:                 my $colsleft = $numinrow - $rem;
                   8779:                 if ($colsleft > 1) {
1.191     raeburn  8780:                     $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125     raeburn  8781:                 } else {
1.191     raeburn  8782:                     $table .= '<td class="LC_left_item">';
1.125     raeburn  8783:                 }
                   8784:             } else {
1.191     raeburn  8785:                 $table .= '<td class="LC_left_item">';
                   8786:             }
                   8787:             my ($dcname,$dcdom) = split(':',$domcoord[$i]);
                   8788:             my $user = &Apache::loncommon::plainname($dcname,$dcdom);
                   8789:             $table .= '<span class="LC_nobreak"><label>'.
                   8790:                       '<input type="'.$inputtype.'" name="'.$name.'"'.
                   8791:                       ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
                   8792:             if ($user ne $dcname.':'.$dcdom) {
                   8793:                 $table .=  ' ('.$dcname.':'.$dcdom.')'.
                   8794:                            '</label></span></td>';
                   8795:             }
                   8796:         }
                   8797:         $table .= '</tr></table>';
                   8798:     } elsif ($numdcs == 1) {
                   8799:         if ($inputtype eq 'radio') {
                   8800:             $table .= '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />';
                   8801:         } else {
                   8802:             my $check;
                   8803:             if (exists($currhash{$domcoord[0]})) {
                   8804:                 $check = ' checked="checked"';
1.125     raeburn  8805:             }
1.191     raeburn  8806:             $table .= '<input type="checkbox" name="'.$name.'" '.
                   8807:                       'value="'.$domcoord[0].'"'.$check.' />';
                   8808:             $rows ++;
1.125     raeburn  8809:         }
                   8810:     }
1.191     raeburn  8811:     return ($numdcs,$table,$rows);
1.125     raeburn  8812: }
                   8813: 
1.137     raeburn  8814: sub usersession_titles {
                   8815:     return &Apache::lonlocal::texthash(
                   8816:                hosted => 'Hosting of sessions for users from other domains on servers in this domain',
                   8817:                remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145     raeburn  8818:                spares => 'Servers offloaded to, when busy',
1.137     raeburn  8819:                version => 'LON-CAPA version requirement',
1.138     raeburn  8820:                excludedomain => 'Allow all, but exclude specific domains',
                   8821:                includedomain => 'Deny all, but include specific domains',
1.145     raeburn  8822:                primary => 'Primary (checked first)',
1.154     raeburn  8823:                default => 'Default',
1.137     raeburn  8824:            );
                   8825: }
                   8826: 
1.152     raeburn  8827: sub id_for_thisdom {
                   8828:     my (%servers) = @_;
                   8829:     my %altids;
                   8830:     foreach my $server (keys(%servers)) {
                   8831:         my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
                   8832:         if ($serverhome ne $server) {
                   8833:             $altids{$serverhome} = $server;
                   8834:         }
                   8835:     }
                   8836:     return %altids;
                   8837: }
                   8838: 
1.150     raeburn  8839: sub count_servers {
                   8840:     my ($currbalancer,%servers) = @_;
                   8841:     my (@spares,$numspares);
                   8842:     foreach my $lonhost (sort(keys(%servers))) {
                   8843:         next if ($currbalancer eq $lonhost);
                   8844:         push(@spares,$lonhost);
                   8845:     }
                   8846:     if ($currbalancer) {
                   8847:         $numspares = scalar(@spares);
                   8848:     } else {
                   8849:         $numspares = scalar(@spares) - 1;
                   8850:     }
                   8851:     return ($numspares,@spares);
                   8852: }
                   8853: 
                   8854: sub lonbalance_targets_js {
1.171     raeburn  8855:     my ($dom,$types,$servers,$settings) = @_;
1.150     raeburn  8856:     my $select = &mt('Select');
                   8857:     my ($alltargets,$allishome,$allinsttypes,@alltypes);
                   8858:     if (ref($servers) eq 'HASH') {
                   8859:         $alltargets = join("','",sort(keys(%{$servers})));
                   8860:         my @homedoms;
                   8861:         foreach my $server (sort(keys(%{$servers}))) {
                   8862:             if (&Apache::lonnet::host_domain($server) eq $dom) {
                   8863:                 push(@homedoms,'1');
                   8864:             } else {
                   8865:                 push(@homedoms,'0');
                   8866:             }
                   8867:         }
                   8868:         $allishome = join("','",@homedoms);
                   8869:     }
                   8870:     if (ref($types) eq 'ARRAY') {
                   8871:         if (@{$types} > 0) {
                   8872:             @alltypes = @{$types};
                   8873:         }
                   8874:     }
                   8875:     push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
                   8876:     $allinsttypes = join("','",@alltypes);
1.171     raeburn  8877:     my (%currbalancer,%currtargets,%currrules,%existing);
                   8878:     if (ref($settings) eq 'HASH') {
                   8879:         %existing = %{$settings};
                   8880:     }
                   8881:     &get_loadbalancers_config($servers,\%existing,\%currbalancer,
                   8882:                               \%currtargets,\%currrules);
1.210     raeburn  8883:     my $balancers = join("','",sort(keys(%currbalancer)));
1.150     raeburn  8884:     return <<"END";
                   8885: 
                   8886: <script type="text/javascript">
                   8887: // <![CDATA[
                   8888: 
1.171     raeburn  8889: currBalancers = new Array('$balancers');
                   8890: 
                   8891: function toggleTargets(balnum) {
                   8892:     var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
                   8893:     var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
                   8894:     var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
                   8895:     var prevbalancer = prevhostitem.value;
                   8896:     var baltotal = document.getElementById('loadbalancing_total').value;
                   8897:     prevhostitem.value = balancer;
                   8898:     if (prevbalancer != '') {
                   8899:         var prevIdx = currBalancers.indexOf(prevbalancer);
                   8900:         if (prevIdx != -1) {
                   8901:             currBalancers.splice(prevIdx,1);
                   8902:         }
                   8903:     }
1.150     raeburn  8904:     if (balancer == '') {
1.171     raeburn  8905:         hideSpares(balnum);
1.150     raeburn  8906:     } else {
1.171     raeburn  8907:         var currIdx = currBalancers.indexOf(balancer);
                   8908:         if (currIdx == -1) {
                   8909:             currBalancers.push(balancer);
                   8910:         }
1.150     raeburn  8911:         var homedoms = new Array('$allishome');
1.171     raeburn  8912:         var ishomedom = homedoms[lonhostitem.selectedIndex];
                   8913:         showSpares(balancer,ishomedom,balnum);
1.150     raeburn  8914:     }
1.171     raeburn  8915:     balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150     raeburn  8916:     return;
                   8917: }
                   8918: 
1.171     raeburn  8919: function showSpares(balancer,ishomedom,balnum) {
1.150     raeburn  8920:     var alltargets = new Array('$alltargets');
                   8921:     var insttypes = new Array('$allinsttypes');
1.151     raeburn  8922:     var offloadtypes = new Array('primary','default');
                   8923: 
1.171     raeburn  8924:     document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
                   8925:     document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152     raeburn  8926:  
1.151     raeburn  8927:     for (var i=0; i<offloadtypes.length; i++) {
                   8928:         var count = 0;
                   8929:         for (var j=0; j<alltargets.length; j++) {
                   8930:             if (alltargets[j] != balancer) {
1.171     raeburn  8931:                 var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
                   8932:                 item.value = alltargets[j];
                   8933:                 item.style.textAlign='left';
                   8934:                 item.style.textFace='normal';
                   8935:                 document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
                   8936:                 if (currBalancers.indexOf(alltargets[j]) == -1) {
                   8937:                     item.disabled = '';
                   8938:                 } else {
                   8939:                     item.disabled = 'disabled';
                   8940:                     item.checked = false;
                   8941:                 }
1.151     raeburn  8942:                 count ++;
                   8943:             }
1.150     raeburn  8944:         }
                   8945:     }
1.151     raeburn  8946:     for (var k=0; k<insttypes.length; k++) {
                   8947:         if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150     raeburn  8948:             if (ishomedom == 1) {
1.171     raeburn  8949:                 document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
                   8950:                 document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150     raeburn  8951:             } else {
1.171     raeburn  8952:                 document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
                   8953:                 document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150     raeburn  8954:             }
                   8955:         } else {
1.171     raeburn  8956:             document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
                   8957:             document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150     raeburn  8958:         }
1.151     raeburn  8959:         if ((insttypes[k] != '_LC_external') && 
                   8960:             ((insttypes[k] != '_LC_internetdom') ||
                   8961:              ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171     raeburn  8962:             var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
                   8963:             item.options.length = 0;
                   8964:             item.options[0] = new Option("","",true,true);
1.210     raeburn  8965:             var idx = 0;
1.151     raeburn  8966:             for (var m=0; m<alltargets.length; m++) {
1.171     raeburn  8967:                 if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
                   8968:                     idx ++;
                   8969:                     item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150     raeburn  8970:                 }
                   8971:             }
                   8972:         }
                   8973:     }
                   8974:     return;
                   8975: }
                   8976: 
1.171     raeburn  8977: function hideSpares(balnum) {
1.150     raeburn  8978:     var alltargets = new Array('$alltargets');
                   8979:     var insttypes = new Array('$allinsttypes');
                   8980:     var offloadtypes = new Array('primary','default');
                   8981: 
1.171     raeburn  8982:     document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
                   8983:     document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150     raeburn  8984: 
                   8985:     var total = alltargets.length - 1;
                   8986:     for (var i=0; i<offloadtypes; i++) {
                   8987:         for (var j=0; j<total; j++) {
1.171     raeburn  8988:            document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
                   8989:            document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
                   8990:            document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151     raeburn  8991:         }
1.150     raeburn  8992:     }
                   8993:     for (var k=0; k<insttypes.length; k++) {
1.171     raeburn  8994:         document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
                   8995:         document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151     raeburn  8996:         if (insttypes[k] != '_LC_external') {
1.171     raeburn  8997:             document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
                   8998:             document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150     raeburn  8999:         }
                   9000:     }
                   9001:     return;
                   9002: }
                   9003: 
1.171     raeburn  9004: function checkOffloads(item,balnum,type) {
1.150     raeburn  9005:     var alltargets = new Array('$alltargets');
                   9006:     var offloadtypes = new Array('primary','default');
                   9007:     if (item.checked) {
                   9008:         var total = alltargets.length - 1;
                   9009:         var other;
                   9010:         if (type == offloadtypes[0]) {
1.151     raeburn  9011:             other = offloadtypes[1];
1.150     raeburn  9012:         } else {
1.151     raeburn  9013:             other = offloadtypes[0];
1.150     raeburn  9014:         }
                   9015:         for (var i=0; i<total; i++) {
1.171     raeburn  9016:             var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150     raeburn  9017:             if (server == item.value) {
1.171     raeburn  9018:                 if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
                   9019:                     document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150     raeburn  9020:                 }
                   9021:             }
                   9022:         }
                   9023:     }
                   9024:     return;
                   9025: }
                   9026: 
1.171     raeburn  9027: function singleServerToggle(balnum,type) {
                   9028:     var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150     raeburn  9029:     if (offloadtoSelIdx == 0) {
1.171     raeburn  9030:         document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
                   9031:         document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150     raeburn  9032: 
                   9033:     } else {
1.171     raeburn  9034:         document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
                   9035:         document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150     raeburn  9036:     }
                   9037:     return;
                   9038: }
                   9039: 
1.171     raeburn  9040: function balanceruleChange(formname,balnum,type) {
1.150     raeburn  9041:     if (type == '_LC_external') {
1.171     raeburn  9042:         return;
1.150     raeburn  9043:     }
1.171     raeburn  9044:     var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150     raeburn  9045:     for (var i=0; i<typesRules.length; i++) {
                   9046:         if (formname.elements[typesRules[i]].checked) {
                   9047:             if (formname.elements[typesRules[i]].value != 'specific') {
1.171     raeburn  9048:                 document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
                   9049:                 document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150     raeburn  9050:             } else {
1.171     raeburn  9051:                 document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
                   9052:             }
                   9053:         }
                   9054:     }
                   9055:     return;
                   9056: }
                   9057: 
                   9058: function balancerDeleteChange(balnum) {
                   9059:     var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
                   9060:     var baltotal = document.getElementById('loadbalancing_total').value;
                   9061:     var addtarget;
                   9062:     var removetarget;
                   9063:     var action = 'delete';
                   9064:     if (document.getElementById('loadbalancing_delete_'+balnum)) {
                   9065:         var lonhost = hostitem.value;
                   9066:         var currIdx = currBalancers.indexOf(lonhost);
                   9067:         if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
                   9068:             if (currIdx != -1) {
                   9069:                 currBalancers.splice(currIdx,1);
                   9070:             }
                   9071:             addtarget = lonhost;
                   9072:         } else {
                   9073:             if (currIdx == -1) {
                   9074:                 currBalancers.push(lonhost);
                   9075:             }
                   9076:             removetarget = lonhost;
                   9077:             action = 'undelete';
                   9078:         }
                   9079:         balancerChange(balnum,baltotal,action,addtarget,removetarget);
                   9080:     }
                   9081:     return;
                   9082: }
                   9083: 
                   9084: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
                   9085:     if (baltotal > 1) {
                   9086:         var offloadtypes = new Array('primary','default');
                   9087:         var alltargets = new Array('$alltargets');
                   9088:         var insttypes = new Array('$allinsttypes');
                   9089:         for (var i=0; i<baltotal; i++) {
                   9090:             if (i != balnum) {
                   9091:                 for (var j=0; j<offloadtypes.length; j++) {
                   9092:                     var total = alltargets.length - 1;
                   9093:                     for (var k=0; k<total; k++) {
                   9094:                         var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
                   9095:                         var server = serveritem.value;
                   9096:                         if ((action == 'delete') || (action == 'change' && addtarget != ''))  {
                   9097:                             if (server == addtarget) {
                   9098:                                 serveritem.disabled = '';
                   9099:                             }
                   9100:                         }
                   9101:                         if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
                   9102:                             if (server == removetarget) {
                   9103:                                 serveritem.disabled = 'disabled';
                   9104:                                 serveritem.checked = false;
                   9105:                             }
                   9106:                         }
                   9107:                     }
                   9108:                 }
                   9109:                 for (var j=0; j<insttypes.length; j++) {
                   9110:                     if (insttypes[j] != '_LC_external') {
                   9111:                         if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
                   9112:                             var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
                   9113:                             var currSel = singleserver.selectedIndex;
                   9114:                             var currVal = singleserver.options[currSel].value;
                   9115:                             if ((action == 'delete') || (action == 'change' && addtarget != '')) {
                   9116:                                 var numoptions = singleserver.options.length;
                   9117:                                 var needsnew = 1;
                   9118:                                 for (var k=0; k<numoptions; k++) {
                   9119:                                     if (singleserver.options[k] == addtarget) {
                   9120:                                         needsnew = 0;
                   9121:                                         break;
                   9122:                                     }
                   9123:                                 }
                   9124:                                 if (needsnew == 1) {
                   9125:                                     singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
                   9126:                                 }
                   9127:                             }
                   9128:                             if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
                   9129:                                 singleserver.options.length = 0;
                   9130:                                 if ((currVal) && (currVal != removetarget)) {
                   9131:                                     singleserver.options[0] = new Option("","",false,false);
                   9132:                                 } else {
                   9133:                                     singleserver.options[0] = new Option("","",true,true);
                   9134:                                 }
                   9135:                                 var idx = 0;
                   9136:                                 for (var m=0; m<alltargets.length; m++) {
                   9137:                                     if (currBalancers.indexOf(alltargets[m]) == -1) {
                   9138:                                         idx ++;
                   9139:                                         if (currVal == alltargets[m]) {
                   9140:                                             singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
                   9141:                                         } else {
                   9142:                                             singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
                   9143:                                         }
                   9144:                                     }
                   9145:                                 }
                   9146:                             }
                   9147:                         }
                   9148:                     }
                   9149:                 }
1.150     raeburn  9150:             }
                   9151:         }
                   9152:     }
                   9153:     return;
                   9154: }
                   9155: 
1.152     raeburn  9156: // ]]>
                   9157: </script>
                   9158: 
                   9159: END
                   9160: }
                   9161: 
                   9162: sub new_spares_js {
                   9163:     my @sparestypes = ('primary','default');
                   9164:     my $types = join("','",@sparestypes);
                   9165:     my $select = &mt('Select');
                   9166:     return <<"END";
                   9167: 
                   9168: <script type="text/javascript">
                   9169: // <![CDATA[
                   9170: 
                   9171: function updateNewSpares(formname,lonhost) {
                   9172:     var types = new Array('$types');
                   9173:     var include = new Array();
                   9174:     var exclude = new Array();
                   9175:     for (var i=0; i<types.length; i++) {
                   9176:         var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
                   9177:         for (var j=0; j<spareboxes.length; j++) {
                   9178:             if (formname.elements[spareboxes[j]].checked) {
                   9179:                 exclude.push(formname.elements[spareboxes[j]].value);
                   9180:             } else {
                   9181:                 include.push(formname.elements[spareboxes[j]].value);
                   9182:             }
                   9183:         }
                   9184:     }
                   9185:     for (var i=0; i<types.length; i++) {
                   9186:         var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
                   9187:         var selIdx = newSpare.selectedIndex;
                   9188:         var currnew = newSpare.options[selIdx].value;
                   9189:         var okSpares = new Array();
                   9190:         for (var j=0; j<newSpare.options.length; j++) {
                   9191:             var possible = newSpare.options[j].value;
                   9192:             if (possible != '') {
                   9193:                 if (exclude.indexOf(possible) == -1) {
                   9194:                     okSpares.push(possible);
                   9195:                 } else {
                   9196:                     if (currnew == possible) {
                   9197:                         selIdx = 0;
                   9198:                     }
                   9199:                 }
                   9200:             }
                   9201:         }
                   9202:         for (var k=0; k<include.length; k++) {
                   9203:             if (okSpares.indexOf(include[k]) == -1) {
                   9204:                 okSpares.push(include[k]);
                   9205:             }
                   9206:         }
                   9207:         okSpares.sort();
                   9208:         newSpare.options.length = 0;
                   9209:         if (selIdx == 0) {
                   9210:             newSpare.options[0] = new Option("$select","",true,true);
                   9211:         } else {
                   9212:             newSpare.options[0] = new Option("$select","",false,false);
                   9213:         }
                   9214:         for (var m=0; m<okSpares.length; m++) {
                   9215:             var idx = m+1;
                   9216:             var selThis = 0;
                   9217:             if (selIdx != 0) {
                   9218:                 if (okSpares[m] == currnew) {
                   9219:                     selThis = 1;
                   9220:                 }
                   9221:             }
                   9222:             if (selThis == 1) {
                   9223:                 newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
                   9224:             } else {
                   9225:                 newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
                   9226:             }
                   9227:         }
                   9228:     }
                   9229:     return;
                   9230: }
                   9231: 
                   9232: function checkNewSpares(lonhost,type) {
                   9233:     var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
                   9234:     var chosen =  newSpare.options[newSpare.selectedIndex].value;
                   9235:     if (chosen != '') { 
                   9236:         var othertype;
                   9237:         var othernewSpare;
                   9238:         if (type == 'primary') {
                   9239:             othernewSpare = document.getElementById('newspare_default_'+lonhost);
                   9240:         }
                   9241:         if (type == 'default') {
                   9242:             othernewSpare = document.getElementById('newspare_primary_'+lonhost);
                   9243:         }
                   9244:         if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
                   9245:             othernewSpare.selectedIndex = 0;
                   9246:         }
                   9247:     }
                   9248:     return;
                   9249: }
                   9250: 
                   9251: // ]]>
                   9252: </script>
                   9253: 
                   9254: END
                   9255: 
                   9256: }
                   9257: 
                   9258: sub common_domprefs_js {
                   9259:     return <<"END";
                   9260: 
                   9261: <script type="text/javascript">
                   9262: // <![CDATA[
                   9263: 
1.150     raeburn  9264: function getIndicesByName(formname,item) {
1.152     raeburn  9265:     var group = new Array();
1.150     raeburn  9266:     for (var i=0;i<formname.elements.length;i++) {
                   9267:         if (formname.elements[i].name == item) {
1.152     raeburn  9268:             group.push(formname.elements[i].id);
1.150     raeburn  9269:         }
                   9270:     }
1.152     raeburn  9271:     return group;
1.150     raeburn  9272: }
                   9273: 
                   9274: // ]]>
                   9275: </script>
                   9276: 
                   9277: END
1.152     raeburn  9278: 
1.150     raeburn  9279: }
                   9280: 
1.165     raeburn  9281: sub recaptcha_js {
                   9282:     my %lt = &captcha_phrases();
                   9283:     return <<"END";
                   9284: 
                   9285: <script type="text/javascript">
                   9286: // <![CDATA[
                   9287: 
                   9288: function updateCaptcha(caller,context) {
                   9289:     var privitem;
                   9290:     var pubitem;
                   9291:     var privtext;
                   9292:     var pubtext;
                   9293:     if (document.getElementById(context+'_recaptchapub')) {
                   9294:         pubitem = document.getElementById(context+'_recaptchapub');
                   9295:     } else {
                   9296:         return;
                   9297:     }
                   9298:     if (document.getElementById(context+'_recaptchapriv')) {
                   9299:         privitem = document.getElementById(context+'_recaptchapriv');
                   9300:     } else {
                   9301:         return;
                   9302:     }
                   9303:     if (document.getElementById(context+'_recaptchapubtxt')) {
                   9304:         pubtext = document.getElementById(context+'_recaptchapubtxt');
                   9305:     } else {
                   9306:         return;
                   9307:     }
                   9308:     if (document.getElementById(context+'_recaptchaprivtxt')) {
                   9309:         privtext = document.getElementById(context+'_recaptchaprivtxt');
                   9310:     } else {
                   9311:         return;
                   9312:     }
                   9313:     if (caller.checked) {
                   9314:         if (caller.value == 'recaptcha') {
                   9315:             pubitem.type = 'text';
                   9316:             privitem.type = 'text';
                   9317:             pubitem.size = '40';
                   9318:             privitem.size = '40';
                   9319:             pubtext.innerHTML = "$lt{'pub'}";
                   9320:             privtext.innerHTML = "$lt{'priv'}";
                   9321:         } else {
                   9322:             pubitem.type = 'hidden';
                   9323:             privitem.type = 'hidden';
                   9324:             pubtext.innerHTML = '';
                   9325:             privtext.innerHTML = '';
                   9326:         }
                   9327:     }
                   9328:     return;
                   9329: }
                   9330: 
                   9331: // ]]>
                   9332: </script>
                   9333: 
                   9334: END
                   9335: 
                   9336: }
                   9337: 
1.192     raeburn  9338: sub credits_js {
                   9339:     return <<"END";
                   9340: 
                   9341: <script type="text/javascript">
                   9342: // <![CDATA[
                   9343: 
                   9344: function toggleCredits(domForm) {
                   9345:     if (document.getElementById('credits')) {
                   9346:         creditsitem = document.getElementById('credits');
                   9347:         var creditsLength = domForm.coursecredits.length;
                   9348:         if (creditsLength) {
                   9349:             var currval;
                   9350:             for (var i=0; i<creditsLength; i++) {
                   9351:                 if (domForm.coursecredits[i].checked) {
                   9352:                    currval = domForm.coursecredits[i].value;
                   9353:                 }
                   9354:             }
                   9355:             if (currval == 1) {
                   9356:                 creditsitem.style.display = 'block';
                   9357:             } else {
                   9358:                 creditsitem.style.display = 'none';
                   9359:             }
                   9360:         }
                   9361:     }
                   9362:     return;
                   9363: }
                   9364: 
                   9365: // ]]>
                   9366: </script>
                   9367: 
                   9368: END
                   9369: 
                   9370: }
                   9371: 
1.165     raeburn  9372: sub captcha_phrases {
                   9373:     return &Apache::lonlocal::texthash (
                   9374:                  priv => 'Private key',
                   9375:                  pub  => 'Public key',
                   9376:                  original  => 'original (CAPTCHA)',
                   9377:                  recaptcha => 'successor (ReCAPTCHA)',
                   9378:                  notused   => 'unused',
                   9379:     );
                   9380: }
                   9381: 
1.205     raeburn  9382: sub devalidate_remote_domconfs {
                   9383:     my ($dom) = @_;
                   9384:     my $primary_id = &Apache::lonnet::domain($dom,'primary');
                   9385:     my $intdom = &Apache::lonnet::internet_dom($primary_id);
                   9386:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
                   9387:     my %thismachine;
                   9388:     map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
                   9389:     if (keys(%servers) > 1) {
                   9390:         foreach my $server (keys(%servers)) {
                   9391:             next if ($thismachine{$server});
1.211   ! raeburn  9392:             my $cachekey = &escape('domainconfig').':'.&escape($dom);
        !          9393:             &Apache::lonnet::remote_devalidate_cache($server,[$cachekey]);
1.205     raeburn  9394:         }
                   9395:     }
                   9396:     return;
                   9397: }
                   9398: 
1.3       raeburn  9399: 1;

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