File:  [LON-CAPA] / loncom / interface / domainprefs.pm
Revision 1.120: download - view: text, annotated - select for diffs
Mon Nov 23 21:45:18 2009 UTC (14 years, 6 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- Accommodate Communities
  - Top Level Category: "Communities" defined in system
    (Domain control to hide/unhide).
    - Can only assign communities to this category (and its subcategories).
- Domain Coordinator definition of new top level categories:
   instcode and communities are reserved for system use
   (may not be used for names of additional top level categories).

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

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