File:  [LON-CAPA] / loncom / interface / domainprefs.pm
Revision 1.102.2.9: download - view: text, annotated - select for diffs
Mon Feb 22 18:39:13 2010 UTC (14 years, 5 months ago) by raeburn
Branches: version_2_9_X
Diff to branchpoint 1.102: preferred, unified
- Backport 1.110 (part), 1.125, 1.126, 1.127.

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

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