File:  [LON-CAPA] / loncom / interface / domainprefs.pm
Revision 1.115: download - view: text, annotated - select for diffs
Wed Oct 21 14:06:11 2009 UTC (14 years, 7 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- Changes for multi-domain servers.
   - Display hostnames instead of hostIDs (hostIDs still stored internally).
   - Check for equivalence in hostname rather than hostID when excluding current server from redirect targets.

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

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