File:  [LON-CAPA] / loncom / interface / domainprefs.pm
Revision 1.137: download - view: text, annotated - select for diffs
Sat Jul 17 20:02:07 2010 UTC (13 years, 11 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- Following the switch to 2.10, domains may prefer that their users do not have sessions hosted on older versions of LON-CAPA.
- Domain Coordinators can control:
  (a) where their users may have sessions hosted (by domain and/or LON-CAPA version).
  (b) which other domains will have user sessions hosted on servers in the domain.

    1: # The LearningOnline Network with CAPA
    2: # Handler to set domain-wide configuration settings
    3: #
    4: # $Id: domainprefs.pm,v 1.137 2010/07/17 20:02:07 raeburn Exp $
    5: #
    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: 
   31: =pod
   32: 
   33: =head1 NAME
   34: 
   35: Apache::domainprefs.pm
   36: 
   37: =head1 SYNOPSIS
   38: 
   39: Handles configuration of a LON-CAPA domain.  
   40: 
   41: This is part of the LearningOnline Network with CAPA project
   42: described at http://www.lon-capa.org.
   43: 
   44: 
   45: =head1 OVERVIEW
   46: 
   47: Each institution using LON-CAPA will typically have a single domain designated 
   48: for use by individuals affliated with the institution.  Accordingly, each domain
   49: may define a default set of logos and a color scheme which can be used to "brand"
   50: the LON-CAPA instance. In addition, an institution will typically have a language
   51: and timezone which are used for the majority of courses.
   52: 
   53: LON-CAPA provides a mechanism to display and modify these defaults, as well as a 
   54: host of other domain-wide settings which determine the types of functionality
   55: available to users and courses in the domain.
   56: 
   57: There is also a mechanism to configure cataloging of courses in the domain, and
   58: controls on the operation of automated processes which govern such things as
   59: roster updates, user directory updates and processing of course requests.
   60: 
   61: The domain coordination manual which is built dynamically on install/update of 
   62: LON-CAPA from the relevant help items provides more information about domain 
   63: configuration.
   64: 
   65: Most of the domain settings are stored in the configuration.db GDBM file which is
   66: housed on the primary library server for the domain in /home/httpd/lonUsers/$dom,
   67: where $dom is the domain.  The configuration.db stores settings in a number of 
   68: frozen hashes of hashes.  In a few cases, domain information must be uploaded to
   69: the domain as files (e.g., image files for logos etc., or plain text files for
   70: bubblesheet formats).  In this case the domainprefs.pm must be running in a user
   71: session hosted on the primary library server in the domain, as these files are 
   72: stored in author space belonging to a special $dom-domainconfig user.   
   73: 
   74: domainprefs.pm in combination with lonconfigsettings.pm will retrieve and display
   75: the current settings, and provides an interface to make modifications.
   76: 
   77: =head1 SUBROUTINES
   78: 
   79: =over
   80: 
   81: =item print_quotas()
   82: 
   83: Inputs: 4 
   84: 
   85: $dom,$settings,$rowtotal,$action.
   86: 
   87: $dom is the domain, $settings is a reference to a hash of current settings for
   88: the current context, $rowtotal is a reference to the scalar used to record the 
   89: number of rows displayed on the page, and $action is the context (either quotas 
   90: or requestcourses).
   91: 
   92: The print_quotas routine was orginally created to display/store information
   93: about default quota sizes for portfolio spaces for the different types of 
   94: institutional affiliation in the domain (e.g., Faculty, Staff, Student etc.), 
   95: but is now also used to manage availability of user tools: 
   96: i.e., blogs, aboutme page, and portfolios, and the course request tool,
   97: used by course owners to request creation of a course.
   98: 
   99: Outputs: 1
  100: 
  101: $datatable  - HTML containing form elements which allow settings to be changed. 
  102: 
  103: In the case of course requests, radio buttons are displayed for each institutional
  104: affiliate type (and also default, and _LC_adv) for each of the course types 
  105: (official, unofficial and community).  In each case the radio buttons allow the 
  106: selection of one of four values:
  107: 
  108: 0, approval, validate, autolimit=N (where N is blank, or a positive integer).
  109: which have the following effects:
  110: 
  111: 0
  112: 
  113: =over
  114: 
  115: - course requests are not allowed for this course types/affiliation
  116: 
  117: =back
  118: 
  119: approval 
  120: 
  121: =over 
  122: 
  123: - course requests must be approved by a Doman Coordinator in the 
  124: course's domain
  125: 
  126: =back
  127: 
  128: validate 
  129: 
  130: =over
  131: 
  132: - an institutional validation (e.g., check requestor is instructor
  133: of record) needs to be passed before the course will be created.  The required
  134: validation is in localenroll.pm on the primary library server for the course 
  135: domain.
  136: 
  137: =back
  138: 
  139: autolimit 
  140: 
  141: =over
  142:  
  143: - course requests will be processed autoatically up to a limit of
  144: N requests for the course type for the particular requestor.
  145: If N is undefined, there is no limit to the number of course requests
  146: which a course owner may submit and have processed automatically. 
  147: 
  148: =back
  149: 
  150: =item modify_quotas() 
  151: 
  152: =back
  153: 
  154: =cut
  155: 
  156: package Apache::domainprefs;
  157: 
  158: use strict;
  159: use Apache::Constants qw(:common :http);
  160: use Apache::lonnet;
  161: use Apache::loncommon();
  162: use Apache::lonhtmlcommon();
  163: use Apache::lonlocal;
  164: use Apache::lonmsg();
  165: use Apache::lonconfigsettings;
  166: use LONCAPA qw(:DEFAULT :match);
  167: use LONCAPA::Enrollment;
  168: use LONCAPA::lonauthcgi();
  169: use File::Copy;
  170: use Locale::Language;
  171: use DateTime::TimeZone;
  172: use DateTime::Locale;
  173: 
  174: sub handler {
  175:     my $r=shift;
  176:     if ($r->header_only) {
  177:         &Apache::loncommon::content_type($r,'text/html');
  178:         $r->send_http_header;
  179:         return OK;
  180:     }
  181: 
  182:     my $context = 'domain';
  183:     my $dom = $env{'request.role.domain'};
  184:     my $domdesc = &Apache::lonnet::domain($dom,'description');
  185:     if (&Apache::lonnet::allowed('mau',$dom)) {
  186:         &Apache::loncommon::content_type($r,'text/html');
  187:         $r->send_http_header;
  188:     } else {
  189:         $env{'user.error.msg'}=
  190:         "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
  191:         return HTTP_NOT_ACCEPTABLE;
  192:     }
  193:     &Apache::lonhtmlcommon::clear_breadcrumbs();
  194:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
  195:                                             ['phase','actions']);
  196:     my $phase = 'pickactions';
  197:     if ( exists($env{'form.phase'}) ) {
  198:         $phase = $env{'form.phase'};
  199:     }
  200:     my %domconfig =
  201:       &Apache::lonnet::get_dom('configuration',['login','rolecolors',
  202:                 'quotas','autoenroll','autoupdate','autocreate',
  203:                 'directorysrch','usercreation','usermodification',
  204:                 'contacts','defaults','scantron','coursecategories',
  205:                 'serverstatuses','requestcourses','helpsettings',
  206:                 'coursedefaults','usersessions'],$dom);
  207:     my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll',
  208:                        'autoupdate','autocreate','directorysrch','contacts',
  209:                        'usercreation','usermodification','scantron',
  210:                        'requestcourses','coursecategories','serverstatuses','helpsettings',
  211:                        'coursedefaults','usersessions');
  212:     my %prefs = (
  213:         'rolecolors' =>
  214:                    { text => 'Default color schemes',
  215:                      help => 'Domain_Configuration_Color_Schemes',
  216:                      header => [{col1 => 'Student Settings',
  217:                                  col2 => '',},
  218:                                 {col1 => 'Coordinator Settings',
  219:                                  col2 => '',},
  220:                                 {col1 => 'Author Settings',
  221:                                  col2 => '',},
  222:                                 {col1 => 'Administrator Settings',
  223:                                  col2 => '',}],
  224:                     },
  225:         'login' =>
  226:                     { text => 'Log-in page options',
  227:                       help => 'Domain_Configuration_Login_Page',
  228:                       header => [{col1 => 'Item',
  229:                                   col2 => '',}],
  230:                     },
  231: 
  232:         'defaults' => 
  233:                     { text => 'Default authentication/language/timezone',
  234:                       help => 'Domain_Configuration_LangTZAuth',
  235:                       header => [{col1 => 'Setting',
  236:                                   col2 => 'Value'}],
  237:                     },
  238:         'quotas' => 
  239:                     { text => 'User blogs, personal information pages, portfolios',
  240:                       help => 'Domain_Configuration_Quotas',
  241:                       header => [{col1 => 'User affiliation',
  242:                                   col2 => 'Available tools',
  243:                                   col3 => 'Portfolio quota',}],
  244:                     },
  245:         'autoenroll' =>
  246:                    { text => 'Auto-enrollment settings',
  247:                      help => 'Domain_Configuration_Auto_Enrollment',
  248:                      header => [{col1 => 'Configuration setting',
  249:                                  col2 => 'Value(s)'}],
  250:                    },
  251:         'autoupdate' => 
  252:                    { text => 'Auto-update settings',
  253:                      help => 'Domain_Configuration_Auto_Updates',
  254:                      header => [{col1 => 'Setting',
  255:                                  col2 => 'Value',},
  256:                                 {col1 => 'Setting',
  257:                                  col2 => 'Affiliation'},
  258:                                 {col1 => 'User population',
  259:                                  col2 => 'Updateable user data'}],
  260:                   },
  261:         'autocreate' => 
  262:                   { text => 'Auto-course creation settings',
  263:                      help => 'Domain_Configuration_Auto_Creation',
  264:                      header => [{col1 => 'Configuration Setting',
  265:                                  col2 => 'Value',}],
  266:                   },
  267:         'directorysrch' => 
  268:                   { text => 'Institutional directory searches',
  269:                     help => 'Domain_Configuration_InstDirectory_Search',
  270:                     header => [{col1 => 'Setting',
  271:                                 col2 => 'Value',}],
  272:                   },
  273:         'contacts' =>
  274:                   { text => 'Contact Information',
  275:                     help => 'Domain_Configuration_Contact_Info',
  276:                     header => [{col1 => 'Setting',
  277:                                 col2 => 'Value',}],
  278:                   },
  279: 
  280:         'usercreation' => 
  281:                   { text => 'User creation',
  282:                     help => 'Domain_Configuration_User_Creation',
  283:                     header => [{col1 => 'Format rule type',
  284:                                 col2 => 'Format rules in force'},
  285:                                {col1 => 'User account creation',
  286:                                 col2 => 'Usernames which may be created',},
  287:                                {col1 => 'Context',
  288:                                 col2 => 'Assignable authentication types'}],
  289:                   },
  290:         'usermodification' =>
  291:                   { text => 'User modification',
  292:                     help => 'Domain_Configuration_User_Modification',
  293:                     header => [{col1 => 'Target user has role',
  294:                                 col2 => 'User information updateable in author context'},
  295:                                {col1 => 'Target user has role',
  296:                                 col2 => 'User information updateable in course context'},
  297:                                {col1 => "Status of user",
  298:                                 col2 => 'Information settable when self-creating account (if directory data blank)'}],
  299:                   },
  300:         'scantron' =>
  301:                   { text => 'Bubblesheet format file',
  302:                     help => 'Domain_Configuration_Scantron_Format',
  303:                     header => [ {col1 => 'Item',
  304:                                  col2 => '',
  305:                               }],
  306:                   },
  307:         'requestcourses' => 
  308:                  {text => 'Request creation of courses',
  309:                   help => 'Domain_Configuration_Request_Courses',
  310:                   header => [{col1 => 'User affiliation',
  311:                               col2 => 'Availability/Processing of requests',},
  312:                              {col1 => 'Setting',
  313:                               col2 => 'Value'}],
  314:                  },
  315:         'coursecategories' =>
  316:                   { text => 'Cataloging of courses/communities',
  317:                     help => 'Domain_Configuration_Cataloging_Courses',
  318:                     header => [{col1 => 'Category settings',
  319:                                 col2 => '',},
  320:                                {col1 => 'Categories',
  321:                                 col2 => '',
  322:                                }],
  323:                   },
  324:         'serverstatuses' =>
  325:                  {text   => 'Access to server status pages',
  326:                   help   => 'Domain_Configuration_Server_Status',
  327:                   header => [{col1 => 'Status Page',
  328:                               col2 => 'Other named users',
  329:                               col3 => 'Specific IPs',
  330:                             }],
  331:                  },
  332:         'helpsettings' =>
  333:                  {text   => 'Help page settings',
  334:                   help   => 'Domain_Configuration_Help_Settings',
  335:                   header => [{col1 => 'Authenticated Help Settings',
  336:                               col2 => ''},
  337:                              {col1 => 'Unauthenticated Help Settings',
  338:                               col2 => ''}],
  339:                  },
  340:         'coursedefaults' => 
  341:                  {text => 'Course/Community defaults',
  342:                   help => 'Domain_Configuration_Course_Defaults',
  343:                   header => [{col1 => 'Setting',
  344:                               col2 => 'Value',}],
  345:                  },
  346:         'privacy' => 
  347:                  {text   => 'User Privacy',
  348:                   help   => 'Domain_Configuration_User_Privacy',
  349:                   header => [{col1 => 'Setting',
  350:                               col2 => 'Value',}],
  351:                  },
  352:          'usersessions' =>
  353:                  {text  => 'User session hosting',
  354:                   help  => 'Domain_Configuration_User_Sessions',
  355:                   header => [{col1 => 'Hosting of users from other domains',
  356:                               col2 => 'Rules'},
  357:                              {col1 => "Hosting domain's own users elsewhere",
  358:                               col2 => 'Rules'}],
  359:                  },
  360:     );
  361:     my %servers = &dom_servers($dom);
  362:     if (keys(%servers) > 1) {
  363:         $prefs{'login'}  = { text   => 'Log-in page options',
  364:                              help   => 'Domain_Configuration_Login_Page',
  365:                             header => [{col1 => 'Log-in Service',
  366:                                         col2 => 'Server Setting',},
  367:                                        {col1 => 'Log-in Page Items',
  368:                                         col2 => ''}],
  369:                            };
  370:     }
  371:     my @roles = ('student','coordinator','author','admin');
  372:     my @actions = &Apache::loncommon::get_env_multiple('form.actions');
  373:     &Apache::lonhtmlcommon::add_breadcrumb
  374:     ({href=>"javascript:changePage(document.$phase,'pickactions')",
  375:       text=>"Settings to display/modify"});
  376:     my $confname = $dom.'-domainconfig';
  377:     if ($phase eq 'process') {
  378:         &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,\@roles);
  379:     } elsif ($phase eq 'display') {
  380:         &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname);
  381:     } else {
  382:         if (keys(%domconfig) == 0) {
  383:             my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
  384:             my @ids=&Apache::lonnet::current_machine_ids();
  385:             if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
  386:                 my %designhash = &Apache::loncommon::get_domainconf($dom);
  387:                 my @loginimages = ('img','logo','domlogo','login');
  388:                 my $custom_img_count = 0;
  389:                 foreach my $img (@loginimages) {
  390:                     if ($designhash{$dom.'.login.'.$img} ne '') {
  391:                         $custom_img_count ++;
  392:                     }
  393:                 }
  394:                 foreach my $role (@roles) {
  395:                     if ($designhash{$dom.'.'.$role.'.img'} ne '') {
  396:                         $custom_img_count ++;
  397:                     }
  398:                 }
  399:                 if ($custom_img_count > 0) {
  400:                     &Apache::lonconfigsettings::print_header($r,$phase,$context);
  401:                     my $switch_server = &check_switchserver($dom,$confname);
  402:                     $r->print(
  403:     &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
  404:     &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
  405:     &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 />'.
  406:     &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
  407:                     if ($switch_server) {
  408:                         $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
  409:                     }
  410:                     $r->print(&Apache::loncommon::end_page());
  411:                     return OK;
  412:                 }
  413:             }
  414:         }
  415:         &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
  416:     }
  417:     return OK;
  418: }
  419: 
  420: sub process_changes {
  421:     my ($r,$dom,$confname,$action,$roles,$values) = @_;
  422:     my %domconfig;
  423:     if (ref($values) eq 'HASH') {
  424:         %domconfig = %{$values};
  425:     }
  426:     my $output;
  427:     if ($action eq 'login') {
  428:         $output = &modify_login($r,$dom,$confname,%domconfig);
  429:     } elsif ($action eq 'rolecolors') {
  430:         $output = &modify_rolecolors($r,$dom,$confname,$roles,
  431:                                      %domconfig);
  432:     } elsif ($action eq 'quotas') {
  433:         $output = &modify_quotas($dom,$action,%domconfig);
  434:     } elsif ($action eq 'autoenroll') {
  435:         $output = &modify_autoenroll($dom,%domconfig);
  436:     } elsif ($action eq 'autoupdate') {
  437:         $output = &modify_autoupdate($dom,%domconfig);
  438:     } elsif ($action eq 'autocreate') {
  439:         $output = &modify_autocreate($dom,%domconfig);
  440:     } elsif ($action eq 'directorysrch') {
  441:         $output = &modify_directorysrch($dom,%domconfig);
  442:     } elsif ($action eq 'usercreation') {
  443:         $output = &modify_usercreation($dom,%domconfig);
  444:     } elsif ($action eq 'usermodification') {
  445:         $output = &modify_usermodification($dom,%domconfig);
  446:     } elsif ($action eq 'contacts') {
  447:         $output = &modify_contacts($dom,%domconfig);
  448:     } elsif ($action eq 'defaults') {
  449:         $output = &modify_defaults($dom,$r);
  450:     } elsif ($action eq 'scantron') {
  451:         $output = &modify_scantron($r,$dom,$confname,%domconfig);
  452:     } elsif ($action eq 'coursecategories') {
  453:         $output = &modify_coursecategories($dom,%domconfig);
  454:     } elsif ($action eq 'serverstatuses') {
  455:         $output = &modify_serverstatuses($dom,%domconfig);
  456:     } elsif ($action eq 'requestcourses') {
  457:         $output = &modify_quotas($dom,$action,%domconfig);
  458:     } elsif ($action eq 'helpsettings') {
  459:         $output = &modify_helpsettings($r,$dom,$confname,%domconfig);
  460:     } elsif ($action eq 'coursedefaults') {
  461:         $output = &modify_coursedefaults($dom,%domconfig);
  462:     } elsif ($action eq 'usersessions') {
  463:         $output = &modify_usersessions($dom,%domconfig);
  464:     }
  465:     return $output;
  466: }
  467: 
  468: sub print_config_box {
  469:     my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
  470:     my $rowtotal = 0;
  471:     my $output;
  472:     if ($action eq 'coursecategories') {
  473:         $output = &coursecategories_javascript($settings);
  474:     }
  475:     $output .= 
  476:          '<table class="LC_nested_outer">
  477:           <tr>
  478:            <th align="left" valign="middle"><span class="LC_nobreak">'.
  479:            &mt($item->{text}).'&nbsp;'.
  480:            &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
  481:           '</tr>';
  482:     $rowtotal ++;
  483:     my $numheaders = 1;
  484:     if (ref($item->{'header'}) eq 'ARRAY') {
  485:         $numheaders = scalar(@{$item->{'header'}});
  486:     }
  487:     if ($numheaders > 1) {
  488:         my $colspan = '';
  489:         if (($action eq 'rolecolors') || ($action eq 'coursecategories') || ($action eq 'helpsettings')) {
  490:             $colspan = ' colspan="2"';
  491:         }
  492:         $output .= '
  493:           <tr>
  494:            <td>
  495:             <table class="LC_nested">
  496:              <tr class="LC_info_row">
  497:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
  498:               <td class="LC_right_item">'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
  499:              </tr>';
  500:         $rowtotal ++;
  501:         if ($action eq 'autoupdate') {
  502:             $output .= &print_autoupdate('top',$dom,$settings,\$rowtotal);
  503:         } elsif ($action eq 'usercreation') {
  504:             $output .= &print_usercreation('top',$dom,$settings,\$rowtotal);
  505:         } elsif ($action eq 'usermodification') {
  506:             $output .= &print_usermodification('top',$dom,$settings,\$rowtotal);
  507:         } elsif ($action eq 'coursecategories') {
  508:             $output .= &print_coursecategories('top',$dom,$item,$settings,\$rowtotal);
  509:         } elsif ($action eq 'login') {
  510:             $output .= &print_login('top',$dom,$confname,$phase,$settings,\$rowtotal);
  511:             $colspan = ' colspan="2"';
  512:         } elsif ($action eq 'requestcourses') {
  513:             $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
  514:         } elsif ($action eq 'helpsettings') {
  515:             $output .= &print_helpsettings('top',$dom,$confname,$settings,\$rowtotal);
  516:         } elsif ($action eq 'usersessions') {
  517:             $output .= &print_usersessions('top',$dom,$settings,\$rowtotal); 
  518:         } elsif ($action eq 'rolecolors') {
  519:             $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
  520:         }
  521:         $output .= '
  522:            </table>
  523:           </td>
  524:          </tr>
  525:          <tr>
  526:            <td>
  527:             <table class="LC_nested">
  528:              <tr class="LC_info_row">
  529:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>';
  530:         $output .= '
  531:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
  532:              </tr>';
  533:             $rowtotal ++;
  534:         if ($action eq 'autoupdate') {
  535:             $output .= &print_autoupdate('middle',$dom,$settings,\$rowtotal).'
  536:            </table>
  537:           </td>
  538:          </tr>
  539:          <tr>
  540:            <td>
  541:             <table class="LC_nested">
  542:              <tr class="LC_info_row">
  543:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
  544:               <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>      </tr>'.
  545:             &print_autoupdate('bottom',$dom,$settings,\$rowtotal);
  546:             $rowtotal ++;
  547:         } elsif ($action eq 'usercreation') {
  548:             $output .= &print_usercreation('middle',$dom,$settings,\$rowtotal).'
  549:            </table>
  550:           </td>
  551:          </tr>
  552:          <tr>
  553:            <td>
  554:             <table class="LC_nested">
  555:              <tr class="LC_info_row">
  556:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
  557:               <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>             </tr>'.
  558:             &print_usercreation('bottom',$dom,$settings,\$rowtotal);
  559:             $rowtotal ++;
  560:         } elsif ($action eq 'usermodification') {
  561:             $output .= &print_usermodification('middle',$dom,$settings,\$rowtotal).'
  562:            </table>
  563:           </td>
  564:          </tr>
  565:          <tr>
  566:            <td>
  567:             <table class="LC_nested">
  568:              <tr class="LC_info_row">
  569:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
  570:               <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>      </tr>'.
  571:                        &print_usermodification('bottom',$dom,$settings,\$rowtotal);
  572:             $rowtotal ++;
  573:         } elsif ($action eq 'coursecategories') {
  574:             $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
  575:         } elsif ($action eq 'login') {
  576:             $output .= &print_login('bottom',$dom,$confname,$phase,$settings,\$rowtotal);
  577:         } elsif ($action eq 'requestcourses') {
  578:             $output .= &print_courserequestmail($dom,$settings,\$rowtotal);
  579:         } elsif ($action eq 'helpsettings') {
  580:             $output .= &print_helpsettings('bottom',$dom,$confname,$settings,\$rowtotal);
  581:         } elsif ($action eq 'usersessions') {
  582:             $output .= &print_usersessions('bottom',$dom,$settings,\$rowtotal);
  583:         } elsif ($action eq 'rolecolors') {
  584:             $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
  585:            </table>
  586:           </td>
  587:          </tr>
  588:          <tr>
  589:            <td>
  590:             <table class="LC_nested">
  591:              <tr class="LC_info_row">
  592:               <td class="LC_left_item"'.$colspan.' valign="top">'.
  593:                &mt($item->{'header'}->[2]->{'col1'}).'</td>
  594:               <td class="LC_right_item" valign="top">'.
  595:                &mt($item->{'header'}->[2]->{'col2'}).'</td>
  596:              </tr>'.
  597:             &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
  598:            </table>
  599:           </td>
  600:          </tr>
  601:          <tr>
  602:            <td>
  603:             <table class="LC_nested">
  604:              <tr class="LC_info_row">
  605:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
  606:               <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
  607:              </tr>'.
  608:             &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
  609:             $rowtotal += 2;
  610:         }
  611:     } else {
  612:         $output .= '
  613:           <tr>
  614:            <td>
  615:             <table class="LC_nested">
  616:              <tr class="LC_info_row">';
  617:         if (($action eq 'login') || ($action eq 'directorysrch')) {
  618:             $output .= '  
  619:               <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
  620:         } elsif ($action eq 'serverstatuses') {
  621:             $output .= '
  622:               <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
  623:               '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
  624: 
  625:         } else {
  626:             $output .= '
  627:               <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
  628:         }
  629:         if (defined($item->{'header'}->[0]->{'col3'})) {
  630:             $output .= '<td class="LC_left_item" valign="top">'.
  631:                        &mt($item->{'header'}->[0]->{'col2'});
  632:             if ($action eq 'serverstatuses') {
  633:                 $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
  634:             } 
  635:         } else {
  636:             $output .= '<td class="LC_right_item" valign="top">'.
  637:                        &mt($item->{'header'}->[0]->{'col2'});
  638:         }
  639:         $output .= '</td>';
  640:         if ($item->{'header'}->[0]->{'col3'}) {
  641:             $output .= '<td class="LC_right_item" valign="top">'.
  642:                        &mt($item->{'header'}->[0]->{'col3'});
  643:             if ($action eq 'serverstatuses') {
  644:                 $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
  645:             }
  646:             $output .= '</td>';
  647:         }
  648:         $output .= '</tr>';
  649:         $rowtotal ++;
  650:         if ($action eq 'login') {
  651:             $output .= &print_login('bottom',$dom,$confname,$phase,$settings,
  652:                                     \$rowtotal);
  653:         } elsif ($action eq 'quotas') {
  654:             $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
  655:         } elsif ($action eq 'autoenroll') {
  656:             $output .= &print_autoenroll($dom,$settings,\$rowtotal);
  657:         } elsif ($action eq 'autocreate') {
  658:             $output .= &print_autocreate($dom,$settings,\$rowtotal);
  659:         } elsif ($action eq 'directorysrch') {
  660:             $output .= &print_directorysrch($dom,$settings,\$rowtotal);
  661:         } elsif ($action eq 'contacts') {
  662:             $output .= &print_contacts($dom,$settings,\$rowtotal);
  663:         } elsif ($action eq 'defaults') {
  664:             $output .= &print_defaults($dom,\$rowtotal);
  665:         } elsif ($action eq 'scantron') {
  666:             $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
  667:         } elsif ($action eq 'serverstatuses') {
  668:             $output .= &print_serverstatuses($dom,$settings,\$rowtotal);
  669:         } elsif ($action eq 'helpsettings') {
  670:             $output .= &print_helpsettings('top',$dom,$confname,$settings,\$rowtotal);
  671:     	} elsif ($action eq 'coursedefaults') {
  672:             $output .= &print_coursedefaults($dom,$settings,\$rowtotal);
  673:         }
  674:     }
  675:     $output .= '
  676:    </table>
  677:   </td>
  678:  </tr>
  679: </table><br />';
  680:     return ($output,$rowtotal);
  681: }
  682: 
  683: sub print_login {
  684:     my ($position,$dom,$confname,$phase,$settings,$rowtotal) = @_;
  685:     my ($css_class,$datatable);
  686:     my %choices = &login_choices();
  687: 
  688:     if ($position eq 'top') {
  689:         my %servers = &dom_servers($dom);
  690:         my $choice = $choices{'disallowlogin'};
  691:         $css_class = ' class="LC_odd_row"';
  692:         $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
  693:                       '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
  694:                       '<th>'.$choices{'server'}.'</th>'.
  695:                       '<th>'.$choices{'serverpath'}.'</th>'.
  696:                       '<th>'.$choices{'custompath'}.'</th>'.
  697:                       '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
  698:         my %disallowed;
  699:         if (ref($settings) eq 'HASH') {
  700:             if (ref($settings->{'loginvia'}) eq 'HASH') {
  701:                %disallowed = %{$settings->{'loginvia'}};
  702:             }
  703:         }
  704:         foreach my $lonhost (sort(keys(%servers))) {
  705:             my $direct = 'selected="selected"';
  706:             if (ref($disallowed{$lonhost}) eq 'HASH') {
  707:                 if ($disallowed{$lonhost}{'server'} ne '') {
  708:                     $direct = '';
  709:                 }
  710:             }
  711:             $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
  712:                           '<td><select name="'.$lonhost.'_server">'.
  713:                           '<option value=""'.$direct.'>'.$choices{'directlogin'}.
  714:                           '</option>';
  715:             foreach my $hostid (keys(%servers)) {
  716:                 next if ($servers{$hostid} eq $servers{$lonhost});
  717:                 my $selected = '';
  718:                 if (ref($disallowed{$lonhost}) eq 'HASH') {
  719:                     if ($hostid eq $disallowed{$lonhost}{'server'}) {
  720:                         $selected = 'selected="selected"';
  721:                     }
  722:                 }
  723:                 $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
  724:                               $servers{$hostid}.'</option>';
  725:             }
  726:             $datatable .= '</select></td>'.
  727:                           '<td><select name="'.$lonhost.'_serverpath">';
  728:             foreach my $path ('','/','/adm/login','/adm/roles','custom') {
  729:                 my $pathname = $path;
  730:                 if ($path eq 'custom') {
  731:                     $pathname = &mt('Custom Path').' ->';
  732:                 }
  733:                 my $selected = '';
  734:                 if (ref($disallowed{$lonhost}) eq 'HASH') {
  735:                     if ($path eq $disallowed{$lonhost}{'serverpath'}) {
  736:                         $selected = 'selected="selected"';
  737:                     }
  738:                 } elsif ($path eq '') {
  739:                     $selected = 'selected="selected"';
  740:                 }
  741:                 $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
  742:             }
  743:             $datatable .= '</select></td>';
  744:             my ($custom,$exempt);
  745:             if (ref($disallowed{$lonhost}) eq 'HASH') {
  746:                 $custom = $disallowed{$lonhost}{'custompath'};
  747:                 $exempt = $disallowed{$lonhost}{'exempt'};
  748:             }
  749:             $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
  750:                           '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
  751:                           '</tr>';
  752:         }
  753:         $datatable .= '</table></td></tr>';
  754:         return $datatable;
  755:     }
  756: 
  757:     my %defaultchecked = ( 
  758:                            'coursecatalog' => 'on',
  759:                            'adminmail'     => 'off',
  760:                            'newuser'       => 'off',
  761:                          );
  762:     my @toggles = ('coursecatalog','adminmail','newuser');
  763:     my (%checkedon,%checkedoff);
  764:     foreach my $item (@toggles) {
  765:         if ($defaultchecked{$item} eq 'on') { 
  766:             $checkedon{$item} = ' checked="checked" ';
  767:             $checkedoff{$item} = ' ';
  768:         } elsif ($defaultchecked{$item} eq 'off') {
  769:             $checkedoff{$item} = ' checked="checked" ';
  770:             $checkedon{$item} = ' ';
  771:         }
  772:     }
  773:     my @images = ('img','logo','domlogo','login');
  774:     my @logintext = ('textcol','bgcol');
  775:     my @bgs = ('pgbg','mainbg','sidebg');
  776:     my @links = ('link','alink','vlink');
  777:     my %designhash = &Apache::loncommon::get_domainconf($dom);
  778:     my %defaultdesign = %Apache::loncommon::defaultdesign;
  779:     my (%is_custom,%designs);
  780:     my %defaults = (
  781:                    font => $defaultdesign{'login.font'},
  782:                    );
  783:     foreach my $item (@images) {
  784:         $defaults{$item} = $defaultdesign{'login.'.$item};
  785:         $defaults{'showlogo'}{$item} = 1;
  786:     }
  787:     foreach my $item (@bgs) {
  788:         $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
  789:     }
  790:     foreach my $item (@logintext) {
  791:         $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
  792:     }
  793:     foreach my $item (@links) {
  794:         $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
  795:     }
  796:     if (ref($settings) eq 'HASH') {
  797:         foreach my $item (@toggles) {
  798:             if ($settings->{$item} eq '1') {
  799:                 $checkedon{$item} =  ' checked="checked" ';
  800:                 $checkedoff{$item} = ' ';
  801:             } elsif ($settings->{$item} eq '0') {
  802:                 $checkedoff{$item} =  ' checked="checked" ';
  803:                 $checkedon{$item} = ' ';
  804:             }
  805:         }
  806:         foreach my $item (@images) {
  807:             if (defined($settings->{$item})) {
  808:                 $designs{$item} = $settings->{$item};
  809:                 $is_custom{$item} = 1;
  810:             }
  811:             if (defined($settings->{'showlogo'}{$item})) {
  812:                 $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
  813:             }
  814:         }
  815:         foreach my $item (@logintext) {
  816:             if ($settings->{$item} ne '') {
  817:                 $designs{'logintext'}{$item} = $settings->{$item};
  818:                 $is_custom{$item} = 1;
  819:             }
  820:         }
  821:         if ($settings->{'font'} ne '') {
  822:             $designs{'font'} = $settings->{'font'};
  823:             $is_custom{'font'} = 1;
  824:         }
  825:         foreach my $item (@bgs) {
  826:             if ($settings->{$item} ne '') {
  827:                 $designs{'bgs'}{$item} = $settings->{$item};
  828:                 $is_custom{$item} = 1;
  829:             }
  830:         }
  831:         foreach my $item (@links) {
  832:             if ($settings->{$item} ne '') {
  833:                 $designs{'links'}{$item} = $settings->{$item};
  834:                 $is_custom{$item} = 1;
  835:             }
  836:         }
  837:     } else {
  838:         if ($designhash{$dom.'.login.font'} ne '') {
  839:             $designs{'font'} = $designhash{$dom.'.login.font'};
  840:             $is_custom{'font'} = 1;
  841:         }
  842:         foreach my $item (@images) {
  843:             if ($designhash{$dom.'.login.'.$item} ne '') {
  844:                 $designs{$item} = $designhash{$dom.'.login.'.$item};
  845:                 $is_custom{$item} = 1;
  846:             }
  847:         }
  848:         foreach my $item (@bgs) {
  849:             if ($designhash{$dom.'.login.'.$item} ne '') {
  850:                 $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
  851:                 $is_custom{$item} = 1;
  852:             }
  853:         }
  854:         foreach my $item (@links) {
  855:             if ($designhash{$dom.'.login.'.$item} ne '') {
  856:                 $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
  857:                 $is_custom{$item} = 1;
  858:             }
  859:         }
  860:     }
  861:     my %alt_text = &Apache::lonlocal::texthash  ( img => 'Log-in banner',
  862:                                                   logo => 'Institution Logo',
  863:                                                   domlogo => 'Domain Logo',
  864:                                                   login => 'Login box');
  865:     my $itemcount = 1;
  866:     my ($css_class,$datatable);
  867:     foreach my $item (@toggles) {
  868:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
  869:         $datatable .=  
  870:             '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
  871:             '</td><td>'.
  872:             '<span class="LC_nobreak"><label><input type="radio" name="'.
  873:             $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
  874:             '</label>&nbsp;<label><input type="radio" name="'.$item.'"'.
  875:             $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
  876:             '</tr>';
  877:         $itemcount ++;
  878:     }
  879:     $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
  880:     $datatable .= '</tr></table></td></tr>';
  881:     return $datatable;
  882: }
  883: 
  884: sub login_choices {
  885:     my %choices =
  886:         &Apache::lonlocal::texthash (
  887:             coursecatalog => 'Display Course/Community Catalog link?',
  888:             adminmail     => "Display Administrator's E-mail Address?",
  889:             disallowlogin => "Login page requests redirected",
  890:             hostid        => "Server",
  891:             server        => "Redirect to:",
  892:             serverpath    => "Path",
  893:             custompath    => "Custom", 
  894:             exempt        => "Exempt IP(s)",
  895:             directlogin   => "No redirect",
  896:             newuser       => "Link to create a user account",
  897:             img           => "Header",
  898:             logo          => "Main Logo",
  899:             domlogo       => "Domain Logo",
  900:             login         => "Log-in Header", 
  901:             textcol       => "Text color",
  902:             bgcol         => "Box color",
  903:             bgs           => "Background colors",
  904:             links         => "Link colors",
  905:             font          => "Font color",
  906:             pgbg          => "Header",
  907:             mainbg        => "Page",
  908:             sidebg        => "Login box",
  909:             link          => "Link",
  910:             alink         => "Active link",
  911:             vlink         => "Visited link",
  912:         );
  913:     return %choices;
  914: }
  915: 
  916: sub print_rolecolors {
  917:     my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
  918:     my %choices = &color_font_choices();
  919:     my @bgs = ('pgbg','tabbg','sidebg');
  920:     my @links = ('link','alink','vlink');
  921:     my @images = ('img');
  922:     my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
  923:     my %designhash = &Apache::loncommon::get_domainconf($dom);
  924:     my %defaultdesign = %Apache::loncommon::defaultdesign;
  925:     my (%is_custom,%designs);
  926:     my %defaults = (
  927:                    img => $defaultdesign{$role.'.img'},
  928:                    font => $defaultdesign{$role.'.font'},
  929: 		   fontmenu => $defaultdesign{$role.'.fontmenu'},
  930:                    );
  931:     foreach my $item (@bgs) {
  932:         $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
  933:     }
  934:     foreach my $item (@links) {
  935:         $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
  936:     }
  937:     if (ref($settings) eq 'HASH') {
  938:         if (ref($settings->{$role}) eq 'HASH') {
  939:             if ($settings->{$role}->{'img'} ne '') {
  940:                 $designs{'img'} = $settings->{$role}->{'img'};
  941:                 $is_custom{'img'} = 1;
  942:             }
  943:             if ($settings->{$role}->{'font'} ne '') {
  944:                 $designs{'font'} = $settings->{$role}->{'font'};
  945:                 $is_custom{'font'} = 1;
  946:             }
  947:             if ($settings->{$role}->{'fontmenu'} ne '') {
  948:                 $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
  949:                 $is_custom{'fontmenu'} = 1;
  950:             }
  951:             foreach my $item (@bgs) {
  952:                 if ($settings->{$role}->{$item} ne '') {
  953:                     $designs{'bgs'}{$item} = $settings->{$role}->{$item};
  954:                     $is_custom{$item} = 1;
  955:                 }
  956:             }
  957:             foreach my $item (@links) {
  958:                 if ($settings->{$role}->{$item} ne '') {
  959:                     $designs{'links'}{$item} = $settings->{$role}->{$item};
  960:                     $is_custom{$item} = 1;
  961:                 }
  962:             }
  963:         }
  964:     } else {
  965:         if ($designhash{$dom.'.'.$role.'.img'} ne '') {
  966:             $designs{img} = $designhash{$dom.'.'.$role.'.img'};
  967:             $is_custom{'img'} = 1;
  968:         }
  969:         if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
  970:             $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
  971:             $is_custom{'fontmenu'} = 1; 
  972:         }
  973:         if ($designhash{$dom.'.'.$role.'.font'} ne '') {
  974:             $designs{font} = $designhash{$dom.'.'.$role.'.font'};
  975:             $is_custom{'font'} = 1;
  976:         }
  977:         foreach my $item (@bgs) {
  978:             if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
  979:                 $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
  980:                 $is_custom{$item} = 1;
  981:             
  982:             }
  983:         }
  984:         foreach my $item (@links) {
  985:             if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
  986:                 $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
  987:                 $is_custom{$item} = 1;
  988:             }
  989:         }
  990:     }
  991:     my $itemcount = 1;
  992:     my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
  993:     $datatable .= '</tr></table></td></tr>';
  994:     return $datatable;
  995: }
  996: 
  997: sub display_color_options {
  998:     my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
  999:         $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
 1000:     my $css_class = $itemcount%2?' class="LC_odd_row"':'';
 1001:     my $datatable = '<tr'.$css_class.'>'.
 1002:         '<td>'.$choices->{'font'}.'</td>';
 1003:     if (!$is_custom->{'font'}) {
 1004:         $datatable .=  '<td>'.&mt('Default in use:').'&nbsp;<span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
 1005:     } else {
 1006:         $datatable .= '<td>&nbsp;</td>';
 1007:     }
 1008:     my $fontlink = &color_pick($phase,$role,'font',$choices->{'font'},$designs->{'font'});
 1009:     $datatable .= '<td><span class="LC_nobreak">'.
 1010:                   '<input type="text" size="10" name="'.$role.'_font"'.
 1011:                   ' value="'.$designs->{'font'}.'" />&nbsp;'.$fontlink.
 1012:                   '&nbsp;<span id="css_'.$role.'_font" style="background-color: '.
 1013:                   $designs->{'font'}.';">&nbsp;&nbsp;&nbsp;</span>'.
 1014:                   '</span></td></tr>';
 1015:     unless ($role eq 'login') { 
 1016:         $datatable .= '<tr'.$css_class.'>'.
 1017:                       '<td>'.$choices->{'fontmenu'}.'</td>';
 1018:         if (!$is_custom->{'fontmenu'}) {
 1019:             $datatable .=  '<td>'.&mt('Default in use:').'&nbsp;<span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
 1020:         } else {
 1021:             $datatable .= '<td>&nbsp;</td>';
 1022:         }
 1023:         $fontlink = &color_pick($phase,$role,'fontmenu',$choices->{'fontmenu'},$designs->{'fontmenu'});
 1024:         $datatable .= '<td><span class="LC_nobreak">'.
 1025:                       '<input type="text" size="10" name="'.$role.'_fontmenu"'.
 1026:                       ' value="'.$designs->{'fontmenu'}.'" />&nbsp;'.$fontlink.
 1027:                       '&nbsp;<span id="css_'.$role.'_fontmenu" style="background-color: '.
 1028:                       $designs->{'fontmenu'}.';">&nbsp;&nbsp;&nbsp;</span>'.
 1029:                       '</span></td></tr>';
 1030:     }
 1031:     my $switchserver = &check_switchserver($dom,$confname);
 1032:     foreach my $img (@{$images}) {
 1033: 	$itemcount ++;
 1034:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
 1035:         $datatable .= '<tr'.$css_class.'>'.
 1036:                       '<td>'.$choices->{$img};
 1037:         my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
 1038:         if ($role eq 'login') {
 1039:             if ($img eq 'login') {
 1040:                 $login_hdr_pick =
 1041:                     &login_header_options($img,$role,$defaults,$is_custom,$choices);
 1042:                 $logincolors =
 1043:                     &login_text_colors($img,$role,$logintext,$phase,$choices,
 1044:                                             $designs);
 1045:             } elsif ($img ne 'domlogo') {
 1046:                 $datatable.= &logo_display_options($img,$defaults,$designs);
 1047:             }
 1048:         }
 1049:         $datatable .= '</td>';
 1050:         if ($designs->{$img} ne '') {
 1051:             $imgfile = $designs->{$img};
 1052: 	    $img_import = ($imgfile =~ m{^/adm/});
 1053:         } else {
 1054:             $imgfile = $defaults->{$img};
 1055:         }
 1056:         if ($imgfile) {
 1057:             my ($showfile,$fullsize);
 1058:             if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
 1059:                 my $urldir = $1;
 1060:                 my $filename = $2;
 1061:                 my @info = &Apache::lonnet::stat_file($designs->{$img});
 1062:                 if (@info) {
 1063:                     my $thumbfile = 'tn-'.$filename;
 1064:                     my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
 1065:                     if (@thumb) {
 1066:                         $showfile = $urldir.'/'.$thumbfile;
 1067:                     } else {
 1068:                         $showfile = $imgfile;
 1069:                     }
 1070:                 } else {
 1071:                     $showfile = '';
 1072:                 }
 1073:             } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
 1074:                 $showfile = $imgfile;
 1075:                 my $imgdir = $1;
 1076:                 my $filename = $2;
 1077:                 if (-e "/home/httpd/html/$imgdir/tn-".$filename) {
 1078:                     $showfile = "/$imgdir/tn-".$filename;
 1079:                 } else {
 1080:                     my $input = "/home/httpd/html".$imgfile;
 1081:                     my $output = '/home/httpd/html/'.$imgdir.'/tn-'.$filename;
 1082:                     if (!-e $output) {
 1083:                         my ($width,$height) = &thumb_dimensions();
 1084:                         my ($fullwidth,$fullheight) = &check_dimensions($input);
 1085:                         if ($fullwidth ne '' && $fullheight ne '') {
 1086:                             if ($fullwidth > $width && $fullheight > $height) { 
 1087:                                 my $size = $width.'x'.$height;
 1088:                                 system("convert -sample $size $input $output");
 1089:                                 $showfile = '/'.$imgdir.'/tn-'.$filename;
 1090:                             }
 1091:                         }
 1092:                     }
 1093:                 }
 1094:             }
 1095:             if ($showfile) {
 1096:                 if ($showfile =~ m{^/(adm|res)/}) {
 1097:                     if ($showfile =~ m{^/res/}) {
 1098:                         my $local_showfile =
 1099:                             &Apache::lonnet::filelocation('',$showfile);
 1100:                         &Apache::lonnet::repcopy($local_showfile);
 1101:                     }
 1102:                     $showfile = &Apache::loncommon::lonhttpdurl($showfile);
 1103:                 }
 1104:                 if ($imgfile) {
 1105:                     if ($imgfile  =~ m{^/(adm|res)/}) {
 1106:                         if ($imgfile =~ m{^/res/}) {
 1107:                             my $local_imgfile =
 1108:                                 &Apache::lonnet::filelocation('',$imgfile);
 1109:                             &Apache::lonnet::repcopy($local_imgfile);
 1110:                         }
 1111:                         $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
 1112:                     } else {
 1113:                         $fullsize = $imgfile;
 1114:                     }
 1115:                 }
 1116:                 $datatable .= '<td>';
 1117:                 if ($img eq 'login') {
 1118:                     $datatable .= $login_hdr_pick;
 1119:                 } 
 1120:                 $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
 1121:                                              $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
 1122:             } else {
 1123:                 $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
 1124:                               &mt('Upload:');
 1125:             }
 1126:         } else {
 1127:             $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
 1128:                           &mt('Upload:');
 1129:         }
 1130:         if ($switchserver) {
 1131:             $datatable .= &mt('Upload to library server: [_1]',$switchserver);
 1132:         } else {
 1133:             if ($img ne 'login') { # suppress file selection for Log-in header
 1134:                 $datatable .='&nbsp;<input type="file" name="'.$role.'_'.$img.'" />';
 1135:             }
 1136:         }
 1137:         $datatable .= '</td></tr>';
 1138:     }
 1139:     $itemcount ++;
 1140:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
 1141:     $datatable .= '<tr'.$css_class.'>'.
 1142:                   '<td>'.$choices->{'bgs'}.'</td>';
 1143:     my $bgs_def;
 1144:     foreach my $item (@{$bgs}) {
 1145:         if (!$is_custom->{$item}) {
 1146:             $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>';
 1147:         }
 1148:     }
 1149:     if ($bgs_def) {
 1150:         $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
 1151:     } else {
 1152:         $datatable .= '<td>&nbsp;</td>';
 1153:     }
 1154:     $datatable .= '<td class="LC_right_item">'.
 1155:                   '<table border="0"><tr>';
 1156:     foreach my $item (@{$bgs}) {
 1157:         my $link = &color_pick($phase,$role,$item,$choices->{$item},$designs->{'bgs'}{$item});
 1158:         $datatable .= '<td align="center">'.$link;
 1159:         if ($designs->{'bgs'}{$item}) {
 1160:             $datatable .= '&nbsp;<span id="css_'.$role.'_'.$item.'" style="background-color: '.$designs->{'bgs'}{$item}.';">&nbsp;&nbsp;&nbsp;</span>';
 1161:         }
 1162:         $datatable .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.$designs->{'bgs'}{$item}.
 1163:                       '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
 1164:     }
 1165:     $datatable .= '</tr></table></td></tr>';
 1166:     $itemcount ++;
 1167:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
 1168:     $datatable .= '<tr'.$css_class.'>'.
 1169:                   '<td>'.$choices->{'links'}.'</td>';
 1170:     my $links_def;
 1171:     foreach my $item (@{$links}) {
 1172:         if (!$is_custom->{$item}) {
 1173:             $links_def .= '<td>'.$choices->{$item}.'<br /><span id="css_default_'.$role.'_'.$item.'" style="color: '.$defaults->{'links'}{$item}.';">'.$defaults->{'links'}{$item}.'</span></td>';
 1174:         }
 1175:     }
 1176:     if ($links_def) {
 1177:         $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
 1178:     } else {
 1179:         $datatable .= '<td>&nbsp;</td>';
 1180:     }
 1181:     $datatable .= '<td class="LC_right_item">'.
 1182:                   '<table border="0"><tr>';
 1183:     foreach my $item (@{$links}) {
 1184:         $datatable .= '<td align="center">'."\n".
 1185:                       &color_pick($phase,$role,$item,$choices->{$item},
 1186:                                   $designs->{'links'}{$item});
 1187:         if ($designs->{'links'}{$item}) {
 1188:             $datatable.='&nbsp;<span id="css_'.$role.'_'.$item.'" style="background-color: '.$designs->{'links'}{$item}.';">&nbsp;&nbsp;&nbsp;</span>';
 1189:         }
 1190:         $datatable .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.$designs->{'links'}{$item}.
 1191:                       '" /></td>';
 1192:     }
 1193:     $$rowtotal += $itemcount;
 1194:     return $datatable;
 1195: }
 1196: 
 1197: sub logo_display_options {
 1198:     my ($img,$defaults,$designs) = @_;
 1199:     my $checkedon;
 1200:     if (ref($defaults) eq 'HASH') {
 1201:         if (ref($defaults->{'showlogo'}) eq 'HASH') {
 1202:             if ($defaults->{'showlogo'}{$img}) {
 1203:                 $checkedon = 'checked="checked" ';     
 1204:             }
 1205:         } 
 1206:     }
 1207:     if (ref($designs) eq 'HASH') {
 1208:         if (ref($designs->{'showlogo'}) eq 'HASH') {
 1209:             if (defined($designs->{'showlogo'}{$img})) {
 1210:                 if ($designs->{'showlogo'}{$img} == 0) {
 1211:                     $checkedon = '';
 1212:                 } elsif ($designs->{'showlogo'}{$img} == 1) {
 1213:                     $checkedon = 'checked="checked" ';
 1214:                 }
 1215:             }
 1216:         }
 1217:     }
 1218:     return '<br /><label>&nbsp;&nbsp;<input type="checkbox" name="'.
 1219:            'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
 1220:            &mt('show').'</label>'."\n";
 1221: }
 1222: 
 1223: sub login_header_options  {
 1224:     my ($img,$role,$defaults,$is_custom,$choices) = @_;
 1225:     my $output = '';
 1226:     if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
 1227:         $output .= &mt('Text default(s):').'<br />';
 1228:         if (!$is_custom->{'textcol'}) {
 1229:             $output .= $choices->{'textcol'}.':&nbsp;'.$defaults->{'logintext'}{'textcol'}.
 1230:                        '&nbsp;&nbsp;&nbsp;';
 1231:         }
 1232:         if (!$is_custom->{'bgcol'}) {
 1233:             $output .= $choices->{'bgcol'}.':&nbsp;'.
 1234:                        '<span id="css_'.$role.'_font" style="background-color: '.
 1235:                        $defaults->{'logintext'}{'bgcol'}.';">&nbsp;&nbsp;&nbsp;</span>';
 1236:         }
 1237:         $output .= '<br />';
 1238:     }
 1239:     $output .='<br />';
 1240:     return $output;
 1241: }
 1242: 
 1243: sub login_text_colors {
 1244:     my ($img,$role,$logintext,$phase,$choices,$designs) = @_;
 1245:     my $color_menu = '<table border="0"><tr>';
 1246:     foreach my $item (@{$logintext}) {
 1247:         my $link = &color_pick($phase,$role,$item,$choices->{$item},$designs->{'logintext'}{$item});
 1248:         $color_menu .= '<td align="center">'.$link;
 1249:         if ($designs->{'logintext'}{$item}) {
 1250:             $color_menu .= '&nbsp;<span id="css_'.$role.'_'.$item.'" style="background-color: '.$designs->{'logintext'}{$item}.';">&nbsp;&nbsp;&nbsp;</span>';
 1251:         }
 1252:         $color_menu .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.
 1253:                        $designs->{'logintext'}{$item}.'" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>'.
 1254:                        '<td>&nbsp;</td>';
 1255:     }
 1256:     $color_menu .= '</tr></table><br />';
 1257:     return $color_menu;
 1258: }
 1259: 
 1260: sub image_changes {
 1261:     my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
 1262:     my $output;
 1263:     if ($img eq 'login') {
 1264:             # suppress image for Log-in header
 1265:     } elsif (!$is_custom) {
 1266:         if ($img ne 'domlogo') {
 1267:             $output .= &mt('Default image:').'<br />';
 1268:         } else {
 1269:             $output .= &mt('Default in use:').'<br />';
 1270:         }
 1271:     }
 1272:     if ($img eq 'login') { # suppress image for Log-in header
 1273:         $output .= '<td>'.$logincolors;
 1274:     } else {
 1275:         if ($img_import) {
 1276:             $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
 1277:         }
 1278:         $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
 1279:                    $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
 1280:         if ($is_custom) {
 1281:             $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
 1282:                        '<input type="checkbox" name="'.
 1283:                        $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
 1284:                        '</label>&nbsp;'.&mt('Replace:').'</span><br />';
 1285:         } else {
 1286:             $output .= '<td valign="bottom">'.$logincolors.&mt('Upload:').'<br />';
 1287:         }
 1288:     }
 1289:     return $output;
 1290: }
 1291: 
 1292: sub color_pick {
 1293:     my ($phase,$role,$item,$desc,$curcol) = @_;
 1294:     my $link = '<a href="javascript:pjump('."'color_custom','".$desc.
 1295:                "','".$curcol."','".$role.'_'.$item."','parmform.pres','psub'".
 1296:                ');">'.$desc.'</a>';
 1297:     return $link;
 1298: }
 1299: 
 1300: sub print_quotas {
 1301:     my ($dom,$settings,$rowtotal,$action) = @_;
 1302:     my $context;
 1303:     if ($action eq 'quotas') {
 1304:         $context = 'tools';
 1305:     } else {
 1306:         $context = $action;
 1307:     }
 1308:     my ($datatable,$defaultquota,@usertools,@options,%validations);
 1309:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
 1310:     my $typecount = 0;
 1311:     my ($css_class,%titles);
 1312:     if ($context eq 'requestcourses') {
 1313:         @usertools = ('official','unofficial','community');
 1314:         @options =('norequest','approval','validate','autolimit');
 1315:         %validations = &Apache::lonnet::auto_courserequest_checks($dom);
 1316:         %titles = &courserequest_titles();
 1317:     } else {
 1318:         @usertools = ('aboutme','blog','portfolio');
 1319:         %titles = &tool_titles();
 1320:     }
 1321:     if (ref($types) eq 'ARRAY') {
 1322:         foreach my $type (@{$types}) {
 1323:             my $currdefquota;
 1324:             unless ($context eq 'requestcourses') {
 1325:                 if (ref($settings) eq 'HASH') {
 1326:                     if (ref($settings->{defaultquota}) eq 'HASH') {
 1327:                         $currdefquota = $settings->{defaultquota}->{$type}; 
 1328:                     } else {
 1329:                         $currdefquota = $settings->{$type};
 1330:                     }
 1331:                 }
 1332:             }
 1333:             if (defined($usertypes->{$type})) {
 1334:                 $typecount ++;
 1335:                 $css_class = $typecount%2?' class="LC_odd_row"':'';
 1336:                 $datatable .= '<tr'.$css_class.'>'.
 1337:                               '<td>'.$usertypes->{$type}.'</td>'.
 1338:                               '<td class="LC_left_item">';
 1339:                 if ($context eq 'requestcourses') {
 1340:                     $datatable .= '<table><tr>';
 1341:                 }
 1342:                 my %cell;  
 1343:                 foreach my $item (@usertools) {
 1344:                     if ($context eq 'requestcourses') {
 1345:                         my ($curroption,$currlimit);
 1346:                         if (ref($settings) eq 'HASH') {
 1347:                             if (ref($settings->{$item}) eq 'HASH') {
 1348:                                 $curroption = $settings->{$item}->{$type};
 1349:                                 if ($curroption =~ /^autolimit=(\d*)$/) {
 1350:                                     $currlimit = $1; 
 1351:                                 }
 1352:                             }
 1353:                         }
 1354:                         if (!$curroption) {
 1355:                             $curroption = 'norequest';
 1356:                         }
 1357:                         $datatable .= '<th>'.$titles{$item}.'</th>';
 1358:                         foreach my $option (@options) {
 1359:                             my $val = $option;
 1360:                             if ($option eq 'norequest') {
 1361:                                 $val = 0;  
 1362:                             }
 1363:                             if ($option eq 'validate') {
 1364:                                 my $canvalidate = 0;
 1365:                                 if (ref($validations{$item}) eq 'HASH') { 
 1366:                                     if ($validations{$item}{$type}) {
 1367:                                         $canvalidate = 1;
 1368:                                     }
 1369:                                 }
 1370:                                 next if (!$canvalidate);
 1371:                             }
 1372:                             my $checked = '';
 1373:                             if ($option eq $curroption) {
 1374:                                 $checked = ' checked="checked"';
 1375:                             } elsif ($option eq 'autolimit') {
 1376:                                 if ($curroption =~ /^autolimit/) {
 1377:                                     $checked = ' checked="checked"';
 1378:                                 }                       
 1379:                             } 
 1380:                             $cell{$item} .= '<span class="LC_nobreak"><label>'.
 1381:                                   '<input type="radio" name="crsreq_'.$item.
 1382:                                   '_'.$type.'" value="'.$val.'"'.$checked.' />'.
 1383:                                   $titles{$option}.'</label>';
 1384:                             if ($option eq 'autolimit') {
 1385:                                 $cell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
 1386:                                                 $item.'_limit_'.$type.'" size="1" '.
 1387:                                                 'value="'.$currlimit.'" />';
 1388:                             }
 1389:                             $cell{$item} .= '</span> ';
 1390:                             if ($option eq 'autolimit') {
 1391:                                 $cell{$item} .= $titles{'unlimited'};
 1392:                             }
 1393:                         }
 1394:                     } else {
 1395:                         my $checked = 'checked="checked" ';
 1396:                         if (ref($settings) eq 'HASH') {
 1397:                             if (ref($settings->{$item}) eq 'HASH') {
 1398:                                 if ($settings->{$item}->{$type} == 0) {
 1399:                                     $checked = '';
 1400:                                 } elsif ($settings->{$item}->{$type} == 1) {
 1401:                                     $checked =  'checked="checked" ';
 1402:                                 }
 1403:                             }
 1404:                         }
 1405:                         $datatable .= '<span class="LC_nobreak"><label>'.
 1406:                                       '<input type="checkbox" name="'.$context.'_'.$item.
 1407:                                       '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
 1408:                                       '</label></span>&nbsp; ';
 1409:                     }
 1410:                 }
 1411:                 if ($context eq 'requestcourses') {
 1412:                     $datatable .= '</tr><tr>';
 1413:                     foreach my $item (@usertools) {
 1414:                         $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';  
 1415:                     }
 1416:                     $datatable .= '</tr></table>';
 1417:                 }
 1418:                 $datatable .= '</td>';
 1419:                 unless ($context eq 'requestcourses') {
 1420:                     $datatable .= 
 1421:                               '<td class="LC_right_item"><span class="LC_nobreak">'.
 1422:                               '<input type="text" name="quota_'.$type.
 1423:                               '" value="'.$currdefquota.
 1424:                               '" size="5" /> Mb</span></td>';
 1425:                 }
 1426:                 $datatable .= '</tr>';
 1427:             }
 1428:         }
 1429:     }
 1430:     unless ($context eq 'requestcourses') {
 1431:         $defaultquota = '20';
 1432:         if (ref($settings) eq 'HASH') {
 1433:             if (ref($settings->{'defaultquota'}) eq 'HASH') {
 1434:                 $defaultquota = $settings->{'defaultquota'}->{'default'};
 1435:             } elsif (defined($settings->{'default'})) {
 1436:                 $defaultquota = $settings->{'default'};
 1437:             }
 1438:         }
 1439:     }
 1440:     $typecount ++;
 1441:     $css_class = $typecount%2?' class="LC_odd_row"':'';
 1442:     $datatable .= '<tr'.$css_class.'>'.
 1443:                   '<td>'.$othertitle.'</td>'.
 1444:                   '<td class="LC_left_item">';
 1445:     if ($context eq 'requestcourses') {
 1446:         $datatable .= '<table><tr>';
 1447:     }
 1448:     my %defcell;
 1449:     foreach my $item (@usertools) {
 1450:         if ($context eq 'requestcourses') {
 1451:             my ($curroption,$currlimit);
 1452:             if (ref($settings) eq 'HASH') {
 1453:                 if (ref($settings->{$item}) eq 'HASH') {
 1454:                     $curroption = $settings->{$item}->{'default'};
 1455:                     if ($curroption =~ /^autolimit=(\d*)$/) {
 1456:                         $currlimit = $1;
 1457:                     }
 1458:                 }
 1459:             }
 1460:             if (!$curroption) {
 1461:                 $curroption = 'norequest';
 1462:             }
 1463:             $datatable .= '<th>'.$titles{$item}.'</th>';
 1464:             foreach my $option (@options) {
 1465:                 my $val = $option;
 1466:                 if ($option eq 'norequest') {
 1467:                     $val = 0;
 1468:                 }
 1469:                 if ($option eq 'validate') {
 1470:                     my $canvalidate = 0;
 1471:                     if (ref($validations{$item}) eq 'HASH') {
 1472:                         if ($validations{$item}{'default'}) {
 1473:                             $canvalidate = 1;
 1474:                         }
 1475:                     }
 1476:                     next if (!$canvalidate);
 1477:                 }
 1478:                 my $checked = '';
 1479:                 if ($option eq $curroption) {
 1480:                     $checked = ' checked="checked"';
 1481:                 } elsif ($option eq 'autolimit') {
 1482:                     if ($curroption =~ /^autolimit/) {
 1483:                         $checked = ' checked="checked"';
 1484:                     }
 1485:                 }
 1486:                 $defcell{$item} .= '<span class="LC_nobreak"><label>'.
 1487:                                   '<input type="radio" name="crsreq_'.$item.
 1488:                                   '_default" value="'.$val.'"'.$checked.' />'.
 1489:                                   $titles{$option}.'</label>';
 1490:                 if ($option eq 'autolimit') {
 1491:                     $defcell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
 1492:                                        $item.'_limit_default" size="1" '.
 1493:                                        'value="'.$currlimit.'" />';
 1494:                 }
 1495:                 $defcell{$item} .= '</span> ';
 1496:                 if ($option eq 'autolimit') {
 1497:                     $defcell{$item} .= $titles{'unlimited'};
 1498:                 }
 1499:             }
 1500:         } else {
 1501:             my $checked = 'checked="checked" ';
 1502:             if (ref($settings) eq 'HASH') {
 1503:                 if (ref($settings->{$item}) eq 'HASH') {
 1504:                     if ($settings->{$item}->{'default'} == 0) {
 1505:                         $checked = '';
 1506:                     } elsif ($settings->{$item}->{'default'} == 1) {
 1507:                         $checked = 'checked="checked" ';
 1508:                     }
 1509:                 }
 1510:             }
 1511:             $datatable .= '<span class="LC_nobreak"><label>'.
 1512:                           '<input type="checkbox" name="'.$context.'_'.$item.
 1513:                           '" value="default" '.$checked.'/>'.$titles{$item}.
 1514:                           '</label></span>&nbsp; ';
 1515:         }
 1516:     }
 1517:     if ($context eq 'requestcourses') {
 1518:         $datatable .= '</tr><tr>';
 1519:         foreach my $item (@usertools) {
 1520:             $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
 1521:         }
 1522:         $datatable .= '</tr></table>';
 1523:     }
 1524:     $datatable .= '</td>';
 1525:     unless ($context eq 'requestcourses') {
 1526:         $datatable .= '<td class="LC_right_item"><span class="LC_nobreak">'.
 1527:                       '<input type="text" name="defaultquota" value="'.
 1528:                       $defaultquota.'" size="5" /> Mb</span></td>';
 1529:     }
 1530:     $datatable .= '</tr>';
 1531:     $typecount ++;
 1532:     $css_class = $typecount%2?' class="LC_odd_row"':'';
 1533:     $datatable .= '<tr'.$css_class.'>'.
 1534:                   '<td>'.&mt('LON-CAPA Advanced Users').' ';
 1535:     if ($context eq 'requestcourses') {
 1536:         $datatable .= &mt('(overrides affiliation, if set)').
 1537:                       '</td>'.
 1538:                       '<td class="LC_left_item">'.
 1539:                       '<table><tr>';
 1540:     } else {
 1541:         $datatable .= &mt('(overrides affiliation, if checked)').
 1542:                       '</td>'.
 1543:                       '<td class="LC_left_item" colspan="2">'.
 1544:                       '<br />';
 1545:     }
 1546:     my %advcell;
 1547:     foreach my $item (@usertools) {
 1548:         if ($context eq 'requestcourses') {
 1549:             my ($curroption,$currlimit);
 1550:             if (ref($settings) eq 'HASH') {
 1551:                 if (ref($settings->{$item}) eq 'HASH') {
 1552:                     $curroption = $settings->{$item}->{'_LC_adv'};
 1553:                     if ($curroption =~ /^autolimit=(\d*)$/) {
 1554:                         $currlimit = $1;
 1555:                     }
 1556:                 }
 1557:             }
 1558:             $datatable .= '<th>'.$titles{$item}.'</th>';
 1559:             my $checked = '';
 1560:             if ($curroption eq '') {
 1561:                 $checked = ' checked="checked"';
 1562:             }
 1563:             $advcell{$item} .= '<span class="LC_nobreak"><label>'.
 1564:                                '<input type="radio" name="crsreq_'.$item.
 1565:                                '__LC_adv" value=""'.$checked.' />'.
 1566:                                &mt('No override set').'</label></span>&nbsp; ';
 1567:             foreach my $option (@options) {
 1568:                 my $val = $option;
 1569:                 if ($option eq 'norequest') {
 1570:                     $val = 0;
 1571:                 }
 1572:                 if ($option eq 'validate') {
 1573:                     my $canvalidate = 0;
 1574:                     if (ref($validations{$item}) eq 'HASH') {
 1575:                         if ($validations{$item}{'_LC_adv'}) {
 1576:                             $canvalidate = 1;
 1577:                         }
 1578:                     }
 1579:                     next if (!$canvalidate);
 1580:                 }
 1581:                 my $checked = '';
 1582:                 if ($val eq $curroption) {
 1583:                     $checked = ' checked="checked"';
 1584:                 } elsif ($option eq 'autolimit') {
 1585:                     if ($curroption =~ /^autolimit/) {
 1586:                         $checked = ' checked="checked"';
 1587:                     }
 1588:                 }
 1589:                 $advcell{$item} .= '<span class="LC_nobreak"><label>'.
 1590:                                   '<input type="radio" name="crsreq_'.$item.
 1591:                                   '__LC_adv" value="'.$val.'"'.$checked.' />'.
 1592:                                   $titles{$option}.'</label>';
 1593:                 if ($option eq 'autolimit') {
 1594:                     $advcell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
 1595:                                        $item.'_limit__LC_adv" size="1" '.
 1596:                                        'value="'.$currlimit.'" />';
 1597:                 }
 1598:                 $advcell{$item} .= '</span> ';
 1599:                 if ($option eq 'autolimit') {
 1600:                     $advcell{$item} .= $titles{'unlimited'};
 1601:                 }
 1602:             }
 1603:         } else {
 1604:             my $checked = 'checked="checked" ';
 1605:             if (ref($settings) eq 'HASH') {
 1606:                 if (ref($settings->{$item}) eq 'HASH') {
 1607:                     if ($settings->{$item}->{'_LC_adv'} == 0) {
 1608:                         $checked = '';
 1609:                     } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
 1610:                         $checked = 'checked="checked" ';
 1611:                     }
 1612:                 }
 1613:             }
 1614:             $datatable .= '<span class="LC_nobreak"><label>'.
 1615:                           '<input type="checkbox" name="'.$context.'_'.$item.
 1616:                           '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
 1617:                           '</label></span>&nbsp; ';
 1618:         }
 1619:     }
 1620:     if ($context eq 'requestcourses') {
 1621:         $datatable .= '</tr><tr>';
 1622:         foreach my $item (@usertools) {
 1623:             $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
 1624:         }
 1625:         $datatable .= '</tr></table>';
 1626:     }
 1627:     $datatable .= '</td></tr>';
 1628:     $$rowtotal += $typecount;
 1629:     return $datatable;
 1630: }
 1631: 
 1632: sub print_courserequestmail {
 1633:     my ($dom,$settings,$rowtotal) = @_;
 1634:     my ($now,$datatable,%dompersonnel,@domcoord,@currapproval,$rows);
 1635:     $now = time;
 1636:     $rows = 0;
 1637:     %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
 1638:     foreach my $server (keys(%dompersonnel)) {
 1639:         foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
 1640:             my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
 1641:             if (!grep(/^$uname:$udom$/,@domcoord)) {
 1642:                 push(@domcoord,$uname.':'.$udom);
 1643:             }
 1644:         }
 1645:     }
 1646:     if (ref($settings) eq 'HASH') {
 1647:         if (ref($settings->{'notify'}) eq 'HASH') {
 1648:             if ($settings->{'notify'}{'approval'} ne '') {
 1649:                @currapproval = split(',',$settings->{'notify'}{'approval'});
 1650:             }
 1651:         }
 1652:     }
 1653:     if (@currapproval) {
 1654:         foreach my $dc (@currapproval) {
 1655:             unless (grep(/^\Q$dc\E$/,@domcoord)) {
 1656:                 push(@domcoord,$dc);
 1657:             }
 1658:         }
 1659:     }
 1660:     @domcoord = sort(@domcoord);
 1661:     my $numinrow = 4;
 1662:     my $numdc = @domcoord;
 1663:     my $css_class = 'class="LC_odd_row"';
 1664:     $datatable = '<tr'.$css_class.'>'.
 1665:                  ' <td>'.&mt('Receive notification of course requests requiring approval.').
 1666:                  ' </td>'.
 1667:                  ' <td class="LC_left_item">';
 1668:     if (@domcoord > 0) {
 1669:         $datatable .= '<table>';
 1670:         for (my $i=0; $i<$numdc; $i++) {
 1671:             my $rem = $i%($numinrow);
 1672:             if ($rem == 0) {
 1673:                 if ($i > 0) {
 1674:                     $datatable .= '</tr>';
 1675:                 }
 1676:                 $datatable .= '<tr>';
 1677:                 $rows ++;
 1678:             }
 1679:             my $check = ' ';
 1680:             if (grep(/^\Q$domcoord[$i]\E$/,@currapproval)) {
 1681:                 $check = ' checked="checked" ';
 1682:             }
 1683:             my ($uname,$udom) = split(':',$domcoord[$i]);
 1684:             my $fullname = &Apache::loncommon::plainname($uname,$udom);
 1685:             if ($i == $numdc-1) {
 1686:                 my $colsleft = $numinrow-$rem;
 1687:                 if ($colsleft > 1) {
 1688:                     $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
 1689:                 } else {
 1690:                     $datatable .= '<td class="LC_left_item">';
 1691:                 }
 1692:             } else {
 1693:                 $datatable .= '<td class="LC_left_item">';
 1694:             }
 1695:             $datatable .= '<span class="LC_nobreak"><label>'.
 1696:                           '<input type="checkbox" name="reqapprovalnotify" '.
 1697:                           'value="'.$domcoord[$i].'"'.$check.'/>'.
 1698:                           $fullname.'</label></span></td>';
 1699:         }
 1700:         $datatable .= '</tr></table>';
 1701:     } else {
 1702:         $datatable .= &mt('There are no active Domain Coordinators');
 1703:         $rows ++;
 1704:     }
 1705:     $datatable .='</td></tr>';
 1706:     $$rowtotal += $rows;
 1707:     return $datatable;
 1708: }
 1709: 
 1710: sub print_autoenroll {
 1711:     my ($dom,$settings,$rowtotal) = @_;
 1712:     my $autorun = &Apache::lonnet::auto_run(undef,$dom),
 1713:     my ($defdom,$runon,$runoff,$coownerson,$coownersoff);
 1714:     if (ref($settings) eq 'HASH') {
 1715:         if (exists($settings->{'run'})) {
 1716:             if ($settings->{'run'} eq '0') {
 1717:                 $runoff = ' checked="checked" ';
 1718:                 $runon = ' ';
 1719:             } else {
 1720:                 $runon = ' checked="checked" ';
 1721:                 $runoff = ' ';
 1722:             }
 1723:         } else {
 1724:             if ($autorun) {
 1725:                 $runon = ' checked="checked" ';
 1726:                 $runoff = ' ';
 1727:             } else {
 1728:                 $runoff = ' checked="checked" ';
 1729:                 $runon = ' ';
 1730:             }
 1731:         }
 1732:         if (exists($settings->{'co-owners'})) {
 1733:             if ($settings->{'co-owners'} eq '0') {
 1734:                 $coownersoff = ' checked="checked" ';
 1735:                 $coownerson = ' ';
 1736:             } else {
 1737:                 $coownerson = ' checked="checked" ';
 1738:                 $coownersoff = ' ';
 1739:             }
 1740:         } else {
 1741:             $coownersoff = ' checked="checked" ';
 1742:             $coownerson = ' ';
 1743:         }
 1744:         if (exists($settings->{'sender_domain'})) {
 1745:             $defdom = $settings->{'sender_domain'};
 1746:         }
 1747:     } else {
 1748:         if ($autorun) {
 1749:             $runon = ' checked="checked" ';
 1750:             $runoff = ' ';
 1751:         } else {
 1752:             $runoff = ' checked="checked" ';
 1753:             $runon = ' ';
 1754:         }
 1755:     }
 1756:     my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
 1757:     my $notif_sender;
 1758:     if (ref($settings) eq 'HASH') {
 1759:         $notif_sender = $settings->{'sender_uname'};
 1760:     }
 1761:     my $datatable='<tr class="LC_odd_row">'.
 1762:                   '<td>'.&mt('Auto-enrollment active?').'</td>'.
 1763:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
 1764:                   '<input type="radio" name="autoenroll_run"'.
 1765:                   $runon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
 1766:                   '<label><input type="radio" name="autoenroll_run"'.
 1767:                   $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
 1768:                   '</tr><tr>'.
 1769:                   '<td>'.&mt('Notification messages - sender').
 1770:                   '</td><td class="LC_right_item"><span class="LC_nobreak">'.
 1771:                   &mt('username').':&nbsp;'.
 1772:                   '<input type="text" name="sender_uname" value="'.
 1773:                   $notif_sender.'" size="10" />&nbsp;&nbsp;'.&mt('domain').
 1774:                   ':&nbsp;'.$domform.'</span></td></tr>'.
 1775:                   '<tr class="LC_odd_row">'.
 1776:                   '<td>'.&mt('Automatically assign co-ownership').'</td>'.
 1777:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
 1778:                   '<input type="radio" name="autoassign_coowners"'.
 1779:                   $coownerson.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
 1780:                   '<label><input type="radio" name="autoassign_coowners"'.
 1781:                   $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
 1782:                   '</tr>';
 1783:     $$rowtotal += 3;
 1784:     return $datatable;
 1785: }
 1786: 
 1787: sub print_autoupdate {
 1788:     my ($position,$dom,$settings,$rowtotal) = @_;
 1789:     my $datatable;
 1790:     if ($position eq 'top') {
 1791:         my $updateon = ' ';
 1792:         my $updateoff = ' checked="checked" ';
 1793:         my $classlistson = ' ';
 1794:         my $classlistsoff = ' checked="checked" ';
 1795:         if (ref($settings) eq 'HASH') {
 1796:             if ($settings->{'run'} eq '1') {
 1797:                 $updateon = $updateoff;
 1798:                 $updateoff = ' ';
 1799:             }
 1800:             if ($settings->{'classlists'} eq '1') {
 1801:                 $classlistson = $classlistsoff;
 1802:                 $classlistsoff = ' ';
 1803:             }
 1804:         }
 1805:         my %title = (
 1806:                    run => 'Auto-update active?',
 1807:                    classlists => 'Update information in classlists?',
 1808:                     );
 1809:         $datatable = '<tr class="LC_odd_row">'. 
 1810:                   '<td>'.&mt($title{'run'}).'</td>'.
 1811:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
 1812:                   '<input type="radio" name="autoupdate_run"'.
 1813:                   $updateon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
 1814:                   '<label><input type="radio" name="autoupdate_run"'.
 1815:                   $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
 1816:                   '</tr><tr>'.
 1817:                   '<td>'.&mt($title{'classlists'}).'</td>'.
 1818:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
 1819:                   '<label><input type="radio" name="classlists"'.
 1820:                   $classlistson.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
 1821:                   '<label><input type="radio" name="classlists"'.
 1822:                   $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
 1823:                   '</tr>';
 1824:         $$rowtotal += 2;
 1825:     } elsif ($position eq 'middle') {
 1826:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
 1827:         my $numinrow = 3;
 1828:         my $locknamesettings;
 1829:         $datatable .= &insttypes_row($settings,$types,$usertypes,
 1830:                                      $dom,$numinrow,$othertitle,
 1831:                                     'lockablenames');
 1832:         $$rowtotal ++;
 1833:     } else {
 1834:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
 1835:         my @fields = ('lastname','firstname','middlename','generation',
 1836:                       'permanentemail','id');
 1837:         my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
 1838:         my $numrows = 0;
 1839:         if (ref($types) eq 'ARRAY') {
 1840:             if (@{$types} > 0) {
 1841:                 $datatable = 
 1842:                     &usertype_update_row($settings,$usertypes,\%fieldtitles,
 1843:                                          \@fields,$types,\$numrows);
 1844:                     $$rowtotal += @{$types}; 
 1845:             }
 1846:         }
 1847:         $datatable .= 
 1848:             &usertype_update_row($settings,{'default' => $othertitle},
 1849:                                  \%fieldtitles,\@fields,['default'],
 1850:                                  \$numrows);
 1851:         $$rowtotal ++;     
 1852:     }
 1853:     return $datatable;
 1854: }
 1855: 
 1856: sub print_autocreate {
 1857:     my ($dom,$settings,$rowtotal) = @_;
 1858:     my (%createon,%createoff);
 1859:     my $curr_dc;
 1860:     my @types = ('xml','req');
 1861:     if (ref($settings) eq 'HASH') {
 1862:         foreach my $item (@types) {
 1863:             $createoff{$item} = ' checked="checked" ';
 1864:             $createon{$item} = ' ';
 1865:             if (exists($settings->{$item})) {
 1866:                 if ($settings->{$item}) {
 1867:                     $createon{$item} = ' checked="checked" ';
 1868:                     $createoff{$item} = ' ';
 1869:                 }
 1870:             }
 1871:         }
 1872:         $curr_dc = $settings->{'xmldc'};
 1873:     } else {
 1874:         foreach my $item (@types) {
 1875:             $createoff{$item} = ' checked="checked" ';
 1876:             $createon{$item} = ' ';
 1877:         }
 1878:     }
 1879:     $$rowtotal += 2;
 1880:     my $datatable='<tr class="LC_odd_row">'.
 1881:                   '<td>'.&mt('Create pending official courses from XML files').'</td>'.
 1882:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
 1883:                   '<input type="radio" name="autocreate_xml"'.
 1884:                   $createon{'xml'}.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
 1885:                   '<label><input type="radio" name="autocreate_xml"'.
 1886:                   $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>';
 1887:     my ($numdc,$dctable) = &active_dc_picker($dom,$curr_dc);
 1888:     if ($numdc > 1) {
 1889:         $datatable .= '</td><tr><td>'.
 1890:                       &mt('XML files processed as: (choose Dom. Coord.)'). 
 1891:                       '</td><td class="LC_left_item">'.$dctable.'</td></tr>'.
 1892:                       '<tr class="LC_odd_row">';
 1893:         $$rowtotal ++ ;
 1894:     } else {
 1895:         $datatable .= '</td></tr><tr>';
 1896:     }
 1897:     $datatable .= '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
 1898:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
 1899:                   '<input type="radio" name="autocreate_req"'.
 1900:                   $createon{'req'}.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
 1901:                   '<label><input type="radio" name="autocreate_req"'.
 1902:                   $createoff{'req'}.' value="0" />'.&mt('No').'</label></span></td>'.
 1903:                   '</tr>';
 1904:     return $datatable;
 1905: }
 1906: 
 1907: sub print_directorysrch {
 1908:     my ($dom,$settings,$rowtotal) = @_;
 1909:     my $srchon = ' ';
 1910:     my $srchoff = ' checked="checked" ';
 1911:     my ($exacton,$containson,$beginson);
 1912:     my $localon = ' ';
 1913:     my $localoff = ' checked="checked" ';
 1914:     if (ref($settings) eq 'HASH') {
 1915:         if ($settings->{'available'} eq '1') {
 1916:             $srchon = $srchoff;
 1917:             $srchoff = ' ';
 1918:         }
 1919:         if ($settings->{'localonly'} eq '1') {
 1920:             $localon = $localoff;
 1921:             $localoff = ' ';
 1922:         }
 1923:         if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
 1924:             foreach my $type (@{$settings->{'searchtypes'}}) {
 1925:                 if ($type eq 'exact') {
 1926:                     $exacton = ' checked="checked" ';
 1927:                 } elsif ($type eq 'contains') {
 1928:                     $containson = ' checked="checked" ';
 1929:                 } elsif ($type eq 'begins') {
 1930:                     $beginson = ' checked="checked" ';
 1931:                 }
 1932:             }
 1933:         } else {
 1934:             if ($settings->{'searchtypes'} eq 'exact') {
 1935:                 $exacton = ' checked="checked" ';
 1936:             } elsif ($settings->{'searchtypes'} eq 'contains') {
 1937:                 $containson = ' checked="checked" ';
 1938:             } elsif ($settings->{'searchtypes'} eq 'specify') {
 1939:                 $exacton = ' checked="checked" ';
 1940:                 $containson = ' checked="checked" ';
 1941:             }
 1942:         }
 1943:     }
 1944:     my ($searchtitles,$titleorder) = &sorted_searchtitles();
 1945:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
 1946: 
 1947:     my $numinrow = 4;
 1948:     my $cansrchrow = 0;
 1949:     my $datatable='<tr class="LC_odd_row">'.
 1950:                   '<td colspan="2"><span class ="LC_nobreak">'.&mt('Directory search available?').'</span></td>'.
 1951:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
 1952:                   '<input type="radio" name="dirsrch_available"'.
 1953:                   $srchon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
 1954:                   '<label><input type="radio" name="dirsrch_available"'.
 1955:                   $srchoff.' value="0" />'.&mt('No').'</label></span></td>'.
 1956:                   '</tr><tr>'.
 1957:                   '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search?').'</span></td>'.
 1958:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
 1959:                   '<input type="radio" name="dirsrch_localonly"'.
 1960:                   $localoff.' value="0" />'.&mt('Yes').'</label>&nbsp;'.
 1961:                   '<label><input type="radio" name="dirsrch_localonly"'.
 1962:                   $localon.' value="1" />'.&mt('No').'</label></span></td>'.
 1963:                   '</tr>';
 1964:     $$rowtotal += 2;
 1965:     if (ref($usertypes) eq 'HASH') {
 1966:         if (keys(%{$usertypes}) > 0) {
 1967:             $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
 1968:                                          $numinrow,$othertitle,'cansearch');
 1969:             $cansrchrow = 1;
 1970:         }
 1971:     }
 1972:     if ($cansrchrow) {
 1973:         $$rowtotal ++;
 1974:         $datatable .= '<tr>';
 1975:     } else {
 1976:         $datatable .= '<tr class="LC_odd_row">';
 1977:     }
 1978:     $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
 1979:                   '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
 1980:     foreach my $title (@{$titleorder}) {
 1981:         if (defined($searchtitles->{$title})) {
 1982:             my $check = ' ';
 1983:             if (ref($settings) eq 'HASH') {
 1984:                 if (ref($settings->{'searchby'}) eq 'ARRAY') {
 1985:                     if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
 1986:                         $check = ' checked="checked" ';
 1987:                     }
 1988:                 }
 1989:             }
 1990:             $datatable .= '<td class="LC_left_item">'.
 1991:                           '<span class="LC_nobreak"><label>'.
 1992:                           '<input type="checkbox" name="searchby" '.
 1993:                           'value="'.$title.'"'.$check.'/>'.
 1994:                           $searchtitles->{$title}.'</label></span></td>';
 1995:         }
 1996:     }
 1997:     $datatable .= '</tr></table></td></tr>';
 1998:     $$rowtotal ++;
 1999:     if ($cansrchrow) {
 2000:         $datatable .= '<tr class="LC_odd_row">';
 2001:     } else {
 2002:         $datatable .= '<tr>';
 2003:     }
 2004:     $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.   
 2005:                   '<td class="LC_left_item" colspan="2">'.
 2006:                   '<span class="LC_nobreak"><label>'.
 2007:                   '<input type="checkbox" name="searchtypes" '.
 2008:                   $exacton.' value="exact" />'.&mt('Exact match').
 2009:                   '</label>&nbsp;'.
 2010:                   '<label><input type="checkbox" name="searchtypes" '.
 2011:                   $beginson.' value="begins" />'.&mt('Begins with').
 2012:                   '</label>&nbsp;'.
 2013:                   '<label><input type="checkbox" name="searchtypes" '.
 2014:                   $containson.' value="contains" />'.&mt('Contains').
 2015:                   '</label></span></td></tr>';
 2016:     $$rowtotal ++;
 2017:     return $datatable;
 2018: }
 2019: 
 2020: sub print_contacts {
 2021:     my ($dom,$settings,$rowtotal) = @_;
 2022:     my $datatable;
 2023:     my @contacts = ('adminemail','supportemail');
 2024:     my (%checked,%to,%otheremails,%bccemails);
 2025:     my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail',
 2026:                     'requestsmail');
 2027:     foreach my $type (@mailings) {
 2028:         $otheremails{$type} = '';
 2029:     }
 2030:     $bccemails{'helpdeskmail'} = '';
 2031:     if (ref($settings) eq 'HASH') {
 2032:         foreach my $item (@contacts) {
 2033:             if (exists($settings->{$item})) {
 2034:                 $to{$item} = $settings->{$item};
 2035:             }
 2036:         }
 2037:         foreach my $type (@mailings) {
 2038:             if (exists($settings->{$type})) {
 2039:                 if (ref($settings->{$type}) eq 'HASH') {
 2040:                     foreach my $item (@contacts) {
 2041:                         if ($settings->{$type}{$item}) {
 2042:                             $checked{$type}{$item} = ' checked="checked" ';
 2043:                         }
 2044:                     }
 2045:                     $otheremails{$type} = $settings->{$type}{'others'};
 2046:                     if ($type eq 'helpdeskmail') {
 2047:                         $bccemails{$type} = $settings->{$type}{'bcc'};
 2048:                     }
 2049:                 }
 2050:             } elsif ($type eq 'lonstatusmail') {
 2051:                 $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
 2052:             }
 2053:         }
 2054:     } else {
 2055:         $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
 2056:         $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
 2057:         $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
 2058:         $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
 2059:         $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
 2060:         $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" '; 
 2061:         $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
 2062:     }
 2063:     my ($titles,$short_titles) = &contact_titles();
 2064:     my $rownum = 0;
 2065:     my $css_class;
 2066:     foreach my $item (@contacts) {
 2067:         $rownum ++;
 2068:         $css_class = $rownum%2?' class="LC_odd_row"':'';
 2069:         $datatable .= '<tr'.$css_class.'>'. 
 2070:                   '<td><span class="LC_nobreak">'.$titles->{$item}.
 2071:                   '</span></td><td class="LC_right_item">'.
 2072:                   '<input type="text" name="'.$item.'" value="'.
 2073:                   $to{$item}.'" /></td></tr>';
 2074:     }
 2075:     foreach my $type (@mailings) {
 2076:         $rownum ++;
 2077:         $css_class = $rownum%2?' class="LC_odd_row"':'';
 2078:         $datatable .= '<tr'.$css_class.'>'.
 2079:                       '<td><span class="LC_nobreak">'.
 2080:                       $titles->{$type}.': </span></td>'.
 2081:                       '<td class="LC_left_item">'.
 2082:                       '<span class="LC_nobreak">';
 2083:         foreach my $item (@contacts) {
 2084:             $datatable .= '<label>'.
 2085:                           '<input type="checkbox" name="'.$type.'"'.
 2086:                           $checked{$type}{$item}.
 2087:                           ' value="'.$item.'" />'.$short_titles->{$item}.
 2088:                           '</label>&nbsp;';
 2089:         }
 2090:         $datatable .= '</span><br />'.&mt('Others').':&nbsp;&nbsp;'.
 2091:                       '<input type="text" name="'.$type.'_others" '.
 2092:                       'value="'.$otheremails{$type}.'"  />';
 2093:         if ($type eq 'helpdeskmail') {
 2094:             $datatable .= '<br />'.&mt('Bcc:').('&nbsp;'x6).
 2095:                           '<input type="text" name="'.$type.'_bcc" '.
 2096:                           'value="'.$bccemails{$type}.'"  />';
 2097:         }
 2098:         $datatable .= '</td></tr>'."\n";
 2099:     }
 2100:     $$rowtotal += $rownum;
 2101:     return $datatable;
 2102: }
 2103: 
 2104: sub print_helpsettings {
 2105: 
 2106: 	my ($position,$dom,$confname,$settings,$rowtotal) = @_;
 2107: 	my ($css_class,$datatable);
 2108: 	
 2109: 	my $switchserver = &check_switchserver($dom,$confname);
 2110: 	
 2111: 	my $itemcount = 1;
 2112: 	
 2113: 	if ($position eq 'top') {
 2114: 		
 2115: 		my (%checkedon,%checkedoff,%choices,%defaultchecked,@toggles);
 2116: 		
 2117: 		%choices =
 2118: 			&Apache::lonlocal::texthash (
 2119: 				submitbugs => 'Display &quot;Submit a bug&quot; link?',
 2120: 		);
 2121: 		
 2122: 		%defaultchecked = ('submitbugs' => 'on');
 2123: 		
 2124: 		@toggles = ('submitbugs',);
 2125: 		
 2126: 		foreach my $item (@toggles) {
 2127: 			if ($defaultchecked{$item} eq 'on') { 
 2128: 				$checkedon{$item} = ' checked="checked" ';
 2129: 				$checkedoff{$item} = ' ';
 2130: 			} elsif ($defaultchecked{$item} eq 'off') {
 2131: 				$checkedoff{$item} = ' checked="checked" ';
 2132: 				$checkedon{$item} = ' ';
 2133: 			}
 2134: 		}
 2135: 		
 2136: 		if (ref($settings) eq 'HASH') {
 2137: 			foreach my $item (@toggles) {
 2138: 				if ($settings->{$item} eq '1') {
 2139: 					$checkedon{$item} =  ' checked="checked" ';
 2140: 					$checkedoff{$item} = ' ';
 2141: 				} elsif ($settings->{$item} eq '0') {
 2142: 					$checkedoff{$item} =  ' checked="checked" ';
 2143: 					$checkedon{$item} = ' ';
 2144: 				}
 2145: 			}
 2146: 		 }
 2147: 		
 2148: 		 foreach my $item (@toggles) {
 2149: 			$css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
 2150: 			$datatable .=  
 2151: 				'<tr'.$css_class.'>
 2152: 				<td><span class="LC_nobreak">'.$choices{$item}.'</span></td>
 2153: 				<td><span class="LC_nobreak">&nbsp;</span></td>
 2154: 				<td class="LC_right_item"><span class="LC_nobreak">
 2155: 				<label><input type="radio" name="'.$item.'" '.$checkedon{$item}.' value="1" />'.&mt('Yes').'</label>&nbsp;
 2156: 				<label><input type="radio" name="'.$item.'" '.$checkedoff{$item}.' value="0" />'.&mt('No').'</label>'.
 2157: 				'</span></td>'.
 2158: 				'</tr>';
 2159: 			$itemcount ++;
 2160: 		 }
 2161:      
 2162:      } else {
 2163:      
 2164:      	$css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
 2165:      	
 2166:      	$datatable .= '<tr'.$css_class.'>';
 2167:      	
 2168:      	if (ref($settings) eq 'HASH') {
 2169: 			if ($settings->{'loginhelpurl'} ne '') {
 2170: 				my($directory, $filename) = $settings->{'loginhelpurl'} =~ m/(.*\/)(.*)$/;
 2171: 				$datatable .= '<td width="33%"><span class="LC_left_item"><label><a href="'.$settings->{'loginhelpurl'}.'" target="_blank">'.&mt('Custom Login Page Help File In Use').'</a></label></span></td>';
 2172: 				$datatable .= '<td width="33%"><span class="LC_right_item"><label><input type="checkbox" name="loginhelpurl_del" value="1" />'.&mt('Delete?').'</label></span></td>'
 2173: 			} else {
 2174: 				$datatable .= '<td width="33%"><span class="LC_left_item"><label>'.&mt('Default Login Page Help File In Use').'</label></span></td>';
 2175: 				$datatable .= '<td width="33%"><span class="LC_right_item">&nbsp;</span></td>';
 2176: 			}
 2177: 		} else {
 2178: 			$datatable .= '<td><span class="LC_left_item">&nbsp;</span></td>';
 2179: 			$datatable .= '<td><span class="LC_right_item">&nbsp;</span></td>';
 2180: 		}
 2181:     	
 2182:      	$datatable .= '<td width="33%"><span class="LC_right_item">';
 2183:      	if ($switchserver) {
 2184:             $datatable .= &mt('Upload to library server: [_1]',$switchserver);
 2185:         } else {
 2186:         	$datatable .= &mt('Upload Custom Login Page Help File:');
 2187:             $datatable .='<input type="file" name="loginhelpurl" />';
 2188:         }
 2189:         $datatable .= '</span></td></tr>';
 2190:         
 2191:      }
 2192:      
 2193:      return $datatable;
 2194: 	
 2195: }
 2196: 
 2197: 
 2198: sub radiobutton_prefs {
 2199:     my ($settings,$toggles,$defaultchecked,$choices,$itemcount) = @_;
 2200:     return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
 2201:                    (ref($choices) eq 'HASH'));
 2202: 
 2203:     my (%checkedon,%checkedoff,$datatable,$css_class);
 2204: 
 2205:     foreach my $item (@{$toggles}) {
 2206:         if ($defaultchecked->{$item} eq 'on') {
 2207:             $checkedon{$item} = ' checked="checked" ';
 2208:             $checkedoff{$item} = ' ';
 2209:         } elsif ($defaultchecked->{$item} eq 'off') {
 2210:             $checkedoff{$item} = ' checked="checked" ';
 2211:             $checkedon{$item} = ' ';
 2212:         }
 2213:     }
 2214:     if (ref($settings) eq 'HASH') {
 2215:         foreach my $item (@{$toggles}) {
 2216:             if ($settings->{$item} eq '1') {
 2217:                 $checkedon{$item} =  ' checked="checked" ';
 2218:                 $checkedoff{$item} = ' ';
 2219:             } elsif ($settings->{$item} eq '0') {
 2220:                 $checkedoff{$item} =  ' checked="checked" ';
 2221:                 $checkedon{$item} = ' ';
 2222:             }
 2223:         }
 2224:     }
 2225:     foreach my $item (@{$toggles}) {
 2226:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
 2227:         $datatable .=
 2228:             '<tr'.$css_class.'><td><span class="LC_nobreak">'.$choices->{$item}.
 2229:             '</span></td>'.
 2230:             '<td class="LC_right_item"><span class="LC_nobreak">'.
 2231:             '<label><input type="radio" name="'.
 2232:             $item.'" '.$checkedon{$item}.' value="1" />'.&mt('Yes').
 2233:             '</label>&nbsp;<label><input type="radio" name="'.$item.'" '.
 2234:             $checkedoff{$item}.' value="0" />'.&mt('No').'</label>'.
 2235:             '</span></td>'.
 2236:             '</tr>';
 2237:         $itemcount ++;
 2238:     }
 2239:     return ($datatable,$itemcount);
 2240: }
 2241: 
 2242: sub print_coursedefaults {
 2243:     my ($dom,$settings,$rowtotal) = @_;
 2244:     my ($css_class,$datatable);
 2245:     my $itemcount = 1;
 2246:     my (%checkedon,%checkedoff,%choices,%defaultchecked,@toggles);
 2247:     %choices =
 2248:         &Apache::lonlocal::texthash (
 2249:             canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
 2250:     );
 2251:     %defaultchecked = ('canuse_pdfforms' => 'off');
 2252:     @toggles = ('canuse_pdfforms',);
 2253:     ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
 2254:                                                  \%choices,$itemcount);
 2255:     $$rowtotal += $itemcount;
 2256:     return $datatable;
 2257: }
 2258: 
 2259: sub print_usersessions {
 2260:     my ($position,$dom,$settings,$rowtotal) = @_;
 2261:     my ($css_class,$datatable,%checked,%choices);
 2262:     my %lt = &usersession_titles();
 2263:     my $itemcount = 1;
 2264:     my $numinrow = 6;
 2265:     my $prefix;
 2266:     my @types;
 2267:     if ($position eq 'top') {
 2268:         $prefix = 'hosted';
 2269:         @types = ('excludedomain','includedomain');
 2270:     } else {
 2271:         $prefix = 'remote';
 2272:         @types = ('version','excludedomain','includedomain');
 2273:     } 
 2274:     my (%current,%checkedon,%checkedoff);
 2275:     my @lcversions = &Apache::lonnet::all_loncaparevs();
 2276:     my @alldoms = sort(&Apache::lonnet::all_domains());
 2277:     foreach my $type (@types) {
 2278:         $checkedon{$type} = '';
 2279:         $checkedoff{$type} = ' checked="checked"';
 2280:     }
 2281:     if (ref($settings) eq 'HASH') {
 2282:         if (ref($settings->{$prefix}) eq 'HASH') {
 2283:             foreach my $key (keys(%{$settings->{$prefix}})) {
 2284:                 $current{$key} = $settings->{$prefix}{$key};
 2285:                 if ($key eq 'version') {
 2286:                     if ($current{$key} ne '') {
 2287:                         $checkedon{$key} = ' checked="checked"';
 2288:                         $checkedoff{$key} = '';
 2289:                     }
 2290:                 } elsif (ref($current{$key}) eq 'ARRAY') {
 2291:                     $checkedon{$key} = ' checked="checked"';
 2292:                     $checkedoff{$key} = '';
 2293:                 }
 2294:             }
 2295:         }
 2296:     }
 2297:     foreach my $type (@types) {
 2298:         $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
 2299:         $datatable .= '<tr'.$css_class.'>
 2300:                        <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
 2301:                            <span class="LC_nobreak">&nbsp;
 2302:                            <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>&nbsp;
 2303:                            <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
 2304:         if ($type eq 'version') {
 2305:             my $selector = '<select name="'.$prefix.'_version">';
 2306:             foreach my $version (@lcversions) {
 2307:                 my $selected = '';
 2308:                 if ($current{'version'} eq $version) {
 2309:                     $selected = ' selected="selected"';
 2310:                 }
 2311:                 $selector .= ' <option value="'.$version.'"'.
 2312:                              $selected.'>'.$version.'</option>';
 2313:             }
 2314:             $selector .= '</select> ';
 2315:             $datatable .= &mt('remote server must be version: [_1] or later',$selector);
 2316:         } else {
 2317:             $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
 2318:                          'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
 2319:                          ' />'.('&nbsp;'x2).
 2320:                          '<input type="button" value="'.&mt('uncheck all').'" '.
 2321:                          'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
 2322:                          "\n".
 2323:                          '</div><div><table>';
 2324:             my $rem;
 2325:             for (my $i=0; $i<@alldoms; $i++) {
 2326:                 next if ($alldoms[$i] eq $dom);
 2327:                 my $checkedtype;
 2328:                 if (ref($current{$type}) eq 'ARRAY') {
 2329:                     if (grep(/^\Q$alldoms[$i]\E$/,@{$current{$type}})) {
 2330:                         $checkedtype = ' checked="checked"';
 2331:                     }
 2332:                 }
 2333:                 $rem = $i%($numinrow);
 2334:                 if ($rem == 0) {
 2335:                     if ($i > 0) {
 2336:                         $datatable .= '</tr>';
 2337:                     }
 2338:                     $datatable .= '<tr>';
 2339:                 }
 2340:                 $datatable .= '<td class="LC_left_item">'.
 2341:                               '<span class="LC_nobreak"><label>'.
 2342:                               '<input type="checkbox" name="'.$prefix.'_'.$type.
 2343:                               '" value="'.$alldoms[$i].'"'.$checkedtype.' />'.$alldoms[$i].
 2344:                               '</label></span></td>';
 2345:             }
 2346:             $rem = @alldoms%($numinrow);
 2347:             my $colsleft = $numinrow - $rem;
 2348:             if ($colsleft > 1 ) {
 2349:                 $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
 2350:                               '&nbsp;</td>';
 2351:             } elsif ($colsleft == 1) {
 2352:                 $datatable .= '<td class="LC_left_item">&nbsp;</td>';
 2353:             }
 2354:             $datatable .= '</tr></table>';
 2355:         }
 2356:         $datatable .= '</td></tr>';
 2357:         $itemcount ++;
 2358:     }
 2359:     $$rowtotal += $itemcount;
 2360:     return $datatable;
 2361: }
 2362: 
 2363: sub contact_titles {
 2364:     my %titles = &Apache::lonlocal::texthash (
 2365:                    'supportemail' => 'Support E-mail address',
 2366:                    'adminemail'   => 'Default Server Admin E-mail address',
 2367:                    'errormail'    => 'Error reports to be e-mailed to',
 2368:                    'packagesmail' => 'Package update alerts to be e-mailed to',
 2369:                    'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
 2370:                    'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
 2371:                    'requestsmail' => 'E-mail from course requests requiring approval',
 2372:                  );
 2373:     my %short_titles = &Apache::lonlocal::texthash (
 2374:                            adminemail   => 'Admin E-mail address',
 2375:                            supportemail => 'Support E-mail',
 2376:                        );   
 2377:     return (\%titles,\%short_titles);
 2378: }
 2379: 
 2380: sub tool_titles {
 2381:     my %titles = &Apache::lonlocal::texthash (
 2382:                      aboutme    => 'Personal Information Page',
 2383:                      blog       => 'Blog',
 2384:                      portfolio  => 'Portfolio',
 2385:                      official   => 'Official courses (with institutional codes)',
 2386:                      unofficial => 'Unofficial courses',
 2387:                      community  => 'Communities',
 2388:                  );
 2389:     return %titles;
 2390: }
 2391: 
 2392: sub courserequest_titles {
 2393:     my %titles = &Apache::lonlocal::texthash (
 2394:                                    official   => 'Official',
 2395:                                    unofficial => 'Unofficial',
 2396:                                    community  => 'Communities',
 2397:                                    norequest  => 'Not allowed',
 2398:                                    approval   => 'Approval by Dom. Coord.',
 2399:                                    validate   => 'With validation',
 2400:                                    autolimit  => 'Numerical limit',
 2401:                                    unlimited  => '(blank for unlimited)',
 2402:                  );
 2403:     return %titles;
 2404: }
 2405: 
 2406: sub courserequest_conditions {
 2407:     my %conditions = &Apache::lonlocal::texthash (
 2408:        approval    => '(Processing of request subject to approval by Domain Coordinator).',
 2409:        validate   => '(Processing of request subject to instittutional validation).',
 2410:                  );
 2411:     return %conditions;
 2412: }
 2413: 
 2414: 
 2415: sub print_usercreation {
 2416:     my ($position,$dom,$settings,$rowtotal) = @_;
 2417:     my $numinrow = 4;
 2418:     my $datatable;
 2419:     if ($position eq 'top') {
 2420:         $$rowtotal ++;
 2421:         my $rowcount = 0;
 2422:         my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
 2423:         if (ref($rules) eq 'HASH') {
 2424:             if (keys(%{$rules}) > 0) {
 2425:                 $datatable .= &user_formats_row('username',$settings,$rules,
 2426:                                                 $ruleorder,$numinrow,$rowcount);
 2427:                 $$rowtotal ++;
 2428:                 $rowcount ++;
 2429:             }
 2430:         }
 2431:         my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
 2432:         if (ref($idrules) eq 'HASH') {
 2433:             if (keys(%{$idrules}) > 0) {
 2434:                 $datatable .= &user_formats_row('id',$settings,$idrules,
 2435:                                                 $idruleorder,$numinrow,$rowcount);
 2436:                 $$rowtotal ++;
 2437:                 $rowcount ++;
 2438:             }
 2439:         }
 2440:         my ($emailrules,$emailruleorder) = 
 2441:             &Apache::lonnet::inst_userrules($dom,'email');
 2442:         if (ref($emailrules) eq 'HASH') {
 2443:             if (keys(%{$emailrules}) > 0) {
 2444:                 $datatable .= &user_formats_row('email',$settings,$emailrules,
 2445:                                                 $emailruleorder,$numinrow,$rowcount);
 2446:                 $$rowtotal ++;
 2447:                 $rowcount ++;
 2448:             }
 2449:         }
 2450:         if ($rowcount == 0) {
 2451:             $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';  
 2452:             $$rowtotal ++;
 2453:             $rowcount ++;
 2454:         }
 2455:     } elsif ($position eq 'middle') {
 2456:         my @creators = ('author','course','requestcrs','selfcreate');
 2457:         my ($rules,$ruleorder) =
 2458:             &Apache::lonnet::inst_userrules($dom,'username');
 2459:         my %lt = &usercreation_types();
 2460:         my %checked;
 2461:         my @selfcreate; 
 2462:         if (ref($settings) eq 'HASH') {
 2463:             if (ref($settings->{'cancreate'}) eq 'HASH') {
 2464:                 foreach my $item (@creators) {
 2465:                     $checked{$item} = $settings->{'cancreate'}{$item};
 2466:                 }
 2467:                 if (ref($settings->{'cancreate'}{'selfcreate'}) eq 'ARRAY') {
 2468:                     @selfcreate = @{$settings->{'cancreate'}{'selfcreate'}};
 2469:                 } elsif ($settings->{'cancreate'}{'selfcreate'} ne '') {
 2470:                     if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
 2471:                         @selfcreate = ('email','login','sso');
 2472:                     } elsif ($settings->{'cancreate'}{'selfcreate'} ne 'none') {
 2473:                         @selfcreate = ($settings->{'cancreate'}{'selfcreate'});
 2474:                     }
 2475:                 }
 2476:             } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
 2477:                 foreach my $item (@creators) {
 2478:                     if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
 2479:                         $checked{$item} = 'none';
 2480:                     }
 2481:                 }
 2482:             }
 2483:         }
 2484:         my $rownum = 0;
 2485:         foreach my $item (@creators) {
 2486:             $rownum ++;
 2487:             if ($item ne 'selfcreate') {  
 2488:                 if ($checked{$item} eq '') {
 2489:                     $checked{$item} = 'any';
 2490:                 }
 2491:             }
 2492:             my $css_class;
 2493:             if ($rownum%2) {
 2494:                 $css_class = '';
 2495:             } else {
 2496:                 $css_class = ' class="LC_odd_row" ';
 2497:             }
 2498:             $datatable .= '<tr'.$css_class.'>'.
 2499:                          '<td><span class="LC_nobreak">'.$lt{$item}.
 2500:                          '</span></td><td align="right">';
 2501:             my @options;
 2502:             if ($item eq 'selfcreate') {
 2503:                 push(@options,('email','login','sso'));
 2504:             } else {
 2505:                 @options = ('any');
 2506:                 if (ref($rules) eq 'HASH') {
 2507:                     if (keys(%{$rules}) > 0) {
 2508:                         push(@options,('official','unofficial'));
 2509:                     }
 2510:                 }
 2511:                 push(@options,'none');
 2512:             }
 2513:             foreach my $option (@options) {
 2514:                 my $type = 'radio';
 2515:                 my $check = ' ';
 2516:                 if ($item eq 'selfcreate') {
 2517:                     $type = 'checkbox';
 2518:                     if (grep(/^\Q$option\E$/,@selfcreate)) {
 2519:                         $check = ' checked="checked" ';
 2520:                     }
 2521:                 } else {
 2522:                     if ($checked{$item} eq $option) {
 2523:                         $check = ' checked="checked" ';
 2524:                     }
 2525:                 } 
 2526:                 $datatable .= '<span class="LC_nobreak"><label>'.
 2527:                               '<input type="'.$type.'" name="can_createuser_'.
 2528:                               $item.'" value="'.$option.'"'.$check.'/>&nbsp;'.
 2529:                               $lt{$option}.'</label>&nbsp;&nbsp;</span>';
 2530:             }
 2531:             $datatable .= '</td></tr>';
 2532:         }
 2533:         my ($othertitle,$usertypes,$types) =
 2534:             &Apache::loncommon::sorted_inst_types($dom);
 2535:         if (ref($usertypes) eq 'HASH') {
 2536:             if (keys(%{$usertypes}) > 0) {
 2537:                 my $createsettings;
 2538:                 if (ref($settings) eq 'HASH') {
 2539:                     $createsettings = $settings->{cancreate};
 2540:                 }
 2541:                 $datatable .= &insttypes_row($createsettings,$types,$usertypes,
 2542:                                              $dom,$numinrow,$othertitle,
 2543:                                              'statustocreate');
 2544:                 $$rowtotal ++;
 2545:             }
 2546:         }
 2547:     } else {
 2548:         my @contexts = ('author','course','domain');
 2549:         my @authtypes = ('int','krb4','krb5','loc');
 2550:         my %checked;
 2551:         if (ref($settings) eq 'HASH') {
 2552:             if (ref($settings->{'authtypes'}) eq 'HASH') {
 2553:                 foreach my $item (@contexts) {
 2554:                     if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
 2555:                         foreach my $auth (@authtypes) {
 2556:                             if ($settings->{'authtypes'}{$item}{$auth}) {
 2557:                                 $checked{$item}{$auth} = ' checked="checked" ';
 2558:                             }
 2559:                         }
 2560:                     }
 2561:                 }
 2562:             }
 2563:         } else {
 2564:             foreach my $item (@contexts) {
 2565:                 foreach my $auth (@authtypes) {
 2566:                     $checked{$item}{$auth} = ' checked="checked" ';
 2567:                 }
 2568:             }
 2569:         }
 2570:         my %title = &context_names();
 2571:         my %authname = &authtype_names();
 2572:         my $rownum = 0;
 2573:         my $css_class; 
 2574:         foreach my $item (@contexts) {
 2575:             if ($rownum%2) {
 2576:                 $css_class = '';
 2577:             } else {
 2578:                 $css_class = ' class="LC_odd_row" ';
 2579:             }
 2580:             $datatable .=   '<tr'.$css_class.'>'.
 2581:                             '<td>'.$title{$item}.
 2582:                             '</td><td class="LC_left_item">'.
 2583:                             '<span class="LC_nobreak">';
 2584:             foreach my $auth (@authtypes) {
 2585:                 $datatable .= '<label>'. 
 2586:                               '<input type="checkbox" name="'.$item.'_auth" '.
 2587:                               $checked{$item}{$auth}.' value="'.$auth.'" />'.
 2588:                               $authname{$auth}.'</label>&nbsp;';
 2589:             }
 2590:             $datatable .= '</span></td></tr>';
 2591:             $rownum ++;
 2592:         }
 2593:         $$rowtotal += $rownum;
 2594:     }
 2595:     return $datatable;
 2596: }
 2597: 
 2598: sub user_formats_row {
 2599:     my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
 2600:     my $output;
 2601:     my %text = (
 2602:                    'username' => 'new usernames',
 2603:                    'id'       => 'IDs',
 2604:                    'email'    => 'self-created accounts (e-mail)',
 2605:                );
 2606:     my $css_class = $rowcount%2?' class="LC_odd_row"':'';
 2607:     $output = '<tr '.$css_class.'>'.
 2608:               '<td><span class="LC_nobreak">';
 2609:     if ($type eq 'email') {
 2610:         $output .= &mt("Formats disallowed for $text{$type}: ");
 2611:     } else {
 2612:         $output .= &mt("Format rules to check for $text{$type}: ");
 2613:     }
 2614:     $output .= '</span></td>'.
 2615:                '<td class="LC_left_item" colspan="2"><table>';
 2616:     my $rem;
 2617:     if (ref($ruleorder) eq 'ARRAY') {
 2618:         for (my $i=0; $i<@{$ruleorder}; $i++) {
 2619:             if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
 2620:                 my $rem = $i%($numinrow);
 2621:                 if ($rem == 0) {
 2622:                     if ($i > 0) {
 2623:                         $output .= '</tr>';
 2624:                     }
 2625:                     $output .= '<tr>';
 2626:                 }
 2627:                 my $check = ' ';
 2628:                 if (ref($settings) eq 'HASH') {
 2629:                     if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
 2630:                         if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
 2631:                             $check = ' checked="checked" ';
 2632:                         }
 2633:                     }
 2634:                 }
 2635:                 $output .= '<td class="LC_left_item">'.
 2636:                            '<span class="LC_nobreak"><label>'.
 2637:                            '<input type="checkbox" name="'.$type.'_rule" '.
 2638:                            'value="'.$ruleorder->[$i].'"'.$check.'/>'.
 2639:                            $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
 2640:             }
 2641:         }
 2642:         $rem = @{$ruleorder}%($numinrow);
 2643:     }
 2644:     my $colsleft = $numinrow - $rem;
 2645:     if ($colsleft > 1 ) {
 2646:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
 2647:                    '&nbsp;</td>';
 2648:     } elsif ($colsleft == 1) {
 2649:         $output .= '<td class="LC_left_item">&nbsp;</td>';
 2650:     }
 2651:     $output .= '</tr></table></td></tr>';
 2652:     return $output;
 2653: }
 2654: 
 2655: sub usercreation_types {
 2656:     my %lt = &Apache::lonlocal::texthash (
 2657:                     author     => 'When adding a co-author',
 2658:                     course     => 'When adding a user to a course',
 2659:                     requestcrs => 'When requesting a course',
 2660:                     selfcreate => 'User creates own account', 
 2661:                     any        => 'Any',
 2662:                     official   => 'Institutional only ',
 2663:                     unofficial => 'Non-institutional only',
 2664:                     email      => 'E-mail address',
 2665:                     login      => 'Institutional Login',
 2666:                     sso        => 'SSO', 
 2667:                     none       => 'None',
 2668:     );
 2669:     return %lt;
 2670: }
 2671: 
 2672: sub authtype_names {
 2673:     my %lt = &Apache::lonlocal::texthash(
 2674:                       int    => 'Internal',
 2675:                       krb4   => 'Kerberos 4',
 2676:                       krb5   => 'Kerberos 5',
 2677:                       loc    => 'Local',
 2678:                   );
 2679:     return %lt;
 2680: }
 2681: 
 2682: sub context_names {
 2683:     my %context_title = &Apache::lonlocal::texthash(
 2684:        author => 'Creating users when an Author',
 2685:        course => 'Creating users when in a course',
 2686:        domain => 'Creating users when a Domain Coordinator',
 2687:     );
 2688:     return %context_title;
 2689: }
 2690: 
 2691: sub print_usermodification {
 2692:     my ($position,$dom,$settings,$rowtotal) = @_;
 2693:     my $numinrow = 4;
 2694:     my ($context,$datatable,$rowcount);
 2695:     if ($position eq 'top') {
 2696:         $rowcount = 0;
 2697:         $context = 'author'; 
 2698:         foreach my $role ('ca','aa') {
 2699:             $datatable .= &modifiable_userdata_row($context,$role,$settings,
 2700:                                                    $numinrow,$rowcount);
 2701:             $$rowtotal ++;
 2702:             $rowcount ++;
 2703:         }
 2704:     } elsif ($position eq 'middle') {
 2705:         $context = 'course';
 2706:         $rowcount = 0;
 2707:         foreach my $role ('st','ep','ta','in','cr') {
 2708:             $datatable .= &modifiable_userdata_row($context,$role,$settings,
 2709:                                                    $numinrow,$rowcount);
 2710:             $$rowtotal ++;
 2711:             $rowcount ++;
 2712:         }
 2713:     } elsif ($position eq 'bottom') {
 2714:         $context = 'selfcreate';
 2715:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
 2716:         $usertypes->{'default'} = $othertitle;
 2717:         if (ref($types) eq 'ARRAY') {
 2718:             push(@{$types},'default');
 2719:             $usertypes->{'default'} = $othertitle;
 2720:             foreach my $status (@{$types}) {
 2721:                 $datatable .= &modifiable_userdata_row($context,$status,$settings,
 2722:                                                        $numinrow,$rowcount,$usertypes);
 2723:                 $$rowtotal ++;
 2724:                 $rowcount ++;
 2725:             }
 2726:         }
 2727:     }
 2728:     return $datatable;
 2729: }
 2730: 
 2731: sub print_defaults {
 2732:     my ($dom,$rowtotal) = @_;
 2733:     my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
 2734:                  'datelocale_def');
 2735:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
 2736:     my $titles = &defaults_titles();
 2737:     my $rownum = 0;
 2738:     my ($datatable,$css_class);
 2739:     foreach my $item (@items) {
 2740:         if ($rownum%2) {
 2741:             $css_class = '';
 2742:         } else {
 2743:             $css_class = ' class="LC_odd_row" ';
 2744:         }
 2745:         $datatable .= '<tr'.$css_class.'>'.
 2746:                   '<td><span class="LC_nobreak">'.$titles->{$item}.
 2747:                   '</span></td><td class="LC_right_item">';
 2748:         if ($item eq 'auth_def') {
 2749:             my @authtypes = ('internal','krb4','krb5','localauth');
 2750:             my %shortauth = (
 2751:                              internal => 'int',
 2752:                              krb4 => 'krb4',
 2753:                              krb5 => 'krb5',
 2754:                              localauth  => 'loc'
 2755:                            );
 2756:             my %authnames = &authtype_names();
 2757:             foreach my $auth (@authtypes) {
 2758:                 my $checked = ' ';
 2759:                 if ($domdefaults{$item} eq $auth) {
 2760:                     $checked = ' checked="checked" ';
 2761:                 }
 2762:                 $datatable .= '<label><input type="radio" name="'.$item.
 2763:                               '" value="'.$auth.'"'.$checked.'/>'.
 2764:                               $authnames{$shortauth{$auth}}.'</label>&nbsp;&nbsp;';
 2765:             }
 2766:         } elsif ($item eq 'timezone_def') {
 2767:             my $includeempty = 1;
 2768:             $datatable .= &Apache::loncommon::select_timezone($item,$domdefaults{$item},undef,$includeempty);
 2769:         } elsif ($item eq 'datelocale_def') {
 2770:             my $includeempty = 1;
 2771:             $datatable .= &Apache::loncommon::select_datelocale($item,$domdefaults{$item},undef,$includeempty);
 2772:         } else {
 2773:             $datatable .= '<input type="text" name="'.$item.'" value="'.
 2774:                           $domdefaults{$item}.'" />';
 2775:         }
 2776:         $datatable .= '</td></tr>';
 2777:         $rownum ++;
 2778:     }
 2779:     $$rowtotal += $rownum;
 2780:     return $datatable;
 2781: }
 2782: 
 2783: sub defaults_titles {
 2784:     my %titles = &Apache::lonlocal::texthash (
 2785:                    'auth_def'      => 'Default authentication type',
 2786:                    'auth_arg_def'  => 'Default authentication argument',
 2787:                    'lang_def'      => 'Default language',
 2788:                    'timezone_def'  => 'Default timezone',
 2789:                    'datelocale_def' => 'Default locale for dates',
 2790:                  );
 2791:     return (\%titles);
 2792: }
 2793: 
 2794: sub print_scantronformat {
 2795:     my ($r,$dom,$confname,$settings,$rowtotal) = @_;
 2796:     my $itemcount = 1;
 2797:     my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
 2798:         %confhash);
 2799:     my $switchserver = &check_switchserver($dom,$confname);
 2800:     my %lt = &Apache::lonlocal::texthash (
 2801:                 default => 'Default bubblesheet format file error',
 2802:                 custom  => 'Custom bubblesheet format file error',
 2803:              );
 2804:     my %scantronfiles = (
 2805:         default => 'default.tab',
 2806:         custom => 'custom.tab',
 2807:     );
 2808:     foreach my $key (keys(%scantronfiles)) {
 2809:         $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
 2810:                               .$scantronfiles{$key};
 2811:     }
 2812:     my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
 2813:     if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
 2814:         if (!$switchserver) {
 2815:             my $servadm = $r->dir_config('lonAdmEMail');
 2816:             my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
 2817:             if ($configuserok eq 'ok') {
 2818:                 if ($author_ok eq 'ok') {
 2819:                     my %legacyfile = (
 2820:  default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab', 
 2821:  custom  => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab', 
 2822:                     );
 2823:                     my %md5chk;
 2824:                     foreach my $type (keys(%legacyfile)) {
 2825:                         ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
 2826:                         chomp($md5chk{$type});
 2827:                     }
 2828:                     if ($md5chk{'default'} ne $md5chk{'custom'}) {
 2829:                         foreach my $type (keys(%legacyfile)) {
 2830:                             ($scantronurls{$type},my $error) = 
 2831:                                 &legacy_scantronformat($r,$dom,$confname,
 2832:                                                  $type,$legacyfile{$type},
 2833:                                                  $scantronurls{$type},
 2834:                                                  $scantronfiles{$type});
 2835:                             if ($error ne '') {
 2836:                                 $error{$type} = $error;
 2837:                             }
 2838:                         }
 2839:                         if (keys(%error) == 0) {
 2840:                             $is_custom = 1;
 2841:                             $confhash{'scantron'}{'scantronformat'} = 
 2842:                                 $scantronurls{'custom'};
 2843:                             my $putresult = 
 2844:                                 &Apache::lonnet::put_dom('configuration',
 2845:                                                          \%confhash,$dom);
 2846:                             if ($putresult ne 'ok') {
 2847:                                 $error{'custom'} = 
 2848:                                     '<span class="LC_error">'.
 2849:                                     &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
 2850:                             }
 2851:                         }
 2852:                     } else {
 2853:                         ($scantronurls{'default'},my $error) =
 2854:                             &legacy_scantronformat($r,$dom,$confname,
 2855:                                           'default',$legacyfile{'default'},
 2856:                                           $scantronurls{'default'},
 2857:                                           $scantronfiles{'default'});
 2858:                         if ($error eq '') {
 2859:                             $confhash{'scantron'}{'scantronformat'} = ''; 
 2860:                             my $putresult =
 2861:                                 &Apache::lonnet::put_dom('configuration',
 2862:                                                          \%confhash,$dom);
 2863:                             if ($putresult ne 'ok') {
 2864:                                 $error{'default'} =
 2865:                                     '<span class="LC_error">'.
 2866:                                     &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
 2867:                             }
 2868:                         } else {
 2869:                             $error{'default'} = $error;
 2870:                         }
 2871:                     }
 2872:                 }
 2873:             }
 2874:         } else {
 2875:             $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
 2876:         }
 2877:     }
 2878:     if (ref($settings) eq 'HASH') {
 2879:         if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
 2880:             my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
 2881:             if ((!@info) || ($info[0] eq 'no_such_dir')) {
 2882:                 $scantronurl = '';
 2883:             } else {
 2884:                 $scantronurl = $settings->{'scantronformat'};
 2885:             }
 2886:             $is_custom = 1;
 2887:         } else {
 2888:             $scantronurl = $scantronurls{'default'};
 2889:         }
 2890:     } else {
 2891:         if ($is_custom) {
 2892:             $scantronurl = $scantronurls{'custom'};
 2893:         } else {
 2894:             $scantronurl = $scantronurls{'default'};
 2895:         }
 2896:     }
 2897:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
 2898:     $datatable .= '<tr'.$css_class.'>';
 2899:     if (!$is_custom) {
 2900:         $datatable .= '<td>'.&mt('Default in use:').'<br />'.
 2901:                       '<span class="LC_nobreak">';
 2902:         if ($scantronurl) {
 2903:             $datatable .= '<a href="'.$scantronurl.'" target="_blank">'.
 2904:                           &mt('Default bubblesheet format file').'</a>';
 2905:         } else {
 2906:             $datatable = &mt('File unavailable for display');
 2907:         }
 2908:         $datatable .= '</span></td>';
 2909:         if (keys(%error) == 0) { 
 2910:             $datatable .= '<td valign="bottom">';
 2911:             if (!$switchserver) {
 2912:                 $datatable .= &mt('Upload:').'<br />';
 2913:             }
 2914:         } else {
 2915:             my $errorstr;
 2916:             foreach my $key (sort(keys(%error))) {
 2917:                 $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
 2918:             }
 2919:             $datatable .= '<td>'.$errorstr;
 2920:         }
 2921:     } else {
 2922:         if (keys(%error) > 0) {
 2923:             my $errorstr;
 2924:             foreach my $key (sort(keys(%error))) {
 2925:                 $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
 2926:             } 
 2927:             $datatable .= '<td>'.$errorstr.'</td><td>&nbsp;';
 2928:         } elsif ($scantronurl) {
 2929:             $datatable .= '<td><span class="LC_nobreak">'.
 2930:                           '<a href="'.$scantronurl.'" target="_blank">'.
 2931:                           &mt('Custom bubblesheet format file').'</a><label>'.
 2932:                           '<input type="checkbox" name="scantronformat_del"'.
 2933:                           '" value="1" />'.&mt('Delete?').'</label></span></td>'.
 2934:                           '<td><span class="LC_nobreak">&nbsp;'.
 2935:                           &mt('Replace:').'</span><br />';
 2936:         }
 2937:     }
 2938:     if (keys(%error) == 0) {
 2939:         if ($switchserver) {
 2940:             $datatable .= &mt('Upload to library server: [_1]',$switchserver);
 2941:         } else {
 2942:             $datatable .='<span class="LC_nobreak">&nbsp;'.
 2943:                          '<input type="file" name="scantronformat" /></span>';
 2944:         }
 2945:     }
 2946:     $datatable .= '</td></tr>';
 2947:     $$rowtotal ++;
 2948:     return $datatable;
 2949: }
 2950: 
 2951: sub legacy_scantronformat {
 2952:     my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
 2953:     my ($url,$error);
 2954:     my @statinfo = &Apache::lonnet::stat_file($newurl);
 2955:     if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
 2956:         (my $result,$url) =
 2957:             &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
 2958:                          '','',$newfile);
 2959:         if ($result ne 'ok') {
 2960:             $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
 2961:         }
 2962:     }
 2963:     return ($url,$error);
 2964: }
 2965: 
 2966: sub print_coursecategories {
 2967:     my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
 2968:     my $datatable;
 2969:     if ($position eq 'top') {
 2970:         my $toggle_cats_crs = ' ';
 2971:         my $toggle_cats_dom = ' checked="checked" ';
 2972:         my $can_cat_crs = ' ';
 2973:         my $can_cat_dom = ' checked="checked" ';
 2974:         my $toggle_catscomm_comm = ' ';
 2975:         my $toggle_catscomm_dom = ' checked="checked" ';
 2976:         my $can_catcomm_comm = ' ';
 2977:         my $can_catcomm_dom = ' checked="checked" ';
 2978: 
 2979:         if (ref($settings) eq 'HASH') {
 2980:             if ($settings->{'togglecats'} eq 'crs') {
 2981:                 $toggle_cats_crs = $toggle_cats_dom;
 2982:                 $toggle_cats_dom = ' ';
 2983:             }
 2984:             if ($settings->{'categorize'} eq 'crs') {
 2985:                 $can_cat_crs = $can_cat_dom;
 2986:                 $can_cat_dom = ' ';
 2987:             }
 2988:             if ($settings->{'togglecatscomm'} eq 'comm') {
 2989:                 $toggle_catscomm_comm = $toggle_catscomm_dom;
 2990:                 $toggle_catscomm_dom = ' ';
 2991:             }
 2992:             if ($settings->{'categorizecomm'} eq 'comm') {
 2993:                 $can_catcomm_comm = $can_catcomm_dom;
 2994:                 $can_catcomm_dom = ' ';
 2995:             }
 2996:         }
 2997:         my %title = &Apache::lonlocal::texthash (
 2998:                      togglecats     => 'Show/Hide a course in catalog',
 2999:                      togglecatscomm => 'Show/Hide a community in catalog',
 3000:                      categorize     => 'Assign a category to a course',
 3001:                      categorizecomm => 'Assign a category to a community',
 3002:                     );
 3003:         my %level = &Apache::lonlocal::texthash (
 3004:                      dom  => 'Set in Domain',
 3005:                      crs  => 'Set in Course',
 3006:                      comm => 'Set in Community',
 3007:                     );
 3008:         $datatable = '<tr class="LC_odd_row">'.
 3009:                   '<td>'.$title{'togglecats'}.'</td>'.
 3010:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
 3011:                   '<input type="radio" name="togglecats"'.
 3012:                   $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
 3013:                   '<label><input type="radio" name="togglecats"'.
 3014:                   $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
 3015:                   '</tr><tr>'.
 3016:                   '<td>'.$title{'categorize'}.'</td>'.
 3017:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
 3018:                   '<label><input type="radio" name="categorize"'.
 3019:                   $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
 3020:                   '<label><input type="radio" name="categorize"'.
 3021:                   $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
 3022:                   '</tr><tr class="LC_odd_row">'.
 3023:                   '<td>'.$title{'togglecatscomm'}.'</td>'.
 3024:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
 3025:                   '<input type="radio" name="togglecatscomm"'.
 3026:                   $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
 3027:                   '<label><input type="radio" name="togglecatscomm"'.
 3028:                   $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
 3029:                   '</tr><tr>'.
 3030:                   '<td>'.$title{'categorizecomm'}.'</td>'.
 3031:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
 3032:                   '<label><input type="radio" name="categorizecomm"'.
 3033:                   $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
 3034:                   '<label><input type="radio" name="categorizecomm"'.
 3035:                   $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
 3036:                   '</tr>';
 3037:         $$rowtotal += 4;
 3038:     } else {
 3039:         my $css_class;
 3040:         my $itemcount = 1;
 3041:         my $cathash; 
 3042:         if (ref($settings) eq 'HASH') {
 3043:             $cathash = $settings->{'cats'};
 3044:         }
 3045:         if (ref($cathash) eq 'HASH') {
 3046:             my (@cats,@trails,%allitems,%idx,@jsarray);
 3047:             &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
 3048:                                                    \%allitems,\%idx,\@jsarray);
 3049:             my $maxdepth = scalar(@cats);
 3050:             my $colattrib = '';
 3051:             if ($maxdepth > 2) {
 3052:                 $colattrib = ' colspan="2" ';
 3053:             }
 3054:             my @path;
 3055:             if (@cats > 0) {
 3056:                 if (ref($cats[0]) eq 'ARRAY') {
 3057:                     my $numtop = @{$cats[0]};
 3058:                     my $maxnum = $numtop;
 3059:                     my %default_names = (
 3060:                           instcode    => &mt('Official courses'),
 3061:                           communities => &mt('Communities'),
 3062:                     );
 3063: 
 3064:                     if ((!grep(/^instcode$/,@{$cats[0]})) || 
 3065:                         ($cathash->{'instcode::0'} eq '') ||
 3066:                         (!grep(/^communities$/,@{$cats[0]})) || 
 3067:                         ($cathash->{'communities::0'} eq '')) {
 3068:                         $maxnum ++;
 3069:                     }
 3070:                     my $lastidx;
 3071:                     for (my $i=0; $i<$numtop; $i++) {
 3072:                         my $parent = $cats[0][$i];
 3073:                         $css_class = $itemcount%2?' class="LC_odd_row"':'';
 3074:                         my $item = &escape($parent).'::0';
 3075:                         my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
 3076:                         $lastidx = $idx{$item};
 3077:                         $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
 3078:                                       .'<select name="'.$item.'"'.$chgstr.'>';
 3079:                         for (my $k=0; $k<=$maxnum; $k++) {
 3080:                             my $vpos = $k+1;
 3081:                             my $selstr;
 3082:                             if ($k == $i) {
 3083:                                 $selstr = ' selected="selected" ';
 3084:                             }
 3085:                             $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
 3086:                         }
 3087:                         $datatable .= '</select></td><td>';
 3088:                         if ($parent eq 'instcode' || $parent eq 'communities') {
 3089:                             $datatable .=  '<span class="LC_nobreak">'
 3090:                                            .$default_names{$parent}.'</span>';
 3091:                             if ($parent eq 'instcode') {
 3092:                                 $datatable .= '<br /><span class="LC_nobreak">('
 3093:                                               .&mt('with institutional codes')
 3094:                                               .')</span></td><td'.$colattrib.'>';
 3095:                             } else {
 3096:                                 $datatable .= '<table><tr><td>';
 3097:                             }
 3098:                             $datatable .= '<span class="LC_nobreak">'
 3099:                                           .'<label><input type="radio" name="'
 3100:                                           .$parent.'" value="1" checked="checked" />'
 3101:                                           .&mt('Display').'</label>';
 3102:                             if ($parent eq 'instcode') {
 3103:                                 $datatable .= '&nbsp;';
 3104:                             } else {
 3105:                                 $datatable .= '</span></td></tr><tr><td>'
 3106:                                               .'<span class="LC_nobreak">';
 3107:                             }
 3108:                             $datatable .= '<label><input type="radio" name="'
 3109:                                           .$parent.'" value="0" />'
 3110:                                           .&mt('Do not display').'</label></span>';
 3111:                             if ($parent eq 'communities') {
 3112:                                 $datatable .= '</td></tr></table>';
 3113:                             }
 3114:                             $datatable .= '</td>';
 3115:                         } else {
 3116:                             $datatable .= $parent
 3117:                                           .'&nbsp;<label><input type="checkbox" name="deletecategory" '
 3118:                                           .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
 3119:                         }
 3120:                         my $depth = 1;
 3121:                         push(@path,$parent);
 3122:                         $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
 3123:                         pop(@path);
 3124:                         $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
 3125:                         $itemcount ++;
 3126:                     }
 3127:                     $css_class = $itemcount%2?' class="LC_odd_row"':'';
 3128:                     my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
 3129:                     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
 3130:                     for (my $k=0; $k<=$maxnum; $k++) {
 3131:                         my $vpos = $k+1;
 3132:                         my $selstr;
 3133:                         if ($k == $numtop) {
 3134:                             $selstr = ' selected="selected" ';
 3135:                         }
 3136:                         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
 3137:                     }
 3138:                     $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').'&nbsp;'
 3139:                                   .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
 3140:                                   .'</tr>'."\n";
 3141:                     $itemcount ++;
 3142:                     foreach my $default ('instcode','communities') {
 3143:                         if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
 3144:                             $css_class = $itemcount%2?' class="LC_odd_row"':'';
 3145:                             my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
 3146:                             $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
 3147:                                           '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
 3148:                             for (my $k=0; $k<=$maxnum; $k++) {
 3149:                                 my $vpos = $k+1;
 3150:                                 my $selstr;
 3151:                                 if ($k == $maxnum) {
 3152:                                     $selstr = ' selected="selected" ';
 3153:                                 }
 3154:                                 $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
 3155:                             }
 3156:                             $datatable .= '</select></span></td>'.
 3157:                                           '<td><span class="LC_nobreak">'.
 3158:                                           $default_names{$default}.'</span>';
 3159:                             if ($default eq 'instcode') {
 3160:                                 $datatable .= '<br /><span class="LC_nobreak">(' 
 3161:                                               .&mt('with institutional codes').')</span>';
 3162:                             }
 3163:                             $datatable .= '</td>'
 3164:                                           .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
 3165:                                           .&mt('Display').'</label>&nbsp;'
 3166:                                           .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
 3167:                                           .&mt('Do not display').'</label></span></td></tr>';
 3168:                         }
 3169:                     }
 3170:                 }
 3171:             } else {
 3172:                 $datatable .= &initialize_categories($itemcount);
 3173:             }
 3174:         } else {
 3175:             $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[0]->{'col2'}.'</td>'
 3176:                           .&initialize_categories($itemcount);
 3177:         }
 3178:         $$rowtotal += $itemcount;
 3179:     }
 3180:     return $datatable;
 3181: }
 3182: 
 3183: sub print_serverstatuses {
 3184:     my ($dom,$settings,$rowtotal) = @_;
 3185:     my $datatable;
 3186:     my @pages = &serverstatus_pages();
 3187:     my (%namedaccess,%machineaccess);
 3188:     foreach my $type (@pages) {
 3189:         $namedaccess{$type} = '';
 3190:         $machineaccess{$type}= '';
 3191:     }
 3192:     if (ref($settings) eq 'HASH') {
 3193:         foreach my $type (@pages) {
 3194:             if (exists($settings->{$type})) {
 3195:                 if (ref($settings->{$type}) eq 'HASH') {
 3196:                     foreach my $key (keys(%{$settings->{$type}})) {
 3197:                         if ($key eq 'namedusers') {
 3198:                             $namedaccess{$type} = $settings->{$type}->{$key};
 3199:                         } elsif ($key eq 'machines') {
 3200:                             $machineaccess{$type} = $settings->{$type}->{$key};
 3201:                         }
 3202:                     }
 3203:                 }
 3204:             }
 3205:         }
 3206:     }
 3207:     my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
 3208:     my $rownum = 0;
 3209:     my $css_class;
 3210:     foreach my $type (@pages) {
 3211:         $rownum ++;
 3212:         $css_class = $rownum%2?' class="LC_odd_row"':'';
 3213:         $datatable .= '<tr'.$css_class.'>'.
 3214:                       '<td><span class="LC_nobreak">'.
 3215:                       $titles->{$type}.'</span></td>'.
 3216:                       '<td class="LC_left_item">'.
 3217:                       '<input type="text" name="'.$type.'_namedusers" '.
 3218:                       'value="'.$namedaccess{$type}.'" size="30" /></td>'.
 3219:                       '<td class="LC_right_item">'.
 3220:                       '<span class="LC_nobreak">'.
 3221:                       '<input type="text" name="'.$type.'_machines" '.
 3222:                       'value="'.$machineaccess{$type}.'" size="10" />'.
 3223:                       '</td></tr>'."\n";
 3224:     }
 3225:     $$rowtotal += $rownum;
 3226:     return $datatable;
 3227: }
 3228: 
 3229: sub serverstatus_pages {
 3230:     return ('userstatus','lonstatus','loncron','server-status','codeversions',
 3231:             'clusterstatus','metadata_keywords','metadata_harvest',
 3232:             'takeoffline','takeonline','showenv','toggledebug');
 3233: }
 3234: 
 3235: sub coursecategories_javascript {
 3236:     my ($settings) = @_;
 3237:     my ($output,$jstext,$cathash);
 3238:     if (ref($settings) eq 'HASH') {
 3239:         $cathash = $settings->{'cats'};
 3240:     }
 3241:     if (ref($cathash) eq 'HASH') {
 3242:         my (@cats,@jsarray,%idx);
 3243:         &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
 3244:         if (@jsarray > 0) {
 3245:             $jstext = '    var categories = Array('.scalar(@jsarray).');'."\n";
 3246:             for (my $i=0; $i<@jsarray; $i++) {
 3247:                 if (ref($jsarray[$i]) eq 'ARRAY') {
 3248:                     my $catstr = join('","',@{$jsarray[$i]});
 3249:                     $jstext .= '    categories['.$i.'] = Array("'.$catstr.'");'."\n";
 3250:                 }
 3251:             }
 3252:         }
 3253:     } else {
 3254:         $jstext  = '    var categories = Array(1);'."\n".
 3255:                    '    categories[0] = Array("instcode_pos");'."\n"; 
 3256:     }
 3257:     my $instcode_reserved = &mt('The name: "instcode" is a reserved category');
 3258:     my $communities_reserved = &mt('The name: "communities" is a reserved category');
 3259:     my $choose_again = '\\n'.&mt('Please use a different name for the new top level category'); 
 3260:     $output = <<"ENDSCRIPT";
 3261: <script type="text/javascript">
 3262: // <![CDATA[
 3263: function reorderCats(form,parent,item,idx) {
 3264:     var changedVal;
 3265: $jstext
 3266:     var newpos = 'addcategory_pos';
 3267:     var current = new Array;
 3268:     if (parent == '') {
 3269:         var has_instcode = 0;
 3270:         var maxtop = categories[idx].length;
 3271:         for (var j=0; j<maxtop; j++) {
 3272:             if (categories[idx][j] == 'instcode::0') {
 3273:                 has_instcode == 1;
 3274:             }
 3275:         }
 3276:         if (has_instcode == 0) {
 3277:             categories[idx][maxtop] = 'instcode_pos';
 3278:         }
 3279:     } else {
 3280:         newpos += '_'+parent;
 3281:     }
 3282:     var maxh = 1 + categories[idx].length;
 3283:     var current = new Array;
 3284:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
 3285:     if (item == newpos) {
 3286:         changedVal = newitemVal;
 3287:     } else {
 3288:         changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
 3289:         current[newitemVal] = newpos;
 3290:     }
 3291:     for (var i=0; i<categories[idx].length; i++) {
 3292:         var elementName = categories[idx][i];
 3293:         if (elementName != item) {
 3294:             if (form.elements[elementName]) {
 3295:                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
 3296:                 current[currVal] = elementName;
 3297:             }
 3298:         }
 3299:     }
 3300:     var oldVal;
 3301:     for (var j=0; j<maxh; j++) {
 3302:         if (current[j] == undefined) {
 3303:             oldVal = j;
 3304:         }
 3305:     }
 3306:     if (oldVal < changedVal) {
 3307:         for (var k=oldVal+1; k<=changedVal ; k++) {
 3308:            var elementName = current[k];
 3309:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
 3310:         }
 3311:     } else {
 3312:         for (var k=changedVal; k<oldVal; k++) {
 3313:             var elementName = current[k];
 3314:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
 3315:         }
 3316:     }
 3317:     return;
 3318: }
 3319: 
 3320: function categoryCheck(form) {
 3321:     if (form.elements['addcategory_name'].value == 'instcode') {
 3322:         alert('$instcode_reserved\\n$choose_again');
 3323:         return false;
 3324:     }
 3325:     if (form.elements['addcategory_name'].value == 'communities') {
 3326:         alert('$communities_reserved\\n$choose_again');
 3327:         return false;
 3328:     }
 3329:     return true;
 3330: }
 3331: 
 3332: // ]]>
 3333: </script>
 3334: 
 3335: ENDSCRIPT
 3336:     return $output;
 3337: }
 3338: 
 3339: sub initialize_categories {
 3340:     my ($itemcount) = @_;
 3341:     my ($datatable,$css_class,$chgstr);
 3342:     my %default_names = (
 3343:                       instcode    => 'Official courses (with institutional codes)',
 3344:                       communities => 'Communities',
 3345:                         );
 3346:     my $select0 = ' selected="selected"';
 3347:     my $select1 = '';
 3348:     foreach my $default ('instcode','communities') {
 3349:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
 3350:         $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
 3351:         if ($default eq 'communities') {
 3352:             $select1 = $select0;
 3353:             $select0 = '';
 3354:         }
 3355:         $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
 3356:                      .'<select name="'.$default.'_pos">'
 3357:                      .'<option value="0"'.$select0.'>1</option>'
 3358:                      .'<option value="1"'.$select1.'>2</option>'
 3359:                      .'<option value="2">3</option></select>&nbsp;'
 3360:                      .$default_names{$default}
 3361:                      .'</span></td><td><span class="LC_nobreak">'
 3362:                      .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
 3363:                      .&mt('Display').'</label>&nbsp;<label>'
 3364:                      .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
 3365:                  .'</label></span></td></tr>';
 3366:         $itemcount ++;
 3367:     }
 3368:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
 3369:     $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
 3370:     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
 3371:                   .'<select name="addcategory_pos"'.$chgstr.'>'
 3372:                   .'<option value="0">1</option>'
 3373:                   .'<option value="1">2</option>'
 3374:                   .'<option value="2" selected="selected">3</option></select>&nbsp;'
 3375:                   .&mt('Add category').'</td><td>'.&mt('Name:')
 3376:                   .'&nbsp;<input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
 3377:     return $datatable;
 3378: }
 3379: 
 3380: sub build_category_rows {
 3381:     my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
 3382:     my ($text,$name,$item,$chgstr);
 3383:     if (ref($cats) eq 'ARRAY') {
 3384:         my $maxdepth = scalar(@{$cats});
 3385:         if (ref($cats->[$depth]) eq 'HASH') {
 3386:             if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
 3387:                 my $numchildren = @{$cats->[$depth]{$parent}};
 3388:                 my $css_class = $itemcount%2?' class="LC_odd_row"':'';
 3389:                 $text .= '<td><table class="LC_datatable">';
 3390:                 my ($idxnum,$parent_name,$parent_item);
 3391:                 my $higher = $depth - 1;
 3392:                 if ($higher == 0) {
 3393:                     $parent_name = &escape($parent).'::'.$higher;
 3394:                 } else {
 3395:                     if (ref($path) eq 'ARRAY') {
 3396:                         $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
 3397:                     }
 3398:                 }
 3399:                 $parent_item = 'addcategory_pos_'.$parent_name;
 3400:                 for (my $j=0; $j<=$numchildren; $j++) {
 3401:                     if ($j < $numchildren) {
 3402:                         $name = $cats->[$depth]{$parent}[$j];
 3403:                         $item = &escape($name).':'.&escape($parent).':'.$depth;
 3404:                         $idxnum = $idx->{$item};
 3405:                     } else {
 3406:                         $name = $parent_name;
 3407:                         $item = $parent_item;
 3408:                     }
 3409:                     $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
 3410:                     $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
 3411:                     for (my $i=0; $i<=$numchildren; $i++) {
 3412:                         my $vpos = $i+1;
 3413:                         my $selstr;
 3414:                         if ($j == $i) {
 3415:                             $selstr = ' selected="selected" ';
 3416:                         }
 3417:                         $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
 3418:                     }
 3419:                     $text .= '</select>&nbsp;';
 3420:                     if ($j < $numchildren) {
 3421:                         my $deeper = $depth+1;
 3422:                         $text .= $name.'&nbsp;'
 3423:                                  .'<label><input type="checkbox" name="deletecategory" value="'
 3424:                                  .$item.'" />'.&mt('Delete').'</label></span></td><td>';
 3425:                         if(ref($path) eq 'ARRAY') {
 3426:                             push(@{$path},$name);
 3427:                             $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
 3428:                             pop(@{$path});
 3429:                         }
 3430:                     } else {
 3431:                         $text .= &mt('Add subcategory:').'&nbsp;</span><input type="textbox" size="20" name="addcategory_name_';
 3432:                         if ($j == $numchildren) {
 3433:                             $text .= $name;
 3434:                         } else {
 3435:                             $text .= $item;
 3436:                         }
 3437:                         $text .= '" value="" />';
 3438:                     }
 3439:                     $text .= '</td></tr>';
 3440:                 }
 3441:                 $text .= '</table></td>';
 3442:             } else {
 3443:                 my $higher = $depth-1;
 3444:                 if ($higher == 0) {
 3445:                     $name = &escape($parent).'::'.$higher;
 3446:                 } else {
 3447:                     if (ref($path) eq 'ARRAY') {
 3448:                         $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
 3449:                     }
 3450:                 }
 3451:                 my $colspan;
 3452:                 if ($parent ne 'instcode') {
 3453:                     $colspan = $maxdepth - $depth - 1;
 3454:                     $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
 3455:                 }
 3456:             }
 3457:         }
 3458:     }
 3459:     return $text;
 3460: }
 3461: 
 3462: sub modifiable_userdata_row {
 3463:     my ($context,$role,$settings,$numinrow,$rowcount,$usertypes) = @_;
 3464:     my $rolename;
 3465:     if ($context eq 'selfcreate') {
 3466:         if (ref($usertypes) eq 'HASH') {
 3467:             $rolename = $usertypes->{$role};
 3468:         } else {
 3469:             $rolename = $role;
 3470:         }
 3471:     } else {
 3472:         if ($role eq 'cr') {
 3473:             $rolename = &mt('Custom role');
 3474:         } else {
 3475:             $rolename = &Apache::lonnet::plaintext($role);
 3476:         }
 3477:     }
 3478:     my @fields = ('lastname','firstname','middlename','generation',
 3479:                   'permanentemail','id');
 3480:     my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
 3481:     my $output;
 3482:     my $css_class = $rowcount%2?' class="LC_odd_row"':'';
 3483:     $output = '<tr '.$css_class.'>'.
 3484:               '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
 3485:               '<td class="LC_left_item" colspan="2"><table>';
 3486:     my $rem;
 3487:     my %checks;
 3488:     if (ref($settings) eq 'HASH') {
 3489:         if (ref($settings->{$context}) eq 'HASH') {
 3490:             if (ref($settings->{$context}->{$role}) eq 'HASH') {
 3491:                 foreach my $field (@fields) {
 3492:                     if ($settings->{$context}->{$role}->{$field}) {
 3493:                         $checks{$field} = ' checked="checked" ';
 3494:                     }
 3495:                 }
 3496:             }
 3497:         }
 3498:     }
 3499:     for (my $i=0; $i<@fields; $i++) {
 3500:         my $rem = $i%($numinrow);
 3501:         if ($rem == 0) {
 3502:             if ($i > 0) {
 3503:                 $output .= '</tr>';
 3504:             }
 3505:             $output .= '<tr>';
 3506:         }
 3507:         my $check = ' ';
 3508:         if (exists($checks{$fields[$i]})) {
 3509:             $check = $checks{$fields[$i]}
 3510:         } else {
 3511:             if ($role eq 'st') {
 3512:                 if (ref($settings) ne 'HASH') {
 3513:                     $check = ' checked="checked" '; 
 3514:                 }
 3515:             }
 3516:         }
 3517:         $output .= '<td class="LC_left_item">'.
 3518:                    '<span class="LC_nobreak"><label>'.
 3519:                    '<input type="checkbox" name="canmodify_'.$role.'" '.
 3520:                    'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
 3521:                    '</label></span></td>';
 3522:         $rem = @fields%($numinrow);
 3523:     }
 3524:     my $colsleft = $numinrow - $rem;
 3525:     if ($colsleft > 1 ) {
 3526:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
 3527:                    '&nbsp;</td>';
 3528:     } elsif ($colsleft == 1) {
 3529:         $output .= '<td class="LC_left_item">&nbsp;</td>';
 3530:     }
 3531:     $output .= '</tr></table></td></tr>';
 3532:     return $output;
 3533: }
 3534: 
 3535: sub insttypes_row {
 3536:     my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context) = @_;
 3537:     my %lt = &Apache::lonlocal::texthash (
 3538:                       cansearch => 'Users allowed to search',
 3539:                       statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
 3540:                       lockablenames => 'User preference to lock name',
 3541:              );
 3542:     my $showdom;
 3543:     if ($context eq 'cansearch') {
 3544:         $showdom = ' ('.$dom.')';
 3545:     }
 3546:     my $output =  '<tr class="LC_odd_row">'.
 3547:                   '<td>'.$lt{$context}.$showdom.
 3548:                   '</td><td class="LC_left_item" colspan="2"><table>';
 3549:     my $rem;
 3550:     if (ref($types) eq 'ARRAY') {
 3551:         for (my $i=0; $i<@{$types}; $i++) {
 3552:             if (defined($usertypes->{$types->[$i]})) {
 3553:                 my $rem = $i%($numinrow);
 3554:                 if ($rem == 0) {
 3555:                     if ($i > 0) {
 3556:                         $output .= '</tr>';
 3557:                     }
 3558:                     $output .= '<tr>';
 3559:                 }
 3560:                 my $check = ' ';
 3561:                 if (ref($settings) eq 'HASH') {
 3562:                     if (ref($settings->{$context}) eq 'ARRAY') {
 3563:                         if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
 3564:                             $check = ' checked="checked" ';
 3565:                         }
 3566:                     } elsif ($context eq 'statustocreate') {
 3567:                         $check = ' checked="checked" ';
 3568:                     }
 3569:                 }
 3570:                 $output .= '<td class="LC_left_item">'.
 3571:                            '<span class="LC_nobreak"><label>'.
 3572:                            '<input type="checkbox" name="'.$context.'" '.
 3573:                            'value="'.$types->[$i].'"'.$check.'/>'.
 3574:                            $usertypes->{$types->[$i]}.'</label></span></td>';
 3575:             }
 3576:         }
 3577:         $rem = @{$types}%($numinrow);
 3578:     }
 3579:     my $colsleft = $numinrow - $rem;
 3580:     if (($rem == 0) && (@{$types} > 0)) {
 3581:         $output .= '<tr>';
 3582:     }
 3583:     if ($colsleft > 1) {
 3584:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
 3585:     } else {
 3586:         $output .= '<td class="LC_left_item">';
 3587:     }
 3588:     my $defcheck = ' ';
 3589:     if (ref($settings) eq 'HASH') {  
 3590:         if (ref($settings->{$context}) eq 'ARRAY') {
 3591:             if (grep(/^default$/,@{$settings->{$context}})) {
 3592:                 $defcheck = ' checked="checked" ';
 3593:             }
 3594:         } elsif ($context eq 'statustocreate') {
 3595:             $defcheck = ' checked="checked" ';
 3596:         }
 3597:     }
 3598:     $output .= '<span class="LC_nobreak"><label>'.
 3599:                '<input type="checkbox" name="'.$context.'" '.
 3600:                'value="default"'.$defcheck.'/>'.
 3601:                $othertitle.'</label></span></td>'.
 3602:                '</tr></table></td></tr>';
 3603:     return $output;
 3604: }
 3605: 
 3606: sub sorted_searchtitles {
 3607:     my %searchtitles = &Apache::lonlocal::texthash(
 3608:                          'uname' => 'username',
 3609:                          'lastname' => 'last name',
 3610:                          'lastfirst' => 'last name, first name',
 3611:                      );
 3612:     my @titleorder = ('uname','lastname','lastfirst');
 3613:     return (\%searchtitles,\@titleorder);
 3614: }
 3615: 
 3616: sub sorted_searchtypes {
 3617:     my %srchtypes_desc = (
 3618:                            exact    => 'is exact match',
 3619:                            contains => 'contains ..',
 3620:                            begins   => 'begins with ..',
 3621:                          );
 3622:     my @srchtypeorder = ('exact','begins','contains');
 3623:     return (\%srchtypes_desc,\@srchtypeorder);
 3624: }
 3625: 
 3626: sub usertype_update_row {
 3627:     my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
 3628:     my $datatable;
 3629:     my $numinrow = 4;
 3630:     foreach my $type (@{$types}) {
 3631:         if (defined($usertypes->{$type})) {
 3632:             $$rownums ++;
 3633:             my $css_class = $$rownums%2?' class="LC_odd_row"':'';
 3634:             $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
 3635:                           '</td><td class="LC_left_item"><table>';
 3636:             for (my $i=0; $i<@{$fields}; $i++) {
 3637:                 my $rem = $i%($numinrow);
 3638:                 if ($rem == 0) {
 3639:                     if ($i > 0) {
 3640:                         $datatable .= '</tr>';
 3641:                     }
 3642:                     $datatable .= '<tr>';
 3643:                 }
 3644:                 my $check = ' ';
 3645:                 if (ref($settings) eq 'HASH') {
 3646:                     if (ref($settings->{'fields'}) eq 'HASH') {
 3647:                         if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
 3648:                             if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
 3649:                                 $check = ' checked="checked" ';
 3650:                             }
 3651:                         }
 3652:                     }
 3653:                 }
 3654: 
 3655:                 if ($i == @{$fields}-1) {
 3656:                     my $colsleft = $numinrow - $rem;
 3657:                     if ($colsleft > 1) {
 3658:                         $datatable .= '<td colspan="'.$colsleft.'">';
 3659:                     } else {
 3660:                         $datatable .= '<td>';
 3661:                     }
 3662:                 } else {
 3663:                     $datatable .= '<td>';
 3664:                 }
 3665:                 $datatable .= '<span class="LC_nobreak"><label>'.
 3666:                               '<input type="checkbox" name="updateable_'.$type.
 3667:                               '_'.$fields->[$i].'" value="1"'.$check.'/>'.
 3668:                               $fieldtitles->{$fields->[$i]}.'</label></span></td>';
 3669:             }
 3670:             $datatable .= '</tr></table></td></tr>';
 3671:         }
 3672:     }
 3673:     return $datatable;
 3674: }
 3675: 
 3676: sub modify_login {
 3677:     my ($r,$dom,$confname,%domconfig) = @_;
 3678:     my ($resulttext,$errors,$colchgtext,%changes,%colchanges);
 3679:     my %title = ( coursecatalog => 'Display course catalog',
 3680:                   adminmail => 'Display administrator E-mail address',
 3681:                   newuser => 'Link for visitors to create a user account',
 3682:                   loginheader => 'Log-in box header');
 3683:     my @offon = ('off','on');
 3684:     my %curr_loginvia;
 3685:     if (ref($domconfig{login}) eq 'HASH') {
 3686:         if (ref($domconfig{login}{loginvia}) eq 'HASH') {
 3687:             foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
 3688:                 $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
 3689:             }
 3690:         }
 3691:     }
 3692:     my %loginhash;
 3693:     ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
 3694:                                            \%domconfig,\%loginhash);
 3695:     my @toggles = ('coursecatalog','adminmail','newuser');
 3696:     foreach my $item (@toggles) {
 3697:         $loginhash{login}{$item} = $env{'form.'.$item};
 3698:     }
 3699:     $loginhash{login}{loginheader} = $env{'form.loginheader'};
 3700:     if (ref($colchanges{'login'}) eq 'HASH') {  
 3701:         $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
 3702:                                          \%loginhash);
 3703:     }
 3704: 
 3705:     my %servers = &dom_servers($dom);
 3706:     my @loginvia_attribs = ('serverpath','custompath','exempt');
 3707:     if (keys(%servers) > 1) {
 3708:         foreach my $lonhost (keys(%servers)) {
 3709:             next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
 3710:             if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
 3711:                 if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
 3712:                     $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
 3713:                 } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
 3714:                     if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
 3715:                         $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
 3716:                         $changes{'loginvia'}{$lonhost} = 1;
 3717:                     } else {
 3718:                         $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
 3719:                         $changes{'loginvia'}{$lonhost} = 1;
 3720:                     }
 3721:                 } else {
 3722:                     if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
 3723:                         $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
 3724:                         $changes{'loginvia'}{$lonhost} = 1;
 3725:                     }
 3726:                 }
 3727:                 if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
 3728:                     foreach my $item (@loginvia_attribs) {
 3729:                         $loginhash{login}{loginvia}{$lonhost}{$item} = '';
 3730:                     }
 3731:                 } else {
 3732:                     foreach my $item (@loginvia_attribs) {
 3733:                         my $new = $env{'form.'.$lonhost.'_'.$item};
 3734:                         if (($item eq 'serverpath') && ($new eq 'custom')) {
 3735:                             $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
 3736:                             if ($env{'form.'.$lonhost.'_custompath'} eq '') {
 3737:                                 $new = '/';
 3738:                             }
 3739:                         }
 3740:                         if (($item eq 'custompath') && 
 3741:                             ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
 3742:                             $new = '';
 3743:                         }
 3744:                         if ($new ne $curr_loginvia{$lonhost}{$item}) {
 3745:                             $changes{'loginvia'}{$lonhost} = 1;
 3746:                         }
 3747:                         if ($item eq 'exempt') {
 3748:                             $new =~ s/^\s+//;
 3749:                             $new =~ s/\s+$//;
 3750:                             my @poss_ips = split(/\s*[,:]\s*/,$new);
 3751:                             my @okips;
 3752:                             foreach my $ip (@poss_ips) {
 3753:                                 if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
 3754:                                     if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
 3755:                                         push(@okips,$ip); 
 3756:                                     }
 3757:                                 }
 3758:                             }
 3759:                             if (@okips > 0) {
 3760:                                 $new = join(',',@okips); 
 3761:                             } else {
 3762:                                 $new = ''; 
 3763:                             }
 3764:                         }
 3765: 
 3766:                         $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
 3767:                     }
 3768:                 }
 3769:             } else {
 3770:                 if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
 3771:                     $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
 3772:                     $changes{'loginvia'}{$lonhost} = 1;
 3773:                     foreach my $item (@loginvia_attribs) {
 3774:                         my $new = $env{'form.'.$lonhost.'_'.$item};
 3775:                         if (($item eq 'serverpath') && ($new eq 'custom')) {
 3776:                             if ($env{'form.'.$lonhost.'_custompath'} eq '') {
 3777:                                 $new = '/';
 3778:                             }
 3779:                         }
 3780:                         if (($item eq 'custompath') && 
 3781:                             ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
 3782:                             $new = '';
 3783:                         }
 3784:                         $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
 3785:                     }
 3786:                 }
 3787:             }
 3788:         }
 3789:     }
 3790: 
 3791:     my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
 3792:                                              $dom);
 3793:     if ($putresult eq 'ok') {
 3794:         my @toggles = ('coursecatalog','adminmail','newuser');
 3795:         my %defaultchecked = (
 3796:                     'coursecatalog' => 'on',
 3797:                     'adminmail'     => 'off',
 3798:                     'newuser'       => 'off',
 3799:         );
 3800:         if (ref($domconfig{'login'}) eq 'HASH') {
 3801:             foreach my $item (@toggles) {
 3802:                 if ($defaultchecked{$item} eq 'on') { 
 3803:                     if (($domconfig{'login'}{$item} eq '0') &&
 3804:                         ($env{'form.'.$item} eq '1')) {
 3805:                         $changes{$item} = 1;
 3806:                     } elsif (($domconfig{'login'}{$item} eq '' ||
 3807:                               $domconfig{'login'}{$item} eq '1') &&
 3808:                              ($env{'form.'.$item} eq '0')) {
 3809:                         $changes{$item} = 1;
 3810:                     }
 3811:                 } elsif ($defaultchecked{$item} eq 'off') {
 3812:                     if (($domconfig{'login'}{$item} eq '1') &&
 3813:                         ($env{'form.'.$item} eq '0')) {
 3814:                         $changes{$item} = 1;
 3815:                     } elsif (($domconfig{'login'}{$item} eq '' ||
 3816:                               $domconfig{'login'}{$item} eq '0') &&
 3817:                              ($env{'form.'.$item} eq '1')) {
 3818:                         $changes{$item} = 1;
 3819:                     }
 3820:                 }
 3821:             }
 3822:         }
 3823:         if (keys(%changes) > 0 || $colchgtext) {
 3824:             &Apache::loncommon::devalidate_domconfig_cache($dom);
 3825:             $resulttext = &mt('Changes made:').'<ul>';
 3826:             foreach my $item (sort(keys(%changes))) {
 3827:                 if ($item eq 'loginvia') {
 3828:                     if (ref($changes{$item}) eq 'HASH') {
 3829:                         $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
 3830:                         foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
 3831:                             if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
 3832:                                 if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
 3833:                                     my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
 3834:                                     $protocol = 'http' if ($protocol ne 'https');
 3835:                                     my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
 3836: 
 3837:                                     if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
 3838:                                         $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
 3839:                                     } else {
 3840:                                         $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'}; 
 3841:                                     }
 3842:                                     $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
 3843:                                     if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
 3844:                                         $resulttext .= '&nbsp;'.&mt('No redirection for clients from following IPs:').'&nbsp;'.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
 3845:                                     }
 3846:                                     $resulttext .= '</li>';
 3847:                                 } else {
 3848:                                     $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
 3849:                                 }
 3850:                             } else {
 3851:                                 $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
 3852:                             }
 3853:                         }
 3854:                         $resulttext .= '</ul></li>';
 3855:                     }
 3856:                 } else {
 3857:                     $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
 3858:                 }
 3859:             }
 3860:             $resulttext .= $colchgtext.'</ul>';
 3861:         } else {
 3862:             $resulttext = &mt('No changes made to log-in page settings');
 3863:         }
 3864:     } else {
 3865:         $resulttext = '<span class="LC_error">'.
 3866: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
 3867:     }
 3868:     if ($errors) {
 3869:         $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
 3870:                        $errors.'</ul>';
 3871:     }
 3872:     return $resulttext;
 3873: }
 3874: 
 3875: sub color_font_choices {
 3876:     my %choices =
 3877:         &Apache::lonlocal::texthash (
 3878:             img => "Header",
 3879:             bgs => "Background colors",
 3880:             links => "Link colors",
 3881:             images => "Images",
 3882:             font => "Font color",
 3883:             fontmenu => "Font Menu",
 3884:             pgbg => "Page",
 3885:             tabbg => "Header",
 3886:             sidebg => "Border",
 3887:             link => "Link",
 3888:             alink => "Active link",
 3889:             vlink => "Visited link",
 3890:         );
 3891:     return %choices;
 3892: }
 3893: 
 3894: sub modify_rolecolors {
 3895:     my ($r,$dom,$confname,$roles,%domconfig) = @_;
 3896:     my ($resulttext,%rolehash);
 3897:     $rolehash{'rolecolors'} = {};
 3898:     if (ref($domconfig{'rolecolors'}) ne 'HASH') {
 3899:         if ($domconfig{'rolecolors'} eq '') {
 3900:             $domconfig{'rolecolors'} = {};
 3901:         }
 3902:     }
 3903:     my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
 3904:                          $domconfig{'rolecolors'},$rolehash{'rolecolors'});
 3905:     my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
 3906:                                              $dom);
 3907:     if ($putresult eq 'ok') {
 3908:         if (keys(%changes) > 0) {
 3909:             &Apache::loncommon::devalidate_domconfig_cache($dom);
 3910:             $resulttext = &display_colorchgs($dom,\%changes,$roles,
 3911:                                              $rolehash{'rolecolors'});
 3912:         } else {
 3913:             $resulttext = &mt('No changes made to default color schemes');
 3914:         }
 3915:     } else {
 3916:         $resulttext = '<span class="LC_error">'.
 3917: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
 3918:     }
 3919:     if ($errors) {
 3920:         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
 3921:                        $errors.'</ul>';
 3922:     }
 3923:     return $resulttext;
 3924: }
 3925: 
 3926: sub modify_colors {
 3927:     my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
 3928:     my (%changes,%choices);
 3929:     my @bgs;
 3930:     my @links = ('link','alink','vlink');
 3931:     my @logintext;
 3932:     my @images;
 3933:     my $servadm = $r->dir_config('lonAdmEMail');
 3934:     my $errors;
 3935:     foreach my $role (@{$roles}) {
 3936:         if ($role eq 'login') {
 3937:             %choices = &login_choices();
 3938:             @logintext = ('textcol','bgcol');
 3939:         } else {
 3940:             %choices = &color_font_choices();
 3941:             $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
 3942:         }
 3943:         if ($role eq 'login') {
 3944:             @images = ('img','logo','domlogo','login');
 3945:             @bgs = ('pgbg','mainbg','sidebg');
 3946:         } else {
 3947:             @images = ('img');
 3948:             @bgs = ('pgbg','tabbg','sidebg'); 
 3949:         }
 3950:         $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
 3951:         foreach my $item (@bgs,@links,@logintext) {
 3952:             $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
 3953:         }
 3954:         my ($configuserok,$author_ok,$switchserver) = 
 3955:             &config_check($dom,$confname,$servadm);
 3956:         my ($width,$height) = &thumb_dimensions();
 3957:         if (ref($domconfig->{$role}) ne 'HASH') {
 3958:             $domconfig->{$role} = {};
 3959:         }
 3960:         foreach my $img (@images) {
 3961:             if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {  
 3962:                 if (defined($env{'form.login_showlogo_'.$img})) {
 3963:                     $confhash->{$role}{'showlogo'}{$img} = 1;
 3964:                 } else { 
 3965:                     $confhash->{$role}{'showlogo'}{$img} = 0;
 3966:                 }
 3967:             } 
 3968: 	    if ( ! $env{'form.'.$role.'_'.$img.'.filename'} 
 3969: 		 && !defined($domconfig->{$role}{$img})
 3970: 		 && !$env{'form.'.$role.'_del_'.$img}
 3971: 		 && $env{'form.'.$role.'_import_'.$img}) {
 3972: 		# import the old configured image from the .tab setting
 3973: 		# if they haven't provided a new one 
 3974: 		$domconfig->{$role}{$img} = 
 3975: 		    $env{'form.'.$role.'_import_'.$img};
 3976: 	    }
 3977:             if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
 3978:                 my $error;
 3979:                 if ($configuserok eq 'ok') {
 3980:                     if ($switchserver) {
 3981:                         $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
 3982:                     } else {
 3983:                         if ($author_ok eq 'ok') {
 3984:                             my ($result,$logourl) = 
 3985:                                 &publishlogo($r,'upload',$role.'_'.$img,
 3986:                                            $dom,$confname,$img,$width,$height);
 3987:                             if ($result eq 'ok') {
 3988:                                 $confhash->{$role}{$img} = $logourl;
 3989:                                 $changes{$role}{'images'}{$img} = 1;
 3990:                             } else {
 3991:                                 $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);
 3992:                             }
 3993:                         } else {
 3994:                             $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);
 3995:                         }
 3996:                     }
 3997:                 } else {
 3998:                     $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);
 3999:                 }
 4000:                 if ($error) {
 4001:                     &Apache::lonnet::logthis($error);
 4002:                     $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
 4003:                 }
 4004:             } elsif ($domconfig->{$role}{$img} ne '') {
 4005:                 if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
 4006:                     my $error;
 4007:                     if ($configuserok eq 'ok') {
 4008: # is confname an author?
 4009:                         if ($switchserver eq '') {
 4010:                             if ($author_ok eq 'ok') {
 4011:                                 my ($result,$logourl) = 
 4012:                                &publishlogo($r,'copy',$domconfig->{$role}{$img},
 4013:                                             $dom,$confname,$img,$width,$height);
 4014:                                 if ($result eq 'ok') {
 4015:                                     $confhash->{$role}{$img} = $logourl;
 4016: 				    $changes{$role}{'images'}{$img} = 1;
 4017:                                 }
 4018:                             }
 4019:                         }
 4020:                     }
 4021:                 }
 4022:             }
 4023:         }
 4024:         if (ref($domconfig) eq 'HASH') {
 4025:             if (ref($domconfig->{$role}) eq 'HASH') {
 4026:                 foreach my $img (@images) {
 4027:                     if ($domconfig->{$role}{$img} ne '') {
 4028:                         if ($env{'form.'.$role.'_del_'.$img}) {
 4029:                             $confhash->{$role}{$img} = '';
 4030:                             $changes{$role}{'images'}{$img} = 1;
 4031:                         } else {
 4032:                             if ($confhash->{$role}{$img} eq '') {
 4033:                                 $confhash->{$role}{$img} = $domconfig->{$role}{$img};
 4034:                             }
 4035:                         }
 4036:                     } else {
 4037:                         if ($env{'form.'.$role.'_del_'.$img}) {
 4038:                             $confhash->{$role}{$img} = '';
 4039:                             $changes{$role}{'images'}{$img} = 1;
 4040:                         } 
 4041:                     }
 4042:                     if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
 4043:                         if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
 4044:                             if ($confhash->{$role}{'showlogo'}{$img} ne 
 4045:                                 $domconfig->{$role}{'showlogo'}{$img}) {
 4046:                                 $changes{$role}{'showlogo'}{$img} = 1; 
 4047:                             }
 4048:                         } else {
 4049:                             if ($confhash->{$role}{'showlogo'}{$img} == 0) {
 4050:                                 $changes{$role}{'showlogo'}{$img} = 1;
 4051:                             }
 4052:                         }
 4053:                     }
 4054:                 }
 4055:                 if ($domconfig->{$role}{'font'} ne '') {
 4056:                     if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
 4057:                         $changes{$role}{'font'} = 1;
 4058:                     }
 4059:                 } else {
 4060:                     if ($confhash->{$role}{'font'}) {
 4061:                         $changes{$role}{'font'} = 1;
 4062:                     }
 4063:                 }
 4064:                 if ($role ne 'login') {
 4065:                     if ($domconfig->{$role}{'fontmenu'} ne '') {
 4066:                         if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
 4067:                             $changes{$role}{'fontmenu'} = 1;
 4068:                         }
 4069:                     } else {
 4070:                         if ($confhash->{$role}{'fontmenu'}) {
 4071:                             $changes{$role}{'fontmenu'} = 1;
 4072:                         }
 4073:                     }
 4074:                 }
 4075:                 foreach my $item (@bgs) {
 4076:                     if ($domconfig->{$role}{$item} ne '') {
 4077:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
 4078:                             $changes{$role}{'bgs'}{$item} = 1;
 4079:                         } 
 4080:                     } else {
 4081:                         if ($confhash->{$role}{$item}) {
 4082:                             $changes{$role}{'bgs'}{$item} = 1;
 4083:                         }
 4084:                     }
 4085:                 }
 4086:                 foreach my $item (@links) {
 4087:                     if ($domconfig->{$role}{$item} ne '') {
 4088:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
 4089:                             $changes{$role}{'links'}{$item} = 1;
 4090:                         }
 4091:                     } else {
 4092:                         if ($confhash->{$role}{$item}) {
 4093:                             $changes{$role}{'links'}{$item} = 1;
 4094:                         }
 4095:                     }
 4096:                 }
 4097:                 foreach my $item (@logintext) {
 4098:                     if ($domconfig->{$role}{$item} ne '') {
 4099:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
 4100:                             $changes{$role}{'logintext'}{$item} = 1;
 4101:                         }
 4102:                     } else {
 4103:                         if ($confhash->{$role}{$item}) {
 4104:                             $changes{$role}{'logintext'}{$item} = 1;
 4105:                         }
 4106:                     }
 4107:                 }
 4108:             } else {
 4109:                 &default_change_checker($role,\@images,\@links,\@bgs,
 4110:                                         \@logintext,$confhash,\%changes); 
 4111:             }
 4112:         } else {
 4113:             &default_change_checker($role,\@images,\@links,\@bgs,
 4114:                                     \@logintext,$confhash,\%changes); 
 4115:         }
 4116:     }
 4117:     return ($errors,%changes);
 4118: }
 4119: 
 4120: sub config_check {
 4121:     my ($dom,$confname,$servadm) = @_;
 4122:     my ($configuserok,$author_ok,$switchserver,%currroles);
 4123:     my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
 4124:     ($configuserok,%currroles) = &check_configuser($uhome,$dom,
 4125:                                                    $confname,$servadm);
 4126:     if ($configuserok eq 'ok') {
 4127:         $switchserver = &check_switchserver($dom,$confname);
 4128:         if ($switchserver eq '') {
 4129:             $author_ok = &check_authorstatus($dom,$confname,%currroles);
 4130:         }
 4131:     }
 4132:     return ($configuserok,$author_ok,$switchserver);
 4133: }
 4134: 
 4135: sub default_change_checker {
 4136:     my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
 4137:     foreach my $item (@{$links}) {
 4138:         if ($confhash->{$role}{$item}) {
 4139:             $changes->{$role}{'links'}{$item} = 1;
 4140:         }
 4141:     }
 4142:     foreach my $item (@{$bgs}) {
 4143:         if ($confhash->{$role}{$item}) {
 4144:             $changes->{$role}{'bgs'}{$item} = 1;
 4145:         }
 4146:     }
 4147:     foreach my $item (@{$logintext}) {
 4148:         if ($confhash->{$role}{$item}) {
 4149:             $changes->{$role}{'logintext'}{$item} = 1;
 4150:         }
 4151:     }
 4152:     foreach my $img (@{$images}) {
 4153:         if ($env{'form.'.$role.'_del_'.$img}) {
 4154:             $confhash->{$role}{$img} = '';
 4155:             $changes->{$role}{'images'}{$img} = 1;
 4156:         }
 4157:         if ($role eq 'login') {
 4158:             if ($confhash->{$role}{'showlogo'}{$img} == 0) {
 4159:                 $changes->{$role}{'showlogo'}{$img} = 1;
 4160:             }
 4161:         }
 4162:     }
 4163:     if ($confhash->{$role}{'font'}) {
 4164:         $changes->{$role}{'font'} = 1;
 4165:     }
 4166: }
 4167: 
 4168: sub display_colorchgs {
 4169:     my ($dom,$changes,$roles,$confhash) = @_;
 4170:     my (%choices,$resulttext);
 4171:     if (!grep(/^login$/,@{$roles})) {
 4172:         $resulttext = &mt('Changes made:').'<br />';
 4173:     }
 4174:     foreach my $role (@{$roles}) {
 4175:         if ($role eq 'login') {
 4176:             %choices = &login_choices();
 4177:         } else {
 4178:             %choices = &color_font_choices();
 4179:         }
 4180:         if (ref($changes->{$role}) eq 'HASH') {
 4181:             if ($role ne 'login') {
 4182:                 $resulttext .= '<h4>'.&mt($role).'</h4>';
 4183:             }
 4184:             foreach my $key (sort(keys(%{$changes->{$role}}))) {
 4185:                 if ($role ne 'login') {
 4186:                     $resulttext .= '<ul>';
 4187:                 }
 4188:                 if (ref($changes->{$role}{$key}) eq 'HASH') {
 4189:                     if ($role ne 'login') {
 4190:                         $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
 4191:                     }
 4192:                     foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
 4193:                         if (($role eq 'login') && ($key eq 'showlogo')) {
 4194:                             if ($confhash->{$role}{$key}{$item}) {
 4195:                                 $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
 4196:                             } else {
 4197:                                 $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
 4198:                             }
 4199:                         } elsif ($confhash->{$role}{$item} eq '') {
 4200:                             $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
 4201:                         } else {
 4202:                             my $newitem = $confhash->{$role}{$item};
 4203:                             if ($key eq 'images') {
 4204:                                 $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
 4205:                             }
 4206:                             $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
 4207:                         }
 4208:                     }
 4209:                     if ($role ne 'login') {
 4210:                         $resulttext .= '</ul></li>';
 4211:                     }
 4212:                 } else {
 4213:                     if ($confhash->{$role}{$key} eq '') {
 4214:                         $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
 4215:                     } else {
 4216:                         $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
 4217:                     }
 4218:                 }
 4219:                 if ($role ne 'login') {
 4220:                     $resulttext .= '</ul>';
 4221:                 }
 4222:             }
 4223:         }
 4224:     }
 4225:     return $resulttext;
 4226: }
 4227: 
 4228: sub thumb_dimensions {
 4229:     return ('200','50');
 4230: }
 4231: 
 4232: sub check_dimensions {
 4233:     my ($inputfile) = @_;
 4234:     my ($fullwidth,$fullheight);
 4235:     if ($inputfile =~ m|^[/\w.\-]+$|) {
 4236:         if (open(PIPE,"identify $inputfile 2>&1 |")) {
 4237:             my $imageinfo = <PIPE>;
 4238:             if (!close(PIPE)) {
 4239:                 &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
 4240:             }
 4241:             chomp($imageinfo);
 4242:             my ($fullsize) = 
 4243:                 ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
 4244:             if ($fullsize) {
 4245:                 ($fullwidth,$fullheight) = split(/x/,$fullsize);
 4246:             }
 4247:         }
 4248:     }
 4249:     return ($fullwidth,$fullheight);
 4250: }
 4251: 
 4252: sub check_configuser {
 4253:     my ($uhome,$dom,$confname,$servadm) = @_;
 4254:     my ($configuserok,%currroles);
 4255:     if ($uhome eq 'no_host') {
 4256:         srand( time() ^ ($$ + ($$ << 15))  ); # Seed rand.
 4257:         my $configpass = &LONCAPA::Enrollment::create_password();
 4258:         $configuserok = 
 4259:             &Apache::lonnet::modifyuser($dom,$confname,'','internal',
 4260:                              $configpass,'','','','','',undef,$servadm);
 4261:     } else {
 4262:         $configuserok = 'ok';
 4263:         %currroles = 
 4264:             &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
 4265:     }
 4266:     return ($configuserok,%currroles);
 4267: }
 4268: 
 4269: sub check_authorstatus {
 4270:     my ($dom,$confname,%currroles) = @_;
 4271:     my $author_ok;
 4272:     if (!$currroles{':'.$dom.':au'}) {
 4273:         my $start = time;
 4274:         my $end = 0;
 4275:         $author_ok = 
 4276:             &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
 4277:                                         'au',$end,$start,'','','domconfig');
 4278:     } else {
 4279:         $author_ok = 'ok';
 4280:     }
 4281:     return $author_ok;
 4282: }
 4283: 
 4284: sub publishlogo {
 4285:     my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
 4286:     my ($output,$fname,$logourl);
 4287:     if ($action eq 'upload') {
 4288:         $fname=$env{'form.'.$formname.'.filename'};
 4289:         chop($env{'form.'.$formname});
 4290:     } else {
 4291:         ($fname) = ($formname =~ /([^\/]+)$/);
 4292:     }
 4293:     if ($savefileas ne '') {
 4294:         $fname = $savefileas;
 4295:     }
 4296:     $fname=&Apache::lonnet::clean_filename($fname);
 4297: # See if there is anything left
 4298:     unless ($fname) { return ('error: no uploaded file'); }
 4299:     $fname="$subdir/$fname";
 4300:     my $filepath='/home/'.$confname.'/public_html';
 4301:     my ($fnamepath,$file,$fetchthumb);
 4302:     $file=$fname;
 4303:     if ($fname=~m|/|) {
 4304:         ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
 4305:     }
 4306:     my @parts=split(/\//,$filepath.'/'.$fnamepath);
 4307:     my $count;
 4308:     for ($count=4;$count<=$#parts;$count++) {
 4309:         $filepath.="/$parts[$count]";
 4310:         if ((-e $filepath)!=1) {
 4311:             mkdir($filepath,02770);
 4312:         }
 4313:     }
 4314:     # Check for bad extension and disallow upload
 4315:     if ($file=~/\.(\w+)$/ &&
 4316:         (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
 4317:         $output = 
 4318:             &mt('Invalid file extension ([_1]) - reserved for LONCAPA use.',$1); 
 4319:     } elsif ($file=~/\.(\w+)$/ &&
 4320:         !defined(&Apache::loncommon::fileembstyle($1))) {
 4321:         $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
 4322:     } elsif ($file=~/\.(\d+)\.(\w+)$/) {
 4323:         $output = &mt('File name not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
 4324:     } elsif (-d "$filepath/$file") {
 4325:         $output = &mt('File name is a directory name - rename the file and re-upload');
 4326:     } else {
 4327:         my $source = $filepath.'/'.$file;
 4328:         my $logfile;
 4329:         if (!open($logfile,">>$source".'.log')) {
 4330:             return (&mt('No write permission to Construction Space'));
 4331:         }
 4332:         print $logfile
 4333: "\n================= Publish ".localtime()." ================\n".
 4334: $env{'user.name'}.':'.$env{'user.domain'}."\n";
 4335: # Save the file
 4336:         if (!open(FH,'>'.$source)) {
 4337:             &Apache::lonnet::logthis('Failed to create '.$source);
 4338:             return (&mt('Failed to create file'));
 4339:         }
 4340:         if ($action eq 'upload') {
 4341:             if (!print FH ($env{'form.'.$formname})) {
 4342:                 &Apache::lonnet::logthis('Failed to write to '.$source);
 4343:                 return (&mt('Failed to write file'));
 4344:             }
 4345:         } else {
 4346:             my $original = &Apache::lonnet::filelocation('',$formname);
 4347:             if(!copy($original,$source)) {
 4348:                 &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
 4349:                 return (&mt('Failed to write file'));
 4350:             }
 4351:         }
 4352:         close(FH);
 4353:         chmod(0660, $source); # Permissions to rw-rw---.
 4354: 
 4355:         my $docroot=$r->dir_config('lonDocRoot');
 4356:         my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
 4357:         my $copyfile=$targetdir.'/'.$file;
 4358: 
 4359:         my @parts=split(/\//,$targetdir);
 4360:         my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
 4361:         for (my $count=5;$count<=$#parts;$count++) {
 4362:             $path.="/$parts[$count]";
 4363:             if (!-e $path) {
 4364:                 print $logfile "\nCreating directory ".$path;
 4365:                 mkdir($path,02770);
 4366:             }
 4367:         }
 4368:         my $versionresult;
 4369:         if (-e $copyfile) {
 4370:             $versionresult = &logo_versioning($targetdir,$file,$logfile);
 4371:         } else {
 4372:             $versionresult = 'ok';
 4373:         }
 4374:         if ($versionresult eq 'ok') {
 4375:             if (copy($source,$copyfile)) {
 4376:                 print $logfile "\nCopied original source to ".$copyfile."\n";
 4377:                 $output = 'ok';
 4378:                 &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
 4379:                 $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
 4380:             } else {
 4381:                 print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
 4382:                 $output = &mt('Failed to copy file to RES space').", $!";
 4383:             }
 4384:             if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
 4385:                 my $inputfile = $filepath.'/'.$file;
 4386:                 my $outfile = $filepath.'/'.'tn-'.$file;
 4387:                 my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
 4388:                 if ($fullwidth ne '' && $fullheight ne '') { 
 4389:                     if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
 4390:                         my $thumbsize = $thumbwidth.'x'.$thumbheight;
 4391:                         system("convert -sample $thumbsize $inputfile $outfile");
 4392:                         chmod(0660, $filepath.'/tn-'.$file);
 4393:                         if (-e $outfile) {
 4394:                             my $copyfile=$targetdir.'/tn-'.$file;
 4395:                             if (copy($outfile,$copyfile)) {
 4396:                                 print $logfile "\nCopied source to ".$copyfile."\n";
 4397:                                 &write_metadata($dom,$confname,$formname,
 4398:                                                 $targetdir,'tn-'.$file,$logfile);
 4399:                             } else {
 4400:                                 print $logfile "\nUnable to write ".$copyfile.
 4401:                                                ':'.$!."\n";
 4402:                             }
 4403:                         }
 4404:                     }
 4405:                 }
 4406:             }
 4407:         } else {
 4408:             $output = $versionresult;
 4409:         }
 4410:     }
 4411:     return ($output,$logourl);
 4412: }
 4413: 
 4414: sub logo_versioning {
 4415:     my ($targetdir,$file,$logfile) = @_;
 4416:     my $target = $targetdir.'/'.$file;
 4417:     my ($maxversion,$fn,$extn,$output);
 4418:     $maxversion = 0;
 4419:     if ($file =~ /^(.+)\.(\w+)$/) {
 4420:         $fn=$1;
 4421:         $extn=$2;
 4422:     }
 4423:     opendir(DIR,$targetdir);
 4424:     while (my $filename=readdir(DIR)) {
 4425:         if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
 4426:             $maxversion=($1>$maxversion)?$1:$maxversion;
 4427:         }
 4428:     }
 4429:     $maxversion++;
 4430:     print $logfile "\nCreating old version ".$maxversion."\n";
 4431:     my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
 4432:     if (copy($target,$copyfile)) {
 4433:         print $logfile "Copied old target to ".$copyfile."\n";
 4434:         $copyfile=$copyfile.'.meta';
 4435:         if (copy($target.'.meta',$copyfile)) {
 4436:             print $logfile "Copied old target metadata to ".$copyfile."\n";
 4437:             $output = 'ok';
 4438:         } else {
 4439:             print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
 4440:             $output = &mt('Failed to copy old meta').", $!, ";
 4441:         }
 4442:     } else {
 4443:         print $logfile "Unable to write ".$copyfile.':'.$!."\n";
 4444:         $output = &mt('Failed to copy old target').", $!, ";
 4445:     }
 4446:     return $output;
 4447: }
 4448: 
 4449: sub write_metadata {
 4450:     my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
 4451:     my (%metadatafields,%metadatakeys,$output);
 4452:     $metadatafields{'title'}=$formname;
 4453:     $metadatafields{'creationdate'}=time;
 4454:     $metadatafields{'lastrevisiondate'}=time;
 4455:     $metadatafields{'copyright'}='public';
 4456:     $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
 4457:                                          $env{'user.domain'};
 4458:     $metadatafields{'authorspace'}=$confname.':'.$dom;
 4459:     $metadatafields{'domain'}=$dom;
 4460:     {
 4461:         print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
 4462:         my $mfh;
 4463:         unless (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
 4464:             $output = &mt('Could not write metadata');
 4465:         }
 4466:         foreach (sort keys %metadatafields) {
 4467:             unless ($_=~/\./) {
 4468:                 my $unikey=$_;
 4469:                 $unikey=~/^([A-Za-z]+)/;
 4470:                 my $tag=$1;
 4471:                 $tag=~tr/A-Z/a-z/;
 4472:                 print $mfh "\n\<$tag";
 4473:                 foreach (split(/\,/,$metadatakeys{$unikey})) {
 4474:                     my $value=$metadatafields{$unikey.'.'.$_};
 4475:                     $value=~s/\"/\'\'/g;
 4476:                     print $mfh ' '.$_.'="'.$value.'"';
 4477:                 }
 4478:                 print $mfh '>'.
 4479:                     &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
 4480:                         .'</'.$tag.'>';
 4481:             }
 4482:         }
 4483:         $output = 'ok';
 4484:         print $logfile "\nWrote metadata";
 4485:         close($mfh);
 4486:     }
 4487: }
 4488: 
 4489: sub check_switchserver {
 4490:     my ($dom,$confname) = @_;
 4491:     my ($allowed,$switchserver);
 4492:     my $home = &Apache::lonnet::homeserver($confname,$dom);
 4493:     if ($home eq 'no_host') {
 4494:         $home = &Apache::lonnet::domain($dom,'primary');
 4495:     }
 4496:     my @ids=&Apache::lonnet::current_machine_ids();
 4497:     foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
 4498:     if (!$allowed) {
 4499: 	$switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/">'.&mt('Switch Server').'</a>';
 4500:     }
 4501:     return $switchserver;
 4502: }
 4503: 
 4504: sub modify_quotas {
 4505:     my ($dom,$action,%domconfig) = @_;
 4506:     my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
 4507:         %limithash,$toolregexp,%conditions,$resulttext,%changes);
 4508:     if ($action eq 'quotas') {
 4509:         $context = 'tools'; 
 4510:     } else { 
 4511:         $context = $action;
 4512:     }
 4513:     if ($context eq 'requestcourses') {
 4514:         @usertools = ('official','unofficial','community');
 4515:         @options =('norequest','approval','validate','autolimit');
 4516:         %validations = &Apache::lonnet::auto_courserequest_checks($dom);
 4517:         %titles = &courserequest_titles();
 4518:         $toolregexp = join('|',@usertools);
 4519:         %conditions = &courserequest_conditions();
 4520:     } else {
 4521:         @usertools = ('aboutme','blog','portfolio');
 4522:         %titles = &tool_titles();
 4523:     }
 4524:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
 4525:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
 4526:     foreach my $key (keys(%env)) {
 4527:         if ($context eq 'requestcourses') {
 4528:             if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
 4529:                 my $item = $1;
 4530:                 my $type = $2;
 4531:                 if ($type =~ /^limit_(.+)/) {
 4532:                     $limithash{$item}{$1} = $env{$key};
 4533:                 } else {
 4534:                     $confhash{$item}{$type} = $env{$key};
 4535:                 }
 4536:             }
 4537:         } else {
 4538:             if ($key =~ /^form\.quota_(.+)$/) {
 4539:                 $confhash{'defaultquota'}{$1} = $env{$key};
 4540:             }
 4541:             if ($key =~ /^form\.\Q$context\E_(.+)$/) {
 4542:                 @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
 4543:             }
 4544:         }
 4545:     }
 4546:     if ($context eq 'requestcourses') {
 4547:         my @approvalnotify = &Apache::loncommon::get_env_multiple('form.reqapprovalnotify');
 4548:         @approvalnotify = sort(@approvalnotify);
 4549:         $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
 4550:         if (ref($domconfig{$action}) eq 'HASH') {
 4551:             if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
 4552:                 if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
 4553:                     $changes{'notify'}{'approval'} = 1;
 4554:                 }
 4555:             } else {
 4556:                 if ($domconfig{$action}{'notify'}{'approval'}) {
 4557:                     $changes{'notify'}{'approval'} = 1;
 4558:                 }
 4559:             }
 4560:         } else {
 4561:             if ($domconfig{$action}{'notify'}{'approval'}) {
 4562:                 $changes{'notify'}{'approval'} = 1;
 4563:             }
 4564:         }
 4565:     } else {
 4566:         $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
 4567:     }
 4568:     foreach my $item (@usertools) {
 4569:         foreach my $type (@{$types},'default','_LC_adv') {
 4570:             my $unset; 
 4571:             if ($context eq 'requestcourses') {
 4572:                 $unset = '0';
 4573:                 if ($type eq '_LC_adv') {
 4574:                     $unset = '';
 4575:                 }
 4576:                 if ($confhash{$item}{$type} eq 'autolimit') {
 4577:                     $confhash{$item}{$type} .= '=';
 4578:                     unless ($limithash{$item}{$type} =~ /\D/) {
 4579:                         $confhash{$item}{$type} .= $limithash{$item}{$type};
 4580:                     }
 4581:                 }
 4582:             } else {
 4583:                 if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
 4584:                     $confhash{$item}{$type} = 1;
 4585:                 } else {
 4586:                     $confhash{$item}{$type} = 0;
 4587:                 }
 4588:             }
 4589:             if (ref($domconfig{$action}) eq 'HASH') {
 4590:                 if (ref($domconfig{$action}{$item}) eq 'HASH') {
 4591:                     if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
 4592:                         $changes{$item}{$type} = 1;
 4593:                     }
 4594:                 } else {
 4595:                     if ($context eq 'requestcourses') {
 4596:                         if ($confhash{$item}{$type} ne $unset) {
 4597:                             $changes{$item}{$type} = 1;
 4598:                         }
 4599:                     } else {
 4600:                         if (!$confhash{$item}{$type}) {
 4601:                             $changes{$item}{$type} = 1;
 4602:                         }
 4603:                     }
 4604:                 }
 4605:             } else {
 4606:                 if ($context eq 'requestcourses') {
 4607:                     if ($confhash{$item}{$type} ne $unset) {
 4608:                         $changes{$item}{$type} = 1;
 4609:                     }
 4610:                 } else {
 4611:                     if (!$confhash{$item}{$type}) {
 4612:                         $changes{$item}{$type} = 1;
 4613:                     }
 4614:                 }
 4615:             }
 4616:         }
 4617:     }
 4618:     unless ($context eq 'requestcourses') {
 4619:         if (ref($domconfig{'quotas'}) eq 'HASH') {
 4620:             if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
 4621:                 foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
 4622:                     if (exists($confhash{'defaultquota'}{$key})) {
 4623:                         if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
 4624:                             $changes{'defaultquota'}{$key} = 1;
 4625:                         }
 4626:                     } else {
 4627:                         $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
 4628:                     }
 4629:                 }
 4630:             } else {
 4631:                 foreach my $key (keys(%{$domconfig{'quotas'}})) {
 4632:                     if (exists($confhash{'defaultquota'}{$key})) {
 4633:                         if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
 4634:                             $changes{'defaultquota'}{$key} = 1;
 4635:                         }
 4636:                     } else {
 4637:                         $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
 4638:                     }
 4639:                 }
 4640:             }
 4641:         }
 4642:         if (ref($confhash{'defaultquota'}) eq 'HASH') {
 4643:             foreach my $key (keys(%{$confhash{'defaultquota'}})) {
 4644:                 if (ref($domconfig{'quotas'}) eq 'HASH') {
 4645:                     if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
 4646:                         if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
 4647:                             $changes{'defaultquota'}{$key} = 1;
 4648:                         }
 4649:                     } else {
 4650:                         if (!exists($domconfig{'quotas'}{$key})) {
 4651:                             $changes{'defaultquota'}{$key} = 1;
 4652:                         }
 4653:                     }
 4654:                 } else {
 4655:                     $changes{'defaultquota'}{$key} = 1;
 4656:                 }
 4657:             }
 4658:         }
 4659:     }
 4660: 
 4661:     foreach my $key (keys(%confhash)) {
 4662:         $domdefaults{$key} = $confhash{$key};
 4663:     }
 4664:    
 4665:     my %quotahash = (
 4666:                       $action => { %confhash }
 4667:                     );
 4668:     my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
 4669:                                              $dom);
 4670:     if ($putresult eq 'ok') {
 4671:         if (keys(%changes) > 0) {
 4672:             my $cachetime = 24*60*60;
 4673:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
 4674: 
 4675:             $resulttext = &mt('Changes made:').'<ul>';
 4676:             unless ($context eq 'requestcourses') {
 4677:                 if (ref($changes{'defaultquota'}) eq 'HASH') {
 4678:                     $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
 4679:                     foreach my $type (@{$types},'default') {
 4680:                         if (defined($changes{'defaultquota'}{$type})) {
 4681:                             my $typetitle = $usertypes->{$type};
 4682:                             if ($type eq 'default') {
 4683:                                 $typetitle = $othertitle;
 4684:                             }
 4685:                             $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
 4686:                         }
 4687:                     }
 4688:                     $resulttext .= '</ul></li>';
 4689:                 }
 4690:             }
 4691:             my %newenv;
 4692:             foreach my $item (@usertools) {
 4693:                 if (ref($changes{$item}) eq 'HASH') {
 4694:                     my $newacc = 
 4695:                         &Apache::lonnet::usertools_access($env{'user.name'},
 4696:                                                           $env{'user.domain'},
 4697:                                                           $item,'reload',$context);
 4698:                     if ($context eq 'requestcourses') {
 4699:                         if ($env{'environment.canrequest.'.$item} ne $newacc) {
 4700:                             $newenv{'environment.canrequest.'.$item} = $newacc;
 4701:                         }
 4702:                     } else {
 4703:                         if ($env{'environment.availabletools.'.$item} ne $newacc) { 
 4704:                             $newenv{'environment.availabletools.'.$item} = $newacc;
 4705:                         }
 4706:                     }
 4707:                     $resulttext .= '<li>'.$titles{$item}.'<ul>';
 4708:                     foreach my $type (@{$types},'default','_LC_adv') {
 4709:                         if ($changes{$item}{$type}) {
 4710:                             my $typetitle = $usertypes->{$type};
 4711:                             if ($type eq 'default') {
 4712:                                 $typetitle = $othertitle;
 4713:                             } elsif ($type eq '_LC_adv') {
 4714:                                 $typetitle = 'LON-CAPA Advanced Users'; 
 4715:                             }
 4716:                             if ($confhash{$item}{$type}) {
 4717:                                 if ($context eq 'requestcourses') {
 4718:                                     my $cond;
 4719:                                     if ($confhash{$item}{$type} =~ /^autolimit=(\d*)$/) {
 4720:                                         if ($1 eq '') {
 4721:                                             $cond = &mt('(Automatic processing of any request).');
 4722:                                         } else {
 4723:                                             $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
 4724:                                         }
 4725:                                     } else { 
 4726:                                         $cond = $conditions{$confhash{$item}{$type}};
 4727:                                     }
 4728:                                     $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
 4729:                                 } else {
 4730:                                     $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
 4731:                                 }
 4732:                             } else {
 4733:                                 if ($type eq '_LC_adv') {
 4734:                                     if ($confhash{$item}{$type} eq '0') {
 4735:                                         $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
 4736:                                     } else { 
 4737:                                         $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
 4738:                                     }
 4739:                                 } else {
 4740:                                     $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
 4741:                                 }
 4742:                             }
 4743:                         }
 4744:                     }
 4745:                     $resulttext .= '</ul></li>';
 4746:                 }
 4747:             }
 4748:             if ($action eq 'requestcourses') {
 4749:                 if (ref($changes{'notify'}) eq 'HASH') {
 4750:                     if ($changes{'notify'}{'approval'}) {
 4751:                         if (ref($confhash{'notify'}) eq 'HASH') {
 4752:                             if ($confhash{'notify'}{'approval'}) {
 4753:                                 $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
 4754:                             } else {
 4755:                                 $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of course requests requiring approval.').'</li>';
 4756:                             }
 4757:                         }
 4758:                     }
 4759:                 }
 4760:             }
 4761:             $resulttext .= '</ul>';
 4762:             if (keys(%newenv)) {
 4763:                 &Apache::lonnet::appenv(\%newenv);
 4764:             }
 4765:         } else {
 4766:             if ($context eq 'requestcourses') {
 4767:                 $resulttext = &mt('No changes made to rights to request creation of courses.');
 4768:             } else {
 4769:                 $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
 4770:             }
 4771:         }
 4772:     } else {
 4773:         $resulttext = '<span class="LC_error">'.
 4774: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
 4775:     }
 4776:     return $resulttext;
 4777: }
 4778: 
 4779: sub modify_autoenroll {
 4780:     my ($dom,%domconfig) = @_;
 4781:     my ($resulttext,%changes);
 4782:     my %currautoenroll;
 4783:     if (ref($domconfig{'autoenroll'}) eq 'HASH') {
 4784:         foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
 4785:             $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
 4786:         }
 4787:     }
 4788:     my $autorun = &Apache::lonnet::auto_run(undef,$dom),
 4789:     my %title = ( run => 'Auto-enrollment active',
 4790:                   sender => 'Sender for notification messages',
 4791:                   coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)');
 4792:     my @offon = ('off','on');
 4793:     my $sender_uname = $env{'form.sender_uname'};
 4794:     my $sender_domain = $env{'form.sender_domain'};
 4795:     if ($sender_domain eq '') {
 4796:         $sender_uname = '';
 4797:     } elsif ($sender_uname eq '') {
 4798:         $sender_domain = '';
 4799:     }
 4800:     my $coowners = $env{'form.autoassign_coowners'};
 4801:     my %autoenrollhash =  (
 4802:                        autoenroll => { 'run' => $env{'form.autoenroll_run'},
 4803:                                        'sender_uname' => $sender_uname,
 4804:                                        'sender_domain' => $sender_domain,
 4805:                                        'co-owners' => $coowners,
 4806:                                 }
 4807:                      );
 4808:     my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
 4809:                                              $dom);
 4810:     if ($putresult eq 'ok') {
 4811:         if (exists($currautoenroll{'run'})) {
 4812:              if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
 4813:                  $changes{'run'} = 1;
 4814:              }
 4815:         } elsif ($autorun) {
 4816:             if ($env{'form.autoenroll_run'} ne '1') {
 4817:                  $changes{'run'} = 1;
 4818:             }
 4819:         }
 4820:         if ($currautoenroll{'sender_uname'} ne $sender_uname) {
 4821:             $changes{'sender'} = 1;
 4822:         }
 4823:         if ($currautoenroll{'sender_domain'} ne $sender_domain) {
 4824:             $changes{'sender'} = 1;
 4825:         }
 4826:         if ($currautoenroll{'co-owners'} ne '') {
 4827:             if ($currautoenroll{'co-owners'} ne $coowners) {
 4828:                 $changes{'coowners'} = 1;
 4829:             }
 4830:         } elsif ($coowners) {
 4831:             $changes{'coowners'} = 1;
 4832:         }      
 4833:         if (keys(%changes) > 0) {
 4834:             $resulttext = &mt('Changes made:').'<ul>';
 4835:             if ($changes{'run'}) {
 4836:                 $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
 4837:             }
 4838:             if ($changes{'sender'}) {
 4839:                 if ($sender_uname eq '' || $sender_domain eq '') {
 4840:                     $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
 4841:                 } else {
 4842:                     $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
 4843:                 }
 4844:             }
 4845:             if ($changes{'coowners'}) {
 4846:                 $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
 4847:                 &Apache::loncommon::devalidate_domconfig_cache($dom);
 4848:             }
 4849:             $resulttext .= '</ul>';
 4850:         } else {
 4851:             $resulttext = &mt('No changes made to auto-enrollment settings');
 4852:         }
 4853:     } else {
 4854:         $resulttext = '<span class="LC_error">'.
 4855: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
 4856:     }
 4857:     return $resulttext;
 4858: }
 4859: 
 4860: sub modify_autoupdate {
 4861:     my ($dom,%domconfig) = @_;
 4862:     my ($resulttext,%currautoupdate,%fields,%changes);
 4863:     if (ref($domconfig{'autoupdate'}) eq 'HASH') {
 4864:         foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
 4865:             $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
 4866:         }
 4867:     }
 4868:     my @offon = ('off','on');
 4869:     my %title = &Apache::lonlocal::texthash (
 4870:                    run => 'Auto-update:',
 4871:                    classlists => 'Updates to user information in classlists?'
 4872:                 );
 4873:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
 4874:     my %fieldtitles = &Apache::lonlocal::texthash (
 4875:                         id => 'Student/Employee ID',
 4876:                         permanentemail => 'E-mail address',
 4877:                         lastname => 'Last Name',
 4878:                         firstname => 'First Name',
 4879:                         middlename => 'Middle Name',
 4880:                         generation => 'Generation',
 4881:                       );
 4882:     my $othertitle = &mt('All users');
 4883:     if (keys(%{$usertypes}) >  0) {
 4884:         $othertitle = &mt('Other users');
 4885:     }
 4886:     foreach my $key (keys(%env)) {
 4887:         if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
 4888:             my ($usertype,$item) = ($1,$2);
 4889:             if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
 4890:                 if ($usertype eq 'default') {   
 4891:                     push(@{$fields{$1}},$2);
 4892:                 } elsif (ref($types) eq 'ARRAY') {
 4893:                     if (grep(/^\Q$usertype\E$/,@{$types})) {
 4894:                         push(@{$fields{$1}},$2);
 4895:                     }
 4896:                 }
 4897:             }
 4898:         }
 4899:     }
 4900:     my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
 4901:     @lockablenames = sort(@lockablenames);
 4902:     if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
 4903:         my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
 4904:         if (@changed) {
 4905:             $changes{'lockablenames'} = 1;
 4906:         }
 4907:     } else {
 4908:         if (@lockablenames) {
 4909:             $changes{'lockablenames'} = 1;
 4910:         }
 4911:     }
 4912:     my %updatehash = (
 4913:                       autoupdate => { run => $env{'form.autoupdate_run'},
 4914:                                       classlists => $env{'form.classlists'},
 4915:                                       fields => {%fields},
 4916:                                       lockablenames => \@lockablenames,
 4917:                                     }
 4918:                      );
 4919:     foreach my $key (keys(%currautoupdate)) {
 4920:         if (($key eq 'run') || ($key eq 'classlists')) {
 4921:             if (exists($updatehash{autoupdate}{$key})) {
 4922:                 if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
 4923:                     $changes{$key} = 1;
 4924:                 }
 4925:             }
 4926:         } elsif ($key eq 'fields') {
 4927:             if (ref($currautoupdate{$key}) eq 'HASH') {
 4928:                 foreach my $item (@{$types},'default') {
 4929:                     if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
 4930:                         my $change = 0;
 4931:                         foreach my $type (@{$currautoupdate{$key}{$item}}) {
 4932:                             if (!exists($fields{$item})) {
 4933:                                 $change = 1;
 4934:                                 last;
 4935:                             } elsif (ref($fields{$item}) eq 'ARRAY') {
 4936:                                 if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
 4937:                                     $change = 1;
 4938:                                     last;
 4939:                                 }
 4940:                             }
 4941:                         }
 4942:                         if ($change) {
 4943:                             push(@{$changes{$key}},$item);
 4944:                         }
 4945:                     } 
 4946:                 }
 4947:             }
 4948:         } elsif ($key eq 'lockablenames') {
 4949:             if (ref($currautoupdate{$key}) eq 'ARRAY') {
 4950:                 my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
 4951:                 if (@changed) {
 4952:                     $changes{'lockablenames'} = 1;
 4953:                 }
 4954:             } else {
 4955:                 if (@lockablenames) {
 4956:                     $changes{'lockablenames'} = 1;
 4957:                 }
 4958:             }
 4959:         }
 4960:     }
 4961:     unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
 4962:         if (@lockablenames) {
 4963:             $changes{'lockablenames'} = 1;
 4964:         }
 4965:     }
 4966:     foreach my $item (@{$types},'default') {
 4967:         if (defined($fields{$item})) {
 4968:             if (ref($currautoupdate{'fields'}) eq 'HASH') {
 4969:                 if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
 4970:                     my $change = 0;
 4971:                     if (ref($fields{$item}) eq 'ARRAY') {
 4972:                         foreach my $type (@{$fields{$item}}) {
 4973:                             if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
 4974:                                 $change = 1;
 4975:                                 last;
 4976:                             }
 4977:                         }
 4978:                     }
 4979:                     if ($change) {
 4980:                         push(@{$changes{'fields'}},$item);
 4981:                     }
 4982:                 } else {
 4983:                     push(@{$changes{'fields'}},$item);
 4984:                 }
 4985:             } else {
 4986:                 push(@{$changes{'fields'}},$item);
 4987:             }
 4988:         }
 4989:     }
 4990:     my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
 4991:                                              $dom);
 4992:     if ($putresult eq 'ok') {
 4993:         if (keys(%changes) > 0) {
 4994:             $resulttext = &mt('Changes made:').'<ul>';
 4995:             foreach my $key (sort(keys(%changes))) {
 4996:                 if ($key eq 'lockablenames') {
 4997:                     $resulttext .= '<li>';
 4998:                     if (@lockablenames) {
 4999:                         $usertypes->{'default'} = $othertitle;
 5000:                         $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
 5001:                                    join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
 5002:                     } else {
 5003:                         $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
 5004:                     }
 5005:                     $resulttext .= '</li>';
 5006:                 } elsif (ref($changes{$key}) eq 'ARRAY') {
 5007:                     foreach my $item (@{$changes{$key}}) {
 5008:                         my @newvalues;
 5009:                         foreach my $type (@{$fields{$item}}) {
 5010:                             push(@newvalues,$fieldtitles{$type});
 5011:                         }
 5012:                         my $newvaluestr;
 5013:                         if (@newvalues > 0) {
 5014:                             $newvaluestr = join(', ',@newvalues);
 5015:                         } else {
 5016:                             $newvaluestr = &mt('none');
 5017:                         }
 5018:                         if ($item eq 'default') {
 5019:                             $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
 5020:                         } else {
 5021:                             $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
 5022:                         }
 5023:                     }
 5024:                 } else {
 5025:                     my $newvalue;
 5026:                     if ($key eq 'run') {
 5027:                         $newvalue = $offon[$env{'form.autoupdate_run'}];
 5028:                     } else {
 5029:                         $newvalue = $offon[$env{'form.'.$key}];
 5030:                     }
 5031:                     $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
 5032:                 }
 5033:             }
 5034:             $resulttext .= '</ul>';
 5035:         } else {
 5036:             $resulttext = &mt('No changes made to autoupdates');
 5037:         }
 5038:     } else {
 5039:         $resulttext = '<span class="LC_error">'.
 5040: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
 5041:     }
 5042:     return $resulttext;
 5043: }
 5044: 
 5045: sub modify_autocreate {
 5046:     my ($dom,%domconfig) = @_;
 5047:     my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
 5048:     if (ref($domconfig{'autocreate'}) eq 'HASH') {
 5049:         foreach my $key (keys(%{$domconfig{'autocreate'}})) {
 5050:             $currautocreate{$key} = $domconfig{'autocreate'}{$key};
 5051:         }
 5052:     }
 5053:     my %title= ( xml => 'Auto-creation of courses in XML course description files',
 5054:                  req => 'Auto-creation of validated requests for official courses',
 5055:                  xmldc => 'Identity of course creator of courses from XML files',
 5056:                );
 5057:     my @types = ('xml','req');
 5058:     foreach my $item (@types) {
 5059:         $newvals{$item} = $env{'form.autocreate_'.$item};
 5060:         $newvals{$item} =~ s/\D//g;
 5061:         $newvals{$item} = 0 if ($newvals{$item} eq '');
 5062:     }
 5063:     $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
 5064:     my %domcoords = &get_active_dcs($dom);
 5065:     unless (exists($domcoords{$newvals{'xmldc'}})) {
 5066:         $newvals{'xmldc'} = '';
 5067:     } 
 5068:     %autocreatehash =  (
 5069:                         autocreate => { xml => $newvals{'xml'},
 5070:                                         req => $newvals{'req'},
 5071:                                       }
 5072:                        );
 5073:     if ($newvals{'xmldc'} ne '') {
 5074:         $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
 5075:     }
 5076:     my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
 5077:                                              $dom);
 5078:     if ($putresult eq 'ok') {
 5079:         my @items = @types;
 5080:         if ($newvals{'xml'}) {
 5081:             push(@items,'xmldc');
 5082:         }
 5083:         foreach my $item (@items) {
 5084:             if (exists($currautocreate{$item})) {
 5085:                 if ($currautocreate{$item} ne $newvals{$item}) {
 5086:                     $changes{$item} = 1;
 5087:                 }
 5088:             } elsif ($newvals{$item}) {
 5089:                 $changes{$item} = 1;
 5090:             }
 5091:         }
 5092:         if (keys(%changes) > 0) {
 5093:             my @offon = ('off','on'); 
 5094:             $resulttext = &mt('Changes made:').'<ul>';
 5095:             foreach my $item (@types) {
 5096:                 if ($changes{$item}) {
 5097:                     my $newtxt = $offon[$newvals{$item}];
 5098:                     $resulttext .= '<li>'.&mt("$title{$item} set to [_1]$newtxt [_2]",'<b>','</b>').'</li>';
 5099:                 }
 5100:             }
 5101:             if ($changes{'xmldc'}) {
 5102:                 my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
 5103:                 my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
 5104:                 $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]$newtxt [_2]",'<b>','</b>').'</li>'; 
 5105:             }
 5106:             $resulttext .= '</ul>';
 5107:         } else {
 5108:             $resulttext = &mt('No changes made to auto-creation settings');
 5109:         }
 5110:     } else {
 5111:         $resulttext = '<span class="LC_error">'.
 5112:             &mt('An error occurred: [_1]',$putresult).'</span>';
 5113:     }
 5114:     return $resulttext;
 5115: }
 5116: 
 5117: sub modify_directorysrch {
 5118:     my ($dom,%domconfig) = @_;
 5119:     my ($resulttext,%changes);
 5120:     my %currdirsrch;
 5121:     if (ref($domconfig{'directorysrch'}) eq 'HASH') {
 5122:         foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
 5123:             $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
 5124:         }
 5125:     }
 5126:     my %title = ( available => 'Directory search available',
 5127:                   localonly => 'Other domains can search',
 5128:                   searchby => 'Search types',
 5129:                   searchtypes => 'Search latitude');
 5130:     my @offon = ('off','on');
 5131:     my @otherdoms = ('Yes','No');
 5132: 
 5133:     my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');  
 5134:     my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
 5135:     my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
 5136: 
 5137:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
 5138:     if (keys(%{$usertypes}) == 0) {
 5139:         @cansearch = ('default');
 5140:     } else {
 5141:         if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
 5142:             foreach my $type (@{$currdirsrch{'cansearch'}}) {
 5143:                 if (!grep(/^\Q$type\E$/,@cansearch)) {
 5144:                     push(@{$changes{'cansearch'}},$type);
 5145:                 }
 5146:             }
 5147:             foreach my $type (@cansearch) {
 5148:                 if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
 5149:                     push(@{$changes{'cansearch'}},$type);
 5150:                 }
 5151:             }
 5152:         } else {
 5153:             push(@{$changes{'cansearch'}},@cansearch);
 5154:         }
 5155:     }
 5156: 
 5157:     if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
 5158:         foreach my $by (@{$currdirsrch{'searchby'}}) {
 5159:             if (!grep(/^\Q$by\E$/,@searchby)) {
 5160:                 push(@{$changes{'searchby'}},$by);
 5161:             }
 5162:         }
 5163:         foreach my $by (@searchby) {
 5164:             if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
 5165:                 push(@{$changes{'searchby'}},$by);
 5166:             }
 5167:         }
 5168:     } else {
 5169:         push(@{$changes{'searchby'}},@searchby);
 5170:     }
 5171: 
 5172:     if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
 5173:         foreach my $type (@{$currdirsrch{'searchtypes'}}) {
 5174:             if (!grep(/^\Q$type\E$/,@searchtypes)) {
 5175:                 push(@{$changes{'searchtypes'}},$type);
 5176:             }
 5177:         }
 5178:         foreach my $type (@searchtypes) {
 5179:             if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
 5180:                 push(@{$changes{'searchtypes'}},$type);
 5181:             }
 5182:         }
 5183:     } else {
 5184:         if (exists($currdirsrch{'searchtypes'})) {
 5185:             foreach my $type (@searchtypes) {  
 5186:                 if ($type ne $currdirsrch{'searchtypes'}) { 
 5187:                     push(@{$changes{'searchtypes'}},$type);
 5188:                 }
 5189:             }
 5190:             if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
 5191:                 push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
 5192:             }   
 5193:         } else {
 5194:             push(@{$changes{'searchtypes'}},@searchtypes); 
 5195:         }
 5196:     }
 5197: 
 5198:     my %dirsrch_hash =  (
 5199:             directorysrch => { available => $env{'form.dirsrch_available'},
 5200:                                cansearch => \@cansearch,
 5201:                                localonly => $env{'form.dirsrch_localonly'},
 5202:                                searchby => \@searchby,
 5203:                                searchtypes => \@searchtypes,
 5204:                              }
 5205:             );
 5206:     my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
 5207:                                              $dom);
 5208:     if ($putresult eq 'ok') {
 5209:         if (exists($currdirsrch{'available'})) {
 5210:              if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
 5211:                  $changes{'available'} = 1;
 5212:              }
 5213:         } else {
 5214:             if ($env{'form.dirsrch_available'} eq '1') {
 5215:                 $changes{'available'} = 1;
 5216:             }
 5217:         }
 5218:         if (exists($currdirsrch{'localonly'})) {
 5219:              if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
 5220:                  $changes{'localonly'} = 1;
 5221:              }
 5222:         } else {
 5223:             if ($env{'form.dirsrch_localonly'} eq '1') {
 5224:                 $changes{'localonly'} = 1;
 5225:             }
 5226:         }
 5227:         if (keys(%changes) > 0) {
 5228:             $resulttext = &mt('Changes made:').'<ul>';
 5229:             if ($changes{'available'}) {
 5230:                 $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
 5231:             }
 5232:             if ($changes{'localonly'}) {
 5233:                 $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
 5234:             }
 5235: 
 5236:             if (ref($changes{'cansearch'}) eq 'ARRAY') {
 5237:                 my $chgtext;
 5238:                 if (ref($usertypes) eq 'HASH') {
 5239:                     if (keys(%{$usertypes}) > 0) {
 5240:                         foreach my $type (@{$types}) {
 5241:                             if (grep(/^\Q$type\E$/,@cansearch)) {
 5242:                                 $chgtext .= $usertypes->{$type}.'; ';
 5243:                             }
 5244:                         }
 5245:                         if (grep(/^default$/,@cansearch)) {
 5246:                             $chgtext .= $othertitle;
 5247:                         } else {
 5248:                             $chgtext =~ s/\; $//;
 5249:                         }
 5250:                         $resulttext .= '<li>'.&mt("Users from domain '<span class=\"LC_cusr_emph\">[_1]</span>' permitted to search the institutional directory set to: [_2]",$dom,$chgtext).'</li>';
 5251:                     }
 5252:                 }
 5253:             }
 5254:             if (ref($changes{'searchby'}) eq 'ARRAY') {
 5255:                 my ($searchtitles,$titleorder) = &sorted_searchtitles();
 5256:                 my $chgtext;
 5257:                 foreach my $type (@{$titleorder}) {
 5258:                     if (grep(/^\Q$type\E$/,@searchby)) {
 5259:                         if (defined($searchtitles->{$type})) {
 5260:                             $chgtext .= $searchtitles->{$type}.'; ';
 5261:                         }
 5262:                     }
 5263:                 }
 5264:                 $chgtext =~ s/\; $//;
 5265:                 $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
 5266:             }
 5267:             if (ref($changes{'searchtypes'}) eq 'ARRAY') {
 5268:                 my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes(); 
 5269:                 my $chgtext;
 5270:                 foreach my $type (@{$srchtypeorder}) {
 5271:                     if (grep(/^\Q$type\E$/,@searchtypes)) {
 5272:                         if (defined($srchtypes_desc->{$type})) {
 5273:                             $chgtext .= $srchtypes_desc->{$type}.'; ';
 5274:                         }
 5275:                     }
 5276:                 }
 5277:                 $chgtext =~ s/\; $//;
 5278:                 $resulttext .= '<li>'.&mt("$title{'searchtypes'} set to: \"[_1]\"",$chgtext).'</li>';
 5279:             }
 5280:             $resulttext .= '</ul>';
 5281:         } else {
 5282:             $resulttext = &mt('No changes made to institution directory search settings');
 5283:         }
 5284:     } else {
 5285:         $resulttext = '<span class="LC_error">'.
 5286:                       &mt('An error occurred: [_1]',$putresult).'</span>';
 5287:     }
 5288:     return $resulttext;
 5289: }
 5290: 
 5291: sub modify_contacts {
 5292:     my ($dom,%domconfig) = @_;
 5293:     my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
 5294:     if (ref($domconfig{'contacts'}) eq 'HASH') {
 5295:         foreach my $key (keys(%{$domconfig{'contacts'}})) {
 5296:             $currsetting{$key} = $domconfig{'contacts'}{$key};
 5297:         }
 5298:     }
 5299:     my (%others,%to,%bcc);
 5300:     my @contacts = ('supportemail','adminemail');
 5301:     my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
 5302:                     'requestsmail');
 5303:     foreach my $type (@mailings) {
 5304:         @{$newsetting{$type}} = 
 5305:             &Apache::loncommon::get_env_multiple('form.'.$type);
 5306:         foreach my $item (@contacts) {
 5307:             if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
 5308:                 $contacts_hash{contacts}{$type}{$item} = 1;
 5309:             } else {
 5310:                 $contacts_hash{contacts}{$type}{$item} = 0;
 5311:             }
 5312:         }  
 5313:         $others{$type} = $env{'form.'.$type.'_others'};
 5314:         $contacts_hash{contacts}{$type}{'others'} = $others{$type};
 5315:         if ($type eq 'helpdeskmail') {
 5316:             $bcc{$type} = $env{'form.'.$type.'_bcc'};
 5317:             $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
 5318:         }
 5319:     }
 5320:     foreach my $item (@contacts) {
 5321:         $to{$item} = $env{'form.'.$item};
 5322:         $contacts_hash{'contacts'}{$item} = $to{$item};
 5323:     }
 5324:     if (keys(%currsetting) > 0) {
 5325:         foreach my $item (@contacts) {
 5326:             if ($to{$item} ne $currsetting{$item}) {
 5327:                 $changes{$item} = 1;
 5328:             }
 5329:         }
 5330:         foreach my $type (@mailings) {
 5331:             foreach my $item (@contacts) {
 5332:                 if (ref($currsetting{$type}) eq 'HASH') {
 5333:                     if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
 5334:                         push(@{$changes{$type}},$item);
 5335:                     }
 5336:                 } else {
 5337:                     push(@{$changes{$type}},@{$newsetting{$type}});
 5338:                 }
 5339:             }
 5340:             if ($others{$type} ne $currsetting{$type}{'others'}) {
 5341:                 push(@{$changes{$type}},'others');
 5342:             }
 5343:             if ($type eq 'helpdeskmail') {   
 5344:                 if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
 5345:                     push(@{$changes{$type}},'bcc'); 
 5346:                 }
 5347:             }
 5348:         }
 5349:     } else {
 5350:         my %default;
 5351:         $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
 5352:         $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
 5353:         $default{'errormail'} = 'adminemail';
 5354:         $default{'packagesmail'} = 'adminemail';
 5355:         $default{'helpdeskmail'} = 'supportemail';
 5356:         $default{'lonstatusmail'} = 'adminemail';
 5357:         $default{'requestsmail'} = 'adminemail';
 5358:         foreach my $item (@contacts) {
 5359:            if ($to{$item} ne $default{$item}) {
 5360:               $changes{$item} = 1;
 5361:            } 
 5362:         }
 5363:         foreach my $type (@mailings) {
 5364:             if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
 5365:                
 5366:                 push(@{$changes{$type}},@{$newsetting{$type}});
 5367:             }
 5368:             if ($others{$type} ne '') {
 5369:                 push(@{$changes{$type}},'others');
 5370:             }
 5371:             if ($type eq 'helpdeskmail') {
 5372:                 if ($bcc{$type} ne '') {
 5373:                     push(@{$changes{$type}},'bcc');
 5374:                 }
 5375:             }
 5376:         }
 5377:     }
 5378:     my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
 5379:                                              $dom);
 5380:     if ($putresult eq 'ok') {
 5381:         if (keys(%changes) > 0) {
 5382:             my ($titles,$short_titles)  = &contact_titles();
 5383:             $resulttext = &mt('Changes made:').'<ul>';
 5384:             foreach my $item (@contacts) {
 5385:                 if ($changes{$item}) {
 5386:                     $resulttext .= '<li>'.$titles->{$item}.
 5387:                                     &mt(' set to: ').
 5388:                                     '<span class="LC_cusr_emph">'.
 5389:                                     $to{$item}.'</span></li>';
 5390:                 }
 5391:             }
 5392:             foreach my $type (@mailings) {
 5393:                 if (ref($changes{$type}) eq 'ARRAY') {
 5394:                     $resulttext .= '<li>'.$titles->{$type}.': ';
 5395:                     my @text;
 5396:                     foreach my $item (@{$newsetting{$type}}) {
 5397:                         push(@text,$short_titles->{$item});
 5398:                     }
 5399:                     if ($others{$type} ne '') {
 5400:                         push(@text,$others{$type});
 5401:                     }
 5402:                     $resulttext .= '<span class="LC_cusr_emph">'.
 5403:                                    join(', ',@text).'</span>';
 5404:                     if ($type eq 'helpdeskmail') {
 5405:                         if ($bcc{$type} ne '') {
 5406:                             $resulttext .= '&nbsp;'.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
 5407:                         }
 5408:                     }
 5409:                     $resulttext .= '</li>';
 5410:                 }
 5411:             }
 5412:             $resulttext .= '</ul>';
 5413:         } else {
 5414:             $resulttext = &mt('No changes made to contact information');
 5415:         }
 5416:     } else {
 5417:         $resulttext = '<span class="LC_error">'.
 5418:             &mt('An error occurred: [_1].',$putresult).'</span>';
 5419:     }
 5420:     return $resulttext;
 5421: }
 5422: 
 5423: sub modify_usercreation {
 5424:     my ($dom,%domconfig) = @_;
 5425:     my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate);
 5426:     my $warningmsg;
 5427:     if (ref($domconfig{'usercreation'}) eq 'HASH') {
 5428:         foreach my $key (keys(%{$domconfig{'usercreation'}})) {
 5429:             $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
 5430:         }
 5431:     }
 5432:     my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
 5433:     my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
 5434:     my @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
 5435:     my @contexts = ('author','course','requestcrs','selfcreate');
 5436:     foreach my $item(@contexts) {
 5437:         if ($item eq 'selfcreate') {
 5438:             @{$cancreate{$item}} = &Apache::loncommon::get_env_multiple('form.can_createuser_'.$item);
 5439:             my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
 5440:             if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) || ($domdefaults{'auth_def'} eq 'localauth'))) {
 5441:                 if (ref($cancreate{$item}) eq 'ARRAY') { 
 5442:                     if (grep(/^login$/,@{$cancreate{$item}})) {
 5443:                         $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.');   
 5444:                     }
 5445:                 }
 5446:             }
 5447:         } else {
 5448:             $cancreate{$item} = $env{'form.can_createuser_'.$item};
 5449:         }
 5450:     }
 5451:     my ($othertitle,$usertypes,$types) = 
 5452:         &Apache::loncommon::sorted_inst_types($dom);
 5453:     if (ref($types) eq 'ARRAY') {
 5454:         if (@{$types} > 0) {
 5455:             @{$cancreate{'statustocreate'}} = 
 5456:                 &Apache::loncommon::get_env_multiple('form.statustocreate');
 5457:         } else {
 5458:             @{$cancreate{'statustocreate'}} = ();
 5459:         }
 5460:         push(@contexts,'statustocreate');
 5461:     }
 5462:     if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
 5463:         foreach my $item (@contexts) {
 5464:             if (($item eq 'selfcreate') || ($item eq 'statustocreate')) {
 5465:                 if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
 5466:                     foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
 5467:                         if (ref($cancreate{$item}) eq 'ARRAY') {
 5468:                             if (!grep(/^$curr$/,@{$cancreate{$item}})) {
 5469:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
 5470:                                     push(@{$changes{'cancreate'}},$item);
 5471:                                 }
 5472:                             }
 5473:                         }
 5474:                     }
 5475:                 } else {
 5476:                     if ($curr_usercreation{'cancreate'}{$item} eq '') {
 5477:                         if (@{$cancreate{$item}} > 0) {
 5478:                             if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
 5479:                                 push(@{$changes{'cancreate'}},$item);
 5480:                             }
 5481:                         }
 5482:                     } else {
 5483:                         if ($curr_usercreation{'cancreate'}{$item} eq 'any') {
 5484:                             if (@{$cancreate{$item}} < 3) {
 5485:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
 5486:                                     push(@{$changes{'cancreate'}},$item);
 5487:                                 }
 5488:                             }
 5489:                         } elsif ($curr_usercreation{'cancreate'}{$item} eq 'none') {
 5490:                             if (@{$cancreate{$item}} > 0) {
 5491:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
 5492:                                     push(@{$changes{'cancreate'}},$item);
 5493:                                 }
 5494:                             }
 5495:                         } elsif (!grep(/^$curr_usercreation{'cancreate'}{$item}$/,@{$cancreate{$item}})) {
 5496:                             if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
 5497:                                 push(@{$changes{'cancreate'}},$item);
 5498:                             }
 5499:                         }
 5500:                     }
 5501:                 }
 5502:                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
 5503:                     foreach my $type (@{$cancreate{$item}}) {
 5504:                         if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
 5505:                             if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
 5506:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
 5507:                                     push(@{$changes{'cancreate'}},$item);
 5508:                                 }
 5509:                             }
 5510:                         } elsif (($curr_usercreation{'cancreate'}{$item} ne 'any') &&
 5511:                                  ($curr_usercreation{'cancreate'}{$item} ne 'none')) {
 5512:                             if ($curr_usercreation{'cancreate'}{$item} ne $type) {
 5513:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
 5514:                                     push(@{$changes{'cancreate'}},$item);
 5515:                                 }
 5516:                             }
 5517:                         }
 5518:                     }
 5519:                 }
 5520:             } else {
 5521:                 if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
 5522:                     push(@{$changes{'cancreate'}},$item);
 5523:                 }
 5524:             }
 5525:         }
 5526:     } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
 5527:         foreach my $item (@contexts) {
 5528:             if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
 5529:                 if ($cancreate{$item} ne 'any') {
 5530:                     push(@{$changes{'cancreate'}},$item);
 5531:                 }
 5532:             } else {
 5533:                 if ($cancreate{$item} ne 'none') {
 5534:                     push(@{$changes{'cancreate'}},$item);
 5535:                 }
 5536:             }
 5537:         }
 5538:     } else {
 5539:         foreach my $item (@contexts)  {
 5540:             push(@{$changes{'cancreate'}},$item);
 5541:         }
 5542:     }
 5543: 
 5544:     if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
 5545:         foreach my $type (@{$curr_usercreation{'username_rule'}}) {
 5546:             if (!grep(/^\Q$type\E$/,@username_rule)) {
 5547:                 push(@{$changes{'username_rule'}},$type);
 5548:             }
 5549:         }
 5550:         foreach my $type (@username_rule) {
 5551:             if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
 5552:                 push(@{$changes{'username_rule'}},$type);
 5553:             }
 5554:         }
 5555:     } else {
 5556:         push(@{$changes{'username_rule'}},@username_rule);
 5557:     }
 5558: 
 5559:     if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
 5560:         foreach my $type (@{$curr_usercreation{'id_rule'}}) {
 5561:             if (!grep(/^\Q$type\E$/,@id_rule)) {
 5562:                 push(@{$changes{'id_rule'}},$type);
 5563:             }
 5564:         }
 5565:         foreach my $type (@id_rule) {
 5566:             if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
 5567:                 push(@{$changes{'id_rule'}},$type);
 5568:             }
 5569:         }
 5570:     } else {
 5571:         push(@{$changes{'id_rule'}},@id_rule);
 5572:     }
 5573: 
 5574:     if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
 5575:         foreach my $type (@{$curr_usercreation{'email_rule'}}) {
 5576:             if (!grep(/^\Q$type\E$/,@email_rule)) {
 5577:                 push(@{$changes{'email_rule'}},$type);
 5578:             }
 5579:         }
 5580:         foreach my $type (@email_rule) {
 5581:             if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
 5582:                 push(@{$changes{'email_rule'}},$type);
 5583:             }
 5584:         }
 5585:     } else {
 5586:         push(@{$changes{'email_rule'}},@email_rule);
 5587:     }
 5588: 
 5589:     my @authen_contexts = ('author','course','domain');
 5590:     my @authtypes = ('int','krb4','krb5','loc');
 5591:     my %authhash;
 5592:     foreach my $item (@authen_contexts) {
 5593:         my @authallowed =  &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
 5594:         foreach my $auth (@authtypes) {
 5595:             if (grep(/^\Q$auth\E$/,@authallowed)) {
 5596:                 $authhash{$item}{$auth} = 1;
 5597:             } else {
 5598:                 $authhash{$item}{$auth} = 0;
 5599:             }
 5600:         }
 5601:     }
 5602:     if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
 5603:         foreach my $item (@authen_contexts) {
 5604:             if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
 5605:                 foreach my $auth (@authtypes) {
 5606:                     if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
 5607:                         push(@{$changes{'authtypes'}},$item);
 5608:                         last;
 5609:                     }
 5610:                 }
 5611:             }
 5612:         }
 5613:     } else {
 5614:         foreach my $item (@authen_contexts) {
 5615:             push(@{$changes{'authtypes'}},$item);
 5616:         }
 5617:     }
 5618: 
 5619:     my %usercreation_hash =  (
 5620:             usercreation => {
 5621:                               cancreate     => \%cancreate,
 5622:                               username_rule => \@username_rule,
 5623:                               id_rule       => \@id_rule,
 5624:                               email_rule    => \@email_rule,
 5625:                               authtypes     => \%authhash,
 5626:                             }
 5627:             );
 5628: 
 5629:     my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
 5630:                                              $dom);
 5631: 
 5632:     my %selfcreatetypes = (
 5633:                              sso   => 'users authenticated by institutional single sign on',
 5634:                              login => 'users authenticated by institutional log-in',
 5635:                              email => 'users who provide a valid e-mail address for use as the username',
 5636:                           );
 5637:     if ($putresult eq 'ok') {
 5638:         if (keys(%changes) > 0) {
 5639:             $resulttext = &mt('Changes made:').'<ul>';
 5640:             if (ref($changes{'cancreate'}) eq 'ARRAY') {
 5641:                 my %lt = &usercreation_types();
 5642:                 foreach my $type (@{$changes{'cancreate'}}) {
 5643:                     my $chgtext;
 5644:                     unless ($type eq 'statustocreate') {
 5645:                         $chgtext = $lt{$type}.', ';
 5646:                     }
 5647:                     if ($type eq 'selfcreate') {
 5648:                         if (@{$cancreate{$type}} == 0) {
 5649:                             $chgtext .= &mt('creation of a new user account is not permitted.');
 5650:                         } else {
 5651:                             $chgtext .= &mt('creation of a new account is permitted for:').'<ul>';
 5652:                             foreach my $case (@{$cancreate{$type}}) {
 5653:                                 $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
 5654:                             }
 5655:                             $chgtext .= '</ul>';
 5656:                             if (ref($cancreate{$type}) eq 'ARRAY') {
 5657:                                 if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
 5658:                                     if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
 5659:                                         if (@{$cancreate{'statustocreate'}} == 0) {
 5660:                                             $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
 5661:                                         }
 5662:                                     }
 5663:                                 }
 5664:                             }
 5665:                         }
 5666:                     } elsif ($type eq 'statustocreate') {
 5667:                         if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
 5668:                             (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
 5669:                             if (@{$cancreate{'selfcreate'}} > 0) {
 5670:                                 if (@{$cancreate{'statustocreate'}} == 0) {
 5671: 
 5672:                                     $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
 5673:                                     if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
 5674:                                         $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
 5675:                                     } 
 5676:                                 } elsif (ref($usertypes) eq 'HASH') {
 5677:                                     if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
 5678:                                         $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
 5679:                                     } else {
 5680:                                         $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
 5681:                                     }
 5682:                                     $chgtext .= '<ul>';
 5683:                                     foreach my $case (@{$cancreate{$type}}) {
 5684:                                         if ($case eq 'default') {
 5685:                                             $chgtext .= '<li>'.$othertitle.'</li>';
 5686:                                         } else {
 5687:                                             $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
 5688:                                         }
 5689:                                     }
 5690:                                     $chgtext .= '</ul>';
 5691:                                     if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
 5692:                                         $chgtext .= '<br /><span class="LC_warning">'.&mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').'</span>';
 5693:                                     }
 5694:                                 }
 5695:                             } else {
 5696:                                 if (@{$cancreate{$type}} == 0) {
 5697:                                     $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
 5698:                                 } else {
 5699:                                     $chgtext .= &mt('Although institutional affiliations permitted to create accounts were changed, self creation of accounts is not currently permitted for any authentication types.');
 5700:                                 }
 5701:                             }
 5702:                         }
 5703:                     } else {
 5704:                         if ($cancreate{$type} eq 'none') {
 5705:                             $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
 5706:                         } elsif ($cancreate{$type} eq 'any') {
 5707:                             $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
 5708:                         } elsif ($cancreate{$type} eq 'official') {
 5709:                             $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
 5710:                         } elsif ($cancreate{$type} eq 'unofficial') {
 5711:                             $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
 5712:                         }
 5713:                     }
 5714:                     $resulttext .= '<li>'.$chgtext.'</li>';
 5715:                 }
 5716:             }
 5717:             if (ref($changes{'username_rule'}) eq 'ARRAY') {
 5718:                 my ($rules,$ruleorder) = 
 5719:                     &Apache::lonnet::inst_userrules($dom,'username');
 5720:                 my $chgtext = '<ul>';
 5721:                 foreach my $type (@username_rule) {
 5722:                     if (ref($rules->{$type}) eq 'HASH') {
 5723:                         $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
 5724:                     }
 5725:                 }
 5726:                 $chgtext .= '</ul>';
 5727:                 if (@username_rule > 0) {
 5728:                     $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';     
 5729:                 } else {
 5730:                     $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>'; 
 5731:                 }
 5732:             }
 5733:             if (ref($changes{'id_rule'}) eq 'ARRAY') {
 5734:                 my ($idrules,$idruleorder) = 
 5735:                     &Apache::lonnet::inst_userrules($dom,'id');
 5736:                 my $chgtext = '<ul>';
 5737:                 foreach my $type (@id_rule) {
 5738:                     if (ref($idrules->{$type}) eq 'HASH') {
 5739:                         $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
 5740:                     }
 5741:                 }
 5742:                 $chgtext .= '</ul>';
 5743:                 if (@id_rule > 0) {
 5744:                     $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
 5745:                 } else {
 5746:                     $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
 5747:                 }
 5748:             }
 5749:             if (ref($changes{'email_rule'}) eq 'ARRAY') {
 5750:                 my ($emailrules,$emailruleorder) =
 5751:                     &Apache::lonnet::inst_userrules($dom,'email');
 5752:                 my $chgtext = '<ul>';
 5753:                 foreach my $type (@email_rule) {
 5754:                     if (ref($emailrules->{$type}) eq 'HASH') {
 5755:                         $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
 5756:                     }
 5757:                 }
 5758:                 $chgtext .= '</ul>';
 5759:                 if (@email_rule > 0) {
 5760:                     $resulttext .= '<li>'.&mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').$chgtext.'</li>';
 5761:                 } else {
 5762:                     $resulttext .= '<li>'.&mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').'</li>';
 5763:                 }
 5764:             }
 5765: 
 5766:             my %authname = &authtype_names();
 5767:             my %context_title = &context_names();
 5768:             if (ref($changes{'authtypes'}) eq 'ARRAY') {
 5769:                 my $chgtext = '<ul>';
 5770:                 foreach my $type (@{$changes{'authtypes'}}) {
 5771:                     my @allowed;
 5772:                     $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
 5773:                     foreach my $auth (@authtypes) {
 5774:                         if ($authhash{$type}{$auth}) {
 5775:                             push(@allowed,$authname{$auth});
 5776:                         }
 5777:                     }
 5778:                     if (@allowed > 0) {
 5779:                         $chgtext .= join(', ',@allowed).'</li>';
 5780:                     } else {
 5781:                         $chgtext .= &mt('none').'</li>';
 5782:                     }
 5783:                 }
 5784:                 $chgtext .= '</ul>';
 5785:                 $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
 5786:                 $resulttext .= '</li>';
 5787:             }
 5788:             $resulttext .= '</ul>';
 5789:         } else {
 5790:             $resulttext = &mt('No changes made to user creation settings');
 5791:         }
 5792:     } else {
 5793:         $resulttext = '<span class="LC_error">'.
 5794:             &mt('An error occurred: [_1]',$putresult).'</span>';
 5795:     }
 5796:     if ($warningmsg ne '') {
 5797:         $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
 5798:     }
 5799:     return $resulttext;
 5800: }
 5801: 
 5802: sub modify_usermodification {
 5803:     my ($dom,%domconfig) = @_;
 5804:     my ($resulttext,%curr_usermodification,%changes);
 5805:     if (ref($domconfig{'usermodification'}) eq 'HASH') {
 5806:         foreach my $key (keys(%{$domconfig{'usermodification'}})) {
 5807:             $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
 5808:         }
 5809:     }
 5810:     my @contexts = ('author','course','selfcreate');
 5811:     my %context_title = (
 5812:                            author => 'In author context',
 5813:                            course => 'In course context',
 5814:                            selfcreate => 'When self creating account', 
 5815:                         );
 5816:     my @fields = ('lastname','firstname','middlename','generation',
 5817:                   'permanentemail','id');
 5818:     my %roles = (
 5819:                   author => ['ca','aa'],
 5820:                   course => ['st','ep','ta','in','cr'],
 5821:                 );
 5822:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
 5823:     if (ref($types) eq 'ARRAY') {
 5824:         push(@{$types},'default');
 5825:         $usertypes->{'default'} = $othertitle;
 5826:     }
 5827:     $roles{'selfcreate'} = $types;  
 5828:     my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
 5829:     my %modifyhash;
 5830:     foreach my $context (@contexts) {
 5831:         foreach my $role (@{$roles{$context}}) {
 5832:             my @modifiable =  &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
 5833:             foreach my $item (@fields) {
 5834:                 if (grep(/^\Q$item\E$/,@modifiable)) {
 5835:                     $modifyhash{$context}{$role}{$item} = 1;
 5836:                 } else {
 5837:                     $modifyhash{$context}{$role}{$item} = 0;
 5838:                 }
 5839:             }
 5840:         }
 5841:         if (ref($curr_usermodification{$context}) eq 'HASH') {
 5842:             foreach my $role (@{$roles{$context}}) {
 5843:                 if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
 5844:                     foreach my $field (@fields) {
 5845:                         if ($modifyhash{$context}{$role}{$field} ne 
 5846:                                 $curr_usermodification{$context}{$role}{$field}) {
 5847:                             push(@{$changes{$context}},$role);
 5848:                             last;
 5849:                         }
 5850:                     }
 5851:                 }
 5852:             }
 5853:         } else {
 5854:             foreach my $context (@contexts) {
 5855:                 foreach my $role (@{$roles{$context}}) {
 5856:                     push(@{$changes{$context}},$role);
 5857:                 }
 5858:             }
 5859:         }
 5860:     }
 5861:     my %usermodification_hash =  (
 5862:                                    usermodification => \%modifyhash,
 5863:                                  );
 5864:     my $putresult = &Apache::lonnet::put_dom('configuration',
 5865:                                              \%usermodification_hash,$dom);
 5866:     if ($putresult eq 'ok') {
 5867:         if (keys(%changes) > 0) {
 5868:             $resulttext = &mt('Changes made: ').'<ul>';
 5869:             foreach my $context (@contexts) {
 5870:                 if (ref($changes{$context}) eq 'ARRAY') {
 5871:                     $resulttext .= '<li>'.$context_title{$context}.':<ul>';
 5872:                     if (ref($changes{$context}) eq 'ARRAY') {
 5873:                         foreach my $role (@{$changes{$context}}) {
 5874:                             my $rolename;
 5875:                             if ($context eq 'selfcreate') {
 5876:                                 $rolename = $role;
 5877:                                 if (ref($usertypes) eq 'HASH') {
 5878:                                     if ($usertypes->{$role} ne '') {
 5879:                                         $rolename = $usertypes->{$role};
 5880:                                     }
 5881:                                 }
 5882:                             } else {
 5883:                                 if ($role eq 'cr') {
 5884:                                     $rolename = &mt('Custom');
 5885:                                 } else {
 5886:                                     $rolename = &Apache::lonnet::plaintext($role);
 5887:                                 }
 5888:                             }
 5889:                             my @modifiable;
 5890:                             if ($context eq 'selfcreate') {
 5891:                                 $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): ');
 5892:                             } else {
 5893:                                 $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
 5894:                             }
 5895:                             foreach my $field (@fields) {
 5896:                                 if ($modifyhash{$context}{$role}{$field}) {
 5897:                                     push(@modifiable,$fieldtitles{$field});
 5898:                                 }
 5899:                             }
 5900:                             if (@modifiable > 0) {
 5901:                                 $resulttext .= join(', ',@modifiable);
 5902:                             } else {
 5903:                                 $resulttext .= &mt('none'); 
 5904:                             }
 5905:                             $resulttext .= '</li>';
 5906:                         }
 5907:                         $resulttext .= '</ul></li>';
 5908:                     }
 5909:                 }
 5910:             }
 5911:             $resulttext .= '</ul>';
 5912:         } else {
 5913:             $resulttext = &mt('No changes made to user modification settings');
 5914:         }
 5915:     } else {
 5916:         $resulttext = '<span class="LC_error">'.
 5917:             &mt('An error occurred: [_1]',$putresult).'</span>';
 5918:     }
 5919:     return $resulttext;
 5920: }
 5921: 
 5922: sub modify_defaults {
 5923:     my ($dom,$r) = @_;
 5924:     my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
 5925:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
 5926:     my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def');
 5927:     my @authtypes = ('internal','krb4','krb5','localauth');
 5928:     foreach my $item (@items) {
 5929:         $newvalues{$item} = $env{'form.'.$item};
 5930:         if ($item eq 'auth_def') {
 5931:             if ($newvalues{$item} ne '') {
 5932:                 if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
 5933:                     push(@errors,$item);
 5934:                 }
 5935:             }
 5936:         } elsif ($item eq 'lang_def') {
 5937:             if ($newvalues{$item} ne '') {
 5938:                 if ($newvalues{$item} =~ /^(\w+)/) {
 5939:                     my $langcode = $1;
 5940:                     if ($langcode ne 'x_chef') {
 5941:                         if (code2language($langcode) eq '') {
 5942:                             push(@errors,$item);
 5943:                         }
 5944:                     }
 5945:                 } else {
 5946:                     push(@errors,$item);
 5947:                 }
 5948:             }
 5949:         } elsif ($item eq 'timezone_def') {
 5950:             if ($newvalues{$item} ne '') {
 5951:                 if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
 5952:                     push(@errors,$item);   
 5953:                 }
 5954:             }
 5955:         } elsif ($item eq 'datelocale_def') {
 5956:             if ($newvalues{$item} ne '') {
 5957:                 my @datelocale_ids = DateTime::Locale->ids();
 5958:                 if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
 5959:                     push(@errors,$item);
 5960:                 }
 5961:             }
 5962:         }
 5963:         if (grep(/^\Q$item\E$/,@errors)) {
 5964:             $newvalues{$item} = $domdefaults{$item};
 5965:         } elsif ($domdefaults{$item} ne $newvalues{$item}) {
 5966:             $changes{$item} = 1;
 5967:         }
 5968:         $domdefaults{$item} = $newvalues{$item};
 5969:     }
 5970:     my %defaults_hash = (
 5971:                          defaults => \%newvalues,
 5972:                         );
 5973:     my $title = &defaults_titles();
 5974:     my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
 5975:                                              $dom);
 5976:     if ($putresult eq 'ok') {
 5977:         if (keys(%changes) > 0) {
 5978:             $resulttext = &mt('Changes made:').'<ul>';
 5979:             my $version = $r->dir_config('lonVersion');
 5980:             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";
 5981:             foreach my $item (sort(keys(%changes))) {
 5982:                 my $value = $env{'form.'.$item};
 5983:                 if ($value eq '') {
 5984:                     $value = &mt('none');
 5985:                 } elsif ($item eq 'auth_def') {
 5986:                     my %authnames = &authtype_names();
 5987:                     my %shortauth = (
 5988:                              internal => 'int',
 5989:                              krb4 => 'krb4',
 5990:                              krb5 => 'krb5',
 5991:                              localauth  => 'loc',
 5992:                     );
 5993:                     $value = $authnames{$shortauth{$value}};
 5994:                 }
 5995:                 $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
 5996:                 $mailmsgtext .= "$title->{$item} set to $value\n";  
 5997:             }
 5998:             $resulttext .= '</ul>';
 5999:             $mailmsgtext .= "\n";
 6000:             my $cachetime = 24*60*60;
 6001:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
 6002:             if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
 6003:                 my $sysmail = $r->dir_config('lonSysEMail');
 6004:                 &Apache::lonmsg::sendemail($sysmail,"LON-CAPA Domain Settings Change - $dom",$mailmsgtext);
 6005:             }
 6006:         } else {
 6007:             $resulttext = &mt('No changes made to default authentication/language/timezone settings');
 6008:         }
 6009:     } else {
 6010:         $resulttext = '<span class="LC_error">'.
 6011:             &mt('An error occurred: [_1]',$putresult).'</span>';
 6012:     }
 6013:     if (@errors > 0) {
 6014:         $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
 6015:         foreach my $item (@errors) {
 6016:             $resulttext .= ' "'.$title->{$item}.'",';
 6017:         }
 6018:         $resulttext =~ s/,$//;
 6019:     }
 6020:     return $resulttext;
 6021: }
 6022: 
 6023: sub modify_scantron {
 6024:     my ($r,$dom,$confname,%domconfig) = @_;
 6025:     my ($resulttext,%confhash,%changes,$errors);
 6026:     my $custom = 'custom.tab';
 6027:     my $default = 'default.tab';
 6028:     my $servadm = $r->dir_config('lonAdmEMail');
 6029:     my ($configuserok,$author_ok,$switchserver) = 
 6030:         &config_check($dom,$confname,$servadm);
 6031:     if ($env{'form.scantronformat.filename'} ne '') {
 6032:         my $error;
 6033:         if ($configuserok eq 'ok') {
 6034:             if ($switchserver) {
 6035:                 $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
 6036:             } else {
 6037:                 if ($author_ok eq 'ok') {
 6038:                     my ($result,$scantronurl) =
 6039:                         &publishlogo($r,'upload','scantronformat',$dom,
 6040:                                      $confname,'scantron','','',$custom);
 6041:                     if ($result eq 'ok') {
 6042:                         $confhash{'scantron'}{'scantronformat'} = $scantronurl;
 6043:                         $changes{'scantronformat'} = 1;
 6044:                     } else {
 6045:                         $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
 6046:                     }
 6047:                 } else {
 6048:                     $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);
 6049:                 }
 6050:             }
 6051:         } else {
 6052:             $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);
 6053:         }
 6054:         if ($error) {
 6055:             &Apache::lonnet::logthis($error);
 6056:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
 6057:         }
 6058:     }
 6059:     if (ref($domconfig{'scantron'}) eq 'HASH') {
 6060:         if ($domconfig{'scantron'}{'scantronformat'} ne '') {
 6061:             if ($env{'form.scantronformat_del'}) {
 6062:                 $confhash{'scantron'}{'scantronformat'} = '';
 6063:                 $changes{'scantronformat'} = 1;
 6064:             }
 6065:         }
 6066:     }
 6067:     if (keys(%confhash) > 0) {
 6068:         my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
 6069:                                                  $dom);
 6070:         if ($putresult eq 'ok') {
 6071:             if (keys(%changes) > 0) {
 6072:                 if (ref($confhash{'scantron'}) eq 'HASH') {
 6073:                     $resulttext = &mt('Changes made:').'<ul>';
 6074:                     if ($confhash{'scantron'}{'scantronformat'} eq '') {
 6075:                         $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
 6076:                     } else {
 6077:                         $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
 6078:                     }
 6079:                     $resulttext .= '</ul>';
 6080:                 } else {
 6081:                     $resulttext = &mt('Changes made to bubblesheet format file.');
 6082:                 }
 6083:                 $resulttext .= '</ul>';
 6084:                 &Apache::loncommon::devalidate_domconfig_cache($dom);
 6085:             } else {
 6086:                 $resulttext = &mt('No changes made to bubblesheet format file');
 6087:             }
 6088:         } else {
 6089:             $resulttext = '<span class="LC_error">'.
 6090:                 &mt('An error occurred: [_1]',$putresult).'</span>';
 6091:         }
 6092:     } else {
 6093:         $resulttext = &mt('No changes made to bubblesheet format file'); 
 6094:     }
 6095:     if ($errors) {
 6096:         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
 6097:                        $errors.'</ul>';
 6098:     }
 6099:     return $resulttext;
 6100: }
 6101: 
 6102: sub modify_coursecategories {
 6103:     my ($dom,%domconfig) = @_;
 6104:     my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
 6105:         $cathash);
 6106:     my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
 6107:     if (ref($domconfig{'coursecategories'}) eq 'HASH') {
 6108:         $cathash = $domconfig{'coursecategories'}{'cats'};
 6109:         if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
 6110:             $changes{'togglecats'} = 1;
 6111:             $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
 6112:         }
 6113:         if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
 6114:             $changes{'categorize'} = 1;
 6115:             $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
 6116:         }
 6117:         if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
 6118:             $changes{'togglecatscomm'} = 1;
 6119:             $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
 6120:         }
 6121:         if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
 6122:             $changes{'categorizecomm'} = 1;
 6123:             $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
 6124:         }
 6125:     } else {
 6126:         $changes{'togglecats'} = 1;
 6127:         $changes{'categorize'} = 1;
 6128:         $changes{'togglecatscomm'} = 1;
 6129:         $changes{'categorizecomm'} = 1;
 6130:         $domconfig{'coursecategories'} = {
 6131:                                              togglecats => $env{'form.togglecats'},
 6132:                                              categorize => $env{'form.categorize'},
 6133:                                              togglecatscomm => $env{'form.togglecatscomm'},
 6134:                                              categorizecomm => $env{'form.categorizecomm'},
 6135:                                          };
 6136:     }
 6137:     if (ref($cathash) eq 'HASH') {
 6138:         if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '')  && ($env{'form.instcode'} == 0)) {
 6139:             push (@deletecategory,'instcode::0');
 6140:         }
 6141:         if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '')  && ($env{'form.communities'} == 0)) {
 6142:             push(@deletecategory,'communities::0');
 6143:         }
 6144:     }
 6145:     my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
 6146:     if (ref($cathash) eq 'HASH') {
 6147:         if (@deletecategory > 0) {
 6148:             #FIXME Need to remove category from all courses using a deleted category 
 6149:             &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
 6150:             foreach my $item (@deletecategory) {
 6151:                 if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
 6152:                     delete($domconfig{'coursecategories'}{'cats'}{$item});
 6153:                     $deletions{$item} = 1;
 6154:                     &recurse_cat_deletes($item,$cathash,\%deletions);
 6155:                 }
 6156:             }
 6157:         }
 6158:         foreach my $item (keys(%{$cathash})) {
 6159:             my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
 6160:             if ($cathash->{$item} ne $env{'form.'.$item}) {
 6161:                 $reorderings{$item} = 1;
 6162:                 $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
 6163:             }
 6164:             if ($env{'form.addcategory_name_'.$item} ne '') {
 6165:                 my $newcat = $env{'form.addcategory_name_'.$item};
 6166:                 my $newdepth = $depth+1;
 6167:                 my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
 6168:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
 6169:                 $adds{$newitem} = 1; 
 6170:             }
 6171:             if ($env{'form.subcat_'.$item} ne '') {
 6172:                 my $newcat = $env{'form.subcat_'.$item};
 6173:                 my $newdepth = $depth+1;
 6174:                 my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
 6175:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
 6176:                 $adds{$newitem} = 1;
 6177:             }
 6178:         }
 6179:     }
 6180:     if ($env{'form.instcode'} eq '1') {
 6181:         if (ref($cathash) eq 'HASH') {
 6182:             my $newitem = 'instcode::0';
 6183:             if ($cathash->{$newitem} eq '') {  
 6184:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
 6185:                 $adds{$newitem} = 1;
 6186:             }
 6187:         } else {
 6188:             my $newitem = 'instcode::0';
 6189:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
 6190:             $adds{$newitem} = 1;
 6191:         }
 6192:     }
 6193:     if ($env{'form.communities'} eq '1') {
 6194:         if (ref($cathash) eq 'HASH') {
 6195:             my $newitem = 'communities::0';
 6196:             if ($cathash->{$newitem} eq '') {
 6197:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
 6198:                 $adds{$newitem} = 1;
 6199:             }
 6200:         } else {
 6201:             my $newitem = 'communities::0';
 6202:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
 6203:             $adds{$newitem} = 1;
 6204:         }
 6205:     }
 6206:     if ($env{'form.addcategory_name'} ne '') {
 6207:         if (($env{'form.addcategory_name'} ne 'instcode') &&
 6208:             ($env{'form.addcategory_name'} ne 'communities')) {
 6209:             my $newitem = &escape($env{'form.addcategory_name'}).'::0';
 6210:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
 6211:             $adds{$newitem} = 1;
 6212:         }
 6213:     }
 6214:     my $putresult;
 6215:     if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
 6216:         if (keys(%deletions) > 0) {
 6217:             foreach my $key (keys(%deletions)) {
 6218:                 if ($predelallitems{$key} ne '') {
 6219:                     $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
 6220:                 }
 6221:             }
 6222:         }
 6223:         my (@chkcats,@chktrails,%chkallitems);
 6224:         &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
 6225:         if (ref($chkcats[0]) eq 'ARRAY') {
 6226:             my $depth = 0;
 6227:             my $chg = 0;
 6228:             for (my $i=0; $i<@{$chkcats[0]}; $i++) {
 6229:                 my $name = $chkcats[0][$i];
 6230:                 my $item;
 6231:                 if ($name eq '') {
 6232:                     $chg ++;
 6233:                 } else {
 6234:                     $item = &escape($name).'::0';
 6235:                     if ($chg) {
 6236:                         $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
 6237:                     }
 6238:                     $depth ++; 
 6239:                     &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
 6240:                     $depth --;
 6241:                 }
 6242:             }
 6243:         }
 6244:     }
 6245:     if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
 6246:         $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
 6247:         if ($putresult eq 'ok') {
 6248:             my %title = (
 6249:                          togglecats     => 'Show/Hide a course in catalog',
 6250:                          categorize     => 'Assign a category to a course',
 6251:                          togglecatscomm => 'Show/Hide a community in catalog',
 6252:                          categorizecomm => 'Assign a category to a community',
 6253:                         );
 6254:             my %level = (
 6255:                          dom  => 'set in Domain ("Modify Course/Community")',
 6256:                          crs  => 'set in Course ("Course Configuration")',
 6257:                          comm => 'set in Community ("Community Configuration")',
 6258:                         );
 6259:             $resulttext = &mt('Changes made:').'<ul>';
 6260:             if ($changes{'togglecats'}) {
 6261:                 $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>'; 
 6262:             }
 6263:             if ($changes{'categorize'}) {
 6264:                 $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
 6265:             }
 6266:             if ($changes{'togglecatscomm'}) {
 6267:                 $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
 6268:             }
 6269:             if ($changes{'categorizecomm'}) {
 6270:                 $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
 6271:             }
 6272:             if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
 6273:                 my $cathash;
 6274:                 if (ref($domconfig{'coursecategories'}) eq 'HASH') {
 6275:                     $cathash = $domconfig{'coursecategories'}{'cats'};
 6276:                 } else {
 6277:                     $cathash = {};
 6278:                 } 
 6279:                 my (@cats,@trails,%allitems);
 6280:                     &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
 6281:                 if (keys(%deletions) > 0) {
 6282:                     $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
 6283:                     foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) { 
 6284:                         $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
 6285:                     }
 6286:                     $resulttext .= '</ul></li>';
 6287:                 }
 6288:                 if (keys(%reorderings) > 0) {
 6289:                     my %sort_by_trail;
 6290:                     $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
 6291:                     foreach my $key (keys(%reorderings)) {
 6292:                         if ($allitems{$key} ne '') {
 6293:                             $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
 6294:                         }
 6295:                     }
 6296:                     foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
 6297:                         $resulttext .= '<li>'.$trails[$trail].'</li>';
 6298:                     }
 6299:                     $resulttext .= '</ul></li>';
 6300:                 }
 6301:                 if (keys(%adds) > 0) {
 6302:                     my %sort_by_trail;
 6303:                     $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
 6304:                     foreach my $key (keys(%adds)) {
 6305:                         if ($allitems{$key} ne '') {
 6306:                             $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
 6307:                         }
 6308:                     }
 6309:                     foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
 6310:                         $resulttext .= '<li>'.$trails[$trail].'</li>';
 6311:                     }
 6312:                     $resulttext .= '</ul></li>';
 6313:                 }
 6314:             }
 6315:             $resulttext .= '</ul>';
 6316:         } else {
 6317:             $resulttext = '<span class="LC_error">'.
 6318:                           &mt('An error occurred: [_1]',$putresult).'</span>';
 6319:         }
 6320:     } else {
 6321:         $resulttext = &mt('No changes made to course and community categories');
 6322:     }
 6323:     return $resulttext;
 6324: }
 6325: 
 6326: sub modify_serverstatuses {
 6327:     my ($dom,%domconfig) = @_;
 6328:     my ($resulttext,%changes,%currserverstatus,%newserverstatus);
 6329:     if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
 6330:         %currserverstatus = %{$domconfig{'serverstatuses'}};
 6331:     }
 6332:     my @pages = &serverstatus_pages();
 6333:     foreach my $type (@pages) {
 6334:         $newserverstatus{$type}{'namedusers'} = '';
 6335:         $newserverstatus{$type}{'machines'} = '';
 6336:         if (defined($env{'form.'.$type.'_namedusers'})) {
 6337:             my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
 6338:             my @okusers;
 6339:             foreach my $user (@users) {
 6340:                 my ($uname,$udom) = split(/:/,$user);
 6341:                 if (($udom =~ /^$match_domain$/) &&   
 6342:                     (&Apache::lonnet::domain($udom)) &&
 6343:                     ($uname =~ /^$match_username$/)) {
 6344:                     if (!grep(/^\Q$user\E/,@okusers)) {
 6345:                         push(@okusers,$user);
 6346:                     }
 6347:                 }
 6348:             }
 6349:             if (@okusers > 0) {
 6350:                  @okusers = sort(@okusers);
 6351:                  $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
 6352:             }
 6353:         }
 6354:         if (defined($env{'form.'.$type.'_machines'})) {
 6355:             my @machines = split(/,/,$env{'form.'.$type.'_machines'});
 6356:             my @okmachines;
 6357:             foreach my $ip (@machines) {
 6358:                 my @parts = split(/\./,$ip);
 6359:                 next if (@parts < 4);
 6360:                 my $badip = 0;
 6361:                 for (my $i=0; $i<4; $i++) {
 6362:                     if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
 6363:                         $badip = 1;
 6364:                         last;
 6365:                     }
 6366:                 }
 6367:                 if (!$badip) {
 6368:                     push(@okmachines,$ip);     
 6369:                 }
 6370:             }
 6371:             @okmachines = sort(@okmachines);
 6372:             $newserverstatus{$type}{'machines'} = join(',',@okmachines);
 6373:         }
 6374:     }
 6375:     my %serverstatushash =  (
 6376:                                 serverstatuses => \%newserverstatus,
 6377:                             );
 6378:     my %changes;
 6379:     foreach my $type (@pages) {
 6380:         foreach my $setting ('namedusers','machines') {
 6381:             my (@current,@new);
 6382:             if (ref($currserverstatus{$type}) eq 'HASH') {
 6383:                 if ($currserverstatus{$type}{$setting} ne '') { 
 6384:                     @current = split(/,/,$currserverstatus{$type}{$setting});
 6385:                 }
 6386:             }
 6387:             if ($newserverstatus{$type}{$setting} ne '') {
 6388:                 @new = split(/,/,$newserverstatus{$type}{$setting});
 6389:             }
 6390:             if (@current > 0) {
 6391:                 if (@new > 0) {
 6392:                     foreach my $item (@current) {
 6393:                         if (!grep(/^\Q$item\E$/,@new)) {
 6394:                             $changes{$type}{$setting} = 1;
 6395:                             last;
 6396:                         }
 6397:                     }
 6398:                     foreach my $item (@new) {
 6399:                         if (!grep(/^\Q$item\E$/,@current)) {
 6400:                             $changes{$type}{$setting} = 1;
 6401:                             last;
 6402:                         }
 6403:                     }
 6404:                 } else {
 6405:                     $changes{$type}{$setting} = 1;
 6406:                 }
 6407:             } elsif (@new > 0) {
 6408:                 $changes{$type}{$setting} = 1;
 6409:             }
 6410:         }
 6411:     }
 6412:     if (keys(%changes) > 0) {
 6413:         my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
 6414:         my $putresult = &Apache::lonnet::put_dom('configuration',
 6415:                                                  \%serverstatushash,$dom);
 6416:         if ($putresult eq 'ok') {
 6417:             $resulttext .= &mt('Changes made:').'<ul>';
 6418:             foreach my $type (@pages) {
 6419:                 if (ref($changes{$type}) eq 'HASH') {
 6420:                     $resulttext .= '<li>'.$titles->{$type}.'<ul>';
 6421:                     if ($changes{$type}{'namedusers'}) {
 6422:                         if ($newserverstatus{$type}{'namedusers'} eq '') {
 6423:                             $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
 6424:                         } else {
 6425:                             $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
 6426:                         }
 6427:                     }
 6428:                     if ($changes{$type}{'machines'}) {
 6429:                         if ($newserverstatus{$type}{'machines'} eq '') {
 6430:                             $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
 6431:                         } else {
 6432:                             $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
 6433:                         }
 6434: 
 6435:                     }
 6436:                     $resulttext .= '</ul></li>';
 6437:                 }
 6438:             }
 6439:             $resulttext .= '</ul>';
 6440:         } else {
 6441:             $resulttext = '<span class="LC_error">'.
 6442:                           &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
 6443: 
 6444:         }
 6445:     } else {
 6446:         $resulttext = &mt('No changes made to access to server status pages');
 6447:     }
 6448:     return $resulttext;
 6449: }
 6450: 
 6451: sub modify_helpsettings {
 6452:     my ($r,$dom,$confname,%domconfig) = @_;
 6453:  	my ($resulttext,$errors,%changes,%helphash);
 6454:  	
 6455:  	my $customhelpfile  = $env{'form.loginhelpurl.filename'};
 6456:     my $defaulthelpfile = 'defaulthelp.html';
 6457:  	my $servadm = $r->dir_config('lonAdmEMail');
 6458:     my ($configuserok,$author_ok,$switchserver) = 
 6459:         &config_check($dom,$confname,$servadm);
 6460:  	
 6461:  	my %defaultchecked = ('submitbugs'	=> 'on');
 6462:  	my @offon = ('off','on');
 6463:     my %title = ( submitbugs     => 'Display link for users to submit a bug', 
 6464:     			  loginhelpurl  => 'Unauthenticated login help page set to custom file');
 6465:     			  
 6466:     my @toggles = ('submitbugs');
 6467: 
 6468:     $helphash{'helpsettings'} = {};
 6469:     
 6470:     if (ref($domconfig{'helpsettings'}) ne 'HASH') {
 6471:         if ($domconfig{'helpsettings'} eq '') {
 6472:             $domconfig{'helpsettings'} = {};
 6473:         }
 6474:     }
 6475:     
 6476:     if (ref($domconfig{'helpsettings'}) eq 'HASH') {
 6477:     	
 6478:         foreach my $item (@toggles) {
 6479:         	
 6480: 			if ($defaultchecked{$item} eq 'on') { 
 6481: 				if (($domconfig{'helpsettings'}{$item} eq '') &&
 6482: 					 ($env{'form.'.$item} eq '0')) {
 6483: 					$changes{$item} = 1;
 6484: 				} elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
 6485: 					$changes{$item} = 1;
 6486: 				}
 6487: 			} elsif ($defaultchecked{$item} eq 'off') {
 6488: 				if (($domconfig{'helpsettings'}{$item} eq '') &&
 6489: 					 ($env{'form.'.$item} eq '1')) {
 6490: 					$changes{$item} = 1;
 6491: 				} elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
 6492: 					$changes{$item} = 1;
 6493: 				}
 6494: 			}
 6495: 			$helphash{'helpsettings'}{$item} = $env{'form.'.$item};
 6496: 		}
 6497: 		
 6498: 		if ($customhelpfile ne '') {
 6499: 			my $error;
 6500: 			if ($configuserok eq 'ok') {
 6501: 				if ($switchserver) {
 6502: 					$error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
 6503: 				} else {
 6504: 					if ($author_ok eq 'ok') {
 6505: 						my ($result,$loginhelpurl) =
 6506: 							&publishlogo($r,'upload','loginhelpurl',$dom,
 6507: 										 $confname,'help','','',$customhelpfile);
 6508: 						if ($result eq 'ok') {
 6509: 							$helphash{'helpsettings'}{'loginhelpurl'} = $loginhelpurl;
 6510: 							$changes{'loginhelpurl'} = 1;
 6511: 						} else {
 6512: 							$error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customhelpfile,$result);
 6513: 						}
 6514: 					} else {
 6515: 						$error = &mt("Upload of [_1] failed because an author role could not be assigned to a Domain Configuration user ([_2]) in domain: [_3].  Error was: [_4].",$customhelpfile,$confname,$dom,$author_ok);
 6516: 					}
 6517: 				}
 6518: 			} else {
 6519: 				$error = &mt("Upload of [_1] failed because a Domain Configuration user ([_2]) could not be created in domain: [_3].  Error was: [_4].",$customhelpfile,$confname,$dom,$configuserok);
 6520: 			}
 6521: 			if ($error) {
 6522: 				&Apache::lonnet::logthis($error);
 6523: 				$errors .= '<li><span class="LC_error">'.$error.'</span></li>';
 6524: 			}
 6525: 		}
 6526: 		
 6527:         if ($domconfig{'helpsettings'}{'loginhelpurl'} ne '') {
 6528:             if ($env{'form.loginhelpurl_del'}) {
 6529:                 $helphash{'helpsettings'}{'loginhelpurl'} = '';
 6530:                 $changes{'loginhelpurl'} = 1;
 6531:             }
 6532:         }
 6533:     }
 6534:     
 6535:     
 6536:     my $putresult;
 6537:     
 6538:     if (keys(%changes) > 0) {
 6539:     	$putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
 6540:     } else {
 6541:     	$putresult = 'ok';
 6542:     }
 6543:                                              
 6544:     if ($putresult eq 'ok') {
 6545:         if (keys(%changes) > 0) {
 6546: 			$resulttext = &mt('Changes made:').'<ul>';
 6547: 			foreach my $item (sort(keys(%changes))) {
 6548: 				if ($item eq 'submitbugs') {
 6549: 					$resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
 6550: 				}
 6551: 				if ($item eq 'loginhelpurl') {
 6552: 					if ($helphash{'helpsettings'}{'loginhelpurl'} eq '') {
 6553:                         $resulttext .= '<li>'.&mt('[_1] help file removed; [_2] file will be used for the unathorized help page in this domain.',$customhelpfile,$defaulthelpfile).'</li>';
 6554:                     } else {
 6555:                         $resulttext .= '<li>'.&mt("$title{$item} [_1]",$customhelpfile).'</li>';
 6556:                     }
 6557: 				}
 6558: 			}
 6559: 			$resulttext .= '</ul>';
 6560: 		} else {
 6561: 			$resulttext = &mt('No changes made to help settings');
 6562: 		}
 6563:     } else {
 6564:         $resulttext = '<span class="LC_error">'.
 6565: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
 6566:     }
 6567:     if ($errors) {
 6568:         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
 6569:                        $errors.'</ul>';
 6570:     }
 6571:     return $resulttext;
 6572: }
 6573: 
 6574: sub modify_coursedefaults {
 6575:     my ($dom,%domconfig) = @_;
 6576:     my ($resulttext,$errors,%changes,%defaultshash);
 6577:     my %defaultchecked = ('canuse_pdfforms' => 'off');
 6578:     my @offon = ('off','on');
 6579:     my @toggles = ('canuse_pdfforms');
 6580: 
 6581:     $defaultshash{'coursedefaults'} = {};
 6582: 
 6583:     if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
 6584:         if ($domconfig{'coursedefaults'} eq '') {
 6585:             $domconfig{'coursedefaults'} = {};
 6586:         }
 6587:     }
 6588: 
 6589:     if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
 6590:         foreach my $item (@toggles) {
 6591:             if ($defaultchecked{$item} eq 'on') {
 6592:                 if (($domconfig{'coursedefaults'}{$item} eq '') &&
 6593:                     ($env{'form.'.$item} eq '0')) {
 6594:                     $changes{$item} = 1;
 6595:                 } elsif ($domconfig{'coursdefaults'}{$item} ne $env{'form.'.$item}) {
 6596:                     $changes{$item} = 1;
 6597:                 }
 6598:             } elsif ($defaultchecked{$item} eq 'off') {
 6599:                 if (($domconfig{'coursedefaults'}{$item} eq '') &&
 6600:                     ($env{'form.'.$item} eq '1')) {
 6601:                     $changes{$item} = 1;
 6602:                 } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
 6603:                     $changes{$item} = 1;
 6604:                 }
 6605:             }
 6606:             $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
 6607:         }
 6608:     }
 6609:     my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
 6610:                                              $dom);
 6611:     if ($putresult eq 'ok') {
 6612:         if (keys(%changes) > 0) {
 6613:             if ($changes{'canuse_pdfforms'}) {
 6614:                 my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
 6615:                 $domdefaults{'canuse_pdfforms'}=$defaultshash{'coursedefaults'}{'canuse_pdfforms'};
 6616:                 my $cachetime = 24*60*60;
 6617:                 &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
 6618:             }
 6619:             $resulttext = &mt('Changes made:').'<ul>';
 6620:             foreach my $item (sort(keys(%changes))) {
 6621:                 if ($item eq 'canuse_pdfforms') {
 6622:                     if ($env{'form.'.$item} eq '1') {
 6623:                         $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
 6624:                     } else {
 6625:                         $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
 6626:                     }
 6627:                 }
 6628:             }
 6629:             $resulttext .= '</ul>';
 6630:         } else {
 6631:             $resulttext = &mt('No changes made to course defaults');
 6632:         }
 6633:     } else {
 6634:         $resulttext = '<span class="LC_error">'.
 6635:             &mt('An error occurred: [_1]',$putresult).'</span>';
 6636:     }
 6637:     return $resulttext;
 6638: }
 6639: 
 6640: sub modify_usersessions {
 6641:     my ($dom,%domconfig) = @_;
 6642:     my @types = ('version','excludedomain','includedomain');
 6643:     my @prefixes = ('remote','hosted');
 6644:     my @lcversions = &Apache::lonnet::all_loncaparevs();
 6645:     my (%defaultshash,%changes);
 6646:     foreach my $prefix (@prefixes) {
 6647:         $defaultshash{'usersessions'}{$prefix} = {};
 6648:     }
 6649:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
 6650:     my $resulttext;
 6651:     foreach my $prefix (@prefixes) {
 6652:         foreach my $type (@types) {
 6653:             my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
 6654:             if ($type eq 'version') {
 6655:                 my $value = $env{'form.'.$prefix.'_'.$type};
 6656:                 my $okvalue;
 6657:                 if ($value ne '') {
 6658:                     if (grep(/^\Q$value\E$/,@lcversions)) {
 6659:                         $okvalue = $value;
 6660:                     }
 6661:                 }
 6662:                 if (ref($domconfig{'usersessions'}) eq 'HASH') {
 6663:                     if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
 6664:                         if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
 6665:                             if ($inuse == 0) {
 6666:                                 $changes{$prefix}{$type} = 1;
 6667:                             } else {
 6668:                                 if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
 6669:                                     $changes{$prefix}{$type} = 1;
 6670:                                 }
 6671:                                 if ($okvalue ne '') {
 6672:                                     $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
 6673:                                 } 
 6674:                             }
 6675:                         } else {
 6676:                             if (($inuse == 1) && ($okvalue ne '')) {
 6677:                                 $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
 6678:                                 $changes{$prefix}{$type} = 1;
 6679:                             }
 6680:                         }
 6681:                     } else {
 6682:                         if (($inuse == 1) && ($okvalue ne '')) {
 6683:                             $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
 6684:                             $changes{$prefix}{$type} = 1;
 6685:                         }
 6686:                     }
 6687:                 } else {
 6688:                     if (($inuse == 1) && ($okvalue ne '')) {
 6689:                         $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
 6690:                         $changes{$prefix}{$type} = 1;
 6691:                     }
 6692:                 }
 6693:             } else {
 6694:                 my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
 6695:                 my @okvals;
 6696:                 foreach my $val (@vals) {
 6697:                     if (&Apache::lonnet::domain($val) ne '') {
 6698:                         push(@okvals,$val);
 6699:                     }
 6700:                 }
 6701:                 @okvals = sort(@okvals);
 6702:                 if (ref($domconfig{'usersessions'}) eq 'HASH') {
 6703:                     if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
 6704:                         if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
 6705:                             if ($inuse == 0) {
 6706:                                 $changes{$prefix}{$type} = 1; 
 6707:                             } else {
 6708:                                 $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
 6709:                                 my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
 6710:                                 if (@changed > 0) {
 6711:                                     $changes{$prefix}{$type} = 1;
 6712:                                 }
 6713:                             }
 6714:                         } else {
 6715:                             if ($inuse == 1) {
 6716:                                 $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
 6717:                                 $changes{$prefix}{$type} = 1;
 6718:                             }
 6719:                         } 
 6720:                     } else {
 6721:                         if ($inuse == 1) {
 6722:                             $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
 6723:                             $changes{$prefix}{$type} = 1;
 6724:                         }
 6725:                     }
 6726:                 } else {
 6727:                     if ($inuse == 1) {
 6728:                         $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
 6729:                         $changes{$prefix}{$type} = 1;
 6730:                     }
 6731:                 }
 6732:             }
 6733:         }
 6734:     }
 6735:     if (keys(%changes) > 0) {
 6736:         my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
 6737:                                                  $dom);
 6738:         if ($putresult eq 'ok') {
 6739:             if (ref($defaultshash{'usersessions'}) eq 'HASH') {
 6740:                 if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
 6741:                     $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
 6742:                 }
 6743:                 if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
 6744:                     $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
 6745:                 }
 6746:             }
 6747:             my $cachetime = 24*60*60;
 6748:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
 6749:             my %lt = &usersession_titles();
 6750:             $resulttext = &mt('Changes made:').'<ul>';
 6751:             foreach my $prefix (@prefixes) {
 6752:                 if (ref($changes{$prefix}) eq 'HASH') {
 6753:                     $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
 6754:                     foreach my $type (@types) {
 6755:                         if (defined($changes{$prefix}{$type})) {
 6756:                             my $newvalue;
 6757:                             if (ref($defaultshash{'usersessions'}) eq 'HASH') {
 6758:                                 if (ref($defaultshash{'usersessions'}{$prefix})) {
 6759:                                     if ($type eq 'version') {
 6760:                                         $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
 6761:                                     } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
 6762:                                         if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
 6763:                                             $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
 6764:                                         }
 6765:                                     }
 6766:                                 }
 6767:                             }
 6768:                             if ($newvalue eq '') {
 6769:                                 if ($type eq 'version') {
 6770:                                     $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
 6771:                                 } else {
 6772:                                     $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
 6773:                                 }
 6774:                             } else {
 6775:                                 if ($type eq 'version') {
 6776:                                     $newvalue .= ' '.&mt('(or later)'); 
 6777:                                 } 
 6778:                                 $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>'; 
 6779:                             }
 6780:                         }
 6781:                     }
 6782:                     $resulttext .= '</ul>';
 6783:                 }
 6784:             }
 6785:             $resulttext .= '</ul>';
 6786:         } else {
 6787:             $resulttext = '<span class="LC_error">'.
 6788:                           &mt('An error occurred: [_1]',$putresult).'</span>';
 6789:         }
 6790:     } else {
 6791:         $resulttext =  &mt('No changes made to settings for user session hosting.');
 6792:     }
 6793:     return $resulttext;
 6794: }
 6795: 
 6796: sub recurse_check {
 6797:     my ($chkcats,$categories,$depth,$name) = @_;
 6798:     if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
 6799:         my $chg = 0;
 6800:         for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
 6801:             my $category = $chkcats->[$depth]{$name}[$j];
 6802:             my $item;
 6803:             if ($category eq '') {
 6804:                 $chg ++;
 6805:             } else {
 6806:                 my $deeper = $depth + 1;
 6807:                 $item = &escape($category).':'.&escape($name).':'.$depth;
 6808:                 if ($chg) {
 6809:                     $categories->{$item} -= $chg;
 6810:                 }
 6811:                 &recurse_check($chkcats,$categories,$deeper,$category);
 6812:                 $deeper --;
 6813:             }
 6814:         }
 6815:     }
 6816:     return;
 6817: }
 6818: 
 6819: sub recurse_cat_deletes {
 6820:     my ($item,$coursecategories,$deletions) = @_;
 6821:     my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
 6822:     my $subdepth = $depth + 1;
 6823:     if (ref($coursecategories) eq 'HASH') {
 6824:         foreach my $subitem (keys(%{$coursecategories})) {
 6825:             my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
 6826:             if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
 6827:                 delete($coursecategories->{$subitem});
 6828:                 $deletions->{$subitem} = 1;
 6829:                 &recurse_cat_deletes($subitem,$coursecategories,$deletions);
 6830:             }  
 6831:         }
 6832:     }
 6833:     return;
 6834: }
 6835: 
 6836: sub dom_servers {
 6837:     my ($dom) = @_;
 6838:     my (%uniqservers,%servers);
 6839:     my $primaryserver = &Apache::lonnet::hostname(&Apache::lonnet::domain($dom,'primary'));
 6840:     my @machinedoms = &Apache::lonnet::machine_domains($primaryserver);
 6841:     foreach my $mdom (@machinedoms) {
 6842:         my %currservers = %servers;
 6843:         my %server = &Apache::lonnet::get_servers($mdom);
 6844:         %servers = (%currservers,%server);
 6845:     }
 6846:     my %by_hostname;
 6847:     foreach my $id (keys(%servers)) {
 6848:         push(@{$by_hostname{$servers{$id}}},$id);
 6849:     }
 6850:     foreach my $hostname (sort(keys(%by_hostname))) {
 6851:         if (@{$by_hostname{$hostname}} > 1) {
 6852:             my $match = 0;
 6853:             foreach my $id (@{$by_hostname{$hostname}}) {
 6854:                 if (&Apache::lonnet::host_domain($id) eq $dom) {
 6855:                     $uniqservers{$id} = $hostname;
 6856:                     $match = 1;
 6857:                 }
 6858:             }
 6859:             unless ($match) {
 6860:                 $uniqservers{$by_hostname{$hostname}[0]} = $hostname;
 6861:             }
 6862:         } else {
 6863:             $uniqservers{$by_hostname{$hostname}[0]} = $hostname;
 6864:         }
 6865:     }
 6866:     return %uniqservers;
 6867: }
 6868: 
 6869: sub get_active_dcs {
 6870:     my ($dom) = @_;
 6871:     my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc']);
 6872:     my %domcoords;
 6873:     my $numdcs = 0;
 6874:     my $now = time;
 6875:     foreach my $server (keys(%dompersonnel)) {
 6876:         foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
 6877:             my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
 6878:             my ($end,$start) = split(':',$dompersonnel{$server}{$user});
 6879:             if (($end eq '') || ($end == 0) || ($end > $now)) {
 6880:                 if ($start <= $now) {
 6881:                     $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
 6882:                 }
 6883:             }
 6884:         }
 6885:     }
 6886:     return %domcoords;
 6887: }
 6888: 
 6889: sub active_dc_picker {
 6890:     my ($dom,$curr_dc) = @_;
 6891:     my %domcoords = &get_active_dcs($dom); 
 6892:     my @dcs = sort(keys(%domcoords));
 6893:     my $numdcs = scalar(@dcs); 
 6894:     my $datatable;
 6895:     my $numinrow = 2;
 6896:     if ($numdcs > 1) {
 6897:         $datatable = '<table>';
 6898:         for (my $i=0; $i<@dcs; $i++) {
 6899:             my $rem = $i%($numinrow);
 6900:             if ($rem == 0) {
 6901:                 if ($i > 0) {
 6902:                     $datatable .= '</tr>';
 6903:                 }
 6904:                 $datatable .= '<tr>';
 6905:             }
 6906:             my $check = ' ';
 6907:             if ($curr_dc eq '') {
 6908:                 if (!$i) { 
 6909:                     $check = ' checked="checked" ';
 6910:                 }
 6911:             } elsif ($dcs[$i] eq $curr_dc) {
 6912:                 $check = ' checked="checked" ';
 6913:             }
 6914:             if ($i == @dcs - 1) {
 6915:                 my $colsleft = $numinrow - $rem;
 6916:                 if ($colsleft > 1) {
 6917:                     $datatable .= '<td colspan="'.$colsleft.'">';
 6918:                 } else {
 6919:                     $datatable .= '<td>';
 6920:                 }
 6921:             } else {
 6922:                 $datatable .= '<td>';
 6923:             }
 6924:             my ($dcname,$dcdom) = split(':',$dcs[$i]);
 6925:             $datatable .= '<span class="LC_nobreak"><label>'.
 6926:                           '<input type="radio" name="autocreate_xmldc"'.
 6927:                           ' value="'.$dcs[$i].'"'.$check.'/>'.
 6928:                           &Apache::loncommon::plainname($dcname,$dcdom).
 6929:                           '</label></span></td>';
 6930:         }
 6931:         $datatable .= '</tr></table>';
 6932:     } elsif (@dcs) {
 6933:         $datatable .= '<input type="hidden" name="autocreate_dc" value="'.
 6934:                       $dcs[0].'" />';
 6935:     }
 6936:     return ($numdcs,$datatable);
 6937: }
 6938: 
 6939: sub usersession_titles {
 6940:     return &Apache::lonlocal::texthash(
 6941:                hosted => 'Hosting of sessions for users from other domains on servers in this domain',
 6942: 
 6943:                remote => 'Hosting of sessions for users in this domain on servers in other domains',
 6944:                version => 'LON-CAPA version requirement',
 6945:                excludedomain => 'Specific domains excluded',
 6946:                includedomain => 'Specific domains included',
 6947:            );
 6948: }
 6949: 
 6950: 1;

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