File:  [LON-CAPA] / loncom / interface / domainprefs.pm
Revision 1.102.2.8: download - view: text, annotated - select for diffs
Tue Jan 26 15:47:27 2010 UTC (14 years, 4 months ago) by raeburn
Branches: version_2_9_X
Diff to branchpoint 1.102: preferred, unified
- Fix typo in 1.102.2.6 backport of 1.120.

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

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